mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2025-01-09 01:47:38 +01:00
WIP fix for NPCs not despawning properly
This commit is contained in:
parent
2b19473832
commit
d04ea81225
@ -74,7 +74,7 @@ public class NPCCommandSelector extends NumericPrompt {
|
||||
public String getPromptText(ConversationContext context) {
|
||||
String text = Messaging.tr(Messages.SELECTION_PROMPT);
|
||||
for (NPC npc : choices) {
|
||||
text += "\n - " + npc.getId();
|
||||
text += "<br> - " + npc.getId();
|
||||
}
|
||||
Messaging.send((CommandSender) context.getForWhom(), text);
|
||||
return "";
|
||||
|
@ -2,8 +2,10 @@ package net.citizensnpcs.npc;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.npc.skin.SkinnableEntity;
|
||||
import net.citizensnpcs.util.NMS;
|
||||
|
||||
public abstract class AbstractEntityController implements EntityController {
|
||||
@ -27,8 +29,16 @@ public abstract class AbstractEntityController implements EntityController {
|
||||
public void remove() {
|
||||
if (bukkitEntity == null)
|
||||
return;
|
||||
bukkitEntity.remove();
|
||||
bukkitEntity = null;
|
||||
if (bukkitEntity instanceof Player) {
|
||||
NMS.removeFromWorld(bukkitEntity);
|
||||
SkinnableEntity npc = bukkitEntity instanceof SkinnableEntity ? (SkinnableEntity) bukkitEntity : null;
|
||||
npc.getSkinTracker().onRemoveNPC();
|
||||
NMS.remove(bukkitEntity);
|
||||
setEntity(null);
|
||||
} else {
|
||||
bukkitEntity.remove();
|
||||
bukkitEntity = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -70,7 +70,7 @@ public class CitizensNPC extends AbstractNPC {
|
||||
|
||||
@Override
|
||||
public boolean despawn(DespawnReason reason) {
|
||||
if (!isSpawned() && reason != DespawnReason.DEATH) {
|
||||
if (getEntity() == null && reason != DespawnReason.DEATH) {
|
||||
Messaging.debug("Tried to despawn", this, "while already despawned, DespawnReason." + reason);
|
||||
if (reason == DespawnReason.RELOAD) {
|
||||
unloadEvents();
|
||||
|
@ -89,8 +89,7 @@ public class NPCSelector implements Listener, net.citizensnpcs.api.npc.NPCSelect
|
||||
removeMetadata(block);
|
||||
}
|
||||
} else {
|
||||
Player search = Bukkit.getPlayerExact(value);
|
||||
removeMetadata(search);
|
||||
removeMetadata(Bukkit.getPlayer(UUID.fromString(value)));
|
||||
}
|
||||
}
|
||||
npc.data().remove("selectors");
|
||||
@ -128,7 +127,7 @@ public class NPCSelector implements Listener, net.citizensnpcs.api.npc.NPCSelect
|
||||
if (sender instanceof Player) {
|
||||
Player player = (Player) sender;
|
||||
setMetadata(npc, player);
|
||||
selectors.add(sender.getName());
|
||||
selectors.add(player.getUniqueId().toString());
|
||||
|
||||
// Remove editor if the player has one
|
||||
Editor.leave(player);
|
||||
|
@ -15,7 +15,6 @@ import net.citizensnpcs.api.CitizensAPI;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.npc.AbstractEntityController;
|
||||
import net.citizensnpcs.npc.skin.Skin;
|
||||
import net.citizensnpcs.npc.skin.SkinnableEntity;
|
||||
import net.citizensnpcs.trait.ScoreboardTrait;
|
||||
import net.citizensnpcs.util.NMS;
|
||||
import net.citizensnpcs.util.Util;
|
||||
@ -81,15 +80,4 @@ public class HumanController extends AbstractEntityController {
|
||||
public Player getBukkitEntity() {
|
||||
return (Player) super.getBukkitEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove() {
|
||||
Player entity = getBukkitEntity();
|
||||
if (entity != null) {
|
||||
NMS.removeFromWorld(entity);
|
||||
SkinnableEntity npc = entity instanceof SkinnableEntity ? (SkinnableEntity) entity : null;
|
||||
npc.getSkinTracker().onRemoveNPC();
|
||||
}
|
||||
super.remove();
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,6 @@ import net.citizensnpcs.api.CitizensAPI;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.npc.AbstractEntityController;
|
||||
import net.citizensnpcs.npc.skin.Skin;
|
||||
import net.citizensnpcs.npc.skin.SkinnableEntity;
|
||||
import net.citizensnpcs.trait.ScoreboardTrait;
|
||||
import net.citizensnpcs.util.NMS;
|
||||
import net.citizensnpcs.util.Util;
|
||||
@ -81,15 +80,4 @@ public class HumanController extends AbstractEntityController {
|
||||
public Player getBukkitEntity() {
|
||||
return (Player) super.getBukkitEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove() {
|
||||
Player entity = getBukkitEntity();
|
||||
if (entity != null) {
|
||||
NMS.removeFromWorld(entity);
|
||||
SkinnableEntity npc = entity instanceof SkinnableEntity ? (SkinnableEntity) entity : null;
|
||||
npc.getSkinTracker().onRemoveNPC();
|
||||
}
|
||||
super.remove();
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,6 @@ import net.citizensnpcs.api.CitizensAPI;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.npc.AbstractEntityController;
|
||||
import net.citizensnpcs.npc.skin.Skin;
|
||||
import net.citizensnpcs.npc.skin.SkinnableEntity;
|
||||
import net.citizensnpcs.trait.ScoreboardTrait;
|
||||
import net.citizensnpcs.util.NMS;
|
||||
import net.citizensnpcs.util.Util;
|
||||
@ -81,15 +80,4 @@ public class HumanController extends AbstractEntityController {
|
||||
public Player getBukkitEntity() {
|
||||
return (Player) super.getBukkitEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove() {
|
||||
Player entity = getBukkitEntity();
|
||||
if (entity != null) {
|
||||
NMS.removeFromWorld(entity);
|
||||
SkinnableEntity npc = entity instanceof SkinnableEntity ? (SkinnableEntity) entity : null;
|
||||
npc.getSkinTracker().onRemoveNPC();
|
||||
}
|
||||
super.remove();
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,6 @@ import net.citizensnpcs.api.CitizensAPI;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.npc.AbstractEntityController;
|
||||
import net.citizensnpcs.npc.skin.Skin;
|
||||
import net.citizensnpcs.npc.skin.SkinnableEntity;
|
||||
import net.citizensnpcs.trait.ScoreboardTrait;
|
||||
import net.citizensnpcs.util.NMS;
|
||||
import net.citizensnpcs.util.Util;
|
||||
@ -81,16 +80,4 @@ public class HumanController extends AbstractEntityController {
|
||||
public Player getBukkitEntity() {
|
||||
return (Player) super.getBukkitEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove() {
|
||||
Player entity = getBukkitEntity();
|
||||
if (entity != null) {
|
||||
NMS.removeFromWorld(entity);
|
||||
SkinnableEntity npc = entity instanceof SkinnableEntity ? (SkinnableEntity) entity : null;
|
||||
npc.getSkinTracker().onRemoveNPC();
|
||||
}
|
||||
NMS.remove(entity);
|
||||
setEntity(null);
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,6 @@ import net.citizensnpcs.api.CitizensAPI;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.npc.AbstractEntityController;
|
||||
import net.citizensnpcs.npc.skin.Skin;
|
||||
import net.citizensnpcs.npc.skin.SkinnableEntity;
|
||||
import net.citizensnpcs.trait.ScoreboardTrait;
|
||||
import net.citizensnpcs.util.NMS;
|
||||
import net.citizensnpcs.util.Util;
|
||||
@ -81,16 +80,4 @@ public class HumanController extends AbstractEntityController {
|
||||
public Player getBukkitEntity() {
|
||||
return (Player) super.getBukkitEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove() {
|
||||
Player entity = getBukkitEntity();
|
||||
if (entity != null) {
|
||||
NMS.removeFromWorld(entity);
|
||||
SkinnableEntity npc = entity instanceof SkinnableEntity ? (SkinnableEntity) entity : null;
|
||||
npc.getSkinTracker().onRemoveNPC();
|
||||
}
|
||||
NMS.remove(entity);
|
||||
setEntity(null);
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,6 @@ import net.citizensnpcs.api.CitizensAPI;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.npc.AbstractEntityController;
|
||||
import net.citizensnpcs.npc.skin.Skin;
|
||||
import net.citizensnpcs.npc.skin.SkinnableEntity;
|
||||
import net.citizensnpcs.trait.ScoreboardTrait;
|
||||
import net.citizensnpcs.util.NMS;
|
||||
import net.citizensnpcs.util.Util;
|
||||
@ -81,16 +80,4 @@ public class HumanController extends AbstractEntityController {
|
||||
public Player getBukkitEntity() {
|
||||
return (Player) super.getBukkitEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove() {
|
||||
Player entity = getBukkitEntity();
|
||||
if (entity != null) {
|
||||
NMS.removeFromWorld(entity);
|
||||
SkinnableEntity npc = entity instanceof SkinnableEntity ? (SkinnableEntity) entity : null;
|
||||
npc.getSkinTracker().onRemoveNPC();
|
||||
}
|
||||
NMS.remove(entity);
|
||||
setEntity(null);
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,6 @@ import net.citizensnpcs.api.CitizensAPI;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.npc.AbstractEntityController;
|
||||
import net.citizensnpcs.npc.skin.Skin;
|
||||
import net.citizensnpcs.npc.skin.SkinnableEntity;
|
||||
import net.citizensnpcs.trait.ScoreboardTrait;
|
||||
import net.citizensnpcs.util.NMS;
|
||||
import net.citizensnpcs.util.Util;
|
||||
@ -80,16 +79,4 @@ public class HumanController extends AbstractEntityController {
|
||||
public Player getBukkitEntity() {
|
||||
return (Player) super.getBukkitEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove() {
|
||||
Player entity = getBukkitEntity();
|
||||
if (entity != null) {
|
||||
NMS.removeFromWorld(entity);
|
||||
SkinnableEntity npc = entity instanceof SkinnableEntity ? (SkinnableEntity) entity : null;
|
||||
npc.getSkinTracker().onRemoveNPC();
|
||||
}
|
||||
NMS.remove(entity);
|
||||
setEntity(null);
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,6 @@ import net.citizensnpcs.api.CitizensAPI;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.npc.AbstractEntityController;
|
||||
import net.citizensnpcs.npc.skin.Skin;
|
||||
import net.citizensnpcs.npc.skin.SkinnableEntity;
|
||||
import net.citizensnpcs.trait.ScoreboardTrait;
|
||||
import net.citizensnpcs.util.NMS;
|
||||
import net.citizensnpcs.util.Util;
|
||||
@ -78,16 +77,4 @@ public class HumanController extends AbstractEntityController {
|
||||
public Player getBukkitEntity() {
|
||||
return (Player) super.getBukkitEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove() {
|
||||
Player entity = getBukkitEntity();
|
||||
if (entity != null) {
|
||||
NMS.removeFromWorld(entity);
|
||||
SkinnableEntity npc = entity instanceof SkinnableEntity ? (SkinnableEntity) entity : null;
|
||||
npc.getSkinTracker().onRemoveNPC();
|
||||
}
|
||||
NMS.remove(entity);
|
||||
setEntity(null);
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,6 @@ import net.citizensnpcs.api.CitizensAPI;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.npc.AbstractEntityController;
|
||||
import net.citizensnpcs.npc.skin.Skin;
|
||||
import net.citizensnpcs.npc.skin.SkinnableEntity;
|
||||
import net.citizensnpcs.trait.ScoreboardTrait;
|
||||
import net.citizensnpcs.util.NMS;
|
||||
import net.citizensnpcs.util.Util;
|
||||
@ -78,16 +77,4 @@ public class HumanController extends AbstractEntityController {
|
||||
public Player getBukkitEntity() {
|
||||
return (Player) super.getBukkitEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove() {
|
||||
Player entity = getBukkitEntity();
|
||||
if (entity != null) {
|
||||
NMS.removeFromWorld(entity);
|
||||
SkinnableEntity npc = entity instanceof SkinnableEntity ? (SkinnableEntity) entity : null;
|
||||
npc.getSkinTracker().onRemoveNPC();
|
||||
}
|
||||
NMS.remove(entity);
|
||||
setEntity(null);
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,6 @@ import net.citizensnpcs.api.CitizensAPI;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.npc.AbstractEntityController;
|
||||
import net.citizensnpcs.npc.skin.Skin;
|
||||
import net.citizensnpcs.npc.skin.SkinnableEntity;
|
||||
import net.citizensnpcs.trait.ScoreboardTrait;
|
||||
import net.citizensnpcs.util.NMS;
|
||||
import net.citizensnpcs.util.Util;
|
||||
@ -77,16 +76,4 @@ public class HumanController extends AbstractEntityController {
|
||||
public Player getBukkitEntity() {
|
||||
return (Player) super.getBukkitEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove() {
|
||||
Player entity = getBukkitEntity();
|
||||
if (entity != null) {
|
||||
NMS.removeFromWorld(entity);
|
||||
SkinnableEntity npc = entity instanceof SkinnableEntity ? (SkinnableEntity) entity : null;
|
||||
npc.getSkinTracker().onRemoveNPC();
|
||||
}
|
||||
NMS.remove(entity);
|
||||
setEntity(null);
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,6 @@ import net.citizensnpcs.api.CitizensAPI;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.npc.AbstractEntityController;
|
||||
import net.citizensnpcs.npc.skin.Skin;
|
||||
import net.citizensnpcs.npc.skin.SkinnableEntity;
|
||||
import net.citizensnpcs.trait.ScoreboardTrait;
|
||||
import net.citizensnpcs.util.NMS;
|
||||
import net.citizensnpcs.util.Util;
|
||||
@ -81,15 +80,4 @@ public class HumanController extends AbstractEntityController {
|
||||
public Player getBukkitEntity() {
|
||||
return (Player) super.getBukkitEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove() {
|
||||
Player entity = getBukkitEntity();
|
||||
if (entity != null) {
|
||||
NMS.removeFromWorld(entity);
|
||||
SkinnableEntity npc = entity instanceof SkinnableEntity ? (SkinnableEntity) entity : null;
|
||||
npc.getSkinTracker().onRemoveNPC();
|
||||
}
|
||||
super.remove();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user