mirror of
https://github.com/proxiodev/RedisBungee.git
synced 2024-11-22 20:28:00 +00:00
rename listener classes depending on the platform, readd plugin message back #38
This commit is contained in:
parent
cd4f2aded4
commit
ceef1f5184
@ -26,10 +26,10 @@ import redis.clients.jedis.Pipeline;
|
||||
import java.net.InetAddress;
|
||||
import java.util.*;
|
||||
|
||||
public class RedisBungeeListener extends AbstractRedisBungeeListener<LoginEvent, PostLoginEvent, PlayerDisconnectEvent, ServerConnectedEvent, ProxyPingEvent, PluginMessageEvent, PubSubMessageEvent> implements Listener {
|
||||
public class RedisBungeeBungeeListener extends AbstractRedisBungeeListener<LoginEvent, PostLoginEvent, PlayerDisconnectEvent, ServerConnectedEvent, ProxyPingEvent, PluginMessageEvent, PubSubMessageEvent> implements Listener {
|
||||
|
||||
|
||||
public RedisBungeeListener(RedisBungeePlugin<?> plugin, List<InetAddress> exemptAddresses) {
|
||||
public RedisBungeeBungeeListener(RedisBungeePlugin<?> plugin, List<InetAddress> exemptAddresses) {
|
||||
super(plugin, exemptAddresses);
|
||||
}
|
||||
|
||||
@ -194,7 +194,7 @@ public class RedisBungeeListener extends AbstractRedisBungeeListener<LoginEvent,
|
||||
String user = in.readUTF();
|
||||
out.writeUTF("LastOnline");
|
||||
out.writeUTF(user);
|
||||
out.writeLong(plugin.getApi().getLastOnline(plugin.getUuidTranslator().getTranslatedUuid(user, true)));
|
||||
out.writeLong(plugin.getApi().getLastOnline(Objects.requireNonNull(plugin.getUuidTranslator().getTranslatedUuid(user, true))));
|
||||
break;
|
||||
case "ServerPlayers":
|
||||
String type1 = in.readUTF();
|
||||
@ -235,7 +235,7 @@ public class RedisBungeeListener extends AbstractRedisBungeeListener<LoginEvent,
|
||||
String username = in.readUTF();
|
||||
out.writeUTF("PlayerProxy");
|
||||
out.writeUTF(username);
|
||||
out.writeUTF(plugin.getApi().getProxy(plugin.getUuidTranslator().getTranslatedUuid(username, true)));
|
||||
out.writeUTF(plugin.getApi().getProxy(Objects.requireNonNull(plugin.getUuidTranslator().getTranslatedUuid(username, true))));
|
||||
break;
|
||||
default:
|
||||
return;
|
@ -7,7 +7,6 @@ import com.google.common.collect.ImmutableMultimap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.google.common.io.ByteStreams;
|
||||
import com.google.gson.Gson;
|
||||
import com.imaginarycode.minecraft.redisbungee.commands.RedisBungeeCommands;
|
||||
import com.imaginarycode.minecraft.redisbungee.events.PlayerChangedServerNetworkEvent;
|
||||
import com.imaginarycode.minecraft.redisbungee.events.PlayerJoinedNetworkEvent;
|
||||
@ -397,7 +396,7 @@ public class RedisBungeeBungeePlugin extends Plugin implements RedisBungeePlugin
|
||||
}
|
||||
}, 0, 3, TimeUnit.SECONDS);
|
||||
dataManager = new BungeeDataManager(this);
|
||||
getProxy().getPluginManager().registerListener(this, new RedisBungeeListener(this, configuration.getExemptAddresses()));
|
||||
getProxy().getPluginManager().registerListener(this, new RedisBungeeBungeeListener(this, configuration.getExemptAddresses()));
|
||||
getProxy().getPluginManager().registerListener(this, dataManager);
|
||||
psl = new PubSubListener(this);
|
||||
getProxy().getScheduler().runAsync(this, psl);
|
||||
|
@ -1,5 +1,11 @@
|
||||
package com.imaginarycode.minecraft.redisbungee;
|
||||
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.collect.HashMultimap;
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.google.common.io.ByteArrayDataInput;
|
||||
import com.google.common.io.ByteArrayDataOutput;
|
||||
import com.google.common.io.ByteStreams;
|
||||
import com.imaginarycode.minecraft.redisbungee.internal.AbstractRedisBungeeListener;
|
||||
import com.imaginarycode.minecraft.redisbungee.internal.AbstractDataManager;
|
||||
import com.imaginarycode.minecraft.redisbungee.internal.RedisBungeePlugin;
|
||||
@ -18,6 +24,7 @@ import com.velocitypowered.api.event.player.ServerConnectedEvent;
|
||||
import com.velocitypowered.api.event.proxy.ProxyPingEvent;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import com.velocitypowered.api.proxy.ServerConnection;
|
||||
import com.velocitypowered.api.proxy.messages.LegacyChannelIdentifier;
|
||||
import com.velocitypowered.api.proxy.server.ServerPing;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import redis.clients.jedis.Jedis;
|
||||
@ -26,10 +33,10 @@ import redis.clients.jedis.Pipeline;
|
||||
import java.net.InetAddress;
|
||||
import java.util.*;
|
||||
|
||||
public class RedisBungeeListener extends AbstractRedisBungeeListener<LoginEvent, PostLoginEvent, DisconnectEvent, ServerConnectedEvent, ProxyPingEvent, PluginMessageEvent, PubSubMessageEvent> {
|
||||
public class RedisBungeeVelocityListener extends AbstractRedisBungeeListener<LoginEvent, PostLoginEvent, DisconnectEvent, ServerConnectedEvent, ProxyPingEvent, PluginMessageEvent, PubSubMessageEvent> {
|
||||
|
||||
|
||||
public RedisBungeeListener(RedisBungeePlugin<?> plugin, List<InetAddress> exemptAddresses) {
|
||||
public RedisBungeeVelocityListener(RedisBungeePlugin<?> plugin, List<InetAddress> exemptAddresses) {
|
||||
super(plugin, exemptAddresses);
|
||||
}
|
||||
|
||||
@ -136,12 +143,106 @@ public class RedisBungeeListener extends AbstractRedisBungeeListener<LoginEvent,
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("UnstableApiUsage")
|
||||
public void onPluginMessage(PluginMessageEvent event) {
|
||||
/*
|
||||
* Ham1255 note: for some reason plugin messages were not working in velocity?
|
||||
* not sure how to fix, but for now i have removed the code until a fix is made.
|
||||
*
|
||||
*/
|
||||
if ((event.getIdentifier().getId().equals("legacy:redisbungee") || event.getIdentifier().getId().equals("RedisBungee")) && event.getSource() instanceof ServerConnection) {
|
||||
final String currentChannel = event.getIdentifier().getId();
|
||||
final byte[] data = Arrays.copyOf(event.getData(), event.getData().length);
|
||||
plugin.executeAsync(() -> {
|
||||
ByteArrayDataInput in = ByteStreams.newDataInput(data);
|
||||
|
||||
String subchannel = in.readUTF();
|
||||
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
||||
String type;
|
||||
|
||||
switch (subchannel) {
|
||||
case "PlayerList":
|
||||
out.writeUTF("PlayerList");
|
||||
Set<UUID> original = Collections.emptySet();
|
||||
type = in.readUTF();
|
||||
if (type.equals("ALL")) {
|
||||
out.writeUTF("ALL");
|
||||
original = plugin.getPlayers();
|
||||
} else {
|
||||
try {
|
||||
original = plugin.getApi().getPlayersOnServer(type);
|
||||
} catch (IllegalArgumentException ignored) {
|
||||
}
|
||||
}
|
||||
Set<String> players = new HashSet<>();
|
||||
for (UUID uuid : original)
|
||||
players.add(plugin.getUuidTranslator().getNameFromUuid(uuid, false));
|
||||
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.getApi().getPlayersOnServer(type).size());
|
||||
} catch (IllegalArgumentException e) {
|
||||
out.writeInt(0);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "LastOnline":
|
||||
String user = in.readUTF();
|
||||
out.writeUTF("LastOnline");
|
||||
out.writeUTF(user);
|
||||
out.writeLong(plugin.getApi().getLastOnline(Objects.requireNonNull(plugin.getUuidTranslator().getTranslatedUuid(user, true))));
|
||||
break;
|
||||
case "ServerPlayers":
|
||||
String type1 = in.readUTF();
|
||||
out.writeUTF("ServerPlayers");
|
||||
Multimap<String, UUID> multimap = plugin.getApi().getServerToPlayers();
|
||||
|
||||
boolean includesUsers;
|
||||
|
||||
switch (type1) {
|
||||
case "COUNT":
|
||||
includesUsers = false;
|
||||
break;
|
||||
case "PLAYERS":
|
||||
includesUsers = true;
|
||||
break;
|
||||
default:
|
||||
// TODO: Should I raise an error?
|
||||
return;
|
||||
}
|
||||
|
||||
out.writeUTF(type1);
|
||||
|
||||
if (includesUsers) {
|
||||
Multimap<String, String> human = HashMultimap.create();
|
||||
for (Map.Entry<String, UUID> entry : multimap.entries()) {
|
||||
human.put(entry.getKey(), plugin.getUuidTranslator().getNameFromUuid(entry.getValue(), false));
|
||||
}
|
||||
serializeMultimap(human, true, out);
|
||||
} else {
|
||||
serializeMultiset(multimap.keys(), out);
|
||||
}
|
||||
break;
|
||||
case "Proxy":
|
||||
out.writeUTF("Proxy");
|
||||
out.writeUTF(plugin.getConfiguration().getServerId());
|
||||
break;
|
||||
case "PlayerProxy":
|
||||
String username = in.readUTF();
|
||||
out.writeUTF("PlayerProxy");
|
||||
out.writeUTF(username);
|
||||
out.writeUTF(plugin.getApi().getProxy(Objects.requireNonNull(plugin.getUuidTranslator().getTranslatedUuid(username, true))));
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
((ServerConnection) event.getSource()).sendPluginMessage(new LegacyChannelIdentifier(currentChannel), out.toByteArray());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -29,6 +29,8 @@ import com.velocitypowered.api.plugin.Plugin;
|
||||
import com.velocitypowered.api.plugin.annotation.DataDirectory;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import com.velocitypowered.api.proxy.ProxyServer;
|
||||
import com.velocitypowered.api.proxy.messages.LegacyChannelIdentifier;
|
||||
import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier;
|
||||
import com.velocitypowered.api.scheduler.ScheduledTask;
|
||||
import ninja.leaping.configurate.ConfigurationNode;
|
||||
import ninja.leaping.configurate.objectmapping.ObjectMappingException;
|
||||
@ -409,7 +411,7 @@ public class RedisBungeeVelocityPlugin implements RedisBungeePlugin<Player> {
|
||||
}
|
||||
}).repeat(3, TimeUnit.SECONDS).schedule();
|
||||
|
||||
getProxy().getEventManager().register(this, new RedisBungeeListener(this, configuration.getExemptAddresses()));
|
||||
getProxy().getEventManager().register(this, new RedisBungeeVelocityListener(this, configuration.getExemptAddresses()));
|
||||
getProxy().getEventManager().register(this, dataManager);
|
||||
getProxy().getScheduler().buildTask(this, psl).schedule();
|
||||
integrityCheck = getProxy().getScheduler().buildTask(this, () -> {
|
||||
@ -473,10 +475,10 @@ public class RedisBungeeVelocityPlugin implements RedisBungeePlugin<Player> {
|
||||
}
|
||||
}).repeat(1, TimeUnit.MINUTES).schedule();
|
||||
|
||||
// plugin messages are disabled for now
|
||||
//getProxy().registerChannel("legacy:redisbungee");
|
||||
//getProxy().registerChannel("RedisBungee");
|
||||
|
||||
getProxy().getChannelRegistrar().register(new LegacyChannelIdentifier("RedisBungee"));
|
||||
getProxy().getChannelRegistrar().register(new LegacyChannelIdentifier("legacy:redisbungee"));
|
||||
getProxy().getChannelRegistrar().register(MinecraftChannelIdentifier.create("legacy", "redisbungee"));
|
||||
// register commands
|
||||
// those still bungeecord commands will migrate them later.
|
||||
// if (configuration.doOverrideBungeeCommands()) {
|
||||
|
Loading…
Reference in New Issue
Block a user