Check for online players in /npc remove --owner

This commit is contained in:
fullwall 2022-07-08 22:15:48 +08:00
parent 98c2d3492a
commit 665e19d472

View File

@ -1838,8 +1838,12 @@ public class NPCCommands {
public void remove(final CommandContext args, final CommandSender sender, NPC npc) throws CommandException {
if (args.hasValueFlag("owner")) {
String owner = args.getFlag("owner");
Player playerOwner = Bukkit.getPlayerExact(owner);
for (NPC rem : Lists.newArrayList(CitizensAPI.getNPCRegistry())) {
if (rem.getOrAddTrait(Owner.class).isOwnedBy(owner)) {
if (playerOwner != null && rem.getOrAddTrait(Owner.class).isOwnedBy(playerOwner)) {
history.add(sender, new RemoveNPCHistoryItem(rem));
rem.destroy(sender);
} else if (rem.getOrAddTrait(Owner.class).isOwnedBy(owner)) {
history.add(sender, new RemoveNPCHistoryItem(rem));
rem.destroy(sender);
}