mirror of
https://github.com/proxiodev/RedisBungee.git
synced 2024-11-22 20:28:00 +00:00
add glist command *reset will be added later
This commit is contained in:
parent
08c7d89749
commit
e53f8a02ba
@ -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()) {
|
||||
// glist command
|
||||
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));
|
||||
*/
|
||||
|
||||
|
||||
getProxy().getPluginManager().registerListener(this, new RedisBungeeListener(this, configuration.getExemptAddresses()));
|
||||
getProxy().getPluginManager().registerListener(this, dataManager);
|
||||
|
@ -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.
|
||||
* <p>
|
||||
* 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<String, UUID> serverToPlayers = plugin.getApi().getServerToPlayers();
|
||||
Multimap<String, String> human = HashMultimap.create();
|
||||
for (Map.Entry<String, UUID> entry : serverToPlayers.entries()) {
|
||||
human.put(entry.getKey(), plugin.getUuidTranslator().getNameFromUuid(entry.getValue(), false));
|
||||
}
|
||||
for (String server : new TreeSet<>(serverToPlayers.keySet())) {
|
||||
TextComponent serverName = new TextComponent();
|
||||
serverName.setColor(ChatColor.GREEN);
|
||||
serverName.setText("[" + server + "] ");
|
||||
TextComponent serverCount = new TextComponent();
|
||||
serverCount.setColor(ChatColor.YELLOW);
|
||||
serverCount.setText("(" + serverToPlayers.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 /glist showall.").color(ChatColor.YELLOW).create());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user