mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-04 06:28:49 +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
|
// Bungee settings
|
||||||
boolean doBungee;
|
boolean doBungee;
|
||||||
|
int clusterID;
|
||||||
String server;
|
String server;
|
||||||
|
|
||||||
// Data storage settings
|
// Data storage settings
|
||||||
@@ -84,6 +85,7 @@ public class Settings {
|
|||||||
|
|
||||||
this.doBungee = configFile.getBoolean("bungee_options.enable_bungee_mode");
|
this.doBungee = configFile.getBoolean("bungee_options.enable_bungee_mode");
|
||||||
this.server = configFile.getString("bungee_options.server_id");
|
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.storageType = configFile.getString("data_storage_options.storage_type");
|
||||||
this.playerDataTable = configFile.getString("data_storage_options.table_names.player_data");
|
this.playerDataTable = configFile.getString("data_storage_options.table_names.player_data");
|
||||||
@@ -233,6 +235,8 @@ public class Settings {
|
|||||||
return server;
|
return server;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getServerClusterID() { return clusterID; }
|
||||||
|
|
||||||
public boolean doBungee() {
|
public boolean doBungee() {
|
||||||
return doBungee;
|
return doBungee;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,18 +27,6 @@ public class messageManager {
|
|||||||
|
|
||||||
private static final HuskHomes plugin = HuskHomes.getInstance();
|
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
|
// Create a new file, at the pointer specified
|
||||||
private static void createFile(File f) {
|
private static void createFile(File f) {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -27,13 +27,14 @@ public class pluginMessageHandler implements PluginMessageListener {
|
|||||||
// Send a plugin message
|
// Send a plugin message
|
||||||
public static void sendPluginMessage(Player sender, String targetPlayerName, String messageType, String messageData) {
|
public static void sendPluginMessage(Player sender, String targetPlayerName, String messageType, String messageData) {
|
||||||
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
||||||
|
int clusterID = HuskHomes.settings.getServerClusterID();
|
||||||
|
|
||||||
// Send a plugin message to the specified player name
|
// Send a plugin message to the specified player name
|
||||||
out.writeUTF("ForwardToPlayer");
|
out.writeUTF("ForwardToPlayer");
|
||||||
out.writeUTF(targetPlayerName);
|
out.writeUTF(targetPlayerName);
|
||||||
|
|
||||||
// Send the HuskHomes message with a specific type
|
// Send the HuskHomes message with a specific type
|
||||||
out.writeUTF("HuskHomes:" + messageType);
|
out.writeUTF("HuskHomes:" + clusterID + ":" + messageType);
|
||||||
ByteArrayOutputStream messageBytes = new ByteArrayOutputStream();
|
ByteArrayOutputStream messageBytes = new ByteArrayOutputStream();
|
||||||
DataOutputStream messageOut = new DataOutputStream(messageBytes);
|
DataOutputStream messageOut = new DataOutputStream(messageBytes);
|
||||||
|
|
||||||
@@ -61,15 +62,32 @@ public class pluginMessageHandler implements PluginMessageListener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ByteArrayDataInput input = ByteStreams.newDataInput(message);
|
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();
|
String messageType = input.readUTF();
|
||||||
|
int clusterID;
|
||||||
|
|
||||||
// Return if the message was not sent by HuskHomes
|
// Return if the message was not sent by HuskHomes
|
||||||
if (!messageType.contains("HuskHomes:")) {
|
if (!messageType.contains("HuskHomes:")) {
|
||||||
return;
|
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
|
// Get the HuskHomes message type
|
||||||
messageType = messageType.split(":")[1];
|
messageType = messageType.split(":")[2];
|
||||||
|
|
||||||
// Get the message data packets
|
// Get the message data packets
|
||||||
String messageData = "";
|
String messageData = "";
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ general:
|
|||||||
bungee_options:
|
bungee_options:
|
||||||
enable_bungee_mode: false
|
enable_bungee_mode: false
|
||||||
server_id: 'server'
|
server_id: 'server'
|
||||||
|
cluster_id: 0
|
||||||
enable_warp_command: true
|
enable_warp_command: true
|
||||||
spawn_command:
|
spawn_command:
|
||||||
enabled: true
|
enabled: true
|
||||||
|
|||||||
Reference in new issue
Block a user