mirror of
https://github.com/proxiodev/RedisBungee.git
synced 2024-11-22 20:28:00 +00:00
readd commands after i forgotten about them
This commit is contained in:
parent
6e02ab70db
commit
eee36923c1
@ -9,9 +9,10 @@ import java.util.List;
|
|||||||
public class RedisBungeeConfiguration {
|
public class RedisBungeeConfiguration {
|
||||||
private final String serverId;
|
private final String serverId;
|
||||||
private final List<InetAddress> exemptAddresses;
|
private final List<InetAddress> exemptAddresses;
|
||||||
|
private final boolean overrideBungeeCommands;
|
||||||
private static RedisBungeeConfiguration config;
|
private static RedisBungeeConfiguration config;
|
||||||
|
|
||||||
public RedisBungeeConfiguration(String serverId, List<String> exemptAddresses) {
|
public RedisBungeeConfiguration(String serverId, List<String> exemptAddresses, boolean overrideBungeeCommands) {
|
||||||
this.serverId = serverId;
|
this.serverId = serverId;
|
||||||
|
|
||||||
ImmutableList.Builder<InetAddress> addressBuilder = ImmutableList.builder();
|
ImmutableList.Builder<InetAddress> addressBuilder = ImmutableList.builder();
|
||||||
@ -20,6 +21,7 @@ public class RedisBungeeConfiguration {
|
|||||||
}
|
}
|
||||||
this.exemptAddresses = addressBuilder.build();
|
this.exemptAddresses = addressBuilder.build();
|
||||||
config = this;
|
config = this;
|
||||||
|
this.overrideBungeeCommands = overrideBungeeCommands;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getServerId() {
|
public String getServerId() {
|
||||||
@ -30,6 +32,10 @@ public class RedisBungeeConfiguration {
|
|||||||
return exemptAddresses;
|
return exemptAddresses;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean doOverrideBungeeCommands() {
|
||||||
|
return overrideBungeeCommands;
|
||||||
|
}
|
||||||
|
|
||||||
public static RedisBungeeConfiguration getConfig() {
|
public static RedisBungeeConfiguration getConfig() {
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
|
@ -405,10 +405,6 @@ public class RedisBungeeBungeePlugin extends Plugin implements RedisBungeePlugin
|
|||||||
}
|
}
|
||||||
}, 0, 3, TimeUnit.SECONDS);
|
}, 0, 3, TimeUnit.SECONDS);
|
||||||
dataManager = new BungeeDataManager(this);
|
dataManager = new BungeeDataManager(this);
|
||||||
// glist command
|
|
||||||
getProxy().getPluginManager().registerCommand(this, new RedisBungeeCommands.GlistCommand(this));
|
|
||||||
|
|
||||||
|
|
||||||
getProxy().getPluginManager().registerListener(this, new RedisBungeeListener(this, configuration.getExemptAddresses()));
|
getProxy().getPluginManager().registerListener(this, new RedisBungeeListener(this, configuration.getExemptAddresses()));
|
||||||
getProxy().getPluginManager().registerListener(this, dataManager);
|
getProxy().getPluginManager().registerListener(this, dataManager);
|
||||||
psl = new PubSubListener(this);
|
psl = new PubSubListener(this);
|
||||||
@ -479,6 +475,18 @@ public class RedisBungeeBungeePlugin extends Plugin implements RedisBungeePlugin
|
|||||||
}
|
}
|
||||||
getProxy().registerChannel("legacy:redisbungee");
|
getProxy().registerChannel("legacy:redisbungee");
|
||||||
getProxy().registerChannel("RedisBungee");
|
getProxy().registerChannel("RedisBungee");
|
||||||
|
// register commands
|
||||||
|
if (configuration.doOverrideBungeeCommands()) {
|
||||||
|
getProxy().getPluginManager().registerCommand(this, new RedisBungeeCommands.GlistCommand(this));
|
||||||
|
getProxy().getPluginManager().registerCommand(this, new RedisBungeeCommands.FindCommand(this));
|
||||||
|
getProxy().getPluginManager().registerCommand(this, new RedisBungeeCommands.LastSeenCommand(this));
|
||||||
|
getProxy().getPluginManager().registerCommand(this, new RedisBungeeCommands.IpCommand(this));
|
||||||
|
}
|
||||||
|
getProxy().getPluginManager().registerCommand(this, new RedisBungeeCommands.SendToAll(this));
|
||||||
|
getProxy().getPluginManager().registerCommand(this, new RedisBungeeCommands.ServerId(this));
|
||||||
|
getProxy().getPluginManager().registerCommand(this, new RedisBungeeCommands.ServerIds(this));
|
||||||
|
getProxy().getPluginManager().registerCommand(this, new RedisBungeeCommands.PlayerProxyCommand(this));
|
||||||
|
getProxy().getPluginManager().registerCommand(this, new RedisBungeeCommands.PlistCommand(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -550,7 +558,7 @@ public class RedisBungeeBungeePlugin extends Plugin implements RedisBungeePlugin
|
|||||||
} else {
|
} else {
|
||||||
getLogger().info("Loaded server id " + serverId + '.');
|
getLogger().info("Loaded server id " + serverId + '.');
|
||||||
}
|
}
|
||||||
this.configuration = new RedisBungeeConfiguration(serverId, yamlConfiguration.getStringList("exempt-ip-addresses"));
|
this.configuration = new RedisBungeeConfiguration(serverId, yamlConfiguration.getStringList("exempt-ip-addresses"), yamlConfiguration.getBoolean("register-bungee-commands", true));
|
||||||
|
|
||||||
if (redisServer != null && !redisServer.isEmpty()) {
|
if (redisServer != null && !redisServer.isEmpty()) {
|
||||||
try {
|
try {
|
||||||
|
@ -4,15 +4,21 @@ import com.google.common.base.Joiner;
|
|||||||
import com.google.common.collect.HashMultimap;
|
import com.google.common.collect.HashMultimap;
|
||||||
import com.google.common.collect.Multimap;
|
import com.google.common.collect.Multimap;
|
||||||
import com.imaginarycode.minecraft.redisbungee.RedisBungeeAPI;
|
import com.imaginarycode.minecraft.redisbungee.RedisBungeeAPI;
|
||||||
|
import com.imaginarycode.minecraft.redisbungee.RedisBungeeBungeePlugin;
|
||||||
import com.imaginarycode.minecraft.redisbungee.internal.RedisBungeePlugin;
|
import com.imaginarycode.minecraft.redisbungee.internal.RedisBungeePlugin;
|
||||||
import net.md_5.bungee.api.ChatColor;
|
import net.md_5.bungee.api.ChatColor;
|
||||||
import net.md_5.bungee.api.CommandSender;
|
import net.md_5.bungee.api.CommandSender;
|
||||||
import net.md_5.bungee.api.chat.BaseComponent;
|
import net.md_5.bungee.api.chat.BaseComponent;
|
||||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||||
import net.md_5.bungee.api.chat.TextComponent;
|
import net.md_5.bungee.api.chat.TextComponent;
|
||||||
|
import net.md_5.bungee.api.config.ServerInfo;
|
||||||
|
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||||
import net.md_5.bungee.api.plugin.Command;
|
import net.md_5.bungee.api.plugin.Command;
|
||||||
|
|
||||||
|
import java.net.InetAddress;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.TreeSet;
|
import java.util.TreeSet;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@ -25,22 +31,28 @@ import java.util.UUID;
|
|||||||
* @since 0.2.3
|
* @since 0.2.3
|
||||||
*/
|
*/
|
||||||
public class RedisBungeeCommands {
|
public class RedisBungeeCommands {
|
||||||
|
private static final BaseComponent[] NO_PLAYER_SPECIFIED =
|
||||||
|
new ComponentBuilder("You must specify a player name.").color(ChatColor.RED).create();
|
||||||
|
private static final BaseComponent[] PLAYER_NOT_FOUND =
|
||||||
|
new ComponentBuilder("No such player found.").color(ChatColor.RED).create();
|
||||||
|
private static final BaseComponent[] NO_COMMAND_SPECIFIED =
|
||||||
|
new ComponentBuilder("You must specify a command to be run.").color(ChatColor.RED).create();
|
||||||
|
|
||||||
private static String playerPlural(int num) {
|
private static String playerPlural(int num) {
|
||||||
return num == 1 ? num + " player is" : num + " players are";
|
return num == 1 ? num + " player is" : num + " players are";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class GlistCommand extends Command {
|
public static class GlistCommand extends Command {
|
||||||
private final RedisBungeePlugin<?> plugin;
|
private final RedisBungeeBungeePlugin plugin;
|
||||||
|
|
||||||
public GlistCommand(RedisBungeePlugin<?> plugin) {
|
public GlistCommand(RedisBungeeBungeePlugin plugin) {
|
||||||
super("glist", "bungeecord.command.list", "redisbungee", "rglist");
|
super("glist", "bungeecord.command.list", "redisbungee", "rglist");
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(final CommandSender sender, final String[] args) {
|
public void execute(final CommandSender sender, final String[] args) {
|
||||||
plugin.executeAsync(new Runnable() {
|
plugin.getProxy().getScheduler().runAsync(plugin, new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
int count = plugin.getApi().getPlayerCount();
|
int count = plugin.getApi().getPlayerCount();
|
||||||
@ -74,5 +86,258 @@ public class RedisBungeeCommands {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class FindCommand extends Command {
|
||||||
|
private final RedisBungeeBungeePlugin plugin;
|
||||||
|
|
||||||
}
|
public FindCommand(RedisBungeeBungeePlugin plugin) {
|
||||||
|
super("find", "bungeecord.command.find", "rfind");
|
||||||
|
this.plugin = plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(final CommandSender sender, final String[] args) {
|
||||||
|
plugin.getProxy().getScheduler().runAsync(plugin, new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if (args.length > 0) {
|
||||||
|
UUID uuid = plugin.getUuidTranslator().getTranslatedUuid(args[0], true);
|
||||||
|
if (uuid == null) {
|
||||||
|
sender.sendMessage(PLAYER_NOT_FOUND);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ServerInfo si = plugin.getProxy().getServerInfo(plugin.getApi().getServerFor(uuid));
|
||||||
|
if (si != null) {
|
||||||
|
TextComponent message = new TextComponent();
|
||||||
|
message.setColor(ChatColor.BLUE);
|
||||||
|
message.setText(args[0] + " is on " + si.getName() + ".");
|
||||||
|
sender.sendMessage(message);
|
||||||
|
} else {
|
||||||
|
sender.sendMessage(PLAYER_NOT_FOUND);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
sender.sendMessage(NO_PLAYER_SPECIFIED);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class LastSeenCommand extends Command {
|
||||||
|
private final RedisBungeeBungeePlugin plugin;
|
||||||
|
|
||||||
|
public LastSeenCommand(RedisBungeeBungeePlugin plugin) {
|
||||||
|
super("lastseen", "redisbungee.command.lastseen", "rlastseen");
|
||||||
|
this.plugin = plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(final CommandSender sender, final String[] args) {
|
||||||
|
plugin.getProxy().getScheduler().runAsync(plugin, new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if (args.length > 0) {
|
||||||
|
UUID uuid = plugin.getUuidTranslator().getTranslatedUuid(args[0], true);
|
||||||
|
if (uuid == null) {
|
||||||
|
sender.sendMessage(PLAYER_NOT_FOUND);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
long secs = plugin.getApi().getLastOnline(uuid);
|
||||||
|
TextComponent message = new TextComponent();
|
||||||
|
if (secs == 0) {
|
||||||
|
message.setColor(ChatColor.GREEN);
|
||||||
|
message.setText(args[0] + " is currently online.");
|
||||||
|
} else if (secs != -1) {
|
||||||
|
message.setColor(ChatColor.BLUE);
|
||||||
|
message.setText(args[0] + " was last online on " + new SimpleDateFormat().format(secs) + ".");
|
||||||
|
} else {
|
||||||
|
message.setColor(ChatColor.RED);
|
||||||
|
message.setText(args[0] + " has never been online.");
|
||||||
|
}
|
||||||
|
sender.sendMessage(message);
|
||||||
|
} else {
|
||||||
|
sender.sendMessage(NO_PLAYER_SPECIFIED);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class IpCommand extends Command {
|
||||||
|
private final RedisBungeeBungeePlugin plugin;
|
||||||
|
|
||||||
|
public IpCommand(RedisBungeeBungeePlugin plugin) {
|
||||||
|
super("ip", "redisbungee.command.ip", "playerip", "rip", "rplayerip");
|
||||||
|
this.plugin = plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(final CommandSender sender, final String[] args) {
|
||||||
|
plugin.getProxy().getScheduler().runAsync(plugin, new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if (args.length > 0) {
|
||||||
|
UUID uuid = plugin.getUuidTranslator().getTranslatedUuid(args[0], true);
|
||||||
|
if (uuid == null) {
|
||||||
|
sender.sendMessage(PLAYER_NOT_FOUND);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
InetAddress ia = plugin.getApi().getPlayerIp(uuid);
|
||||||
|
if (ia != null) {
|
||||||
|
TextComponent message = new TextComponent();
|
||||||
|
message.setColor(ChatColor.GREEN);
|
||||||
|
message.setText(args[0] + " is connected from " + ia.toString() + ".");
|
||||||
|
sender.sendMessage(message);
|
||||||
|
} else {
|
||||||
|
sender.sendMessage(PLAYER_NOT_FOUND);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
sender.sendMessage(NO_PLAYER_SPECIFIED);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class PlayerProxyCommand extends Command {
|
||||||
|
private final RedisBungeeBungeePlugin plugin;
|
||||||
|
|
||||||
|
public PlayerProxyCommand(RedisBungeeBungeePlugin plugin) {
|
||||||
|
super("pproxy", "redisbungee.command.pproxy");
|
||||||
|
this.plugin = plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(final CommandSender sender, final String[] args) {
|
||||||
|
plugin.getProxy().getScheduler().runAsync(plugin, new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if (args.length > 0) {
|
||||||
|
UUID uuid = plugin.getUuidTranslator().getTranslatedUuid(args[0], true);
|
||||||
|
if (uuid == null) {
|
||||||
|
sender.sendMessage(PLAYER_NOT_FOUND);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String proxy = plugin.getApi().getProxy(uuid);
|
||||||
|
if (proxy != null) {
|
||||||
|
TextComponent message = new TextComponent();
|
||||||
|
message.setColor(ChatColor.GREEN);
|
||||||
|
message.setText(args[0] + " is connected to " + proxy + ".");
|
||||||
|
sender.sendMessage(message);
|
||||||
|
} else {
|
||||||
|
sender.sendMessage(PLAYER_NOT_FOUND);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
sender.sendMessage(NO_PLAYER_SPECIFIED);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class SendToAll extends Command {
|
||||||
|
private final RedisBungeeBungeePlugin plugin;
|
||||||
|
|
||||||
|
public SendToAll(RedisBungeeBungeePlugin plugin) {
|
||||||
|
super("sendtoall", "redisbungee.command.sendtoall", "rsendtoall");
|
||||||
|
this.plugin = plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(CommandSender sender, String[] args) {
|
||||||
|
if (args.length > 0) {
|
||||||
|
String command = Joiner.on(" ").skipNulls().join(args);
|
||||||
|
plugin.getApi().sendProxyCommand(command);
|
||||||
|
TextComponent message = new TextComponent();
|
||||||
|
message.setColor(ChatColor.GREEN);
|
||||||
|
message.setText("Sent the command /" + command + " to all proxies.");
|
||||||
|
sender.sendMessage(message);
|
||||||
|
} else {
|
||||||
|
sender.sendMessage(NO_COMMAND_SPECIFIED);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class ServerId extends Command {
|
||||||
|
private final RedisBungeeBungeePlugin plugin;
|
||||||
|
|
||||||
|
public ServerId(RedisBungeeBungeePlugin plugin) {
|
||||||
|
super("serverid", "redisbungee.command.serverid", "rserverid");
|
||||||
|
this.plugin = plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(CommandSender sender, String[] args) {
|
||||||
|
TextComponent textComponent = new TextComponent();
|
||||||
|
textComponent.setText("You are on " + plugin.getApi().getServerId() + ".");
|
||||||
|
textComponent.setColor(ChatColor.YELLOW);
|
||||||
|
sender.sendMessage(textComponent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class ServerIds extends Command {
|
||||||
|
private final RedisBungeeBungeePlugin plugin;
|
||||||
|
public ServerIds(RedisBungeeBungeePlugin plugin) {
|
||||||
|
super("serverids", "redisbungee.command.serverids");
|
||||||
|
this.plugin =plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(CommandSender sender, String[] strings) {
|
||||||
|
TextComponent textComponent = new TextComponent();
|
||||||
|
textComponent.setText("All server IDs: " + Joiner.on(", ").join(plugin.getApi().getAllServers()));
|
||||||
|
textComponent.setColor(ChatColor.YELLOW);
|
||||||
|
sender.sendMessage(textComponent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class PlistCommand extends Command {
|
||||||
|
private final RedisBungeeBungeePlugin plugin;
|
||||||
|
|
||||||
|
public PlistCommand(RedisBungeeBungeePlugin plugin) {
|
||||||
|
super("plist", "redisbungee.command.plist", "rplist");
|
||||||
|
this.plugin = plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(final CommandSender sender, final String[] args) {
|
||||||
|
plugin.getProxy().getScheduler().runAsync(plugin, new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
String proxy = args.length >= 1 ? args[0] : plugin.getConfiguration().getServerId();
|
||||||
|
if (!plugin.getServerIds().contains(proxy)) {
|
||||||
|
sender.sendMessage(new ComponentBuilder(proxy + " is not a valid proxy. See /serverids for valid proxies.").color(ChatColor.RED).create());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Set<UUID> players = plugin.getApi().getPlayersOnProxy(proxy);
|
||||||
|
BaseComponent[] playersOnline = new ComponentBuilder("").color(ChatColor.YELLOW)
|
||||||
|
.append(playerPlural(players.size()) + " currently on proxy " + proxy + ".").create();
|
||||||
|
if (args.length >= 2 && args[1].equals("showall")) {
|
||||||
|
Multimap<String, UUID> serverToPlayers = plugin.getApi().getServerToPlayers();
|
||||||
|
Multimap<String, String> human = HashMultimap.create();
|
||||||
|
for (Map.Entry<String, UUID> entry : serverToPlayers.entries()) {
|
||||||
|
if (players.contains(entry.getValue())) {
|
||||||
|
human.put(entry.getKey(), plugin.getUuidTranslator().getNameFromUuid(entry.getValue(), false));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (String server : new TreeSet<>(human.keySet())) {
|
||||||
|
TextComponent serverName = new TextComponent();
|
||||||
|
serverName.setColor(ChatColor.RED);
|
||||||
|
serverName.setText("[" + server + "] ");
|
||||||
|
TextComponent serverCount = new TextComponent();
|
||||||
|
serverCount.setColor(ChatColor.YELLOW);
|
||||||
|
serverCount.setText("(" + human.get(server).size() + "): ");
|
||||||
|
TextComponent serverPlayers = new TextComponent();
|
||||||
|
serverPlayers.setColor(ChatColor.WHITE);
|
||||||
|
serverPlayers.setText(Joiner.on(", ").join(human.get(server)));
|
||||||
|
sender.sendMessage(serverName, serverCount, serverPlayers);
|
||||||
|
}
|
||||||
|
sender.sendMessage(playersOnline);
|
||||||
|
} else {
|
||||||
|
sender.sendMessage(playersOnline);
|
||||||
|
sender.sendMessage(new ComponentBuilder("To see all players online, use /plist " + proxy + " showall.").color(ChatColor.YELLOW).create());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user