Skip to content

Commit

Permalink
Remove COTW entities on chunk unload
Browse files Browse the repository at this point in the history
Fixes #4289
  • Loading branch information
nossr50 committed Dec 17, 2020
1 parent 22a738b commit 8c52884
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions Changelog.txt
Expand Up @@ -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!
Expand Down
30 changes: 30 additions & 0 deletions src/main/java/com/gmail/nossr50/listeners/ChunkListener.java
@@ -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();
}
}
}
}
}
}
Expand Up @@ -570,6 +570,7 @@ public void cleanupAllSummons() {

//Remove from existence
if(livingEntity != null && livingEntity.isValid()) {
mcMMO.getCompatibilityManager().getPersistentDataLayer().removeMobFlags(livingEntity);
livingEntity.setHealth(0);
livingEntity.remove();
}
Expand Down

0 comments on commit 8c52884

Please sign in to comment.