Java 类org.bukkit.event.player.PlayerAttackEntityEvent 实例源码

项目:ProjectAres    文件:EventFilterMatchModule.java   
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onAttack(final PlayerAttackEntityEvent event) {
    if(cancelUnlessInteracting(event, event.getPlayer())) {
        final MatchPlayer attacker = getMatch().getPlayer(event.getPlayer());
        if(attacker == null || attacker.isSpawned()) return;
        getMatch().callEvent(new ObserverInteractEvent(attacker, ClickType.LEFT, null, event.getLeftClicked(), event.getPlayer().getInventory().getItemInMainHand()));
    }
}
项目:Cardinal    文件:InteractModule.java   
/**
 * Prevents a player that can't interact from attacking an entity.
 *
 * @param event The event.
 */
@EventHandler(ignoreCancelled = true)
public void onPlayerAttackEntity(PlayerAttackEntityEvent event) {
  if (!canInteract(event.getPlayer())) {
    event.setCancelled(true);
  }
}
项目:Cardinal-Plus    文件:TntDefuse.java   
@EventHandler
public void onPlayerLeftClick(PlayerAttackEntityEvent event) {
    if (event.getLeftClicked() instanceof TNTPrimed) {
        if (TntTracker.getWhoPlaced(event.getLeftClicked()) != null) {
            UUID player = TntTracker.getWhoPlaced(event.getLeftClicked());
            TeamModule playerTeam = TeamUtils.getTeamByPlayer(Bukkit.getPlayer(player));
            if (Bukkit.getOfflinePlayer(player).isOnline()) {
                if (TeamUtils.getTeamByPlayer(Bukkit.getPlayer(player)) == TeamUtils.getTeamByPlayer(event.getPlayer()) && TeamUtils.getTeamByPlayer(Bukkit.getPlayer(player)) != null && !TeamUtils.getTeamByPlayer(Bukkit.getPlayer(player)).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.getColor() + Bukkit.getPlayer(player).getDisplayName() + ChatColor.RED + "'s TNT.");
                            ChatChannelModule channel = GameHandler.getGameHandler().getMatch().getModules().getModule(AdminChannel.class);
                            channel.sendMessage("[" + ChatColor.GOLD + "A" + ChatColor.WHITE + "] " + TeamUtils.getTeamByPlayer(event.getPlayer()).getColor() + event.getPlayer().getDisplayName() + ChatColor.RESET + " defused " + playerTeam.getColor() + Bukkit.getPlayer(player).getDisplayName() + ChatColor.RESET + "'s " + ChatColor.DARK_RED + "TNT");
                        }
                    } else {
                        ChatUtils.sendWarningMessage(event.getPlayer(), "You may not defuse TNT in water!");
                    }
                } else {
                    ChatUtils.sendWarningMessage(event.getPlayer(), "You may not defuse enemy TNT.");
                }
            } else {
                ChatUtils.sendWarningMessage(event.getPlayer(), "You may not defuse enemy TNT.");
            }
        }
    }
}
项目:CardinalPGM    文件:BlockBreakRegion.java   
@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);
        }
    }
}
项目:CardinalPGM    文件:BlockEventRegion.java   
@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);
        }
    }
}
项目:CardinalPGM    文件:TntDefuse.java   
@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.");
            }
        }
    }
}
项目:CardinalPGM    文件:AttackSpeed.java   
@EventHandler
public void onPlayerAttack(PlayerAttackEntityEvent event) {
    Optional<TeamModule> team = Teams.getTeamByPlayer(event.getPlayer());
    if (GameHandler.getGameHandler().getMatch().isRunning() && (!team.isPresent() || !team.get().isObserver())) {
        sendActionBar(event.getPlayer());
    }
}
项目:CardinalPGM    文件:FreezeModule.java   
@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());
        }
    }
}
项目:CardinalPGM    文件:SpectatorTools.java   
@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);
    }
}
项目:ProjectAres    文件:DefuseListener.java   
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void leftClickDefuse(final PlayerAttackEntityEvent event) {
    this.participantDefuse(event.getPlayer(), event.getLeftClicked());
}
项目:CardinalPGM    文件:ObserverModule.java   
@EventHandler
public void onEntityAttack(PlayerAttackEntityEvent event) {
    if (testObserverOrDead(event.getPlayer())) {
        event.setCancelled(true);
    }
}