mirror of
https://github.com/proxiodev/RedisBungee.git
synced 2026-05-03 11:40:29 +00:00
RedisBungee 0.3 base code. A lot has changed. There is more to come.
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
package com.imaginarycode.minecraft.redisbungee;
|
||||
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.collect.HashMultimap;
|
||||
import com.google.common.collect.Multimap;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
@@ -18,7 +19,9 @@ import net.md_5.bungee.api.plugin.Command;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.text.SimpleDateFormat;
|
||||
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.
|
||||
@@ -37,119 +40,158 @@ class RedisBungeeCommands {
|
||||
new ComponentBuilder("You must specify a command to be run.").color(ChatColor.RED).create();
|
||||
|
||||
public static class GlistCommand extends Command {
|
||||
GlistCommand() {
|
||||
private final RedisBungee plugin;
|
||||
|
||||
GlistCommand(RedisBungee plugin) {
|
||||
super("glist", "bungeecord.command.list", "redisbungee", "rglist");
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
int count = RedisBungee.getApi().getPlayerCount();
|
||||
BaseComponent[] playersOnline = new ComponentBuilder("").color(ChatColor.YELLOW).append(String.valueOf(count))
|
||||
.append(" player(s) are currently online.").create();
|
||||
if (args.length > 0 && args[0].equals("showall")) {
|
||||
if (RedisBungee.getConfiguration().getBoolean("canonical-glist", true)) {
|
||||
Multimap<String, String> serverToPlayers = RedisBungee.getApi().getServerToPlayers();
|
||||
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(serverToPlayers.get(server)));
|
||||
sender.sendMessage(serverName, serverCount, serverPlayers);
|
||||
public void execute(final CommandSender sender, final String[] args) {
|
||||
plugin.getProxy().getScheduler().runAsync(plugin, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
int count = RedisBungee.getApi().getPlayerCount();
|
||||
BaseComponent[] playersOnline = new ComponentBuilder("").color(ChatColor.YELLOW).append(String.valueOf(count))
|
||||
.append(" player(s) are currently online.").create();
|
||||
if (args.length > 0 && args[0].equals("showall")) {
|
||||
if (RedisBungee.getConfiguration().getBoolean("canonical-glist", true)) {
|
||||
Multimap<String, UUID> serverToPlayers = RedisBungee.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()));
|
||||
}
|
||||
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);
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage(new ComponentBuilder("Players: " + Joiner.on(", ").join(RedisBungee.getApi().getPlayersOnline()))
|
||||
.color(ChatColor.YELLOW).create());
|
||||
}
|
||||
sender.sendMessage(playersOnline);
|
||||
} else {
|
||||
sender.sendMessage(playersOnline);
|
||||
sender.sendMessage(new ComponentBuilder("To see all players online, use /glist showall.").color(ChatColor.YELLOW).create());
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage(new ComponentBuilder("Players: " + Joiner.on(", ").join(RedisBungee.getApi().getPlayersOnline()))
|
||||
.color(ChatColor.YELLOW).create());
|
||||
}
|
||||
sender.sendMessage(playersOnline);
|
||||
} else {
|
||||
sender.sendMessage(playersOnline);
|
||||
sender.sendMessage(new ComponentBuilder("To see all players online, use /glist showall.").color(ChatColor.YELLOW).create());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public static class FindCommand extends Command {
|
||||
FindCommand() {
|
||||
private final RedisBungee plugin;
|
||||
|
||||
FindCommand(RedisBungee plugin) {
|
||||
super("find", "bungeecord.command.find", "rfind");
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
if (args.length > 0) {
|
||||
ServerInfo si = RedisBungee.getApi().getServerFor(args[0]);
|
||||
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);
|
||||
public void execute(final CommandSender sender, final String[] args) {
|
||||
plugin.getProxy().getScheduler().runAsync(plugin, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (args.length > 0) {
|
||||
ServerInfo si = RedisBungee.getApi().getServerFor(plugin.getUuidTranslator().getTranslatedUuid(args[0]));
|
||||
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);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage(NO_PLAYER_SPECIFIED);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public static class LastSeenCommand extends Command {
|
||||
LastSeenCommand() {
|
||||
private final RedisBungee plugin;
|
||||
|
||||
LastSeenCommand(RedisBungee plugin) {
|
||||
super("lastseen", "redisbungee.command.lastseen", "rlastseen");
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
if (args.length > 0) {
|
||||
long secs = RedisBungee.getApi().getLastOnline(args[0]);
|
||||
TextComponent message = new TextComponent();
|
||||
if (secs == 0) {
|
||||
message.setColor(ChatColor.GREEN);
|
||||
message.setText(args[0] + " is currently online.");
|
||||
sender.sendMessage(message);
|
||||
} else if (secs != -1) {
|
||||
message.setColor(ChatColor.BLUE);
|
||||
message.setText(args[0] + " was last online on " + new SimpleDateFormat().format(secs) + ".");
|
||||
sender.sendMessage(message);
|
||||
} else {
|
||||
message.setColor(ChatColor.RED);
|
||||
message.setText(args[0] + " has never been online.");
|
||||
sender.sendMessage(message);
|
||||
public void execute(final CommandSender sender, final String[] args) {
|
||||
plugin.getProxy().getScheduler().runAsync(plugin, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (args.length > 0) {
|
||||
long secs = RedisBungee.getApi().getLastOnline(plugin.getUuidTranslator().getTranslatedUuid(args[0]));
|
||||
TextComponent message = new TextComponent();
|
||||
if (secs == 0) {
|
||||
message.setColor(ChatColor.GREEN);
|
||||
message.setText(args[0] + " is currently online.");
|
||||
sender.sendMessage(message);
|
||||
} else if (secs != -1) {
|
||||
message.setColor(ChatColor.BLUE);
|
||||
message.setText(args[0] + " was last online on " + new SimpleDateFormat().format(secs) + ".");
|
||||
sender.sendMessage(message);
|
||||
} else {
|
||||
message.setColor(ChatColor.RED);
|
||||
message.setText(args[0] + " has never been online.");
|
||||
sender.sendMessage(message);
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage(NO_PLAYER_SPECIFIED);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage(NO_PLAYER_SPECIFIED);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public static class IpCommand extends Command {
|
||||
IpCommand() {
|
||||
private final RedisBungee plugin;
|
||||
|
||||
IpCommand(RedisBungee plugin) {
|
||||
super("ip", "redisbungee.command.ip", "playerip", "rip", "rplayerip");
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
if (args.length > 0) {
|
||||
InetAddress ia = RedisBungee.getApi().getPlayerIp(args[0]);
|
||||
if (ia != null) {
|
||||
TextComponent message = new TextComponent();
|
||||
message.setColor(ChatColor.GREEN);
|
||||
message.setText(args[0] + " is connected from " + ia.toString() + ".");
|
||||
} else {
|
||||
sender.sendMessage(PLAYER_NOT_FOUND);
|
||||
public void execute(final CommandSender sender, final String[] args) {
|
||||
plugin.getProxy().getScheduler().runAsync(plugin, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (args.length > 0) {
|
||||
InetAddress ia = RedisBungee.getApi().getPlayerIp(plugin.getUuidTranslator().getTranslatedUuid(args[0]));
|
||||
if (ia != null) {
|
||||
TextComponent message = new TextComponent();
|
||||
message.setColor(ChatColor.GREEN);
|
||||
message.setText(args[0] + " is connected from " + ia.toString() + ".");
|
||||
} else {
|
||||
sender.sendMessage(PLAYER_NOT_FOUND);
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage(NO_PLAYER_SPECIFIED);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage(NO_PLAYER_SPECIFIED);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public static class SendToAll extends Command {
|
||||
SendToAll() {
|
||||
private final RedisBungee plugin;
|
||||
|
||||
SendToAll(RedisBungee plugin) {
|
||||
super("sendtoall", "redisbungee.command.sendtoall", "rsendtoall");
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -167,8 +209,11 @@ class RedisBungeeCommands {
|
||||
}
|
||||
|
||||
public static class ServerId extends Command {
|
||||
ServerId() {
|
||||
private final RedisBungee plugin;
|
||||
|
||||
ServerId(RedisBungee plugin) {
|
||||
super("serverid", "redisbungee.command.serverid", "rserverid");
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -179,4 +224,18 @@ class RedisBungeeCommands {
|
||||
sender.sendMessage(textComponent);
|
||||
}
|
||||
}
|
||||
|
||||
public static class ServerIds extends Command {
|
||||
public ServerIds() {
|
||||
super("serverids", "redisbungee.command.serverids");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] strings) {
|
||||
TextComponent textComponent = new TextComponent();
|
||||
textComponent.setText("All server IDs: " + Joiner.on(", ").join(RedisBungee.getApi().getAllServers()));
|
||||
textComponent.setColor(ChatColor.YELLOW);
|
||||
sender.sendMessage(textComponent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user