update & rollback some "big changes"

This commit is contained in:
HSGamer 2023-08-18 22:34:08 +07:00
parent 5ed0c47e84
commit c11223b174
9 changed files with 52 additions and 59 deletions

View File

@ -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 `uuid` varchar(36) NULL DEFAULT NULL");
statement.executeUpdate("ALTER TABLE `" + tablePrefix + "users` ADD UNIQUE INDEX `uuid` (`uuid`) USING BTREE"); 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); mcMMO.getUpgradeManager().setUpgradeCompleted(UpgradeType.ADD_UUIDS);

View File

@ -149,10 +149,7 @@ public class PlayerListener implements Listener {
new MobHealthDisplayUpdaterTask(attacker).run(); new MobHealthDisplayUpdaterTask(attacker).run();
// set the name back // set the name back
mcMMO.p.getFoliaLib().getImpl().runAtEntityLater(attacker, mcMMO.p.getFoliaLib().getImpl().runAtEntityLater(attacker, () -> MobHealthbarUtils.handleMobHealthbars(attacker, 0, mcMMO.p), 1);
() -> MobHealthbarUtils.handleMobHealthbars(attacker, 0, mcMMO.p),
Misc.TICK_MS_CONVERSION_FACTOR, TimeUnit.MILLISECONDS
);
} }
/** /**

View File

@ -37,7 +37,7 @@ public class WorldListener implements Listener {
for (BlockState blockState : event.getBlocks()) { for (BlockState blockState : event.getBlocks()) {
mcMMO.getPlaceStore().setFalse(blockState); mcMMO.getPlaceStore().setFalse(blockState);
} }
}, 50, TimeUnit.MILLISECONDS); }, 1);
} }
/** /**

View File

@ -242,7 +242,8 @@ public class mcMMO extends JavaPlugin {
.getImpl() .getImpl()
.runTimer( .runTimer(
() -> getLogger().severe("You are running an outdated version of "+platformManager.getServerSoftware()+", mcMMO will not work unless you update to a newer version!"), () -> 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) if(platformManager.getServerSoftware() == ServerSoftwareType.CRAFT_BUKKIT)
{ {
@ -250,7 +251,8 @@ public class mcMMO extends JavaPlugin {
.getImpl() .getImpl()
.runTimer( .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."), () -> 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 { } else {
registerEvents(); registerEvents();
@ -635,7 +637,7 @@ public class mcMMO extends JavaPlugin {
if (generalConfig.getChimaeraEnabled()) { if (generalConfig.getChimaeraEnabled()) {
getServer().addRecipe(ChimaeraWing.getChimaeraWingRecipe()); getServer().addRecipe(ChimaeraWing.getChimaeraWingRecipe());
} }
}, 40 * 50, TimeUnit.MILLISECONDS); }, 40);
} }
private void scheduleTasks() { private void scheduleTasks() {

View File

@ -5,26 +5,22 @@ import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.party.PartyManager; import com.gmail.nossr50.party.PartyManager;
import com.gmail.nossr50.runnables.player.PlayerProfileSaveTask; import com.gmail.nossr50.runnables.player.PlayerProfileSaveTask;
import com.gmail.nossr50.util.LogUtils; import com.gmail.nossr50.util.LogUtils;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.player.UserManager; 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 { for (McMMOPlayer mcMMOPlayer : UserManager.getPlayers()) {
public WrappedTask runTaskTimer(long delay, long period) { new PlayerProfileSaveTask(mcMMOPlayer.getProfile(), false).runTaskLaterAsynchronously(mcMMO.p, count);
return mcMMO.p.getFoliaLib().getImpl().runTimer(() -> { count++;
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++;
}
PartyManager.saveParties(); PartyManager.saveParties();
}, delay * Misc.TICK_CONVERSION_FACTOR, period * Misc.TICK_CONVERSION_FACTOR, TimeUnit.MILLISECONDS);
} }
} }

View File

@ -110,7 +110,7 @@ public class UUIDUpdateAsyncTask implements Runnable {
// Bukkit runnables don't let themselves reschedule themselves, so we are a pseudo bukkit runnable. // Bukkit runnables don't let themselves reschedule themselves, so we are a pseudo bukkit runnable.
private void runTaskLaterAsynchronously(mcMMO plugin, int delay) { private void runTaskLaterAsynchronously(mcMMO plugin, int delay) {
plugin.getFoliaLib().getImpl().runLaterAsync(this, delay, TimeUnit.MILLISECONDS); plugin.getFoliaLib().getImpl().runLaterAsync(this, delay);
} }
public void start() { public void start() {

View File

@ -26,7 +26,6 @@ public final class Misc {
public static final int TIME_CONVERSION_FACTOR = 1000; public static final int TIME_CONVERSION_FACTOR = 1000;
public static final int TICK_CONVERSION_FACTOR = 20; 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 int PLAYER_RESPAWN_COOLDOWN_SECONDS = 5;
public static final double SKILL_MESSAGE_MAX_SENDING_DISTANCE = 10.0; public static final double SKILL_MESSAGE_MAX_SENDING_DISTANCE = 10.0;

View File

@ -18,10 +18,12 @@ import com.gmail.nossr50.util.player.NotificationManager;
import com.gmail.nossr50.util.player.UserManager; import com.gmail.nossr50.util.player.UserManager;
import com.gmail.nossr50.util.scoreboards.ScoreboardManager.SidebarType; import com.gmail.nossr50.util.scoreboards.ScoreboardManager.SidebarType;
import com.gmail.nossr50.util.skills.SkillTools; import com.gmail.nossr50.util.skills.SkillTools;
import com.tcoded.folialib.wrapper.task.WrappedTask;
import org.apache.commons.lang.Validate; import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scheduler.BukkitTask;
import org.bukkit.scoreboard.DisplaySlot; import org.bukkit.scoreboard.DisplaySlot;
import org.bukkit.scoreboard.Objective; import org.bukkit.scoreboard.Objective;
import org.bukkit.scoreboard.Score; import org.bukkit.scoreboard.Score;
@ -30,7 +32,6 @@ import org.jetbrains.annotations.NotNull;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.TimeUnit;
public class ScoreboardWrapper { public class ScoreboardWrapper {
public static final String SIDE_OBJECTIVE = "mcMMO_sideObjective"; 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 { private class ScoreboardQuickUpdate extends BukkitRunnable {
public WrappedTask runTaskLater(long delay) { @Override
return mcMMO.p.getFoliaLib().getImpl().runLater(() -> { public void run() {
updateSidebar(); updateSidebar();
updateTask = null; updateTask = null;
}, delay * Misc.TICK_CONVERSION_FACTOR, TimeUnit.MILLISECONDS);
} }
} }
public WrappedTask revertTask = null; public BukkitTask revertTask = null;
private class ScoreboardChangeTask { private class ScoreboardChangeTask extends BukkitRunnable {
public WrappedTask runTaskLater(long delay) { @Override
return mcMMO.p.getFoliaLib().getImpl().runLater(() -> { public void run() {
tryRevertBoard(); tryRevertBoard();
revertTask = null; revertTask = null;
}, delay * Misc.TICK_CONVERSION_FACTOR, TimeUnit.MILLISECONDS);
} }
} }
public WrappedTask cooldownTask = null; public BukkitTask cooldownTask = null;
private class ScoreboardCooldownTask { private class ScoreboardCooldownTask extends BukkitRunnable {
public WrappedTask runTaskTimer(long delay, long period) { @Override
return mcMMO.p.getFoliaLib().getImpl().runTimer(() -> { public void run() {
// Stop updating if it's no longer something displaying cooldowns // Stop updating if it's no longer something displaying cooldowns
if (isBoardShown() && (isSkillScoreboard() || isCooldownScoreboard())) { if (isBoardShown() && (isSkillScoreboard() || isCooldownScoreboard())) {
doSidebarUpdateSoon(); doSidebarUpdateSoon();
} else { }
stopCooldownUpdating(); else {
} stopCooldownUpdating();
}, delay, period, TimeUnit.MILLISECONDS); }
} }
} }
@ -126,7 +125,7 @@ public class ScoreboardWrapper {
public void doSidebarUpdateSoon() { public void doSidebarUpdateSoon() {
if (updateTask == null) { if (updateTask == null) {
// To avoid spamming the scheduler, store the instance and run 2 ticks later // 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) { if (cooldownTask == null) {
// Repeat every 5 seconds. // Repeat every 5 seconds.
// Cancels once all cooldowns are done, using stopCooldownUpdating(). // 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); 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? // 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)); // 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"); NotificationManager.sendPlayerInformationChatOnlyPrefixed(player, "Scoreboard.Recovery");
initBoard(); //Start over initBoard(); //Start over
mcMMO.p.getFoliaLib().getImpl().runLater(() -> ScoreboardManager.retryLastSkillBoard(player), 0, TimeUnit.MILLISECONDS); Bukkit.getScheduler().runTaskLater(mcMMO.p, () -> ScoreboardManager.retryLastSkillBoard(player), 0);
} }
} }

View File

@ -983,6 +983,6 @@ public final class CombatUtils {
* @param entity the projectile * @param entity the projectile
*/ */
public static void delayArrowMetaCleanup(@NotNull Projectile entity) { 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);
} }
} }