| 1 | package net.minecraft.command.server;
|
| 2 |
|
| 3 | import java.util.EnumSet;
|
| 4 | import java.util.List;
|
| 5 | import java.util.Set;
|
| 6 | import net.minecraft.command.CommandBase;
|
| 7 | import net.minecraft.command.CommandException;
|
| 8 | import net.minecraft.command.ICommandSender;
|
| 9 | import net.minecraft.command.WrongUsageException;
|
| 10 | import net.minecraft.entity.Entity;
|
| 11 | import net.minecraft.entity.player.EntityPlayerMP;
|
| 12 | import net.minecraft.network.play.server.S08PacketPlayerPosLook;
|
| 13 | import net.minecraft.server.MinecraftServer;
|
| 14 | import net.minecraft.util.BlockPos;
|
| 15 | import net.minecraft.util.MathHelper;
|
| 16 |
|
| 17 | public class CommandTeleport extends CommandBase
|
| 18 | {
|
| 19 | /**
|
| 20 | * Gets the name of the command
|
| 21 | */
|
| 22 | public String getCommandName()
|
| 23 | {
|
| 24 | return "tp";
|
| 25 | }
|
| 26 |
|
| 27 | /**
|
| 28 | * Return the required permission level for this command.
|
| 29 | */
|
| 30 | public int getRequiredPermissionLevel()
|
| 31 | {
|
| 32 | return 2;
|
| 33 | }
|
| 34 |
|
| 35 | /**
|
| 36 | * Gets the usage string for the command.
|
| 37 | */
|
| 38 | public String getCommandUsage(ICommandSender sender)
|
| 39 | {
|
| 40 | return "commands.tp.usage";
|
| 41 | }
|
| 42 |
|
| 43 | /**
|
| 44 | * Callback when the command is invoked
|
| 45 | */
|
| 46 | public void processCommand(ICommandSender sender, String[] args) throws CommandException
|
| 47 | {
|
| 48 | if (args.length < 1)
|
| 49 | {
|
| 50 | throw new WrongUsageException("commands.tp.usage", new Object[0]);
|
| 51 | }
|
| 52 | else
|
| 53 | {
|
| 54 | int i = 0;
|
| 55 | Entity entity;
|
| 56 |
|
| 57 | if (args.length != 2 && args.length != 4 && args.length != 6)
|
| 58 | {
|
| 59 | entity = getCommandSenderAsPlayer(sender);
|
| 60 | }
|
| 61 | else
|
| 62 | {
|
| 63 | entity = getEntity(sender, args[0]);
|
| 64 | i = 1;
|
| 65 | }
|
| 66 |
|
| 67 | if (args.length != 1 && args.length != 2)
|
| 68 | {
|
| 69 | if (args.length < i + 3)
|
| 70 | {
|
| 71 | throw new WrongUsageException("commands.tp.usage", new Object[0]);
|
| 72 | }
|
| 73 | else if (entity.worldObj != null)
|
| 74 | {
|
| 75 | int lvt_5_2_ = i + 1;
|
| 76 | CommandBase.CoordinateArg commandbase$coordinatearg = parseCoordinate(entity.posX, args[i], true);
|
| 77 | CommandBase.CoordinateArg commandbase$coordinatearg1 = parseCoordinate(entity.posY, args[lvt_5_2_++], 0, 0, false);
|
| 78 | CommandBase.CoordinateArg commandbase$coordinatearg2 = parseCoordinate(entity.posZ, args[lvt_5_2_++], true);
|
| 79 | CommandBase.CoordinateArg commandbase$coordinatearg3 = parseCoordinate((double)entity.rotationYaw, args.length > lvt_5_2_ ? args[lvt_5_2_++] : "~", false);
|
| 80 | CommandBase.CoordinateArg commandbase$coordinatearg4 = parseCoordinate((double)entity.rotationPitch, args.length > lvt_5_2_ ? args[lvt_5_2_] : "~", false);
|
| 81 |
|
| 82 | if (entity instanceof EntityPlayerMP)
|
| 83 | {
|
| 84 | Set<S08PacketPlayerPosLook.EnumFlags> set = EnumSet.<S08PacketPlayerPosLook.EnumFlags>noneOf(S08PacketPlayerPosLook.EnumFlags.class);
|
| 85 |
|
| 86 | if (commandbase$coordinatearg.func_179630_c())
|
| 87 | {
|
| 88 | set.add(S08PacketPlayerPosLook.EnumFlags.X);
|
| 89 | }
|
| 90 |
|
| 91 | if (commandbase$coordinatearg1.func_179630_c())
|
| 92 | {
|
| 93 | set.add(S08PacketPlayerPosLook.EnumFlags.Y);
|
| 94 | }
|
| 95 |
|
| 96 | if (commandbase$coordinatearg2.func_179630_c())
|
| 97 | {
|
| 98 | set.add(S08PacketPlayerPosLook.EnumFlags.Z);
|
| 99 | }
|
| 100 |
|
| 101 | if (commandbase$coordinatearg4.func_179630_c())
|
| 102 | {
|
| 103 | set.add(S08PacketPlayerPosLook.EnumFlags.X_ROT);
|
| 104 | }
|
| 105 |
|
| 106 | if (commandbase$coordinatearg3.func_179630_c())
|
| 107 | {
|
| 108 | set.add(S08PacketPlayerPosLook.EnumFlags.Y_ROT);
|
| 109 | }
|
| 110 |
|
| 111 | float f = (float)commandbase$coordinatearg3.func_179629_b();
|
| 112 |
|
| 113 | if (!commandbase$coordinatearg3.func_179630_c())
|
| 114 | {
|
| 115 | f = MathHelper.wrapAngleTo180_float(f);
|
| 116 | }
|
| 117 |
|
| 118 | float f1 = (float)commandbase$coordinatearg4.func_179629_b();
|
| 119 |
|
| 120 | if (!commandbase$coordinatearg4.func_179630_c())
|
| 121 | {
|
| 122 | f1 = MathHelper.wrapAngleTo180_float(f1);
|
| 123 | }
|
| 124 |
|
| 125 | if (f1 > 90.0F || f1 < -90.0F)
|
| 126 | {
|
| 127 | f1 = MathHelper.wrapAngleTo180_float(180.0F - f1);
|
| 128 | f = MathHelper.wrapAngleTo180_float(f + 180.0F);
|
| 129 | }
|
| 130 |
|
| 131 | entity.mountEntity((Entity)null);
|
| 132 | ((EntityPlayerMP)entity).playerNetServerHandler.setPlayerLocation(commandbase$coordinatearg.func_179629_b(), commandbase$coordinatearg1.func_179629_b(), commandbase$coordinatearg2.func_179629_b(), f, f1, set);
|
| 133 | entity.setRotationYawHead(f);
|
| 134 | }
|
| 135 | else
|
| 136 | {
|
| 137 | float f2 = (float)MathHelper.wrapAngleTo180_double(commandbase$coordinatearg3.func_179628_a());
|
| 138 | float f3 = (float)MathHelper.wrapAngleTo180_double(commandbase$coordinatearg4.func_179628_a());
|
| 139 |
|
| 140 | if (f3 > 90.0F || f3 < -90.0F)
|
| 141 | {
|
| 142 | f3 = MathHelper.wrapAngleTo180_float(180.0F - f3);
|
| 143 | f2 = MathHelper.wrapAngleTo180_float(f2 + 180.0F);
|
| 144 | }
|
| 145 |
|
| 146 | entity.setLocationAndAngles(commandbase$coordinatearg.func_179628_a(), commandbase$coordinatearg1.func_179628_a(), commandbase$coordinatearg2.func_179628_a(), f2, f3);
|
| 147 | entity.setRotationYawHead(f2);
|
| 148 | }
|
| 149 |
|
| 150 | notifyOperators(sender, this, "commands.tp.success.coordinates", new Object[] {entity.getName(), Double.valueOf(commandbase$coordinatearg.func_179628_a()), Double.valueOf(commandbase$coordinatearg1.func_179628_a()), Double.valueOf(commandbase$coordinatearg2.func_179628_a())});
|
| 151 | }
|
| 152 | }
|
| 153 | else
|
| 154 | {
|
| 155 | Entity entity1 = getEntity(sender, args[args.length - 1]);
|
| 156 |
|
| 157 | if (entity1.worldObj != entity.worldObj)
|
| 158 | {
|
| 159 | throw new CommandException("commands.tp.notSameDimension", new Object[0]);
|
| 160 | }
|
| 161 | else
|
| 162 | {
|
| 163 | entity.mountEntity((Entity)null);
|
| 164 |
|
| 165 | if (entity instanceof EntityPlayerMP)
|
| 166 | {
|
| 167 | ((EntityPlayerMP)entity).playerNetServerHandler.setPlayerLocation(entity1.posX, entity1.posY, entity1.posZ, entity1.rotationYaw, entity1.rotationPitch);
|
| 168 | }
|
| 169 | else
|
| 170 | {
|
| 171 | entity.setLocationAndAngles(entity1.posX, entity1.posY, entity1.posZ, entity1.rotationYaw, entity1.rotationPitch);
|
| 172 | }
|
| 173 |
|
| 174 | notifyOperators(sender, this, "commands.tp.success", new Object[] {entity.getName(), entity1.getName()});
|
| 175 | }
|
| 176 | }
|
| 177 | }
|
| 178 | }
|
| 179 |
|
| 180 | public List<String> addTabCompletionOptions(ICommandSender sender, String[] args, BlockPos pos)
|
| 181 | {
|
| 182 | return args.length != 1 && args.length != 2 ? null : getListOfStringsMatchingLastWord(args, MinecraftServer.getServer().getAllUsernames());
|
| 183 | }
|
| 184 |
|
| 185 | /**
|
| 186 | * Return whether the specified command parameter index is a username parameter.
|
| 187 | */
|
| 188 | public boolean isUsernameIndex(String[] args, int index)
|
| 189 | {
|
| 190 | return index == 0;
|
| 191 | }
|
| 192 | }
|
| 193 |
|