Example #1
0
  private static void buildTreeLayer2(ArrayList<Block> blocks) {
    ArrayList<Block> branches = new ArrayList<Block>();

    for (Block b : blocks) {
      BlockFace dir = getBuildDirection(b);
      Block handle = b.getRelative(dir);
      handle.setTypeIdAndData(17, (byte) 1, false);
      branches.add(handle);
      switch (dir) {
        case NORTH:
          branches.add(handle.getRelative(-1, 0, 1));
          branches.add(handle.getRelative(-1, 0, -1));
          break;
        case EAST:
          branches.add(handle.getRelative(-1, 0, -1));
          branches.add(handle.getRelative(1, 0, -1));
          break;
        case SOUTH:
          branches.add(handle.getRelative(1, 0, 1));
          branches.add(handle.getRelative(1, 0, -1));
          break;
        case WEST:
          branches.add(handle.getRelative(-1, 0, 1));
          branches.add(handle.getRelative(1, 0, 1));
          break;
      }
    }
    if (!branches.isEmpty()) {
      for (Block branch : branches) {
        branch.setTypeIdAndData(17, (byte) 1, false);
        populateTreeBranch(branch, 2);
      }
    }
  }
 private void highlightBoardSquare(int row, int col) {
   Cuboid sq = getSquare(row, col);
   MaterialData squareHighlightColor = boardStyle.getHighlightMaterial(col + (row % 2) % 2 == 1);
   switch (boardStyle.getHighlightStyle()) {
     case EDGES:
       sq.getFace(CuboidDirection.East).fill(squareHighlightColor);
       sq.getFace(CuboidDirection.North).fill(squareHighlightColor);
       sq.getFace(CuboidDirection.West).fill(squareHighlightColor);
       sq.getFace(CuboidDirection.South).fill(squareHighlightColor);
       break;
     case CORNERS:
       for (Block b : sq.corners()) {
         b.setTypeIdAndData(
             squareHighlightColor.getItemTypeId(), squareHighlightColor.getData(), false);
       }
       break;
     case CHECKERED:
     case CHEQUERED:
       for (Block b : sq) {
         if ((b.getLocation().getBlockX() - b.getLocation().getBlockZ()) % 2 == 0) {
           b.setTypeIdAndData(
               squareHighlightColor.getItemTypeId(), squareHighlightColor.getData(), false);
         }
       }
       break;
     default:
       break;
   }
   if (ChessCraft.getInstance().getDynmapIntegration() != null) {
     ChessCraft.getInstance().getDynmapIntegration().triggerUpdate(sq);
   }
 }
  public static void setSellSign(final World world, final AthionPlot plot) {
    removeSellSign(world, plot.id);

    if (plot.forsale || plot.auctionned) {
      final Location pillar =
          new Location(
              world,
              bottomX(plot.id, world) - 1,
              getMap(world).RoadHeight + 1,
              bottomZ(plot.id, world) - 1);

      Block bsign = pillar.clone().add(-1, 0, 0).getBlock();
      bsign.setType(Material.AIR);
      bsign.setTypeIdAndData(Material.WALL_SIGN.getId(), (byte) 4, false);

      Sign sign = (Sign) bsign.getState();

      if (plot.forsale) {
        sign.setLine(0, AthionPlots.caption("SignForSale"));
        sign.setLine(1, AthionPlots.caption("SignPrice"));
        if ((plot.customprice % 1) == 0) {
          sign.setLine(2, AthionPlots.caption("SignPriceColor") + Math.round(plot.customprice));
        } else {
          sign.setLine(2, AthionPlots.caption("SignPriceColor") + plot.customprice);
        }
        sign.setLine(3, "/ap " + AthionPlots.caption("CommandBuy"));

        sign.update(true);
      }

      if (plot.auctionned) {
        if (plot.forsale) {
          bsign = pillar.clone().add(-1, 0, 1).getBlock();
          bsign.setType(Material.AIR);
          bsign.setTypeIdAndData(Material.WALL_SIGN.getId(), (byte) 4, false);

          sign = (Sign) bsign.getState();
        }

        sign.setLine(0, "" + AthionPlots.caption("SignOnAuction"));
        if (plot.currentbidder.equals("")) {
          sign.setLine(1, AthionPlots.caption("SignMinimumBid"));
        } else {
          sign.setLine(1, AthionPlots.caption("SignCurrentBid"));
        }
        if ((plot.currentbid % 1) == 0) {
          sign.setLine(2, AthionPlots.caption("SignCurrentBidColor") + Math.round(plot.currentbid));
        } else {
          sign.setLine(2, AthionPlots.caption("SignCurrentBidColor") + plot.currentbid);
        }
        sign.setLine(3, "/ap " + AthionPlots.caption("CommandBid") + " <x>");

        sign.update(true);
      }
    }
  }
  public void updateFlag() {
    DyeColor[] woolColors = TownyWarConfig.getWoolColors();
    if (flagColorId < woolColors.length) {
      System.out.println(
          String.format(
              "Flag at %s turned %s.", getCellString(), woolColors[flagColorId].toString()));
      int woolId = Material.WOOL.getId();
      byte woolData = woolColors[flagColorId].getData();

      flagBlock.setTypeIdAndData(woolId, woolData, true);
      for (Block block : beaconFlagBlocks) block.setTypeIdAndData(woolId, woolData, true);
    }
  }
 @Override
 public void perform(Block b) {
   if (b.getTypeId() == ir) {
     h.put(b);
     b.setTypeIdAndData(i, d, true);
   }
 }
Example #6
0
  /**
   * Applies a list of transformation on a block, if the block is not protected.
   *
   * @param toTransform the Bukkit block object to transform
   * @param transformations the list if transformations to apply
   */
  public static void transform(Block toTransform, List<List<String>> transformations) {
    if (isBlockProtected(toTransform)) {
      return;
    }

    for (List<String> toCheck : transformations) {
      ArrayList<String[]> stateIndex = new ArrayList<String[]>();

      for (int i = 0; i != 2; ++i) {
        String got = toCheck.get(i);

        if (got.contains(":")) { // Check for data _ appended.
          stateIndex.add(got.split(":"));
        } else {
          stateIndex.add(new String[] {got, "0"});
        }
      }

      String[] curState = stateIndex.get(0), toState = stateIndex.get(1);

      if (Integer.valueOf(curState[0]) == toTransform.getTypeId()
          && Integer.valueOf(curState[1]) == toTransform.getData()) {
        toTransform.setTypeIdAndData(Integer.valueOf(toState[0]), Byte.parseByte(toState[1]), true);
        return;
      }
    }
  }
Example #7
0
  private static void buildTreeLayer3(ArrayList<Block> blocks) {
    ArrayList<Block> branches = new ArrayList<Block>();

    for (Block b : blocks) {
      BlockFace dir = getBuildDirection(b);
      Block handle = b.getRelative(dir);
      handle.setTypeIdAndData(17, (byte) 1, false);
      branches.add(handle);
    }
    if (!branches.isEmpty()) {
      for (Block branch : branches) {
        branch.setTypeIdAndData(17, (byte) 1, false);
        populateTreeBranch(branch, 2);
      }
    }
  }
  /*
   * (non-Javadoc)
   * @see com.nitnelave.CreeperHeal.block.Replaceable#replace(boolean)
   */
  @Override
  public boolean replace(boolean shouldDrop) {
    Block block = getBlock();
    int blockId = block.getTypeId();

    if (!CreeperConfig.overwriteBlocks && !isEmpty(blockId)) {
      if (CreeperConfig.dropDestroyedBlocks) drop();
      return true;
    } else if (CreeperConfig.overwriteBlocks
        && !isEmpty(blockId)
        && CreeperConfig.dropDestroyedBlocks) {
      CreeperBlock.newBlock(block.getState()).drop();
      block.setTypeIdAndData(0, (byte) 0, false);
    }

    if (!shouldDrop
        && isDependent(getTypeId())
        && isEmpty(getBlock().getRelative(getAttachingFace()).getTypeId())) {
      delay_replacement();
      return true;
    } else update();

    // TODO: Check the necessity, and move to CreeperRail if possible.
    checkForAscendingRails();

    return true;
  }
Example #9
0
  @SuppressWarnings("deprecation")
  @Override
  public void setBlockSuperFast(Block b, int blockId, byte data, boolean applyPhysics) {
    net.minecraft.server.v1_7_R4.World w = ((CraftWorld) b.getWorld()).getHandle();
    net.minecraft.server.v1_7_R4.Chunk chunk = w.getChunkAt(b.getX() >> 4, b.getZ() >> 4);
    try {
      Field f = chunk.getClass().getDeclaredField("sections");
      f.setAccessible(true);
      ChunkSection[] sections = (ChunkSection[]) f.get(chunk);
      ChunkSection chunksection = sections[b.getY() >> 4];

      if (chunksection == null) {
        chunksection =
            sections[b.getY() >> 4] =
                new ChunkSection(b.getY() >> 4 << 4, !chunk.world.worldProvider.f);
      }
      net.minecraft.server.v1_7_R4.Block mb = net.minecraft.server.v1_7_R4.Block.getById(blockId);
      chunksection.setTypeId(b.getX() & 15, b.getY() & 15, b.getZ() & 15, mb);
      chunksection.setData(b.getX() & 15, b.getY() & 15, b.getZ() & 15, data);
      if (applyPhysics) {
        w.update(b.getX(), b.getY(), b.getZ(), mb);
      }
    } catch (Exception e) {
      // Bukkit.getLogger().info("Error");
      b.setTypeIdAndData(blockId, data, applyPhysics);
    }
  }
Example #10
0
 public void setBlockCheck(World w, int x, int y, int z, int m, byte d, int id) {
   // List of blocks that a door cannot be placed on
   List<Integer> ids =
       Arrays.asList(
           0, 6, 8, 9, 10, 11, 18, 20, 26, 27, 28, 29, 30, 31, 32, 33, 34, 37, 38, 39, 40, 44, 46,
           50, 51, 53, 54, 55, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 75, 76,
           77, 78, 79, 81, 83, 85, 89, 92, 93, 94, 96, 101, 102, 104, 105, 106, 107, 108, 109, 111,
           113, 114, 115, 116, 117, 118, 119, 120, 122, 128, 130, 131, 132, 134, 135, 136);
   Block b = w.getBlockAt(x, y, z);
   Integer bId = Integer.valueOf(b.getTypeId());
   byte bData = b.getData();
   Statement statement = null;
   if (ids.contains(bId)) {
     b.setTypeIdAndData(m, d, true);
     // remember replaced block location, TypeId and Data so we can restore it later
     try {
       Connection connection = service.getConnection();
       statement = connection.createStatement();
       String replaced = w.getName() + ":" + x + ":" + y + ":" + z + ":" + bId + ":" + bData;
       String queryReplaced =
           "UPDATE tardis SET replaced = '" + replaced + "' WHERE tardis_id = " + id;
       statement.executeUpdate(queryReplaced);
       statement.close();
     } catch (SQLException e) {
       plugin.console.sendMessage(plugin.pluginName + "Set Replaced Block Error: " + e);
     } finally {
       try {
         statement.close();
       } catch (Exception e) {
       }
     }
   }
 }
Example #11
0
  private void setDoor(boolean open) {

    for (int x = 0; x < width; x++) {
      for (int z = 0; z < depth; z++) {
        Block block = LocationUtil.getRelativeOffset(center, faceing, x, 0, z);
        // do not replace the block the sign is on
        boolean isSource = block.equals(getBackBlock());

        if (open) {
          if (isSource && BlockUtil.isBlockReplacable(Material.getMaterial(onMaterial))) continue;
          block.setTypeIdAndData(onMaterial, (byte) onData, true);
        } else {
          if (isSource && BlockUtil.isBlockReplacable(Material.getMaterial(offMaterial))) continue;
          block.setTypeIdAndData(offMaterial, (byte) offData, true);
        }
      }
    }
  }
Example #12
0
 /*
  * Установка блока с проверкой на приват
  */
 public boolean placeBlock(Block block, Player p, Material newType, byte newData, boolean phys) {
   BlockState state = block.getState();
   block.setTypeIdAndData(newType.getId(), newData, phys);
   BlockPlaceEvent event =
       new BlockPlaceEvent(state.getBlock(), state, block, p.getItemInHand(), p, true);
   plg.getServer().getPluginManager().callEvent(event);
   if (event.isCancelled()) state.update(true);
   return event.isCancelled();
 }
Example #13
0
 private static void buildTreeLayer4(ArrayList<Block> blocks) {
   ArrayList<Block> branches = new ArrayList<Block>();
   for (Block block : blocks) {
     branches.add(block);
   }
   if (!branches.isEmpty()) {
     for (Block branch : branches) {
       branch.setTypeIdAndData(17, (byte) 1, false);
       populateTreeBranch(branch, 2);
     }
   }
 }
 @Override
 public void perform(Block b) {
   if (b.getTypeId() != i) {
     h.put(b);
     b.setTypeIdAndData(i, d, false);
     ((CraftPlayer) s.p)
         .getHandle()
         .netServerHandler
         .sendPacket(
             new Packet53BlockChange(
                 b.getX(), b.getY(), b.getZ(), ((CraftWorld) s.p.getWorld()).getHandle()));
   }
 }
Example #15
0
 @Override
 public void populate(World world, Random random, Chunk source) {
   for (int x = 0; x < 16; x++) {
     for (int z = 0; z < 16; z++) {
       int chance = random.nextInt(100);
       if (chance < 33) {
         Block handle = world.getHighestBlockAt(x + source.getX() * 16, z + source.getZ() * 16);
         if (handle.getRelative(BlockFace.DOWN).getType().equals(Material.GRASS)) {
           handle.setTypeIdAndData(Material.LONG_GRASS.getId(), (byte) 1, false);
         }
       }
     }
   }
 }
 public HallTunneler tunnel(int min, int max, XorZRetriever currentAxisValue) {
   int cVal = currentAxisValue.get(current);
   if (nextDir != null) {
     Byte dir = getByteDirection(nextDir);
     Byte opDir = getByteDirection(nextDir.getOppositeFace());
     while (!(cVal >= min && cVal <= max)) {
       current = current.getFace(nextDir);
       current.setTypeId(0);
       current.getFace(BlockFace.UP).setTypeId(0);
       if (by < requester.getMinY()) {
         if (dir != null) {
           current.setTypeIdAndData(67, dir, false);
         }
         current = current.getFace(BlockFace.UP);
         current.getFace(BlockFace.UP).setTypeId(0);
       } else if (by > requester.getMinY()) {
         current = current.getFace(BlockFace.DOWN);
         current.setTypeId(0);
         if (by + BlockFace.DOWN.getModY() >= requester.getMinY()) {
           current.getFace(BlockFace.DOWN).setTypeIdAndData(67, opDir, false);
         }
         if (Material.AIR.equals(current.getFace(nextDir).getType())) {
           current = current.getFace(nextDir);
           while (Material.AIR.equals(current.getFace(BlockFace.DOWN).getType())) {
             current = current.getFace(BlockFace.DOWN);
             current.setTypeIdAndData(Material.LADDER.getId(), opDir, false);
           }
           break;
         }
       }
       cVal = currentAxisValue.get(current);
       by = current.getY();
     }
     nextDir = null;
   }
   return this;
 }
    public void run() {

      ArrayList<BlockData> data = queue.get(id);
      if (data != null) {
        int a = data.size() - 1;
        int rb = 0;
        while (a >= 0 && (rb < 100 || shutdown)) {
          SurvivalGames.debug("Reseting " + a);
          BlockData result = data.get(a);
          if (result.getGameId() == game.getID()) {

            data.remove(a);
            Location l =
                new Location(
                    Bukkit.getWorld(result.getWorld()),
                    result.getX(),
                    result.getY(),
                    result.getZ());
            Block b = l.getBlock();
            b.setTypeIdAndData(result.getPrevid(), result.getPrevdata(), false);
            b.getState().update();

            /*	if(result.getItems() != null){
            	Chest c = (Chest)b;
            	c.getBlockInventory().setContents(result.getItems());
            }
             */

            rb++;
          }
          a--;
        }

        if (a != -1) {
          Bukkit.getScheduler()
              .scheduleSyncDelayedTask(
                  GameManager.getInstance().getPlugin(), new Rollback(id, shutdown), 1);
        } else {
          SurvivalGames.$("Arena " + id + " reset. ");
          game.resetCallback();
        }
      } else {
        SurvivalGames.$(" Arena " + id + " reset. ");
        game.resetCallback();
      }
    }
  public static void setOwnerSign(final World world, final AthionPlot plot) {
    final Location pillar =
        new Location(
            world,
            bottomX(plot.id, world) - 1,
            getMap(world).RoadHeight + 1,
            bottomZ(plot.id, world) - 1);

    final Block bsign = pillar.add(0, 0, -1).getBlock();
    final Block redlight = pillar.add(0, -1, 0).getBlock();
    final Block redtorch = pillar.add(0, -2, 0).getBlock();
    bsign.setType(Material.AIR);
    redlight.setType(Material.REDSTONE_LAMP_ON);
    redtorch.setType(Material.REDSTONE_TORCH_ON);
    ;
    bsign.setTypeIdAndData(Material.WALL_SIGN.getId(), (byte) 2, false);

    final String id =
        getPlotID(new Location(world, bottomX(plot.id, world), 0, bottomZ(plot.id, world)));

    final Sign sign = (Sign) bsign.getState();
    if (("Plot: " + ChatColor.DARK_GRAY + id).length() > 16) {
      sign.setLine(0, ("Plot: " + ChatColor.DARK_GRAY + id).substring(0, 16));
      if (("Plot: " + ChatColor.DARK_GRAY + id).length() > 32) {
        sign.setLine(1, ("Plot: " + ChatColor.DARK_GRAY + id).substring(16, 32));
      } else {
        sign.setLine(1, ("Plot: " + ChatColor.DARK_GRAY + id).substring(16));
      }
    } else {
      sign.setLine(0, "Plot: " + ChatColor.DARK_GRAY + id);
    }
    if (("By: " + ChatColor.DARK_GRAY + plot.owner).length() > 16) {
      sign.setLine(2, ("By: " + ChatColor.DARK_GRAY + plot.owner).substring(0, 16));
      if (("By: " + ChatColor.DARK_GRAY + plot.owner).length() > 32) {
        sign.setLine(3, ("By: " + ChatColor.DARK_GRAY + plot.owner).substring(16, 32));
      } else {
        sign.setLine(3, ("By: " + ChatColor.DARK_GRAY + plot.owner).substring(16));
      }
    } else {
      sign.setLine(2, "By: " + ChatColor.DARK_GRAY + plot.owner);
      sign.setLine(3, "");
    }
    sign.update(true);
  }
Example #19
0
 public void setBlockAndRemember(
     World w, int x, int y, int z, int m, byte d, int id, boolean rebuild) {
   Block b = w.getBlockAt(x, y, z);
   // save the block location so that we can protect it from damage and restore it (if it wasn't
   // air)!
   int bid = b.getTypeId();
   String l = b.getLocation().toString();
   Statement statement = null;
   String queryAddBlock;
   if (rebuild == false) {
     if (bid != 0) {
       byte data = b.getData();
       queryAddBlock =
           "INSERT INTO blocks (tardis_id, location, block, data) VALUES ("
               + id
               + ",'"
               + l
               + "', "
               + bid
               + ", "
               + data
               + ")";
     } else {
       queryAddBlock = "INSERT INTO blocks (tardis_id, location) VALUES (" + id + ",'" + l + "')";
     }
     try {
       Connection connection = service.getConnection();
       statement = connection.createStatement();
       statement.executeUpdate(queryAddBlock);
       statement.close();
     } catch (SQLException e) {
       plugin.console.sendMessage(plugin.pluginName + " Could not save block location to DB!");
     } finally {
       try {
         statement.close();
       } catch (Exception e) {
       }
     }
   }
   b.setTypeIdAndData(m, d, true);
 }
Example #20
0
  private static void populateTreeBranch(Block block, int radius) {
    int centerX = block.getX();
    int centerZ = block.getZ();
    int centerY = block.getY();
    World w = block.getWorld();

    int radius_check = radius * radius + 1;

    for (int x = -radius; x <= radius; x++) {
      for (int z = -radius; z <= radius; z++) {
        for (int y = -radius; y <= radius; y++) {
          if (x * x + y * y + z * z <= radius_check) {
            Block b = w.getBlockAt(centerX + x, centerY + y, centerZ + z);
            if (b.isEmpty()) {
              b.setTypeIdAndData(18, (byte) 1, false);
            }
          }
        }
      }
    }
  }
  private static void setWall(final Block block, final String currentblockid) {

    int blockId;
    byte blockData = 0;
    final AthionMaps pmi = getMap(block);

    if (currentblockid.contains(":")) {
      try {
        blockId = Integer.parseInt(currentblockid.substring(0, currentblockid.indexOf(":")));
        blockData = Byte.parseByte(currentblockid.substring(currentblockid.indexOf(":") + 1));
      } catch (final NumberFormatException e) {
        blockId = pmi.WallBlockId;
        blockData = pmi.WallBlockValue;
      }
    } else {
      try {
        blockId = Integer.parseInt(currentblockid);
      } catch (final NumberFormatException e) {
        blockId = pmi.WallBlockId;
      }
    }

    block.setTypeIdAndData(blockId, blockData, true);
  }
Example #22
0
 public void setBlock(World w, int x, int y, int z, int m, byte d) {
   Block b = w.getBlockAt(x, y, z);
   b.setTypeIdAndData(m, d, true);
 }
 @Override
 public void setBlock(Block block, boolean applyPhysics) {
   if (data < 16) {
     block.setTypeIdAndData(type, (byte) data, applyPhysics);
   }
 }
  public boolean growTree(Block sapling, Random random) {

    int data = sapling.getData() & 3;
    int i1 = 0;
    int j1 = 0;
    boolean flag = false;

    TreeType treeType = null;

    if (data == 1) {
      treeType = TreeType.REDWOOD;
    } else if (data == 2) {
      treeType = TreeType.BIRCH;
    } else if (data == 3) {
      for (i1 = 0; i1 >= -1; --i1) {
        for (j1 = 0; j1 >= -1; --j1) {
          if (isSameSapling(sapling, sapling.getRelative(i1, 0, j1))
              && isSameSapling(sapling, sapling.getRelative(i1 + 1, 0, j1))
              && isSameSapling(sapling, sapling.getRelative(i1, 0, j1 + 1))
              && isSameSapling(sapling, sapling.getRelative(i1 + 1, 0, j1 + 1))) {
            treeType = TreeType.JUNGLE;
            flag = true;
            break;
          }
        }

        if (flag) {
          break;
        }
      }

      if (!flag) {
        j1 = 0;
        i1 = 0;
        treeType = TreeType.SMALL_JUNGLE;
      }
    } else {
      treeType = TreeType.TREE;
      if (random.nextInt(10) == 0) {
        treeType = TreeType.BIG_TREE;
      }
    }

    if (flag) {
      sapling.getRelative(i1, 0, j1).setTypeId(0);
      sapling.getRelative(i1 + 1, 0, j1).setTypeId(0);
      sapling.getRelative(i1, 0, j1 + 1).setTypeId(0);
      sapling.getRelative(i1 + 1, 0, j1 + 1).setTypeId(0);
    } else {
      sapling.setTypeId(0);
    }

    boolean planted =
        sapling.getWorld().generateTree(sapling.getRelative(i1, 0, j1).getLocation(), treeType);

    if (!planted) {
      if (flag) {
        sapling.getRelative(i1, 0, j1).setTypeIdAndData(BlockID.SAPLING, (byte) data, true);
        sapling.getRelative(i1 + 1, 0, j1).setTypeIdAndData(BlockID.SAPLING, (byte) data, true);
        sapling.getRelative(i1, 0, j1 + 1).setTypeIdAndData(BlockID.SAPLING, (byte) data, true);
        sapling.getRelative(i1 + 1, 0, j1 + 1).setTypeIdAndData(BlockID.SAPLING, (byte) data, true);
      } else {
        sapling.setTypeIdAndData(BlockID.SAPLING, (byte) data, true);
      }
    }

    return planted;
  }
Example #25
0
 PerformResult perform() throws WorldEditorException {
   if (dontRollback.contains(replaced)) return PerformResult.BLACKLISTED;
   final Block block = loc.getBlock();
   if (replaced == 0 && block.getTypeId() == 0) return PerformResult.NO_ACTION;
   final BlockState state = block.getState();
   if (!world.isChunkLoaded(block.getChunk())) world.loadChunk(block.getChunk());
   if (type == replaced) {
     if (type == 0) {
       if (!block.setTypeId(0))
         throw new WorldEditorException(block.getTypeId(), 0, block.getLocation());
     } else if (ca != null && (type == 23 || type == 54 || type == 61 || type == 62)) {
       int leftover = 0;
       try {
         leftover =
             modifyContainer(
                 state, new ItemStack(ca.itemType, -ca.itemAmount, (short) 0, ca.itemData));
         if (leftover > 0)
           for (final BlockFace face :
               new BlockFace[] {
                 BlockFace.NORTH, BlockFace.SOUTH, BlockFace.EAST, BlockFace.WEST
               })
             if (block.getRelative(face).getTypeId() == 54)
               leftover =
                   modifyContainer(
                       block.getRelative(face).getState(),
                       new ItemStack(
                           ca.itemType,
                           ca.itemAmount < 0 ? leftover : -leftover,
                           (short) 0,
                           ca.itemData));
       } catch (final Exception ex) {
         throw new WorldEditorException(ex.getMessage(), block.getLocation());
       }
       if (!state.update())
         throw new WorldEditorException(
             "Failed to update inventory of " + materialName(block.getTypeId()),
             block.getLocation());
       if (leftover > 0 && ca.itemAmount < 0)
         throw new WorldEditorException(
             "Not enough space left in " + materialName(block.getTypeId()), block.getLocation());
     } else return PerformResult.NO_ACTION;
     return PerformResult.SUCCESS;
   }
   if (!(equalTypes(block.getTypeId(), type) || replaceAnyway.contains(block.getTypeId())))
     return PerformResult.NO_ACTION;
   if (state instanceof InventoryHolder) {
     ((InventoryHolder) state).getInventory().clear();
     state.update();
   }
   if (block.getTypeId() == replaced) {
     if (block.getData() != (type == 0 ? data : (byte) 0))
       block.setData(type == 0 ? data : (byte) 0, true);
     else return PerformResult.NO_ACTION;
   } else if (!block.setTypeIdAndData(replaced, type == 0 ? data : (byte) 0, true))
     throw new WorldEditorException(block.getTypeId(), replaced, block.getLocation());
   final int curtype = block.getTypeId();
   if (signtext != null && (curtype == 63 || curtype == 68)) {
     final Sign sign = (Sign) block.getState();
     final String[] lines = signtext.split("\0", 4);
     if (lines.length < 4) return PerformResult.NO_ACTION;
     for (int i = 0; i < 4; i++) sign.setLine(i, lines[i]);
     if (!sign.update())
       throw new WorldEditorException(
           "Failed to update signtext of " + materialName(block.getTypeId()),
           block.getLocation());
   } else if (curtype == 26) {
     final Bed bed = (Bed) block.getState().getData();
     final Block secBlock =
         bed.isHeadOfBed()
             ? block.getRelative(bed.getFacing().getOppositeFace())
             : block.getRelative(bed.getFacing());
     if (secBlock.getTypeId() == 0
         && !secBlock.setTypeIdAndData(26, (byte) (bed.getData() | 8), true))
       throw new WorldEditorException(secBlock.getTypeId(), 26, secBlock.getLocation());
   } else if (curtype == 64 || curtype == 71) {
     final byte blockData = block.getData();
     final Block secBlock =
         (blockData & 8) == 8
             ? block.getRelative(BlockFace.DOWN)
             : block.getRelative(BlockFace.UP);
     if (secBlock.getTypeId() == 0
         && !secBlock.setTypeIdAndData(curtype, (byte) (blockData | 8), true))
       throw new WorldEditorException(secBlock.getTypeId(), curtype, secBlock.getLocation());
   } else if ((curtype == 29 || curtype == 33) && (block.getData() & 8) > 0) {
     final PistonBaseMaterial piston = (PistonBaseMaterial) block.getState().getData();
     final Block secBlock = block.getRelative(piston.getFacing());
     if (secBlock.getTypeId() == 0
         && !secBlock.setTypeIdAndData(
             34,
             curtype == 29 ? (byte) (block.getData() | 8) : (byte) (block.getData() & ~8),
             true))
       throw new WorldEditorException(secBlock.getTypeId(), 34, secBlock.getLocation());
   } else if (curtype == 34) {
     final PistonExtensionMaterial piston = (PistonExtensionMaterial) block.getState().getData();
     final Block secBlock = block.getRelative(piston.getFacing().getOppositeFace());
     if (secBlock.getTypeId() == 0
         && !secBlock.setTypeIdAndData(
             piston.isSticky() ? 29 : 33, (byte) (block.getData() | 8), true))
       throw new WorldEditorException(
           secBlock.getTypeId(), piston.isSticky() ? 29 : 33, secBlock.getLocation());
   } else if (curtype == 18 && (block.getData() & 8) > 0)
     block.setData((byte) (block.getData() & 0xF7));
   return PerformResult.SUCCESS;
 }
Example #26
0
  private static void buildTree(World world, XYZ[] snakeBlocks) {
    // cut the snake into slices, this is my lab report
    HashMap<Integer, ArrayList<Block>> slices = new HashMap<Integer, ArrayList<Block>>();
    // System.out.println(snakeBlocks.length);
    for (XYZ loc : snakeBlocks) {
      Block block = world.getBlockAt(loc.x, loc.y, loc.z);
      if (block.isEmpty() && !block.isLiquid() && block.getType() != Material.BEDROCK) {
        if (slices.containsKey(Integer.valueOf(loc.y))) {
          slices.get(Integer.valueOf(loc.y)).add(block);
        } else {
          slices.put(Integer.valueOf(loc.y), new ArrayList<Block>());
          slices.get(Integer.valueOf(loc.y)).add(block);
        }
      }
    }

    ArrayList<Integer> sortedKeys = new ArrayList<Integer>(slices.keySet());
    Collections.sort(sortedKeys);
    int low = sortedKeys.get(0);
    int high = sortedKeys.get(sortedKeys.size() - 1);
    // boolean buildLayer1 = false;
    boolean buildLayer2 = false;
    boolean buildLayer3 = false;
    boolean buildLayer4 = false;
    for (Integer key : sortedKeys) {
      ArrayList<Block> slice = slices.get(key);
      for (Block b : slice) {
        b.setTypeIdAndData(17, (byte) 1, false);
      }
      //			if (!buildLayer1) {
      //				ArrayList<Block> toBranches = new ArrayList<Block>();
      //				for (Block b : slice) {
      //					if (b.getY()-low >= (high-low)-12 && checkBlockIsOnBorderOfSlice(b, slice)) {
      //						toBranches.add(b);
      //						buildLayer1 = true;
      //					}
      //				}
      //				buildTreeLayer1(toBranches);
      //			}
      if (!buildLayer2) {
        ArrayList<Block> toBranches = new ArrayList<Block>();
        for (Block b : slice) {
          if (b.getY() - low >= (high - low) - 8 && checkBlockIsOnBorderOfSlice(b, slice)) {
            toBranches.add(b);
            buildLayer2 = true;
          }
        }
        buildTreeLayer2(toBranches);
      }
      if (!buildLayer3) {
        ArrayList<Block> toBranches = new ArrayList<Block>();
        for (Block b : slice) {
          if (b.getY() - low >= (high - low) - 4 && checkBlockIsOnBorderOfSlice(b, slice)) {
            toBranches.add(b);
            buildLayer3 = true;
          }
        }
        buildTreeLayer3(toBranches);
      }
      if (!buildLayer4) {
        ArrayList<Block> toBranches = new ArrayList<Block>();
        for (Block b : slice) {
          if (b.getY() - low >= (high - low) && checkBlockIsOnBorderOfSlice(b, slice)) {
            toBranches.add(b);
            buildLayer4 = true;
          }
        }
        buildTreeLayer4(toBranches);
      }
    }
  }
Example #27
0
  @Override
  public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    if (!(sender instanceof BlockCommandSender)) {
      sender.sendMessage(ChatColor.RED + "'/cpplayers' is only for command block.");
      return true;
    }

    if (args.length != 4) {
      sender.sendMessage(ChatColor.RED + "'/cpenchant' command must have 4 arguments.");
      sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage);
      return true;
    }

    // Définition du block visé par la commande
    String[] _material_data = args[3].split(":");
    Material _material = Material.matchMaterial(_material_data[0]);
    if (_material == null) {
      sender.sendMessage(ChatColor.RED + "Block '" + _material_data[0] + "' not found.");
      sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage);
      return true;
    }
    Byte _data = 0;
    if (_material_data.length == 2) {
      _data = Byte.valueOf(_material_data[1]);
    }

    // Définition des coordonnées
    String[] x = args[0].split(":");
    String[] y = args[1].split(":");
    String[] z = args[2].split(":");
    Integer xmin, xmax = null, ymin, ymax = null, zmin, zmax = null;
    xmin = VariablesUtils.getInteger(x[0]);
    if (x.length == 2) {
      xmax = VariablesUtils.getInteger(x[1]);
    }
    ymin = VariablesUtils.getInteger(y[0]);
    if (y.length == 2) {
      ymax = VariablesUtils.getInteger(y[1]);
    }
    zmin = VariablesUtils.getInteger(z[0]);
    if (z.length == 2) {
      zmax = VariablesUtils.getInteger(z[1]);
    }
    if (xmin == null || ymin == null || zmin == null) {
      sender.sendMessage(
          ChatColor.RED
              + "Coords zone '"
              + args[0]
              + ","
              + args[1]
              + ","
              + args[2]
              + "' not correct.");
      sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage);
      return true;
    }

    // Récupération des info du command block qui utilise la commande
    BlockCommandSender _commandSender = (BlockCommandSender) sender;
    Location _location = _commandSender.getBlock().getLocation();
    World _world = _location.getWorld();

    // Si on a xmax, ymax et zmax on rempli une zone du block
    if (xmax != null && ymax != null && zmax != null) {
      for (Integer i = xmin; i <= xmax; i++) {
        for (Integer j = ymin; j <= ymax; j++) {
          for (Integer k = zmin; k <= zmax; k++) {
            Block blockWillChange = _world.getBlockAt(i, j, k);
            blockWillChange.setTypeIdAndData(_material.getId(), _data, true);
          }
        }
      }
      Block blockWillChange = _world.getBlockAt(xmin, ymin, zmin);
      blockWillChange.setType(_material);
    }
    // Sinon c'est on ne prend pas une zone, mais juste une coordonné
    else {
      Block blockWillChange = _world.getBlockAt(xmin, ymin, zmin);
      blockWillChange.setTypeIdAndData(_material.getId(), _data, true);
    }

    return true;
  }
  public static boolean mP(final World w, final String idFrom, final String idTo) {
    final Location plot1Bottom = getPlotBottomLoc(w, idFrom);
    final Location plot2Bottom = getPlotBottomLoc(w, idTo);
    final Location plot1Top = getPlotTopLoc(w, idFrom);

    final int distanceX = plot1Bottom.getBlockX() - plot2Bottom.getBlockX();
    final int distanceZ = plot1Bottom.getBlockZ() - plot2Bottom.getBlockZ();

    for (int x = plot1Bottom.getBlockX(); x <= plot1Top.getBlockX(); x++) {
      for (int z = plot1Bottom.getBlockZ(); z <= plot1Top.getBlockZ(); z++) {
        Block plot1Block = w.getBlockAt(new Location(w, x, 0, z));
        Block plot2Block = w.getBlockAt(new Location(w, x - distanceX, 0, z - distanceZ));

        final String plot1Biome = plot1Block.getBiome().name();
        final String plot2Biome = plot2Block.getBiome().name();

        plot1Block.setBiome(Biome.valueOf(plot2Biome));
        plot2Block.setBiome(Biome.valueOf(plot1Biome));

        for (int y = 0; y < w.getMaxHeight(); y++) {
          plot1Block = w.getBlockAt(new Location(w, x, y, z));
          final int plot1Type = plot1Block.getTypeId();
          final byte plot1Data = plot1Block.getData();

          plot2Block = w.getBlockAt(new Location(w, x - distanceX, y, z - distanceZ));

          final int plot2Type = plot2Block.getTypeId();
          final byte plot2Data = plot2Block.getData();

          // plot1Block.setTypeId(plot2Type);
          plot1Block.setTypeIdAndData(plot2Type, plot2Data, false);
          plot1Block.setData(plot2Data);

          // net.minecraft.server.World world = ((org.bukkit.craftbukkit.CraftWorld) w).getHandle();
          // world.setRawTypeIdAndData(plot1Block.getX(), plot1Block.getY(), plot1Block.getZ(),
          // plot2Type, plot2Data);

          // plot2Block.setTypeId(plot1Type);
          plot2Block.setTypeIdAndData(plot1Type, plot1Data, false);
          plot2Block.setData(plot1Data);
          // world.setRawTypeIdAndData(plot2Block.getX(), plot2Block.getY(), plot2Block.getZ(),
          // plot1Type, plot1Data);
        }
      }
    }

    final HashMap<String, AthionPlot> plots = getPlots(w);

    if (plots.containsKey(idFrom)) {
      if (plots.containsKey(idTo)) {
        final AthionPlot plot1 = plots.get(idFrom);
        final AthionPlot plot2 = plots.get(idTo);

        int idX = getIdX(idTo);
        int idZ = getIdZ(idTo);
        AthionSQL.deletePlot(idX, idZ, plot2.world);
        plots.remove(idFrom);
        plots.remove(idTo);
        idX = getIdX(idFrom);
        idZ = getIdZ(idFrom);
        AthionSQL.deletePlot(idX, idZ, plot1.world);

        plot2.id = "" + idX + ";" + idZ;
        AthionSQL.addPlot(plot2, idX, idZ, w);
        plots.put(idFrom, plot2);

        for (int i = 0; i < plot2.comments.size(); i++) {
          String strUUID = "";
          UUID uuid = null;

          if (plot2.comments.get(i).length >= 3) {
            strUUID = plot2.comments.get(i)[2];
            try {
              uuid = UUID.fromString(strUUID);
            } catch (final Exception e) {
            }
          }
          AthionSQL.addPlotComment(plot2.comments.get(i), i, idX, idZ, plot2.world, uuid);
        }

        for (final String player : plot2.allowed()) {
          AthionSQL.addPlotAllowed(player, idX, idZ, plot2.world);
        }

        idX = getIdX(idTo);
        idZ = getIdZ(idTo);
        plot1.id = "" + idX + ";" + idZ;
        AthionSQL.addPlot(plot1, idX, idZ, w);
        plots.put(idTo, plot1);

        for (int i = 0; i < plot1.comments.size(); i++) {
          String strUUID = "";
          UUID uuid = null;

          if (plot1.comments.get(i).length >= 3) {
            strUUID = plot1.comments.get(i)[2];
            try {
              uuid = UUID.fromString(strUUID);
            } catch (final Exception e) {
            }
          }

          AthionSQL.addPlotComment(plot1.comments.get(i), i, idX, idZ, plot1.world, uuid);
        }

        for (final String player : plot1.allowed()) {
          AthionSQL.addPlotAllowed(player, idX, idZ, plot1.world);
        }

        setOwnerSign(w, plot1);
        setSellSign(w, plot1);
        setOwnerSign(w, plot2);
        setSellSign(w, plot2);

      } else {
        final AthionPlot plot = plots.get(idFrom);

        int idX = getIdX(idFrom);
        int idZ = getIdZ(idFrom);
        AthionSQL.deletePlot(idX, idZ, plot.world);
        plots.remove(idFrom);
        idX = getIdX(idTo);
        idZ = getIdZ(idTo);
        plot.id = "" + idX + ";" + idZ;
        AthionSQL.addPlot(plot, idX, idZ, w);
        plots.put(idTo, plot);

        for (int i = 0; i < plot.comments.size(); i++) {
          String strUUID = "";
          UUID uuid = null;

          if (plot.comments.get(i).length >= 3) {
            strUUID = plot.comments.get(i)[2];
            try {
              uuid = UUID.fromString(strUUID);
            } catch (final Exception e) {
            }
          }
          AthionSQL.addPlotComment(plot.comments.get(i), i, idX, idZ, plot.world, uuid);
        }

        for (final String player : plot.allowed()) {
          AthionSQL.addPlotAllowed(player, idX, idZ, plot.world);
        }

        setOwnerSign(w, plot);
        setSellSign(w, plot);
        removeOwnerSign(w, idFrom);
        removeSellSign(w, idFrom);
      }
    } else {
      if (plots.containsKey(idTo)) {
        final AthionPlot plot = plots.get(idTo);

        int idX = getIdX(idTo);
        int idZ = getIdZ(idTo);
        AthionSQL.deletePlot(idX, idZ, plot.world);
        plots.remove(idTo);

        idX = getIdX(idFrom);
        idZ = getIdZ(idFrom);
        plot.id = "" + idX + ";" + idZ;
        AthionSQL.addPlot(plot, idX, idZ, w);
        plots.put(idFrom, plot);

        for (int i = 0; i < plot.comments.size(); i++) {
          String strUUID = "";
          UUID uuid = null;

          if (plot.comments.get(i).length >= 3) {
            strUUID = plot.comments.get(i)[2];
            try {
              uuid = UUID.fromString(strUUID);
            } catch (final Exception e) {
            }
          }
          AthionSQL.addPlotComment(plot.comments.get(i), i, idX, idZ, plot.world, uuid);
        }

        for (final String player : plot.allowed()) {
          AthionSQL.addPlotAllowed(player, idX, idZ, plot.world);
        }

        setOwnerSign(w, plot);
        setSellSign(w, plot);
        removeOwnerSign(w, idTo);
        removeSellSign(w, idTo);
      }
    }

    return true;
  }
  public static void clear(final Location bottom, final Location top) {
    final AthionMaps pmi = getMap(bottom);

    final int bottomX = bottom.getBlockX();
    final int topX = top.getBlockX();
    final int bottomZ = bottom.getBlockZ();
    final int topZ = top.getBlockZ();

    final int minChunkX = (int) Math.floor((double) bottomX / 16);
    final int maxChunkX = (int) Math.floor((double) topX / 16);
    final int minChunkZ = (int) Math.floor((double) bottomZ / 16);
    final int maxChunkZ = (int) Math.floor((double) topZ / 16);

    final World w = bottom.getWorld();

    for (int cx = minChunkX; cx <= maxChunkX; cx++) {
      for (int cz = minChunkZ; cz <= maxChunkZ; cz++) {
        final Chunk chunk = w.getChunkAt(cx, cz);

        for (final Entity e : chunk.getEntities()) {
          final Location eloc = e.getLocation();

          if (!(e instanceof Player)
              && (eloc.getBlockX() >= bottom.getBlockX())
              && (eloc.getBlockX() <= top.getBlockX())
              && (eloc.getBlockZ() >= bottom.getBlockZ())
              && (eloc.getBlockZ() <= top.getBlockZ())) {
            e.remove();
          }
        }
      }
    }

    for (int x = bottomX; x <= topX; x++) {
      for (int z = bottomZ; z <= topZ; z++) {
        Block block = new Location(w, x, 0, z).getBlock();

        block.setBiome(Biome.PLAINS);

        for (int y = w.getMaxHeight(); y >= 0; y--) {
          block = new Location(w, x, y, z).getBlock();

          final BlockState state = block.getState();

          if (state instanceof InventoryHolder) {
            final InventoryHolder holder = (InventoryHolder) state;
            holder.getInventory().clear();
          }

          if (state instanceof Jukebox) {
            final Jukebox jukebox = (Jukebox) state;
            // Remove once they fix the NullPointerException
            try {
              jukebox.setPlaying(Material.AIR);
            } catch (final Exception e) {
            }
          }

          if (y == 0) {
            block.setTypeId(pmi.BottomBlockId);
          } else if (y == pmi.RoadHeight) {
            block.setTypeId(pmi.PlotFloorBlockId);
          } else if (y < pmi.RoadHeight) {
            block.setTypeId(pmi.PlotFillingBlockId);
          } else {
            if ((y == (pmi.RoadHeight))
                && ((x == (bottomX - 1))
                    || (x == (topX + 1))
                    || (z == (bottomZ - 1))
                    || (z == (topZ + 1)))) {
              // block.setTypeId(pmi.WallBlockId);
            } else {
              block.setTypeIdAndData(0, (byte) 0, false); // .setType(Material.AIR);
            }
          }
        }
      }
    }

    adjustWall(bottom);
  }
Example #30
0
 private void setBlock(vBlock vb) {
   Block b = w.getBlockAt(vb.x, vb.y, vb.z);
   b.setTypeIdAndData(vb.id, vb.d, false);
 }