Skip to content

Commit

Permalink
replace with expiringset
Browse files Browse the repository at this point in the history
  • Loading branch information
xGinko committed Dec 27, 2023
1 parent 0fdcdb4 commit 881df12
Showing 1 changed file with 6 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,19 @@
import com.comphenix.protocol.events.ListenerPriority;
import com.comphenix.protocol.events.PacketAdapter;
import com.comphenix.protocol.events.PacketEvent;
import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
import me.moomoo.anarchyexploitfixes.AnarchyExploitFixes;
import me.moomoo.anarchyexploitfixes.utils.models.ExpiringSet;

import java.time.Duration;
import java.util.UUID;

public class AutoRecipePacketListener extends PacketAdapter {

private final Cache<UUID, Boolean> recipeCooldowns;
private final ExpiringSet<UUID> recipeCooldowns;

protected AutoRecipePacketListener(AnarchyExploitFixes plugin, long craftingRecipeDelayInMillis) {
super(plugin, ListenerPriority.NORMAL, PacketType.Play.Client.AUTO_RECIPE);
this.recipeCooldowns = Caffeine.newBuilder().expireAfterWrite(Duration.ofMillis(craftingRecipeDelayInMillis)).build();
super(plugin, ListenerPriority.HIGHEST, PacketType.Play.Client.AUTO_RECIPE);
this.recipeCooldowns = new ExpiringSet<>(Duration.ofMillis(craftingRecipeDelayInMillis));
}

protected void register() {
Expand All @@ -31,10 +30,10 @@ public void onPacketReceiving(PacketEvent event) {

final UUID playerUniqueID = event.getPlayer().getUniqueId();

if (recipeCooldowns.getIfPresent(playerUniqueID) != null) {
if (recipeCooldowns.contains(playerUniqueID)) {
event.setCancelled(true);
} else {
recipeCooldowns.put(playerUniqueID, true);
recipeCooldowns.add(playerUniqueID);
}
}
}

0 comments on commit 881df12

Please sign in to comment.