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
1 change: 1 addition & 0 deletions Menu Library/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ dependencies {
compileOnly(libs.com.google.code.gson.gson)
compileOnly(libs.google.findbugs.jsr305)
compileOnly(libs.mojang.authlib)
compileOnly(libs.space.arim.morepaperlib)
}

java {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.scheduler.BukkitRunnable;
import space.arim.morepaperlib.MorePaperLib;
import space.arim.morepaperlib.scheduling.ScheduledTask;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
Expand Down Expand Up @@ -82,7 +83,7 @@ public class MenuUtility<T> {
protected boolean autoTitleCurrentPage;
protected boolean useColorConversion;

protected int taskid;
protected ScheduledTask taskid;
protected int animateButtonTime = 20;

protected int slotIndex;
Expand All @@ -95,7 +96,7 @@ public class MenuUtility<T> {
protected int updateTime;

protected int animateTitleTime = 5;
private int taskIdAnimateTitle;
private ScheduledTask taskIdAnimateTitle;
protected int highestFillSlot;

/**
Expand Down Expand Up @@ -666,8 +667,8 @@ protected void updateButtons() {

protected void updateTimeButtons() {
boolean cancelTask = false;
if (this.taskid > 0 && Bukkit.getScheduler().isCurrentlyRunning(this.taskid) || Bukkit.getScheduler().isQueued(this.taskid)) {
Bukkit.getScheduler().cancelTask(this.taskid);
if (this.taskid != null && !this.taskid.isCancelled()) {
this.taskid.cancel();
cancelTask = true;
}
if (cancelTask) {
Expand Down Expand Up @@ -760,11 +761,11 @@ protected void onMenuOpenPlaySound() {
* Note: this is only for internal use, don't try to override this.
*/
protected final void closeTasks() {
if (Bukkit.getScheduler().isCurrentlyRunning(this.taskid) || Bukkit.getScheduler().isQueued(this.taskid)) {
Bukkit.getScheduler().cancelTask(this.taskid);
if (this.taskid != null && !this.taskid.isCancelled()) {
this.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 @@ -929,29 +930,26 @@ protected ItemStack getMenuItem(final MenuButton menuButton, final ButtonData<T>
protected void runAnimateTitle() {
Function<?> task = getAnimateTitle();
if (task == null) return;
this.taskIdAnimateTitle = new BukkitRunnable() {
@Override
public void run() {
Object text = task.apply();
if (text == null || (ServerVersion.atLeast(ServerVersion.V1_9) && this.isCancelled())) {
this.cancel();
updateTitle();
return;
}
if (!text.equals("") && !menuAPI.isNotFoundUpdateTitleClazz()) {
updateTitle(text);
}
this.taskIdAnimateTitle = menuAPI.getMorePaperLib().scheduling().entitySpecificScheduler(player).runAtFixedRate(() -> {
Object text = task.apply();
if (text == null || (ServerVersion.atLeast(ServerVersion.V1_9) && this.taskIdAnimateTitle.isCancelled())) {
this.taskIdAnimateTitle.cancel();
updateTitle();
return;
}
}.runTaskTimerAsynchronously(menuAPI.getPlugin(), 1, 20 + this.animateTitleTime).getTaskId();
if (!text.equals("") && !menuAPI.isNotFoundUpdateTitleClazz()) {
updateTitle(text);
}
}, null, 1, 20 + this.animateTitleTime);
}

public void cancelAnimateTitle() {
Function<?> task = getAnimateTitle();
if (task == null) return;
this.animateTitle = null;
this.animateTitleJson = null;
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();
}
updateTitle();
}
Expand All @@ -971,11 +969,18 @@ private void updateTitle(Object text) {
UpdateTitle.update(player, (JsonObject) text);
}

private class RunButtonAnimation extends BukkitRunnable {
private class RunButtonAnimation implements Runnable {
private int counter = 0;

public int runTask(long delay) {
return runTaskTimer(menuAPI.getPlugin(), 1L, delay).getTaskId();
private ScheduledTask task;

public ScheduledTask runTask(long delay) {
this.task = menuAPI.getMorePaperLib().scheduling().entitySpecificScheduler(player).runAtFixedRate(
this,
null,
1L,
delay
);
return this.task;
}

@Override
Expand All @@ -991,7 +996,7 @@ else if (counter >= timeLeft) {
getMenuData(getPageNumber());
final MenuDataUtility<T> menuDataUtility = getMenuData(getPageNumber());
if (menuDataUtility == null) {
cancel();
task.cancel();
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.Plugin;
import space.arim.morepaperlib.MorePaperLib;

import javax.annotation.Nullable;
import java.util.HashMap;
Expand All @@ -34,6 +35,7 @@ public class RegisterMenuAPI {
private static RegisterMenuAPI menuAPI;// = new RegisterMenuAPI();
private final MenuCache menuCache;
private final Plugin plugin;
private MorePaperLib morePaperLib;
private Metadata playerMeta;
private ItemCreator itemCreator;
private CheckItemsInsideMenu checkItemsInsideMenu;
Expand All @@ -53,6 +55,7 @@ public RegisterMenuAPI(final Plugin plugin) {
public RegisterMenuAPI(final Plugin plugin, boolean turnOffLogger) {
menuAPI = this;
this.plugin = plugin;
this.morePaperLib = new MorePaperLib(plugin);
this.menuCache = new MenuCache();
versionCheck(turnOffLogger);
if (this.plugin == null) {
Expand Down Expand Up @@ -102,6 +105,10 @@ public Plugin getPlugin() {
return plugin;
}

public MorePaperLib getMorePaperLib() {
return morePaperLib;
}

public Metadata getPlayerMeta() {
return playerMeta;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public void menuOpen(@Nonnull final Player player, @Nullable final Location loca

if (!getButtonsToUpdate().isEmpty())
updateButtonsInList();
Bukkit.getScheduler().runTaskLater(menuAPI.getPlugin(), this::updateTitle, 1);
menuAPI.getMorePaperLib().scheduling().entitySpecificScheduler(player).runDelayed(this::updateTitle, null, 1L);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class LoadDependency : Plugin<Project> {
maven { url = URI("https://oss.sonatype.org/content/repositories/snapshots/") }
maven { url = URI("https://repo.maven.apache.org/maven2/") }
maven { url = URI("https://libraries.minecraft.net/") }
maven { url = URI("https://mvn-repo.arim.space/lesser-gpl3/") }
}
}
}
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ dependencyResolutionManagement {
library("tr7zw.item.nbt.api", "de.tr7zw:item-nbt-api:2.13.1")
library("google.findbugs.jsr305", "com.google.code.findbugs:jsr305:3.0.2")
library("mojang.authlib","com.mojang:authlib:1.6.25");
library("space.arim.morepaperlib","space.arim.morepaperlib:morepaperlib:0.4.3");
plugin("shadow", "com.github.johnrengelman.shadow").version("8.1.1")
}
}
Expand Down