mirror of
https://github.com/filoghost/HolographicDisplays.git
synced 2024-12-20 07:47:38 +01:00
Improve code readability
This commit is contained in:
parent
e4ece4dc80
commit
137d23b408
@ -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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user