mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2024-11-27 01:05:38 +00:00
Restructure gadmin. Resolves #245
This commit is contained in:
parent
461cfa7bdc
commit
86f61f1487
@ -1,11 +1,10 @@
|
||||
package me.StevenLawson.TotalFreedomMod.Commands;
|
||||
|
||||
import me.StevenLawson.TotalFreedomMod.TFM_Ban;
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import me.StevenLawson.TotalFreedomMod.TFM_BanManager;
|
||||
import me.StevenLawson.TotalFreedomMod.TFM_ServerInterface;
|
||||
import me.StevenLawson.TotalFreedomMod.TFM_PlayerData;
|
||||
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
||||
import me.StevenLawson.TotalFreedomMod.TFM_UuidResolver;
|
||||
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
@ -14,10 +13,48 @@ import org.bukkit.entity.Player;
|
||||
|
||||
@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH)
|
||||
@CommandParameters(
|
||||
description = "Use admin commands on someone by hash. Use mode 'list' to get a player's hash. Other modes are kick, nameban, ipban, ban, op, deop, ci",
|
||||
usage = "/<command> [list | [<kick | nameban | ipban | ban | op | deop | ci | fr> <targethash>] ]")
|
||||
description = "Use admin commands on someone by hash. Use mode 'list' to get a player's hash. Other modes are kick, nameban, ipban, ban, op, deop, ci, fr, smite.",
|
||||
usage = "/<command> [list | [<kick | nameban | ipban | ban | op | deop | ci | fr | smite> <targethash>] ]")
|
||||
public class Command_gadmin extends TFM_Command
|
||||
{
|
||||
private enum GadminMode
|
||||
{
|
||||
LIST("list"),
|
||||
KICK("kick"),
|
||||
NAMEBAN("nameban"),
|
||||
IPBAN("ipban"),
|
||||
BAN("ban"),
|
||||
OP("op"),
|
||||
DEOP("deop"),
|
||||
CI("ci"),
|
||||
FR("fr"),
|
||||
SMITE("smite");
|
||||
|
||||
private final String modeName;
|
||||
|
||||
private GadminMode(String command)
|
||||
{
|
||||
this.modeName = command;
|
||||
}
|
||||
|
||||
public String getModeName()
|
||||
{
|
||||
return modeName;
|
||||
}
|
||||
|
||||
public static GadminMode findMode(String needle)
|
||||
{
|
||||
for (final GadminMode mode : GadminMode.values())
|
||||
{
|
||||
if (needle.equalsIgnoreCase(mode.getModeName()))
|
||||
{
|
||||
return mode;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
@ -26,22 +63,29 @@ public class Command_gadmin extends TFM_Command
|
||||
return false;
|
||||
}
|
||||
|
||||
final String mode = args[0].toLowerCase();
|
||||
|
||||
if (mode.equals("list"))
|
||||
final GadminMode mode = GadminMode.findMode(args[0].toLowerCase());
|
||||
if (mode == null)
|
||||
{
|
||||
playerMsg("[ Real Name ] : [ Display Name ] - Hash:");
|
||||
playerMsg("Invalid mode: " + args[0], ChatColor.RED);
|
||||
return true;
|
||||
}
|
||||
|
||||
for (Player player : server.getOnlinePlayers())
|
||||
final Iterator<Player> it = Arrays.asList(server.getOnlinePlayers()).iterator();
|
||||
|
||||
if (mode == GadminMode.LIST)
|
||||
{
|
||||
String hash = TFM_Util.getUuid(player).toString().substring(0, 4);
|
||||
if (mode.equals("list"))
|
||||
playerMsg("[ Real Name ] : [ Display Name ] - Hash:");
|
||||
while (it.hasNext())
|
||||
{
|
||||
final Player player = it.next();
|
||||
final String hash = TFM_Util.getUuid(player).toString().substring(0, 4);
|
||||
sender.sendMessage(ChatColor.GRAY + String.format("[ %s ] : [ %s ] - %s",
|
||||
player.getName(),
|
||||
ChatColor.stripColor(player.getDisplayName()),
|
||||
hash));
|
||||
hash
|
||||
));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args.length < 2)
|
||||
@ -49,81 +93,112 @@ public class Command_gadmin extends TFM_Command
|
||||
return false;
|
||||
}
|
||||
|
||||
Player target = null;
|
||||
while (it.hasNext() && target == null)
|
||||
{
|
||||
final Player player = it.next();
|
||||
final String hash = TFM_Util.getUuid(player).toString().substring(0, 4);
|
||||
|
||||
if (hash.equalsIgnoreCase(args[1]))
|
||||
{
|
||||
if (mode.equals("kick"))
|
||||
{
|
||||
TFM_Util.adminAction(sender.getName(), String.format("Kicking: %s.", player.getName()), false);
|
||||
player.kickPlayer("Kicked by Administrator");
|
||||
target = player;
|
||||
}
|
||||
}
|
||||
else if (mode.equals("nameban"))
|
||||
{
|
||||
TFM_BanManager.addUuidBan(player);
|
||||
|
||||
TFM_Util.adminAction(sender.getName(), String.format("Banning Name: %s.", player.getName()), true);
|
||||
player.kickPlayer("Username banned by Administrator.");
|
||||
}
|
||||
else if (mode.equals("ipban"))
|
||||
if (target == null)
|
||||
{
|
||||
String ip = player.getAddress().getAddress().getHostAddress();
|
||||
playerMsg("Invalid player hash: " + args[1], ChatColor.RED);
|
||||
return true;
|
||||
}
|
||||
|
||||
switch (mode)
|
||||
{
|
||||
case KICK:
|
||||
{
|
||||
TFM_Util.adminAction(sender.getName(), String.format("Kicking: %s.", target.getName()), false);
|
||||
target.kickPlayer("Kicked by Administrator");
|
||||
|
||||
break;
|
||||
}
|
||||
case NAMEBAN:
|
||||
{
|
||||
TFM_BanManager.addUuidBan(target);
|
||||
|
||||
TFM_Util.adminAction(sender.getName(), String.format("Banning Name: %s.", target.getName()), true);
|
||||
target.kickPlayer("Username banned by Administrator.");
|
||||
|
||||
break;
|
||||
}
|
||||
case IPBAN:
|
||||
{
|
||||
String ip = target.getAddress().getAddress().getHostAddress();
|
||||
String[] ip_parts = ip.split("\\.");
|
||||
if (ip_parts.length == 4)
|
||||
{
|
||||
ip = String.format("%s.%s.*.*", ip_parts[0], ip_parts[1]);
|
||||
}
|
||||
TFM_Util.adminAction(sender.getName(), String.format("Banning IP: %s.", player.getName(), ip), true);
|
||||
TFM_BanManager.addIpBan(player);
|
||||
TFM_Util.adminAction(sender.getName(), String.format("Banning IP: %s.", target.getName(), ip), true);
|
||||
TFM_BanManager.addIpBan(target);
|
||||
|
||||
player.kickPlayer("IP address banned by Administrator.");
|
||||
target.kickPlayer("IP address banned by Administrator.");
|
||||
|
||||
break;
|
||||
}
|
||||
else if (mode.equals("ban"))
|
||||
case BAN:
|
||||
{
|
||||
String ip = player.getAddress().getAddress().getHostAddress();
|
||||
String ip = target.getAddress().getAddress().getHostAddress();
|
||||
String[] ip_parts = ip.split("\\.");
|
||||
if (ip_parts.length == 4)
|
||||
{
|
||||
ip = String.format("%s.%s.*.*", ip_parts[0], ip_parts[1]);
|
||||
}
|
||||
TFM_Util.adminAction(sender.getName(), String.format("Banning Name: %s, IP: %s.", player.getName(), ip), true);
|
||||
TFM_Util.adminAction(sender.getName(), String.format("Banning Name: %s, IP: %s.", target.getName(), ip), true);
|
||||
|
||||
TFM_BanManager.addUuidBan(player);
|
||||
TFM_BanManager.addIpBan(player);
|
||||
TFM_BanManager.addUuidBan(target);
|
||||
TFM_BanManager.addIpBan(target);
|
||||
|
||||
player.kickPlayer("IP and username banned by Administrator.");
|
||||
target.kickPlayer("IP and username banned by Administrator.");
|
||||
|
||||
break;
|
||||
}
|
||||
else if (mode.equals("op"))
|
||||
case OP:
|
||||
{
|
||||
TFM_Util.adminAction(sender.getName(), String.format("Opping %s.", player.getName()), false);
|
||||
player.setOp(false);
|
||||
player.sendMessage(TotalFreedomMod.YOU_ARE_OP);
|
||||
TFM_Util.adminAction(sender.getName(), String.format("Opping %s.", target.getName()), false);
|
||||
target.setOp(false);
|
||||
target.sendMessage(TotalFreedomMod.YOU_ARE_OP);
|
||||
|
||||
break;
|
||||
}
|
||||
else if (mode.equals("deop"))
|
||||
case DEOP:
|
||||
{
|
||||
TFM_Util.adminAction(sender.getName(), String.format("Deopping %s.", player.getName()), false);
|
||||
player.setOp(false);
|
||||
player.sendMessage(TotalFreedomMod.YOU_ARE_NOT_OP);
|
||||
TFM_Util.adminAction(sender.getName(), String.format("Deopping %s.", target.getName()), false);
|
||||
target.setOp(false);
|
||||
target.sendMessage(TotalFreedomMod.YOU_ARE_NOT_OP);
|
||||
|
||||
break;
|
||||
}
|
||||
else if (mode.equals("ci"))
|
||||
case CI:
|
||||
{
|
||||
player.getInventory().clear();
|
||||
target.getInventory().clear();
|
||||
|
||||
break;
|
||||
}
|
||||
else if (mode.equals("fr"))
|
||||
case FR:
|
||||
{
|
||||
TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player);
|
||||
TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(target);
|
||||
playerdata.setFrozen(!playerdata.isFrozen());
|
||||
|
||||
playerMsg(player.getName() + " has been " + (playerdata.isFrozen() ? "frozen" : "unfrozen") + ".");
|
||||
player.sendMessage(ChatColor.AQUA + "You have been " + (playerdata.isFrozen() ? "frozen" : "unfrozen") + ".");
|
||||
}
|
||||
playerMsg(target.getName() + " has been " + (playerdata.isFrozen() ? "frozen" : "unfrozen") + ".");
|
||||
target.sendMessage(ChatColor.AQUA + "You have been " + (playerdata.isFrozen() ? "frozen" : "unfrozen") + ".");
|
||||
|
||||
return true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!mode.equals("list"))
|
||||
case SMITE:
|
||||
{
|
||||
playerMsg("Invalid hash.", ChatColor.RED);
|
||||
Command_smite.smite(target);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
|
Loading…
Reference in New Issue
Block a user