mirror of
https://github.com/filoghost/ChestCommands.git
synced 2024-11-22 10:05:17 +01:00
Use ticks as unit for menu refreshing
This commit is contained in:
parent
4040e60307
commit
035b445418
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
@ -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;
|
||||
|
@ -27,7 +27,7 @@ public class MenuSettings {
|
||||
// Optional settings
|
||||
private List<String> commands;
|
||||
private List<Action> 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() {
|
||||
|
@ -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++;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user