Skip to content

Commit

Permalink
Added onRegister and onRemove master functions to registries
Browse files Browse the repository at this point in the history
  • Loading branch information
WillFP committed May 11, 2024
1 parent f71fa64 commit d99121a
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions eco-api/src/main/java/com/willfp/eco/core/registry/Registry.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public T register(@NotNull final T element) {
registry.put(element.getID(), element);

element.onRegister();
onRegister(element);

return element;
}
Expand All @@ -78,6 +79,7 @@ public T remove(@NotNull final T element) {
}

element.onRemove();
onRemove(element);

registry.remove(element.getID());

Expand All @@ -99,10 +101,10 @@ public T remove(@NotNull final String id) {
T element = registry.get(id);

if (element != null) {
element.onRemove();
return remove(element);
}

return registry.remove(id);
return null;
}

/**
Expand Down Expand Up @@ -171,6 +173,24 @@ public void unlock(@Nullable final Object locker) {
isLocked = false;
}

/**
* Run when an element is registered.
*
* @param element The element.
*/
protected void onRegister(@NotNull final T element) {
// Override this method to do something when an element is registered.
}

/**
* Run when an element is removed.
*
* @param element The element.
*/
protected void onRemove(@NotNull final T element) {
// Override this method to do something when an element is removed.
}

/**
* Get if the registry is empty.
*
Expand Down

0 comments on commit d99121a

Please sign in to comment.