mirror of
https://github.com/proxiodev/RedisBungee.git
synced 2025-04-20 01:27:07 +00:00
Fix UUIDTranslator bug, add UUID null checking, make plugin messaging asynchronous
This commit is contained in:
parent
c82adc61b0
commit
4aeb762c17
@ -102,7 +102,12 @@ class RedisBungeeCommands {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (args.length > 0) {
|
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) {
|
if (si != null) {
|
||||||
TextComponent message = new TextComponent();
|
TextComponent message = new TextComponent();
|
||||||
message.setColor(ChatColor.BLUE);
|
message.setColor(ChatColor.BLUE);
|
||||||
@ -133,7 +138,12 @@ class RedisBungeeCommands {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (args.length > 0) {
|
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();
|
TextComponent message = new TextComponent();
|
||||||
if (secs == 0) {
|
if (secs == 0) {
|
||||||
message.setColor(ChatColor.GREEN);
|
message.setColor(ChatColor.GREEN);
|
||||||
@ -170,7 +180,12 @@ class RedisBungeeCommands {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (args.length > 0) {
|
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) {
|
if (ia != null) {
|
||||||
TextComponent message = new TextComponent();
|
TextComponent message = new TextComponent();
|
||||||
message.setColor(ChatColor.GREEN);
|
message.setColor(ChatColor.GREEN);
|
||||||
|
@ -22,10 +22,7 @@ import net.md_5.bungee.api.plugin.Listener;
|
|||||||
import net.md_5.bungee.event.EventHandler;
|
import net.md_5.bungee.event.EventHandler;
|
||||||
import redis.clients.jedis.Jedis;
|
import redis.clients.jedis.Jedis;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.*;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class RedisBungeeListener implements Listener {
|
public class RedisBungeeListener implements Listener {
|
||||||
@ -87,60 +84,66 @@ public class RedisBungeeListener implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPluginMessage(PluginMessageEvent event) {
|
public void onPluginMessage(final PluginMessageEvent event) {
|
||||||
if (event.getTag().equals("RedisBungee") && event.getSender() instanceof Server) {
|
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();
|
String subchannel = in.readUTF();
|
||||||
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
||||||
String type;
|
String type;
|
||||||
|
|
||||||
switch (subchannel) {
|
switch (subchannel) {
|
||||||
case "PlayerList":
|
case "PlayerList":
|
||||||
out.writeUTF("Players");
|
out.writeUTF("Players");
|
||||||
Set<UUID> original = Collections.emptySet();
|
Set<UUID> original = Collections.emptySet();
|
||||||
type = in.readUTF();
|
type = in.readUTF();
|
||||||
if (type.equals("ALL")) {
|
if (type.equals("ALL")) {
|
||||||
out.writeUTF("ALL");
|
out.writeUTF("ALL");
|
||||||
original = plugin.getPlayers();
|
original = plugin.getPlayers();
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
original = plugin.getPlayersOnServer(type);
|
original = plugin.getPlayersOnServer(type);
|
||||||
} catch (IllegalArgumentException ignored) {
|
} 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());
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ public class UUIDTranslator {
|
|||||||
if (stored != null && UUID_PATTERN.matcher(stored).find()) {
|
if (stored != null && UUID_PATTERN.matcher(stored).find()) {
|
||||||
// This is it!
|
// This is it!
|
||||||
uuid = UUID.fromString(stored);
|
uuid = UUID.fromString(stored);
|
||||||
uuidMap.put(stored, UUID.fromString(stored));
|
uuidMap.put(player, UUID.fromString(stored));
|
||||||
return uuid;
|
return uuid;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,7 +55,7 @@ public class UUIDTranslator {
|
|||||||
uuid = UUIDFetcher.getUUIDOf(player);
|
uuid = UUIDFetcher.getUUIDOf(player);
|
||||||
|
|
||||||
if (uuid != null) {
|
if (uuid != null) {
|
||||||
uuidMap.put(stored, uuid);
|
uuidMap.put(player, uuid);
|
||||||
jedis.hset("uuids", player, uuid.toString());
|
jedis.hset("uuids", player, uuid.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user