예제 #1
0
 @EventHandler(priority = EventPriority.NORMAL)
 public void onBlockBreak(BlockBreakEvent event) {
   Block block = event.getBlock();
   if ((block.getType() == Material.SIGN_POST || block.getType() == Material.WALL_SIGN)) {
     Sign s = (Sign) block.getState();
     if (!plugin.loc.containsKey(block.getLocation())) {
       for (int i = 0; i < s.getLines().length; i++) {
         if (s.getLine(i).toLowerCase().contains("[sortal]")
             || s.getLine(i).toLowerCase().contains(plugin.signContains)) {
           if (!event.getPlayer().hasPermission("sortal.delsign")) {
             event
                 .getPlayer()
                 .sendMessage("[Sortal] You do not have permissions to destroy a [Sortal] sign!");
             event.setCancelled(true);
           }
         }
       }
       return;
     }
     if (!event.getPlayer().hasPermission("sortal.delsign")) {
       event
           .getPlayer()
           .sendMessage("[Sortal] You do not have permissions to destroy a registered sign!");
       event.setCancelled(true);
       return;
     }
     delLoc(block.getLocation());
     plugin.log.info(
         "Registered sign destroyed by "
             + event.getPlayer().getDisplayName()
             + ", AKA "
             + event.getPlayer().getName()
             + "!");
   }
 }
예제 #2
0
  public boolean onCommand(CommandSender sender, Command cmd, String CommandLabel, String args[]) {

    if (sender instanceof Player) {
      Player Spieler = (Player) sender;

      if (cmd.getName().equalsIgnoreCase("xA-EasyQuest")) {
        Block TargetBlock = Spieler.getPlayer().getTargetBlock(null, 10);

        if (TargetBlock.getType().toString().equalsIgnoreCase("SIGN_POST")
            || Spieler.getPlayer()
                .getTargetBlock(null, 10)
                .getType()
                .toString()
                .equalsIgnoreCase("WALL_SIGN")) {
          Spieler.sendMessage("WELL DONE!" + TargetBlock.getType().SIGN_POST.toString());
          // Sign TeleSign = ;^

        }
        return true;
      }

    } else {
      sender.sendMessage("You are no Player");
    }

    return false;
  }
예제 #3
0
  @Override
  public void populate(World world, Random rand, Chunk chunk) {
    int x, y, z;
    Block block;

    for (x = 0; x < 16; ++x) {
      for (z = 0; z < 16; ++z) {
        for (y = 80; chunk.getBlock(x, y, z).getType() == Material.AIR; --y) ;
        block = chunk.getBlock(x, y, z);
        if (block != null) {
          // snow on snow biomes
          if ((block.getBiome() == Biome.FROZEN_OCEAN)
              || (block.getBiome() == Biome.FROZEN_RIVER)
              || (block.getBiome() == Biome.ICE_DESERT)
              || (block.getBiome() == Biome.ICE_MOUNTAINS)
              || (block.getBiome() == Biome.ICE_PLAINS)
              || (block.getBiome() == Biome.TUNDRA)
              || (block.getBiome() == Biome.EXTREME_HILLS)) {
            if ((block.getType() == Material.RED_ROSE)
                || (block.getType() == Material.YELLOW_FLOWER)
                || (block.getType() == Material.LONG_GRASS)
                || (block.getType() == Material.CACTUS)
                || (block.getType() == Material.SUGAR_CANE_BLOCK)) {
            } else if ((block.getType() == Material.STATIONARY_WATER)
                || (block.getType() == Material.WATER)) {
              block.setType(Material.ICE);
            } else {
              block.getRelative(0, 1, 0).setTypeId(Material.SNOW.getId());
            }
          }
        }
      }
    }
  }
  public void onPlayerInteract(PlayerInteractEvent pie) {
    if (Action.LEFT_CLICK_BLOCK.equals(pie.getAction())
        || (isValidBlock(pie.getClickedBlock())
            && Action.RIGHT_CLICK_BLOCK.equals(pie.getAction()))) {
      Block clicked = pie.getClickedBlock();
      Block behind = clicked.getRelative(pie.getBlockFace().getOppositeFace());

      SecretDoor door = null;

      if (Material.WOODEN_DOOR.equals(clicked.getType()) && !SecretDoor.isDoubleDoor(clicked)) {
        if (this.plugin.isSecretDoor(SecretDoor.getKeyFromBlock(clicked))) {
          this.plugin.closeDoor(SecretDoor.getKeyFromBlock(clicked));
        } else if (!Material.AIR.equals(behind.getType())) {
          if (SecretDoor.isAdjacentDoor(clicked, pie.getBlockFace()))
            door = new SecretDoor(clicked, behind, SecretDoor.Direction.DOOR_FIRST);
        }

      } else if (Material.WOODEN_DOOR.equals(behind.getType())
          && !SecretDoor.isDoubleDoor(behind)) {
        if (this.plugin.isSecretDoor(SecretDoor.getKeyFromBlock(behind))) {
          this.plugin.closeDoor(SecretDoor.getKeyFromBlock(behind));
        } else if (SecretDoor.isAdjacentDoor(behind, pie.getBlockFace().getOppositeFace()))
          door = new SecretDoor(behind, clicked, SecretDoor.Direction.BLOCK_FIRST);
      }

      if (!(door == null)) {
        plugin.addDoor(door).open();
        pie.getPlayer().sendMessage(ChatColor.RED + "Don't forget to close the door!");
      }
    }
  }
 /**
  * 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);
           }
         }
       }
     }
   }
 }
예제 #6
0
  public BlockData getWorldBlockType() {
    Block b1, b2;
    Material mat1, mat2;
    byte data1, data2;
    boolean legacyBlockFace = BlockFace.NORTH.getModX() == -1;
    // This all needs to be remathed. Ugh.
    if (legacyBlockFace) {
      if (this.facingNorth) {
        b1 = this.keyBlock.getRelative(BlockFace.UP, 3).getRelative(BlockFace.EAST);
        b2 = this.keyBlock.getRelative(BlockFace.UP, 3).getRelative(BlockFace.WEST, 2);
      } else {
        b1 = this.keyBlock.getRelative(BlockFace.UP, 3).getRelative(BlockFace.NORTH);
        b2 = this.keyBlock.getRelative(BlockFace.UP, 3).getRelative(BlockFace.SOUTH, 2);
      }
    } else {
      if (this.facingNorth) {
        b1 = this.keyBlock.getRelative(BlockFace.UP, 3).getRelative(BlockFace.NORTH);
        b2 = this.keyBlock.getRelative(BlockFace.UP, 3).getRelative(BlockFace.SOUTH, 2);
      } else {
        b1 = this.keyBlock.getRelative(BlockFace.UP, 3).getRelative(BlockFace.WEST);
        b2 = this.keyBlock.getRelative(BlockFace.UP, 3).getRelative(BlockFace.EAST, 2);
      }
    }

    mat1 = b1.getType();
    mat2 = b2.getType();
    data1 = b1.getData();
    data2 = b2.getData();

    if (mat1.equals(mat2) && data1 == data2) {
      return new BlockData(mat1, data1);
    }
    return null;
  }
예제 #7
0
 @Override
 protected void onBlockHitByProjectile(ProjectileHitEvent evt, Block b, Projectile proj) {
   // TODO Auto-generated method stub
   super.onBlockHitByProjectile(evt, b, proj);
   // sendGlobalMessage("Pilotassa");
   Material t = b.getType();
   if (t == Material.GLASS
       || t == Material.STAINED_GLASS
       || t == Material.STAINED_GLASS_PANE
       || t == Material.THIN_GLASS
       || t == Material.GLOWSTONE) {
     b.setType(Material.AIR);
     getWorld().playSound(b.getLocation(), Sound.GLASS, 15F, 1.2F);
     proj.remove();
     for (BlockFace f : BlockFace.values()) {
       if (GUtils.Possibilitat(58)) continue;
       Block relative = b.getRelative(f);
       t = relative.getType();
       if (t == Material.GLASS
           || t == Material.STAINED_GLASS
           || t == Material.STAINED_GLASS_PANE
           || t == Material.THIN_GLASS
           || t == Material.GLOWSTONE) {
         relative.setType(Material.AIR);
       }
     }
   }
 }
예제 #8
0
  /** Removes chests when they're destroyed. */
  @EventHandler(priority = EventPriority.HIGHEST)
  public void onBreak(final BlockBreakEvent e) {
    if (e.isCancelled()) return;

    Block b = e.getBlock();
    Player p = e.getPlayer();

    // If the chest was a chest
    if (b.getType() == Material.CHEST) {
      Shop shop = plugin.getShopManager().getShop(b.getLocation());
      // If it was a shop
      if (shop != null) {
        if (plugin.lock) {
          // If they owned it or have bypass perms, they can destroy it
          if (!shop.getOwner().equalsIgnoreCase(p.getName())
              && !p.hasPermission("quickshop.other.destroy")) {
            e.setCancelled(true);
            p.sendMessage(MsgUtil.getMessage("no-permission"));
            return;
          }
        }

        // If they're either survival or the owner, they can break it
        if (p.getGameMode() == GameMode.CREATIVE
            && !p.getName().equalsIgnoreCase(shop.getOwner())) {
          e.setCancelled(true);
          p.sendMessage(MsgUtil.getMessage("no-creative-break"));
          return;
        }

        // Cancel their current menu... Doesnt cancel other's menu's.
        Info action = plugin.getShopManager().getActions().get(p.getName());
        if (action != null) {
          action.setAction(ShopAction.CANCELLED);
        }
        shop.delete();
        p.sendMessage(MsgUtil.getMessage("success-removed-shop"));
      }
    } else if (b.getType() == Material.WALL_SIGN) {
      Shop shop = getShopNextTo(e.getBlock().getLocation());
      if (shop != null) { // It is a shop sign we're dealing with.
        if (plugin.lock) {
          // If they're the shop owner or have bypass perms, they can destroy it.
          if (!shop.getOwner().equalsIgnoreCase(p.getName())
              && !e.getPlayer().hasPermission("quickshop.other.destroy")) {
            e.setCancelled(true);
            p.sendMessage(MsgUtil.getMessage("no-permission"));
            return;
          }
        }
        // If they're in creative and not the owner, don't let them (accidents happen)
        if (p.getGameMode() == GameMode.CREATIVE
            && !p.getName().equalsIgnoreCase(shop.getOwner())) {
          e.setCancelled(true);
          p.sendMessage(MsgUtil.getMessage("no-creative-break"));
          return;
        }
      }
    }
  }
예제 #9
0
  private void placePlayerSafely(final Player player, final Location spawnLoc) {
    Location loc = null;
    if (spawnLoc == null) return;
    if (!Settings.noTeleport) return;
    if (Settings.isTeleportToSpawnEnabled
        || (Settings.isForceSpawnLocOnJoinEnabled
            && Settings.getForcedWorlds.contains(player.getWorld().getName()))) return;
    if (!database.isAuthAvailable(player.getName().toLowerCase()) || !player.hasPlayedBefore())
      return;
    Block b = player.getLocation().getBlock();
    if (b.getType() == Material.PORTAL || b.getType() == Material.ENDER_PORTAL) {
      m.send(player, "unsafe_spawn");
      if (spawnLoc.getWorld() != null) loc = spawnLoc;
    } else {
      Block c = player.getLocation().add(0D, 1D, 0D).getBlock();
      if (c.getType() == Material.PORTAL || c.getType() == Material.ENDER_PORTAL) {
        m.send(player, "unsafe_spawn");
        if (spawnLoc.getWorld() != null) loc = spawnLoc;
      }
    }
    if (loc != null) {
      final Location floc = loc;
      Bukkit.getScheduler()
          .scheduleSyncDelayedTask(
              plugin,
              new Runnable() {

                @Override
                public void run() {
                  player.teleport(floc);
                }
              });
    }
  }
  /**
   * Checks if one of the Signs saved is the passed block
   *
   * @param block
   * @return
   */
  public boolean isSpawnSign(Block block) {
    if (block.getType().equals(Material.CHEST)) {

      Block doubleChest = getDoubleChest(block);
      for (SpawnChest chest : chests) {
        if (block.equals(doubleChest)) {
          return true;
        }

        if (block.equals(chest.getLocation().getBlock())) {
          return true;
        }
      }
    }

    if (block.getType().equals(Material.SIGN_POST)) {
      for (SpawnSign sign : signs) {
        if (sign.getLocation().getBlock().equals(block)) {
          return true;
        }
      }
    }

    return false;
  }
예제 #11
0
 /**
  * Blocks block breaking inside an arena for players not in that arena,<br>
  * or if the block's material is not whitelisted for breaking.
  *
  * <p>Stops blocks with ug signs attached from breaking.
  */
 @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
 public void onBlockBreak(BlockBreakEvent event) {
   Arena arena = ultimateGames.getArenaManager().getLocationArena(event.getBlock().getLocation());
   if (arena != null) {
     String playerName = event.getPlayer().getName();
     if (ultimateGames.getPlayerManager().isPlayerInArena(playerName)) {
       if (!ultimateGames.getPlayerManager().getArenaPlayer(playerName).isEditing()) {
         if (arena.getStatus() == ArenaStatus.RUNNING
             && ultimateGames
                 .getWhitelistManager()
                 .getBlockBreakWhitelist()
                 .canBreakMaterial(arena.getGame(), event.getBlock().getType())) {
           Block block = event.getBlock();
           if ((block.getType() == Material.SIGN_POST || block.getType() == Material.WALL_SIGN)
               && ultimateGames.getUGSignManager().isUGSign((Sign) block.getState())) {
             event.setCancelled(true);
             return;
           }
           for (Sign attachedSign : UGUtils.getAttachedSigns(block, true)) {
             if (ultimateGames.getUGSignManager().isUGSign(attachedSign)) {
               event.setCancelled(true);
               return;
             }
           }
           arena.getGame().getGamePlugin().onBlockBreak(arena, event);
         } else {
           event.setCancelled(true);
         }
       }
     } else {
       event.setCancelled(true);
     }
   }
 }
예제 #12
0
  @EventHandler
  public void onMove(PlayerMoveEvent e) {
    Player p = e.getPlayer();
    double x = p.getLocation().getX();
    double y = p.getLocation().getY() - 1;
    double z = p.getLocation().getZ();
    Location loc = new Location(p.getWorld(), x, y, z);
    Block b1 = loc.getBlock();
    Block b2 = p.getLocation().getBlock();

    if (b1.getType().equals(Material.REDSTONE_BLOCK) && b2.getType().equals(Material.WOOD_PLATE)) {
      // p.sendMessage("ON " + b1.getType().toString() + " + " + b2.getType().toString());
      p.setVelocity(p.getLocation().getDirection().multiply(2).setY(p.getVelocity().getY() + 1));
      p.setFallDistance(0f);
      for (Player all : Bukkit.getOnlinePlayers()) {
        all.playSound(p.getLocation(), Sound.WITHER_SHOOT, 0.1f, 0.1f);
      }
    }

    p.setSaturation(100f);
    p.setFoodLevel(20);
    p.setHealth(20f);

    if (p.getLocation().getY() <= 80) {
      p.teleport(p.getWorld().getSpawnLocation());
      p.setGameMode(GameMode.ADVENTURE);
      p.setAllowFlight(true);
      p.setFlying(false);
    }
  }
 @HawkEvent(dataType = DataType.BLOCK_BREAK)
 public void onBlockBreak(BlockBreakEvent event) {
   Block block = event.getBlock();
   if (block.getType() == Material.WALL_SIGN || block.getType() == Material.SIGN_POST)
     DataManager.addEntry(new SignEntry(event.getPlayer(), DataType.SIGN_BREAK, event.getBlock()));
   DataManager.addEntry(new BlockEntry(event.getPlayer(), DataType.BLOCK_BREAK, block));
 }
예제 #14
0
  public void storeNonSolidBlocks() {
    sensitiveBlocks = new LinkedList<Location>();
    Iterator<Entry<Location, StructureBlock>> i = blocks.entrySet().iterator();
    while (i.hasNext()) {
      StructureBlock current = i.next().getValue();

      if (Structure.annoyingBlocks.contains(current.originalBlock.getType())) {
        sensitiveBlocks.add(current.location);
        if (current.originalBlock.getType() == Material.IRON_DOOR_BLOCK
            || current.originalBlock.getType() == Material.WOODEN_DOOR) {
          Block above = current.originalBlock.getBlock().getRelative(BlockFace.UP);
          Block below = current.originalBlock.getBlock().getRelative(BlockFace.DOWN);
          if (above.getType() == Material.IRON_DOOR_BLOCK
              || above.getType() == Material.WOODEN_DOOR) {
            current.originalBlock.getBlock().setType(Material.AIR);
            above.setType(Material.AIR);
            continue;
          } else if (below.getType() == Material.IRON_DOOR_BLOCK
              || below.getType() == Material.WOODEN_DOOR) {
            below.setType(Material.AIR);
            current.originalBlock.getBlock().setType(Material.AIR);
            continue;
          }
        }
        current.originalBlock.getBlock().setType(Material.AIR);
      }
    }
  }
  /* (non-Javadoc)
   * @see org.bukkit.event.player.PlayerListener#onPlayerInteract(org.bukkit.event.player.PlayerInteractEvent)
   */
  @Override
  public void onPlayerInteract(PlayerInteractEvent event) {
    Block clicked = event.getClickedBlock();
    Player player = event.getPlayer();

    if (clicked != null
        && (clicked.getType() == Material.STONE_BUTTON || clicked.getType() == Material.LEVER)) {
      if (!this.ButtonLeverHit(player, clicked, null)) {
        event.setCancelled(true);
      }
    } else if (clicked != null && clicked.getType() == Material.WALL_SIGN) {
      Stargate stargate = StargateManager.getGateFromBlock(clicked);

      if (stargate != null) {
        if (WXPermissions.checkWXPermissions(player, stargate, PermissionType.SIGN)) {
          if (stargate.TryClickTeleportSign(clicked)) {
            String target = "";
            if (stargate.SignTarget != null) {
              target = stargate.SignTarget.Name;
            }
            player.sendMessage("Dialer set to: " + target);
          }
        } else {
          player.sendMessage(ConfigManager.output_strings.get(StringTypes.PERMISSION_NO));
          event.setCancelled(true);
        }
      }
    }
  }
  private boolean editSign(CommandSender sender, String[] args) {
    if (!(sender instanceof Player)) return true;

    if (args.length == 0) return false;
    if (!args[0].matches("^[0-9]+$")) return false;

    int lineNo = Integer.parseInt(args[0]) - 1;
    String newLine = "";
    for (int i = 1; i < args.length; i++) {
      newLine += args[i] + " ";
    }
    newLine = newLine.trim();
    System.out.println("-" + newLine + "-");

    Player player = (Player) sender;
    Block b = player.getTargetBlock(null, 5);
    System.out.println(b);
    if (b != null && (b.getType() == Material.SIGN_POST || b.getType() == Material.WALL_SIGN)) {
      Sign sign = (Sign) b.getState();
      String[] lines = sign.getLines();
      lines[lineNo] = newLine;
      SignChangeEvent event = new SignChangeEvent(b, player, lines);
      Bukkit.getPluginManager().callEvent(event);
      if (!event.isCancelled()) {
        sign.setLine(lineNo, newLine);
        sign.update();
      }
    }

    return true;
  }
 public void run() {
   for (String s : lifewalkers.toArray(strArr)) {
     Player player = Bukkit.getServer().getPlayer(s);
     if (player != null) {
       if (isExpired(player)) {
         turnOff(player);
         continue;
       }
       Block feet = player.getLocation().getBlock();
       Block ground = feet.getRelative(BlockFace.DOWN);
       if (feet.getType() == Material.AIR
           && (ground.getType() == Material.DIRT || ground.getType() == Material.GRASS)) {
         if (ground.getType() == Material.DIRT) {
           ground.setType(Material.GRASS);
         }
         int rand = random.nextInt(100);
         if (rand < redFlowerChance) {
           feet.setType(Material.RED_ROSE);
           addUse(player);
           chargeUseCost(player);
         } else {
           rand -= redFlowerChance;
           if (rand < yellowFlowerChance) {
             feet.setType(Material.YELLOW_FLOWER);
             addUse(player);
             chargeUseCost(player);
           } else {
             rand -= yellowFlowerChance;
             if (rand < saplingChance) {
               feet.setType(Material.SAPLING);
               addUse(player);
               chargeUseCost(player);
             } else {
               rand -= saplingChance;
               if (rand < tallgrassChance) {
                 BlockState state = feet.getState();
                 state.setType(Material.LONG_GRASS);
                 state.setData(new LongGrass(GrassSpecies.NORMAL));
                 state.update(true);
                 addUse(player);
                 chargeUseCost(player);
               } else {
                 rand -= tallgrassChance;
                 if (rand < fernChance) {
                   BlockState state = feet.getState();
                   state.setType(Material.LONG_GRASS);
                   state.setData(new LongGrass(GrassSpecies.FERN_LIKE));
                   state.update(true);
                   addUse(player);
                   chargeUseCost(player);
                 }
               }
             }
           }
         }
       }
     }
   }
 }
예제 #18
0
  public boolean handleCommand(String[] args, CommandSender sender) {
    Player p = null;
    if (sender instanceof Player) p = (Player) sender;
    if (args.length >= 1) {
      if (p == null) {
        sender.sendMessage(playerOnly);
        return true;
      }
      if (args[0].equalsIgnoreCase("add")) {
        if (!Main.cmdhandler.pm.hasPlayerPermission(p, Permission.MPVP_RS_ADD)) {
          sender.sendMessage(this.noPermMsg);
          return true;
        }
        Block tb = p.getTargetBlock((HashSet<Byte>) null, 10);
        if (tb != null && (tb.getType().equals(Material.WALL_SIGN))) {
          String name = "";
          boolean sky = true;
          if (args.length >= 2) {
            name = args[1];
            if (args.length >= 3) {
              try {
                sky = Boolean.parseBoolean(args[2]);
              } catch (Exception ex) {
              }
              ;
            }
          }
          Sign sign = (Sign) tb.getState();
          RadioStation.buildRadioStation(sign, RadioStation.getFacing(sign));
          Main.gameEngine.configuration.addRadioStation(new RadioStationContainer(sign, name, sky));
          Main.gameEngine.configuration.addNewProtectedRegion(
              sign.getLocation().clone().subtract(11d, 11d, 11d),
              sign.getLocation().clone().add(11d, 11d, 11d));
          sender.sendMessage(ChatColor.DARK_GREEN + Main.gameEngine.dict.get("addRs"));
        } else {
          sender.sendMessage(ChatColor.DARK_RED + Main.gameEngine.dict.get("mustPointOnSign"));
        }
        return true;
      }

      if (args[0].equalsIgnoreCase("remove")) {
        if (!Main.cmdhandler.pm.hasPlayerPermission(p, Permission.MPVP_RS_DEL)) {
          sender.sendMessage(this.noPermMsg);
          return true;
        }
        Block tb = p.getTargetBlock((HashSet<Byte>) null, 10);
        if (tb != null && (tb.getType().equals(Material.WALL_SIGN))) {
          Sign sign = (Sign) tb.getState();
          Main.gameEngine.configuration.removeRadioStation(sign);
          sender.sendMessage(ChatColor.DARK_GREEN + Main.gameEngine.dict.get("rmRs"));
        } else {
          sender.sendMessage(ChatColor.DARK_RED + Main.gameEngine.dict.get("mustPointOnSign"));
        }
        return true;
      }
    }
    return false;
  }
  @EventHandler(priority = EventPriority.HIGHEST)
  public void onEntityExplode(final EntityExplodeEvent event) {
    if (event.isCancelled()) {
      return;
    }
    final int maxHeight = ess.getSettings().getProtectCreeperMaxHeight();

    if (event.getEntity() instanceof EnderDragon
        && prot.getSettingBool(ProtectConfig.prevent_enderdragon_blockdmg)) {
      event.setCancelled(true);
      if (prot.getSettingBool(ProtectConfig.enderdragon_fakeexplosions)) {
        event.getLocation().getWorld().createExplosion(event.getLocation(), 0F);
      }
      return;
    } else if (event.getEntity() instanceof Creeper
        && (prot.getSettingBool(ProtectConfig.prevent_creeper_explosion)
            || prot.getSettingBool(ProtectConfig.prevent_creeper_blockdmg)
            || (maxHeight >= 0 && event.getLocation().getBlockY() > maxHeight))) {
      // Nicccccccccce plaaacccccccccce..
      event.setCancelled(true);
      event.getLocation().getWorld().createExplosion(event.getLocation(), 0F);
      return;
    } else if (event.getEntity() instanceof TNTPrimed
        && prot.getSettingBool(ProtectConfig.prevent_tnt_explosion)) {
      event.setCancelled(true);
      return;
    } else if ((event.getEntity() instanceof Fireball || event.getEntity() instanceof SmallFireball)
        && prot.getSettingBool(ProtectConfig.prevent_fireball_explosion)) {
      event.setCancelled(true);
      return;
    }
    // This code will prevent explosions near protected rails, signs or protected chests
    // TODO: Use protect db instead of this code

    for (Block block : event.blockList()) {
      if ((block.getRelative(BlockFace.UP).getType() == Material.RAILS
              || block.getType() == Material.RAILS
              || block.getRelative(BlockFace.UP).getType() == Material.POWERED_RAIL
              || block.getType() == Material.POWERED_RAIL
              || block.getRelative(BlockFace.UP).getType() == Material.DETECTOR_RAIL
              || block.getType() == Material.DETECTOR_RAIL)
          && prot.getSettingBool(ProtectConfig.protect_rails)) {
        event.setCancelled(true);
        return;
      }
      if ((block.getType() == Material.WALL_SIGN
              || block.getRelative(BlockFace.NORTH).getType() == Material.WALL_SIGN
              || block.getRelative(BlockFace.EAST).getType() == Material.WALL_SIGN
              || block.getRelative(BlockFace.SOUTH).getType() == Material.WALL_SIGN
              || block.getRelative(BlockFace.WEST).getType() == Material.WALL_SIGN
              || block.getType() == Material.SIGN_POST
              || block.getRelative(BlockFace.UP).getType() == Material.SIGN_POST)
          && prot.getSettingBool(ProtectConfig.protect_signs)) {
        event.setCancelled(true);
        return;
      }
    }
  }
예제 #20
0
 public static boolean isBlockSolid(Block block) {
   return block.getType().isOccluding()
       || block.getType() == Material.SOIL
       || block.getType() == Material.LEAVES
       || block.getType() == Material.SNOW
       || block.getType() == Material.STAINED_GLASS
       || block.getType() == Material.STAINED_GLASS_PANE
       || block.getType() == Material.GLASS;
 }
예제 #21
0
 /**
  * Gets the player's depth
  *
  * @param player
  * @return
  */
 public static int getDepth(CraftPlayer player) {
   Block block = player.getLocation().getBlock().getRelative(BlockFace.UP);
   int depth = 0;
   while (block.getType() == Material.WATER || block.getType() == Material.STATIONARY_WATER) {
     depth++;
     block = block.getRelative(BlockFace.UP);
   }
   return depth;
 }
예제 #22
0
 public void onBlockBreak(BlockBreakEvent event) {
   if (event.isCancelled()) return;
   Block block = event.getBlock();
   if (block.getType() == Material.BOOKSHELF) {
     AdvShelf shelf = new AdvShelf(block.getLocation());
     shelf.delete();
     ItemStack stack = new ItemStack(block.getType(), 1);
     block.getWorld().dropItemNaturally(block.getLocation(), stack);
   }
 }
예제 #23
0
  @Override
  public boolean onCast(String[] parameters) {
    Block target = getTargetBlock();
    if (target == null) {
      castMessage(player, "No target");
      return false;
    }
    int MAX_HEIGHT = 255;
    int height = 16;
    int maxHeight = 127;
    int material = 20;
    int midX = target.getX();
    int midY = target.getY();
    int midZ = target.getZ();

    // Check for roof
    for (int i = height; i < maxHeight; i++) {
      int y = midY + i;
      if (y > MAX_HEIGHT) {
        maxHeight = MAX_HEIGHT - midY;
        height = height > maxHeight ? maxHeight : height;
        break;
      }
      Block block = getBlockAt(midX, y, midZ);
      if (block.getType() != Material.AIR) {
        castMessage(player, "Found ceiling of " + block.getType().name().toLowerCase());
        height = i;
        break;
      }
    }

    int blocksCreated = 0;
    BlockList towerBlocks = new BlockList();
    for (int i = 0; i < height; i++) {
      midY++;
      for (int dx = -1; dx <= 1; dx++) {
        for (int dz = -1; dz <= 1; dz++) {
          int x = midX + dx;
          int y = midY;
          int z = midZ + dz;
          // Leave the middle empty
          if (dx != 0 || dz != 0) {
            blocksCreated++;
            Block block = getBlockAt(x, y, z);
            towerBlocks.addBlock(block);
            block.setTypeId(material);
          }
        }
      }
    }
    spells.addToUndoQueue(player, towerBlocks);
    castMessage(player, "Made tower " + height + " high with " + blocksCreated + " blocks");
    return true;
  }
예제 #24
0
 private static boolean isFreezable(Player player, Block block) {
   if (GeneralMethods.isRegionProtectedFromBuild(player, "PhaseChange", block.getLocation())) {
     return false;
   }
   if (block.getType() == Material.WATER || block.getType() == Material.STATIONARY_WATER) {
     if (WaterManipulation.canPhysicsChange(block) && !TempBlock.isTempBlock(block)) {
       return true;
     }
   }
   return false;
 }
 @HawkEvent(dataType = DataType.BLOCK_PLACE)
 public void onBlockPlace(BlockPlaceEvent event) {
   Block block = event.getBlock();
   if (block.getType() == Material.WALL_SIGN || block.getType() == Material.SIGN_POST) return;
   DataManager.addEntry(
       new BlockChangeEntry(
           event.getPlayer(),
           DataType.BLOCK_PLACE,
           block.getLocation(),
           event.getBlockReplacedState(),
           block.getState()));
 }
  @EventHandler(priority = EventPriority.HIGHEST)
  public void limitRedstone(BlockRedstoneEvent event) {
    Block block = event.getBlock();
    if (!materials.contains(block.getType()) || event.getOldCurrent() != 0) {
      return;
    }

    Location loc = block.getLocation();
    BlockPosition blockPos = new BlockPosition(loc);
    AtomicInteger score = scores.putIfAbsent(blockPos, new AtomicInteger());

    if (score == null) {
      score = scores.get(blockPos);
      if (score == null) {
        limitRedstone(event);
        return;
      }
    }

    int newScore = score.incrementAndGet();
    int threshold = getConfig().getInt("threshold");

    if (newScore < threshold) {
      return;
    }

    if (newScore > threshold) {
      score.compareAndSet(newScore, threshold);
    } else {
      Bukkit.broadcast(
          "§cToo much redstone @ §e"
              + loc.getWorld().getName()
              + " §b"
              + loc.getBlockX()
              + " "
              + loc.getBlockY()
              + " "
              + loc.getBlockZ()
              + " §8[§7"
              + block.getType().name()
              + "§8]",
          "redstonelimiter.notify");
    }

    event.setNewCurrent(0);

    for (int i = 0; i < 3; ++i) {
      Location l =
          loc.clone()
              .add(random.nextDouble() * 1.1, random.nextDouble() - 0.5, random.nextDouble() * 1.1);
      loc.getWorld().playEffect(l, Effect.SMOKE, 64);
    }
  }
  @EventHandler
  public void onPhysics(BlockPhysicsEvent event) {
    Block block = event.getBlock();

    if (block.getType() == Material.GRASS
        || block.getType() == Material.LONG_GRASS
        || block.getType() == Material.YELLOW_FLOWER
            && (plugin.isProtectedRegion(block))
            && (plugin.getWorlds().contains(block.getWorld().getName()))
            && !(plugin.isExcluded(block))
            && !(plugin.isPaused())) {}
  }
예제 #28
0
 /**
  * Changes the sign to red if it exists
  *
  * @param loc
  */
 private void popSign(Location loc) {
   Block b = loc.getBlock();
   if (b.getType().equals(Material.SIGN_POST) || b.getType().equals(Material.WALL_SIGN)) {
     Sign s = (Sign) b.getState();
     if (s != null) {
       if (s.getLine(0).equalsIgnoreCase(ChatColor.GREEN + plugin.myLocale().warpswelcomeLine)) {
         s.setLine(0, ChatColor.RED + plugin.myLocale().warpswelcomeLine);
         s.update();
       }
     }
   }
 }
예제 #29
0
 @EventHandler(priority = EventPriority.MONITOR)
 public void onBlockBreak(BlockBreakEvent event) {
   Block block = event.getBlock();
   if (block.getType() == Material.DISPENSER) {
     plugin.removeCannon(block);
   } else if (block.getType() == Material.WEB) {
     if (plugin.removeWeb(block)) {
       // event.setCancelled(true);
       block.setType(Material.AIR);
     }
   }
 }
예제 #30
0
 private boolean canInstantiate() {
   if (block.getType() != Material.ICE) return false;
   for (Block block : affectedblocks.keySet()) {
     if (blockInAllAffectedBlocks(block)
         || alreadydoneblocks.containsKey(block)
         || block.getType() != Material.AIR
         || (block.getX() == player.getEyeLocation().getBlock().getX()
             && block.getZ() == player.getEyeLocation().getBlock().getZ())) {
       return false;
     }
   }
   return true;
 }