From d8d428947a186c53aea20c1db56dc7e6bc9dd265 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Tue, 27 Jun 2023 20:46:05 +0200 Subject: [PATCH] Add AsyncHeadsFetchedEvent --- .../api/events/AsyncHeadsFetchedEvent.java | 45 +++++++++++++++++++ .../java/tsp/headdb/core/task/UpdateTask.java | 12 ++++- 2 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 src/main/java/tsp/headdb/core/api/events/AsyncHeadsFetchedEvent.java 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..2ed4e92 --- /dev/null +++ b/src/main/java/tsp/headdb/core/api/events/AsyncHeadsFetchedEvent.java @@ -0,0 +1,45 @@ +package tsp.headdb.core.api.events; + +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; +import org.jetbrains.annotations.NotNull; + +public class AsyncHeadsFetchedEvent extends Event { + private static final HandlerList HANDLER_LIST = new HandlerList(); + private final int headsCount; + private final String providerName; + private final long timeTook; + + public AsyncHeadsFetchedEvent(int headsCount, String providerName, long timeTook) { + this.headsCount = headsCount; + this.providerName = providerName; + this.timeTook = timeTook; + } + + @NotNull + @SuppressWarnings("unused") + public static HandlerList getHandlerList() { + return HANDLER_LIST; + } + + @NotNull + @Override + public HandlerList getHandlers() { + return new HandlerList(); + } + + @SuppressWarnings("unused") + public int getHeadsCount() { + return headsCount; + } + + @SuppressWarnings("unused") + public String getProviderName() { + return providerName; + } + + @SuppressWarnings("unused") + 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..29a221a 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 class UpdateTask implements Task { 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( + size, + providerName, + time)); }); HeadDB.getInstance().getStorage().getPlayerStorage().backup(); HeadDB.getInstance().getLog().debug("UpdateTask finished!");