| 1 | package net.minecraft.command;
|
| 2 |
|
| 3 | import com.google.common.base.Functions;
|
| 4 | import com.google.common.collect.Iterables;
|
| 5 | import com.google.common.collect.Lists;
|
| 6 | import com.google.common.primitives.Doubles;
|
| 7 | import java.util.Arrays;
|
| 8 | import java.util.Collection;
|
| 9 | import java.util.Collections;
|
| 10 | import java.util.List;
|
| 11 | import java.util.UUID;
|
| 12 | import net.minecraft.block.Block;
|
| 13 | import net.minecraft.entity.Entity;
|
| 14 | import net.minecraft.entity.player.EntityPlayerMP;
|
| 15 | import net.minecraft.item.Item;
|
| 16 | import net.minecraft.server.MinecraftServer;
|
| 17 | import net.minecraft.util.BlockPos;
|
| 18 | import net.minecraft.util.ChatComponentText;
|
| 19 | import net.minecraft.util.IChatComponent;
|
| 20 | import net.minecraft.util.ResourceLocation;
|
| 21 |
|
| 22 | public abstract class CommandBase implements ICommand
|
| 23 | {
|
| 24 | private static IAdminCommand theAdmin;
|
| 25 |
|
| 26 | /**
|
| 27 | * Return the required permission level for this command.
|
| 28 | */
|
| 29 | public int getRequiredPermissionLevel()
|
| 30 | {
|
| 31 | return 4;
|
| 32 | }
|
| 33 |
|
| 34 | public List<String> getCommandAliases()
|
| 35 | {
|
| 36 | return Collections.<String>emptyList();
|
| 37 | }
|
| 38 |
|
| 39 | /**
|
| 40 | * Returns true if the given command sender is allowed to use this command.
|
| 41 | */
|
| 42 | public boolean canCommandSenderUseCommand(ICommandSender sender)
|
| 43 | {
|
| 44 | return sender.canCommandSenderUseCommand(this.getRequiredPermissionLevel(), this.getCommandName());
|
| 45 | }
|
| 46 |
|
| 47 | public List<String> addTabCompletionOptions(ICommandSender sender, String[] args, BlockPos pos)
|
| 48 | {
|
| 49 | return null;
|
| 50 | }
|
| 51 |
|
| 52 | public static int parseInt(String input) throws NumberInvalidException
|
| 53 | {
|
| 54 | try
|
| 55 | {
|
| 56 | return Integer.parseInt(input);
|
| 57 | }
|
| 58 | catch (NumberFormatException var2)
|
| 59 | {
|
| 60 | throw new NumberInvalidException("commands.generic.num.invalid", new Object[] {input});
|
| 61 | }
|
| 62 | }
|
| 63 |
|
| 64 | public static int parseInt(String input, int min) throws NumberInvalidException
|
| 65 | {
|
| 66 | return parseInt(input, min, Integer.MAX_VALUE);
|
| 67 | }
|
| 68 |
|
| 69 | public static int parseInt(String input, int min, int max) throws NumberInvalidException
|
| 70 | {
|
| 71 | int i = parseInt(input);
|
| 72 |
|
| 73 | if (i < min)
|
| 74 | {
|
| 75 | throw new NumberInvalidException("commands.generic.num.tooSmall", new Object[] {Integer.valueOf(i), Integer.valueOf(min)});
|
| 76 | }
|
| 77 | else if (i > max)
|
| 78 | {
|
| 79 | throw new NumberInvalidException("commands.generic.num.tooBig", new Object[] {Integer.valueOf(i), Integer.valueOf(max)});
|
| 80 | }
|
| 81 | else
|
| 82 | {
|
| 83 | return i;
|
| 84 | }
|
| 85 | }
|
| 86 |
|
| 87 | public static long parseLong(String input) throws NumberInvalidException
|
| 88 | {
|
| 89 | try
|
| 90 | {
|
| 91 | return Long.parseLong(input);
|
| 92 | }
|
| 93 | catch (NumberFormatException var2)
|
| 94 | {
|
| 95 | throw new NumberInvalidException("commands.generic.num.invalid", new Object[] {input});
|
| 96 | }
|
| 97 | }
|
| 98 |
|
| 99 | public static long parseLong(String input, long min, long max) throws NumberInvalidException
|
| 100 | {
|
| 101 | long i = parseLong(input);
|
| 102 |
|
| 103 | if (i < min)
|
| 104 | {
|
| 105 | throw new NumberInvalidException("commands.generic.num.tooSmall", new Object[] {Long.valueOf(i), Long.valueOf(min)});
|
| 106 | }
|
| 107 | else if (i > max)
|
| 108 | {
|
| 109 | throw new NumberInvalidException("commands.generic.num.tooBig", new Object[] {Long.valueOf(i), Long.valueOf(max)});
|
| 110 | }
|
| 111 | else
|
| 112 | {
|
| 113 | return i;
|
| 114 | }
|
| 115 | }
|
| 116 |
|
| 117 | public static BlockPos parseBlockPos(ICommandSender sender, String[] args, int startIndex, boolean centerBlock) throws NumberInvalidException
|
| 118 | {
|
| 119 | BlockPos blockpos = sender.getPosition();
|
| 120 | return new BlockPos(parseDouble((double)blockpos.getX(), args[startIndex], -30000000, 30000000, centerBlock), parseDouble((double)blockpos.getY(), args[startIndex + 1], 0, 256, false), parseDouble((double)blockpos.getZ(), args[startIndex + 2], -30000000, 30000000, centerBlock));
|
| 121 | }
|
| 122 |
|
| 123 | public static double parseDouble(String input) throws NumberInvalidException
|
| 124 | {
|
| 125 | try
|
| 126 | {
|
| 127 | double d0 = Double.parseDouble(input);
|
| 128 |
|
| 129 | if (!Doubles.isFinite(d0))
|
| 130 | {
|
| 131 | throw new NumberInvalidException("commands.generic.num.invalid", new Object[] {input});
|
| 132 | }
|
| 133 | else
|
| 134 | {
|
| 135 | return d0;
|
| 136 | }
|
| 137 | }
|
| 138 | catch (NumberFormatException var3)
|
| 139 | {
|
| 140 | throw new NumberInvalidException("commands.generic.num.invalid", new Object[] {input});
|
| 141 | }
|
| 142 | }
|
| 143 |
|
| 144 | public static double parseDouble(String input, double min) throws NumberInvalidException
|
| 145 | {
|
| 146 | return parseDouble(input, min, Double.MAX_VALUE);
|
| 147 | }
|
| 148 |
|
| 149 | public static double parseDouble(String input, double min, double max) throws NumberInvalidException
|
| 150 | {
|
| 151 | double d0 = parseDouble(input);
|
| 152 |
|
| 153 | if (d0 < min)
|
| 154 | {
|
| 155 | throw new NumberInvalidException("commands.generic.double.tooSmall", new Object[] {Double.valueOf(d0), Double.valueOf(min)});
|
| 156 | }
|
| 157 | else if (d0 > max)
|
| 158 | {
|
| 159 | throw new NumberInvalidException("commands.generic.double.tooBig", new Object[] {Double.valueOf(d0), Double.valueOf(max)});
|
| 160 | }
|
| 161 | else
|
| 162 | {
|
| 163 | return d0;
|
| 164 | }
|
| 165 | }
|
| 166 |
|
| 167 | public static boolean parseBoolean(String input) throws CommandException
|
| 168 | {
|
| 169 | if (!input.equals("true") && !input.equals("1"))
|
| 170 | {
|
| 171 | if (!input.equals("false") && !input.equals("0"))
|
| 172 | {
|
| 173 | throw new CommandException("commands.generic.boolean.invalid", new Object[] {input});
|
| 174 | }
|
| 175 | else
|
| 176 | {
|
| 177 | return false;
|
| 178 | }
|
| 179 | }
|
| 180 | else
|
| 181 | {
|
| 182 | return true;
|
| 183 | }
|
| 184 | }
|
| 185 |
|
| 186 | /**
|
| 187 | * Returns the given ICommandSender as a EntityPlayer or throw an exception.
|
| 188 | */
|
| 189 | public static EntityPlayerMP getCommandSenderAsPlayer(ICommandSender sender) throws PlayerNotFoundException
|
| 190 | {
|
| 191 | if (sender instanceof EntityPlayerMP)
|
| 192 | {
|
| 193 | return (EntityPlayerMP)sender;
|
| 194 | }
|
| 195 | else
|
| 196 | {
|
| 197 | throw new PlayerNotFoundException("You must specify which player you wish to perform this action on.", new Object[0]);
|
| 198 | }
|
| 199 | }
|
| 200 |
|
| 201 | public static EntityPlayerMP getPlayer(ICommandSender sender, String username) throws PlayerNotFoundException
|
| 202 | {
|
| 203 | EntityPlayerMP entityplayermp = PlayerSelector.matchOnePlayer(sender, username);
|
| 204 |
|
| 205 | if (entityplayermp == null)
|
| 206 | {
|
| 207 | try
|
| 208 | {
|
| 209 | entityplayermp = MinecraftServer.getServer().getConfigurationManager().getPlayerByUUID(UUID.fromString(username));
|
| 210 | }
|
| 211 | catch (IllegalArgumentException var4)
|
| 212 | {
|
| 213 | ;
|
| 214 | }
|
| 215 | }
|
| 216 |
|
| 217 | if (entityplayermp == null)
|
| 218 | {
|
| 219 | entityplayermp = MinecraftServer.getServer().getConfigurationManager().getPlayerByUsername(username);
|
| 220 | }
|
| 221 |
|
| 222 | if (entityplayermp == null)
|
| 223 | {
|
| 224 | throw new PlayerNotFoundException();
|
| 225 | }
|
| 226 | else
|
| 227 | {
|
| 228 | return entityplayermp;
|
| 229 | }
|
| 230 | }
|
| 231 |
|
| 232 | public static Entity getEntity(ICommandSender p_175768_0_, String p_175768_1_) throws EntityNotFoundException
|
| 233 | {
|
| 234 | return getEntity(p_175768_0_, p_175768_1_, Entity.class);
|
| 235 | }
|
| 236 |
|
| 237 | public static <T extends Entity> T getEntity(ICommandSender commandSender, String p_175759_1_, Class <? extends T > p_175759_2_) throws EntityNotFoundException
|
| 238 | {
|
| 239 | Entity entity = PlayerSelector.matchOneEntity(commandSender, p_175759_1_, p_175759_2_);
|
| 240 | MinecraftServer minecraftserver = MinecraftServer.getServer();
|
| 241 |
|
| 242 | if (entity == null)
|
| 243 | {
|
| 244 | entity = minecraftserver.getConfigurationManager().getPlayerByUsername(p_175759_1_);
|
| 245 | }
|
| 246 |
|
| 247 | if (entity == null)
|
| 248 | {
|
| 249 | try
|
| 250 | {
|
| 251 | UUID uuid = UUID.fromString(p_175759_1_);
|
| 252 | entity = minecraftserver.getEntityFromUuid(uuid);
|
| 253 |
|
| 254 | if (entity == null)
|
| 255 | {
|
| 256 | entity = minecraftserver.getConfigurationManager().getPlayerByUUID(uuid);
|
| 257 | }
|
| 258 | }
|
| 259 | catch (IllegalArgumentException var6)
|
| 260 | {
|
| 261 | throw new EntityNotFoundException("commands.generic.entity.invalidUuid", new Object[0]);
|
| 262 | }
|
| 263 | }
|
| 264 |
|
| 265 | if (entity != null && p_175759_2_.isAssignableFrom(entity.getClass()))
|
| 266 | {
|
| 267 | return (T)entity;
|
| 268 | }
|
| 269 | else
|
| 270 | {
|
| 271 | throw new EntityNotFoundException();
|
| 272 | }
|
| 273 | }
|
| 274 |
|
| 275 | public static List<Entity> func_175763_c(ICommandSender p_175763_0_, String p_175763_1_) throws EntityNotFoundException
|
| 276 | {
|
| 277 | return (List<Entity>)(PlayerSelector.hasArguments(p_175763_1_) ? PlayerSelector.matchEntities(p_175763_0_, p_175763_1_, Entity.class) : Lists.newArrayList(new Entity[] {getEntity(p_175763_0_, p_175763_1_)}));
|
| 278 | }
|
| 279 |
|
| 280 | public static String getPlayerName(ICommandSender sender, String query) throws PlayerNotFoundException
|
| 281 | {
|
| 282 | try
|
| 283 | {
|
| 284 | return getPlayer(sender, query).getName();
|
| 285 | }
|
| 286 | catch (PlayerNotFoundException playernotfoundexception)
|
| 287 | {
|
| 288 | if (PlayerSelector.hasArguments(query))
|
| 289 | {
|
| 290 | throw playernotfoundexception;
|
| 291 | }
|
| 292 | else
|
| 293 | {
|
| 294 | return query;
|
| 295 | }
|
| 296 | }
|
| 297 | }
|
| 298 |
|
| 299 | /**
|
| 300 | * Attempts to retrieve an entity's name, first assuming that the entity is a player, and then exhausting all other
|
| 301 | * possibilities.
|
| 302 | */
|
| 303 | public static String getEntityName(ICommandSender p_175758_0_, String p_175758_1_) throws EntityNotFoundException
|
| 304 | {
|
| 305 | try
|
| 306 | {
|
| 307 | return getPlayer(p_175758_0_, p_175758_1_).getName();
|
| 308 | }
|
| 309 | catch (PlayerNotFoundException var5)
|
| 310 | {
|
| 311 | try
|
| 312 | {
|
| 313 | return getEntity(p_175758_0_, p_175758_1_).getUniqueID().toString();
|
| 314 | }
|
| 315 | catch (EntityNotFoundException entitynotfoundexception)
|
| 316 | {
|
| 317 | if (PlayerSelector.hasArguments(p_175758_1_))
|
| 318 | {
|
| 319 | throw entitynotfoundexception;
|
| 320 | }
|
| 321 | else
|
| 322 | {
|
| 323 | return p_175758_1_;
|
| 324 | }
|
| 325 | }
|
| 326 | }
|
| 327 | }
|
| 328 |
|
| 329 | public static IChatComponent getChatComponentFromNthArg(ICommandSender sender, String[] args, int p_147178_2_) throws CommandException, PlayerNotFoundException
|
| 330 | {
|
| 331 | return getChatComponentFromNthArg(sender, args, p_147178_2_, false);
|
| 332 | }
|
| 333 |
|
| 334 | public static IChatComponent getChatComponentFromNthArg(ICommandSender sender, String[] args, int index, boolean p_147176_3_) throws PlayerNotFoundException
|
| 335 | {
|
| 336 | IChatComponent ichatcomponent = new ChatComponentText("");
|
| 337 |
|
| 338 | for (int i = index; i < args.length; ++i)
|
| 339 | {
|
| 340 | if (i > index)
|
| 341 | {
|
| 342 | ichatcomponent.appendText(" ");
|
| 343 | }
|
| 344 |
|
| 345 | IChatComponent ichatcomponent1 = new ChatComponentText(args[i]);
|
| 346 |
|
| 347 | if (p_147176_3_)
|
| 348 | {
|
| 349 | IChatComponent ichatcomponent2 = PlayerSelector.matchEntitiesToChatComponent(sender, args[i]);
|
| 350 |
|
| 351 | if (ichatcomponent2 == null)
|
| 352 | {
|
| 353 | if (PlayerSelector.hasArguments(args[i]))
|
| 354 | {
|
| 355 | throw new PlayerNotFoundException();
|
| 356 | }
|
| 357 | }
|
| 358 | else
|
| 359 | {
|
| 360 | ichatcomponent1 = ichatcomponent2;
|
| 361 | }
|
| 362 | }
|
| 363 |
|
| 364 | ichatcomponent.appendSibling(ichatcomponent1);
|
| 365 | }
|
| 366 |
|
| 367 | return ichatcomponent;
|
| 368 | }
|
| 369 |
|
| 370 | /**
|
| 371 | * Builds a string starting at startPos
|
| 372 | */
|
| 373 | public static String buildString(String[] args, int startPos)
|
| 374 | {
|
| 375 | StringBuilder stringbuilder = new StringBuilder();
|
| 376 |
|
| 377 | for (int i = startPos; i < args.length; ++i)
|
| 378 | {
|
| 379 | if (i > startPos)
|
| 380 | {
|
| 381 | stringbuilder.append(" ");
|
| 382 | }
|
| 383 |
|
| 384 | String s = args[i];
|
| 385 | stringbuilder.append(s);
|
| 386 | }
|
| 387 |
|
| 388 | return stringbuilder.toString();
|
| 389 | }
|
| 390 |
|
| 391 | public static CommandBase.CoordinateArg parseCoordinate(double base, String p_175770_2_, boolean centerBlock) throws NumberInvalidException
|
| 392 | {
|
| 393 | return parseCoordinate(base, p_175770_2_, -30000000, 30000000, centerBlock);
|
| 394 | }
|
| 395 |
|
| 396 | public static CommandBase.CoordinateArg parseCoordinate(double p_175767_0_, String p_175767_2_, int min, int max, boolean centerBlock) throws NumberInvalidException
|
| 397 | {
|
| 398 | boolean flag = p_175767_2_.startsWith("~");
|
| 399 |
|
| 400 | if (flag && Double.isNaN(p_175767_0_))
|
| 401 | {
|
| 402 | throw new NumberInvalidException("commands.generic.num.invalid", new Object[] {Double.valueOf(p_175767_0_)});
|
| 403 | }
|
| 404 | else
|
| 405 | {
|
| 406 | double d0 = 0.0D;
|
| 407 |
|
| 408 | if (!flag || p_175767_2_.length() > 1)
|
| 409 | {
|
| 410 | boolean flag1 = p_175767_2_.contains(".");
|
| 411 |
|
| 412 | if (flag)
|
| 413 | {
|
| 414 | p_175767_2_ = p_175767_2_.substring(1);
|
| 415 | }
|
| 416 |
|
| 417 | d0 += parseDouble(p_175767_2_);
|
| 418 |
|
| 419 | if (!flag1 && !flag && centerBlock)
|
| 420 | {
|
| 421 | d0 += 0.5D;
|
| 422 | }
|
| 423 | }
|
| 424 |
|
| 425 | if (min != 0 || max != 0)
|
| 426 | {
|
| 427 | if (d0 < (double)min)
|
| 428 | {
|
| 429 | throw new NumberInvalidException("commands.generic.double.tooSmall", new Object[] {Double.valueOf(d0), Integer.valueOf(min)});
|
| 430 | }
|
| 431 |
|
| 432 | if (d0 > (double)max)
|
| 433 | {
|
| 434 | throw new NumberInvalidException("commands.generic.double.tooBig", new Object[] {Double.valueOf(d0), Integer.valueOf(max)});
|
| 435 | }
|
| 436 | }
|
| 437 |
|
| 438 | return new CommandBase.CoordinateArg(d0 + (flag ? p_175767_0_ : 0.0D), d0, flag);
|
| 439 | }
|
| 440 | }
|
| 441 |
|
| 442 | public static double parseDouble(double base, String input, boolean centerBlock) throws NumberInvalidException
|
| 443 | {
|
| 444 | return parseDouble(base, input, -30000000, 30000000, centerBlock);
|
| 445 | }
|
| 446 |
|
| 447 | public static double parseDouble(double base, String input, int min, int max, boolean centerBlock) throws NumberInvalidException
|
| 448 | {
|
| 449 | boolean flag = input.startsWith("~");
|
| 450 |
|
| 451 | if (flag && Double.isNaN(base))
|
| 452 | {
|
| 453 | throw new NumberInvalidException("commands.generic.num.invalid", new Object[] {Double.valueOf(base)});
|
| 454 | }
|
| 455 | else
|
| 456 | {
|
| 457 | double d0 = flag ? base : 0.0D;
|
| 458 |
|
| 459 | if (!flag || input.length() > 1)
|
| 460 | {
|
| 461 | boolean flag1 = input.contains(".");
|
| 462 |
|
| 463 | if (flag)
|
| 464 | {
|
| 465 | input = input.substring(1);
|
| 466 | }
|
| 467 |
|
| 468 | d0 += parseDouble(input);
|
| 469 |
|
| 470 | if (!flag1 && !flag && centerBlock)
|
| 471 | {
|
| 472 | d0 += 0.5D;
|
| 473 | }
|
| 474 | }
|
| 475 |
|
| 476 | if (min != 0 || max != 0)
|
| 477 | {
|
| 478 | if (d0 < (double)min)
|
| 479 | {
|
| 480 | throw new NumberInvalidException("commands.generic.double.tooSmall", new Object[] {Double.valueOf(d0), Integer.valueOf(min)});
|
| 481 | }
|
| 482 |
|
| 483 | if (d0 > (double)max)
|
| 484 | {
|
| 485 | throw new NumberInvalidException("commands.generic.double.tooBig", new Object[] {Double.valueOf(d0), Integer.valueOf(max)});
|
| 486 | }
|
| 487 | }
|
| 488 |
|
| 489 | return d0;
|
| 490 | }
|
| 491 | }
|
| 492 |
|
| 493 | /**
|
| 494 | * Gets the Item specified by the given text string. First checks the item registry, then tries by parsing the
|
| 495 | * string as an integer ID (deprecated). Warns the sender if we matched by parsing the ID. Throws if the item
|
| 496 | * wasn't found. Returns the item if it was found.
|
| 497 | */
|
| 498 | public static Item getItemByText(ICommandSender sender, String id) throws NumberInvalidException
|
| 499 | {
|
| 500 | ResourceLocation resourcelocation = new ResourceLocation(id);
|
| 501 | Item item = (Item)Item.itemRegistry.getObject(resourcelocation);
|
| 502 |
|
| 503 | if (item == null)
|
| 504 | {
|
| 505 | throw new NumberInvalidException("commands.give.item.notFound", new Object[] {resourcelocation});
|
| 506 | }
|
| 507 | else
|
| 508 | {
|
| 509 | return item;
|
| 510 | }
|
| 511 | }
|
| 512 |
|
| 513 | /**
|
| 514 | * Gets the Block specified by the given text string. First checks the block registry, then tries by parsing the
|
| 515 | * string as an integer ID (deprecated). Warns the sender if we matched by parsing the ID. Throws if the block
|
| 516 | * wasn't found. Returns the block if it was found.
|
| 517 | */
|
| 518 | public static Block getBlockByText(ICommandSender sender, String id) throws NumberInvalidException
|
| 519 | {
|
| 520 | ResourceLocation resourcelocation = new ResourceLocation(id);
|
| 521 |
|
| 522 | if (!Block.blockRegistry.containsKey(resourcelocation))
|
| 523 | {
|
| 524 | throw new NumberInvalidException("commands.give.block.notFound", new Object[] {resourcelocation});
|
| 525 | }
|
| 526 | else
|
| 527 | {
|
| 528 | Block block = (Block)Block.blockRegistry.getObject(resourcelocation);
|
| 529 |
|
| 530 | if (block == null)
|
| 531 | {
|
| 532 | throw new NumberInvalidException("commands.give.block.notFound", new Object[] {resourcelocation});
|
| 533 | }
|
| 534 | else
|
| 535 | {
|
| 536 | return block;
|
| 537 | }
|
| 538 | }
|
| 539 | }
|
| 540 |
|
| 541 | /**
|
| 542 | * Creates a linguistic series joining the input objects together. Examples: 1) {} --> "", 2) {"Steve"} -->
|
| 543 | * "Steve", 3) {"Steve", "Phil"} --> "Steve and Phil", 4) {"Steve", "Phil", "Mark"} --> "Steve, Phil and Mark"
|
| 544 | */
|
| 545 | public static String joinNiceString(Object[] elements)
|
| 546 | {
|
| 547 | StringBuilder stringbuilder = new StringBuilder();
|
| 548 |
|
| 549 | for (int i = 0; i < elements.length; ++i)
|
| 550 | {
|
| 551 | String s = elements[i].toString();
|
| 552 |
|
| 553 | if (i > 0)
|
| 554 | {
|
| 555 | if (i == elements.length - 1)
|
| 556 | {
|
| 557 | stringbuilder.append(" and ");
|
| 558 | }
|
| 559 | else
|
| 560 | {
|
| 561 | stringbuilder.append(", ");
|
| 562 | }
|
| 563 | }
|
| 564 |
|
| 565 | stringbuilder.append(s);
|
| 566 | }
|
| 567 |
|
| 568 | return stringbuilder.toString();
|
| 569 | }
|
| 570 |
|
| 571 | public static IChatComponent join(List<IChatComponent> components)
|
| 572 | {
|
| 573 | IChatComponent ichatcomponent = new ChatComponentText("");
|
| 574 |
|
| 575 | for (int i = 0; i < components.size(); ++i)
|
| 576 | {
|
| 577 | if (i > 0)
|
| 578 | {
|
| 579 | if (i == components.size() - 1)
|
| 580 | {
|
| 581 | ichatcomponent.appendText(" and ");
|
| 582 | }
|
| 583 | else if (i > 0)
|
| 584 | {
|
| 585 | ichatcomponent.appendText(", ");
|
| 586 | }
|
| 587 | }
|
| 588 |
|
| 589 | ichatcomponent.appendSibling((IChatComponent)components.get(i));
|
| 590 | }
|
| 591 |
|
| 592 | return ichatcomponent;
|
| 593 | }
|
| 594 |
|
| 595 | /**
|
| 596 | * Creates a linguistic series joining together the elements of the given collection. Examples: 1) {} --> "", 2)
|
| 597 | * {"Steve"} --> "Steve", 3) {"Steve", "Phil"} --> "Steve and Phil", 4) {"Steve", "Phil", "Mark"} --> "Steve, Phil
|
| 598 | * and Mark"
|
| 599 | */
|
| 600 | public static String joinNiceStringFromCollection(Collection<String> strings)
|
| 601 | {
|
| 602 | return joinNiceString(strings.toArray(new String[strings.size()]));
|
| 603 | }
|
| 604 |
|
| 605 | public static List<String> func_175771_a(String[] p_175771_0_, int p_175771_1_, BlockPos p_175771_2_)
|
| 606 | {
|
| 607 | if (p_175771_2_ == null)
|
| 608 | {
|
| 609 | return null;
|
| 610 | }
|
| 611 | else
|
| 612 | {
|
| 613 | int i = p_175771_0_.length - 1;
|
| 614 | String s;
|
| 615 |
|
| 616 | if (i == p_175771_1_)
|
| 617 | {
|
| 618 | s = Integer.toString(p_175771_2_.getX());
|
| 619 | }
|
| 620 | else if (i == p_175771_1_ + 1)
|
| 621 | {
|
| 622 | s = Integer.toString(p_175771_2_.getY());
|
| 623 | }
|
| 624 | else
|
| 625 | {
|
| 626 | if (i != p_175771_1_ + 2)
|
| 627 | {
|
| 628 | return null;
|
| 629 | }
|
| 630 |
|
| 631 | s = Integer.toString(p_175771_2_.getZ());
|
| 632 | }
|
| 633 |
|
| 634 | return Lists.newArrayList(new String[] {s});
|
| 635 | }
|
| 636 | }
|
| 637 |
|
| 638 | public static List<String> func_181043_b(String[] p_181043_0_, int p_181043_1_, BlockPos p_181043_2_)
|
| 639 | {
|
| 640 | if (p_181043_2_ == null)
|
| 641 | {
|
| 642 | return null;
|
| 643 | }
|
| 644 | else
|
| 645 | {
|
| 646 | int i = p_181043_0_.length - 1;
|
| 647 | String s;
|
| 648 |
|
| 649 | if (i == p_181043_1_)
|
| 650 | {
|
| 651 | s = Integer.toString(p_181043_2_.getX());
|
| 652 | }
|
| 653 | else
|
| 654 | {
|
| 655 | if (i != p_181043_1_ + 1)
|
| 656 | {
|
| 657 | return null;
|
| 658 | }
|
| 659 |
|
| 660 | s = Integer.toString(p_181043_2_.getZ());
|
| 661 | }
|
| 662 |
|
| 663 | return Lists.newArrayList(new String[] {s});
|
| 664 | }
|
| 665 | }
|
| 666 |
|
| 667 | /**
|
| 668 | * Returns true if the given substring is exactly equal to the start of the given string (case insensitive).
|
| 669 | */
|
| 670 | public static boolean doesStringStartWith(String original, String region)
|
| 671 | {
|
| 672 | return region.regionMatches(true, 0, original, 0, original.length());
|
| 673 | }
|
| 674 |
|
| 675 | public static List<String> getListOfStringsMatchingLastWord(String[] args, String... possibilities)
|
| 676 | {
|
| 677 | return getListOfStringsMatchingLastWord(args, Arrays.asList(possibilities));
|
| 678 | }
|
| 679 |
|
| 680 | public static List<String> getListOfStringsMatchingLastWord(String[] p_175762_0_, Collection<?> p_175762_1_)
|
| 681 | {
|
| 682 | String s = p_175762_0_[p_175762_0_.length - 1];
|
| 683 | List<String> list = Lists.<String>newArrayList();
|
| 684 |
|
| 685 | if (!p_175762_1_.isEmpty())
|
| 686 | {
|
| 687 | for (String s1 : Iterables.transform(p_175762_1_, Functions.toStringFunction()))
|
| 688 | {
|
| 689 | if (doesStringStartWith(s, s1))
|
| 690 | {
|
| 691 | list.add(s1);
|
| 692 | }
|
| 693 | }
|
| 694 |
|
| 695 | if (list.isEmpty())
|
| 696 | {
|
| 697 | for (Object object : p_175762_1_)
|
| 698 | {
|
| 699 | if (object instanceof ResourceLocation && doesStringStartWith(s, ((ResourceLocation)object).getResourcePath()))
|
| 700 | {
|
| 701 | list.add(String.valueOf(object));
|
| 702 | }
|
| 703 | }
|
| 704 | }
|
| 705 | }
|
| 706 |
|
| 707 | return list;
|
| 708 | }
|
| 709 |
|
| 710 | /**
|
| 711 | * Return whether the specified command parameter index is a username parameter.
|
| 712 | */
|
| 713 | public boolean isUsernameIndex(String[] args, int index)
|
| 714 | {
|
| 715 | return false;
|
| 716 | }
|
| 717 |
|
| 718 | public static void notifyOperators(ICommandSender sender, ICommand command, String msgFormat, Object... msgParams)
|
| 719 | {
|
| 720 | notifyOperators(sender, command, 0, msgFormat, msgParams);
|
| 721 | }
|
| 722 |
|
| 723 | public static void notifyOperators(ICommandSender sender, ICommand command, int p_152374_2_, String msgFormat, Object... msgParams)
|
| 724 | {
|
| 725 | if (theAdmin != null)
|
| 726 | {
|
| 727 | theAdmin.notifyOperators(sender, command, p_152374_2_, msgFormat, msgParams);
|
| 728 | }
|
| 729 | }
|
| 730 |
|
| 731 | /**
|
| 732 | * Sets the static IAdminCommander.
|
| 733 | */
|
| 734 | public static void setAdminCommander(IAdminCommand command)
|
| 735 | {
|
| 736 | theAdmin = command;
|
| 737 | }
|
| 738 |
|
| 739 | public int compareTo(ICommand p_compareTo_1_)
|
| 740 | {
|
| 741 | return this.getCommandName().compareTo(p_compareTo_1_.getCommandName());
|
| 742 | }
|
| 743 |
|
| 744 | public static class CoordinateArg
|
| 745 | {
|
| 746 | private final double field_179633_a;
|
| 747 | private final double field_179631_b;
|
| 748 | private final boolean field_179632_c;
|
| 749 |
|
| 750 | protected CoordinateArg(double p_i46051_1_, double p_i46051_3_, boolean p_i46051_5_)
|
| 751 | {
|
| 752 | this.field_179633_a = p_i46051_1_;
|
| 753 | this.field_179631_b = p_i46051_3_;
|
| 754 | this.field_179632_c = p_i46051_5_;
|
| 755 | }
|
| 756 |
|
| 757 | public double func_179628_a()
|
| 758 | {
|
| 759 | return this.field_179633_a;
|
| 760 | }
|
| 761 |
|
| 762 | public double func_179629_b()
|
| 763 | {
|
| 764 | return this.field_179631_b;
|
| 765 | }
|
| 766 |
|
| 767 | public boolean func_179630_c()
|
| 768 | {
|
| 769 | return this.field_179632_c;
|
| 770 | }
|
| 771 | }
|
| 772 | }
|
| 773 |
|