Skip to content
This repository has been archived by the owner on Jun 21, 2024. It is now read-only.

Commit

Permalink
Actually fix RedisBungee channel for 1.13+
Browse files Browse the repository at this point in the history
  • Loading branch information
Drc-DEV authored and filoghost committed Oct 16, 2019
1 parent 8c09806 commit 7496bf8
Showing 1 changed file with 22 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://www.gnu.org/licenses/>.
*/
Expand Down Expand Up @@ -36,48 +36,47 @@
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";

This comment has been minimized.

Copy link
@Elecast2

Elecast2 Mar 30, 2020

change this to String targetChannel = "legacy:redisbungee";

if (NMSVersion.isGreaterEqualThan(NMSVersion.v1_13_R1)) targetChannel = "legacy:redisbungee";

This comment has been minimized.

Copy link
@Elecast2

Elecast2 Mar 30, 2020

remove this


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) {
Expand All @@ -86,8 +85,8 @@ public void onPluginMessageReceived(String channel, Player player, byte[] messag
}
}
}


public void askPlayerCount(String server) {
ByteArrayOutputStream b = new ByteArrayOutputStream();
DataOutputStream out = new DataOutputStream(b);
Expand All @@ -103,7 +102,9 @@ public void askPlayerCount(String server) {
// OR, if you don't need to send it to a specific player
Collection<? extends Player> 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());
}
}
}

4 comments on commit 7496bf8

@Elecast2
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, there are still problems with this if the server is older than 1.13 version, but uses viaversion to support newer version. My suggestion is to only keep "legacy:redisbungee" instead of checking the nms version, "legacy:redisbungee" will work with any spigot version since it is only a bungee side channel.

I made custom plugins that uses this channel on 1.8 server and viaversion with no problem,

@filoghost
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can see here that it checks if the tag is equal to legacy:RedisBungee. Will this be a problem, since on Spigot you can only register the channel legacy:redisbungee (all lowercase)?

@Elecast2
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, there are moments where placeholders that shows server playercount using redisbungee just freeze up

@filoghost
Copy link
Owner

@filoghost filoghost commented on 7496bf8 Apr 18, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's an issue already open for RedisBungee: minecrafter/RedisBungee#71

In the meanwhile, I changed it to always use legacy:redisbungee: 636b7d4

Please sign in to comment.