TotalFreedomMod/src/main/java/me/totalfreedom/totalfreedommod/command/Command_gadmin.java

210 lines
6.5 KiB
Java
Raw Normal View History

package me.totalfreedom.totalfreedommod.command;
2011-10-19 00:37:00 +00:00
import java.nio.charset.StandardCharsets;
2014-07-26 03:11:44 +00:00
import java.util.Iterator;
import java.util.UUID;
import me.totalfreedom.totalfreedommod.banning.Ban;
import me.totalfreedom.totalfreedommod.freeze.FreezeData;
import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.util.FUtil;
2011-10-19 00:37:00 +00:00
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandPermissions(level = Rank.SUPER_ADMIN, source = SourceType.BOTH, blockHostConsole = true)
@CommandParameters(
2014-07-26 03:11:44 +00:00
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 FreedomCommand
2011-10-19 00:37:00 +00:00
{
2014-07-26 03:11:44 +00:00
private enum GadminMode
{
2014-07-26 03:11:44 +00:00
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;
}
}
public String getPlayerHash(Player player)
{
return UUID.nameUUIDFromBytes(player.getName().toLowerCase().getBytes(StandardCharsets.UTF_8)).toString().substring(0, 4);
}
2011-10-19 00:37:00 +00:00
@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
2011-10-19 00:37:00 +00:00
{
if (args.length == 0)
{
return false;
}
2014-07-26 03:11:44 +00:00
final GadminMode mode = GadminMode.findMode(args[0].toLowerCase());
if (mode == null)
2011-10-19 00:37:00 +00:00
{
msg("Invalid mode: " + args[0], ChatColor.RED);
2014-07-26 03:11:44 +00:00
return true;
}
final Iterator<? extends Player> it = server.getOnlinePlayers().iterator();
2014-07-26 03:11:44 +00:00
if (mode == GadminMode.LIST)
{
msg("[ Real Name ] : [ Display Name ] - Hash:");
2014-07-26 03:11:44 +00:00
while (it.hasNext())
2011-10-19 00:37:00 +00:00
{
2014-07-26 03:11:44 +00:00
final Player player = it.next();
sender.sendMessage(ChatColor.GRAY + String.format("[ %s ] : [ %s ] - %s",
2013-08-14 14:01:42 +00:00
player.getName(),
ChatColor.stripColor(player.getDisplayName()),
getPlayerHash(player)));
2011-10-19 00:37:00 +00:00
}
2014-07-26 03:11:44 +00:00
return true;
}
2014-07-26 03:11:44 +00:00
if (args.length < 2)
{
return false;
}
Player target = null;
while (it.hasNext() && target == null)
{
final Player player = it.next();
final String hash = getPlayerHash(player);
2014-07-26 03:11:44 +00:00
if (hash.equalsIgnoreCase(args[1]))
{
2014-07-26 03:11:44 +00:00
target = player;
}
2014-07-26 03:11:44 +00:00
}
2014-07-26 03:11:44 +00:00
if (target == null)
{
msg("Invalid player hash: " + args[1], ChatColor.RED);
2014-07-26 03:11:44 +00:00
return true;
}
2014-07-26 03:11:44 +00:00
switch (mode)
{
case KICK:
2011-10-19 00:37:00 +00:00
{
FUtil.adminAction(sender.getName(), String.format("Kicking: %s.", target.getName()), false);
2014-07-26 03:11:44 +00:00
target.kickPlayer("Kicked by Administrator");
2014-06-29 08:53:39 +00:00
2014-07-26 03:11:44 +00:00
break;
}
case NAMEBAN:
{
FUtil.adminAction(sender.getName(), String.format("Banning Name: %s.", target.getName()), true);
plugin.bm.addBan(Ban.forPlayerName(target, sender, null, null));
2014-07-26 03:11:44 +00:00
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)
{
2014-07-26 03:11:44 +00:00
ip = String.format("%s.%s.*.*", ip_parts[0], ip_parts[1]);
}
FUtil.adminAction(sender.getName(), String.format("Banning IP: %s.", ip), true);
plugin.bm.addBan(Ban.forPlayerIp(ip, sender, null, null));
2014-07-26 03:11:44 +00:00
target.kickPlayer("IP address banned by Administrator.");
break;
}
case BAN:
{
String ip = target.getAddress().getAddress().getHostAddress();
String[] ip_parts = ip.split("\\.");
if (ip_parts.length == 4)
{
2014-07-26 03:11:44 +00:00
ip = String.format("%s.%s.*.*", ip_parts[0], ip_parts[1]);
}
FUtil.adminAction(sender.getName(), String.format("Banning Name: %s, IP: %s.", target.getName(), ip), true);
2011-10-19 00:37:00 +00:00
plugin.bm.addBan(Ban.forPlayer(target, sender));
2011-10-19 00:37:00 +00:00
2014-07-26 03:11:44 +00:00
target.kickPlayer("IP and username banned by Administrator.");
break;
2011-10-19 00:37:00 +00:00
}
2014-07-26 03:11:44 +00:00
case OP:
{
FUtil.adminAction(sender.getName(), String.format("Opping %s.", target.getName()), false);
TotalFreedomMod Electrum Version 5.0 This TotalFreedomMod release implements many changes. Most notably, the internals have been completely revamped. TotalFreedomMod now relies on the Aero library for core mechanics such as command handling and services. Another important change is the UUID system. In TotalFreedomMod Electrum, it has been completely removed. The core reason for this is that the system as a whole was very bugged. Additionally, it did not solve the primary reason for its conception: preserving player data when the player changes their username. This is because TotalFreedomMod servers usually run in offline-mode. This meaning that some of the players joining do not have a registerd Mojang UUID whatsoever. All in all, the UUID system was buggy, and it did not fix the reason it was implemented, so it has been completely removed. The admin list and the ban list now use usernames and IPs again. Lastly, many smaller changes have been implemented. Due to the amount of changes, they have not been named individualy. Please refer to the issues below for more details. Fixes #342 Fixes #350 Fixes #380 Fixes #684 Fixes #704 Fixes #716 Fixes #735 Fixes #745 Fixes #784 Fixes #765 Fixes #791 Fixes #805 Fixes #826 Fixes #883 Fixes #1524 Fixes #1534 Fixes #1536 Fixes #1538 Fixes #1545 Fixes #1546 Fixes #1568 Fixes #1627 Resolves #403 Resolves #435 Resolves #597 Resolves #603 Resolves #628 Resolves #690 Resolves #708 Resolves #747 Resolves #748 Resolves #749 Resolves #764 Resolves #767 Resolves #782 Resolves #809 Resolves #803 Resolves #811 Resolves #813 Resolves #830 Resolves #848 Resolves #856 Resolves #876 Resolves #908 Resolves #992 Resolves #1018 Resolves #1432 Resolves #1446 Resolves #1494 Resolves #1501 Resolves #1526 Resolves #1540 Resolves #1550 Resolves #1560 Resolves #1561 Resolves #1578 Resolves #1613
2016-05-12 19:40:39 +00:00
target.setOp(true);
target.sendMessage(FreedomCommand.YOU_ARE_OP);
2014-07-26 03:11:44 +00:00
break;
}
case DEOP:
{
FUtil.adminAction(sender.getName(), String.format("Deopping %s.", target.getName()), false);
2014-07-26 03:11:44 +00:00
target.setOp(false);
target.sendMessage(FreedomCommand.YOU_ARE_NOT_OP);
2014-07-26 03:11:44 +00:00
break;
}
case CI:
{
target.getInventory().clear();
break;
}
case FR:
{
FreezeData fd = plugin.pl.getPlayer(target).getFreezeData();
fd.setFrozen(!fd.isFrozen());
2014-07-26 03:11:44 +00:00
msg(target.getName() + " has been " + (fd.isFrozen() ? "frozen" : "unfrozen") + ".");
target.sendMessage(ChatColor.AQUA + "You have been " + (fd.isFrozen() ? "frozen" : "unfrozen") + ".");
2014-07-26 03:11:44 +00:00
break;
}
case SMITE:
{
Command_smite.smite(target);
break;
}
2011-10-19 00:37:00 +00:00
}
return true;
}
}