From 7496bf8d4d6b7d8f5e10752e3bd547b90d9a0be7 Mon Sep 17 00:00:00 2001 From: Drc-DEV <33911680+Drc-DEV@users.noreply.github.com> Date: Wed, 16 Oct 2019 19:33:42 +0200 Subject: [PATCH] Actually fix RedisBungee channel for 1.13+ --- .../bridge/bungeecord/BungeeChannel.java | 43 ++++++++++--------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/Plugin/src/main/java/com/gmail/filoghost/holographicdisplays/bridge/bungeecord/BungeeChannel.java b/Plugin/src/main/java/com/gmail/filoghost/holographicdisplays/bridge/bungeecord/BungeeChannel.java index dfeeacda..335ea6ae 100644 --- a/Plugin/src/main/java/com/gmail/filoghost/holographicdisplays/bridge/bungeecord/BungeeChannel.java +++ b/Plugin/src/main/java/com/gmail/filoghost/holographicdisplays/bridge/bungeecord/BungeeChannel.java @@ -3,12 +3,12 @@ * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ @@ -36,48 +36,47 @@ import com.gmail.filoghost.holographicdisplays.util.NMSVersion; public class BungeeChannel implements PluginMessageListener { private static BungeeChannel instance; - + public static BungeeChannel getInstance() { if (instance == null) { instance = new BungeeChannel(HolographicDisplays.getInstance()); } return instance; } - + private BungeeChannel(Plugin plugin) { Bukkit.getMessenger().registerOutgoingPluginChannel(plugin, "BungeeCord"); Bukkit.getMessenger().registerIncomingPluginChannel(plugin, "BungeeCord", this); - - if (NMSVersion.isGreaterEqualThan(NMSVersion.v1_13_R1)) { - Bukkit.getMessenger().registerOutgoingPluginChannel(plugin, "legacy:redisbungee"); - Bukkit.getMessenger().registerIncomingPluginChannel(plugin, "legacy:redisbungee", this); - } else { - Bukkit.getMessenger().registerOutgoingPluginChannel(plugin, "RedisBungee"); - Bukkit.getMessenger().registerIncomingPluginChannel(plugin, "RedisBungee", this); - } + + String targetChannel = "RedisBungee"; + if (NMSVersion.isGreaterEqualThan(NMSVersion.v1_13_R1)) targetChannel = "legacy:redisbungee"; + + Bukkit.getMessenger().registerOutgoingPluginChannel(plugin, targetChannel); + Bukkit.getMessenger().registerIncomingPluginChannel(plugin, targetChannel, this); + } @Override public void onPluginMessageReceived(String channel, Player player, byte[] message) { String targetChannel = Configuration.useRedisBungee ? "RedisBungee" : "BungeeCord"; - + if (targetChannel.equalsIgnoreCase("RedisBungee") && NMSVersion.isGreaterEqualThan(NMSVersion.v1_13_R1)) targetChannel = "legacy:redisbungee"; if (channel.equals(targetChannel)) { DataInputStream in = new DataInputStream(new ByteArrayInputStream(message)); - + try { String subChannel = in.readUTF(); - + if (subChannel.equals("PlayerCount")) { String server = in.readUTF(); - + if (in.available() > 0) { int online = in.readInt(); - + BungeeServerInfo serverInfo = BungeeServerTracker.getOrCreateServerInfo(server); serverInfo.setOnlinePlayers(online); } } - + } catch (EOFException e) { // Do nothing. } catch (IOException e) { @@ -86,8 +85,8 @@ public class BungeeChannel implements PluginMessageListener { } } } - - + + public void askPlayerCount(String server) { ByteArrayOutputStream b = new ByteArrayOutputStream(); DataOutputStream out = new DataOutputStream(b); @@ -103,7 +102,9 @@ public class BungeeChannel implements PluginMessageListener { // OR, if you don't need to send it to a specific player Collection players = Bukkit.getOnlinePlayers(); if (players.size() > 0) { - players.iterator().next().sendPluginMessage(HolographicDisplays.getInstance(), Configuration.useRedisBungee ? "RedisBungee" : "BungeeCord", b.toByteArray()); + String targetChannel = Configuration.useRedisBungee ? "RedisBungee" : "BungeeCord"; + if (targetChannel.equalsIgnoreCase("RedisBungee") && NMSVersion.isGreaterEqualThan(NMSVersion.v1_13_R1)) targetChannel = "legacy:redisbungee"; + players.iterator().next().sendPluginMessage(HolographicDisplays.getInstance(), targetChannel, b.toByteArray()); } } }