diff --git a/api/src/main/java/de/erethon/dungeonsxl/api/dungeon/GameRule.java b/api/src/main/java/de/erethon/dungeonsxl/api/dungeon/GameRule.java index 0fe5efae..1f851605 100644 --- a/api/src/main/java/de/erethon/dungeonsxl/api/dungeon/GameRule.java +++ b/api/src/main/java/de/erethon/dungeonsxl/api/dungeon/GameRule.java @@ -355,6 +355,10 @@ public class GameRule { * If group tags are used. */ public static final GameRule GROUP_TAG_ENABLED = new GameRule<>(Boolean.class, "groupTagEnabled", false); + /** + * If Citizens NPCs should be copied to the native registry. + */ + public static final GameRule USE_NATIVE_CITIZENS_REGISTRY = new GameRule<>(Boolean.class, "useNativeCitizensRegistry", false); /** * An array of all game rules that exist natively in DungeonsXL. diff --git a/core/src/main/java/de/erethon/dungeonsxl/command/AnnounceCommand.java b/core/src/main/java/de/erethon/dungeonsxl/command/AnnounceCommand.java index 6e42f1aa..e957c85c 100644 --- a/core/src/main/java/de/erethon/dungeonsxl/command/AnnounceCommand.java +++ b/core/src/main/java/de/erethon/dungeonsxl/command/AnnounceCommand.java @@ -24,9 +24,8 @@ import de.erethon.dungeonsxl.api.player.InstancePlayer; import de.erethon.dungeonsxl.config.DMessage; import de.erethon.dungeonsxl.player.DGlobalPlayer; import de.erethon.dungeonsxl.player.DPermission; -import org.bukkit.command.CommandSender; - import java.util.List; +import org.bukkit.command.CommandSender; /** * @author Goh Wei Wen diff --git a/core/src/main/java/de/erethon/dungeonsxl/dungeon/DGame.java b/core/src/main/java/de/erethon/dungeonsxl/dungeon/DGame.java index 43f96d43..d1595faa 100644 --- a/core/src/main/java/de/erethon/dungeonsxl/dungeon/DGame.java +++ b/core/src/main/java/de/erethon/dungeonsxl/dungeon/DGame.java @@ -16,7 +16,6 @@ */ package de.erethon.dungeonsxl.dungeon; -import de.erethon.commons.player.PlayerUtil; import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.api.dungeon.Dungeon; import de.erethon.dungeonsxl.api.dungeon.Game; diff --git a/core/src/main/java/de/erethon/dungeonsxl/mob/CitizensMobProvider.java b/core/src/main/java/de/erethon/dungeonsxl/mob/CitizensMobProvider.java index 1d30e292..7f4c4e39 100644 --- a/core/src/main/java/de/erethon/dungeonsxl/mob/CitizensMobProvider.java +++ b/core/src/main/java/de/erethon/dungeonsxl/mob/CitizensMobProvider.java @@ -18,6 +18,7 @@ package de.erethon.dungeonsxl.mob; import de.erethon.commons.misc.NumberUtil; import de.erethon.dungeonsxl.DungeonsXL; +import de.erethon.dungeonsxl.api.dungeon.GameRule; import de.erethon.dungeonsxl.api.mob.ExternalMobProvider; import de.erethon.dungeonsxl.api.world.GameWorld; import java.util.HashSet; @@ -27,6 +28,7 @@ import net.citizensnpcs.api.event.NPCDeathEvent; import net.citizensnpcs.api.npc.AbstractNPC; import net.citizensnpcs.api.npc.NPC; import org.bukkit.Location; +import org.bukkit.World; import org.bukkit.entity.LivingEntity; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -69,6 +71,17 @@ public class CitizensMobProvider implements ExternalMobProvider, Listener { */ public void removeSpawnedNPC(NPC npc) { spawnedNPCs.remove(npc); + npc.destroy(); + } + + public void removeSpawnedNPCs(World world) { + Set worldNPCs = new HashSet<>(); + for (NPC npc : spawnedNPCs) { + if (npc.getStoredLocation().getWorld().equals(world)) { + worldNPCs.add(npc); + } + } + worldNPCs.forEach(this::removeSpawnedNPC); } @Override @@ -93,19 +106,19 @@ public class CitizensMobProvider implements ExternalMobProvider, Listener { return; } - NPC npc = registry.createTransientClone((AbstractNPC) source); + GameWorld gameWorld = DungeonsXL.getInstance().getGameWorld(location.getWorld()); + if (gameWorld == null) { + return; + } + + boolean nativeRegistry = gameWorld.getDungeon().getRules().getState(GameRule.USE_NATIVE_CITIZENS_REGISTRY); + NPC npc = nativeRegistry ? source.clone() : registry.createTransientClone((AbstractNPC) source); if (npc.isSpawned()) { npc.despawn(); } npc.spawn(location); spawnedNPCs.add(npc); - - GameWorld gameWorld = DungeonsXL.getInstance().getGameWorld(location.getWorld()); - if (gameWorld == null) { - return; - } - new DMob((LivingEntity) npc.getEntity(), gameWorld, mob); } diff --git a/core/src/main/java/de/erethon/dungeonsxl/player/DEditPlayer.java b/core/src/main/java/de/erethon/dungeonsxl/player/DEditPlayer.java index e4b2b7d7..5ab86a84 100644 --- a/core/src/main/java/de/erethon/dungeonsxl/player/DEditPlayer.java +++ b/core/src/main/java/de/erethon/dungeonsxl/player/DEditPlayer.java @@ -17,7 +17,6 @@ package de.erethon.dungeonsxl.player; import de.erethon.commons.chat.MessageUtil; -import de.erethon.commons.player.PlayerUtil; import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.api.player.EditPlayer; import de.erethon.dungeonsxl.api.world.EditWorld; diff --git a/core/src/main/java/de/erethon/dungeonsxl/player/DGamePlayer.java b/core/src/main/java/de/erethon/dungeonsxl/player/DGamePlayer.java index 3c74f305..7e06b623 100644 --- a/core/src/main/java/de/erethon/dungeonsxl/player/DGamePlayer.java +++ b/core/src/main/java/de/erethon/dungeonsxl/player/DGamePlayer.java @@ -19,7 +19,6 @@ package de.erethon.dungeonsxl.player; import de.erethon.caliburn.item.VanillaItem; import de.erethon.caliburn.mob.VanillaMob; import de.erethon.commons.chat.MessageUtil; -import de.erethon.commons.player.PlayerUtil; import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.api.Reward; import de.erethon.dungeonsxl.api.dungeon.Game; diff --git a/core/src/main/java/de/erethon/dungeonsxl/player/RespawnTask.java b/core/src/main/java/de/erethon/dungeonsxl/player/RespawnTask.java index 2907c8e3..7bd1d86c 100644 --- a/core/src/main/java/de/erethon/dungeonsxl/player/RespawnTask.java +++ b/core/src/main/java/de/erethon/dungeonsxl/player/RespawnTask.java @@ -16,7 +16,6 @@ */ package de.erethon.dungeonsxl.player; -import de.erethon.commons.player.PlayerUtil; import de.erethon.dungeonsxl.api.player.GamePlayer; import org.bukkit.Location; import org.bukkit.entity.Player; diff --git a/core/src/main/java/de/erethon/dungeonsxl/world/DEditWorld.java b/core/src/main/java/de/erethon/dungeonsxl/world/DEditWorld.java index 8818b794..4ced283a 100644 --- a/core/src/main/java/de/erethon/dungeonsxl/world/DEditWorld.java +++ b/core/src/main/java/de/erethon/dungeonsxl/world/DEditWorld.java @@ -23,6 +23,7 @@ import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.api.event.world.EditWorldSaveEvent; import de.erethon.dungeonsxl.api.event.world.EditWorldUnloadEvent; import de.erethon.dungeonsxl.api.world.EditWorld; +import de.erethon.dungeonsxl.mob.CitizensMobProvider; import de.erethon.dungeonsxl.player.DEditPlayer; import java.io.File; import java.io.IOException; @@ -158,6 +159,10 @@ public class DEditWorld extends DInstanceWorld implements EditWorld { return; } + if (Bukkit.getPluginManager().getPlugin("Citizens") != null) { + ((CitizensMobProvider) plugin.getExternalMobProviderRegistry().get("CI")).removeSpawnedNPCs(getWorld()); + } + kickAllPlayers(); if (save) { diff --git a/core/src/main/java/de/erethon/dungeonsxl/world/DGameWorld.java b/core/src/main/java/de/erethon/dungeonsxl/world/DGameWorld.java index 22c0a21a..498adc01 100644 --- a/core/src/main/java/de/erethon/dungeonsxl/world/DGameWorld.java +++ b/core/src/main/java/de/erethon/dungeonsxl/world/DGameWorld.java @@ -34,6 +34,7 @@ import de.erethon.dungeonsxl.api.mob.DungeonMob; import de.erethon.dungeonsxl.api.player.PlayerGroup; import de.erethon.dungeonsxl.api.sign.DungeonSign; import de.erethon.dungeonsxl.api.world.GameWorld; +import de.erethon.dungeonsxl.mob.CitizensMobProvider; import de.erethon.dungeonsxl.sign.button.ReadySign; import de.erethon.dungeonsxl.sign.passive.StartSign; import de.erethon.dungeonsxl.sign.windup.MobSign; @@ -467,6 +468,10 @@ public class DGameWorld extends DInstanceWorld implements GameWorld { return; } + if (Bukkit.getPluginManager().getPlugin("Citizens") != null) { + ((CitizensMobProvider) plugin.getExternalMobProviderRegistry().get("CI")).removeSpawnedNPCs(getWorld()); + } + kickAllPlayers(); Bukkit.unloadWorld(getWorld(), /* SPIGOT-5225 */ !Version.isAtLeast(Version.MC1_14_4)); diff --git a/core/src/main/java/de/erethon/dungeonsxl/world/DInstanceWorld.java b/core/src/main/java/de/erethon/dungeonsxl/world/DInstanceWorld.java index 8456cd4f..8a6a17a6 100644 --- a/core/src/main/java/de/erethon/dungeonsxl/world/DInstanceWorld.java +++ b/core/src/main/java/de/erethon/dungeonsxl/world/DInstanceWorld.java @@ -17,7 +17,6 @@ package de.erethon.dungeonsxl.world; import de.erethon.commons.chat.MessageUtil; -import de.erethon.commons.player.PlayerUtil; import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.api.DungeonsAPI; import de.erethon.dungeonsxl.api.dungeon.GameRule;