mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-02 14:38:52 +00:00
Added multiple server cluster handling, Closes #15
This commit is contained in:
1 parent
95b762e283
commit
e1a22e29cc
4 files changed
+25
-14
No files matched your search
@@ -17,6 +17,7 @@ public class Settings {
|
||||
|
||||
// Bungee settings
|
||||
boolean doBungee;
|
||||
int clusterID;
|
||||
String server;
|
||||
|
||||
// Data storage settings
|
||||
@@ -84,6 +85,7 @@ public class Settings {
|
||||
|
||||
this.doBungee = configFile.getBoolean("bungee_options.enable_bungee_mode");
|
||||
this.server = configFile.getString("bungee_options.server_id");
|
||||
this.clusterID = configFile.getInt("bungee_options.cluster_id");
|
||||
|
||||
this.storageType = configFile.getString("data_storage_options.storage_type");
|
||||
this.playerDataTable = configFile.getString("data_storage_options.table_names.player_data");
|
||||
@@ -233,6 +235,8 @@ public class Settings {
|
||||
return server;
|
||||
}
|
||||
|
||||
public int getServerClusterID() { return clusterID; }
|
||||
|
||||
public boolean doBungee() {
|
||||
return doBungee;
|
||||
}
|
||||
|
||||
@@ -27,18 +27,6 @@ public class messageManager {
|
||||
|
||||
private static final HuskHomes plugin = HuskHomes.getInstance();
|
||||
|
||||
// Delete the file at the pointer specified
|
||||
private static void deleteFile(File f) {
|
||||
try {
|
||||
if (!f.delete()) {
|
||||
Bukkit.getLogger().severe("Failed to delete messages.yml file!");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Bukkit.getLogger().severe("An error occurred while deleting the messages.yml file!");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
// Create a new file, at the pointer specified
|
||||
private static void createFile(File f) {
|
||||
try {
|
||||
|
||||
@@ -27,13 +27,14 @@ public class pluginMessageHandler implements PluginMessageListener {
|
||||
// Send a plugin message
|
||||
public static void sendPluginMessage(Player sender, String targetPlayerName, String messageType, String messageData) {
|
||||
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
||||
int clusterID = HuskHomes.settings.getServerClusterID();
|
||||
|
||||
// Send a plugin message to the specified player name
|
||||
out.writeUTF("ForwardToPlayer");
|
||||
out.writeUTF(targetPlayerName);
|
||||
|
||||
// Send the HuskHomes message with a specific type
|
||||
out.writeUTF("HuskHomes:" + messageType);
|
||||
out.writeUTF("HuskHomes:" + clusterID + ":" + messageType);
|
||||
ByteArrayOutputStream messageBytes = new ByteArrayOutputStream();
|
||||
DataOutputStream messageOut = new DataOutputStream(messageBytes);
|
||||
|
||||
@@ -61,15 +62,32 @@ public class pluginMessageHandler implements PluginMessageListener {
|
||||
return;
|
||||
}
|
||||
ByteArrayDataInput input = ByteStreams.newDataInput(message);
|
||||
|
||||
// Plugin messages are formatted as such:
|
||||
// HuskHomes:<cluster_id>:<message_type>, followed by the message arguments and data.
|
||||
String messageType = input.readUTF();
|
||||
int clusterID;
|
||||
|
||||
// Return if the message was not sent by HuskHomes
|
||||
if (!messageType.contains("HuskHomes:")) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Ensure the cluster ID matches
|
||||
try {
|
||||
clusterID = Integer.parseInt(messageType.split(":")[1]);
|
||||
} catch (Exception e) {
|
||||
// In case the message is malformed or the cluster ID is invalid
|
||||
Bukkit.getLogger().warning("Received a HuskHomes plugin message with an invalid server cluster ID! \n" +
|
||||
"Please ensure you are running the latest version of HuskHomes on all your servers and that the cluster ID is set to a valid integer on all of them.");
|
||||
return;
|
||||
}
|
||||
if (HuskHomes.settings.getServerClusterID() != clusterID) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Get the HuskHomes message type
|
||||
messageType = messageType.split(":")[1];
|
||||
messageType = messageType.split(":")[2];
|
||||
|
||||
// Get the message data packets
|
||||
String messageData = "";
|
||||
|
||||
Reference in new issue
Block a user