/**
  * 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);
           }
         }
       }
     }
   }
 }
Beispiel #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.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);
   }
 }