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,9 +84,13 @@ 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();
|
||||||
@ -142,6 +143,8 @@ public class RedisBungeeListener implements Listener {
|
|||||||
|
|
||||||
((Server) event.getSender()).sendData("RedisBungee", out.toByteArray());
|
((Server) event.getSender()).sendData("RedisBungee", out.toByteArray());
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
|
@ -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