/**
  * Remove a island from SkyBlock.
  *
  * @param l given location
  */
 public void removeIsland(Location l) {
   if (l != null) {
     int px = l.getBlockX();
     int py = l.getBlockY();
     int pz = l.getBlockZ();
     for (int x = -15; x <= 15; x++) {
       for (int y = -15; y <= 15; y++) {
         for (int z = -15; z <= 15; z++) {
           Block b = new Location(l.getWorld(), px + x, py + y, pz + z).getBlock();
           if (b.getType() != Material.AIR) {
             if (b.getType() == Material.CHEST) {
               Chest c = (Chest) b.getState();
               ItemStack[] items = new ItemStack[c.getInventory().getContents().length];
               c.getInventory().setContents(items);
             } else if (b.getType() == Material.FURNACE) {
               Furnace f = (Furnace) b.getState();
               ItemStack[] items = new ItemStack[f.getInventory().getContents().length];
               f.getInventory().setContents(items);
             } else if (b.getType() == Material.DISPENSER) {
               Dispenser d = (Dispenser) b.getState();
               ItemStack[] items = new ItemStack[d.getInventory().getContents().length];
               d.getInventory().setContents(items);
             }
             b.setType(Material.AIR);
           }
         }
       }
     }
   }
 }
Ejemplo n.º 2
0
  public ItemStack getTool() {
    Dispenser disp = (Dispenser) getDispenser().getState();
    Inventory inv = disp.getInventory();
    for (ItemStack item : inv.getContents()) {
      if (item == null) continue;

      if (item.getType() == Material.DIAMOND_AXE
          || item.getType() == Material.GOLD_AXE
          || item.getType() == Material.IRON_AXE
          || item.getType() == Material.STONE_AXE
          || item.getType() == Material.WOOD_AXE) {
        return item;
      }
    }

    return null;
  }
  @EventHandler(priority = EventPriority.LOWEST)
  public void onInventoryOpenEvent(InventoryOpenEvent event) {
    if (event.isCancelled()
        || event.getInventory() == null
        || event.getInventory().getHolder() == null) return;

    final Player player = (Player) event.getPlayer();
    final InventoryHolder h = event.getInventory().getHolder();

    if (h instanceof Chest
        || h instanceof DoubleChest
        || h instanceof Furnace
        || h instanceof Dispenser) {
      if (player.getWorld() != plugin.getIslandWorld()) return;
      if (player.isOp()) return;
      if (player.hasPermission("islandworld.bypass.island")) return;

      Location loc = player.getLocation();
      if (event.getInventory().getHolder() instanceof Chest) {
        final Chest chest = (Chest) event.getInventory().getHolder();
        loc = chest.getLocation();
      } else if (event.getInventory().getHolder() instanceof Furnace) {
        final Furnace fur = (Furnace) event.getInventory().getHolder();
        loc = fur.getLocation();
      } else if (event.getInventory().getHolder() instanceof DoubleChest) {
        final DoubleChest chest = (DoubleChest) event.getInventory().getHolder();
        loc = chest.getLocation();
      } else if (event.getInventory().getHolder() instanceof Dispenser) {
        final Dispenser disp = (Dispenser) event.getInventory().getHolder();
        loc = disp.getLocation();
      }

      if (!(plugin.canBuildOnLocation(player, loc))) event.setCancelled(true);
    }

    plugin.debug(
        "Event :"
            + event.getEventName()
            + ", class: "
            + h.getClass()
            + ", cancelled:"
            + event.isCancelled());
  }
Ejemplo n.º 4
0
 @EventHandler(priority = EventPriority.NORMAL)
 public void onEntityExplode(EntityExplodeEvent event) {
   if (event.isCancelled() || event.getEntity() == null) return;
   Boolean cancel = false;
   EntityType entity = event.getEntityType();
   FlagPermissions perms = Residence.getPermsByLoc(event.getEntity().getLocation());
   if (entity == EntityType.CREEPER) {
     if (!perms.has("creeper", perms.has("explode", true))) {
       cancel = true;
     }
   }
   if (entity == EntityType.PRIMED_TNT) {
     if (!perms.has("tnt", perms.has("explode", true))) {
       cancel = true;
     }
   }
   if (entity == EntityType.FIREBALL) {
     if (!perms.has("fireball", perms.has("explode", true))) {
       event.setCancelled(true);
       event.getEntity().remove();
     }
   }
   if (cancel) {
     event.setCancelled(true);
     event.getEntity().remove();
   } else {
     for (Block block : event.blockList()) {
       FlagPermissions blockperms = Residence.getPermsByLoc(block.getLocation());
       if ((!blockperms.has("fireball", perms.has("explode", true))
               && entity == EntityType.FIREBALL)
           || (!blockperms.has("tnt", perms.has("explode", true))
               && entity == EntityType.PRIMED_TNT)
           || (!blockperms.has("creeper", perms.has("explode", true))
               && entity == EntityType.CREEPER)) {
         if (block != null) {
           ItemStack[] inventory = null;
           BlockState save = block.getState();
           if (block.getType() == Material.CHEST) {
             Chest chest = (Chest) save;
             inventory = chest.getInventory().getContents();
             chest.getInventory().clear();
           }
           if (block.getType() == Material.FURNACE
               || block.getType() == Material.BURNING_FURNACE) {
             Furnace furnace = (Furnace) save;
             inventory = furnace.getInventory().getContents();
             furnace.getInventory().clear();
           }
           if (block.getType() == Material.BREWING_STAND) {
             BrewingStand brew = (BrewingStand) save;
             inventory = brew.getInventory().getContents();
             brew.getInventory().clear();
           }
           if (block.getType() == Material.DISPENSER) {
             Dispenser dispenser = (Dispenser) save;
             inventory = dispenser.getInventory().getContents();
             dispenser.getInventory().clear();
           }
           if (block.getType() == Material.JUKEBOX) {
             Jukebox jukebox = (Jukebox) save;
             if (jukebox.isPlaying()) {
               inventory = new ItemStack[1];
               inventory[0] = new ItemStack(jukebox.getPlaying());
               jukebox.setPlaying(null);
             }
           }
           ExplodeRestore.put(save, inventory);
           block.setType(Material.AIR);
         }
       }
     }
     Residence.getServ()
         .getScheduler()
         .scheduleSyncDelayedTask(
             Residence.getServ().getPluginManager().getPlugin("Residence"),
             new Runnable() {
               public void run() {
                 for (BlockState block : ExplodeRestore.keySet().toArray(new BlockState[0])) {
                   ItemStack[] inventory = ExplodeRestore.get(block);
                   block.update(true);
                   if (inventory != null) {
                     if (block.getType() == Material.CHEST)
                       ((Chest) block.getLocation().getBlock().getState())
                           .getInventory()
                           .setContents(inventory);
                     if (block.getType() == Material.FURNACE
                         || block.getType() == Material.BURNING_FURNACE)
                       ((Furnace) block.getLocation().getBlock().getState())
                           .getInventory()
                           .setContents(inventory);
                     if (block.getType() == Material.BREWING_STAND)
                       ((BrewingStand) block.getLocation().getBlock().getState())
                           .getInventory()
                           .setContents(inventory);
                     if (block.getType() == Material.DISPENSER)
                       ((Dispenser) block.getLocation().getBlock().getState())
                           .getInventory()
                           .setContents(inventory);
                     if (block.getType() == Material.JUKEBOX)
                       ((Jukebox) block.getLocation().getBlock().getState())
                           .setPlaying(inventory[0].getType());
                   }
                 }
                 ExplodeRestore.clear();
               }
             },
             1L);
   }
 }