mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2025-01-29 19:41:50 +01:00
Using /npc despawn now removes from the respawn list
This commit is contained in:
parent
c10a41b395
commit
5f093276f1
@ -18,6 +18,7 @@ import net.citizensnpcs.api.command.Injector;
|
||||
import net.citizensnpcs.api.event.CitizensDisableEvent;
|
||||
import net.citizensnpcs.api.event.CitizensEnableEvent;
|
||||
import net.citizensnpcs.api.event.CitizensReloadEvent;
|
||||
import net.citizensnpcs.api.event.DespawnReason;
|
||||
import net.citizensnpcs.api.exception.NPCLoadException;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.api.npc.NPCDataStore;
|
||||
@ -114,7 +115,7 @@ public class Citizens extends JavaPlugin implements CitizensPlugin {
|
||||
while (itr.hasNext()) {
|
||||
NPC npc = itr.next();
|
||||
try {
|
||||
npc.despawn();
|
||||
npc.despawn(DespawnReason.REMOVAL);
|
||||
for (Trait trait : npc.getTraits())
|
||||
trait.onRemove();
|
||||
} catch (Throwable e) {
|
||||
|
@ -14,6 +14,7 @@ import net.citizensnpcs.api.event.NPCDamageByBlockEvent;
|
||||
import net.citizensnpcs.api.event.NPCDamageByEntityEvent;
|
||||
import net.citizensnpcs.api.event.NPCDamageEvent;
|
||||
import net.citizensnpcs.api.event.NPCDeathEvent;
|
||||
import net.citizensnpcs.api.event.NPCDespawnEvent;
|
||||
import net.citizensnpcs.api.event.NPCLeftClickEvent;
|
||||
import net.citizensnpcs.api.event.NPCRightClickEvent;
|
||||
import net.citizensnpcs.api.event.PlayerCreateNPCEvent;
|
||||
@ -179,6 +180,12 @@ public class EventListen implements Listener {
|
||||
toRespawn.put(toCoord(event.getSpawnLocation()), event.getNPC());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onNPCDespawn(NPCDespawnEvent event) {
|
||||
if (event.getReason() == DespawnReason.PLUGIN || event.getReason() == DespawnReason.REMOVAL)
|
||||
toRespawn.remove(toCoord(event.getNPC().getBukkitEntity().getLocation()), event.getNPC());
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onPlayerChangedWorld(PlayerChangedWorldEvent event) {
|
||||
if (!(event.getPlayer() instanceof NPCHolder))
|
||||
|
@ -16,6 +16,7 @@ import net.citizensnpcs.api.command.exception.CommandException;
|
||||
import net.citizensnpcs.api.command.exception.NoPermissionsException;
|
||||
import net.citizensnpcs.api.command.exception.ServerCommandException;
|
||||
import net.citizensnpcs.api.event.CommandSenderCreateNPCEvent;
|
||||
import net.citizensnpcs.api.event.DespawnReason;
|
||||
import net.citizensnpcs.api.event.PlayerCreateNPCEvent;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.api.npc.NPCRegistry;
|
||||
@ -444,7 +445,7 @@ public class NPCCommands {
|
||||
throw new CommandException(Messages.NO_NPC_WITH_ID_FOUND, id);
|
||||
}
|
||||
npc.getTrait(Spawned.class).setSpawned(false);
|
||||
npc.despawn();
|
||||
npc.despawn(DespawnReason.REMOVAL);
|
||||
Messaging.sendTr(sender, Messages.NPC_DESPAWNED, npc.getName());
|
||||
}
|
||||
|
||||
@ -851,7 +852,7 @@ public class NPCCommands {
|
||||
newName = newName.substring(0, 15);
|
||||
}
|
||||
Location prev = npc.isSpawned() ? npc.getBukkitEntity().getLocation() : null;
|
||||
npc.despawn();
|
||||
npc.despawn(DespawnReason.PENDING_RESPAWN);
|
||||
npc.setName(newName);
|
||||
if (prev != null)
|
||||
npc.spawn(prev);
|
||||
@ -1059,13 +1060,13 @@ public class NPCCommands {
|
||||
npc.spawn(args.getSenderLocation());
|
||||
if (!sender.hasPermission("citizens.npc.tphere.multiworld")
|
||||
&& npc.getBukkitEntity().getLocation().getWorld() != args.getSenderLocation().getWorld()) {
|
||||
npc.despawn();
|
||||
npc.despawn(DespawnReason.REMOVAL);
|
||||
throw new CommandException(Messages.CANNOT_TELEPORT_ACROSS_WORLDS);
|
||||
}
|
||||
} else {
|
||||
if (!sender.hasPermission("citizens.npc.tphere.multiworld")
|
||||
&& npc.getBukkitEntity().getLocation().getWorld() != args.getSenderLocation().getWorld()) {
|
||||
npc.despawn();
|
||||
npc.despawn(DespawnReason.REMOVAL);
|
||||
throw new CommandException(Messages.CANNOT_TELEPORT_ACROSS_WORLDS);
|
||||
}
|
||||
npc.getBukkitEntity().teleport(args.getSenderLocation(), TeleportCause.COMMAND);
|
||||
|
@ -152,7 +152,7 @@ public class CitizensNPC extends AbstractNPC {
|
||||
Location prev = null;
|
||||
if (wasSpawned) {
|
||||
prev = getBukkitEntity().getLocation();
|
||||
despawn();
|
||||
despawn(DespawnReason.PENDING_RESPAWN);
|
||||
}
|
||||
entityController = newController;
|
||||
if (wasSpawned)
|
||||
|
@ -2,6 +2,7 @@ package net.citizensnpcs.npc;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import net.citizensnpcs.api.event.DespawnReason;
|
||||
import net.citizensnpcs.api.event.NPCCreateEvent;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.api.npc.NPCDataStore;
|
||||
@ -48,7 +49,7 @@ public class CitizensNPCRegistry implements NPCRegistry {
|
||||
npcs.remove(npc.getId());
|
||||
if (saves != null)
|
||||
saves.clearData(npc);
|
||||
npc.despawn();
|
||||
npc.despawn(DespawnReason.REMOVAL);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -57,7 +58,7 @@ public class CitizensNPCRegistry implements NPCRegistry {
|
||||
while (itr.hasNext()) {
|
||||
NPC npc = itr.next();
|
||||
itr.remove();
|
||||
npc.despawn();
|
||||
npc.despawn(DespawnReason.REMOVAL);
|
||||
for (Trait t : npc.getTraits())
|
||||
t.onRemove();
|
||||
if (saves != null)
|
||||
|
Loading…
Reference in New Issue
Block a user