| 1 | package net.minecraft.command;
|
| 2 |
|
| 3 | import java.util.List;
|
| 4 | import net.minecraft.server.MinecraftServer;
|
| 5 | import net.minecraft.util.BlockPos;
|
| 6 | import net.minecraft.util.ChatComponentTranslation;
|
| 7 | import net.minecraft.util.MathHelper;
|
| 8 | import net.minecraft.world.border.WorldBorder;
|
| 9 |
|
| 10 | public class CommandWorldBorder extends CommandBase
|
| 11 | {
|
| 12 | /**
|
| 13 | * Gets the name of the command
|
| 14 | */
|
| 15 | public String getCommandName()
|
| 16 | {
|
| 17 | return "worldborder";
|
| 18 | }
|
| 19 |
|
| 20 | /**
|
| 21 | * Return the required permission level for this command.
|
| 22 | */
|
| 23 | public int getRequiredPermissionLevel()
|
| 24 | {
|
| 25 | return 2;
|
| 26 | }
|
| 27 |
|
| 28 | /**
|
| 29 | * Gets the usage string for the command.
|
| 30 | */
|
| 31 | public String getCommandUsage(ICommandSender sender)
|
| 32 | {
|
| 33 | return "commands.worldborder.usage";
|
| 34 | }
|
| 35 |
|
| 36 | /**
|
| 37 | * Callback when the command is invoked
|
| 38 | */
|
| 39 | public void processCommand(ICommandSender sender, String[] args) throws CommandException
|
| 40 | {
|
| 41 | if (args.length < 1)
|
| 42 | {
|
| 43 | throw new WrongUsageException("commands.worldborder.usage", new Object[0]);
|
| 44 | }
|
| 45 | else
|
| 46 | {
|
| 47 | WorldBorder worldborder = this.getWorldBorder();
|
| 48 |
|
| 49 | if (args[0].equals("set"))
|
| 50 | {
|
| 51 | if (args.length != 2 && args.length != 3)
|
| 52 | {
|
| 53 | throw new WrongUsageException("commands.worldborder.set.usage", new Object[0]);
|
| 54 | }
|
| 55 |
|
| 56 | double d0 = worldborder.getTargetSize();
|
| 57 | double d2 = parseDouble(args[1], 1.0D, 6.0E7D);
|
| 58 | long i = args.length > 2 ? parseLong(args[2], 0L, 9223372036854775L) * 1000L : 0L;
|
| 59 |
|
| 60 | if (i > 0L)
|
| 61 | {
|
| 62 | worldborder.setTransition(d0, d2, i);
|
| 63 |
|
| 64 | if (d0 > d2)
|
| 65 | {
|
| 66 | notifyOperators(sender, this, "commands.worldborder.setSlowly.shrink.success", new Object[] {String.format("%.1f", new Object[]{Double.valueOf(d2)}), String.format("%.1f", new Object[]{Double.valueOf(d0)}), Long.toString(i / 1000L)});
|
| 67 | }
|
| 68 | else
|
| 69 | {
|
| 70 | notifyOperators(sender, this, "commands.worldborder.setSlowly.grow.success", new Object[] {String.format("%.1f", new Object[]{Double.valueOf(d2)}), String.format("%.1f", new Object[]{Double.valueOf(d0)}), Long.toString(i / 1000L)});
|
| 71 | }
|
| 72 | }
|
| 73 | else
|
| 74 | {
|
| 75 | worldborder.setTransition(d2);
|
| 76 | notifyOperators(sender, this, "commands.worldborder.set.success", new Object[] {String.format("%.1f", new Object[]{Double.valueOf(d2)}), String.format("%.1f", new Object[]{Double.valueOf(d0)})});
|
| 77 | }
|
| 78 | }
|
| 79 | else if (args[0].equals("add"))
|
| 80 | {
|
| 81 | if (args.length != 2 && args.length != 3)
|
| 82 | {
|
| 83 | throw new WrongUsageException("commands.worldborder.add.usage", new Object[0]);
|
| 84 | }
|
| 85 |
|
| 86 | double d4 = worldborder.getDiameter();
|
| 87 | double d8 = d4 + parseDouble(args[1], -d4, 6.0E7D - d4);
|
| 88 | long i1 = worldborder.getTimeUntilTarget() + (args.length > 2 ? parseLong(args[2], 0L, 9223372036854775L) * 1000L : 0L);
|
| 89 |
|
| 90 | if (i1 > 0L)
|
| 91 | {
|
| 92 | worldborder.setTransition(d4, d8, i1);
|
| 93 |
|
| 94 | if (d4 > d8)
|
| 95 | {
|
| 96 | notifyOperators(sender, this, "commands.worldborder.setSlowly.shrink.success", new Object[] {String.format("%.1f", new Object[]{Double.valueOf(d8)}), String.format("%.1f", new Object[]{Double.valueOf(d4)}), Long.toString(i1 / 1000L)});
|
| 97 | }
|
| 98 | else
|
| 99 | {
|
| 100 | notifyOperators(sender, this, "commands.worldborder.setSlowly.grow.success", new Object[] {String.format("%.1f", new Object[]{Double.valueOf(d8)}), String.format("%.1f", new Object[]{Double.valueOf(d4)}), Long.toString(i1 / 1000L)});
|
| 101 | }
|
| 102 | }
|
| 103 | else
|
| 104 | {
|
| 105 | worldborder.setTransition(d8);
|
| 106 | notifyOperators(sender, this, "commands.worldborder.set.success", new Object[] {String.format("%.1f", new Object[]{Double.valueOf(d8)}), String.format("%.1f", new Object[]{Double.valueOf(d4)})});
|
| 107 | }
|
| 108 | }
|
| 109 | else if (args[0].equals("center"))
|
| 110 | {
|
| 111 | if (args.length != 3)
|
| 112 | {
|
| 113 | throw new WrongUsageException("commands.worldborder.center.usage", new Object[0]);
|
| 114 | }
|
| 115 |
|
| 116 | BlockPos blockpos = sender.getPosition();
|
| 117 | double d1 = parseDouble((double)blockpos.getX() + 0.5D, args[1], true);
|
| 118 | double d3 = parseDouble((double)blockpos.getZ() + 0.5D, args[2], true);
|
| 119 | worldborder.setCenter(d1, d3);
|
| 120 | notifyOperators(sender, this, "commands.worldborder.center.success", new Object[] {Double.valueOf(d1), Double.valueOf(d3)});
|
| 121 | }
|
| 122 | else if (args[0].equals("damage"))
|
| 123 | {
|
| 124 | if (args.length < 2)
|
| 125 | {
|
| 126 | throw new WrongUsageException("commands.worldborder.damage.usage", new Object[0]);
|
| 127 | }
|
| 128 |
|
| 129 | if (args[1].equals("buffer"))
|
| 130 | {
|
| 131 | if (args.length != 3)
|
| 132 | {
|
| 133 | throw new WrongUsageException("commands.worldborder.damage.buffer.usage", new Object[0]);
|
| 134 | }
|
| 135 |
|
| 136 | double d5 = parseDouble(args[2], 0.0D);
|
| 137 | double d9 = worldborder.getDamageBuffer();
|
| 138 | worldborder.setDamageBuffer(d5);
|
| 139 | notifyOperators(sender, this, "commands.worldborder.damage.buffer.success", new Object[] {String.format("%.1f", new Object[]{Double.valueOf(d5)}), String.format("%.1f", new Object[]{Double.valueOf(d9)})});
|
| 140 | }
|
| 141 | else if (args[1].equals("amount"))
|
| 142 | {
|
| 143 | if (args.length != 3)
|
| 144 | {
|
| 145 | throw new WrongUsageException("commands.worldborder.damage.amount.usage", new Object[0]);
|
| 146 | }
|
| 147 |
|
| 148 | double d6 = parseDouble(args[2], 0.0D);
|
| 149 | double d10 = worldborder.getDamageAmount();
|
| 150 | worldborder.setDamageAmount(d6);
|
| 151 | notifyOperators(sender, this, "commands.worldborder.damage.amount.success", new Object[] {String.format("%.2f", new Object[]{Double.valueOf(d6)}), String.format("%.2f", new Object[]{Double.valueOf(d10)})});
|
| 152 | }
|
| 153 | }
|
| 154 | else if (args[0].equals("warning"))
|
| 155 | {
|
| 156 | if (args.length < 2)
|
| 157 | {
|
| 158 | throw new WrongUsageException("commands.worldborder.warning.usage", new Object[0]);
|
| 159 | }
|
| 160 |
|
| 161 | int j = parseInt(args[2], 0);
|
| 162 |
|
| 163 | if (args[1].equals("time"))
|
| 164 | {
|
| 165 | if (args.length != 3)
|
| 166 | {
|
| 167 | throw new WrongUsageException("commands.worldborder.warning.time.usage", new Object[0]);
|
| 168 | }
|
| 169 |
|
| 170 | int k = worldborder.getWarningTime();
|
| 171 | worldborder.setWarningTime(j);
|
| 172 | notifyOperators(sender, this, "commands.worldborder.warning.time.success", new Object[] {Integer.valueOf(j), Integer.valueOf(k)});
|
| 173 | }
|
| 174 | else if (args[1].equals("distance"))
|
| 175 | {
|
| 176 | if (args.length != 3)
|
| 177 | {
|
| 178 | throw new WrongUsageException("commands.worldborder.warning.distance.usage", new Object[0]);
|
| 179 | }
|
| 180 |
|
| 181 | int l = worldborder.getWarningDistance();
|
| 182 | worldborder.setWarningDistance(j);
|
| 183 | notifyOperators(sender, this, "commands.worldborder.warning.distance.success", new Object[] {Integer.valueOf(j), Integer.valueOf(l)});
|
| 184 | }
|
| 185 | }
|
| 186 | else
|
| 187 | {
|
| 188 | if (!args[0].equals("get"))
|
| 189 | {
|
| 190 | throw new WrongUsageException("commands.worldborder.usage", new Object[0]);
|
| 191 | }
|
| 192 |
|
| 193 | double d7 = worldborder.getDiameter();
|
| 194 | sender.setCommandStat(CommandResultStats.Type.QUERY_RESULT, MathHelper.floor_double(d7 + 0.5D));
|
| 195 | sender.addChatMessage(new ChatComponentTranslation("commands.worldborder.get.success", new Object[] {String.format("%.0f", new Object[]{Double.valueOf(d7)})}));
|
| 196 | }
|
| 197 | }
|
| 198 | }
|
| 199 |
|
| 200 | protected WorldBorder getWorldBorder()
|
| 201 | {
|
| 202 | return MinecraftServer.getServer().worldServers[0].getWorldBorder();
|
| 203 | }
|
| 204 |
|
| 205 | public List<String> addTabCompletionOptions(ICommandSender sender, String[] args, BlockPos pos)
|
| 206 | {
|
| 207 | return args.length == 1 ? getListOfStringsMatchingLastWord(args, new String[] {"set", "center", "damage", "warning", "add", "get"}): (args.length == 2 && args[0].equals("damage") ? getListOfStringsMatchingLastWord(args, new String[] {"buffer", "amount"}): (args.length >= 2 && args.length <= 3 && args[0].equals("center") ? func_181043_b(args, 1, pos) : (args.length == 2 && args[0].equals("warning") ? getListOfStringsMatchingLastWord(args, new String[] {"time", "distance"}): null)));
|
| 208 | }
|
| 209 | }
|
| 210 |
|