Skip to content

Commit eb1c45f

Browse files
committed
shorten code
1 parent 0100fdd commit eb1c45f

File tree

2 files changed

+14
-21
lines changed
  • AnarchyExploitFixesFolia/src/main/java/me/xginko/aef/modules/lagpreventions
  • AnarchyExploitFixesLegacy/src/main/java/me/xginko/aef/modules/lagpreventions

2 files changed

+14
-21
lines changed

AnarchyExploitFixesFolia/src/main/java/me/xginko/aef/modules/lagpreventions/LeverSpam.java

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,9 @@ public void disable() {
6060
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
6161
private void onInteract(PlayerInteractEvent event) {
6262
if (!event.getAction().isRightClick()) return;
63-
Block clicked = event.getClickedBlock();
64-
if (clicked.getType() != XMaterial.LEVER.parseMaterial()) return;
63+
if (event.getClickedBlock().getType() != XMaterial.LEVER.get()) return;
6564

66-
final Player player = event.getPlayer();
67-
68-
final Location leverLoc = clicked.getLocation();
65+
final Location leverLoc = event.getClickedBlock().getLocation();
6966
Integer activationCount = leverLocationCooldowns.getIfPresent(leverLoc);
7067
if (activationCount == null) activationCount = 0;
7168

@@ -75,30 +72,29 @@ private void onInteract(PlayerInteractEvent event) {
7572
if (activationCount > leverUsageLimit) {
7673
event.setCancelled(true);
7774
if (shouldKickPlayer) {
78-
player.kick(AnarchyExploitFixes.getLang(player.locale()).lagpreventions_stopSpammingLevers);
75+
event.getPlayer().kick(AnarchyExploitFixes.getLang(event.getPlayer().locale()).lagpreventions_stopSpammingLevers);
7976
return;
8077
}
8178
if (sendActionBar) {
82-
player.sendActionBar(AnarchyExploitFixes.getLang(player.locale()).lagpreventions_stopSpammingLevers);
79+
event.getPlayer().sendActionBar(AnarchyExploitFixes.getLang(event.getPlayer().locale()).lagpreventions_stopSpammingLevers);
8380
}
8481
return;
8582
}
8683

87-
final UUID playerUniqueId = player.getUniqueId();
88-
Integer leverFlickCount = playersUsingLeversCooldowns.getIfPresent(playerUniqueId);
84+
Integer leverFlickCount = playersUsingLeversCooldowns.getIfPresent(event.getPlayer().getUniqueId());
8985
if (leverFlickCount == null) leverFlickCount = 0;
9086

9187
leverFlickCount++;
92-
playersUsingLeversCooldowns.put(playerUniqueId, leverFlickCount);
88+
playersUsingLeversCooldowns.put(event.getPlayer().getUniqueId(), leverFlickCount);
9389

9490
if (leverFlickCount > leverUsageLimit) {
9591
event.setCancelled(true);
9692
if (shouldKickPlayer) {
97-
player.kick(AnarchyExploitFixes.getLang(player.locale()).lagpreventions_stopSpammingLevers);
93+
event.getPlayer().kick(AnarchyExploitFixes.getLang(event.getPlayer().locale()).lagpreventions_stopSpammingLevers);
9894
return;
9995
}
10096
if (sendActionBar) {
101-
player.sendActionBar(AnarchyExploitFixes.getLang(player.locale()).lagpreventions_stopSpammingLevers);
97+
event.getPlayer().sendActionBar(AnarchyExploitFixes.getLang(event.getPlayer().locale()).lagpreventions_stopSpammingLevers);
10298
}
10399
}
104100
}

AnarchyExploitFixesLegacy/src/main/java/me/xginko/aef/modules/lagpreventions/LeverSpam.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@ private void onInteract(PlayerInteractEvent event) {
6262
if (event.getAction() != Action.RIGHT_CLICK_BLOCK) return;
6363
if (event.getClickedBlock().getType() != XMaterial.LEVER.get()) return;
6464

65-
final Player player = event.getPlayer();
66-
6765
final Location leverLoc = event.getClickedBlock().getLocation();
6866
Integer activationCount = leverLocationCooldowns.getIfPresent(leverLoc);
6967
if (activationCount == null) activationCount = 0;
@@ -74,30 +72,29 @@ private void onInteract(PlayerInteractEvent event) {
7472
if (activationCount > leverUsageLimit) {
7573
event.setCancelled(true);
7674
if (shouldKickPlayer) {
77-
player.kickPlayer(AnarchyExploitFixes.getLang(player.getLocale()).lagpreventions_stopSpammingLevers);
75+
event.getPlayer().kickPlayer(AnarchyExploitFixes.getLang(event.getPlayer().getLocale()).lagpreventions_stopSpammingLevers);
7876
return;
7977
}
8078
if (sendActionBar) {
81-
player.sendActionBar(AnarchyExploitFixes.getLang(player.getLocale()).lagpreventions_stopSpammingLevers);
79+
event.getPlayer().sendActionBar(AnarchyExploitFixes.getLang(event.getPlayer().getLocale()).lagpreventions_stopSpammingLevers);
8280
}
8381
return;
8482
}
8583

86-
final UUID playerUniqueId = player.getUniqueId();
87-
Integer leverFlickCount = playersUsingLeversCooldowns.getIfPresent(playerUniqueId);
84+
Integer leverFlickCount = playersUsingLeversCooldowns.getIfPresent(event.getPlayer().getUniqueId());
8885
if (leverFlickCount == null) leverFlickCount = 0;
8986

9087
leverFlickCount++;
91-
playersUsingLeversCooldowns.put(playerUniqueId, leverFlickCount);
88+
playersUsingLeversCooldowns.put(event.getPlayer().getUniqueId(), leverFlickCount);
9289

9390
if (leverFlickCount > leverUsageLimit) {
9491
event.setCancelled(true);
9592
if (shouldKickPlayer) {
96-
player.kickPlayer(AnarchyExploitFixes.getLang(player.getLocale()).lagpreventions_stopSpammingLevers);
93+
event.getPlayer().kickPlayer(AnarchyExploitFixes.getLang(event.getPlayer().getLocale()).lagpreventions_stopSpammingLevers);
9794
return;
9895
}
9996
if (sendActionBar) {
100-
player.sendActionBar(AnarchyExploitFixes.getLang(player.getLocale()).lagpreventions_stopSpammingLevers);
97+
event.getPlayer().sendActionBar(AnarchyExploitFixes.getLang(event.getPlayer().getLocale()).lagpreventions_stopSpammingLevers);
10198
}
10299
}
103100
}

0 commit comments

Comments
 (0)