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,48 +44,31 @@ 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)) {
DataInputStream in = new DataInputStream(new ByteArrayInputStream(message));
if (Configuration.useRedisBungee) { try {
// If we use RedisBungee, we must ignore this channel. String subChannel = in.readUTF();
return;
}
} else if (channel.equals("RedisBungee")) { if (subChannel.equals("PlayerCount")) {
String server = in.readUTF();
if (!Configuration.useRedisBungee) { if (in.available() > 0) {
// Same as above, just the opposite case. int online = in.readInt();
return;
}
} else { BungeeServerInfo serverInfo = BungeeServerTracker.getOrCreateServerInfo(server);
// Not our channels, ignore the message. serverInfo.setOnlinePlayers(online);
return; }
}
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) { } catch (EOFException e) {
// Do nothing. // Do nothing.
} catch (IOException e) { } catch (IOException e) {
// This should never happen. // This should never happen.
e.printStackTrace(); e.printStackTrace();
}
} }
} }