Started thinking about the implemtation of #11

This commit is contained in:
Jitse Boonstra
2019-10-21 09:49:23 +02:00
parent 6d5895870b
commit 4d2140d24c
24 changed files with 377 additions and 254 deletions
@@ -22,15 +22,13 @@ import org.bukkit.util.Vector;
import java.util.*;
public abstract class SimpleNPC implements NPC, PacketHandler {
public abstract class NPCBase implements NPC, NPCPacketHandler {
protected final UUID uuid = UUID.randomUUID();
protected final int entityId = Integer.MAX_VALUE - NPCManager.getAllNPCs().size();
protected final String name = uuid.toString().replace("-", "").substring(0, 10);
protected final GameProfile gameProfile = new GameProfile(uuid, name);
protected final List<String> lines;
private final Set<UUID> shown = new HashSet<>();
private final Set<UUID> autoHidden = new HashSet<>();
@@ -38,15 +36,16 @@ public abstract class SimpleNPC implements NPC, PacketHandler {
protected NPCState[] activeStates = new NPCState[]{};
protected NPCLib instance;
protected List<String> text;
protected Location location;
protected Skin skin;
// offHand support in 1.9 R1 and later.
protected ItemStack helmet, chestplate, leggings, boots, inHand, offHand;
public SimpleNPC(NPCLib instance, List<String> lines) {
public NPCBase(NPCLib instance, List<String> text) {
this.instance = instance;
this.lines = lines == null ? Collections.emptyList() : lines;
this.text = text == null ? Collections.emptyList() : text;
NPCManager.add(this);
}
@@ -299,4 +298,16 @@ public abstract class SimpleNPC implements NPC, PacketHandler {
}
return this;
}
@Override
public NPC setText(List<String> text) {
for (UUID shownUuid : shown) {
Player player = Bukkit.getPlayer(shownUuid);
if (player != null && isShown(player)) {
sendTextUpdatePackets(this.text, text, player);
}
}
this.text = text;
return this;
}
}
@@ -12,17 +12,17 @@ import java.util.Set;
*/
public final class NPCManager {
private static Set<SimpleNPC> npcs = new HashSet<>();
private static Set<NPCBase> npcs = new HashSet<>();
public static Set<SimpleNPC> getAllNPCs() {
public static Set<NPCBase> getAllNPCs() {
return npcs;
}
public static void add(SimpleNPC npc) {
public static void add(NPCBase npc) {
npcs.add(npc);
}
public static void remove(SimpleNPC npc) {
public static void remove(NPCBase npc) {
npcs.remove(npc);
}
@@ -10,7 +10,7 @@ import org.bukkit.entity.Player;
/**
* @author Jitse Boonstra
*/
interface PacketHandler {
interface NPCPacketHandler {
void createPackets();