Files
Tplus/src/main/java/net/nuggetmc/ai/npc/NPCManager.java

49 lines
1.0 KiB
Java
Raw Normal View History

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 {
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
}
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);
}
}
}