public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
    Entity attacker = event.getDamager();
    Entity defender = event.getEntity();

    if (defender instanceof Player) {
      Player player = (Player) defender;

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

      if (cfg.isInvinciblePlayer(player.getName())) {
        event.setCancelled(true);
        return;
      }

      if (attacker != null && attacker instanceof Player) {
        if (wcfg.useRegions) {
          Vector pt = toVector(defender.getLocation());
          RegionManager mgr =
              plugin.getGlobalRegionManager().getRegionManager(player.getWorld().getName());

          if (!mgr.getApplicableRegions(pt).isStateFlagAllowed(Flags.PVP)) {
            ((Player) attacker).sendMessage(ChatColor.DARK_RED + "You are in a no-PvP area.");
            event.setCancelled(true);
            return;
          }
        }
      }

      if (attacker != null && attacker instanceof Monster) {
        if (attacker instanceof Creeper && wcfg.blockCreeperExplosions) {
          event.setCancelled(true);
          return;
        }

        if (wcfg.useRegions) {
          Vector pt = toVector(defender.getLocation());
          RegionManager mgr =
              plugin.getGlobalRegionManager().getRegionManager(player.getWorld().getName());
          ApplicableRegionSet set = mgr.getApplicableRegions(pt);

          if (!set.isStateFlagAllowed(Flags.MOB_DAMAGE)) {
            event.setCancelled(true);
            return;
          }

          if (attacker instanceof Creeper) {
            if (!set.isStateFlagAllowed(Flags.CREEPER_EXPLOSION)) {
              event.setCancelled(true);
              return;
            }
          }
        }
      }
    }
  }
  /** Called when a block is broken. */
  @Override
  public void onBlockBreak(BlockBreakEvent event) {
    if (event.isCancelled()) {
      return;
    }

    Player player = event.getPlayer();
    WorldConfiguration wcfg = getWorldConfig(player);

    if (!wcfg.itemDurability) {
      ItemStack held = player.getItemInHand();
      if (held.getTypeId() > 0) {
        held.setDurability((short) -1);
        player.setItemInHand(held);
      }
    }

    if (!plugin.getGlobalRegionManager().canBuild(player, event.getBlock())) {
      player.sendMessage(ChatColor.DARK_RED + "You don't have permission for this area.");
      event.setCancelled(true);
      return;
    }

    if (wcfg.getBlacklist() != null) {
      if (!wcfg.getBlacklist()
          .check(
              new BlockBreakBlacklistEvent(
                  plugin.wrapPlayer(player),
                  toVector(event.getBlock()),
                  event.getBlock().getTypeId()),
              false,
              false)) {
        event.setCancelled(true);
        return;
      }

      if (!wcfg.getBlacklist()
          .check(
              new DestroyWithBlacklistEvent(
                  plugin.wrapPlayer(player),
                  toVector(event.getBlock()),
                  player.getItemInHand().getTypeId()),
              false,
              false)) {
        event.setCancelled(true);
        return;
      }
    }

    if (wcfg.isChestProtected(event.getBlock(), player)) {
      player.sendMessage(ChatColor.DARK_RED + "The chest is protected.");
      event.setCancelled(true);
      return;
    }
  }
  /*
   * Called when a block is destroyed from burning.
   */
  @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
  public void onBlockBurn(BlockBurnEvent event) {
    ConfigurationManager cfg = plugin.getGlobalStateManager();
    WorldConfiguration wcfg = cfg.get(event.getBlock().getWorld());

    if (cfg.activityHaltToggle) {
      event.setCancelled(true);
      return;
    }

    if (wcfg.disableFireSpread) {
      event.setCancelled(true);
      return;
    }

    if (wcfg.fireSpreadDisableToggle) {
      Block block = event.getBlock();
      event.setCancelled(true);
      checkAndDestroyAround(
          block.getWorld(), block.getX(), block.getY(), block.getZ(), BlockID.FIRE);
      return;
    }

    if (wcfg.disableFireSpreadBlocks.size() > 0) {
      Block block = event.getBlock();

      if (wcfg.disableFireSpreadBlocks.contains(block.getTypeId())) {
        event.setCancelled(true);
        checkAndDestroyAround(
            block.getWorld(), block.getX(), block.getY(), block.getZ(), BlockID.FIRE);
        return;
      }
    }

    if (wcfg.isChestProtected(event.getBlock())) {
      event.setCancelled(true);
      return;
    }

    if (wcfg.useRegions) {
      Block block = event.getBlock();
      int x = block.getX();
      int y = block.getY();
      int z = block.getZ();
      Vector pt = toVector(block);
      RegionManager mgr = plugin.getGlobalRegionManager().get(block.getWorld());
      ApplicableRegionSet set = mgr.getApplicableRegions(pt);

      if (!set.allows(DefaultFlag.FIRE_SPREAD)) {
        checkAndDestroyAround(block.getWorld(), x, y, z, BlockID.FIRE);
        event.setCancelled(true);
        return;
      }
    }
  }
  /*
   * Called when a block is broken.
   */
  @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
  public void onBlockBreak(BlockBreakEvent event) {
    Player player = event.getPlayer();
    WorldConfiguration wcfg = getWorldConfig(player);

    if (!wcfg.itemDurability) {
      ItemStack held = player.getItemInHand();
      if (held.getTypeId() > 0
          && !(ItemType.usesDamageValue(held.getTypeId())
              || BlockType.usesData(held.getTypeId()))) {
        held.setDurability((short) 0);
        player.setItemInHand(held);
      }
    }

    if (!plugin.getGlobalRegionManager().canBuild(player, event.getBlock())
        || !plugin.getGlobalRegionManager().canConstruct(player, event.getBlock())) {
      player.sendMessage(ChatColor.DARK_RED + "You don't have permission for this area.");
      event.setCancelled(true);
      return;
    }

    if (wcfg.getBlacklist() != null) {
      if (!wcfg.getBlacklist()
          .check(
              new BlockBreakBlacklistEvent(
                  plugin.wrapPlayer(player),
                  toVector(event.getBlock()),
                  event.getBlock().getTypeId()),
              false,
              false)) {
        event.setCancelled(true);
        return;
      }

      if (!wcfg.getBlacklist()
          .check(
              new DestroyWithBlacklistEvent(
                  plugin.wrapPlayer(player),
                  toVector(event.getBlock()),
                  player.getItemInHand().getTypeId()),
              false,
              false)) {
        event.setCancelled(true);
        return;
      }
    }

    if (wcfg.isChestProtected(event.getBlock(), player)) {
      player.sendMessage(ChatColor.DARK_RED + "The chest is protected.");
      event.setCancelled(true);
      return;
    }
  }
 /*
  * Called when a block yields exp
  */
 @EventHandler(priority = EventPriority.HIGH)
 public void onBlockExp(BlockExpEvent event) {
   ConfigurationManager cfg = plugin.getGlobalStateManager();
   WorldConfiguration wcfg = cfg.get(event.getBlock().getWorld());
   if (wcfg.disableExpDrops
       || !plugin
           .getGlobalRegionManager()
           .allows(DefaultFlag.EXP_DROPS, event.getBlock().getLocation())) {
     event.setExpToDrop(0);
   }
 }
  /*
   * Called when a player places a block.
   */
  @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
  public void onBlockPlace(BlockPlaceEvent event) {
    Block blockPlaced = event.getBlock();
    Player player = event.getPlayer();
    World world = blockPlaced.getWorld();

    ConfigurationManager cfg = plugin.getGlobalStateManager();
    WorldConfiguration wcfg = cfg.get(world);

    if (wcfg.useRegions) {
      final Location location = blockPlaced.getLocation();
      if (!plugin.getGlobalRegionManager().canBuild(player, location)
          || !plugin.getGlobalRegionManager().canConstruct(player, location)) {
        player.sendMessage(ChatColor.DARK_RED + "You don't have permission for this area.");
        event.setCancelled(true);
        return;
      }
    }

    if (wcfg.getBlacklist() != null) {
      if (!wcfg.getBlacklist()
          .check(
              new BlockPlaceBlacklistEvent(
                  plugin.wrapPlayer(player), toVector(blockPlaced), blockPlaced.getTypeId()),
              false,
              false)) {
        event.setCancelled(true);
        return;
      }
    }

    if (wcfg.signChestProtection && wcfg.getChestProtection().isChest(blockPlaced.getTypeId())) {
      if (wcfg.isAdjacentChestProtected(event.getBlock(), player)) {
        player.sendMessage(
            ChatColor.DARK_RED + "This spot is for a chest that you don't have permission for.");
        event.setCancelled(true);
        return;
      }
    }

    if (wcfg.simulateSponge && blockPlaced.getTypeId() == 19) {
      if (wcfg.redstoneSponges && blockPlaced.isBlockIndirectlyPowered()) {
        return;
      }

      int ox = blockPlaced.getX();
      int oy = blockPlaced.getY();
      int oz = blockPlaced.getZ();

      SpongeUtil.clearSpongeWater(plugin, world, ox, oy, oz);
    }
  }
  @Override
  public void onEntityExplode(EntityExplodeEvent event) {

    if (event.isCancelled()) {
      return;
    }

    GlobalConfiguration cfg = plugin.getGlobalConfiguration();
    Location l = event.getLocation();
    WorldConfiguration wcfg = cfg.getWorldConfig(l.getWorld().getName());

    if (event.getEntity() instanceof LivingEntity) {

      if (wcfg.blockCreeperBlockDamage) {
        event.setCancelled(true);
        return;
      }

      if (wcfg.blockCreeperExplosions) {
        event.setCancelled(true);
        return;
      }

      if (wcfg.useRegions) {
        Vector pt = toVector(l);
        RegionManager mgr = plugin.getGlobalRegionManager().getRegionManager(wcfg.getWorldName());

        if (!mgr.getApplicableRegions(pt).isStateFlagAllowed(Flags.CREEPER_EXPLOSION)) {
          event.setCancelled(true);
          return;
        }
      }
    } else { // Shall assume that this is TNT
      if (wcfg.blockTNT) {
        event.setCancelled(true);
        return;
      }

      if (wcfg.useRegions) {
        Vector pt = toVector(l);
        RegionManager mgr = plugin.getGlobalRegionManager().getRegionManager(wcfg.getWorldName());

        if (!mgr.getApplicableRegions(pt).isStateFlagAllowed(Flags.TNT)) {
          event.setCancelled(true);
          return;
        }
      }
    }
  }
  /*
   * Called when a piston retracts
   */
  @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
  public void onBlockPistonRetract(BlockPistonRetractEvent event) {
    ConfigurationManager cfg = plugin.getGlobalStateManager();
    WorldConfiguration wcfg = cfg.get(event.getBlock().getWorld());

    if (wcfg.useRegions && event.isSticky()) {
      if (!(plugin.getGlobalRegionManager().allows(DefaultFlag.PISTONS, event.getRetractLocation()))
          || !(plugin
              .getGlobalRegionManager()
              .allows(DefaultFlag.PISTONS, event.getBlock().getLocation()))) {
        event.setCancelled(true);
        return;
      }
    }
  }
  /*
   * Called when block physics occurs.
   */
  @EventHandler(ignoreCancelled = true)
  public void onBlockPhysics(BlockPhysicsEvent event) {
    ConfigurationManager cfg = plugin.getGlobalStateManager();
    WorldConfiguration wcfg = cfg.get(event.getBlock().getWorld());

    if (cfg.activityHaltToggle) {
      event.setCancelled(true);
      return;
    }

    int id = event.getChangedTypeId();

    if (id == 13 && wcfg.noPhysicsGravel) {
      event.setCancelled(true);
      return;
    }

    if (id == 12 && wcfg.noPhysicsSand) {
      event.setCancelled(true);
      return;
    }

    if (id == 90 && wcfg.allowPortalAnywhere) {
      event.setCancelled(true);
      return;
    }

    if (wcfg.ropeLadders && event.getBlock().getType() == Material.LADDER) {
      if (event.getBlock().getRelative(0, 1, 0).getType() == Material.LADDER) {
        event.setCancelled(true);
        return;
      }
    }
  }
  public void onEntityDamageByBlock(EntityDamageByBlockEvent event) {

    Entity defender = event.getEntity();
    DamageCause type = event.getCause();

    if (defender instanceof Player) {
      Player player = (Player) defender;

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

      if (cfg.isInvinciblePlayer(player.getName())) {
        event.setCancelled(true);
        return;
      }

      if (wcfg.disableLavaDamage && type == DamageCause.LAVA) {
        event.setCancelled(true);
        return;
      }

      if (wcfg.disableContactDamage && type == DamageCause.CONTACT) {
        event.setCancelled(true);
        return;
      }
    }
  }
Пример #11
0
  /**
   * Called when block physics occurs
   *
   * @param event Relevant event details
   */
  @Override
  public void onBlockPhysics(BlockPhysicsEvent event) {

    if (event.isCancelled()) {
      return;
    }

    ConfigurationManager cfg = plugin.getGlobalConfiguration();
    WorldConfiguration wcfg = cfg.get(event.getBlock().getWorld());

    int id = event.getChangedTypeId();

    if (id == 13 && wcfg.noPhysicsGravel) {
      event.setCancelled(true);
      return;
    }

    if (id == 12 && wcfg.noPhysicsSand) {
      event.setCancelled(true);
      return;
    }

    if (id == 90 && wcfg.allowPortalAnywhere) {
      event.setCancelled(true);
      return;
    }
  }
  /*
   * Called when redstone changes.
   */
  @EventHandler(priority = EventPriority.HIGH)
  public void onBlockRedstoneChange(BlockRedstoneEvent event) {
    Block blockTo = event.getBlock();
    World world = blockTo.getWorld();

    ConfigurationManager cfg = plugin.getGlobalStateManager();
    WorldConfiguration wcfg = cfg.get(world);

    if (wcfg.simulateSponge && wcfg.redstoneSponges) {
      int ox = blockTo.getX();
      int oy = blockTo.getY();
      int oz = blockTo.getZ();

      for (int cx = -1; cx <= 1; cx++) {
        for (int cy = -1; cy <= 1; cy++) {
          for (int cz = -1; cz <= 1; cz++) {
            Block sponge = world.getBlockAt(ox + cx, oy + cy, oz + cz);
            if (sponge.getTypeId() == 19 && sponge.isBlockIndirectlyPowered()) {
              SpongeUtil.clearSpongeWater(plugin, world, ox + cx, oy + cy, oz + cz);
            } else if (sponge.getTypeId() == 19 && !sponge.isBlockIndirectlyPowered()) {
              SpongeUtil.addSpongeWater(plugin, world, ox + cx, oy + cy, oz + cz);
            }
          }
        }
      }

      return;
    }
  }
Пример #13
0
  /**
   * Called when a player places a block
   *
   * @param event Relevant event details
   */
  @Override
  public void onBlockPlace(BlockPlaceEvent event) {

    if (event.isCancelled()) {
      return;
    }

    Block blockPlaced = event.getBlock();
    Player player = event.getPlayer();
    World world = blockPlaced.getWorld();

    ConfigurationManager cfg = plugin.getGlobalConfiguration();
    WorldConfiguration wcfg = cfg.get(world);

    if (wcfg.useRegions) {
      if (!plugin.getGlobalRegionManager().canBuild(player, blockPlaced.getLocation())) {
        player.sendMessage(ChatColor.DARK_RED + "You don't have permission for this area.");
        event.setCancelled(true);
        return;
      }
    }

    if (wcfg.getBlacklist() != null) {
      if (!wcfg.getBlacklist()
          .check(
              new BlockPlaceBlacklistEvent(
                  plugin.wrapPlayer(player), toVector(blockPlaced), blockPlaced.getTypeId()),
              false,
              false)) {
        event.setCancelled(true);
        return;
      }
    }

    if (wcfg.simulateSponge && blockPlaced.getTypeId() == 19) {
      if (wcfg.redstoneSponges && blockPlaced.isBlockIndirectlyPowered()) {
        return;
      }

      int ox = blockPlaced.getX();
      int oy = blockPlaced.getY();
      int oz = blockPlaced.getZ();

      clearSpongeWater(world, ox, oy, oz);
    }
  }
  public void registerEvents() {

    PluginManager pm = plugin.getServer().getPluginManager();

    pm.registerEvent(Event.Type.ENTITY_DAMAGED, this, Priority.High, plugin);
    pm.registerEvent(Event.Type.ENTITY_EXPLODE, this, Priority.High, plugin);
    pm.registerEvent(Event.Type.CREATURE_SPAWN, this, Priority.High, plugin);
  }
  @Override
  public void onCreatureSpawn(CreatureSpawnEvent event) {
    if (event.isCancelled()) {
      return;
    }

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

    // CreatureType creaType = (CreatureType) CreatureType.valueOf(event.getMobType().toString());
    CreatureType creaType = event.getCreatureType();
    String creaName = "";
    Boolean cancelEvent = false;

    if (wcfg.blockCreatureSpawn.contains(creaType)) {
      cancelEvent = true;
    }

    if (wcfg.useRegions) {
      Vector pt = toVector(event.getEntity().getLocation());
      RegionManager mgr =
          plugin.getGlobalRegionManager().getRegionManager(event.getEntity().getWorld().getName());

      Boolean flagValue =
          mgr.getApplicableRegions(pt)
              .getStringFlag(Flags.DENY_SPAWN, true)
              .getValue("")
              .contains(creaType.getName());
      if (flagValue != null) {
        if (flagValue) {
          cancelEvent = true;
        } else {
          cancelEvent = false;
        }
      }
    }

    if (cancelEvent) {
      event.setCancelled(true);
      return;
    }
  }
  /*
   * Called when a piston extends
   */
  @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
  public void onBlockPistonExtend(BlockPistonExtendEvent event) {
    ConfigurationManager cfg = plugin.getGlobalStateManager();
    WorldConfiguration wcfg = cfg.get(event.getBlock().getWorld());

    if (wcfg.useRegions) {
      if (!plugin
          .getGlobalRegionManager()
          .allows(DefaultFlag.PISTONS, event.getBlock().getLocation())) {
        event.setCancelled(true);
        return;
      }
      for (Block block : event.getBlocks()) {
        if (!plugin.getGlobalRegionManager().allows(DefaultFlag.PISTONS, block.getLocation())) {
          event.setCancelled(true);
          return;
        }
      }
    }
  }
Пример #17
0
  /**
   * Called when a block is destroyed from burning
   *
   * @param event Relevant event details
   */
  @Override
  public void onBlockBurn(BlockBurnEvent event) {

    if (event.isCancelled()) {
      return;
    }

    ConfigurationManager cfg = plugin.getGlobalConfiguration();
    WorldConfiguration wcfg = cfg.get(event.getBlock().getWorld());

    if (wcfg.disableFireSpread) {
      event.setCancelled(true);
      return;
    }

    if (wcfg.fireSpreadDisableToggle) {
      event.setCancelled(true);
      return;
    }

    if (wcfg.disableFireSpreadBlocks.size() > 0) {
      Block block = event.getBlock();

      if (wcfg.disableFireSpreadBlocks.contains(block.getTypeId())) {
        event.setCancelled(true);
        return;
      }
    }

    if (wcfg.useRegions) {
      Block block = event.getBlock();
      Vector pt = toVector(block);
      RegionManager mgr = plugin.getGlobalRegionManager().get(block.getWorld());
      ApplicableRegionSet set = mgr.getApplicableRegions(pt);

      if (!set.allows(DefaultFlag.FIRE_SPREAD)) {
        event.setCancelled(true);
        return;
      }
    }
  }
Пример #18
0
  @Override
  public void onSnowForm(SnowFormEvent event) {
    if (event.isCancelled()) {
      return;
    }

    if (!plugin
        .getGlobalRegionManager()
        .allows(DefaultFlag.SNOW_FALL, event.getBlock().getLocation())) {
      event.setCancelled(true);
    }
  }
  /*
   * Called when a block is formed based on world conditions.
   */
  @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
  public void onBlockForm(BlockFormEvent event) {
    ConfigurationManager cfg = plugin.getGlobalStateManager();
    WorldConfiguration wcfg = cfg.get(event.getBlock().getWorld());

    if (cfg.activityHaltToggle) {
      event.setCancelled(true);
      return;
    }

    int type = event.getNewState().getTypeId();

    if (type == BlockID.ICE) {
      if (wcfg.disableIceFormation) {
        event.setCancelled(true);
        return;
      }
      if (wcfg.useRegions
          && !plugin
              .getGlobalRegionManager()
              .allows(DefaultFlag.ICE_FORM, event.getBlock().getLocation())) {
        event.setCancelled(true);
        return;
      }
    }

    if (type == BlockID.SNOW) {
      if (wcfg.disableSnowFormation) {
        event.setCancelled(true);
        return;
      }
      if (wcfg.useRegions
          && !plugin
              .getGlobalRegionManager()
              .allows(DefaultFlag.SNOW_FALL, event.getBlock().getLocation())) {
        event.setCancelled(true);
        return;
      }
    }
  }
  @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
  public void onLeavesDecay(LeavesDecayEvent event) {
    ConfigurationManager cfg = plugin.getGlobalStateManager();
    WorldConfiguration wcfg = cfg.get(event.getBlock().getWorld());

    if (cfg.activityHaltToggle) {
      event.setCancelled(true);
      return;
    }

    if (wcfg.disableLeafDecay) {
      event.setCancelled(true);
      return;
    }

    if (wcfg.useRegions) {
      if (!plugin
          .getGlobalRegionManager()
          .allows(DefaultFlag.LEAF_DECAY, event.getBlock().getLocation())) {
        event.setCancelled(true);
      }
    }
  }
  /*
   * Called when a block fades.
   */
  @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
  public void onBlockFade(BlockFadeEvent event) {

    ConfigurationManager cfg = plugin.getGlobalStateManager();
    WorldConfiguration wcfg = cfg.get(event.getBlock().getWorld());

    int type = event.getBlock().getTypeId();

    if (type == BlockID.ICE) {
      if (wcfg.disableIceMelting) {
        event.setCancelled(true);
        return;
      }
      if (wcfg.useRegions
          && !plugin
              .getGlobalRegionManager()
              .allows(DefaultFlag.ICE_MELT, event.getBlock().getLocation())) {
        event.setCancelled(true);
        return;
      }
    }

    if (type == BlockID.SNOW) {
      if (wcfg.disableSnowMelting) {
        event.setCancelled(true);
        return;
      }
      if (wcfg.useRegions
          && !plugin
              .getGlobalRegionManager()
              .allows(DefaultFlag.SNOW_MELT, event.getBlock().getLocation())) {
        event.setCancelled(true);
        return;
      }
    }
  }
Пример #22
0
  public void registerEvents() {

    PluginManager pm = plugin.getServer().getPluginManager();

    pm.registerEvent(Event.Type.BLOCK_DAMAGE, this, Priority.High, plugin);
    pm.registerEvent(Event.Type.BLOCK_BREAK, this, Priority.High, plugin);
    pm.registerEvent(Event.Type.BLOCK_FROMTO, this, Priority.Normal, plugin);
    pm.registerEvent(Event.Type.BLOCK_IGNITE, this, Priority.High, plugin);
    pm.registerEvent(Event.Type.BLOCK_PHYSICS, this, Priority.Normal, plugin);
    pm.registerEvent(Event.Type.BLOCK_PLACE, this, Priority.High, plugin);
    pm.registerEvent(Event.Type.BLOCK_BURN, this, Priority.High, plugin);
    pm.registerEvent(Event.Type.SIGN_CHANGE, this, Priority.High, plugin);
    pm.registerEvent(Event.Type.REDSTONE_CHANGE, this, Priority.High, plugin);
    pm.registerEvent(Event.Type.SNOW_FORM, this, Priority.High, plugin);
  }
Пример #23
0
  /**
   * Remove water around a sponge.
   *
   * @param world
   * @param ox
   * @param oy
   * @param oz
   */
  private void clearSpongeWater(World world, int ox, int oy, int oz) {

    ConfigurationManager cfg = plugin.getGlobalConfiguration();
    WorldConfiguration wcfg = cfg.get(world);

    for (int cx = -wcfg.spongeRadius; cx <= wcfg.spongeRadius; cx++) {
      for (int cy = -wcfg.spongeRadius; cy <= wcfg.spongeRadius; cy++) {
        for (int cz = -wcfg.spongeRadius; cz <= wcfg.spongeRadius; cz++) {
          if (isBlockWater(world, ox + cx, oy + cy, oz + cz)) {
            world.getBlockAt(ox + cx, oy + cy, oz + cz).setTypeId(0);
          }
        }
      }
    }
  }
  /*
   * Called when a block is damaged.
   */
  @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
  public void onBlockDamage(BlockDamageEvent event) {
    Player player = event.getPlayer();
    Block blockDamaged = event.getBlock();

    // Cake are damaged and not broken when they are eaten, so we must
    // handle them a bit separately
    if (blockDamaged.getTypeId() == BlockID.CAKE_BLOCK) {
      if (!plugin.getGlobalRegionManager().canBuild(player, blockDamaged)) {
        player.sendMessage(ChatColor.DARK_RED + "You're not invited to this tea party!");
        event.setCancelled(true);
        return;
      }
    }
  }
  /*
   * Called when a block is formed by an entity.
   */
  @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
  public void onEntityBlockForm(EntityBlockFormEvent event) {
    ConfigurationManager cfg = plugin.getGlobalStateManager();
    WorldConfiguration wcfg = cfg.get(event.getBlock().getWorld());

    if (cfg.activityHaltToggle) {
      event.setCancelled(true);
      return;
    }

    if (event.getEntity() instanceof Snowman) {
      if (wcfg.disableSnowmanTrails) {
        event.setCancelled(true);
        return;
      }
    }
  }
  /*
   * Called when a block is damaged.
   */
  @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
  public void onBlockDispense(BlockDispenseEvent event) {
    ConfigurationManager cfg = plugin.getGlobalStateManager();
    WorldConfiguration wcfg = cfg.get(event.getBlock().getWorld());

    if (wcfg.blockPotions.size() > 0) {
      ItemStack item = event.getItem();
      if (item.getType() == Material.POTION && !BukkitUtil.isWaterPotion(item)) {
        Potion potion = Potion.fromDamage(BukkitUtil.getPotionEffectBits(item));
        for (PotionEffect effect : potion.getEffects()) {
          if (potion.isSplash() && wcfg.blockPotions.contains(effect.getType())) {
            event.setCancelled(true);
            return;
          }
        }
      }
    }
  }
Пример #27
0
  /** Called when a block is damaged. */
  @Override
  public void onBlockDamage(BlockDamageEvent event) {
    if (event.isCancelled()) {
      return;
    }

    Player player = event.getPlayer();
    Block blockDamaged = event.getBlock();

    // Cake are damaged and not broken when they are eaten, so we must
    // handle them a bit separately
    if (blockDamaged.getType() == Material.CAKE_BLOCK) {
      if (!plugin.getGlobalRegionManager().canBuild(player, blockDamaged)) {
        player.sendMessage(ChatColor.DARK_RED + "You're not invited to this tea party!");
        event.setCancelled(true);
        return;
      }
    }
  }
 /**
  * Get the world configuration given a world.
  *
  * @param world The world to get the configuration for.
  * @return The configuration for {@code world}
  */
 protected WorldConfiguration getWorldConfig(World world) {
   return plugin.getGlobalStateManager().get(world);
 }
  /*
   * Called when a block spreads based on world conditions.
   */
  @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
  public void onBlockSpread(BlockSpreadEvent event) {
    ConfigurationManager cfg = plugin.getGlobalStateManager();
    WorldConfiguration wcfg = cfg.get(event.getBlock().getWorld());

    if (cfg.activityHaltToggle) {
      event.setCancelled(true);
      return;
    }

    int fromType = event.getSource().getTypeId();

    if (fromType == BlockID.RED_MUSHROOM || fromType == BlockID.BROWN_MUSHROOM) {
      if (wcfg.disableMushroomSpread) {
        event.setCancelled(true);
        return;
      }
      if (wcfg.useRegions
          && !plugin
              .getGlobalRegionManager()
              .allows(DefaultFlag.MUSHROOMS, event.getBlock().getLocation())) {
        event.setCancelled(true);
        return;
      }
    }

    if (fromType == BlockID.GRASS) {
      if (wcfg.disableGrassGrowth) {
        event.setCancelled(true);
        return;
      }
      if (wcfg.useRegions
          && !plugin
              .getGlobalRegionManager()
              .allows(DefaultFlag.GRASS_SPREAD, event.getBlock().getLocation())) {
        event.setCancelled(true);
        return;
      }
    }

    if (fromType == BlockID.MYCELIUM) {
      if (wcfg.disableMyceliumSpread) {
        event.setCancelled(true);
        return;
      }

      if (wcfg.useRegions
          && !plugin
              .getGlobalRegionManager()
              .allows(DefaultFlag.MYCELIUM_SPREAD, event.getBlock().getLocation())) {
        event.setCancelled(true);
        return;
      }
    }

    if (fromType == BlockID.VINE) {
      if (wcfg.disableVineGrowth) {
        event.setCancelled(true);
        return;
      }

      if (wcfg.useRegions
          && !plugin
              .getGlobalRegionManager()
              .allows(DefaultFlag.VINE_GROWTH, event.getBlock().getLocation())) {
        event.setCancelled(true);
        return;
      }
    }
  }
 /** Register events. */
 public void registerEvents() {
   plugin.getServer().getPluginManager().registerEvents(this, plugin);
 }