Skip to content

Commit

Permalink
Add PreTimedTypeResetEvent to allow devs to add custom rewards
Browse files Browse the repository at this point in the history
  • Loading branch information
ajgeiss0702 committed Jan 16, 2024
1 parent d2fe20f commit 2135b80
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package us.ajg0702.leaderboards.api.events;

import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;
import us.ajg0702.leaderboards.boards.TimedType;

public class PreTimedTypeResetEvent extends Event {

private final String board;
private final TimedType type;


public PreTimedTypeResetEvent(String board, TimedType type) {
this.board = board;
this.type = type;
}

public String getBoard() {
return board;
}

public TimedType getType() {
return type;
}

private static final HandlerList HANDLERS = new HandlerList();

public @NotNull HandlerList getHandlers() {
return HANDLERS;
}

public static HandlerList getHandlerList() {
return HANDLERS;
}
}
10 changes: 7 additions & 3 deletions src/main/java/us/ajg0702/leaderboards/cache/Cache.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.spongepowered.configurate.ConfigurateException;
import us.ajg0702.leaderboards.Debug;
import us.ajg0702.leaderboards.LeaderboardPlugin;
import us.ajg0702.leaderboards.api.events.PreTimedTypeResetEvent;
import us.ajg0702.leaderboards.api.events.UpdatePlayerEvent;
import us.ajg0702.leaderboards.boards.StatEntry;
import us.ajg0702.leaderboards.boards.TimedType;
Expand Down Expand Up @@ -787,13 +788,16 @@ public void reset(String board, TimedType type) throws ExecutionException, Inter
List<String> updatableBoards = plugin.getAConfig().getStringList("only-update");
if(!updatableBoards.isEmpty() && !updatableBoards.contains(board)) return;

if(type.equals(TimedType.ALLTIME)) {
throw new IllegalArgumentException("Cannot reset ALLTIME!");
}

Bukkit.getPluginManager().callEvent(new PreTimedTypeResetEvent(board, type));

long startTime = System.currentTimeMillis();
LocalDateTime startDateTime = LocalDateTime.now();
long newTime = startDateTime.atOffset(ZoneOffset.UTC).toEpochSecond()*1000;
Debug.info(board+" "+type+" "+startDateTime.atOffset(ZoneOffset.UTC).format(DateTimeFormatter.RFC_1123_DATE_TIME)+" "+newTime);
if(type.equals(TimedType.ALLTIME)) {
throw new IllegalArgumentException("Cannot reset ALLTIME!");
}


List<String> saveableTypes = plugin.getAConfig().getStringList("reset-save-types");
Expand Down

0 comments on commit 2135b80

Please sign in to comment.