mirror of
https://github.com/DRE2N/DungeonsXL.git
synced 2024-11-24 11:37:05 +01:00
Add useNativeCitizensRegistry game rule
This commit is contained in:
parent
3ee64194fc
commit
cae69090be
@ -355,6 +355,10 @@ public class GameRule<V> {
|
||||
* If group tags are used.
|
||||
*/
|
||||
public static final GameRule<Boolean> GROUP_TAG_ENABLED = new GameRule<>(Boolean.class, "groupTagEnabled", false);
|
||||
/**
|
||||
* If Citizens NPCs should be copied to the native registry.
|
||||
*/
|
||||
public static final GameRule<Boolean> USE_NATIVE_CITIZENS_REGISTRY = new GameRule<>(Boolean.class, "useNativeCitizensRegistry", false);
|
||||
|
||||
/**
|
||||
* An array of all game rules that exist natively in DungeonsXL.
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
@ -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<NPC> 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);
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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) {
|
||||
|
@ -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));
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user