123 lines
5.4 KiB
Java
123 lines
5.4 KiB
Java
package xyz.etztech.mixtape.commands;
|
|
|
|
import net.md_5.bungee.api.ChatColor;
|
|
import net.md_5.bungee.api.chat.TextComponent;
|
|
import org.bukkit.Bukkit;
|
|
import org.bukkit.OfflinePlayer;
|
|
import org.bukkit.command.Command;
|
|
import org.bukkit.command.CommandExecutor;
|
|
import org.bukkit.command.CommandSender;
|
|
import org.bukkit.entity.Player;
|
|
import xyz.etztech.mixtape.Alias;
|
|
import xyz.etztech.mixtape.Mixtape;
|
|
|
|
public class CommandMixtape implements CommandExecutor {
|
|
|
|
Mixtape plugin;
|
|
|
|
public CommandMixtape(Mixtape plugin) {
|
|
this.plugin = plugin;
|
|
plugin.getCommand("mixtape").setExecutor(this);
|
|
}
|
|
|
|
@Override
|
|
public boolean onCommand(CommandSender sender, Command command, String base, String[] args) {
|
|
boolean hasAdmin = sender.hasPermission("alias.admin");
|
|
if (args.length == 0) {
|
|
sender.sendMessage(ChatColor.GOLD + "===== Mixtape =====");
|
|
sender.sendMessage(ChatColor.YELLOW + "/mixtape reload");
|
|
sender.sendMessage(ChatColor.YELLOW + "/mixtape list" + (hasAdmin ? " [<player>]" : ""));
|
|
sender.sendMessage(ChatColor.YELLOW + "/mixtape delete <alias>");
|
|
if (hasAdmin) {
|
|
sender.sendMessage(ChatColor.YELLOW + "/mixtape purge [<player>]");
|
|
}
|
|
} else {
|
|
if ("list".equalsIgnoreCase(args[0])) {
|
|
if (sender instanceof Player) {
|
|
list(sender, args.length == 2 ? args[1] : null);
|
|
} else {
|
|
sender.sendMessage(ChatColor.RED + "Console can only use global aliases defined in the config.");
|
|
}
|
|
} else if ("delete".equalsIgnoreCase(args[0])) {
|
|
if (sender instanceof Player) {
|
|
if (args.length > 1) {
|
|
delete(sender, args[1]);
|
|
}
|
|
} else {
|
|
sender.sendMessage(ChatColor.RED + "Console can only use global aliases defined in the config.");
|
|
}
|
|
}
|
|
if (hasAdmin) {
|
|
if ("reload".equalsIgnoreCase(args[0])) {
|
|
plugin.reloadConfig();
|
|
sender.sendMessage(ChatColor.GREEN + "Mixtape Reloaded.");
|
|
} else if ("purge".equalsIgnoreCase(args[0])) {
|
|
if (args.length > 1) {
|
|
Player player = Bukkit.getPlayerExact(args[1]);
|
|
if (player != null) {
|
|
Mixtape.getDatabase().purge(player.getUniqueId().toString());
|
|
sender.sendMessage(ChatColor.GREEN + "Purged all of " + player.getName() + "'s aliases.");
|
|
} else {
|
|
sender.sendMessage(ChatColor.RED + "No player found.");
|
|
}
|
|
} else {
|
|
for (OfflinePlayer offline : Bukkit.getBannedPlayers()) {
|
|
Mixtape.getDatabase().purge(offline.getUniqueId().toString());
|
|
}
|
|
sender.sendMessage(ChatColor.GREEN + "Purged all banned players' aliases.");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
private void list(CommandSender sender, String username) {
|
|
if (username == null || !sender.hasPermission("mixtape.list.other")) {
|
|
username = sender.getName();
|
|
}
|
|
|
|
Player player = Bukkit.getPlayer(username);
|
|
if (player != null) {
|
|
StringBuilder message = new StringBuilder();
|
|
message.append(ChatColor.GOLD).append("|").append(ChatColor.YELLOW);
|
|
message.append(" Aliases for ").append(username).append(" ");
|
|
message.append(ChatColor.GOLD).append("|").append(ChatColor.YELLOW);
|
|
message.append("\n");
|
|
message.append(ChatColor.GOLD).append("|").append(ChatColor.YELLOW);
|
|
message.append(" Type ");
|
|
message.append(ChatColor.GOLD).append("|").append(ChatColor.YELLOW);
|
|
message.append(" Alias ");
|
|
message.append(ChatColor.GOLD).append("|").append(ChatColor.YELLOW);
|
|
message.append(" Command ");
|
|
message.append(ChatColor.GOLD).append("|").append(ChatColor.YELLOW);
|
|
for (Alias alias : Mixtape.getDatabase().getAliases(player.getUniqueId().toString())) {
|
|
message.append("\n");
|
|
message.append(ChatColor.GOLD).append("| ").append(ChatColor.YELLOW);
|
|
message.append(alias.getType().name());
|
|
message.append(ChatColor.GOLD).append(" | ").append(ChatColor.YELLOW);
|
|
message.append(alias.getFrom());
|
|
message.append(ChatColor.GOLD).append(" | ").append(ChatColor.YELLOW);
|
|
message.append(alias.getTo());
|
|
message.append(ChatColor.GOLD).append(" |").append(ChatColor.YELLOW);
|
|
}
|
|
sender.sendMessage(message.toString());
|
|
} else {
|
|
sender.sendMessage(ChatColor.RED + "No aliases found for " + username + ". Are they online?");
|
|
}
|
|
}
|
|
|
|
private void delete(CommandSender sender, String from) {
|
|
Player player = (Player) sender;
|
|
int id = Mixtape.getDatabase().exists(player.getUniqueId().toString(), from);
|
|
if (id > 0) {
|
|
Mixtape.getDatabase().delete(id);
|
|
player.sendMessage(ChatColor.RED + "Deleted alias for '" + from + "'");
|
|
} else {
|
|
player.sendMessage(ChatColor.RED + "No alias found for '" + from + "'");
|
|
}
|
|
}
|
|
|
|
|
|
}
|