Cleanup entity data on chunk and world unload

Fixes #4720
This commit is contained in:
nossr50 2022-01-14 17:08:58 -08:00
parent 2e0a371ed8
commit f8e3111ec0
6 changed files with 48 additions and 3 deletions

View File

@ -1,3 +1,11 @@
Version 2.1.210
Mob metadata is now cleared on chunk unload (change in persistent_data.yml)
Mob metadata is now cleared on world unload (change in persistent_data.yml)
NOTES:
Turning off these new options will result in more system memory being used by mcMMO, but should prevent exploitative behaviour
They are now off by default in the interest of performance, this is a change from expected mcMMO behaviour
Version 2.1.209
Fixed a bug where some config files did not get trimmed completely

View File

@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.gmail.nossr50.mcMMO</groupId>
<artifactId>mcMMO</artifactId>
<version>2.1.209</version>
<version>2.1.210-SNAPSHOT</version>
<name>mcMMO</name>
<url>https://github.com/mcMMO-Dev/mcMMO</url>
<scm>

View File

@ -38,5 +38,14 @@ public class PersistentDataConfig extends BukkitConfig {
return config.getBoolean("mcMMO_Region_System.Enabled", true);
}
public boolean cleanupMobDataOnChunkUnload() {
return config.getBoolean("Persistent_Data.Advanced.Transient_Memory_Cleanup.On_Chunk_Unload", true);
}
public boolean cleanupMobDataOnWorldUnload() {
return config.getBoolean("Persistent_Data.Advanced.Transient_Memory_Cleanup.On_World_Unload", true);
}
}

View File

@ -664,7 +664,7 @@ public class EntityListener implements Listener {
* @param event
* The event to watch
*/
@EventHandler(priority = EventPriority.LOWEST)
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onEntityDeathLowest(EntityDeathEvent event) {
mcMMO.getTransientMetadataTools().cleanLivingEntityMetadata(event.getEntity());
}

View File

@ -1,9 +1,12 @@
package com.gmail.nossr50.listeners;
import com.gmail.nossr50.config.PersistentDataConfig;
import com.gmail.nossr50.config.WorldBlacklist;
import com.gmail.nossr50.mcMMO;
import org.bukkit.Chunk;
import org.bukkit.block.BlockState;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
@ -39,13 +42,23 @@ public class WorldListener implements Listener {
*
* @param event The event to watch
*/
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onWorldUnload(WorldUnloadEvent event) {
/* WORLD BLACKLIST CHECK */
if(WorldBlacklist.isWorldBlacklisted(event.getWorld()))
return;
mcMMO.getPlaceStore().unloadWorld(event.getWorld());
if(PersistentDataConfig.getInstance().cleanupMobDataOnWorldUnload())
{
for(Entity entity : event.getWorld().getEntities()) {
if(entity instanceof LivingEntity livingEntity) {
mcMMO.getTransientMetadataTools().cleanLivingEntityMetadata(livingEntity);
}
}
}
}
/**
@ -62,5 +75,14 @@ public class WorldListener implements Listener {
Chunk chunk = event.getChunk();
mcMMO.getPlaceStore().chunkUnloaded(chunk.getX(), chunk.getZ(), event.getWorld());
if(PersistentDataConfig.getInstance().cleanupMobDataOnChunkUnload()) {
for(Entity entity : event.getWorld().getEntities()) {
if(entity instanceof LivingEntity livingEntity) {
mcMMO.getTransientMetadataTools().cleanLivingEntityMetadata(livingEntity);
}
}
}
}
}

View File

@ -6,6 +6,12 @@
# I am considering alternative to using Spigots NBT API to avoid this performance cost, but the code for those will take some time to write and test, for now it is not recommended
# to turn any of these settings on without monitoring the TPS of your server afterwards. With the exception of the COTW setting which will probably have almost no performance impact if left on.
Persistent_Data:
Advanced:
Transient_Memory_Cleanup:
# False will require more system memory but prevent more exploitative behavior
On_Chunk_Unload: true
# False will require more system memory but prevent more exploitative behavior
On_World_Unload: true
Mobs:
Flags:
# By default mcMMO gives 0 XP for this type of mob, adjust in experience.yml