mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-04 14:38:53 +00:00
Fixed some issues, working towards implementing the cross-server list system (#19)
This commit is contained in:
1 parent
da30aa9076
commit
8de5e954b3
3 files changed
+54
-12
No files matched your search
@@ -33,8 +33,15 @@ public class CrossServerListHandler {
|
|||||||
playerList.put(server, players);
|
playerList.put(server, players);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void requestHashsetUpdate(Player player) {
|
public static void updatePlayerList(Player p) {
|
||||||
playerList.clear();
|
playerList.clear();
|
||||||
PluginMessageHandler.requestPlayerLists(player);
|
if (p == null) {
|
||||||
|
for (Player x : Bukkit.getOnlinePlayers()) {
|
||||||
|
p = x;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (p != null) {
|
||||||
|
PluginMessageHandler.requestPlayerLists(p);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -74,7 +74,7 @@ public class PluginMessageHandler implements PluginMessageListener {
|
|||||||
out.writeUTF("ONLINE");
|
out.writeUTF("ONLINE");
|
||||||
|
|
||||||
// Send the HuskHomes message with a specific type
|
// Send the HuskHomes message with a specific type
|
||||||
out.writeUTF("HuskHomes:" + clusterID + ":send_online_players");
|
out.writeUTF("HuskHomes:" + clusterID + ":get_online_players");
|
||||||
ByteArrayOutputStream messageBytes = new ByteArrayOutputStream();
|
ByteArrayOutputStream messageBytes = new ByteArrayOutputStream();
|
||||||
DataOutputStream messageOut = new DataOutputStream(messageBytes);
|
DataOutputStream messageOut = new DataOutputStream(messageBytes);
|
||||||
|
|
||||||
@@ -100,12 +100,44 @@ public class PluginMessageHandler implements PluginMessageListener {
|
|||||||
sender.sendPluginMessage(plugin, "BungeeCord", out.toByteArray());
|
sender.sendPluginMessage(plugin, "BungeeCord", out.toByteArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void sendPlayerLists(Player sender) {
|
// Sends a plugin message informing other servers the player list needs updating
|
||||||
sendPlayerList(null, sender);
|
public static void broadcastPlayerChange(Player sender) {
|
||||||
|
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
||||||
|
int clusterID = HuskHomes.getSettings().getServerClusterID();
|
||||||
|
|
||||||
|
// Send a plugin message to the specified player name
|
||||||
|
out.writeUTF("Forward");
|
||||||
|
out.writeUTF("ONLINE");
|
||||||
|
|
||||||
|
// Send the HuskHomes message with a specific type
|
||||||
|
out.writeUTF("HuskHomes:" + clusterID + ":player_change");
|
||||||
|
ByteArrayOutputStream messageBytes = new ByteArrayOutputStream();
|
||||||
|
DataOutputStream messageOut = new DataOutputStream(messageBytes);
|
||||||
|
|
||||||
|
// Send the message data; output an exception if there's an error
|
||||||
|
try {
|
||||||
|
messageOut.writeUTF(HuskHomes.getSettings().getServerID());
|
||||||
|
} catch (IOException e) {
|
||||||
|
Bukkit.getLogger().warning("An error occurred trying to send a plugin message (" + e.getCause() + ")");
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Write the messages to the output packet
|
||||||
|
out.writeShort(messageBytes.toByteArray().length);
|
||||||
|
out.write(messageBytes.toByteArray());
|
||||||
|
|
||||||
|
// Send the constructed plugin message packet
|
||||||
|
if (sender == null) {
|
||||||
|
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||||
|
sender = p;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sender.sendPluginMessage(plugin, "BungeeCord", out.toByteArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sends a plugin message with player list
|
// Sends a plugin message with player list
|
||||||
public static void sendPlayerList(String returnTo, Player sender) {
|
public static void returnPlayerList(String returnTo, Player sender) {
|
||||||
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
||||||
int clusterID = HuskHomes.getSettings().getServerClusterID();
|
int clusterID = HuskHomes.getSettings().getServerClusterID();
|
||||||
|
|
||||||
@@ -248,9 +280,9 @@ public class PluginMessageHandler implements PluginMessageListener {
|
|||||||
case "teleport_to_me":
|
case "teleport_to_me":
|
||||||
TeleportManager.teleportPlayer(recipient, messageData);
|
TeleportManager.teleportPlayer(recipient, messageData);
|
||||||
break;
|
break;
|
||||||
case "send_online_players":
|
case "get_online_players":
|
||||||
if (Bukkit.getOnlinePlayers().size() > 0) {
|
if (Bukkit.getOnlinePlayers().size() > 0) {
|
||||||
sendPlayerList(messageData, recipient);
|
returnPlayerList(messageData, recipient);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "return_online_players":
|
case "return_online_players":
|
||||||
@@ -259,6 +291,9 @@ public class PluginMessageHandler implements PluginMessageListener {
|
|||||||
HashSet<String> playerList = new HashSet<>(Arrays.asList(players.split(",")));
|
HashSet<String> playerList = new HashSet<>(Arrays.asList(players.split(",")));
|
||||||
CrossServerListHandler.updateHashset(server, playerList);
|
CrossServerListHandler.updateHashset(server, playerList);
|
||||||
break;
|
break;
|
||||||
|
case "player_change":
|
||||||
|
CrossServerListHandler.updatePlayerList(null);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -71,8 +71,8 @@ public class PlayerListener implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Update player lists globally
|
// Update player lists globally
|
||||||
CrossServerListHandler.requestHashsetUpdate(p);
|
CrossServerListHandler.updatePlayerList(p);
|
||||||
PluginMessageHandler.sendPlayerLists(p);
|
PluginMessageHandler.broadcastPlayerChange(p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,8 +82,8 @@ public class PlayerListener implements Listener {
|
|||||||
// Update player lists globally
|
// Update player lists globally
|
||||||
Player p = e.getPlayer();
|
Player p = e.getPlayer();
|
||||||
|
|
||||||
CrossServerListHandler.requestHashsetUpdate(p);
|
CrossServerListHandler.updatePlayerList(p);
|
||||||
PluginMessageHandler.sendPlayerLists(p);
|
PluginMessageHandler.broadcastPlayerChange(p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user