Exemple #1
0
  @EventHandler(priority = EventPriority.HIGH)
  public void protectBlockStates(PlayerInteractEvent event) {
    Material[] blockedItems = {
      Material.NOTE_BLOCK,
      Material.REDSTONE_COMPARATOR_OFF,
      Material.REDSTONE_COMPARATOR_ON,
      Material.DIODE_BLOCK_OFF,
      Material.DIODE_BLOCK_ON,
      Material.FLOWER_POT,
      Material.CAKE_BLOCK,
      Material.DAYLIGHT_DETECTOR,
      Material.DAYLIGHT_DETECTOR_INVERTED
    };
    if (event.getClickedBlock() == null) {
      return;
    }
    Player p = event.getPlayer();
    // System.out.println(event.getClickedBlock().getType());
    if (event.getAction().equals(Action.RIGHT_CLICK_BLOCK)
        && Arrays.asList(blockedItems).contains(event.getClickedBlock().getType())) {
      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.blockStateChange"));
      event.setCancelled(true);
    }
  }
Exemple #2
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);
    }
  }
 /**
  * Handles player interactions in arenas.<br>
  * If the player is in an arena, the game's onPlayerInteract method is called.<br>
  * If the player is spectating an arena, the event is cancelled.
  */
 @EventHandler(priority = EventPriority.HIGHEST)
 public void onPlayerInteract(PlayerInteractEvent event) {
   Player player = event.getPlayer();
   String playerName = player.getName();
   if (ultimateGames.getPlayerManager().isPlayerInArena(playerName)) {
     Arena arena = ultimateGames.getPlayerManager().getPlayerArena(playerName);
     Game game = arena.getGame();
     ItemStack item = player.getItemInHand();
     if (item != null && ultimateGames.getGameItemManager().isRegistered(game, item)) {
       GameItem gameItem = ultimateGames.getGameItemManager().getGameItem(game, item);
       if (gameItem.click(arena, event) && gameItem.hasSingleUse()) {
         ItemStack itemStack = player.getItemInHand();
         itemStack.setAmount(itemStack.getAmount() - 1);
         player.setItemInHand(itemStack.getAmount() == 0 ? null : itemStack);
         event.setCancelled(true);
       }
     } else {
       game.getGamePlugin().onPlayerInteract(arena, event);
     }
   } else if (ultimateGames.getPlayerManager().isPlayerSpectatingArena(playerName)) {
     event.setCancelled(true);
   }
 }