diff --git a/Changelog.txt b/Changelog.txt index a69371b6e..7d87de21c 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -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 diff --git a/pom.xml b/pom.xml index 50eb1fbd6..1484101cc 100755 --- a/pom.xml +++ b/pom.xml @@ -2,7 +2,7 @@ 4.0.0 com.gmail.nossr50.mcMMO mcMMO - 2.1.209 + 2.1.210-SNAPSHOT mcMMO https://github.com/mcMMO-Dev/mcMMO diff --git a/src/main/java/com/gmail/nossr50/config/PersistentDataConfig.java b/src/main/java/com/gmail/nossr50/config/PersistentDataConfig.java index 11b605eaa..e6b01c382 100644 --- a/src/main/java/com/gmail/nossr50/config/PersistentDataConfig.java +++ b/src/main/java/com/gmail/nossr50/config/PersistentDataConfig.java @@ -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); + } + + } \ No newline at end of file diff --git a/src/main/java/com/gmail/nossr50/listeners/EntityListener.java b/src/main/java/com/gmail/nossr50/listeners/EntityListener.java index 6690efab3..96bd0dc5c 100644 --- a/src/main/java/com/gmail/nossr50/listeners/EntityListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/EntityListener.java @@ -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()); } diff --git a/src/main/java/com/gmail/nossr50/listeners/WorldListener.java b/src/main/java/com/gmail/nossr50/listeners/WorldListener.java index 5abea42b3..f94804e66 100644 --- a/src/main/java/com/gmail/nossr50/listeners/WorldListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/WorldListener.java @@ -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); + } + } + } } + } diff --git a/src/main/resources/persistent_data.yml b/src/main/resources/persistent_data.yml index 8508ab84f..505d7b5df 100644 --- a/src/main/resources/persistent_data.yml +++ b/src/main/resources/persistent_data.yml @@ -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