| 1 | package net.minecraft.command.server;
|
| 2 |
|
| 3 | import java.util.List;
|
| 4 | import net.minecraft.command.CommandBase;
|
| 5 | import net.minecraft.command.CommandException;
|
| 6 | import net.minecraft.command.ICommandSender;
|
| 7 | import net.minecraft.command.WrongUsageException;
|
| 8 | import net.minecraft.entity.Entity;
|
| 9 | import net.minecraft.nbt.JsonToNBT;
|
| 10 | import net.minecraft.nbt.NBTException;
|
| 11 | import net.minecraft.nbt.NBTTagCompound;
|
| 12 | import net.minecraft.nbt.NBTUtil;
|
| 13 | import net.minecraft.server.MinecraftServer;
|
| 14 | import net.minecraft.util.BlockPos;
|
| 15 |
|
| 16 | public class CommandTestFor extends CommandBase
|
| 17 | {
|
| 18 | /**
|
| 19 | * Gets the name of the command
|
| 20 | */
|
| 21 | public String getCommandName()
|
| 22 | {
|
| 23 | return "testfor";
|
| 24 | }
|
| 25 |
|
| 26 | /**
|
| 27 | * Return the required permission level for this command.
|
| 28 | */
|
| 29 | public int getRequiredPermissionLevel()
|
| 30 | {
|
| 31 | return 2;
|
| 32 | }
|
| 33 |
|
| 34 | /**
|
| 35 | * Gets the usage string for the command.
|
| 36 | */
|
| 37 | public String getCommandUsage(ICommandSender sender)
|
| 38 | {
|
| 39 | return "commands.testfor.usage";
|
| 40 | }
|
| 41 |
|
| 42 | /**
|
| 43 | * Callback when the command is invoked
|
| 44 | */
|
| 45 | public void processCommand(ICommandSender sender, String[] args) throws CommandException
|
| 46 | {
|
| 47 | if (args.length < 1)
|
| 48 | {
|
| 49 | throw new WrongUsageException("commands.testfor.usage", new Object[0]);
|
| 50 | }
|
| 51 | else
|
| 52 | {
|
| 53 | Entity entity = getEntity(sender, args[0]);
|
| 54 | NBTTagCompound nbttagcompound = null;
|
| 55 |
|
| 56 | if (args.length >= 2)
|
| 57 | {
|
| 58 | try
|
| 59 | {
|
| 60 | nbttagcompound = JsonToNBT.getTagFromJson(buildString(args, 1));
|
| 61 | }
|
| 62 | catch (NBTException nbtexception)
|
| 63 | {
|
| 64 | throw new CommandException("commands.testfor.tagError", new Object[] {nbtexception.getMessage()});
|
| 65 | }
|
| 66 | }
|
| 67 |
|
| 68 | if (nbttagcompound != null)
|
| 69 | {
|
| 70 | NBTTagCompound nbttagcompound1 = new NBTTagCompound();
|
| 71 | entity.writeToNBT(nbttagcompound1);
|
| 72 |
|
| 73 | if (!NBTUtil.func_181123_a(nbttagcompound, nbttagcompound1, true))
|
| 74 | {
|
| 75 | throw new CommandException("commands.testfor.failure", new Object[] {entity.getName()});
|
| 76 | }
|
| 77 | }
|
| 78 |
|
| 79 | notifyOperators(sender, this, "commands.testfor.success", new Object[] {entity.getName()});
|
| 80 | }
|
| 81 | }
|
| 82 |
|
| 83 | /**
|
| 84 | * Return whether the specified command parameter index is a username parameter.
|
| 85 | */
|
| 86 | public boolean isUsernameIndex(String[] args, int index)
|
| 87 | {
|
| 88 | return index == 0;
|
| 89 | }
|
| 90 |
|
| 91 | public List<String> addTabCompletionOptions(ICommandSender sender, String[] args, BlockPos pos)
|
| 92 | {
|
| 93 | return args.length == 1 ? getListOfStringsMatchingLastWord(args, MinecraftServer.getServer().getAllUsernames()) : null;
|
| 94 | }
|
| 95 | }
|
| 96 |
|