Remove COTW entities on chunk unload

Fixes #4289
This commit is contained in:
nossr50 2020-12-16 16:29:05 -08:00
parent 22a738bace
commit 8c52884ac6
3 changed files with 32 additions and 0 deletions

View File

@ -2,6 +2,7 @@ Version 2.1.163
Fixed the translate URL pointing to the wrong place (thanks chew)
Fixed a bug where FlatFile databases would always attempt a UUID conversion task every save operation (every 10 minutes) causing console spam
mcMMO will no longer throw errors when incoming XP is below 0 (it will just silently cancel the operation)
COTW Summoned entities are now removed when the chunk they are in is unloaded (prevents some exploits)
NOTES:
I often test in SQL environments so I missed this bug, reminder to come bother me on discord if you find any annoying bugs!

View File

@ -0,0 +1,30 @@
package com.gmail.nossr50.listeners;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.util.compat.layers.persistentdata.MobMetaFlagType;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.world.ChunkUnloadEvent;
public class ChunkListener implements Listener {
@EventHandler(ignoreCancelled = true)
public void onChunkUnload(ChunkUnloadEvent event) {
for(Entity entity : event.getChunk().getEntities()) {
if(entity instanceof LivingEntity) {
LivingEntity livingEntity = (LivingEntity) entity;
if(mcMMO.getCompatibilityManager().getPersistentDataLayer().hasMobFlag(MobMetaFlagType.COTW_SUMMONED_MOB, livingEntity)) {
//Remove from existence
if(livingEntity.isValid()) {
mcMMO.getCompatibilityManager().getPersistentDataLayer().removeMobFlags(livingEntity);
livingEntity.setHealth(0);
livingEntity.remove();
}
}
}
}
}
}

View File

@ -570,6 +570,7 @@ public class TamingManager extends SkillManager {
//Remove from existence
if(livingEntity != null && livingEntity.isValid()) {
mcMMO.getCompatibilityManager().getPersistentDataLayer().removeMobFlags(livingEntity);
livingEntity.setHealth(0);
livingEntity.remove();
}