Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,11 @@
<id>sonatype-oss-snapshots</id>
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
</repository>

<!-- MorePaperLib-->
<repository>
<id>arim-mvn-lgpl3</id>
<url>https://mvn-repo.arim.space/lesser-gpl3/</url>
</repository>
</repositories>

<!--
Expand Down Expand Up @@ -118,6 +122,13 @@
<version>24.0.1</version>
<scope>compile</scope>
</dependency>
<!-- MorePaperLib -->
<dependency>
<groupId>space.arim.morepaperlib</groupId>
<artifactId>morepaperlib</artifactId>
<version>0.4.3</version>
<scope>compile</scope>
</dependency>


</dependencies>
Expand Down Expand Up @@ -188,6 +199,7 @@
<includes>
<include>com.github.broken1arrow:*</include>
<include>com.github.broken1arrow.Item-NBT-API:item-nbt-api:*</include>
<include>space.arim.morepaperlib:morepaperlib*</include>
</includes>
<excludes>
</excludes>
Expand All @@ -201,6 +213,10 @@
<pattern>de.tr7zw.changeme</pattern>
<shadedPattern>${project.groupId}.dependencies.nbt</shadedPattern>
</relocation>
<relocation>
<pattern>space.arim.morepaperlib</pattern>
<shadedPattern>${project.groupId}.dependencies.morepaperlib</shadedPattern>
</relocation>
</relocations>
</configuration>
</execution>
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/brokenarrow/menu/library/MenuHolder.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

/**
Expand Down
62 changes: 27 additions & 35 deletions src/main/java/org/brokenarrow/menu/library/MenuUtility.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -75,7 +77,7 @@ public MenuUtility(final @Nullable List<Integer> 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;
Expand All @@ -91,7 +93,7 @@ public MenuUtility(final @Nullable List<Integer> 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<String> animateTitle;

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
}
}

Expand Down Expand Up @@ -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
Expand All @@ -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<Integer> itemSlots = getItemSlotsMap(menuDataUtility, menuButton);
Expand All @@ -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();
Expand All @@ -986,8 +982,7 @@ else if (counter >= timeleft) {
}
counter++;
}
}.runTaskTimer(plugin, 1L, 20L).getTaskId();

}, null, 1L, 20L);
}

@Nullable
Expand Down Expand Up @@ -1044,21 +1039,18 @@ private Set<Integer> getItemSlotsMap(final MenuDataUtility menuDataMap, final Me
protected void animateTitle() {
PairFunction<String> task = this.animateTitle;
if (task == null) return;
this.taskidAnimateTitle = new BukkitRunnable() {

@Override
public void run() {
Pair<String, Boolean> 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<String, Boolean> 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));
}
}