2021-06-26 19:43:58 -05:00
|
|
|
package net.nuggetmc.ai.npc;
|
|
|
|
|
|
|
|
|
|
import net.minecraft.server.v1_16_R3.PlayerConnection;
|
|
|
|
|
import net.nuggetmc.ai.PlayerAI;
|
|
|
|
|
import org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer;
|
|
|
|
|
import org.bukkit.event.EventHandler;
|
|
|
|
|
import org.bukkit.event.Listener;
|
|
|
|
|
import org.bukkit.event.player.PlayerJoinEvent;
|
|
|
|
|
|
|
|
|
|
import java.util.HashSet;
|
|
|
|
|
import java.util.Set;
|
|
|
|
|
|
|
|
|
|
public class NPCManager implements Listener {
|
|
|
|
|
|
2021-06-26 19:26:46 -07:00
|
|
|
private final PlayerAI plugin;
|
2021-06-26 19:43:58 -05:00
|
|
|
|
2021-06-26 20:00:57 -05:00
|
|
|
private final Set<NPC> npcs = new HashSet<>();
|
2021-06-26 19:43:58 -05:00
|
|
|
|
|
|
|
|
public Set<NPC> fetch() {
|
2021-06-26 20:00:57 -05:00
|
|
|
return npcs;
|
2021-06-26 19:43:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void add(NPC npc) {
|
2021-06-26 20:00:57 -05:00
|
|
|
npcs.add(npc);
|
2021-06-26 19:43:58 -05:00
|
|
|
}
|
|
|
|
|
|
2021-06-26 19:26:46 -07:00
|
|
|
public NPCManager(PlayerAI plugin) {
|
|
|
|
|
this.plugin = plugin;
|
2021-06-26 19:43:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void reset() {
|
2021-06-26 20:00:57 -05:00
|
|
|
for (NPC npc : npcs) {
|
2021-06-26 19:43:58 -05:00
|
|
|
npc.despawn();
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-26 20:00:57 -05:00
|
|
|
npcs.clear();
|
2021-06-26 19:43:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@EventHandler
|
|
|
|
|
public void onJoin(PlayerJoinEvent event) {
|
|
|
|
|
PlayerConnection connection = ((CraftPlayer) event.getPlayer()).getHandle().playerConnection;
|
|
|
|
|
|
2021-06-26 20:00:57 -05:00
|
|
|
for (NPC npc : npcs) {
|
2021-06-26 19:43:58 -05:00
|
|
|
npc.render(connection, true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|