From 1d2f29165018df3a16a064570f99e40a12a79056 Mon Sep 17 00:00:00 2001 From: asofold Date: Thu, 29 Aug 2013 21:30:53 +0200 Subject: [PATCH] Add "ncp inspect (player)" command, might be merged/changed with info. --- .../command/NoCheatPlusCommand.java | 2 + .../command/admin/InspectCommand.java | 103 ++++++++++++++++++ .../nocheatplus/permissions/Permissions.java | 2 + NCPPlugin/src/main/resources/plugin.yml | 2 + 4 files changed, 109 insertions(+) create mode 100644 NCPCore/src/main/java/fr/neatmonster/nocheatplus/command/admin/InspectCommand.java diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/command/NoCheatPlusCommand.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/command/NoCheatPlusCommand.java index 454afc76..b477f3e0 100644 --- a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/command/NoCheatPlusCommand.java +++ b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/command/NoCheatPlusCommand.java @@ -20,6 +20,7 @@ import fr.neatmonster.nocheatplus.command.actions.UnKickCommand; import fr.neatmonster.nocheatplus.command.actions.delay.DelayCommand; import fr.neatmonster.nocheatplus.command.admin.CommandsCommand; import fr.neatmonster.nocheatplus.command.admin.InfoCommand; +import fr.neatmonster.nocheatplus.command.admin.InspectCommand; import fr.neatmonster.nocheatplus.command.admin.LagCommand; import fr.neatmonster.nocheatplus.command.admin.NCPVersionCommand; import fr.neatmonster.nocheatplus.command.admin.ReloadCommand; @@ -101,6 +102,7 @@ public class NoCheatPlusCommand extends BaseCommand{ new ExemptCommand(plugin), new ExemptionsCommand(plugin), new InfoCommand(plugin), + new InspectCommand(plugin), new KickCommand(plugin), new KickListCommand(plugin), new LagCommand(plugin), diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/command/admin/InspectCommand.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/command/admin/InspectCommand.java new file mode 100644 index 00000000..eaec6788 --- /dev/null +++ b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/command/admin/InspectCommand.java @@ -0,0 +1,103 @@ +package fr.neatmonster.nocheatplus.command.admin; + +import java.text.DecimalFormat; +import java.util.Collection; +import java.util.List; + +import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.bukkit.potion.PotionEffect; + +import fr.neatmonster.nocheatplus.command.BaseCommand; +import fr.neatmonster.nocheatplus.permissions.Permissions; +import fr.neatmonster.nocheatplus.players.DataManager; + +public class InspectCommand extends BaseCommand { + private final DecimalFormat f1 = new DecimalFormat("#.#"); + + public InspectCommand(JavaPlugin plugin) { + super(plugin, "inspect", Permissions.COMMAND_INSPECT); + } + + /* (non-Javadoc) + * @see fr.neatmonster.nocheatplus.command.AbstractCommand#onCommand(org.bukkit.command.CommandSender, org.bukkit.command.Command, java.lang.String, java.lang.String[]) + */ + @Override + public boolean onCommand(CommandSender sender, Command command, + String alias, String[] args) { + if (args.length == 1) { + if (sender instanceof Player) { + args = new String[]{args[0], sender.getName()}; + } else { + sender.sendMessage("[NoCheatPlus] Please specify a player to inspect."); + return true; + } + } + final String c1; + if (sender instanceof Player) { + c1 = ChatColor.GRAY.toString(); + } else { + c1 = ""; + } + for (int i = 1; i < args.length; i++) { + final Player player = DataManager.getPlayer(args[i].trim().toLowerCase()); + if (player == null) { + sender.sendMessage("(Not online: " + args[i] + ")"); + } else { + final StringBuilder builder = new StringBuilder(256); + builder.append(player.getName() + c1); + builder.append(" (" + (player.isOnline() ? "online" : "offline") + (player.isDead() ? ",dead" : "") + (player.isValid() ? "" : ",invalid") + (player.isInsideVehicle() ? (",vehicle=" + player.getVehicle().getType()) : "")+ "):"); + // TODO: isValid, isDead, isInsideVehicle ... + // Health. + builder.append(" health=" + f1.format(player.getHealth()) + "/" + f1.format(player.getMaxHealth())); + // Food. + builder.append(" food=" + player.getFoodLevel()); + // Exp. + if (player.getExp() > 0f) { + builder.append(" explvl=" + f1.format(player.getExpToLevel()) + "(exp=" + f1.format(player.getExp()) + ")"); + } + // Fly settings. + if (player.isFlying()) { + builder.append(" flying"); + } + if (player.getAllowFlight()) { + builder.append(" allowflight"); + } + // Speed settings. + builder.append(" flyspeed=" + player.getFlySpeed()); + builder.append(" walkspeed=" + player.getWalkSpeed()); + // Potion effects. + final Collection effects = player.getActivePotionEffects(); + if (!effects.isEmpty()) { + builder.append(" effects="); + for (final PotionEffect effect : effects) { + builder.append(effect.getType() + "@" + effect.getAmplifier() +","); + } + } + // TODO: is..sneaking,sprinting,blocking, + // Finally the block location. + final Location loc = player.getLocation(); + builder.append(" pos=" + loc.getWorld().getName() + "/" + loc.getBlockX() + "," + loc.getBlockY() + "," + loc.getBlockZ()); + sender.sendMessage(builder.toString()); + } + } + return true; + } + + /* (non-Javadoc) + * @see fr.neatmonster.nocheatplus.command.AbstractCommand#onTabComplete(org.bukkit.command.CommandSender, org.bukkit.command.Command, java.lang.String, java.lang.String[]) + */ + @Override + public List onTabComplete(CommandSender sender, Command command, + String alias, String[] args) { + // Complete players. + return null; + } + + + +} diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/permissions/Permissions.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/permissions/Permissions.java index 3a10197f..6ae61ecc 100644 --- a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/permissions/Permissions.java +++ b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/permissions/Permissions.java @@ -57,6 +57,8 @@ public class Permissions { public static final String COMMAND_TEMPKICK = COMMAND + ".tempkick"; public static final String COMMAND_UNKICK = COMMAND + ".unkick"; public static final String COMMAND_VERSION = COMMAND + ".version"; + + public static final String COMMAND_INSPECT = COMMAND + ".inspect"; // Permissions for the individual checks. diff --git a/NCPPlugin/src/main/resources/plugin.yml b/NCPPlugin/src/main/resources/plugin.yml index 6cc46610..88e8bc7b 100644 --- a/NCPPlugin/src/main/resources/plugin.yml +++ b/NCPPlugin/src/main/resources/plugin.yml @@ -268,6 +268,8 @@ permissions: description: Allow the player to reload NoCheatPlus configuration. nocheatplus.command.info: description: Allow to see violation info about a player. + nocheatplus.command.inspect: + description: Allow to see detailed information about online players. nocheatplus.command.exemptions: description: Allow to see exemptions for a player. nocheatplus.command.exempt: