2
0
mirror of https://github.com/proxiodev/RedisBungee.git synced 2024-11-22 20:28:00 +00:00

Fix UUIDTranslator bug, add UUID null checking, make plugin messaging asynchronous

This commit is contained in:
Tux 2014-04-20 10:50:45 -04:00
parent c82adc61b0
commit 4aeb762c17
3 changed files with 76 additions and 58 deletions

View File

@ -102,7 +102,12 @@ class RedisBungeeCommands {
@Override
public void run() {
if (args.length > 0) {
ServerInfo si = RedisBungee.getApi().getServerFor(plugin.getUuidTranslator().getTranslatedUuid(args[0]));
UUID uuid = plugin.getUuidTranslator().getTranslatedUuid(args[0]);
if (uuid == null) {
sender.sendMessage(PLAYER_NOT_FOUND);
return;
}
ServerInfo si = RedisBungee.getApi().getServerFor(uuid);
if (si != null) {
TextComponent message = new TextComponent();
message.setColor(ChatColor.BLUE);
@ -133,7 +138,12 @@ class RedisBungeeCommands {
@Override
public void run() {
if (args.length > 0) {
long secs = RedisBungee.getApi().getLastOnline(plugin.getUuidTranslator().getTranslatedUuid(args[0]));
UUID uuid = plugin.getUuidTranslator().getTranslatedUuid(args[0]);
if (uuid == null) {
sender.sendMessage(PLAYER_NOT_FOUND);
return;
}
long secs = RedisBungee.getApi().getLastOnline(uuid);
TextComponent message = new TextComponent();
if (secs == 0) {
message.setColor(ChatColor.GREEN);
@ -170,7 +180,12 @@ class RedisBungeeCommands {
@Override
public void run() {
if (args.length > 0) {
InetAddress ia = RedisBungee.getApi().getPlayerIp(plugin.getUuidTranslator().getTranslatedUuid(args[0]));
UUID uuid = plugin.getUuidTranslator().getTranslatedUuid(args[0]);
if (uuid == null) {
sender.sendMessage(PLAYER_NOT_FOUND);
return;
}
InetAddress ia = RedisBungee.getApi().getPlayerIp(uuid);
if (ia != null) {
TextComponent message = new TextComponent();
message.setColor(ChatColor.GREEN);

View File

@ -22,10 +22,7 @@ import net.md_5.bungee.api.plugin.Listener;
import net.md_5.bungee.event.EventHandler;
import redis.clients.jedis.Jedis;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import java.util.*;
@AllArgsConstructor
public class RedisBungeeListener implements Listener {
@ -87,60 +84,66 @@ public class RedisBungeeListener implements Listener {
}
@EventHandler
public void onPluginMessage(PluginMessageEvent event) {
public void onPluginMessage(final PluginMessageEvent event) {
if (event.getTag().equals("RedisBungee") && event.getSender() instanceof Server) {
ByteArrayDataInput in = ByteStreams.newDataInput(event.getData());
final byte[] data = Arrays.copyOf(event.getData(), event.getData().length);
plugin.getProxy().getScheduler().runAsync(plugin, new Runnable() {
@Override
public void run() {
ByteArrayDataInput in = ByteStreams.newDataInput(data);
String subchannel = in.readUTF();
ByteArrayDataOutput out = ByteStreams.newDataOutput();
String type;
String subchannel = in.readUTF();
ByteArrayDataOutput out = ByteStreams.newDataOutput();
String type;
switch (subchannel) {
case "PlayerList":
out.writeUTF("Players");
Set<UUID> original = Collections.emptySet();
type = in.readUTF();
if (type.equals("ALL")) {
out.writeUTF("ALL");
original = plugin.getPlayers();
} else {
try {
original = plugin.getPlayersOnServer(type);
} catch (IllegalArgumentException ignored) {
}
switch (subchannel) {
case "PlayerList":
out.writeUTF("Players");
Set<UUID> original = Collections.emptySet();
type = in.readUTF();
if (type.equals("ALL")) {
out.writeUTF("ALL");
original = plugin.getPlayers();
} else {
try {
original = plugin.getPlayersOnServer(type);
} catch (IllegalArgumentException ignored) {
}
}
Set<String> players = new HashSet<>();
for (UUID uuid : original)
players.add(plugin.getUuidTranslator().getNameFromUuid(uuid));
out.writeUTF(Joiner.on(',').join(players));
break;
case "PlayerCount":
out.writeUTF("PlayerCount");
type = in.readUTF();
if (type.equals("ALL")) {
out.writeUTF("ALL");
out.writeInt(plugin.getCount());
} else {
out.writeUTF(type);
try {
out.writeInt(plugin.getPlayersOnServer(type).size());
} catch (IllegalArgumentException e) {
out.writeInt(0);
}
}
out.writeInt(plugin.getCurrentCount());
break;
case "LastOnline":
String user = in.readUTF();
out.writeUTF("LastOnline");
out.writeUTF(user);
out.writeLong(plugin.getLastOnline(plugin.getUuidTranslator().getTranslatedUuid(user)));
break;
default:
break;
}
Set<String> players = new HashSet<>();
for (UUID uuid : original)
players.add(plugin.getUuidTranslator().getNameFromUuid(uuid));
out.writeUTF(Joiner.on(',').join(players));
break;
case "PlayerCount":
out.writeUTF("PlayerCount");
type = in.readUTF();
if (type.equals("ALL")) {
out.writeUTF("ALL");
out.writeInt(plugin.getCount());
} else {
out.writeUTF(type);
try {
out.writeInt(plugin.getPlayersOnServer(type).size());
} catch (IllegalArgumentException e) {
out.writeInt(0);
}
}
out.writeInt(plugin.getCurrentCount());
break;
case "LastOnline":
String user = in.readUTF();
out.writeUTF("LastOnline");
out.writeUTF(user);
out.writeLong(plugin.getLastOnline(plugin.getUuidTranslator().getTranslatedUuid(user)));
break;
default:
break;
}
((Server) event.getSender()).sendData("RedisBungee", out.toByteArray());
((Server) event.getSender()).sendData("RedisBungee", out.toByteArray());
}
});
}
}

View File

@ -47,7 +47,7 @@ public class UUIDTranslator {
if (stored != null && UUID_PATTERN.matcher(stored).find()) {
// This is it!
uuid = UUID.fromString(stored);
uuidMap.put(stored, UUID.fromString(stored));
uuidMap.put(player, UUID.fromString(stored));
return uuid;
}
@ -55,7 +55,7 @@ public class UUIDTranslator {
uuid = UUIDFetcher.getUUIDOf(player);
if (uuid != null) {
uuidMap.put(stored, uuid);
uuidMap.put(player, uuid);
jedis.hset("uuids", player, uuid.toString());
}