Skip to content

Commit 18e0349

Browse files
committed
Avoid checking every single entity for despawning
1 parent 1c3e300 commit 18e0349

2 files changed

Lines changed: 5 additions & 2 deletions

File tree

Towny/src/main/java/com/palmergames/bukkit/towny/listeners/TownyPaperEvents.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import org.jetbrains.annotations.ApiStatus;
3737

3838
import java.lang.invoke.MethodHandle;
39+
import java.util.Set;
3940
import java.util.function.Consumer;
4041
import java.util.function.Supplier;
4142
import java.util.logging.Level;
@@ -194,12 +195,14 @@ private Consumer<BeaconEffectEvent> beaconEffectEventListener() {
194195
};
195196
}
196197

198+
private static final Set<EntityType> IGNORED_TYPES = Set.of(EntityType.ITEM_FRAME, EntityType.GLOW_ITEM_FRAME, EntityType.ARMOR_STAND, EntityType.ITEM, EntityType.INTERACTION, EntityType.BLOCK_DISPLAY, EntityType.ITEM_DISPLAY, EntityType.PAINTING);
199+
197200
private Consumer<EntityEvent> entityAddToWorldListener() {
198201
return event -> {
199202
if (!(event.getEntity() instanceof LivingEntity entity))
200203
return;
201204

202-
if (entity instanceof Player || PluginIntegrations.getInstance().isNPC(entity))
205+
if (entity instanceof Player || IGNORED_TYPES.contains(entity.getType()) || PluginIntegrations.getInstance().isNPC(entity))
203206
return;
204207

205208
final TownyWorld world = TownyAPI.getInstance().getTownyWorld(entity.getWorld());

Towny/src/main/java/com/palmergames/bukkit/towny/tasks/MobRemovalTimerTask.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public static void checkEntity(final @NotNull Towny plugin, final @NotNull Towny
111111
if (!(ent instanceof LivingEntity entity))
112112
return;
113113

114-
if (entity instanceof Player || PluginIntegrations.getInstance().isNPC(entity))
114+
if (entity instanceof Player || (!plugin.isFolia() && PluginIntegrations.getInstance().isNPC(entity))) // already checked on folia
115115
return;
116116

117117
// Handles entities Globally.

0 commit comments

Comments
 (0)