diff --git a/pom.xml b/pom.xml index f500c24..2d96a22 100644 --- a/pom.xml +++ b/pom.xml @@ -67,7 +67,11 @@ sonatype-oss-snapshots https://oss.sonatype.org/content/repositories/snapshots/ - + + + arim-mvn-lgpl3 + https://mvn-repo.arim.space/lesser-gpl3/ + + + space.arim.morepaperlib + morepaperlib + 0.4.3 + compile + @@ -188,6 +199,7 @@ com.github.broken1arrow:* com.github.broken1arrow.Item-NBT-API:item-nbt-api:* + space.arim.morepaperlib:morepaperlib* @@ -201,6 +213,10 @@ de.tr7zw.changeme ${project.groupId}.dependencies.nbt + + space.arim.morepaperlib + ${project.groupId}.dependencies.morepaperlib + diff --git a/src/main/java/org/brokenarrow/menu/library/MenuHolder.java b/src/main/java/org/brokenarrow/menu/library/MenuHolder.java index 20ef972..7cf1dfc 100644 --- a/src/main/java/org/brokenarrow/menu/library/MenuHolder.java +++ b/src/main/java/org/brokenarrow/menu/library/MenuHolder.java @@ -12,6 +12,7 @@ import org.bukkit.event.inventory.InventoryType; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; +import space.arim.morepaperlib.MorePaperLib; import javax.annotation.Nullable; import java.util.ArrayList; @@ -140,7 +141,7 @@ public void menuOpen(final Player player, final Location location, final boolean if (!getButtonsToUpdate().isEmpty()) updateButtonsInList(); - Bukkit.getScheduler().runTaskLater(plugin, this::updateTittle, 1); + new MorePaperLib(plugin).scheduling().entitySpecificScheduler(player).runDelayed(this::updateTittle, null, 1L); } /** diff --git a/src/main/java/org/brokenarrow/menu/library/MenuUtility.java b/src/main/java/org/brokenarrow/menu/library/MenuUtility.java index e14f4f5..988b4fe 100644 --- a/src/main/java/org/brokenarrow/menu/library/MenuUtility.java +++ b/src/main/java/org/brokenarrow/menu/library/MenuUtility.java @@ -19,10 +19,12 @@ import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; import org.bukkit.plugin.Plugin; -import org.bukkit.scheduler.BukkitRunnable; +import space.arim.morepaperlib.MorePaperLib; +import space.arim.morepaperlib.scheduling.ScheduledTask; import javax.annotation.Nonnull; import javax.annotation.Nullable; +import java.time.Duration; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; @@ -75,7 +77,7 @@ public MenuUtility(final @Nullable List fillSlots, @Nullable final List protected final Plugin plugin = getPLUGIN(); private Inventory inventory; protected InventoryType inventoryType; - protected int taskid; + protected ScheduledTask taskid; protected boolean shallCacheItems; protected boolean slotsYouCanAddItems; protected boolean allowShiftClick; @@ -91,7 +93,7 @@ public MenuUtility(final @Nullable List fillSlots, @Nullable final List protected int itemsPerPage = this.inventorySize; protected int pageNumber; protected int updateTime; - protected int taskidAnimateTitle; + protected ScheduledTask taskidAnimateTitle; protected int animateTitleTime; protected PairFunction animateTitle; @@ -638,11 +640,10 @@ protected void updateButtons() { protected void updateTimeButtons() { boolean cancelTask = false; - if (this.taskid > 0) - if (Bukkit.getScheduler().isCurrentlyRunning(this.taskid) || Bukkit.getScheduler().isQueued(this.taskid)) { - Bukkit.getScheduler().cancelTask(this.taskid); - cancelTask = true; - } + if (this.taskid != null && !this.taskid.isCancelled()) { + this.taskid.cancel(); + cancelTask = true; + } if (cancelTask) { updateButtonsInList(); this.getTimeWhenUpdatesButtons().clear(); @@ -736,13 +737,11 @@ protected void onMenuOpenPlaySound() { */ @Deprecated protected void onMenuClose(final InventoryCloseEvent event) { - if (Bukkit.getScheduler().isCurrentlyRunning(this.taskid) || Bukkit.getScheduler().isQueued(this.taskid)) { - Bukkit.getScheduler().cancelTask(this.taskid); - + if (this.taskid != null && !this.taskid.isCancelled()) { + taskid.cancel(); } - if (Bukkit.getScheduler().isCurrentlyRunning(this.taskidAnimateTitle) || Bukkit.getScheduler().isQueued(this.taskidAnimateTitle)) { - Bukkit.getScheduler().cancelTask(this.taskidAnimateTitle); - + if (this.taskidAnimateTitle != null && !this.taskidAnimateTitle.isCancelled()) { + this.taskidAnimateTitle.cancel(); } } @@ -938,7 +937,7 @@ private long getupdateTime(final MenuButton menuButton) { } protected void updateButtonsInList() { - taskid = new BukkitRunnable() { + taskid = new MorePaperLib(plugin).scheduling().entitySpecificScheduler(player).runAtFixedRate(new Runnable() { private int counter = 0; @Override @@ -954,8 +953,7 @@ else if (counter >= timeleft) { getMenuData(getPageNumber()); final MenuDataUtility menuDataUtility = getMenuData(getPageNumber()); if (menuDataUtility == null) { - cancel(); - return; + return; // Terminate the task if needed } final Set itemSlots = getItemSlotsMap(menuDataUtility, menuButton); @@ -974,8 +972,6 @@ else if (counter >= timeleft) { final ButtonData newButtonData = new ButtonData(menuItem, buttonData.getMenuButton(), buttonData.getObject()); menuDataUtility.putButton(getSlot(slot), newButtonData, menuDataUtility.getFillMenuButton(getSlot(slot))); - // menuDataMap.put(getSlot(slot), new ButtonData(menuItem, buttonData.getMenuButton(), buttonData.getObject())); - putAddedButtonsCache(getPageNumber(), menuDataUtility); getMenu().setItem(slot, menuItem); slotList.remove(); @@ -986,8 +982,7 @@ else if (counter >= timeleft) { } counter++; } - }.runTaskTimer(plugin, 1L, 20L).getTaskId(); - + }, null, 1L, 20L); } @Nullable @@ -1044,21 +1039,18 @@ private Set getItemSlotsMap(final MenuDataUtility menuDataMap, final Me protected void animateTitle() { PairFunction task = this.animateTitle; if (task == null) return; - this.taskidAnimateTitle = new BukkitRunnable() { - @Override - public void run() { - Pair apply = task.apply(); - String text = apply.getFirst(); - if (text == null || !apply.getSecond()) { - this.cancel(); - UpdateTittleContainers.update(player, getTitle()); - return; - } - if (!text.isEmpty()) { - UpdateTittleContainers.update(player, text); - } + this.taskidAnimateTitle = new MorePaperLib(plugin).scheduling().asyncScheduler().runAtFixedRate(() -> { + Pair apply = task.apply(); + String text = apply.getFirst(); + if (text == null || !apply.getSecond()) { + taskidAnimateTitle.cancel(); + UpdateTittleContainers.update(player, getTitle()); + return; + } + if (!text.isEmpty()) { + UpdateTittleContainers.update(player, text); } - }.runTaskTimerAsynchronously(plugin, 1, 20 + this.animateTitleTime).getTaskId(); + }, Duration.ofMillis(50L), Duration.ofMillis(20L + this.animateTitleTime * 50L)); } }