Improve code readability

This commit is contained in:
filoghost 2018-08-31 14:23:51 +02:00
parent e4ece4dc80
commit 137d23b408

View File

@ -30,7 +30,7 @@ public class BungeeChannel implements PluginMessageListener {
return instance; return instance;
} }
public BungeeChannel(Plugin plugin) { private BungeeChannel(Plugin plugin) {
Bukkit.getMessenger().registerOutgoingPluginChannel(plugin, "BungeeCord"); Bukkit.getMessenger().registerOutgoingPluginChannel(plugin, "BungeeCord");
Bukkit.getMessenger().registerIncomingPluginChannel(plugin, "BungeeCord", this); Bukkit.getMessenger().registerIncomingPluginChannel(plugin, "BungeeCord", this);
@ -44,33 +44,15 @@ public class BungeeChannel implements PluginMessageListener {
@Override @Override
public void onPluginMessageReceived(String channel, Player player, byte[] message) { public void onPluginMessageReceived(String channel, Player player, byte[] message) {
String targetChannel = Configuration.useRedisBungee ? "RedisBungee" : "BungeeCord";
if (channel.equals("BungeeCord")) { if (channel.equals(targetChannel)) {
if (Configuration.useRedisBungee) {
// If we use RedisBungee, we must ignore this channel.
return;
}
} else if (channel.equals("RedisBungee")) {
if (!Configuration.useRedisBungee) {
// Same as above, just the opposite case.
return;
}
} else {
// Not our channels, ignore the message.
return;
}
DataInputStream in = new DataInputStream(new ByteArrayInputStream(message)); DataInputStream in = new DataInputStream(new ByteArrayInputStream(message));
try { try {
String subChannel = in.readUTF(); String subChannel = in.readUTF();
if (subChannel.equals("PlayerCount")) { if (subChannel.equals("PlayerCount")) {
String server = in.readUTF(); String server = in.readUTF();
if (in.available() > 0) { if (in.available() > 0) {
@ -88,6 +70,7 @@ public class BungeeChannel implements PluginMessageListener {
e.printStackTrace(); e.printStackTrace();
} }
} }
}
public void askPlayerCount(String server) { public void askPlayerCount(String server) {