Skip to content

Commit

Permalink
Add new registry API
Browse files Browse the repository at this point in the history
  • Loading branch information
fullwall committed Feb 4, 2021
1 parent 3ea7dda commit 810a673
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/main/java/net/citizensnpcs/api/CitizensAPI.java
Expand Up @@ -34,6 +34,17 @@ public static NPCRegistry createAnonymousNPCRegistry(NPCDataStore store) {
return getImplementation().createAnonymousNPCRegistry(store);
}

/**
* Creates a new <em>anonymous</em> {@link NPCRegistry} that is "Citizens-backed" i.e. will reload and unload at the
* same time that Citizens reloads and unloads.
*
* @param store
* The {@link NPCDataStore} to use with the registry
*/
public static NPCRegistry createCitizensBackedNPCRegistry(NPCDataStore store) {
return getImplementation().createCitizensBackedNPCRegistry(store);
}

/**
* Creates a new {@link NPCRegistry} with its own set of {@link NPC}s. This is stored in memory with the Citizens
* plugin, and can be accessed via {@link #getNamedNPCRegistry(String)}.
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/net/citizensnpcs/api/CitizensPlugin.java
Expand Up @@ -18,6 +18,15 @@ public interface CitizensPlugin extends Plugin {
*/
public NPCRegistry createAnonymousNPCRegistry(NPCDataStore store);

/**
* Creates a new <em>anonymous</em> {@link NPCRegistry} that is "Citizens-backed" i.e. will reload and unload at the
* same time that Citizens reloads and unloads.
*
* @param store
* The {@link NPCDataStore} to use with the registry
*/
public NPCRegistry createCitizensBackedNPCRegistry(NPCDataStore store);

/**
* @param name
* The plugin name
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/net/citizensnpcs/api/npc/NPCRegistry.java
Expand Up @@ -5,6 +5,8 @@
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;

import net.citizensnpcs.api.event.DespawnReason;

/**
* Controls the registration and lookup of a set of {@link NPC}s.
*/
Expand Down Expand Up @@ -47,6 +49,14 @@ public interface NPCRegistry extends Iterable<NPC> {
*/
public void deregisterAll();

/**
* Despawn all NPCs within the registry.
*
* @param reload
* The reason to despawn
*/
public void despawnNPCs(DespawnReason reason);

/**
* Gets the {@link NPC} with the given ID if it exists.
*
Expand Down Expand Up @@ -97,6 +107,11 @@ public interface NPCRegistry extends Iterable<NPC> {
*/
public boolean isNPC(Entity entity);

/**
* Saves the NPCs to the internal {@link NPCDataStore}
*/
public void saveToStore();

/**
* Returns a <em>sorted</em> view of this registry, sorted by NPC id.
*
Expand Down

0 comments on commit 810a673

Please sign in to comment.