Skip to content

Commit

Permalink
Merge pull request #49 from Command435-CRM/master
Browse files Browse the repository at this point in the history
Add AsyncHeadsFetchedEvent
  • Loading branch information
TheSilentPro authored Jul 4, 2023
2 parents 106d26f + e98c289 commit 7ff5411
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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<Category, List<Head>> heads;
private final String providerName;
private final long timeTook;

public AsyncHeadsFetchedEvent(Map<Category, List<Head>> 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<Category, List<Head>> getHeads() {
return heads;
}

public String getProviderName() {
return providerName;
}

public long getTimeTook() {
return timeTook;
}
}
12 changes: 11 additions & 1 deletion src/main/java/tsp/headdb/core/task/UpdateTask.java
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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!");
Expand Down

0 comments on commit 7ff5411

Please sign in to comment.