Remove redundant HuskHomes item in redis message headers

This commit is contained in:
William committed 2021-10-02 21:53:18 +01:00
1 parent 4cdb39ba65
commit b026fbcd0a
3 files changed
+12 -14

No files matched your search

+1 -1
View File
@@ -6,7 +6,7 @@
<groupId>me.William278</groupId> <groupId>me.William278</groupId>
<artifactId>HuskHomes</artifactId> <artifactId>HuskHomes</artifactId>
<version>2.8.2</version> <version>2.9</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>HuskHomes</name> <name>HuskHomes</name>
@@ -30,7 +30,7 @@ public class RedisMessage extends Message {
publisher.auth(jedisPassword); publisher.auth(jedisPassword);
} }
publisher.connect(); publisher.connect();
publisher.publish(RedisReceiver.REDIS_CHANNEL, "HuskHomes:" + getClusterId() + ":" + getPluginMessageString(getMessageType()) + ":" + target); publisher.publish(RedisReceiver.REDIS_CHANNEL, getClusterId() + ":" + getPluginMessageString(getMessageType()) + ":" + target);
} }
}); });
} }
@@ -38,23 +38,18 @@ public class RedisReceiver {
return; return;
} }
// Redis messages are formatted as such: /* HuskHomes Redis messages have a header formatted as such:
// HuskHomes:<cluster_id>:<message_type>:<target_player>£ followed by the message arguments and data. * <cluster_id>:<message_type>:<target_player>£ followed by the message arguments and data. */
final String[] splitMessage = message.split("£"); final String[] splitMessage = message.split("£");
final String messageType = splitMessage[0]; final String messageHeader = splitMessage[0];
int clusterID; int clusterID;
// Return if the message was not sent by HuskHomes
if (!messageType.contains("HuskHomes:")) {
return;
}
// Ensure the cluster ID matches // Ensure the cluster ID matches
try { try {
clusterID = Integer.parseInt(messageType.split(":")[1]); clusterID = Integer.parseInt(messageHeader.split(":")[0]);
} catch (Exception e) { } catch (Exception e) {
// In case the message is malformed or the cluster ID is invalid // In case the message is malformed or the cluster ID is invalid
HuskHomes.getInstance().getLogger().warning("Received a HuskHomes redis message with an invalid server Cluster ID! \n" + HuskHomes.getInstance().getLogger().warning("Received a Redis message on the HuskHomes channel with an invalid server Cluster ID! \n" +
"Please ensure that the cluster ID is set to a valid integer on all servers."); "Please ensure that the cluster ID is set to a valid integer on all servers.");
return; return;
} }
@@ -62,8 +57,11 @@ public class RedisReceiver {
return; return;
} }
// Get the type of redis message
final String messageType = messageHeader.split(":")[1];
// Get the player targeted by the message and make sure they are online // Get the player targeted by the message and make sure they are online
final String target = messageType.split(":")[3]; final String target = messageHeader.split(":")[2];
Player receiver = Bukkit.getPlayerExact(target); Player receiver = Bukkit.getPlayerExact(target);
// If the redis message was targeting this server // If the redis message was targeting this server
@@ -86,7 +84,7 @@ public class RedisReceiver {
} }
final String messageData = splitMessage[1]; final String messageData = splitMessage[1];
CrossServerMessageHandler.handlePluginMessage(new PluginMessage(clusterID, receiver.getName(), messageType.split(":")[2], messageData), receiver); CrossServerMessageHandler.handlePluginMessage(new RedisMessage(clusterID, receiver.getName(), messageType, messageData), receiver);
} }
}, REDIS_CHANNEL), "Redis Subscriber").start(); }, REDIS_CHANNEL), "Redis Subscriber").start();
} }