Skip to content

Commit

Permalink
apply TickUtil to BaseInventoryMenu
Browse files Browse the repository at this point in the history
  • Loading branch information
HSGamer committed Jul 5, 2024
1 parent 1d0a173 commit d66decc
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/main/java/me/hsgamer/bettergui/menu/BaseInventoryMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import me.hsgamer.bettergui.builder.InventoryBuilder;
import me.hsgamer.bettergui.util.ProcessApplierConstants;
import me.hsgamer.bettergui.util.StringReplacerApplier;
import me.hsgamer.bettergui.util.TickUtil;
import me.hsgamer.hscore.bukkit.gui.BukkitGUIDisplay;
import me.hsgamer.hscore.bukkit.gui.BukkitGUIHolder;
import me.hsgamer.hscore.common.MapUtils;
Expand All @@ -28,6 +29,7 @@
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentSkipListSet;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;

import static me.hsgamer.bettergui.BetterGUI.getInstance;
Expand All @@ -42,15 +44,17 @@ public abstract class BaseInventoryMenu<B extends ButtonMap> extends BaseMenu {
private final B buttonMap;
private final Set<UUID> forceClose = new ConcurrentSkipListSet<>();
private final Map<UUID, Task> updateTasks = new ConcurrentHashMap<>();
private final long ticks;
private final long refreshMillis;

protected BaseInventoryMenu(Config config) {
super(config);
guiHolder = new BukkitGUIHolder(getInstance()) {
@Override
protected @NotNull BukkitGUIDisplay newDisplay(UUID uuid) {
BukkitGUIDisplay guiDisplay = super.newDisplay(uuid);
if (ticks >= 0) {
if (refreshMillis >= 0) {
long millis = refreshMillis == 0 ? 50L : refreshMillis;

Player player = Bukkit.getPlayer(uuid);
assert player != null;

Expand All @@ -61,7 +65,7 @@ protected BaseInventoryMenu(Config config) {
} else {
return false;
}
}, ticks, ticks));
}, millis, millis, TimeUnit.MILLISECONDS));
}
return guiDisplay;
}
Expand Down Expand Up @@ -140,10 +144,9 @@ protected void onClose(@NotNull CloseEvent event) {
.map(i -> Math.max(1, i))
.ifPresent(guiHolder::setSize);

ticks = Optional.ofNullable(MapUtils.getIfFound(menuSettings, "auto-refresh", "ticks"))
refreshMillis = Optional.ofNullable(MapUtils.getIfFound(menuSettings, "auto-refresh", "ticks"))
.map(String::valueOf)
.flatMap(Validate::getNumber)
.map(BigDecimal::longValue)
.flatMap(TickUtil::toMillis)
.orElse(0L);

Optional.ofNullable(menuSettings.get("cached"))
Expand Down

0 comments on commit d66decc

Please sign in to comment.