mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2025-01-12 19:30:50 +01:00
properly remove NPC
This commit is contained in:
parent
e5ee5d6dd1
commit
fbf4741ada
@ -32,19 +32,12 @@ import org.bukkit.permissions.PermissionDefault;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public class Citizens extends JavaPlugin {
|
||||
private static final CitizensNPCManager npcManager = new CitizensNPCManager();
|
||||
private static CitizensNPCManager npcManager;
|
||||
private static final InstanceFactory<Character> characterManager = DefaultInstanceFactory.create();
|
||||
private static final InstanceFactory<Trait> traitManager = DefaultInstanceFactory.create();
|
||||
private Settings config;
|
||||
private Storage saves;
|
||||
|
||||
public Citizens() {
|
||||
// Register API managers
|
||||
CitizensAPI.setNPCManager(npcManager);
|
||||
CitizensAPI.setCharacterManager(characterManager);
|
||||
CitizensAPI.setTraitManager(traitManager);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String cmdName, String[] args) {
|
||||
if (args[0].equals("spawn")) {
|
||||
@ -53,7 +46,7 @@ public class Citizens extends JavaPlugin {
|
||||
((CitizensNPC) npc).save(saves);
|
||||
} else if (args[0].equals("despawn")) {
|
||||
for (NPC npc : npcManager.getSpawnedNPCs())
|
||||
npc.despawn();
|
||||
npc.remove();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -79,6 +72,12 @@ public class Citizens extends JavaPlugin {
|
||||
else
|
||||
saves = new YamlStorage(getDataFolder() + File.separator + "saves.yml");
|
||||
|
||||
// Register API managers
|
||||
npcManager = new CitizensNPCManager(saves);
|
||||
CitizensAPI.setNPCManager(npcManager);
|
||||
CitizensAPI.setCharacterManager(characterManager);
|
||||
CitizensAPI.setTraitManager(traitManager);
|
||||
|
||||
// Register events
|
||||
getServer().getPluginManager().registerEvents(new EventListen(npcManager), this);
|
||||
|
||||
|
@ -13,6 +13,7 @@ import net.citizensnpcs.api.npc.trait.Character;
|
||||
import net.citizensnpcs.api.npc.trait.Trait;
|
||||
import net.citizensnpcs.api.npc.trait.trait.SpawnLocation;
|
||||
import net.citizensnpcs.resources.lib.CraftNPC;
|
||||
import net.citizensnpcs.storage.Storage;
|
||||
import net.citizensnpcs.util.ByIdArray;
|
||||
|
||||
import net.minecraft.server.ItemInWorldManager;
|
||||
@ -34,6 +35,11 @@ public class CitizensNPCManager implements NPCManager {
|
||||
private final ByIdArray<NPC> spawned = new ByIdArray<NPC>();
|
||||
private final ByIdArray<NPC> byID = new ByIdArray<NPC>();
|
||||
private final Map<String, Integer> selected = new ConcurrentHashMap<String, Integer>();
|
||||
private final Storage saves;
|
||||
|
||||
public CitizensNPCManager(Storage saves) {
|
||||
this.saves = saves;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NPC createNPC(String name) {
|
||||
@ -117,6 +123,7 @@ public class CitizensNPCManager implements NPCManager {
|
||||
if (spawned.contains(npc.getBukkitEntity().getEntityId()))
|
||||
despawn(npc);
|
||||
byID.remove(npc.getId());
|
||||
saves.getKey("npc").removeKey("" + npc.getId());
|
||||
}
|
||||
|
||||
public CraftNPC spawn(NPC npc, Location loc) {
|
||||
|
@ -210,6 +210,7 @@ public class YamlStorage implements Storage {
|
||||
@Override
|
||||
public void removeKey(String key) {
|
||||
config.set(getKeyExt(key), null);
|
||||
save();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user