Java Code Examples for org.bukkit.event.player.PlayerAttackEntityEvent#getLeftClicked()

The following examples show how to use org.bukkit.event.player.PlayerAttackEntityEvent#getLeftClicked() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BlockBreakRegion.java    From CardinalPGM with MIT License 5 votes vote down vote up
@EventHandler
public void onPlayerAttackEntity(PlayerAttackEntityEvent event) {
    if (event.getLeftClicked() instanceof ItemFrame) {
        if (region.contains(event.getLeftClicked().getLocation().toVector()) && filter.evaluate(event.getLeftClicked(), event.getPlayer(), event).equals(FilterState.DENY)) {
            event.setCancelled(true);
        }
    }
}
 
Example 2
Source File: BlockEventRegion.java    From CardinalPGM with MIT License 5 votes vote down vote up
@EventHandler
public void onPlayerAttackEntity(PlayerAttackEntityEvent event) {
    if (event.getLeftClicked() instanceof ItemFrame) {
        if (region.contains(event.getLeftClicked().getLocation().toVector()) && filter.evaluate(event.getLeftClicked(), event.getPlayer(), event).equals(FilterState.DENY)) {
            event.setCancelled(true);
        }
    }
}
 
Example 3
Source File: TntDefuse.java    From CardinalPGM with MIT License 5 votes vote down vote up
@EventHandler
public void onPlayerLeftClick(PlayerAttackEntityEvent event) {
    if (event.getLeftClicked() instanceof TNTPrimed) {
        if (TntTracker.getWhoPlaced(event.getLeftClicked()) != null) {
            UUID player = TntTracker.getWhoPlaced(event.getLeftClicked());
            Optional<TeamModule> playerTeam = Teams.getTeamByPlayer(Bukkit.getPlayer(player));
            if (Bukkit.getOfflinePlayer(player).isOnline()) {
                if (playerTeam.isPresent() && playerTeam.get().equals(Teams.getTeamByPlayer(event.getPlayer()).orNull()) && Teams.getTeamByPlayer(Bukkit.getPlayer(player)) != null && !playerTeam.get().isObserver()) {
                    if (!event.getLeftClicked().getLocation().getBlock().isLiquid()) {
                        if (!Bukkit.getPlayer(player).equals(event.getPlayer())) {
                            event.getLeftClicked().remove();
                            event.getPlayer().sendMessage(ChatColor.RED + "You defused " + playerTeam.get().getColor() + Bukkit.getPlayer(player).getDisplayName() + ChatColor.RED + "'s TNT.");
                            ChatChannel channel = GameHandler.getGameHandler().getMatch().getModules().getModule(AdminChannel.class);
                            channel.sendMessage("[" + ChatColor.GOLD + "A" + ChatColor.WHITE + "] " + Teams.getTeamByPlayer(event.getPlayer()).get().getColor() + event.getPlayer().getDisplayName() + ChatColor.RESET + " defused " + playerTeam.get().getColor() + Bukkit.getPlayer(player).getDisplayName() + ChatColor.RESET + "'s " + ChatColor.DARK_RED + "TNT");
                        }
                    } else {
                        ChatUtil.sendWarningMessage(event.getPlayer(), "You may not defuse TNT in water!");
                    }
                } else {
                    ChatUtil.sendWarningMessage(event.getPlayer(), "You may not defuse enemy TNT.");
                }
            } else {
                ChatUtil.sendWarningMessage(event.getPlayer(), "You may not defuse enemy TNT.");
            }
        }
    }
}
 
Example 4
Source File: FreezeModule.java    From CardinalPGM with MIT License 5 votes vote down vote up
@EventHandler
public void onPlayerClick(PlayerAttackEntityEvent event) {
    if (event.getPlayer().hasPermission("cardinal.punish.freeze") && event.getLeftClicked() instanceof Player) {
        ItemStack item = event.getPlayer().getInventory().getItemInMainHand();
        if (item != null && item.getType() == Material.ICE
                && item.getItemMeta() != null && item.getItemMeta().getDisplayName() != null
                && item.getItemMeta().getDisplayName().equals(ChatColor.AQUA + ChatConstant.UI_FREEZE_ITEM.getMessage(event.getPlayer().getLocale()))) {
            togglePlayerFreeze((Player) event.getLeftClicked(), event.getPlayer());
        }
    }
}
 
Example 5
Source File: SpectatorTools.java    From CardinalPGM with MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void onSpectatorMount(PlayerAttackEntityEvent event) {
    if (event.getLeftClicked() instanceof Player
            &&ObserverModule.testObserver(event.getPlayer())
            && !ObserverModule.testObserver((Player) event.getLeftClicked())
            && event.getPlayer().getGameMode().equals(GameMode.SPECTATOR)) {
        event.setCancelled(false);
    }
}