diff --git a/RedisBungee-Bungee/src/main/java/com/imaginarycode/minecraft/redisbungee/RedisBungeeBungeePlugin.java b/RedisBungee-Bungee/src/main/java/com/imaginarycode/minecraft/redisbungee/RedisBungeeBungeePlugin.java index dfcd702..1090fdd 100644 --- a/RedisBungee-Bungee/src/main/java/com/imaginarycode/minecraft/redisbungee/RedisBungeeBungeePlugin.java +++ b/RedisBungee-Bungee/src/main/java/com/imaginarycode/minecraft/redisbungee/RedisBungeeBungeePlugin.java @@ -8,6 +8,7 @@ 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.bungee.*; import com.imaginarycode.minecraft.redisbungee.internal.*; import com.imaginarycode.minecraft.redisbungee.internal.util.IOUtil; @@ -395,19 +396,9 @@ public class RedisBungeeBungeePlugin extends Plugin implements RedisBungeePlugin } }, 0, 3, TimeUnit.SECONDS); dataManager = new BungeeDataManager(this); - /*if (configuration.isRegisterBungeeCommands()) { - 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()); - getProxy().getPluginManager().registerCommand(this, new RedisBungeeCommands.PlayerProxyCommand(this)); - getProxy().getPluginManager().registerCommand(this, new RedisBungeeCommands.PlistCommand(this)); - getProxy().getPluginManager().registerCommand(this, new RedisBungeeCommands.DebugCommand(this)); - */ + // glist command + getProxy().getPluginManager().registerCommand(this, new RedisBungeeCommands.GlistCommand(this)); + getProxy().getPluginManager().registerListener(this, new RedisBungeeListener(this, configuration.getExemptAddresses())); getProxy().getPluginManager().registerListener(this, dataManager); diff --git a/RedisBungee-Bungee/src/main/java/com/imaginarycode/minecraft/redisbungee/commands/RedisBungeeCommands.java b/RedisBungee-Bungee/src/main/java/com/imaginarycode/minecraft/redisbungee/commands/RedisBungeeCommands.java new file mode 100644 index 0000000..6c082aa --- /dev/null +++ b/RedisBungee-Bungee/src/main/java/com/imaginarycode/minecraft/redisbungee/commands/RedisBungeeCommands.java @@ -0,0 +1,78 @@ +package com.imaginarycode.minecraft.redisbungee.commands; + +import com.google.common.base.Joiner; +import com.google.common.collect.HashMultimap; +import com.google.common.collect.Multimap; +import com.imaginarycode.minecraft.redisbungee.RedisBungeeAPI; +import com.imaginarycode.minecraft.redisbungee.internal.RedisBungeePlugin; +import net.md_5.bungee.api.ChatColor; +import net.md_5.bungee.api.CommandSender; +import net.md_5.bungee.api.chat.BaseComponent; +import net.md_5.bungee.api.chat.ComponentBuilder; +import net.md_5.bungee.api.chat.TextComponent; +import net.md_5.bungee.api.plugin.Command; + +import java.util.Map; +import java.util.TreeSet; +import java.util.UUID; + +/** + * This class contains subclasses that are used for the commands RedisBungee overrides or includes: /glist, /find and /lastseen. + *
+ * All classes use the {@link RedisBungeeAPI}.
+ *
+ * @author tuxed
+ * @since 0.2.3
+ */
+public class RedisBungeeCommands {
+
+ private static String playerPlural(int num) {
+ return num == 1 ? num + " player is" : num + " players are";
+ }
+
+ public static class GlistCommand extends Command {
+ private final RedisBungeePlugin> plugin;
+
+ public GlistCommand(RedisBungeePlugin> plugin) {
+ super("glist", "bungeecord.command.list", "redisbungee", "rglist");
+ this.plugin = plugin;
+ }
+
+ @Override
+ public void execute(final CommandSender sender, final String[] args) {
+ plugin.executeAsync(new Runnable() {
+ @Override
+ public void run() {
+ int count = plugin.getApi().getPlayerCount();
+ BaseComponent[] playersOnline = new ComponentBuilder("").color(ChatColor.YELLOW)
+ .append(playerPlural(count) + " currently online.").create();
+ if (args.length > 0 && args[0].equals("showall")) {
+ Multimap