This commit is contained in:
zhangyuheng 2024-06-26 11:14:21 +08:00
parent 90245ce5b6
commit 8675d15e25
2 changed files with 95 additions and 0 deletions

View File

@ -0,0 +1,38 @@
package cn.lunadeer.dominion.dtos;
import cn.lunadeer.minecraftpluginutils.databse.Field;
import cn.lunadeer.minecraftpluginutils.databse.FieldType;
import cn.lunadeer.minecraftpluginutils.databse.TableColumn;
import cn.lunadeer.minecraftpluginutils.databse.syntax.CreateTable;
import com.alibaba.fastjson.JSONObject;
import com.google.common.io.ByteArrayDataOutput;
import com.google.common.io.ByteStreams;
public class ServerInfoDTO {
private final Field id = new Field("id", FieldType.INT);
private final Field name = new Field("name", FieldType.STRING);
private final Field uuid = new Field("uuid", FieldType.STRING);
private void initTable() {
TableColumn server_info_id = new TableColumn("id", FieldType.INT, true, true, true, true, 0);
TableColumn server_info_name = new TableColumn("name", FieldType.STRING, false, false, true, true, "server");
TableColumn server_info_uuid = new TableColumn("uuid", FieldType.STRING, false, false, true, true, "00000000-0000-0000-0000-000000000000");
CreateTable privilege_template = new CreateTable().ifNotExists();
privilege_template.table("server_info")
.field(server_info_id)
.field(server_info_name)
.field(server_info_uuid);
privilege_template.execute();
}
public static void initServerInfo() {
ByteArrayDataOutput out = ByteStreams.newDataOutput();
out.writeUTF("GetServer");
JSONObject json = new JSONObject();
}
}

View File

@ -0,0 +1,57 @@
package cn.lunadeer.dominion.managers;
import cn.lunadeer.dominion.dtos.ServerInfoDTO;
import com.google.common.io.ByteArrayDataInput;
import com.google.common.io.ByteStreams;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.plugin.messaging.PluginMessageListener;
import org.jetbrains.annotations.NotNull;
import java.io.File;
import java.util.HashMap;
import java.util.Map;
public class GlobalTeleport implements PluginMessageListener {
public static GlobalTeleport instance;
private final JavaPlugin plugin;
private final File infoFile;
private ServerInfoDTO thisServerInfo;
private Map<Integer, ServerInfoDTO> allServerInfo = new HashMap<>();
public GlobalTeleport(JavaPlugin plugin) {
this.plugin = plugin;
this.plugin.getServer().getMessenger().registerOutgoingPluginChannel(this.plugin, "BungeeCord");
this.plugin.getServer().getMessenger().registerIncomingPluginChannel(this.plugin, "BungeeCord", this);
this.infoFile = new File(plugin.getDataFolder(), "server_info.json");
instance = this;
if (!infoFile.exists()) {
ServerInfoDTO.initServerInfo();
}
// todo load & update info
}
/**
* A method that will be thrown when a PluginMessageSource sends a plugin
* message on a registered channel.
*
* @param channel Channel that the message was sent through.
* @param player Source of the message.
* @param message The raw message that was sent.
*/
@Override
public void onPluginMessageReceived(@NotNull String channel, @NotNull Player player, @NotNull byte[] message) {
if (!channel.equals("BungeeCord")) {
return;
}
ByteArrayDataInput in = ByteStreams.newDataInput(message);
String subchannel = in.readUTF();
if (subchannel.equals("SomeSubChannel")) {
// 使用下文中的"返回Response"一节的代码进行读取
// 数据处理
}
}
}