From 6ea59a99bad71e2e2ffedef135e93be88f245436 Mon Sep 17 00:00:00 2001 From: Silent Date: Fri, 18 Feb 2022 01:58:14 +0100 Subject: [PATCH] hotfix --- pom.xml | 2 +- .../tsp/headdb/database/HeadDatabase.java | 2 + .../tsp/headdb/event/DatabaseUpdateEvent.java | 54 +++++++++++++++++++ 3 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 src/main/java/tsp/headdb/event/DatabaseUpdateEvent.java diff --git a/pom.xml b/pom.xml index 163d046..4481470 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ tsp.headdb HeadDB - 3.2.2 + 3.2.4 jar HeadDB diff --git a/src/main/java/tsp/headdb/database/HeadDatabase.java b/src/main/java/tsp/headdb/database/HeadDatabase.java index e6a2c15..03b388f 100644 --- a/src/main/java/tsp/headdb/database/HeadDatabase.java +++ b/src/main/java/tsp/headdb/database/HeadDatabase.java @@ -8,6 +8,7 @@ import org.json.simple.JSONObject; import org.json.simple.parser.JSONParser; import org.json.simple.parser.ParseException; import tsp.headdb.api.Head; +import tsp.headdb.event.DatabaseUpdateEvent; import tsp.headdb.util.Log; import tsp.headdb.util.Utils; @@ -217,6 +218,7 @@ public class HeadDatabase { HEADS.clear(); HEADS.putAll(heads); result.accept(heads); + Bukkit.getPluginManager().callEvent(new DatabaseUpdateEvent(this, heads)); })); } diff --git a/src/main/java/tsp/headdb/event/DatabaseUpdateEvent.java b/src/main/java/tsp/headdb/event/DatabaseUpdateEvent.java new file mode 100644 index 0000000..b25b02f --- /dev/null +++ b/src/main/java/tsp/headdb/event/DatabaseUpdateEvent.java @@ -0,0 +1,54 @@ +package tsp.headdb.event; + +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; +import tsp.headdb.api.Head; +import tsp.headdb.database.Category; +import tsp.headdb.database.HeadDatabase; + +import java.util.List; +import java.util.Map; + +/** + * This event is called AFTER a {@link tsp.headdb.database.HeadDatabase} updates. + * The event is called asynchronously and can not be cancelled. + * + * @author TheSilentPro + */ +public class DatabaseUpdateEvent extends Event { + + private final HandlerList handlerList = new HandlerList(); + private final HeadDatabase database; + private final Map> heads; + + public DatabaseUpdateEvent(HeadDatabase database, Map> heads) { + super(true); + + this.database = database; + this.heads = heads; + } + + /** + * Retrieve the {@link HeadDatabase} associated with this event + * + * @return The database + */ + public HeadDatabase getDatabase() { + return database; + } + + /** + * Retrieve the result of the update + * + * @return The heads fetched from the update + */ + public Map> getHeads() { + return heads; + } + + @Override + public HandlerList getHandlers() { + return handlerList; + } + +} \ No newline at end of file