Skip to content

Commit

Permalink
shorten code
Browse files Browse the repository at this point in the history
  • Loading branch information
xGinko committed Dec 31, 2024
1 parent 0100fdd commit eb1c45f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
}
}
Expand Down

0 comments on commit eb1c45f

Please sign in to comment.