From eb1c45fc75452ad4e5cf8b9a5aa8a69783238b98 Mon Sep 17 00:00:00 2001 From: xGinko Date: Tue, 31 Dec 2024 22:00:29 +0100 Subject: [PATCH] shorten code --- .../aef/modules/lagpreventions/LeverSpam.java | 20 ++++++++----------- .../aef/modules/lagpreventions/LeverSpam.java | 15 ++++++-------- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/AnarchyExploitFixesFolia/src/main/java/me/xginko/aef/modules/lagpreventions/LeverSpam.java b/AnarchyExploitFixesFolia/src/main/java/me/xginko/aef/modules/lagpreventions/LeverSpam.java index 179cfc7f..f7ff797e 100755 --- a/AnarchyExploitFixesFolia/src/main/java/me/xginko/aef/modules/lagpreventions/LeverSpam.java +++ b/AnarchyExploitFixesFolia/src/main/java/me/xginko/aef/modules/lagpreventions/LeverSpam.java @@ -60,12 +60,9 @@ public void disable() { @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) private void onInteract(PlayerInteractEvent event) { if (!event.getAction().isRightClick()) return; - Block clicked = event.getClickedBlock(); - if (clicked.getType() != XMaterial.LEVER.parseMaterial()) return; + if (event.getClickedBlock().getType() != XMaterial.LEVER.get()) return; - final Player player = event.getPlayer(); - - final Location leverLoc = clicked.getLocation(); + final Location leverLoc = event.getClickedBlock().getLocation(); Integer activationCount = leverLocationCooldowns.getIfPresent(leverLoc); if (activationCount == null) activationCount = 0; @@ -75,30 +72,29 @@ private void onInteract(PlayerInteractEvent event) { if (activationCount > leverUsageLimit) { event.setCancelled(true); if (shouldKickPlayer) { - player.kick(AnarchyExploitFixes.getLang(player.locale()).lagpreventions_stopSpammingLevers); + event.getPlayer().kick(AnarchyExploitFixes.getLang(event.getPlayer().locale()).lagpreventions_stopSpammingLevers); return; } if (sendActionBar) { - player.sendActionBar(AnarchyExploitFixes.getLang(player.locale()).lagpreventions_stopSpammingLevers); + event.getPlayer().sendActionBar(AnarchyExploitFixes.getLang(event.getPlayer().locale()).lagpreventions_stopSpammingLevers); } return; } - final UUID playerUniqueId = player.getUniqueId(); - Integer leverFlickCount = playersUsingLeversCooldowns.getIfPresent(playerUniqueId); + Integer leverFlickCount = playersUsingLeversCooldowns.getIfPresent(event.getPlayer().getUniqueId()); if (leverFlickCount == null) leverFlickCount = 0; leverFlickCount++; - playersUsingLeversCooldowns.put(playerUniqueId, leverFlickCount); + playersUsingLeversCooldowns.put(event.getPlayer().getUniqueId(), leverFlickCount); if (leverFlickCount > leverUsageLimit) { event.setCancelled(true); if (shouldKickPlayer) { - player.kick(AnarchyExploitFixes.getLang(player.locale()).lagpreventions_stopSpammingLevers); + event.getPlayer().kick(AnarchyExploitFixes.getLang(event.getPlayer().locale()).lagpreventions_stopSpammingLevers); return; } if (sendActionBar) { - player.sendActionBar(AnarchyExploitFixes.getLang(player.locale()).lagpreventions_stopSpammingLevers); + event.getPlayer().sendActionBar(AnarchyExploitFixes.getLang(event.getPlayer().locale()).lagpreventions_stopSpammingLevers); } } } diff --git a/AnarchyExploitFixesLegacy/src/main/java/me/xginko/aef/modules/lagpreventions/LeverSpam.java b/AnarchyExploitFixesLegacy/src/main/java/me/xginko/aef/modules/lagpreventions/LeverSpam.java index af700ddd..7a83da17 100755 --- a/AnarchyExploitFixesLegacy/src/main/java/me/xginko/aef/modules/lagpreventions/LeverSpam.java +++ b/AnarchyExploitFixesLegacy/src/main/java/me/xginko/aef/modules/lagpreventions/LeverSpam.java @@ -62,8 +62,6 @@ private void onInteract(PlayerInteractEvent event) { if (event.getAction() != Action.RIGHT_CLICK_BLOCK) return; if (event.getClickedBlock().getType() != XMaterial.LEVER.get()) return; - final Player player = event.getPlayer(); - final Location leverLoc = event.getClickedBlock().getLocation(); Integer activationCount = leverLocationCooldowns.getIfPresent(leverLoc); if (activationCount == null) activationCount = 0; @@ -74,30 +72,29 @@ private void onInteract(PlayerInteractEvent event) { if (activationCount > leverUsageLimit) { event.setCancelled(true); if (shouldKickPlayer) { - player.kickPlayer(AnarchyExploitFixes.getLang(player.getLocale()).lagpreventions_stopSpammingLevers); + event.getPlayer().kickPlayer(AnarchyExploitFixes.getLang(event.getPlayer().getLocale()).lagpreventions_stopSpammingLevers); return; } if (sendActionBar) { - player.sendActionBar(AnarchyExploitFixes.getLang(player.getLocale()).lagpreventions_stopSpammingLevers); + event.getPlayer().sendActionBar(AnarchyExploitFixes.getLang(event.getPlayer().getLocale()).lagpreventions_stopSpammingLevers); } return; } - final UUID playerUniqueId = player.getUniqueId(); - Integer leverFlickCount = playersUsingLeversCooldowns.getIfPresent(playerUniqueId); + Integer leverFlickCount = playersUsingLeversCooldowns.getIfPresent(event.getPlayer().getUniqueId()); if (leverFlickCount == null) leverFlickCount = 0; leverFlickCount++; - playersUsingLeversCooldowns.put(playerUniqueId, leverFlickCount); + playersUsingLeversCooldowns.put(event.getPlayer().getUniqueId(), leverFlickCount); if (leverFlickCount > leverUsageLimit) { event.setCancelled(true); if (shouldKickPlayer) { - player.kickPlayer(AnarchyExploitFixes.getLang(player.getLocale()).lagpreventions_stopSpammingLevers); + event.getPlayer().kickPlayer(AnarchyExploitFixes.getLang(event.getPlayer().getLocale()).lagpreventions_stopSpammingLevers); return; } if (sendActionBar) { - player.sendActionBar(AnarchyExploitFixes.getLang(player.getLocale()).lagpreventions_stopSpammingLevers); + event.getPlayer().sendActionBar(AnarchyExploitFixes.getLang(event.getPlayer().getLocale()).lagpreventions_stopSpammingLevers); } } }