@SuppressWarnings("deprecation")
  @EventHandler
  public void onPlayerMove(PlayerMoveEvent event) {
    Player p = event.getPlayer();
    Block b = p.getTargetBlock((Set<Material>) null, p.getGameMode() == GameMode.CREATIVE ? 5 : 4);
    PumpkinCheck check =
        new PumpkinCheck(p.getWorld().getBlockAt(b.getLocation()).getType(), b.getLocation());

    if (targetBlocks.containsKey(p) && targetBlocks.get(p).isPumpkin() && !check.isPumpkin()) {
      Block newBlock = p.getWorld().getBlockAt(targetBlocks.get(p).getLocation());
      byte data = newBlock.getData();

      newBlock.setType(Material.PUMPKIN);
      newBlock.setData(data);
    }

    targetBlocks.put(p, check);

    if (targetBlocks.get(p).isPumpkin()) {
      Block newBlock = p.getWorld().getBlockAt(targetBlocks.get(p).getLocation());
      byte data = newBlock.getData();

      newBlock.setType(Material.JACK_O_LANTERN);
      newBlock.setData(data);
    }
  }
Example #2
0
 public void increment(Block source) {
   if (source.getData() < (data)) {
     source.setData((byte) (source.getData() + 1));
   } // add one
   else {
     source.setData((byte) (0));
   } // reset it
 }
Example #3
0
  /**
   * Sets the toggled state of a single lever<br>
   * <b>No Lever type check is performed</b>
   *
   * @param lever block
   * @param down state to set to
   */
  private static void setLever(org.bukkit.block.Block lever, boolean down) {
    if (lever.getType() != Material.LEVER) {
      return;
    }

    byte data = lever.getData();
    int newData;
    if (down) {
      newData = data | 0x8;
    } else {
      newData = data & 0x7;
    }
    if (newData != data) {
      // CraftBukkit start - Redstone event for lever
      int old = !down ? 1 : 0;
      int current = down ? 1 : 0;
      BlockRedstoneEvent eventRedstone = new BlockRedstoneEvent(lever, old, current);
      Bukkit.getServer().getPluginManager().callEvent(eventRedstone);
      if ((eventRedstone.getNewCurrent() > 0) != down) {
        return;
      }
      // CraftBukkit end
      lever.setData((byte) newData, true);
      lever.getState().update();
      Block attached =
          lever.getRelative(((Attachable) lever.getState().getData()).getAttachedFace());
    }
  }
Example #4
0
  @Override
  public void changeBlock(Block block) {
    currentJob.addBlock(block.getState());

    block.setType(item.getItemType());
    block.setData(item.getData());
  }
Example #5
0
  @SuppressWarnings("deprecation")
  @EventHandler
  public void onInventoryClick(InventoryClickEvent e) {
    Player player = (Player) e.getWhoClicked();
    Inventory inventory = e.getInventory();
    ItemStack currentItem = e.getCurrentItem();

    if (ArenaManager.getInstance().getArena(player) == null) {
      return;
    }

    Plot plot = ArenaManager.getInstance().getArena(player).getPlot(player);

    if (!inventory.getName().equals(ChatColor.GREEN + "Options menu")) {
      return;
    }
    if (currentItem.getType() != Material.HARD_CLAY) {
      return;
    }
    if (!currentItem.hasItemMeta()) {
      return;
    }
    if (!currentItem.getItemMeta().getDisplayName().equals(ChatColor.GREEN + "Floor block")) {
      return;
    }

    for (Block block : plot.getFloor().getAllBlocks()) {
      block.setType(e.getCursor().getType());
      block.setData(e.getCursor().getData().getData());
    }

    e.setCancelled(true);
  }
Example #6
0
  private boolean isCloseDoor(Location actual) {
    BlockFace[] blockFaces = {BlockFace.EAST, BlockFace.NORTH, BlockFace.WEST, BlockFace.SOUTH};
    actual.setY(actual.getY());
    Block base = actual.getBlock();
    for (BlockFace bf : blockFaces) {
      Block bu = base.getRelative(bf);
      if ((bu.getType() == Material.WOODEN_DOOR)) {
        byte openData = 0x4;
        byte doorData = (byte) (bu.getData());
        if ((doorData & 0x4) == 0x4) {
          doorData = (byte) (doorData & 0x3);
        } else {
          doorData = (byte) (doorData | 0x7);
        }
        bu.setData(doorData);

        if ((bu.getRelative(BlockFace.UP).getType() == Material.WOODEN_DOOR)) {
          doorData = (byte) (bu.getRelative(BlockFace.UP).getData());
          if ((doorData & 0x1) == 1) {
            doorData = 0x9;
          } else {
            doorData = 0x8;
          }
          bu.getRelative(BlockFace.UP).setData(doorData);
        }
        return true;
      }
    }
    return false;
  }
  @SuppressWarnings("deprecation")
  @Command(
      value = "myplanet",
      desc = "Erzeugt einen Testplaneten",
      perm = "craftoplugin.galaxywar.generate",
      onlyplayers = true)
  public void generatePlanet(final CommandSender cs, final String command, final String[] args) {
    final Player p = (Player) cs;
    p.sendMessage("Aktiv!");
    final int r = 6;
    PlanetType type = PlanetType.SUN;
    if (args.length > 0) {
      try {
        type = PlanetType.valueOf(args[0].toUpperCase());
      } catch (final IllegalArgumentException e) {
      }
    }
    final World world = p.getWorld();

    final Planet planet = new Planet(new Position(p.getLocation()), r, type);
    final ArrayList<MaterialBlockPoint> blocks = planet.getMaterialBlockPoints();

    Block block;
    for (final MaterialBlockPoint b : blocks) {
      block = world.getBlockAt(b.getX(), b.getY(), b.getZ());
      block.setType(b.getMaterial());
      block.setData((byte) 0);
    }
  }
Example #8
0
  @Override
  public void perform(Block b) {
    if (b.getY() > 128 || b.getY() < 0) return;

    if (b.getTypeId() == ir && b.getData() == dr) {
      h.put(b);
      b.setData(d);
    }
  }
Example #9
0
 @SuppressWarnings("deprecation")
 public static void thaw(Block block) {
   if (frozenblocks.containsKey(block)) {
     byte data = frozenblocks.get(block);
     frozenblocks.remove(block);
     block.setType(Material.WATER);
     block.setData(data);
   }
 }
Example #10
0
 /**
  * Replaces a block with a new material and data, and after delay, restore it.
  *
  * @param b The block.
  * @param newType The new material.
  * @param newData The new data.
  * @param tickDelay The delay after which the block is restored.
  */
 public static void setToRestore(final Block b, Material newType, byte newData, int tickDelay) {
   if (blocksToRestore.containsKey(b.getLocation())) return;
   Block bUp = b.getRelative(BlockFace.UP);
   if (b.getType() != Material.AIR
       && b.getType() != Material.SIGN_POST
       && b.getType() != Material.CHEST
       && b.getType() != Material.STONE_PLATE
       && b.getType() != Material.WOOD_PLATE
       && b.getType() != Material.WALL_SIGN
       && b.getType() != Material.WALL_BANNER
       && b.getType() != Material.STANDING_BANNER
       && b.getType() != Material.CROPS
       && b.getType() != Material.LONG_GRASS
       && b.getType() != Material.SAPLING
       && b.getType() != Material.DEAD_BUSH
       && b.getType() != Material.RED_ROSE
       && b.getType() != Material.RED_MUSHROOM
       && b.getType() != Material.BROWN_MUSHROOM
       && b.getType() != Material.TORCH
       && b.getType() != Material.LADDER
       && b.getType() != Material.VINE
       && b.getType() != Material.DOUBLE_PLANT
       && b.getType() != Material.PORTAL
       && b.getType() != Material.CACTUS
       && b.getType() != Material.WATER
       && b.getType() != Material.STATIONARY_WATER
       && b.getType() != Material.LAVA
       && b.getType() != Material.STATIONARY_LAVA
       && b.getType() != Material.PORTAL
       && b.getType() != Material.ENDER_PORTAL
       && b.getType() != Material.SOIL
       && b.getType() != Material.BARRIER
       && b.getType() != Material.COMMAND
       && !isPortalBlock(b)
       && !isRocketBlock(b)
       && net.minecraft.server.v1_8_R3.Block.getById(b.getTypeId()).getMaterial().isSolid()
       && a(bUp)
       && b.getType().getId() != 43
       && b.getType().getId() != 44) {
     if (!blocksToRestore.containsKey(b.getLocation())) {
       blocksToRestore.put(b.getLocation(), b.getType().toString() + "," + b.getData());
       b.setType(newType);
       b.setData(newData);
       Bukkit.getScheduler()
           .runTaskLater(
               Core.getPlugin(),
               new Runnable() {
                 @Override
                 public void run() {
                   restoreBlockAt(b.getLocation());
                 }
               },
               tickDelay);
     }
   }
 }
Example #11
0
 /** Forces restoring the blocks. */
 public static void forceRestore() {
   for (Location loc : blocksToRestore.keySet()) {
     Block b = loc.getBlock();
     String s = blocksToRestore.get(loc);
     Material m = Material.valueOf(s.split(",")[0]);
     byte d = Byte.valueOf(s.split(",")[1]);
     b.setType(m);
     b.setData(d);
   }
 }
Example #12
0
 /**
  * Restores the block at the location "loc".
  *
  * @param loc The location of the block to restore.
  */
 public static void restoreBlockAt(Location loc) {
   if (!blocksToRestore.containsKey(loc)) return;
   Block b = loc.getBlock();
   String s = blocksToRestore.get(loc);
   Material m = Material.valueOf(s.split(",")[0]);
   byte d = Byte.valueOf(s.split(",")[1]);
   b.setType(m);
   b.setData(d);
   blocksToRestore.remove(loc);
 }
Example #13
0
 @SuppressWarnings("deprecation")
 public void setBlue() {
   List<Block> blocks = new ArrayList<>();
   for (Location loc : location) {
     blocks.add(loc.getBlock());
   }
   for (Block block : blocks) {
     block.setData((byte) 3);
   }
 }
  @SuppressWarnings("deprecation")
  private boolean signFinder(
      Player player,
      Block block,
      BlockFace[] testBlocks,
      BlockFace[] testFaces,
      final Block lever) {

    Block newBlock;
    BlockFace testFace;

    for (int c = 0; c < 5; c++) {
      if (c == 2) {
        newBlock = block.getRelative(testBlocks[c], 2);
        testFace = testFaces[1];
      } else {
        newBlock = block.getRelative(testBlocks[c]);
        testFace = testFaces[0];
      }
      if (!(newBlock.getState() instanceof Sign)) continue;
      if (((org.bukkit.material.Sign) newBlock.getState().getData()).getFacing() != testFace)
        continue;

      int s = signConverter(player, newBlock);
      if (s > 0) {
        boolean n = s == 1;

        if (n || !enableBL) return n;
        if (lever.getType() != Material.LEVER) return n;
        Lever l = (Lever) lever.getState().getData();
        // if (l.isPowered())
        //	return n;
        l.setPowered(false);
        l.setPowered(true);
        lever.setData(l.getData());
        lever.getWorld().playEffect(lever.getLocation(), Effect.SMOKE, 4);
        Bukkit.getScheduler()
            .scheduleSyncDelayedTask(
                PLUGIN,
                new Runnable() {
                  @Override
                  public void run() {
                    if (lever.getType() != Material.LEVER) return;
                    Lever l = (Lever) lever.getState().getData();
                    if (!l.isPowered()) return;
                    l.setPowered(false);
                    lever.setData(l.getData());
                    lever.getWorld().playEffect(lever.getLocation(), Effect.SMOKE, 4);
                  }
                },
                20L);
      }
    }
    return false;
  }
Example #15
0
 @SuppressWarnings("deprecation")
 private static void thawAll() {
   for (Block block : frozenblocks.keySet()) {
     if (block.getType() == Material.ICE) {
       byte data = frozenblocks.get(block);
       block.setType(Material.WATER);
       block.setData(data);
       frozenblocks.remove(block);
     }
   }
 }
Example #16
0
 @EventHandler(ignoreCancelled = true)
 public void onBlockPistonRetract(BlockPistonRetractEvent event) {
   Block piston = event.getBlock();
   Block extension = piston.getRelative(event.getDirection());
   Block block = extension.getRelative(event.getDirection());
   Deadbolted db = Deadbolt.get(block);
   if (db.isProtected()) {
     // TODO why cant we just cancel
     event.setCancelled(true);
     piston.setData((byte) (piston.getData() ^ 0x8));
     extension.setType(Material.AIR);
   }
 }
Example #17
0
 /**
  * Populates a chunk with flowers and tall grass.
  *
  * @param world World
  * @param random Random
  * @param source Source chunk
  */
 @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 cx = (source.getX() << 4) + x;
       int cz = (source.getZ() << 4) + z;
       int y = world.getHighestBlockYAt(cx, cz);
       Block block = source.getBlock(x, y, z);
       if (block.getType() == Material.AIR
           && block.getRelative(BlockFace.DOWN).getType() == Material.GRASS) {
         if (block.getBiome() == Biome.PLAINS) {
           int n = random.nextInt(64);
           if (n < 1) {
             block.setType(Material.RED_ROSE);
           } else if (n < 4) {
             block.setType(Material.YELLOW_FLOWER);
           }
         } else if (block.getBiome() == Biome.SHRUBLAND || block.getBiome() == Biome.SAVANNA) {
           int n = random.nextInt(256);
           if (n < 2) {
             block.setType(Material.RED_ROSE);
           } else if (n < 3) {
             block.setType(Material.YELLOW_FLOWER);
           } else if (n < 16) {
             block.setType(Material.LONG_GRASS);
             block.setData((byte) 1);
           }
         } else if (block.getBiome() == Biome.FOREST
             || block.getBiome() == Biome.SEASONAL_FOREST) {
           int n = random.nextInt(256);
           if (n < 16) {
             block.setType(Material.LONG_GRASS);
             block.setData((byte) 2);
           }
         }
       }
     }
   }
 }
Example #18
0
 @SuppressWarnings("deprecation")
 public static void remove(Block block) {
   if (ignitedblocks.containsKey(block)) {
     ignitedblocks.remove(block);
   }
   if (ignitedtimes.containsKey(block)) {
     ignitedtimes.remove(block);
   }
   if (replacedBlocks.containsKey(block.getLocation())) {
     block.setType(replacedBlocks.get(block.getLocation()).getItemType());
     block.setData(replacedBlocks.get(block.getLocation()).getData());
     replacedBlocks.remove(block.getLocation());
   }
 }
    @SuppressWarnings("deprecation")
    @Override
    public void populate(World w, Random r, Chunk c) {
      if (dropOffCenter == null) {
        cDropOffX = w.getSpawnLocation().getBlockX() >> 4;
        cDropOffZ = w.getSpawnLocation().getBlockZ() >> 4;
        dropOffCenter =
            new Location(w, cDropOffX * 16 + 7, w.getSeaLevel() + 10, cDropOffZ * 16 + 7);

        cMinX = cDropOffX - 4;
        cMaxX = cDropOffX + 4;
        cMinZ = cDropOffZ - 4;
        cMaxZ = cDropOffZ + 4;
      }

      int cx = c.getX(), cz = c.getZ();
      if (cx < cMinX || cx > cMaxX || cz < cMinZ || cz > cMaxZ) return;

      // create a grassy plain around where the drop off will be, fading to the height of the
      // "underlying" world at the edges
      if (cx == cMinX || cx == cMaxX || cz == cMinZ || cz == cMaxZ) createSlope(c);
      else createFlatSurface(c);

      // generate the central drop-off point itself
      if (c.getX() == cDropOffX && c.getZ() == cDropOffZ) createDropOffPoint(c);

      // generate spawn points for each team
      TeamInfo[] teams = getTeams();
      for (int teamNum = 0; teamNum < numTeams.getValue(); teamNum++) {
        TeamInfo team = teams[teamNum];
        Location spawn = getSpawnLocationForTeam(teamNum);
        if (spawn.getChunk() == c) {
          int spawnX = spawn.getBlockX() & 15,
              spawnY = spawn.getBlockY() - 1,
              spawnZ = spawn.getBlockZ() & 15;

          for (int x = spawnX - 2; x <= spawnX + 2; x++)
            for (int z = spawnZ - 2; z <= spawnZ + 2; z++) {
              Block b = c.getBlock(x, spawnY, z);

              b.setType(Material.WOOL);
              b.setData(team.getDyeColor().getWoolData());
            }
          c.getBlock(spawnX, spawnY, spawnZ).setType(Material.BEDROCK);
        }
      }
    }
 private void unfocusBlock() {
   if (destination != null) {
     breakBlock();
     return;
   }
   if (sourceblock.getType() == Material.SAND) {
     if (sourceblock.getData() == (byte) 0x1) {
       sourceblock.setType(sourcetype);
       sourceblock.setData((byte) 0x1);
     } else {
       sourceblock.setType(sourcetype);
     }
   } else {
     sourceblock.setType(sourcetype);
   }
   instances.remove(id);
 }
Example #21
0
  @SuppressWarnings("deprecation")
  protected void adjust(
      Block block, byte dataValue, boolean recursive, int recurseDistance, int rDepth) {
    registerForUndo(block);
    block.setData(dataValue);

    if (recursive && rDepth < recurseDistance) {
      Material targetMaterial = block.getType();
      tryAdjust(
          block.getRelative(BlockFace.NORTH),
          dataValue,
          targetMaterial,
          recurseDistance,
          rDepth + 1);
      tryAdjust(
          block.getRelative(BlockFace.WEST),
          dataValue,
          targetMaterial,
          recurseDistance,
          rDepth + 1);
      tryAdjust(
          block.getRelative(BlockFace.SOUTH),
          dataValue,
          targetMaterial,
          recurseDistance,
          rDepth + 1);
      tryAdjust(
          block.getRelative(BlockFace.EAST),
          dataValue,
          targetMaterial,
          recurseDistance,
          rDepth + 1);
      tryAdjust(
          block.getRelative(BlockFace.UP), dataValue, targetMaterial, recurseDistance, rDepth + 1);
      tryAdjust(
          block.getRelative(BlockFace.DOWN),
          dataValue,
          targetMaterial,
          recurseDistance,
          rDepth + 1);
    }
  }
Example #22
0
    public void run() {
      Iterator<DoorAction> iter = doors.iterator();
      while (iter.hasNext()) {
        DoorAction doorAction = iter.next();
        Location location = doorAction.location;

        if (System.currentTimeMillis() > doorAction.triggerTime) {
          Block block = location.getBlock();

          Door door = new Door(block.getType(), block.getData());
          byte data = initializeDoorData(door);

          // Close the door
          if (isDoorOpen(door)) {
            if ((block.getData() & 0x4) != 0x4) {
              data |= 0x4;
            }
          }

          block.setData(data);
          iter.remove();
        }
      }
    }
  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 void terraform(boolean overrideChance) {

    for (int x = -radius.getBlockX() + 1; x < radius.getBlockX(); x++) {
      for (int y = -radius.getBlockY() + 1; y < radius.getBlockY(); y++) {
        for (int z = -radius.getBlockZ() + 1; z < radius.getBlockZ(); z++) {
          if (overrideChance || CraftBookPlugin.inst().getRandom().nextInt(40) == 0) {
            int rx = location.getX() - x;
            int ry = location.getY() - y;
            int rz = location.getZ() - z;
            Block b = BukkitUtil.toSign(getSign()).getWorld().getBlockAt(rx, ry, rz);
            if (b.getTypeId() == BlockID.CROPS && b.getData() < 0x7) {
              if (consumeBonemeal()) {
                b.setData((byte) (b.getData() + 0x1));
              }
              return;
            }
            if ((b.getTypeId() == BlockID.CROPS
                    || b.getTypeId() == BlockID.CARROTS
                    || b.getTypeId() == BlockID.POTATOES
                    || b.getTypeId() == BlockID.MELON_STEM
                    || b.getTypeId() == BlockID.PUMPKIN_STEM)
                && b.getData() < 0x7) {
              if (consumeBonemeal()) {
                byte add = (byte) CraftBookPlugin.inst().getRandom().nextInt(3);
                if (b.getData() + add > 0x7) b.setData((byte) 0x7);
                else b.setData((byte) (b.getData() + add));
              }
              return;
            }
            if (b.getTypeId() == BlockID.COCOA_PLANT
                && ((b.getData() & 0x8) != 0x8 || (b.getData() & 0xC) != 0xC)) {
              if (consumeBonemeal()) {
                if (CraftBookPlugin.inst().getRandom().nextInt(30) == 0)
                  b.setData((byte) (b.getData() | 0xC));
                else b.setData((byte) (b.getData() | 0x8));
              }
              return;
            }
            if (b.getTypeId() == BlockID.NETHER_WART && b.getData() < 0x3) {
              if (consumeBonemeal()) {
                b.setData((byte) (b.getData() + 0x1));
              }
              return;
            }
            if (b.getTypeId() == BlockID.SAPLING) {
              if (consumeBonemeal()) {
                if (!growTree(b, CraftBookPlugin.inst().getRandom())) refundBonemeal();
                else return;
              }
            }
            if (b.getTypeId() == BlockID.BROWN_MUSHROOM || b.getTypeId() == BlockID.RED_MUSHROOM) {
              if (consumeBonemeal()) {
                if (b.getTypeId() == BlockID.BROWN_MUSHROOM) {
                  b.setTypeId(0);
                  if (!b.getWorld().generateTree(b.getLocation(), TreeType.BROWN_MUSHROOM)) {
                    b.setTypeId(BlockID.BROWN_MUSHROOM);
                    refundBonemeal();
                  } else return;
                }
                if (b.getTypeId() == BlockID.RED_MUSHROOM) {
                  b.setTypeId(0);
                  if (!b.getWorld().generateTree(b.getLocation(), TreeType.RED_MUSHROOM)) {
                    b.setTypeId(BlockID.RED_MUSHROOM);
                    refundBonemeal();
                  } else return;
                }
              }
            }
            if ((b.getTypeId() == BlockID.REED || b.getTypeId() == BlockID.CACTUS)
                && b.getData() < 0x15
                && b.getRelative(0, 1, 0).getTypeId() == 0) {
              if (consumeBonemeal()) {
                b.getRelative(0, 1, 0).setTypeId(b.getTypeId());
              }
              return;
            }
            if (b.getTypeId() == BlockID.DIRT && b.getRelative(0, 1, 0).getTypeId() == 0) {
              if (consumeBonemeal()) {
                b.setTypeId(
                    b.getBiome() == Biome.MUSHROOM_ISLAND || b.getBiome() == Biome.MUSHROOM_SHORE
                        ? BlockID.MYCELIUM
                        : BlockID.GRASS);
              }
              return;
            }
            if (b.getTypeId() == BlockID.GRASS
                && b.getRelative(0, 1, 0).getTypeId() == BlockID.AIR
                && CraftBookPlugin.inst().getRandom().nextInt(15) == 0) {
              if (consumeBonemeal()) {
                int t = CraftBookPlugin.inst().getRandom().nextInt(7);
                if (t == 0) {
                  b.getRelative(0, 1, 0).setTypeIdAndData(BlockID.LONG_GRASS, (byte) 1, true);
                } else if (t == 1) {
                  b.getRelative(0, 1, 0).setTypeId(BlockID.YELLOW_FLOWER);
                } else if (t == 2) {
                  b.getRelative(0, 1, 0).setTypeId(BlockID.RED_FLOWER);
                } else if (t == 3) {
                  b.getRelative(0, 1, 0).setTypeIdAndData(BlockID.LONG_GRASS, (byte) 2, true);
                } else {
                  b.getRelative(0, 1, 0).setTypeIdAndData(BlockID.LONG_GRASS, (byte) 1, true);
                }
              }
              return;
            }
            if (b.getTypeId() == BlockID.SAND
                && b.getRelative(0, 1, 0).getTypeId() == BlockID.AIR
                && CraftBookPlugin.inst().getRandom().nextInt(15) == 0) {
              if (consumeBonemeal()) {
                b.getRelative(0, 1, 0).setTypeIdAndData(BlockID.LONG_GRASS, (byte) 0, true);
              }
              return;
            }
            if (b.getTypeId() == BlockID.VINE
                && b.getRelative(0, -1, 0).getTypeId() == BlockID.AIR
                && CraftBookPlugin.inst().getRandom().nextInt(15) == 0) {
              if (consumeBonemeal()) {
                b.getRelative(0, -1, 0).setTypeIdAndData(BlockID.VINE, b.getData(), true);
              }
              return;
            }
            if (b.getTypeId() == BlockID.STATIONARY_WATER
                && b.getRelative(0, 1, 0).getTypeId() == BlockID.AIR
                && CraftBookPlugin.inst().getRandom().nextInt(30) == 0) {
              if (consumeBonemeal()) {
                b.getRelative(0, 1, 0).setTypeId(BlockID.LILY_PAD);
              }
              return;
            }
            if (b.getTypeId() == BlockID.MYCELIUM
                && b.getRelative(0, 1, 0).getTypeId() == BlockID.AIR
                && CraftBookPlugin.inst().getRandom().nextInt(15) == 0) {
              if (consumeBonemeal()) {
                int t = CraftBookPlugin.inst().getRandom().nextInt(2);
                if (t == 0) {
                  b.getRelative(0, 1, 0).setTypeId(BlockID.RED_MUSHROOM);
                } else if (t == 1) {
                  b.getRelative(0, 1, 0).setTypeId(BlockID.BROWN_MUSHROOM);
                }
              }
              return;
            }
          }
        }
      }
    }
  }
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
  @Override
  public void impact(Minecart cart, CartMechanismBlocks blocks, boolean minor) {
    // care?
    if (minor) return;

    // validate
    if (cart == null) return;
    if (!blocks.matches("sort")) return;
    Sign sign = (Sign) blocks.sign.getState();

    // pick which sort conditions apply
    //  (left dominates if both apply)
    Hand dir = Hand.STRAIGHT;
    if (isSortApplicable(sign.getLine(2), cart)) {
      dir = Hand.LEFT;
    } else if (isSortApplicable((sign).getLine(3), cart)) {
      dir = Hand.RIGHT;
    }

    // pick the track block to modify and the curve to give it.
    //   perhaps oddly, it's the sign facing that determines the concepts of left and right, and not
    // the track.
    //    this is required since there's not a north track and a south track; just a north-south
    // track type.
    byte trackData;
    BlockFace next = SignUtil.getFacing(blocks.sign);
    switch (next) {
      case WEST:
        switch (dir) {
          case LEFT:
            trackData = 9;
            break;
          case RIGHT:
            trackData = 8;
            break;
          default:
            trackData = 0;
        }
        break;
      case EAST:
        switch (dir) {
          case LEFT:
            trackData = 7;
            break;
          case RIGHT:
            trackData = 6;
            break;
          default:
            trackData = 0;
        }
        break;
      case NORTH:
        switch (dir) {
          case LEFT:
            trackData = 6;
            break;
          case RIGHT:
            trackData = 9;
            break;
          default:
            trackData = 1;
        }
        break;
      case SOUTH:
        switch (dir) {
          case LEFT:
            trackData = 8;
            break;
          case RIGHT:
            trackData = 7;
            break;
          default:
            trackData = 1;
        }
        break;
      default:
        // XXX ohgod the sign's not facing any sensible direction at all, who do we tell?
        return;
    }
    Block targetTrack = blocks.rail.getRelative(next);

    // now check sanity real quick that there's actually a track after this,
    // and then make the change.
    if (targetTrack.getType() == Material.RAILS) targetTrack.setData(trackData);
  }
  public void onPlayerInteract(PlayerInteractEvent event) {
    if (event.isCancelled()) {
      return;
    }
    Action action = event.getAction();
    if (action == Action.RIGHT_CLICK_BLOCK || action == Action.RIGHT_CLICK_AIR) {
      Block block = event.getClickedBlock();
      Material type = block.getType();
      Player player = event.getPlayer();

      GlobalConfiguration cfg = plugin.getGlobalConfiguration();
      WorldConfiguration wcfg = cfg.getWorldConfig(event.getClickedBlock().getWorld().getName());

      if (wcfg.useRegions && player.getItemInHand().getTypeId() == wcfg.regionWand) {
        Vector pt = toVector(block);

        RegionManager mgr =
            plugin.getGlobalRegionManager().getRegionManager(player.getWorld().getName());
        ApplicableRegionSet app = mgr.getApplicableRegions(pt);
        List<String> regions = mgr.getApplicableRegionsIDs(pt);

        if (regions.size() > 0) {
          player.sendMessage(
              ChatColor.YELLOW
                  + "Can you build? "
                  + (app.canBuild(BukkitPlayer.wrapPlayer(plugin, player)) ? "Yes" : "No"));

          StringBuilder str = new StringBuilder();
          for (Iterator<String> it = regions.iterator(); it.hasNext(); ) {
            str.append(it.next());
            if (it.hasNext()) {
              str.append(", ");
            }
          }

          player.sendMessage(ChatColor.YELLOW + "Applicable regions: " + str.toString());
        } else {
          player.sendMessage(ChatColor.YELLOW + "WorldGuard: No defined regions here!");
        }
      }

      if (block.getType() == Material.CHEST
          || block.getType() == Material.DISPENSER
          || block.getType() == Material.FURNACE
          || block.getType() == Material.BURNING_FURNACE
          || block.getType() == Material.NOTE_BLOCK) {
        if (wcfg.useRegions) {
          Vector pt = toVector(block);
          LocalPlayer localPlayer = BukkitPlayer.wrapPlayer(plugin, player);
          RegionManager mgr =
              plugin.getGlobalRegionManager().getRegionManager(player.getWorld().getName());

          if (!plugin.hasPermission(player, "region.bypass")) {
            ApplicableRegionSet set = mgr.getApplicableRegions(pt);
            if (!set.isStateFlagAllowed(Flags.CHEST_ACCESS) && !set.canBuild(localPlayer)) {
              player.sendMessage(ChatColor.DARK_RED + "You don't have permission for this area.");
              event.setCancelled(true);
              return;
            }
          }
        }
      }

      if (wcfg.useRegions && (type == Material.LEVER || type == Material.STONE_BUTTON)) {
        Vector pt = toVector(block);
        RegionManager mgr =
            cfg.getWorldGuardPlugin()
                .getGlobalRegionManager()
                .getRegionManager(player.getWorld().getName());
        ApplicableRegionSet applicableRegions = mgr.getApplicableRegions(pt);
        LocalPlayer localPlayer = BukkitPlayer.wrapPlayer(plugin, player);

        if (!applicableRegions.isStateFlagAllowed(Flags.LEVER_AND_BUTTON, localPlayer)) {
          player.sendMessage(ChatColor.DARK_RED + "You don't have permission for this area.");
          event.setCancelled(true);
          return;
        }
      }

      if (wcfg.useRegions && type == Material.CAKE_BLOCK) {

        Vector pt = toVector(block);

        if (!cfg.canBuild(player, pt)) {
          player.sendMessage(ChatColor.DARK_RED + "You don't have permission for this area.");

          byte newData = (byte) (block.getData() - 1);
          newData = newData < 0 ? 0 : newData;

          block.setData(newData);
          player.setHealth(player.getHealth() - 3);

          return;
        }
      }

      if (wcfg.useRegions
          && wcfg.useiConomy
          && cfg.getiConomy() != null
          && (type == Material.SIGN_POST || type == Material.SIGN || type == Material.WALL_SIGN)) {
        BlockState blockstate = block.getState();

        if (((Sign) blockstate).getLine(0).equalsIgnoreCase("[WorldGuard]")
            && ((Sign) blockstate).getLine(1).equalsIgnoreCase("For sale")) {
          String regionId = ((Sign) blockstate).getLine(2);
          // String regionComment = ((Sign)block).getLine(3);

          if (regionId != null && regionId != "") {
            RegionManager mgr =
                cfg.getWorldGuardPlugin()
                    .getGlobalRegionManager()
                    .getRegionManager(player.getWorld().getName());
            ProtectedRegion region = mgr.getRegion(regionId);

            if (region != null) {
              RegionFlagContainer flags = region.getFlags();

              if (flags.getBooleanFlag(Flags.BUYABLE).getValue(false)) {
                if (iConomy.getBank().hasAccount(player.getName())) {
                  Account account = iConomy.getBank().getAccount(player.getName());
                  double balance = account.getBalance();
                  double regionPrice = flags.getDoubleFlag(Flags.PRICE).getValue();

                  if (balance >= regionPrice) {
                    account.subtract(regionPrice);
                    player.sendMessage(
                        ChatColor.YELLOW
                            + "You have bought the region "
                            + regionId
                            + " for "
                            + iConomy.getBank().format(regionPrice));
                    DefaultDomain owners = region.getOwners();
                    owners.addPlayer(player.getName());
                    region.setOwners(owners);
                    flags.getBooleanFlag(Flags.BUYABLE).setValue(false);
                    account.save();
                  } else {
                    player.sendMessage(ChatColor.YELLOW + "You have not enough money.");
                  }
                } else {
                  player.sendMessage(ChatColor.YELLOW + "You have not enough money.");
                }
              } else {
                player.sendMessage(ChatColor.RED + "Region: " + regionId + " is not buyable");
              }
            } else {
              player.sendMessage(
                  ChatColor.DARK_RED + "The region " + regionId + " does not exist.");
            }
          } else {
            player.sendMessage(ChatColor.DARK_RED + "No region specified.");
          }
        }
      }

      if (wcfg.getBlacklist() != null) {

        if (!wcfg.getBlacklist()
            .check(
                new BlockInteractBlacklistEvent(
                    BukkitPlayer.wrapPlayer(plugin, player), toVector(block), block.getTypeId()),
                false,
                false)) {
          event.setCancelled(true);
          return;
        }
      }
    }
  }
Example #28
0
  /**
   * Handles removing & dropping the blocks from Tree Feller.
   *
   * @param toBeFelled List of Blocks to be removed from the tree
   * @param player The player using the ability
   * @param profile The PlayerProfile of the player
   */
  private static void removeBlocks(
      ArrayList<Block> toBeFelled, Player player, PlayerProfile profile) {
    if (toBeFelled.size() >= Config.getInstance().getTreeFellerThreshold()) {
      player.sendMessage(LocaleLoader.getString("Woodcutting.Skills.TreeFellerThreshold"));
      return;
    }

    int xp = 0;
    ItemStack inHand = player.getItemInHand();
    int level = 0;
    if (inHand.containsEnchantment(Enchantment.DURABILITY)) {
      level = inHand.getEnchantmentLevel(Enchantment.DURABILITY);
    }
    int durabilityLoss = durabilityLossCalulate(toBeFelled, level);

    /* This is to prevent using wood axes everytime you tree fell */
    if (ModChecks.isCustomTool(inHand)) {
      if (inHand.getDurability() + durabilityLoss
          >= ModChecks.getToolFromItemStack(inHand).getDurability()) {
        player.sendMessage(LocaleLoader.getString("Woodcutting.Skills.TreeFeller.Splinter"));

        int health = player.getHealth();

        if (health >= 2) {
          Combat.dealDamage(player, random.nextInt(health - 1));
        }
        inHand.setDurability((short) (inHand.getType().getMaxDurability()));
        return;
      }
    } else if ((inHand.getDurability() + durabilityLoss >= inHand.getType().getMaxDurability())
        || inHand.getType().equals(Material.AIR)) {
      player.sendMessage(LocaleLoader.getString("Woodcutting.Skills.TreeFeller.Splinter"));

      int health = player.getHealth();

      if (health >= 2) {
        Combat.dealDamage(player, random.nextInt(health - 1));
      }
      inHand.setDurability((short) (inHand.getType().getMaxDurability()));
      return;
    }

    /* Damage the tool */
    inHand.setDurability((short) (inHand.getDurability() + durabilityLoss));

    // Prepare ItemStacks
    ItemStack item = null;
    ItemStack oak = (new MaterialData(Material.LOG, TreeSpecies.GENERIC.getData())).toItemStack(1);
    ItemStack spruce =
        (new MaterialData(Material.LOG, TreeSpecies.REDWOOD.getData())).toItemStack(1);
    ItemStack birch = (new MaterialData(Material.LOG, TreeSpecies.BIRCH.getData())).toItemStack(1);
    ItemStack jungle =
        (new MaterialData(Material.LOG, TreeSpecies.JUNGLE.getData())).toItemStack(1);

    for (Block x : toBeFelled) {
      if (Misc.blockBreakSimulate(x, player, true)) {
        if (Config.getInstance().getBlockModsEnabled() && ModChecks.isCustomLogBlock(x)) {
          if (ModChecks.isCustomLogBlock(x)) {
            CustomBlock block = ModChecks.getCustomBlock(x);
            item = block.getItemDrop();

            if (!mcMMO.placeStore.isTrue(x)) {
              WoodCutting.woodCuttingProcCheck(player, x);
              xp = block.getXpGain();
            }

            /* Remove the block */
            x.setData((byte) 0x0);
            x.setType(Material.AIR);

            int minimumDropAmount = block.getMinimumDropAmount();
            int maximumDropAmount = block.getMaximumDropAmount();

            item = block.getItemDrop();

            if (minimumDropAmount != maximumDropAmount) {
              Misc.dropItems(x.getLocation(), item, minimumDropAmount);
              Misc.randomDropItems(
                  x.getLocation(), item, 50, maximumDropAmount - minimumDropAmount);
            } else {
              Misc.dropItems(x.getLocation(), item, minimumDropAmount);
            }
          } else if (ModChecks.isCustomLeafBlock(x)) {
            CustomBlock block = ModChecks.getCustomBlock(x);
            item = block.getItemDrop();

            final int SAPLING_DROP_CHANCE = 10;

            /* Remove the block */
            x.setData((byte) 0x0);
            x.setType(Material.AIR);

            Misc.randomDropItem(x.getLocation(), item, SAPLING_DROP_CHANCE);
          }
        } else if (x.getType() == Material.LOG) {
          Tree tree = (Tree) x.getState().getData();
          TreeSpecies species = tree.getSpecies();

          switch (species) {
            case GENERIC:
              item = oak;
              break;

            case REDWOOD:
              item = spruce;
              break;

            case BIRCH:
              item = birch;
              break;

            case JUNGLE:
              item = jungle;
              break;

            default:
              break;
          }

          if (!mcMMO.placeStore.isTrue(x)) {
            WoodCutting.woodCuttingProcCheck(player, x);

            switch (species) {
              case GENERIC:
                xp += Config.getInstance().getWoodcuttingXPOak();
                break;

              case REDWOOD:
                xp += Config.getInstance().getWoodcuttingXPSpruce();
                break;

              case BIRCH:
                xp += Config.getInstance().getWoodcuttingXPBirch();
                break;

              case JUNGLE:
                xp +=
                    Config.getInstance().getWoodcuttingXPJungle()
                        / 2; // Nerf XP from Jungle Trees when using Tree Feller
                break;

              default:
                break;
            }
          }

          /* Remove the block */
          x.setData((byte) 0x0);
          x.setType(Material.AIR);

          /* Drop the block */
          Misc.dropItem(x.getLocation(), item);
        } else if (x.getType() == Material.LEAVES) {
          final int SAPLING_DROP_CHANCE = 10;

          // Drop the right type of sapling
          item = (new MaterialData(Material.SAPLING, (byte) (x.getData() & 3))).toItemStack(1);

          Misc.randomDropItem(x.getLocation(), item, SAPLING_DROP_CHANCE);

          // Remove the block
          x.setData((byte) 0);
          x.setType(Material.AIR);
        }
      }
    }

    if (Permissions.getInstance().woodcutting(player)) {
      Skills.xpProcessing(player, profile, SkillType.WOODCUTTING, xp);
    }
  }
Example #29
0
  @Override
  protected void onPlayerMove(PlayerMoveEvent evt, Player P) {
    // TODO Auto-generated method stub
    super.onPlayerMove(evt, P);
    Player ply = evt.getPlayer();
    if (isSpectator(ply)) return;
    if (JocIniciat) {
      Player plyr = evt.getPlayer();

      Location to = evt.getTo();
      Location from = evt.getFrom();

      int equip = obtenirEquip(ply).getId() + 1;
      if (ply.getLocation().getY() < 102) {
        ply.setFireTicks(5000);
      }
      if (ply.getLocation().getY() < 60) {
        ply.damage(10000);
      }

      // Torres escuts
      int e = 1;
      while (e <= 2) {
        int i = 0;
        while (i <= 1) {
          Cuboid cub =
              pMapaActual()
                  .ObtenirCuboid("RegT" + Integer.toString(e) + Integer.toString(i), getWorld());
          Location center = cub.getCenter();
          if (cub.contains(to.getBlock())) {
            if (e == equip) {
              Vector vec = Utils.CrearVector(center, from).normalize().add(new Vector(0, 1, 0));
              getWorld().playSound(to, Sound.IRONGOLEM_HIT, 1F, 2.2F);
              getWorld().playEffect(to, Effect.MOBSPAWNER_FLAMES, 3);
              getWorld()
                  .playEffect(to.clone().add(new Vector(0, 1, 0)), Effect.MOBSPAWNER_FLAMES, 3);
              if (cub.contains(from.getBlock()) && plyr.getVelocity().length() >= 1) {
                plyr.teleport(from.add(vec));
                // Bukkit.broadcastMessage("ha entrat");
              } else {
                plyr.setVelocity(vec);
              }
              // evt.setCancelled(true);

            }
          }
          i = i + 1;
        }
        e = e + 1;
      }
      // SECURE NO-FALL
      //
      boolean isNoFallActive = false;

      ItemStack itemInHand = ply.getItemInHand();
      if (itemInHand.hasItemMeta()) {
        ItemMeta itemMeta = itemInHand.getItemMeta();
        if (itemMeta.hasDisplayName()) {
          if (itemMeta.getDisplayName().equals(getBridgeToolName())) {
            isNoFallActive = true;
          }
        }
      }

      if (isNoFallActive) {
        Vector v = Utils.CrearVector(evt.getFrom(), evt.getTo());
        v.multiply(1.45D);
        v.setY(0);
        Block bDown = evt.getTo().add(v).getBlock().getRelative(BlockFace.DOWN);
        if (bDown.isEmpty() && bDown.getRelative(BlockFace.DOWN).isEmpty()) {
          ItemStack placeableItemStack = getPlaceableItemStack(ply);
          if (placeableItemStack != null) {
            bDown.setType(placeableItemStack.getType());
            bDown.setData(placeableItemStack.getData().getData());
            ItemStack sampleIt = new ItemStack(placeableItemStack);
            sampleIt.setAmount(1);
            ply.getInventory().removeItem(sampleIt);
            itemInHand.setDurability((short) (itemInHand.getDurability() + 3));
          }
        }
      }
    }
  }
    @SuppressWarnings("deprecation")
    public void createDropOffPoint(Chunk c) {
      int xmin = dropOffCenter.getBlockX() - 3, xmax = dropOffCenter.getBlockX() + 3;
      int zmin = dropOffCenter.getBlockZ() - 3, zmax = dropOffCenter.getBlockZ() + 3;
      int ymin = dropOffCenter.getBlockY();

      for (int x = xmin - 4; x <= xmax + 4; x++)
        for (int z = zmin - 4; z <= zmax + 4; z++)
          c.getBlock(x, ymin - 1, z).setType(Material.GRAVEL);

      // now, generate a hut for the drop-off
      for (int x = xmin + 1; x < xmax; x++) {
        c.getBlock(x, ymin, zmin + 1).setType(Material.WOOD);
        c.getBlock(x, ymin, zmax - 1).setType(Material.WOOD);

        c.getBlock(x, ymin + 4, zmin + 1).setType(Material.WOOD_STEP);
        c.getBlock(x, ymin + 4, zmax - 1).setType(Material.WOOD_STEP);
      }

      for (int x = xmin; x <= xmax; x++) {
        Block b = c.getBlock(x, ymin, zmin);
        b.setType(Material.WOOD_STAIRS);
        b.setData((byte) 0x2);

        b = c.getBlock(x, ymin, zmax);
        b.setType(Material.WOOD_STAIRS);
        b.setData((byte) 0x3);
      }

      for (int z = zmin + 2; z < zmax - 1; z++) {
        c.getBlock(xmin + 1, ymin, z).setType(Material.WOOD);
        c.getBlock(xmax - 1, ymin, z).setType(Material.WOOD);

        c.getBlock(xmin + 1, ymin + 4, z).setType(Material.WOOD_STEP);
        c.getBlock(xmax - 1, ymin + 4, z).setType(Material.WOOD_STEP);
      }

      for (int z = zmin; z <= zmax; z++) {
        Block b = c.getBlock(xmin, ymin, z);
        b.setType(Material.WOOD_STAIRS);
        b.setData((byte) 0x0);

        b = c.getBlock(xmax, ymin, z);
        b.setType(Material.WOOD_STAIRS);
        b.setData((byte) 0x1);
      }

      for (int x = xmin + 2; x <= xmax - 2; x++)
        for (int z = zmin + 2; z <= zmax - 2; z++) {
          c.getBlock(x, ymin, z).setType(Material.LAPIS_BLOCK);
          c.getBlock(x, ymin + 4, z).setType(Material.WOOD);
        }

      for (int y = ymin + 1; y < ymin + 4; y++) {
        c.getBlock(xmin + 1, y, zmin + 1).setType(Material.FENCE);
        c.getBlock(xmax - 1, y, zmin + 1).setType(Material.FENCE);
        c.getBlock(xmin + 1, y, zmax - 1).setType(Material.FENCE);
        c.getBlock(xmax - 1, y, zmax - 1).setType(Material.FENCE);
      }

      c.getBlock(dropOffCenter.getBlockX(), ymin + 4, dropOffCenter.getBlockZ())
          .setType(Material.GLOWSTONE);
      c.getBlock(dropOffCenter.getBlockX(), ymin + 5, dropOffCenter.getBlockZ())
          .setType(Material.WOOD_STEP);

      c.getBlock(xmin + 2, ymin + 5, zmin + 2).setType(Material.TORCH);
      c.getBlock(xmax - 2, ymin + 5, zmin + 2).setType(Material.TORCH);
      c.getBlock(xmin + 2, ymin + 5, zmax - 2).setType(Material.TORCH);
      c.getBlock(xmax - 2, ymin + 5, zmax - 2).setType(Material.TORCH);
    }