mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-06-28 03:34:43 +02:00
mcMMO-Folia-PR (#4925)
Folia Support --------- Co-authored-by: Rockyers <ethan@yocom.org> Co-authored-by: TechnicallyCoded <technicallycoded@gmail.com> Co-authored-by: HSGamer <huynhqtienvtag@gmail.com>
This commit is contained in:
@ -0,0 +1,28 @@
|
||||
package com.gmail.nossr50.util;
|
||||
|
||||
import com.tcoded.folialib.wrapper.task.WrappedTask;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public abstract class CancellableRunnable implements Consumer<WrappedTask> {
|
||||
private boolean cancelled = false;
|
||||
|
||||
public void cancel() {
|
||||
cancelled = true;
|
||||
}
|
||||
|
||||
public abstract void run();
|
||||
|
||||
@Override
|
||||
public void accept(WrappedTask wrappedTask) {
|
||||
// Run the task if it hasn't been cancelled
|
||||
if (!cancelled) {
|
||||
run();
|
||||
}
|
||||
|
||||
// Cancel the task if it has been cancelled after running
|
||||
if (cancelled) {
|
||||
wrappedTask.cancel();
|
||||
}
|
||||
}
|
||||
}
|
@ -112,7 +112,7 @@ public final class ChimaeraWing {
|
||||
|
||||
if (warmup > 0) {
|
||||
NotificationManager.sendPlayerInformation(player, NotificationType.ITEM_MESSAGE, "Teleport.Commencing", String.valueOf(warmup));
|
||||
new ChimaeraWingWarmup(mcMMOPlayer).runTaskLater(mcMMO.p, 20 * warmup);
|
||||
mcMMO.p.getFoliaLib().getImpl().runAtEntityLater(player, new ChimaeraWingWarmup(mcMMOPlayer), 20 * warmup);
|
||||
}
|
||||
else {
|
||||
chimaeraExecuteTeleport();
|
||||
@ -123,15 +123,18 @@ public final class ChimaeraWing {
|
||||
Player player = mcMMOPlayer.getPlayer();
|
||||
|
||||
if (mcMMO.p.getGeneralConfig().getChimaeraUseBedSpawn() && player.getBedSpawnLocation() != null) {
|
||||
player.teleport(player.getBedSpawnLocation());
|
||||
// player.teleport(player.getBedSpawnLocation());
|
||||
mcMMO.p.getFoliaLib().getImpl().teleportAsync(player, player.getBedSpawnLocation());
|
||||
}
|
||||
else {
|
||||
Location spawnLocation = player.getWorld().getSpawnLocation();
|
||||
if (spawnLocation.getBlock().getType() == Material.AIR) {
|
||||
player.teleport(spawnLocation);
|
||||
// player.teleport(spawnLocation);
|
||||
mcMMO.p.getFoliaLib().getImpl().teleportAsync(player, spawnLocation);
|
||||
}
|
||||
else {
|
||||
player.teleport(player.getWorld().getHighestBlockAt(spawnLocation).getLocation());
|
||||
// player.teleport(player.getWorld().getHighestBlockAt(spawnLocation).getLocation());
|
||||
mcMMO.p.getFoliaLib().getImpl().teleportAsync(player, player.getWorld().getHighestBlockAt(spawnLocation).getLocation());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -367,7 +367,8 @@ public final class EventUtils {
|
||||
return;
|
||||
}
|
||||
|
||||
teleportingPlayer.teleport(targetPlayer);
|
||||
// teleportingPlayer.teleport(targetPlayer);
|
||||
mcMMO.p.getFoliaLib().getImpl().teleportAsync(teleportingPlayer, targetPlayer.getLocation());
|
||||
|
||||
teleportingPlayer.sendMessage(LocaleLoader.getString("Party.Teleport.Player", targetPlayer.getName()));
|
||||
targetPlayer.sendMessage(LocaleLoader.getString("Party.Teleport.Target", teleportingPlayer.getName()));
|
||||
|
@ -12,7 +12,6 @@ import org.bukkit.Material;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.entity.*;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@ -255,7 +254,7 @@ public final class Misc {
|
||||
|
||||
if (player != null) {
|
||||
UserManager.remove(player);
|
||||
new PlayerProfileLoadingTask(player).runTaskLaterAsynchronously(mcMMO.p, 1); // 1 Tick delay to ensure the player is marked as online before we begin loading
|
||||
mcMMO.p.getFoliaLib().getImpl().runLaterAsync(new PlayerProfileLoadingTask(player), 1); // 1 Tick delay to ensure the player is marked as online before we begin loading
|
||||
}
|
||||
}
|
||||
|
||||
@ -326,7 +325,7 @@ public final class Misc {
|
||||
experienceOrb.setExperience(experienceValue);
|
||||
}
|
||||
|
||||
private static class SpawnOrbTask extends BukkitRunnable {
|
||||
private static class SpawnOrbTask implements Runnable {
|
||||
private final Location location;
|
||||
private int orbExpValue;
|
||||
|
||||
|
@ -81,7 +81,7 @@ public final class MobHealthbarUtils {
|
||||
target.setMetadata(MetadataConstants.METADATA_KEY_NAME_VISIBILITY, new FixedMetadataValue(mcMMO.p, false));
|
||||
}
|
||||
|
||||
new MobHealthDisplayUpdaterTask(target).runTaskLater(mcMMO.p, (long) displayTime * Misc.TICK_CONVERSION_FACTOR); // Clear health display after 3 seconds
|
||||
mcMMO.p.getFoliaLib().getImpl().runAtEntityLater(target, new MobHealthDisplayUpdaterTask(target), (long) displayTime * Misc.TICK_CONVERSION_FACTOR); // Clear health display after 3 seconds
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5,6 +5,7 @@ import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
||||
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.runnables.skills.ExperienceBarHideTask;
|
||||
import com.gmail.nossr50.util.Misc;
|
||||
import com.gmail.nossr50.util.player.NotificationManager;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@ -77,7 +78,7 @@ public class ExperienceBarManager {
|
||||
return;
|
||||
|
||||
ExperienceBarHideTask experienceBarHideTask = new ExperienceBarHideTask(this, mcMMOPlayer, primarySkillType);
|
||||
experienceBarHideTask.runTaskLater(plugin, 20L * delaySeconds);
|
||||
mcMMO.p.getFoliaLib().getImpl().runAtEntityLater(mcMMOPlayer.getPlayer(), experienceBarHideTask, (long) delaySeconds * Misc.TICK_CONVERSION_FACTOR);
|
||||
experienceBarHideTaskHashMap.put(primarySkillType, experienceBarHideTask);
|
||||
}
|
||||
|
||||
|
@ -296,7 +296,7 @@ public class NotificationManager {
|
||||
String localeMessage = LocaleLoader.getString("Broadcasts.LevelUpMilestone", mmoPlayer.getPlayer().getDisplayName(), level, mcMMO.p.getSkillTools().getLocalizedSkillName(primarySkillType));
|
||||
Component message = LegacyComponentSerializer.legacySection().deserialize(localeMessage).hoverEvent(levelMilestoneHover);
|
||||
|
||||
Bukkit.getScheduler().runTaskLater(mcMMO.p, () -> audience.sendMessage(Identity.nil(), message), 0);
|
||||
mcMMO.p.getFoliaLib().getImpl().runNextTick(t -> audience.sendMessage(Identity.nil(), message));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -331,7 +331,7 @@ public class NotificationManager {
|
||||
String localeMessage = LocaleLoader.getString("Broadcasts.PowerLevelUpMilestone", mmoPlayer.getPlayer().getDisplayName(), powerLevel);
|
||||
Component message = LegacyComponentSerializer.legacySection().deserialize(localeMessage).hoverEvent(levelMilestoneHover);
|
||||
|
||||
Bukkit.getScheduler().runTaskLater(mcMMO.p, () -> audience.sendMessage(Identity.nil(), message), 0);
|
||||
mcMMO.p.getFoliaLib().getImpl().runNextTick(t -> audience.sendMessage(Identity.nil(), message));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -18,12 +18,10 @@ 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;
|
||||
@ -86,9 +84,9 @@ public class ScoreboardWrapper {
|
||||
}
|
||||
}
|
||||
|
||||
public BukkitTask updateTask = null;
|
||||
public WrappedTask updateTask = null;
|
||||
|
||||
private class ScoreboardQuickUpdate extends BukkitRunnable {
|
||||
private class ScoreboardQuickUpdate implements Runnable {
|
||||
@Override
|
||||
public void run() {
|
||||
updateSidebar();
|
||||
@ -96,9 +94,9 @@ public class ScoreboardWrapper {
|
||||
}
|
||||
}
|
||||
|
||||
public BukkitTask revertTask = null;
|
||||
public WrappedTask revertTask = null;
|
||||
|
||||
private class ScoreboardChangeTask extends BukkitRunnable {
|
||||
private class ScoreboardChangeTask implements Runnable {
|
||||
@Override
|
||||
public void run() {
|
||||
tryRevertBoard();
|
||||
@ -106,9 +104,9 @@ public class ScoreboardWrapper {
|
||||
}
|
||||
}
|
||||
|
||||
public BukkitTask cooldownTask = null;
|
||||
public WrappedTask cooldownTask = null;
|
||||
|
||||
private class ScoreboardCooldownTask extends BukkitRunnable {
|
||||
private class ScoreboardCooldownTask implements Runnable {
|
||||
@Override
|
||||
public void run() {
|
||||
// Stop updating if it's no longer something displaying cooldowns
|
||||
@ -125,7 +123,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(mcMMO.p, 2L);
|
||||
updateTask = mcMMO.p.getFoliaLib().getImpl().runAtEntityLater(player, new ScoreboardQuickUpdate(), 2L);
|
||||
}
|
||||
}
|
||||
|
||||
@ -133,7 +131,7 @@ public class ScoreboardWrapper {
|
||||
if (cooldownTask == null) {
|
||||
// Repeat every 5 seconds.
|
||||
// Cancels once all cooldowns are done, using stopCooldownUpdating().
|
||||
cooldownTask = new ScoreboardCooldownTask().runTaskTimer(mcMMO.p, 5 * Misc.TICK_CONVERSION_FACTOR, 5 * Misc.TICK_CONVERSION_FACTOR);
|
||||
cooldownTask = mcMMO.p.getFoliaLib().getImpl().runAtEntityTimer(player, new ScoreboardCooldownTask(), 5 * Misc.TICK_CONVERSION_FACTOR, 5 * Misc.TICK_CONVERSION_FACTOR);
|
||||
}
|
||||
}
|
||||
|
||||
@ -216,7 +214,7 @@ public class ScoreboardWrapper {
|
||||
}
|
||||
|
||||
player.setScoreboard(scoreboard);
|
||||
revertTask = new ScoreboardChangeTask().runTaskLater(mcMMO.p, ticks);
|
||||
revertTask = mcMMO.p.getFoliaLib().getImpl().runAtEntityLater(player, new ScoreboardChangeTask(), 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));
|
||||
@ -426,7 +424,7 @@ public class ScoreboardWrapper {
|
||||
NotificationManager.sendPlayerInformationChatOnlyPrefixed(player, "Scoreboard.Recovery");
|
||||
|
||||
initBoard(); //Start over
|
||||
Bukkit.getScheduler().runTaskLater(mcMMO.p, () -> ScoreboardManager.retryLastSkillBoard(player), 0);
|
||||
mcMMO.p.getFoliaLib().getImpl().runAtEntity(player, t -> ScoreboardManager.retryLastSkillBoard(player));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -23,7 +23,6 @@ import com.gmail.nossr50.skills.unarmed.UnarmedManager;
|
||||
import com.gmail.nossr50.util.*;
|
||||
import com.gmail.nossr50.util.player.NotificationManager;
|
||||
import com.gmail.nossr50.util.player.UserManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.attribute.Attribute;
|
||||
@ -807,7 +806,7 @@ public final class CombatUtils {
|
||||
baseXP *= multiplier;
|
||||
|
||||
if (baseXP != 0) {
|
||||
new AwardCombatXpTask(mcMMOPlayer, primarySkillType, baseXP, target, xpGainReason).runTaskLater(mcMMO.p, 0);
|
||||
mcMMO.p.getFoliaLib().getImpl().runAtEntity(mcMMOPlayer.getPlayer(), new AwardCombatXpTask(mcMMOPlayer, primarySkillType, baseXP, target, xpGainReason));
|
||||
}
|
||||
}
|
||||
|
||||
@ -982,6 +981,6 @@ public final class CombatUtils {
|
||||
* @param entity the projectile
|
||||
*/
|
||||
public static void delayArrowMetaCleanup(@NotNull Projectile entity) {
|
||||
Bukkit.getServer().getScheduler().runTaskLater(mcMMO.p, () -> cleanupArrowMetadata(entity), 20*60);
|
||||
mcMMO.p.getFoliaLib().getImpl().runLater(() -> cleanupArrowMetadata(entity), 20*60);
|
||||
}
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ public class RankUtils {
|
||||
{
|
||||
SkillUnlockNotificationTask skillUnlockNotificationTask = new SkillUnlockNotificationTask(mcMMOPlayer, subSkillType, newLevel);
|
||||
|
||||
skillUnlockNotificationTask.runTaskLater(plugin, (count * 100L));
|
||||
mcMMO.p.getFoliaLib().getImpl().runAtEntityLater(mcMMOPlayer.getPlayer(), skillUnlockNotificationTask, (count * 100L));
|
||||
|
||||
count++;
|
||||
}
|
||||
|
Reference in New Issue
Block a user