Advertisement
Guest User

Untitled

a guest
Jul 26th, 2016
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.45 KB | None | 0 0
  1. public class CommandSetBlocks extends CommandBase {
  2.  
  3. public CommandSetBlocks() {
  4.  
  5. }
  6.  
  7. public String getCommandName() {
  8. return "setblocks";
  9. }
  10.  
  11. public int getRequiredPermissionLevel() {
  12. return 2;
  13. }
  14.  
  15. public String getCommandUsage(ICommandSender sender) {
  16. return "commands.setblocks.usage";
  17. }
  18.  
  19. public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
  20. if (args.length < 7) {
  21. throw new WrongUsageException("commands.setblocks.usage", new Object[0]);
  22. } else {
  23. sender.setCommandStat(CommandResultStats.Type.AFFECTED_BLOCKS, 0);
  24. BlockPos blockpos = parseBlockPos(sender, args, 0, false);
  25. BlockPos blockpos1 = parseBlockPos(sender, args, 3, false);
  26. Block block = CommandBase.getBlockByText(sender, args[6]);
  27. int i = 0;
  28.  
  29. if (args.length >= 8) {
  30. i = parseInt(args[7], 0, 15);
  31. }
  32. IBlockState state = block.getStateFromMeta(i);
  33.  
  34. BlockPos blockpos2 = new BlockPos(Math.min(blockpos.getX(), blockpos1.getX()),
  35. Math.min(blockpos.getY(), blockpos1.getY()), Math.min(blockpos.getZ(), blockpos1.getZ()));
  36. BlockPos blockpos3 = new BlockPos(Math.max(blockpos.getX(), blockpos1.getX()),
  37. Math.max(blockpos.getY(), blockpos1.getY()), Math.max(blockpos.getZ(), blockpos1.getZ()));
  38. int j = (blockpos3.getX() - blockpos2.getX() + 1) * (blockpos3.getY() - blockpos2.getY() + 1)
  39. * (blockpos3.getZ() - blockpos2.getZ() + 1);
  40.  
  41. if (j > 100000000) {
  42. throw new CommandException("commands.setblocks.tooManyBlocks",
  43. new Object[] { Integer.valueOf(j), Integer.valueOf(100000000) });
  44. } else if (blockpos2.getY() >= 0 && blockpos3.getY() < 256) {
  45. World world = sender.getEntityWorld();
  46.  
  47. for (int k = blockpos2.getZ(); k <= blockpos3.getZ(); k += 16) {
  48. for (int l = blockpos2.getX(); l <= blockpos3.getX(); l += 16) {
  49. if (!world.isBlockLoaded(new BlockPos(l, blockpos3.getY() - blockpos2.getY(), k))) {
  50. throw new CommandException("commands.setblocks.outOfWorld", new Object[0]);
  51. }
  52. }
  53. }
  54.  
  55. NBTTagCompound nbttagcompound = new NBTTagCompound();
  56. boolean flag = false;
  57.  
  58. if (args.length >= 10 && block.hasTileEntity(state)) {
  59. String s = getChatComponentFromNthArg(sender, args, 9).getUnformattedText();
  60.  
  61. try {
  62. nbttagcompound = JsonToNBT.getTagFromJson(s);
  63. flag = true;
  64. } catch (NBTException nbtexception) {
  65. throw new CommandException("commands.setblocks.tagError",
  66. new Object[] { nbtexception.getMessage() });
  67. }
  68. }
  69.  
  70. List<BlockPos> list = Lists.<BlockPos> newArrayList();
  71. j = 0;
  72.  
  73. for (int i1 = blockpos2.getZ(); i1 <= blockpos3.getZ(); ++i1) {
  74. for (int j1 = blockpos2.getY(); j1 <= blockpos3.getY(); ++j1) {
  75. for (int k1 = blockpos2.getX(); k1 <= blockpos3.getX(); ++k1) {
  76. BlockPos blockpos4 = new BlockPos(k1, j1, i1);
  77.  
  78. if (args.length >= 9) {
  79. if (!args[8].equals("outline") && !args[8].equals("hollow")) {
  80. if (args[8].equals("destroy")) {
  81. world.destroyBlock(blockpos4, true);
  82. } else if (args[8].equals("keep")) {
  83. if (!world.isAirBlock(blockpos4)) {
  84. continue;
  85. }
  86. } else if (args[8].equals("replace") && !block.hasTileEntity(state)) {
  87. if (args.length > 9) {
  88. Block block1 = CommandBase.getBlockByText(sender, args[9]);
  89.  
  90. if (world.getBlockState(blockpos4).getBlock() != block1) {
  91. continue;
  92. }
  93. }
  94.  
  95. if (args.length > 10) {
  96. int l1 = CommandBase.parseInt(args[10]);
  97. IBlockState iblockstate = world.getBlockState(blockpos4);
  98.  
  99. if (iblockstate.getBlock().getMetaFromState(iblockstate) != l1) {
  100. continue;
  101. }
  102. }
  103. }
  104. } else if (k1 != blockpos2.getX() && k1 != blockpos3.getX() && j1 != blockpos2.getY()
  105. && j1 != blockpos3.getY() && i1 != blockpos2.getZ() && i1 != blockpos3.getZ()) {
  106. if (args[8].equals("hollow")) {
  107. world.setBlockState(blockpos4, Blocks.AIR.getDefaultState(), 2);
  108. list.add(blockpos4);
  109. }
  110.  
  111. continue;
  112. }
  113. }
  114.  
  115. TileEntity tileentity1 = world.getTileEntity(blockpos4);
  116.  
  117. if (tileentity1 != null) {
  118. if (tileentity1 instanceof IInventory) {
  119. ((IInventory) tileentity1).clear();
  120. }
  121.  
  122. world.setBlockState(blockpos4, Blocks.BARRIER.getDefaultState(),
  123. block == Blocks.BARRIER ? 2 : 4);
  124. }
  125.  
  126. IBlockState iblockstate1 = block.getStateFromMeta(i);
  127.  
  128. if (world.setBlockState(blockpos4, iblockstate1, 2)) {
  129. list.add(blockpos4);
  130. ++j;
  131.  
  132. if (flag) {
  133. TileEntity tileentity = world.getTileEntity(blockpos4);
  134.  
  135. if (tileentity != null) {
  136. nbttagcompound.setInteger("x", blockpos4.getX());
  137. nbttagcompound.setInteger("y", blockpos4.getY());
  138. nbttagcompound.setInteger("z", blockpos4.getZ());
  139. tileentity.readFromNBT(nbttagcompound);
  140. }
  141. }
  142. }
  143. }
  144. }
  145. }
  146.  
  147. for (BlockPos blockpos5 : list) {
  148. Block block2 = world.getBlockState(blockpos5).getBlock();
  149. world.notifyNeighborsRespectDebug(blockpos5, block2);
  150. }
  151.  
  152. if (j <= 0) {
  153. throw new CommandException("commands.setblocks.failed", new Object[0]);
  154. } else {
  155. sender.setCommandStat(CommandResultStats.Type.AFFECTED_BLOCKS, j);
  156. notifyCommandListener(sender, this, "commands.setblocks.success",
  157. new Object[] { Integer.valueOf(j) });
  158. }
  159. } else {
  160. throw new CommandException("commands.setblocks.outOfWorld", new Object[0]);
  161. }
  162. }
  163. }
  164.  
  165. public List<String> getTabCompletionOptions(MinecraftServer server, ICommandSender sender, String[] args,
  166. @Nullable BlockPos pos) {
  167. return args.length > 0
  168. && args.length <= 3
  169. ? getTabCompletionCoordinate(args, 0, pos)
  170. : (args.length > 3 && args.length <= 6 ? getTabCompletionCoordinate(args, 3, pos)
  171. : (args.length == 7 ? getListOfStringsMatchingLastWord(args, Block.REGISTRY.getKeys())
  172. : (args.length == 9
  173. ? getListOfStringsMatchingLastWord(args,
  174. new String[] { "replace", "destroy", "keep", "hollow",
  175. "outline" })
  176. : (args.length == 10 && "replace".equals(args[8])
  177. ? getListOfStringsMatchingLastWord(args,
  178. Block.REGISTRY.getKeys())
  179. : Collections.<String> emptyList()))));
  180. }
  181. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement