init structure

init protocol
This commit is contained in:
tony_all
2023-03-12 13:10:44 +08:00
parent 54ce760feb
commit 75dfd94e66
17 changed files with 303 additions and 34 deletions
+16
View File
@@ -0,0 +1,16 @@
plugins {
kotlin("jvm")
}
group = "cc.maxmc.msm.api"
repositories {
mavenCentral()
maven("https://repo.papermc.io/repository/maven-public/")
}
dependencies {
implementation(kotlin("stdlib"))
@Suppress("VulnerableLibrariesLocal")
compileOnly("io.github.waterfallmc:waterfall-api:1.19-R0.1-SNAPSHOT")
}
@@ -0,0 +1,18 @@
package cc.maxmc.msm.api;
import cc.maxmc.msm.api.misc.ServerInfo;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import java.util.List;
@SuppressWarnings("unused") // API
public interface MultiServerManAPI {
ServerInfo getServer(String type, List<ProxiedPlayer> players);
void informEnd(int id);
ServerInfo getPlayerServer(ProxiedPlayer player);
Boolean containPlayer(ProxiedPlayer player);
}
@@ -0,0 +1,31 @@
package cc.maxmc.msm.api;
@SuppressWarnings("unused") // API
public abstract class MultiServerManAPIProvider {
private static MultiServerManAPIProvider instance;
public static MultiServerManAPI getAPI() {
if (instance == null) {
throw new NotLoadedException();
}
return instance.provideAPI();
}
abstract MultiServerManAPI provideAPI();
/**
* 在加载 API 之前请求 API 时引发异常。
*/
private static final class NotLoadedException extends IllegalStateException {
private static final String MESSAGE = "The MultiServerMan API isn't loaded yet!\n" +
"This could be because:\n" +
" a) the MultiServerMan plugin is not installed or it failed to enable\n" +
" b) the plugin in the stacktrace does not declare a dependency on MultiServerMan\n" +
" c) the plugin in the stacktrace is retrieving the API before the plugin 'enable' phase\n" +
" (call the #get method in onEnable, not the constructor!)\n";
NotLoadedException() {
super(MESSAGE);
}
}
}
@@ -0,0 +1,25 @@
package cc.maxmc.msm.api.misc;
import com.google.common.net.HostAndPort;
import org.jetbrains.annotations.Nullable;
@SuppressWarnings("unused") // API
public class ServerInfo {
@Nullable
private final HostAndPort server;
private final int id;
public ServerInfo(@Nullable HostAndPort server, int id) {
this.server = server;
this.id = id;
}
@Nullable
public HostAndPort getServer() {
return server;
}
public int getId() {
return id;
}
}