Пример #1
0
  @EventHandler(priority = EventPriority.HIGH)
  public void CropTrampleOrFireCharge(PlayerInteractEvent event) {
    if (event.getClickedBlock() == null) {
      return;
    }

    Player p = event.getPlayer();

    // trampling crops
    if (p != null
        && event.getAction().equals(Action.PHYSICAL)
        && event.getClickedBlock().getType().toString().equals("SOIL")) {
      OwnedLand land = OwnedLand.getApplicableLand(event.getClickedBlock().getLocation());
      if (land == null) {
        return;
      }
      if (land.hasPermTo(p, this)) {
        return;
      }
      p.sendMessage(
          ChatColor.RED + getPlugin().getMessageConfig().getString("event.build.cropDestroy"));
      event.setCancelled(true);
      return;
    }

    // Using fire charge
    ItemStack item = event.getItem();
    if (p != null
        && item != null
        && event.getAction().equals(Action.RIGHT_CLICK_BLOCK)
        && event.getItem().getType().equals(Material.FIREBALL)) {
      OwnedLand land = OwnedLand.getApplicableLand(event.getClickedBlock().getLocation());
      if (land == null) {
        return;
      }
      if (land.hasPermTo(p, this)) {
        return;
      }
      p.sendMessage(
          ChatColor.RED + getPlugin().getMessageConfig().getString("event.build.useFireCharge"));
      event.setCancelled(true);
    }
  }