diff --git a/src/main/java/tsp/headdb/core/api/events/AsyncHeadsFetchedEvent.java b/src/main/java/tsp/headdb/core/api/events/AsyncHeadsFetchedEvent.java new file mode 100644 index 0000000..7930ca9 --- /dev/null +++ b/src/main/java/tsp/headdb/core/api/events/AsyncHeadsFetchedEvent.java @@ -0,0 +1,47 @@ +package tsp.headdb.core.api.events; + +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; +import org.jetbrains.annotations.NotNull; +import tsp.headdb.implementation.category.Category; +import tsp.headdb.implementation.head.Head; + +import java.util.List; +import java.util.Map; + +public class AsyncHeadsFetchedEvent extends Event { + private static final HandlerList HANDLER_LIST = new HandlerList(); + private final Map> heads; + private final String providerName; + private final long timeTook; + + public AsyncHeadsFetchedEvent(Map> heads, String providerName, long timeTook) { + super(true); + this.heads = heads; + this.providerName = providerName; + this.timeTook = timeTook; + } + + @NotNull + public static HandlerList getHandlerList() { + return HANDLER_LIST; + } + + @NotNull + @Override + public HandlerList getHandlers() { + return HANDLER_LIST; + } + + public Map> getHeads() { + return heads; + } + + public String getProviderName() { + return providerName; + } + + public long getTimeTook() { + return timeTook; + } +} diff --git a/src/main/java/tsp/headdb/core/task/UpdateTask.java b/src/main/java/tsp/headdb/core/task/UpdateTask.java index ec19c3b..774f287 100644 --- a/src/main/java/tsp/headdb/core/task/UpdateTask.java +++ b/src/main/java/tsp/headdb/core/task/UpdateTask.java @@ -1,7 +1,9 @@ package tsp.headdb.core.task; +import org.bukkit.Bukkit; import tsp.headdb.HeadDB; import tsp.headdb.core.api.HeadAPI; +import tsp.headdb.core.api.events.AsyncHeadsFetchedEvent; import tsp.headdb.implementation.head.Head; import tsp.nexuslib.task.Task; @@ -25,7 +27,15 @@ public void run() { size++; } } - HeadDB.getInstance().getLog().debug("Fetched: " + size + " Heads | Provider: " + HeadAPI.getDatabase().getRequester().getProvider().name() + " | Time: " + time + "ms (" + TimeUnit.MILLISECONDS.toSeconds(time) + "s)"); + + String providerName = HeadAPI.getDatabase().getRequester().getProvider().name(); + + HeadDB.getInstance().getLog().debug("Fetched: " + size + " Heads | Provider: " + providerName + " | Time: " + time + "ms (" + TimeUnit.MILLISECONDS.toSeconds(time) + "s)"); + Bukkit.getPluginManager().callEvent( + new AsyncHeadsFetchedEvent( + heads, + providerName, + time)); }); HeadDB.getInstance().getStorage().getPlayerStorage().backup(); HeadDB.getInstance().getLog().debug("UpdateTask finished!");