Skip to content

Commit ccefca7

Browse files
committed
implement typed limits in regional activity
1 parent e8be936 commit ccefca7

31 files changed

+688
-484
lines changed

AnarchyExploitFixesFolia/src/main/java/me/xginko/aef/modules/lagpreventions/regionalactivity/BlockFormOrGrow.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,28 @@
11
package me.xginko.aef.modules.lagpreventions.regionalactivity;
22

3+
import com.cryptomorin.xseries.XMaterial;
34
import org.bukkit.event.EventHandler;
45
import org.bukkit.event.EventPriority;
56
import org.bukkit.event.block.BlockFormEvent;
67
import org.bukkit.event.block.BlockSpreadEvent;
78

8-
public class BlockFormOrGrow extends RegionalActivityModule {
9+
import java.util.Map;
910

10-
private final int limit;
11+
public class BlockFormOrGrow extends RegionalBlockActivityModule {
1112

1213
public BlockFormOrGrow() {
1314
super(
1415
"block-spread",
1516
false,
1617
true,
18+
2000,
1719
1500.0,
1820
6000,
1921
10000,
2022
10.0,
2123
120.0,
24+
Map.of( XMaterial.ICE, 1000,
25+
XMaterial.SNOW, 1000),
2226
"""
2327
Limits blocks spreading or forming based on world conditions within a\s
2428
configurable radius and timeframe to help reduce lag by cancelling burst\s
@@ -33,21 +37,18 @@ public BlockFormOrGrow() {
3337
- Mushrooms spreading.\s
3438
- Fire spreading."""
3539
);
36-
this.limit = config.getInt(configPath + ".block-form-event-limit", 800,
37-
"Maximum number of times a block can form or spread within the configured\n" +
38-
"timeframe before activity will be put on cooldown.");
3940
}
4041

4142
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
4243
private void onBlockForm(BlockFormEvent event) {
43-
if (shouldCancelActivity(event, event.getBlock().getLocation(), limit)) {
44+
if (shouldCancelBlockEvent(event)) {
4445
event.setCancelled(true);
4546
}
4647
}
4748

4849
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
4950
private void onBlockSpread(BlockSpreadEvent event) {
50-
if (shouldCancelActivity(event, event.getBlock().getLocation(), limit)) {
51+
if (shouldCancelBlockEvent(event)) {
5152
event.setCancelled(true);
5253
}
5354
}

AnarchyExploitFixesFolia/src/main/java/me/xginko/aef/modules/lagpreventions/regionalactivity/BlockPhysics.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,27 @@
11
package me.xginko.aef.modules.lagpreventions.regionalactivity;
22

3+
import com.cryptomorin.xseries.XMaterial;
34
import org.bukkit.event.EventHandler;
45
import org.bukkit.event.EventPriority;
56
import org.bukkit.event.block.BlockPhysicsEvent;
67

7-
public class BlockPhysics extends RegionalActivityModule {
8+
import java.util.Map;
89

9-
private final int limit;
10+
public class BlockPhysics extends RegionalBlockActivityModule {
1011

1112
public BlockPhysics() {
1213
super(
1314
"block-physics",
1415
false,
1516
true,
17+
512000,
1618
1500.0,
1719
18000,
1820
20000,
1921
10.0,
2022
120.0,
23+
Map.of( XMaterial.WATER, 256000,
24+
XMaterial.LAVA, 256000),
2125
"""
2226
Limits block physics within a configurable radius and timeframe\s
2327
to help reduce lag by cancelling burst activity hotspots.\s
@@ -31,14 +35,11 @@ The event used for this check (BlockPhysicsEvent) is a high frequency event,\s
3135
Physics updates that cause other blocks to change their state may not result\s
3236
in an event for each of those blocks (usually adjacent)."""
3337
);
34-
this.limit = config.getInt(configPath + ".block-physics-event-limit", 256000,
35-
"Maximum number of times a physics check can be performed within the configured\n" +
36-
"timeframe before they will be put on cooldown.");
3738
}
3839

3940
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
4041
private void onBlockPhysics(BlockPhysicsEvent event) {
41-
if (shouldCancelActivity(event, event.getBlock().getLocation(), limit)) {
42+
if (shouldCancelBlockEvent(event)) {
4243
event.setCancelled(true);
4344
}
4445
}

AnarchyExploitFixesFolia/src/main/java/me/xginko/aef/modules/lagpreventions/regionalactivity/EntitySpawns.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,27 @@
11
package me.xginko.aef.modules.lagpreventions.regionalactivity;
22

3+
import com.cryptomorin.xseries.XEntityType;
34
import org.bukkit.event.EventHandler;
45
import org.bukkit.event.EventPriority;
56
import org.bukkit.event.entity.EntitySpawnEvent;
67

7-
public class EntitySpawns extends RegionalActivityModule {
8+
import java.util.Map;
89

9-
private final int limit;
10+
public class EntitySpawns extends RegionalEntityActivityModule {
1011

1112
public EntitySpawns() {
1213
super(
1314
"entity-spawn",
1415
false,
1516
true,
17+
6000,
1618
1500.0,
1719
18000,
1820
20000,
1921
10.0,
2022
120.0,
23+
Map.of( XEntityType.WITHER, 50,
24+
XEntityType.WITHER_SKULL, 200),
2125
"""
2226
Limits entity spawning activity within a configurable radius and timeframe\s
2327
to help reduce lag by cancelling high activity hotspots.\s
@@ -28,13 +32,11 @@ public EntitySpawns() {
2832
- An entity gets spawned naturally, by spawner or other reasons.\s
2933
This does not include tile entities."""
3034
);
31-
this.limit = config.getInt(configPath + ".spawn-event-limit", 6000,
32-
"Maximum number of entity spawns within configured timeframe.");
3335
}
3436

3537
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
3638
private void onEntitySpawn(EntitySpawnEvent event) {
37-
if (shouldCancelActivity(event, event.getLocation(), limit)) {
39+
if (shouldCancelEntityEvent(event)) {
3840
event.setCancelled(true);
3941
}
4042
}

AnarchyExploitFixesFolia/src/main/java/me/xginko/aef/modules/lagpreventions/regionalactivity/EntityTargeting.java

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,42 +3,37 @@
33
import com.cryptomorin.xseries.XEntityType;
44
import io.github.thatsmusic99.configurationmaster.api.ConfigSection;
55
import me.xginko.aef.utils.LocationUtil;
6-
import org.bukkit.Location;
7-
import org.bukkit.entity.Entity;
86
import org.bukkit.entity.EntityType;
97
import org.bukkit.event.EventHandler;
108
import org.bukkit.event.EventPriority;
11-
import org.bukkit.event.Listener;
129
import org.bukkit.event.entity.EntityTargetEvent;
1310
import org.bukkit.util.NumberConversions;
1411

1512
import java.util.EnumMap;
1613
import java.util.Map;
1714
import java.util.TreeMap;
1815

19-
public class EntityTargeting extends RegionalActivityModule implements Listener {
16+
public class EntityTargeting extends RegionalEntityActivityModule {
2017

21-
private final Map<EntityType, Double> limitedTypes = new EnumMap<>(EntityType.class);
18+
private final Map<EntityType, Double> typedDistanceLimits = new EnumMap<>(EntityType.class);
2219
private final double globalMaxDistanceSquared;
23-
private final int limit;
2420
private final boolean globalDistanceEnabled, perTypeDistanceEnabled;
2521

2622
public EntityTargeting() {
2723
super("entity-targeting",
2824
false,
2925
true,
26+
8000,
3027
1500.0,
3128
18000,
3229
20000,
3330
14.0,
3431
120.0,
32+
Map.of(XEntityType.VILLAGER, 1000),
3533
"""
3634
Limits entities targeting other entities within a configurable radius\s
3735
and timeframe to help reduce lag by cancelling burst activity hotspots."""
3836
);
39-
this.limit = config.getInt(configPath + ".entity-target-event-limit", 8000, """
40-
Maximum number of times an entity can target another entity within the\s
41-
configured timeframe before the area will be put on cooldown.""");
4237

4338
this.globalDistanceEnabled = config.getBoolean(configPath + ".distance-limit.global-limit.enable", false);
4439
this.globalMaxDistanceSquared = NumberConversions.square(
@@ -66,7 +61,7 @@ public EntityTargeting() {
6661
try {
6762
Double maxDistanceSquared = NumberConversions.square(Double.parseDouble(section.getString(configuredEntity)));
6863
EntityType limitedEntity = EntityType.valueOf(configuredEntity);
69-
this.limitedTypes.put(limitedEntity, maxDistanceSquared);
64+
this.typedDistanceLimits.put(limitedEntity, maxDistanceSquared);
7065
} catch (NumberFormatException e) {
7166
notRecognized(Double.class, configuredEntity);
7267
} catch (IllegalArgumentException e) {
@@ -77,11 +72,9 @@ public EntityTargeting() {
7772

7873
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
7974
private void onEntityTarget(EntityTargetEvent event) {
80-
Entity targetEntity = event.getTarget();
81-
if (targetEntity == null) return; // If entity un-targets an entity, it's good for us.
75+
if (event.getTarget() == null) return; // If entity un-targets an entity, it's good for us.
8276

83-
Location location = event.getEntity().getLocation();
84-
if (shouldCancelActivity(event, location, limit)) {
77+
if (shouldCancelEntityEvent(event)) {
8578
event.setCancelled(true);
8679
return;
8780
}
@@ -92,7 +85,7 @@ private void onEntityTarget(EntityTargetEvent event) {
9285

9386
double targetDistanceSquared;
9487
try {
95-
targetDistanceSquared = event.getEntity().getLocation().distanceSquared(targetEntity.getLocation());
88+
targetDistanceSquared = event.getEntity().getLocation().distanceSquared(event.getTarget().getLocation());
9689
} catch (IllegalArgumentException e) {
9790
if (logIsEnabled) error("Unable to measure distance between entity and target.", e);
9891
return;
@@ -103,18 +96,18 @@ private void onEntityTarget(EntityTargetEvent event) {
10396
event.setCancelled(true);
10497
event.setTarget(null);
10598
if (logIsEnabled) info("Cancelled target acquire for entity " + event.getEntityType().name() + " at " +
106-
LocationUtil.toString(location) +
99+
LocationUtil.toString(event.getEntity().getLocation()) +
107100
" because target is further than the global limit. Distance: " + Math.sqrt(targetDistanceSquared));
108101
return;
109102
}
110103
}
111104

112105
if (perTypeDistanceEnabled) {
113-
if (limitedTypes.containsKey(event.getEntityType()) && targetDistanceSquared > limitedTypes.get(event.getEntityType())) {
106+
if (typedDistanceLimits.containsKey(event.getEntityType()) && targetDistanceSquared > typedDistanceLimits.get(event.getEntityType())) {
114107
event.setCancelled(true);
115108
event.setTarget(null);
116109
if (logIsEnabled) info("Cancelled target acquire for entity " + event.getEntityType().name() + " at " +
117-
LocationUtil.toString(location) +
110+
LocationUtil.toString(event.getEntity().getLocation()) +
118111
" because target further than its configured limit. Distance: " + Math.sqrt(targetDistanceSquared));
119112
}
120113
}

AnarchyExploitFixesFolia/src/main/java/me/xginko/aef/modules/lagpreventions/regionalactivity/Explosions.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,12 @@
88

99
public class Explosions extends RegionalActivityModule {
1010

11-
private final int limit;
12-
1311
public Explosions() {
1412
super(
1513
"explosions",
1614
false,
1715
true,
16+
1000,
1817
1500.0,
1918
6000,
2019
10000,
@@ -30,28 +29,25 @@ public Explosions() {
3029
- An entity exploding.\s
3130
- An entity making the decision to explode."""
3231
);
33-
this.limit = config.getInt(configPath + ".explode-event-limit", 500,
34-
"Maximum number of explode events within the configured timeframe\n" +
35-
"before the region will be put on cooldown.");
3632
}
3733

3834
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
3935
private void onExplosionPrime(ExplosionPrimeEvent event) {
40-
if (shouldCancelActivity(event, event.getEntity().getLocation(), limit)) {
36+
if (shouldCancelEvent(event, event.getEntity().getLocation())) {
4137
event.setCancelled(true);
4238
}
4339
}
4440

4541
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
4642
private void onEntityExplode(EntityExplodeEvent event) {
47-
if (shouldCancelActivity(event, event.getLocation(), limit)) {
43+
if (shouldCancelEvent(event, event.getEntity().getLocation())) {
4844
event.setCancelled(true);
4945
}
5046
}
5147

5248
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
5349
private void onBlockExplode(BlockExplodeEvent event) {
54-
if (shouldCancelActivity(event, event.getBlock().getLocation(), limit)) {
50+
if (shouldCancelEvent(event, event.getBlock().getLocation())) {
5551
event.setCancelled(true);
5652
}
5753
}

AnarchyExploitFixesFolia/src/main/java/me/xginko/aef/modules/lagpreventions/regionalactivity/LiquidSpread.java

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,23 @@
55
import org.bukkit.event.EventPriority;
66
import org.bukkit.event.block.BlockFromToEvent;
77

8-
public class LiquidSpread extends RegionalActivityModule {
8+
import java.util.Map;
99

10-
private final int limit;
11-
private final boolean ignoreDragonEgg;
10+
public class LiquidSpread extends RegionalBlockActivityModule {
1211

1312
public LiquidSpread() {
1413
super(
1514
"liquid-spread",
1615
false,
1716
true,
17+
16000,
1818
1500.0,
1919
18000,
2020
20000,
2121
12.0,
2222
100.0,
23+
Map.of( XMaterial.WATER, 4000,
24+
XMaterial.LAVA, 6000),
2325
"""
2426
Limits liquid spreading within a configurable radius and timeframe\s
2527
to help reduce lag by cancelling high activity hotspots.\s
@@ -28,19 +30,13 @@ public LiquidSpread() {
2830
\s
2931
- A lava block spreading by flowing.\s
3032
- A water block spreading by flowing.\s
31-
- (optional) A dragon egg is teleporting from one position to another."""
33+
- A dragon egg is teleporting from one position to another."""
3234
);
33-
this.limit = config.getInt(configPath + ".liquid-spread-event-limit", 2400,
34-
"Maximum number of times liquids are allowed to spread within the configured\n" +
35-
"timeframe before they will be put on cooldown.");
36-
this.ignoreDragonEgg = config.getBoolean(configPath + ".ignore-dragon-egg", true);
3735
}
3836

3937
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
4038
private void onBlockFromTo(BlockFromToEvent event) {
41-
if (ignoreDragonEgg && event.getBlock().getType() == XMaterial.DRAGON_EGG.get()) return;
42-
43-
if (shouldCancelActivity(event, event.getBlock().getLocation(), limit)) {
39+
if (shouldCancelBlockEvent(event)) {
4440
event.setCancelled(true);
4541
}
4642
}

AnarchyExploitFixesFolia/src/main/java/me/xginko/aef/modules/lagpreventions/regionalactivity/Noteblocks.java

Lines changed: 0 additions & 41 deletions
This file was deleted.

0 commit comments

Comments
 (0)