@EventHandler(priority = EventPriority.LOW) public void onPlayerAnimation(PlayerAnimationEvent e) { Player p = e.getPlayer(); List<String> allowedMoves = Probending.plugin.getConfig().getStringList("TeamSettings.AllowedMoves"); String playerTeam = PBMethods.getPlayerTeam(p.getUniqueId()); if (playerTeam != null) { if (playerTeam.equalsIgnoreCase(PBMethods.TeamOne) || playerTeam.equalsIgnoreCase(PBMethods.TeamTwo)) { if (PBMethods.matchStarted) { if (!allowedMoves.contains(GeneralMethods.getBoundAbility(p).toString()) && GeneralMethods.getBoundAbility(p) != null) { e.setCancelled(true); } } } } if (PBMethods.allowedZone.containsKey(p.getName())) { if (PBMethods.matchStarted && PBMethods.getWorldGuard() != null && PBMethods.AutomateMatches) { Location loc = p.getLocation(); Set<String> regions = PBMethods.RegionsAtLocation(loc); String allowedZone = PBMethods.allowedZone.get(p.getName()); if (regions != null && !regions.isEmpty()) { if (!regions.contains(allowedZone)) { e.setCancelled(true); } } } } }
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) public void onPlayerSwing(PlayerAnimationEvent event) { Player player = event.getPlayer(); if (this.interact.contains(player.getUniqueId())) { this.interact.remove(player.getUniqueId()); return; } if (Bloodbending.isBloodbended(player) || Concussion.getTarget(player) != null) { event.setCancelled(true); return; } String ability = EntityTools.getBendingAbility(player); RegisteredAbility registered = AbilityManager.getManager().getRegisteredAbility(ability); if (registered == null) { return; } if (EntityTools.canBend(player, registered) && (registered.canBeUsedWithTools() || !EntityTools.isTool(player.getInventory().getItemInMainHand().getType()))) { Map<Object, BendingAbility> abilities = AbilityManager.getManager().getInstances(ability); boolean shouldCreateNew = true; for (BendingAbility a : abilities.values()) { if (player.equals(a.getPlayer()) && !((BendingActiveAbility) a).swing()) { shouldCreateNew = false; } } if (shouldCreateNew) { BendingActiveAbility ab = AbilityManager.getManager().buildAbility(ability, player); if (ab == null) { Bending.getInstance() .getLogger() .log( Level.SEVERE, "Ability " + ability + " failed to construct with buildAbility for player " + player.getName()); return; } if (ab.canBeInitialized()) { ab.swing(); if (ab.getState() != BendingAbilityState.START && ab.getState() != BendingAbilityState.ENDED) { AbilityManager.getManager().addInstance(ab); } } } } }