From c11223b17494a80bfdc3530acaff079fb29e1b0b Mon Sep 17 00:00:00 2001 From: HSGamer Date: Fri, 18 Aug 2023 22:34:08 +0700 Subject: [PATCH] update & rollback some "big changes" --- .../nossr50/database/SQLDatabaseManager.java | 2 +- .../nossr50/listeners/PlayerListener.java | 5 +- .../nossr50/listeners/WorldListener.java | 2 +- src/main/java/com/gmail/nossr50/mcMMO.java | 8 ++- .../nossr50/runnables/SaveTimerTask.java | 28 ++++----- .../database/UUIDUpdateAsyncTask.java | 2 +- .../java/com/gmail/nossr50/util/Misc.java | 1 - .../util/scoreboards/ScoreboardWrapper.java | 61 +++++++++---------- .../nossr50/util/skills/CombatUtils.java | 2 +- 9 files changed, 52 insertions(+), 59 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/database/SQLDatabaseManager.java b/src/main/java/com/gmail/nossr50/database/SQLDatabaseManager.java index fd18015bb..5e9d98041 100644 --- a/src/main/java/com/gmail/nossr50/database/SQLDatabaseManager.java +++ b/src/main/java/com/gmail/nossr50/database/SQLDatabaseManager.java @@ -1356,7 +1356,7 @@ public final class SQLDatabaseManager implements DatabaseManager { statement.executeUpdate("ALTER TABLE `" + tablePrefix + "users` ADD `uuid` varchar(36) NULL DEFAULT NULL"); statement.executeUpdate("ALTER TABLE `" + tablePrefix + "users` ADD UNIQUE INDEX `uuid` (`uuid`) USING BTREE"); - mcMMO.p.getFoliaLib().getImpl().runLaterAsync(new GetUUIDUpdatesRequired(), 100 * Misc.TICK_MS_CONVERSION_FACTOR, TimeUnit.MILLISECONDS); // wait until after first purge + mcMMO.p.getFoliaLib().getImpl().runLaterAsync(new GetUUIDUpdatesRequired(), 100); // wait until after first purge } mcMMO.getUpgradeManager().setUpgradeCompleted(UpgradeType.ADD_UUIDS); diff --git a/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java b/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java index 261f01718..78495ba56 100644 --- a/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java @@ -149,10 +149,7 @@ public class PlayerListener implements Listener { new MobHealthDisplayUpdaterTask(attacker).run(); // set the name back - mcMMO.p.getFoliaLib().getImpl().runAtEntityLater(attacker, - () -> MobHealthbarUtils.handleMobHealthbars(attacker, 0, mcMMO.p), - Misc.TICK_MS_CONVERSION_FACTOR, TimeUnit.MILLISECONDS - ); + mcMMO.p.getFoliaLib().getImpl().runAtEntityLater(attacker, () -> MobHealthbarUtils.handleMobHealthbars(attacker, 0, mcMMO.p), 1); } /** diff --git a/src/main/java/com/gmail/nossr50/listeners/WorldListener.java b/src/main/java/com/gmail/nossr50/listeners/WorldListener.java index 8a2f3dbcb..725f890eb 100644 --- a/src/main/java/com/gmail/nossr50/listeners/WorldListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/WorldListener.java @@ -37,7 +37,7 @@ public class WorldListener implements Listener { for (BlockState blockState : event.getBlocks()) { mcMMO.getPlaceStore().setFalse(blockState); } - }, 50, TimeUnit.MILLISECONDS); + }, 1); } /** diff --git a/src/main/java/com/gmail/nossr50/mcMMO.java b/src/main/java/com/gmail/nossr50/mcMMO.java index 19f838077..d08b2238d 100644 --- a/src/main/java/com/gmail/nossr50/mcMMO.java +++ b/src/main/java/com/gmail/nossr50/mcMMO.java @@ -242,7 +242,8 @@ public class mcMMO extends JavaPlugin { .getImpl() .runTimer( () -> getLogger().severe("You are running an outdated version of "+platformManager.getServerSoftware()+", mcMMO will not work unless you update to a newer version!"), - 20 * 50L, 1000 * 60 * 30, TimeUnit.MILLISECONDS); + 20, 20*60*30 + ); if(platformManager.getServerSoftware() == ServerSoftwareType.CRAFT_BUKKIT) { @@ -250,7 +251,8 @@ public class mcMMO extends JavaPlugin { .getImpl() .runTimer( () -> getLogger().severe("We have detected you are using incompatible server software, our best guess is that you are using CraftBukkit. mcMMO requires Spigot or Paper, if you are not using CraftBukkit, you will still need to update your custom server software before mcMMO will work."), - 20 * 50L, 1000 * 60 * 30, TimeUnit.MILLISECONDS); + 20, 20*60*30 + ); } } else { registerEvents(); @@ -635,7 +637,7 @@ public class mcMMO extends JavaPlugin { if (generalConfig.getChimaeraEnabled()) { getServer().addRecipe(ChimaeraWing.getChimaeraWingRecipe()); } - }, 40 * 50, TimeUnit.MILLISECONDS); + }, 40); } private void scheduleTasks() { diff --git a/src/main/java/com/gmail/nossr50/runnables/SaveTimerTask.java b/src/main/java/com/gmail/nossr50/runnables/SaveTimerTask.java index e2c3d3279..d42eb6b2f 100644 --- a/src/main/java/com/gmail/nossr50/runnables/SaveTimerTask.java +++ b/src/main/java/com/gmail/nossr50/runnables/SaveTimerTask.java @@ -5,26 +5,22 @@ import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.party.PartyManager; import com.gmail.nossr50.runnables.player.PlayerProfileSaveTask; import com.gmail.nossr50.util.LogUtils; -import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.player.UserManager; -import com.tcoded.folialib.wrapper.task.WrappedTask; +import org.bukkit.scheduler.BukkitRunnable; -import java.util.concurrent.TimeUnit; +public class SaveTimerTask extends BukkitRunnable { + @Override + public void run() { + LogUtils.debug(mcMMO.p.getLogger(), "[User Data] Saving..."); + // All player data will be saved periodically through this + int count = 1; -public class SaveTimerTask { - public WrappedTask runTaskTimer(long delay, long period) { - return mcMMO.p.getFoliaLib().getImpl().runTimer(() -> { - LogUtils.debug(mcMMO.p.getLogger(), "[User Data] Saving..."); - // All player data will be saved periodically through this - int count = 1; - - for (McMMOPlayer mcMMOPlayer : UserManager.getPlayers()) { - new PlayerProfileSaveTask(mcMMOPlayer.getProfile(), false).runTaskLaterAsynchronously(mcMMO.p, count); - count++; - } + for (McMMOPlayer mcMMOPlayer : UserManager.getPlayers()) { + new PlayerProfileSaveTask(mcMMOPlayer.getProfile(), false).runTaskLaterAsynchronously(mcMMO.p, count); + count++; + } - PartyManager.saveParties(); - }, delay * Misc.TICK_CONVERSION_FACTOR, period * Misc.TICK_CONVERSION_FACTOR, TimeUnit.MILLISECONDS); + PartyManager.saveParties(); } } diff --git a/src/main/java/com/gmail/nossr50/runnables/database/UUIDUpdateAsyncTask.java b/src/main/java/com/gmail/nossr50/runnables/database/UUIDUpdateAsyncTask.java index fc59bf2df..7470ebba1 100644 --- a/src/main/java/com/gmail/nossr50/runnables/database/UUIDUpdateAsyncTask.java +++ b/src/main/java/com/gmail/nossr50/runnables/database/UUIDUpdateAsyncTask.java @@ -110,7 +110,7 @@ public class UUIDUpdateAsyncTask implements Runnable { // Bukkit runnables don't let themselves reschedule themselves, so we are a pseudo bukkit runnable. private void runTaskLaterAsynchronously(mcMMO plugin, int delay) { - plugin.getFoliaLib().getImpl().runLaterAsync(this, delay, TimeUnit.MILLISECONDS); + plugin.getFoliaLib().getImpl().runLaterAsync(this, delay); } public void start() { diff --git a/src/main/java/com/gmail/nossr50/util/Misc.java b/src/main/java/com/gmail/nossr50/util/Misc.java index cc6d28289..1acd5f089 100644 --- a/src/main/java/com/gmail/nossr50/util/Misc.java +++ b/src/main/java/com/gmail/nossr50/util/Misc.java @@ -26,7 +26,6 @@ public final class Misc { public static final int TIME_CONVERSION_FACTOR = 1000; public static final int TICK_CONVERSION_FACTOR = 20; - public static final int TICK_MS_CONVERSION_FACTOR = 50; public static final int PLAYER_RESPAWN_COOLDOWN_SECONDS = 5; public static final double SKILL_MESSAGE_MAX_SENDING_DISTANCE = 10.0; diff --git a/src/main/java/com/gmail/nossr50/util/scoreboards/ScoreboardWrapper.java b/src/main/java/com/gmail/nossr50/util/scoreboards/ScoreboardWrapper.java index 231fb7bbf..e0d337413 100644 --- a/src/main/java/com/gmail/nossr50/util/scoreboards/ScoreboardWrapper.java +++ b/src/main/java/com/gmail/nossr50/util/scoreboards/ScoreboardWrapper.java @@ -18,10 +18,12 @@ import com.gmail.nossr50.util.player.NotificationManager; import com.gmail.nossr50.util.player.UserManager; import com.gmail.nossr50.util.scoreboards.ScoreboardManager.SidebarType; import com.gmail.nossr50.util.skills.SkillTools; -import com.tcoded.folialib.wrapper.task.WrappedTask; import org.apache.commons.lang.Validate; +import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.entity.Player; +import org.bukkit.scheduler.BukkitRunnable; +import org.bukkit.scheduler.BukkitTask; import org.bukkit.scoreboard.DisplaySlot; import org.bukkit.scoreboard.Objective; import org.bukkit.scoreboard.Score; @@ -30,7 +32,6 @@ import org.jetbrains.annotations.NotNull; import java.util.List; import java.util.Map; -import java.util.concurrent.TimeUnit; public class ScoreboardWrapper { public static final String SIDE_OBJECTIVE = "mcMMO_sideObjective"; @@ -85,40 +86,38 @@ public class ScoreboardWrapper { } } - public WrappedTask updateTask = null; + public BukkitTask updateTask = null; - private class ScoreboardQuickUpdate { - public WrappedTask runTaskLater(long delay) { - return mcMMO.p.getFoliaLib().getImpl().runLater(() -> { - updateSidebar(); - updateTask = null; - }, delay * Misc.TICK_CONVERSION_FACTOR, TimeUnit.MILLISECONDS); + private class ScoreboardQuickUpdate extends BukkitRunnable { + @Override + public void run() { + updateSidebar(); + updateTask = null; } } - public WrappedTask revertTask = null; + public BukkitTask revertTask = null; - private class ScoreboardChangeTask { - public WrappedTask runTaskLater(long delay) { - return mcMMO.p.getFoliaLib().getImpl().runLater(() -> { - tryRevertBoard(); - revertTask = null; - }, delay * Misc.TICK_CONVERSION_FACTOR, TimeUnit.MILLISECONDS); + private class ScoreboardChangeTask extends BukkitRunnable { + @Override + public void run() { + tryRevertBoard(); + revertTask = null; } } - public WrappedTask cooldownTask = null; + public BukkitTask cooldownTask = null; - private class ScoreboardCooldownTask { - public WrappedTask runTaskTimer(long delay, long period) { - return mcMMO.p.getFoliaLib().getImpl().runTimer(() -> { - // Stop updating if it's no longer something displaying cooldowns - if (isBoardShown() && (isSkillScoreboard() || isCooldownScoreboard())) { - doSidebarUpdateSoon(); - } else { - stopCooldownUpdating(); - } - }, delay, period, TimeUnit.MILLISECONDS); + private class ScoreboardCooldownTask extends BukkitRunnable { + @Override + public void run() { + // Stop updating if it's no longer something displaying cooldowns + if (isBoardShown() && (isSkillScoreboard() || isCooldownScoreboard())) { + doSidebarUpdateSoon(); + } + else { + stopCooldownUpdating(); + } } } @@ -126,7 +125,7 @@ public class ScoreboardWrapper { public void doSidebarUpdateSoon() { if (updateTask == null) { // To avoid spamming the scheduler, store the instance and run 2 ticks later - updateTask = new ScoreboardQuickUpdate().runTaskLater(2L); + updateTask = new ScoreboardQuickUpdate().runTaskLater(mcMMO.p, 2L); } } @@ -134,7 +133,7 @@ public class ScoreboardWrapper { if (cooldownTask == null) { // Repeat every 5 seconds. // Cancels once all cooldowns are done, using stopCooldownUpdating(). - cooldownTask = new ScoreboardCooldownTask().runTaskTimer(5 * Misc.TICK_CONVERSION_FACTOR, 5 * Misc.TICK_CONVERSION_FACTOR); + cooldownTask = new ScoreboardCooldownTask().runTaskTimer(mcMMO.p, 5 * Misc.TICK_CONVERSION_FACTOR, 5 * Misc.TICK_CONVERSION_FACTOR); } } @@ -217,7 +216,7 @@ public class ScoreboardWrapper { } player.setScoreboard(scoreboard); - revertTask = new ScoreboardChangeTask().runTaskLater(ticks); + revertTask = new ScoreboardChangeTask().runTaskLater(mcMMO.p, ticks); // TODO is there any way to do the time that looks acceptable? // player.sendMessage(LocaleLoader.getString("Commands.Scoreboard.Timer", StringUtils.capitalize(sidebarType.toString().toLowerCase(Locale.ENGLISH)), ticks / 20F)); @@ -427,7 +426,7 @@ public class ScoreboardWrapper { NotificationManager.sendPlayerInformationChatOnlyPrefixed(player, "Scoreboard.Recovery"); initBoard(); //Start over - mcMMO.p.getFoliaLib().getImpl().runLater(() -> ScoreboardManager.retryLastSkillBoard(player), 0, TimeUnit.MILLISECONDS); + Bukkit.getScheduler().runTaskLater(mcMMO.p, () -> ScoreboardManager.retryLastSkillBoard(player), 0); } } diff --git a/src/main/java/com/gmail/nossr50/util/skills/CombatUtils.java b/src/main/java/com/gmail/nossr50/util/skills/CombatUtils.java index 54f975324..f2f7cf77b 100644 --- a/src/main/java/com/gmail/nossr50/util/skills/CombatUtils.java +++ b/src/main/java/com/gmail/nossr50/util/skills/CombatUtils.java @@ -983,6 +983,6 @@ public final class CombatUtils { * @param entity the projectile */ public static void delayArrowMetaCleanup(@NotNull Projectile entity) { - mcMMO.p.getFoliaLib().getImpl().runLater(() -> cleanupArrowMetadata(entity), 1000 * 60, TimeUnit.MILLISECONDS); + mcMMO.p.getFoliaLib().getImpl().runLater(() -> cleanupArrowMetadata(entity), 20*60); } }