Skip to content

Commit 519dcaa

Browse files
committed
cleanup leftover chunklimit modules
1 parent 510ddd5 commit 519dcaa

File tree

6 files changed

+51
-15
lines changed

6 files changed

+51
-15
lines changed

AnarchyExploitFixesFolia/src/main/java/me/xginko/aef/modules/chunklimits/CustomEntityLimit.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,12 @@
2626

2727
public class CustomEntityLimit extends AEFModule implements Consumer<ScheduledTask>, Listener {
2828

29-
private ScheduledTask scheduledTask;
3029
private final Map<EntityType, Integer> entityLimits = new EnumMap<>(EntityType.class);
3130
private final long checkPeriod, minChunkAge;
3231
private final boolean logIsEnabled, enableChunkAgeSkip, forceLoadEntities;
3332

33+
private ScheduledTask scheduledTask;
34+
3435
public CustomEntityLimit() {
3536
super("chunk-limits.entity-limits.custom-limit", false, """
3637
Limit specific entity types per chunk.\s

AnarchyExploitFixesFolia/src/main/java/me/xginko/aef/modules/chunklimits/DroppedItemLimit.java

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
import java.time.Duration;
2525
import java.util.EnumSet;
26+
import java.util.Map;
2627
import java.util.Objects;
2728
import java.util.Set;
2829
import java.util.concurrent.atomic.AtomicInteger;
@@ -31,13 +32,14 @@
3132

3233
public class DroppedItemLimit extends AEFModule implements Consumer<ScheduledTask>, Listener {
3334

34-
private ScheduledTask scheduledTask;
35-
private final Cache<ChunkUID, ScheduledTask> scheduledChecks;
3635
private final Set<Material> whitelistedTypes;
3736
private final long checkPeriod, cleanupDelay;
3837
private final int maxDroppedItemsPerChunk;
3938
private final boolean logIsEnabled, usingWhitelist, onEntitiesLoad;
4039

40+
private Cache<ChunkUID, ScheduledTask> scheduledChecks;
41+
private ScheduledTask scheduledTask;
42+
4143
public DroppedItemLimit() {
4244
super("chunk-limits.entity-limits.dropped-item-limit", false, """
4345
Limit the amount of dropped items in a chunk to combat lag.\s
@@ -55,7 +57,6 @@ public DroppedItemLimit() {
5557
The period in ticks in which all loaded chunks should be regularly\s
5658
checked. Keep in mind: A lower number provides more accuracy but is\s
5759
also worse for performance.""");
58-
this.scheduledChecks = Caffeine.newBuilder().expireAfterWrite(Duration.ofMillis(cleanupDelay * 50L)).build();
5960
this.onEntitiesLoad = config.getBoolean(configPath + ".check-on-entities-load", true, """
6061
Runs item check when a chunk's entities are loaded.""");
6162
this.usingWhitelist = config.getBoolean(configPath + ".whitelist-specific-item-types", false);
@@ -79,16 +80,27 @@ public DroppedItemLimit() {
7980

8081
@Override
8182
public void enable() {
83+
scheduledChecks = Caffeine.newBuilder().expireAfterWrite(Duration.ofMillis(cleanupDelay * 50L)).build();
8284
plugin.getServer().getPluginManager().registerEvents(this, plugin);
83-
this.scheduledTask = plugin.getServer().getGlobalRegionScheduler()
85+
scheduledTask = plugin.getServer().getGlobalRegionScheduler()
8486
.runAtFixedRate(plugin, this, checkPeriod, checkPeriod);
8587
}
8688

8789
@Override
8890
public void disable() {
8991
HandlerList.unregisterAll(this);
90-
if (scheduledTask != null) scheduledTask.cancel();
91-
scheduledChecks.asMap().forEach((chunk, queuedCheck) -> queuedCheck.cancel());
92+
if (scheduledTask != null) {
93+
scheduledTask.cancel();
94+
scheduledTask = null;
95+
}
96+
if (scheduledChecks != null) {
97+
for (Map.Entry<ChunkUID, ScheduledTask> entry : scheduledChecks.asMap().entrySet()) {
98+
entry.getValue().cancel();
99+
}
100+
scheduledChecks.invalidateAll();
101+
scheduledChecks.cleanUp();
102+
scheduledChecks = null;
103+
}
92104
}
93105

94106
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)

AnarchyExploitFixesFolia/src/main/java/me/xginko/aef/modules/chunklimits/ExpBottleLimit.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@
1919

2020
public class ExpBottleLimit extends AEFModule implements Consumer<ScheduledTask>, Listener {
2121

22-
private ScheduledTask scheduledTask;
2322
private final long checkPeriod;
2423
private final int maxExpBottlePerChunk;
2524
private final boolean logIsEnabled;
2625

26+
private ScheduledTask scheduledTask;
27+
2728
public ExpBottleLimit() {
2829
super("chunk-limits.exp-bottle-limit", true, """
2930
Prevent players from crashing the server or other players by\s

AnarchyExploitFixesLegacy/src/main/java/me/xginko/aef/modules/chunklimits/CustomEntityLimit.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public class CustomEntityLimit extends AEFModule implements Runnable, Listener {
2727
private final Map<EntityType, Integer> entityLimits = new EnumMap<>(EntityType.class);
2828
private final long checkPeriod;
2929
private final boolean logIsEnabled;
30+
3031
private BukkitTask bukkitTask;
3132

3233
public CustomEntityLimit() {
@@ -146,7 +147,10 @@ public void enable() {
146147
@Override
147148
public void disable() {
148149
HandlerList.unregisterAll(this);
149-
if (bukkitTask != null) bukkitTask.cancel();
150+
if (bukkitTask != null) {
151+
bukkitTask.cancel();
152+
bukkitTask = null;
153+
}
150154
}
151155

152156
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)

AnarchyExploitFixesLegacy/src/main/java/me/xginko/aef/modules/chunklimits/DroppedItemLimit.java

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,19 @@
2323

2424
import java.time.Duration;
2525
import java.util.EnumSet;
26+
import java.util.Map;
2627
import java.util.Objects;
2728
import java.util.Set;
2829
import java.util.stream.Collectors;
2930

3031
public class DroppedItemLimit extends AEFModule implements Listener, Runnable {
3132

32-
private final Cache<ChunkUID, Integer> scheduledChecks;
3333
private final Set<Material> whitelistedTypes;
3434
private final long checkPeriod, cleanupDelay;
3535
private final int maxDroppedItemsPerChunk;
3636
private final boolean logIsEnabled, usingWhitelist, onChunkLoad;
37+
38+
private Cache<ChunkUID, BukkitTask> scheduledChecks;
3739
private BukkitTask bukkitTask;
3840

3941
public DroppedItemLimit() {
@@ -49,7 +51,6 @@ public DroppedItemLimit() {
4951
"has dropped before the check logic will run.\n" +
5052
"This improves performance as there will be no check for each single\n" +
5153
"item entity that spawns."));
52-
this.scheduledChecks = Caffeine.newBuilder().expireAfterWrite(Duration.ofMillis(cleanupDelay * 50L)).build();
5354
this.checkPeriod = config.getInt(configPath + ".check-period-in-ticks", 1200,
5455
"The period in ticks in which all loaded chunks should be regularly\n" +
5556
"checked. Keep in mind: A lower number provides more accuracy but is\n" +
@@ -77,14 +78,27 @@ public DroppedItemLimit() {
7778

7879
@Override
7980
public void enable() {
81+
scheduledChecks = Caffeine.newBuilder().expireAfterWrite(Duration.ofMillis(cleanupDelay * 50L)).build();
8082
plugin.getServer().getPluginManager().registerEvents(this, plugin);
81-
bukkitTask = plugin.getServer().getScheduler().runTaskTimer(plugin, this, checkPeriod, checkPeriod);
83+
bukkitTask = plugin.getServer().getScheduler()
84+
.runTaskTimer(plugin, this, checkPeriod, checkPeriod);
8285
}
8386

8487
@Override
8588
public void disable() {
8689
HandlerList.unregisterAll(this);
87-
if (bukkitTask != null) bukkitTask.cancel();
90+
if (bukkitTask != null) {
91+
bukkitTask.cancel();
92+
bukkitTask = null;
93+
}
94+
if (scheduledChecks != null) {
95+
for (Map.Entry<ChunkUID, BukkitTask> entry : scheduledChecks.asMap().entrySet()) {
96+
entry.getValue().cancel();
97+
}
98+
scheduledChecks.invalidateAll();
99+
scheduledChecks.cleanUp();
100+
scheduledChecks = null;
101+
}
88102
}
89103

90104
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
@@ -93,7 +107,7 @@ private void onItemDrop(ItemSpawnEvent event) {
93107
final ChunkUID chunkUID = ChunkUID.of(chunk);
94108
// Don't create a check task for each spawning item
95109
scheduledChecks.get(chunkUID, k ->
96-
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, () -> {
110+
plugin.getServer().getScheduler().runTaskLater(plugin, () -> {
97111
if (!chunk.isLoaded()) return;
98112

99113
int droppedItemCount = 0;

AnarchyExploitFixesLegacy/src/main/java/me/xginko/aef/modules/chunklimits/ExpBottleLimit.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public class ExpBottleLimit extends AEFModule implements Runnable, Listener {
1919
private final long checkPeriod;
2020
private final int maxExpBottlePerChunk;
2121
private final boolean logIsEnabled;
22+
2223
private BukkitTask bukkitTask;
2324

2425
public ExpBottleLimit() {
@@ -43,7 +44,10 @@ public void enable() {
4344
@Override
4445
public void disable() {
4546
HandlerList.unregisterAll(this);
46-
if (bukkitTask != null) bukkitTask.cancel();
47+
if (bukkitTask != null) {
48+
bukkitTask.cancel();
49+
bukkitTask = null;
50+
}
4751
}
4852

4953
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)

0 commit comments

Comments
 (0)