make npc move command work across worlds

This commit is contained in:
Pyrbu 2023-12-14 12:00:14 +01:00
parent f933f17e45
commit 993127ed85
2 changed files with 7 additions and 1 deletions

@ -27,6 +27,7 @@ public class MoveCommand implements CommandHandler {
Player player = context.ensureSenderIsPlayer(); Player player = context.ensureSenderIsPlayer();
NpcImpl npc = context.parse(NpcEntryImpl.class).getNpc(); NpcImpl npc = context.parse(NpcEntryImpl.class).getNpc();
npc.setLocation(new NpcLocation(player.getLocation())); npc.setLocation(new NpcLocation(player.getLocation()));
if (!npc.getWorld().equals(player.getWorld())) npc.setWorld(player.getWorld());
context.send(Component.text("NPC moved to your current location.", NamedTextColor.GREEN)); context.send(Component.text("NPC moved to your current location.", NamedTextColor.GREEN));
} }

@ -24,7 +24,7 @@ import java.util.stream.Collectors;
public class NpcImpl extends Viewable implements Npc { public class NpcImpl extends Viewable implements Npc {
private final PacketFactory packetFactory; private final PacketFactory packetFactory;
private final String worldName; private String worldName;
private PacketEntity entity; private PacketEntity entity;
private NpcLocation location; private NpcLocation location;
private NpcTypeImpl type; private NpcTypeImpl type;
@ -196,4 +196,9 @@ public class NpcImpl extends Viewable implements Npc {
public int getPacketEntityId() { public int getPacketEntityId() {
return entity.getEntityId(); return entity.getEntityId();
} }
public void setWorld(World world) {
delete();
this.worldName = world.getName();
}
} }