From 035b445418f2d8f3b2ca6751d94196bae65e9be6 Mon Sep 17 00:00:00 2001 From: filoghost Date: Sun, 5 Jul 2020 12:33:46 +0200 Subject: [PATCH] Use ticks as unit for menu refreshing --- .../java/me/filoghost/chestcommands/ChestCommands.java | 2 +- .../chestcommands/parsing/menu/MenuParser.java | 10 +++++----- .../chestcommands/parsing/menu/MenuSettings.java | 10 +++++----- .../filoghost/chestcommands/task/RefreshMenusTask.java | 6 +++--- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java b/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java index c3778bd..5e1bc40 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/ChestCommands.java @@ -139,7 +139,7 @@ public class ChestCommands extends JavaPlugin { Bukkit.getScheduler().runTaskLater(this, errorCollector::logToConsole, 10L); } - Bukkit.getScheduler().runTaskTimer(this, new RefreshMenusTask(), 2L, 2L); + Bukkit.getScheduler().runTaskTimer(this, new RefreshMenusTask(), 1L, 1L); } diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuParser.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuParser.java index f60d46a..c868437 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuParser.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuParser.java @@ -51,7 +51,7 @@ public class MenuParser { } } - iconMenu.setRefreshTicks(menuSettings.getRefreshTenths()); + iconMenu.setRefreshTicks(menuSettings.getRefreshTicks()); iconMenu.setOpenActions(menuSettings.getOpenActions()); return new LoadedMenu(iconMenu, menuConfig.getFileName(), menuSettings.getCommands(), menuSettings.getOpenTrigger()); @@ -163,11 +163,11 @@ public class MenuParser { } if (settingsSection.isSet(MenuSettingsNode.AUTO_REFRESH)) { - int tenthsToRefresh = (int) (settingsSection.getDouble(MenuSettingsNode.AUTO_REFRESH) * 10.0); - if (tenthsToRefresh < 1) { - tenthsToRefresh = 1; + int refreshTicks = (int) (settingsSection.getDouble(MenuSettingsNode.AUTO_REFRESH) * 20.0); + if (refreshTicks < 1) { + refreshTicks = 1; } - menuSettings.setRefreshTenths(tenthsToRefresh); + menuSettings.setRefreshTicks(refreshTicks); } return menuSettings; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuSettings.java b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuSettings.java index dafa125..9809c04 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuSettings.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/parsing/menu/MenuSettings.java @@ -27,7 +27,7 @@ public class MenuSettings { // Optional settings private List commands; private List openActions; - private int refreshTenths; + private int refreshTicks; private OpenTrigger openTrigger; @@ -60,12 +60,12 @@ public class MenuSettings { this.openActions = openAction; } - public int getRefreshTenths() { - return refreshTenths; + public int getRefreshTicks() { + return refreshTicks; } - public void setRefreshTenths(int refreshTenths) { - this.refreshTenths = refreshTenths; + public void setRefreshTicks(int refreshTicks) { + this.refreshTicks = refreshTicks; } public OpenTrigger getOpenTrigger() { diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/task/RefreshMenusTask.java b/Plugin/src/main/java/me/filoghost/chestcommands/task/RefreshMenusTask.java index bd7611c..d0ebebb 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/task/RefreshMenusTask.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/task/RefreshMenusTask.java @@ -22,7 +22,7 @@ import org.bukkit.entity.Player; public class RefreshMenusTask implements Runnable { - private long elapsedTenths; + private long currentTick; @Override public void run() { @@ -35,12 +35,12 @@ public class RefreshMenusTask implements Runnable { int refreshTicks = ((InternalIconMenu) itemInventory.getMenu()).getRefreshTicks(); - if (refreshTicks > 0 && elapsedTenths % refreshTicks == 0) { + if (refreshTicks > 0 && currentTick % refreshTicks == 0) { itemInventory.refresh(); } } - elapsedTenths++; + currentTick++; } }