diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 00000000..097f9f98 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,9 @@ +# +# https://help.github.com/articles/dealing-with-line-endings/ +# +# Linux start script should use lf +/gradlew text eol=lf + +# These are Windows script files and should use crlf +*.bat text eol=crlf + diff --git a/.gitignore b/.gitignore index 0d938c46..f6bca0f9 100644 --- a/.gitignore +++ b/.gitignore @@ -105,4 +105,11 @@ $RECYCLE.BIN/ *.msp # Windows shortcuts -*.lnk \ No newline at end of file +*.lnk +# Ignore Gradle project-specific cache directory +.gradle + +# Ignore Gradle build output directory +build + +run/ diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 00000000..0dd618d3 --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,115 @@ +import io.papermc.paperweight.userdev.ReobfArtifactConfiguration + +plugins { + java + id("io.papermc.paperweight.userdev") version "2.0.0-beta.14" apply false + id("xyz.jpenilla.run-paper") version "2.3.1" + id("com.gradleup.shadow") version "8.3.5" +} + +java.disableAutoTargetJvm() + +group = "me.athlaeos.valhallammo" + +//repos +allprojects { + repositories { + mavenCentral() + maven { + name = "jitpack.io" + url = uri("https://jitpack.io") + } + maven { + name = "spigot-repo" + url = uri("https://hub.spigotmc.org/nexus/content/repositories/snapshots/") + } + maven { + name = "papermc" + url = uri("https://repo.papermc.io/repository/maven-public/") + } + maven { + name = "lauriichan-release" + url = uri("https://maven.lauriichan.me/release") + } + maven { + name = "jeff-media-public" + url = uri("https://hub.jeff-media.com/nexus/repository/jeff-media-public/") + } + maven { + name = "enginehub" + url = uri("https://maven.enginehub.org/repo/") + } + maven { + name = "placeholderapi" + url = uri("https://repo.extendedclip.com/content/repositories/placeholderapi/") + } + maven { + name = "codemc-repo" + url = uri("https://repo.codemc.io/repository/maven-public/") + } + mavenLocal() + } +} + +subprojects { + apply(plugin = "java") + apply(plugin = "com.gradleup.shadow") + + ext { + set("paperCompiler", ReobfArtifactConfiguration.REOBF_PRODUCTION) + } + + //common dependencies + dependencies { + compileOnly("io.netty:netty-all:4.1.87.Final") + } + + //if we are an NMS module + if (this@subprojects.name.startsWith("v1_")) { + //apply paper weight + apply(plugin = "io.papermc.paperweight.userdev") + + //make sure it requires core + dependencies.implementation(project(":core")) + + //make assemble require the re-obfuscated jar + this@subprojects.tasks.assemble { + dependsOn("reobfJar") + } + } + + tasks { + withType().configureEach { + options.encoding = Charsets.UTF_8.name() // We want UTF-8 for everything + } + withType().configureEach { + // Defaults to java 17, needs to be overridden in newer versions! + options.release = 17 + } + } +} + +tasks { + assemble { + dependsOn("shadowJar") + } + runServer { + version("1.21.4") + } + runPaper.folia.registerTask() +} + +dependencies { + subprojects.forEach { + //if its a version jar we want the reobf variant + if (it.name.startsWith("v1_")) { + runtimeOnly(project(":${it.name}", configuration = "reobf")) + } else { + implementation(it) + } + } +} + +java { + toolchain.languageVersion.set(JavaLanguageVersion.of(21)) +} diff --git a/core/build.gradle.kts b/core/build.gradle.kts new file mode 100644 index 00000000..684adea3 --- /dev/null +++ b/core/build.gradle.kts @@ -0,0 +1,54 @@ +plugins { + `maven-publish` +// `java-library` +} + +java.disableAutoTargetJvm() + +dependencies { + compileOnly("org.spigotmc", "spigot-api", "1.20.1-R0.1-SNAPSHOT") + compileOnly("io.papermc.paper:paper-api:1.20-R0.1-SNAPSHOT") + + //platforms + implementation(project(":platform_api")) + implementation(project(":platform_folia")) + + implementation("com.jeff-media:MorePersistentDataTypes:2.4.0") + implementation("com.jeff-media:custom-block-data:2.2.5") + + compileOnly("me.lauriichan.spigot.justlootit:justlootit-core:1.7.0") + compileOnly("me.lauriichan.spigot.justlootit:justlootit-nms-api:1.7.0") { + exclude("me.lauriichan.laylib") + } + compileOnly("com.github.MilkBowl:VaultAPI:1.7") + compileOnly("com.sk89q.worldedit:worldedit-bukkit:7.3.0-SNAPSHOT") + compileOnly("com.sk89q.worldguard:worldguard-bukkit:7.1.0-SNAPSHOT") + compileOnly("me.clip:placeholderapi:2.11.6") + compileOnly("net.kyori:adventure-text-minimessage:4.17.0") + compileOnly("net.kyori:adventure-text-serializer-legacy:4.17.0") + compileOnly("commons-io:commons-io:2.17.0") + compileOnly("org.bstats:bstats-bukkit:3.0.3") + compileOnly("com.github.decentsoftware-eu:decentholograms:2.8.5") +} + +tasks { + shadowJar { + relocate("com.jeff_media.customblockdata", "me.athlaeos.valhallammo.lib.customblockdata") + } +} + +publishing { + publications { + create("maven") { + groupId = "${rootProject.group}" + artifactId = "valhallammo-core" + version = "${rootProject.version}" + + pom { + name.set("ValhallaMMO") + description.set(rootProject.description) + } + } + } +} + diff --git a/core/dependency-reduced-pom.xml b/core/dependency-reduced-pom.xml deleted file mode 100644 index f8211c42..00000000 --- a/core/dependency-reduced-pom.xml +++ /dev/null @@ -1,96 +0,0 @@ - - - - valhallammo-parent - me.athlaeos - ${revision} - - 4.0.0 - valhallammo-core - - - - maven-shade-plugin - 3.5.1 - - - package - - shade - - - - - true - - - com.jeff_media.morepersistentdatatypes - ${shadedPackage}.com.jeff_media.morepersistentdatatypes - - - com.jeff_media.customblockdata - ${shadedPackage}.com.jeff_media.customblockdata - - - org.bstats - me.athlaeos.valhallammo.bstats - - - - - - - - - - spigotmc-repo - https://hub.spigotmc.org/nexus/content/repositories/snapshots/ - - - jeff-media-public - https://hub.jeff-media.com/nexus/repository/jeff-media-public/ - - - - - org.projectlombok - lombok - 1.18.24 - provided - - - com.github.MilkBowl - VaultAPI - 1.7 - provided - - - com.sk89q.worldedit - worldedit-bukkit - 7.3.0-SNAPSHOT - provided - - - com.sk89q.worldguard - worldguard-bukkit - 7.1.0-SNAPSHOT - provided - - - me.clip - placeholderapi - 2.11.2 - provided - - - commons-io - commons-io - 2.11.0 - provided - - - - 17 - UTF-8 - - diff --git a/core/pom.xml b/core/pom.xml deleted file mode 100644 index 925f24f6..00000000 --- a/core/pom.xml +++ /dev/null @@ -1,130 +0,0 @@ - - 4.0.0 - valhallammo-core - - - 17 - UTF-8 - - - - me.athlaeos - valhallammo-parent - ${revision} - - - - - lauriichan - https://maven.lauriichan.me/release - - - jitpack.io - https://jitpack.io - - - spigotmc-repo - https://hub.spigotmc.org/nexus/content/repositories/snapshots/ - - - jeff-media-public - https://hub.jeff-media.com/nexus/repository/jeff-media-public/ - - - enginehub - https://maven.enginehub.org/repo/ - - - placeholderapi - https://repo.extendedclip.com/content/repositories/placeholderapi/ - - - codemc-repo - https://repo.codemc.io/repository/maven-public/ - default - - - - - - org.spigotmc - spigot-api - 1.20.1-R0.1-SNAPSHOT - provided - - - io.papermc.paper - paper-api - 1.20-R0.1-SNAPSHOT - provided - - - com.jeff-media - MorePersistentDataTypes - 2.4.0 - compile - - - com.jeff-media - custom-block-data - 2.2.2 - compile - - - me.lauriichan.spigot.justlootit - justlootit-core - 1.7.0 - shaded - provided - - - com.github.MilkBowl - VaultAPI - 1.7 - provided - - - com.sk89q.worldedit - worldedit-bukkit - 7.3.0-SNAPSHOT - provided - - - com.sk89q.worldguard - worldguard-bukkit - 7.1.0-SNAPSHOT - provided - - - me.clip - placeholderapi - 2.11.6 - provided - - - net.kyori - adventure-text-minimessage - 4.17.0 - provided - - - commons-io - commons-io - 2.17.0 - provided - - - org.bstats - bstats-bukkit - 3.0.3 - provided - - - com.github.decentsoftware-eu - decentholograms - 2.8.5 - provided - - - diff --git a/core/src/main/java/me/athlaeos/valhallammo/Metrics.java b/core/src/main/java/me/athlaeos/valhallammo/Metrics.java index bca6c4bf..40e3caeb 100644 --- a/core/src/main/java/me/athlaeos/valhallammo/Metrics.java +++ b/core/src/main/java/me/athlaeos/valhallammo/Metrics.java @@ -1,5 +1,6 @@ package me.athlaeos.valhallammo; +import me.athlaeos.valhallammo.utility.Scheduling; import org.bukkit.Bukkit; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.Player; @@ -77,7 +78,7 @@ public Metrics(JavaPlugin plugin, int serviceId) { enabled, this::appendPlatformData, this::appendServiceData, - submitDataTask -> Bukkit.getScheduler().runTask(plugin, submitDataTask), + submitDataTask -> Scheduling.runTask(plugin, submitDataTask), plugin::isEnabled, (message, error) -> this.plugin.getLogger().log(Level.WARNING, message, error), (message) -> this.plugin.getLogger().log(Level.INFO, message), diff --git a/core/src/main/java/me/athlaeos/valhallammo/ValhallaMMO.java b/core/src/main/java/me/athlaeos/valhallammo/ValhallaMMO.java index 53250072..75fd1173 100644 --- a/core/src/main/java/me/athlaeos/valhallammo/ValhallaMMO.java +++ b/core/src/main/java/me/athlaeos/valhallammo/ValhallaMMO.java @@ -1,5 +1,7 @@ package me.athlaeos.valhallammo; +import com.tcoded.folialib.FoliaLib; +import com.tcoded.folialib.impl.PlatformScheduler; import me.athlaeos.valhallammo.block.BlockInteractConversions; import me.athlaeos.valhallammo.commands.*; import me.athlaeos.valhallammo.configuration.ConfigManager; @@ -25,6 +27,10 @@ import me.athlaeos.valhallammo.persistence.Database; import me.athlaeos.valhallammo.persistence.ProfilePersistence; import me.athlaeos.valhallammo.persistence.implementations.SQL; +import me.athlaeos.valhallammo.platform.ValhallaPlatform; +import me.athlaeos.valhallammo.platform.bukkit.BukkitPlatform; +import me.athlaeos.valhallammo.platform.folia.FoliaPlatform; +import me.athlaeos.valhallammo.platform.paper.PaperPlatform; import me.athlaeos.valhallammo.playerstats.LeaderboardManager; import me.athlaeos.valhallammo.playerstats.profiles.implementations.*; import me.athlaeos.valhallammo.potioneffects.PotionEffectRegistry; @@ -45,6 +51,7 @@ import org.bukkit.entity.Player; import org.bukkit.event.Listener; import org.bukkit.plugin.java.JavaPlugin; +import org.jetbrains.annotations.ApiStatus; import java.io.File; import java.io.IOException; @@ -60,18 +67,7 @@ public class ValhallaMMO extends JavaPlugin { private static final Map, PluginHook> activeHooks = new HashMap<>(); private static YamlConfiguration pluginConfig; private static final Collection worldBlacklist = new HashSet<>(); - private static final boolean usingPaperMC = Catch.catchOrElse(() -> { - try { - Class.forName("com.destroystokyo.paper.loottable.LootableInventory"); - } catch (ClassNotFoundException exception) { - return false; - } - return true; - }, false); - - { - instance = this; - } + private static ValhallaPlatform platform = new BukkitPlatform(); public static ValhallaMMO getInstance() { return instance; @@ -81,9 +77,17 @@ public static ValhallaMMO getInstance() { @Override public void onLoad() { + instance = this; // save and update configs pluginConfig = saveAndUpdateConfig("config.yml"); + //platform support + if (FoliaPlatform.usingFolia()) { + platform = new FoliaPlatform(); + } else if (PaperPlatform.usingPaper()) { + platform = new PaperPlatform(); + } + String lang = pluginConfig.getString("language", "en-us"); save("languages/en-us.json"); save("languages/materials/en-us.json"); @@ -170,7 +174,7 @@ public void onEnable() { saveAndUpdateConfig("gui_details.yml"); customMiningSystem = pluginConfig.getBoolean("custom_mining_speeds", true); - if (customMiningSystem){ + if (customMiningSystem && !platform.supportsFolia()) { //todo breaks on folia packetListener = new PacketListener(new BlockBreakNetworkHandlerImpl()); packetListener.addAll(); registerListener(new CustomBreakSpeedListener()); @@ -321,6 +325,7 @@ private boolean setupNMS() { Class clazz = Class.forName("me.athlaeos.valhallammo.nms.NMS_" + nmsVersion); if (NMS.class.isAssignableFrom(clazz)) { + getLogger().info("Loading for version " + nmsVersion); nms = (NMS) clazz.getDeclaredConstructor().newInstance(); } @@ -442,6 +447,11 @@ public static boolean isCustomMiningEnabled() { } public static boolean isUsingPaperMC() { - return usingPaperMC; + return platform.supportsPaper(); + } + + @ApiStatus.Internal + public static ValhallaPlatform getPlatform() { + return platform; } } diff --git a/core/src/main/java/me/athlaeos/valhallammo/animations/implementations/ChargedShotAmmo.java b/core/src/main/java/me/athlaeos/valhallammo/animations/implementations/ChargedShotAmmo.java index 15c1f096..33b4ee1c 100644 --- a/core/src/main/java/me/athlaeos/valhallammo/animations/implementations/ChargedShotAmmo.java +++ b/core/src/main/java/me/athlaeos/valhallammo/animations/implementations/ChargedShotAmmo.java @@ -7,12 +7,12 @@ import me.athlaeos.valhallammo.skills.skills.implementations.ArcherySkill; import me.athlaeos.valhallammo.utility.MathUtils; import me.athlaeos.valhallammo.utility.Utils; +import me.athlaeos.valhallammo.utility.ValhallaRunnable; import org.bukkit.Location; import org.bukkit.Particle; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; -import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.util.Vector; import java.util.Collection; @@ -35,7 +35,7 @@ public ChargedShotAmmo(String id) { @Override public void animate(LivingEntity entity, Location location, Vector direction, int tick) { - if (entity instanceof Player p) new AmmoAnimation(p, ArcherySkill.getChargedShotCharges(p.getUniqueId())).runTaskTimer(ValhallaMMO.getInstance(), 1L, 1L); + if (entity instanceof Player p) new AmmoAnimation(p, ArcherySkill.getChargedShotCharges(p.getUniqueId())).runEntity(ValhallaMMO.getInstance(), p, 1L, 1L); } private static final double cP = MathUtils.cos(MathUtils.toRadians(0)); @@ -45,7 +45,7 @@ public void animate(LivingEntity entity, Location location, Vector direction, in private static final double cR = MathUtils.cos(MathUtils.toRadians(0)); private static final double sR = MathUtils.sin(MathUtils.toRadians(0)); - private static class AmmoAnimation extends BukkitRunnable{ + private static class AmmoAnimation extends ValhallaRunnable { private final Player p; private Collection circle; private int charges; diff --git a/core/src/main/java/me/athlaeos/valhallammo/animations/implementations/ChargedShotSonicBoom.java b/core/src/main/java/me/athlaeos/valhallammo/animations/implementations/ChargedShotSonicBoom.java index 3709520d..426bf3d5 100644 --- a/core/src/main/java/me/athlaeos/valhallammo/animations/implementations/ChargedShotSonicBoom.java +++ b/core/src/main/java/me/athlaeos/valhallammo/animations/implementations/ChargedShotSonicBoom.java @@ -5,6 +5,7 @@ import me.athlaeos.valhallammo.configuration.ConfigManager; import me.athlaeos.valhallammo.dom.Catch; import me.athlaeos.valhallammo.utility.MathUtils; +import me.athlaeos.valhallammo.utility.Scheduling; import me.athlaeos.valhallammo.utility.Utils; import org.bukkit.Location; import org.bukkit.Particle; @@ -48,9 +49,9 @@ public void animate(LivingEntity entity, Location location, Vector direction, in MathUtils.transformExistingPoints(normalizedCenter, 0, entity.getEyeLocation().getPitch() + 90, 0, 1, smallCircle); MathUtils.transformExistingPoints(normalizedCenter, entity.getEyeLocation().getYaw() + 180, 0, 0, 1, smallCircle); - ValhallaMMO.getInstance().getServer().getScheduler().runTaskLater(ValhallaMMO.getInstance(), () -> largeCircle.forEach(l -> pulse(entity.getWorld(), entity.getEyeLocation(), l, largeCircleCenter, 0.25)), 2L); - ValhallaMMO.getInstance().getServer().getScheduler().runTaskLater(ValhallaMMO.getInstance(), () -> middleCircle.forEach(l -> pulse(entity.getWorld(), entity.getEyeLocation(), l, middleCircleCenter, 0.15)), 4L); - ValhallaMMO.getInstance().getServer().getScheduler().runTaskLater(ValhallaMMO.getInstance(), () -> smallCircle.forEach(l -> pulse(entity.getWorld(), entity.getEyeLocation(), l, smallCircleCenter, 0.1)), 6L); + Scheduling.runEntityTask(ValhallaMMO.getInstance(), entity, 2L, () -> largeCircle.forEach(l -> pulse(entity.getWorld(), entity.getEyeLocation(), l, largeCircleCenter, 0.25))); + Scheduling.runEntityTask(ValhallaMMO.getInstance(), entity, 4L, () -> middleCircle.forEach(l -> pulse(entity.getWorld(), entity.getEyeLocation(), l, middleCircleCenter, 0.15))); + Scheduling.runEntityTask(ValhallaMMO.getInstance(), entity, 6L, () -> smallCircle.forEach(l -> pulse(entity.getWorld(), entity.getEyeLocation(), l, smallCircleCenter, 0.1))); } private void pulse(World w, Location location, Location particleLocation, Location center, double intensity){ diff --git a/core/src/main/java/me/athlaeos/valhallammo/animations/implementations/DrillingActive.java b/core/src/main/java/me/athlaeos/valhallammo/animations/implementations/DrillingActive.java index 67ffd071..6837d5f5 100644 --- a/core/src/main/java/me/athlaeos/valhallammo/animations/implementations/DrillingActive.java +++ b/core/src/main/java/me/athlaeos/valhallammo/animations/implementations/DrillingActive.java @@ -9,6 +9,7 @@ import me.athlaeos.valhallammo.utility.ItemUtils; import me.athlaeos.valhallammo.utility.Timer; import me.athlaeos.valhallammo.utility.Utils; +import me.athlaeos.valhallammo.utility.ValhallaRunnable; import org.bukkit.FluidCollisionMode; import org.bukkit.Location; import org.bukkit.Particle; @@ -17,7 +18,6 @@ import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; -import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.util.RayTraceResult; import org.bukkit.util.Vector; @@ -44,10 +44,10 @@ public DrillingActive(String id) { @Override public void animate(LivingEntity entity, Location location, Vector direction, int tick) { AccumulativeStatManager.updateStats(entity); - if (entity instanceof Player p && particle != null) new DrillingAnimation(p).runTaskTimer(ValhallaMMO.getInstance(), 1L, 1L); + if (entity instanceof Player p && particle != null) new DrillingAnimation(p).runEntity(ValhallaMMO.getInstance(), p, 1L, 1L); } - private static class DrillingAnimation extends BukkitRunnable{ + private static class DrillingAnimation extends ValhallaRunnable { private final Player p; public DrillingAnimation(Player p){ this.p = p; diff --git a/core/src/main/java/me/athlaeos/valhallammo/block/BlockDigProcess.java b/core/src/main/java/me/athlaeos/valhallammo/block/BlockDigProcess.java index 446cf2d5..581bd2f1 100644 --- a/core/src/main/java/me/athlaeos/valhallammo/block/BlockDigProcess.java +++ b/core/src/main/java/me/athlaeos/valhallammo/block/BlockDigProcess.java @@ -5,17 +5,18 @@ import me.athlaeos.valhallammo.item.MiningSpeed; import me.athlaeos.valhallammo.listeners.CustomBreakSpeedListener; import me.athlaeos.valhallammo.listeners.LootListener; +import me.athlaeos.valhallammo.platform.scheduler.TaskHolder; import me.athlaeos.valhallammo.playerstats.EntityCache; import me.athlaeos.valhallammo.playerstats.profiles.ProfileCache; import me.athlaeos.valhallammo.playerstats.profiles.implementations.MiningProfile; import me.athlaeos.valhallammo.utility.BlockUtils; import me.athlaeos.valhallammo.utility.ItemUtils; +import me.athlaeos.valhallammo.utility.Scheduling; import me.athlaeos.valhallammo.utility.Timer; import org.bukkit.Location; import org.bukkit.block.Block; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; -import org.bukkit.scheduler.BukkitTask; import java.util.*; @@ -52,7 +53,7 @@ public static void breakBlockInstantly(Player by, Block block){ if (instantBlockBreakerTask != null && !done) return; done = false; - instantBlockBreakerTask = ValhallaMMO.getInstance().getServer().getScheduler().runTask(ValhallaMMO.getInstance(), () -> { + instantBlockBreakerTask = Scheduling.runTask(ValhallaMMO.getInstance(), () -> { try { new HashSet<>((blocksToBreakInstantly.isEmpty() ? blocksToBreakInstantly2 : blocksToBreakInstantly).entrySet()).forEach(e -> { Player p = ValhallaMMO.getInstance().getServer().getPlayer(e.getKey()); @@ -93,7 +94,7 @@ public static void breakBlockInstantly(Player by, Block block){ } private static boolean done = false; - private static BukkitTask instantBlockBreakerTask = null; + private static TaskHolder instantBlockBreakerTask = null; private static final Map blocksToBreakInstantly = new HashMap<>(); private static final Map blocksToBreakInstantly2 = new HashMap<>(); @@ -102,7 +103,7 @@ public int getTicksSinceUpdate() { } public static void sendCracks(Block block, int cracks){ - ValhallaMMO.getInstance().getServer().getScheduler().runTask(ValhallaMMO.getInstance(), () -> { + Scheduling.runLocationTask(ValhallaMMO.getInstance(), block.getLocation(), () -> { for (Entity p : block.getWorld().getNearbyEntities(block.getLocation(), 20, 20, 20, (e) -> e instanceof Player)) ValhallaMMO.getNms().blockBreakAnimation((Player) p, block, getID(block), cracks); }); diff --git a/core/src/main/java/me/athlaeos/valhallammo/block/BlockInteractConversions.java b/core/src/main/java/me/athlaeos/valhallammo/block/BlockInteractConversions.java index fa0a00b6..53fa8402 100644 --- a/core/src/main/java/me/athlaeos/valhallammo/block/BlockInteractConversions.java +++ b/core/src/main/java/me/athlaeos/valhallammo/block/BlockInteractConversions.java @@ -8,6 +8,7 @@ import me.athlaeos.valhallammo.playerstats.profiles.ProfileCache; import me.athlaeos.valhallammo.playerstats.profiles.implementations.PowerProfile; import me.athlaeos.valhallammo.utility.ItemUtils; +import me.athlaeos.valhallammo.utility.Scheduling; import org.bukkit.EntityEffect; import org.bukkit.Material; import org.bukkit.Sound; @@ -113,8 +114,8 @@ else if (!ItemUtils.isEmpty(user.getInventory().getItemInOffHand()) && user, true, mainHand ? EquipmentSlot.HAND : EquipmentSlot.OFF_HAND); ValhallaMMO.getInstance().getServer().getPluginManager().callEvent(event); if (event.isCancelled()) return false; - if (clicked.getBlockData() instanceof Stairs s1) ValhallaMMO.getInstance().getServer().getScheduler().runTaskLater(ValhallaMMO.getInstance(), () -> { if (clicked.getBlockData() instanceof Stairs s2) s2.setShape(s1.getShape()); },1L); - if (clicked.getBlockData() instanceof Slab s1) ValhallaMMO.getInstance().getServer().getScheduler().runTaskLater(ValhallaMMO.getInstance(), () -> { if (clicked.getBlockData() instanceof Slab s2) s2.setType(s1.getType()); },1L); + if (clicked.getBlockData() instanceof Stairs s1) Scheduling.runLocationTask(ValhallaMMO.getInstance(), clicked.getLocation(), 1L, () -> { if (clicked.getBlockData() instanceof Stairs s2) s2.setShape(s1.getShape()); }); + if (clicked.getBlockData() instanceof Slab s1) Scheduling.runLocationTask(ValhallaMMO.getInstance(), clicked.getLocation(), 1L, () -> { if (clicked.getBlockData() instanceof Slab s2) s2.setType(s1.getType()); }); clicked.setType(conversion.to); if (conversion.sound != null) user.playSound(user.getLocation(), conversion.sound, 1F, 1F); diff --git a/core/src/main/java/me/athlaeos/valhallammo/commands/valhallasubcommands/SaveAllCommand.java b/core/src/main/java/me/athlaeos/valhallammo/commands/valhallasubcommands/SaveAllCommand.java index 43e211c7..1c3941fc 100644 --- a/core/src/main/java/me/athlaeos/valhallammo/commands/valhallasubcommands/SaveAllCommand.java +++ b/core/src/main/java/me/athlaeos/valhallammo/commands/valhallasubcommands/SaveAllCommand.java @@ -10,6 +10,7 @@ import me.athlaeos.valhallammo.parties.PartyManager; import me.athlaeos.valhallammo.playerstats.profiles.ProfileRegistry; import me.athlaeos.valhallammo.utility.GlobalEffect; +import me.athlaeos.valhallammo.utility.Scheduling; import me.athlaeos.valhallammo.utility.Utils; import org.bukkit.command.CommandSender; @@ -21,7 +22,7 @@ public boolean execute(CommandSender sender, String[] args) { ProfileRegistry.saveAll(); CustomRecipeRegistry.saveRecipes(true); - ValhallaMMO.getInstance().getServer().getScheduler().runTaskAsynchronously(ValhallaMMO.getInstance(), () -> { + Scheduling.runTaskAsync(ValhallaMMO.getInstance(), () -> { PartyManager.saveParties(); GlobalEffect.saveActiveGlobalEffects(); CustomItemRegistry.saveItems(); diff --git a/core/src/main/java/me/athlaeos/valhallammo/crafting/CustomRecipeRegistry.java b/core/src/main/java/me/athlaeos/valhallammo/crafting/CustomRecipeRegistry.java index 852b033b..873ad055 100644 --- a/core/src/main/java/me/athlaeos/valhallammo/crafting/CustomRecipeRegistry.java +++ b/core/src/main/java/me/athlaeos/valhallammo/crafting/CustomRecipeRegistry.java @@ -16,6 +16,7 @@ import me.athlaeos.valhallammo.listeners.CookingListener; import me.athlaeos.valhallammo.listeners.SmithingTableListener; import me.athlaeos.valhallammo.utility.ItemUtils; +import me.athlaeos.valhallammo.utility.Scheduling; import me.athlaeos.valhallammo.version.SmithingTransformRecipeWrapper; import org.bukkit.Material; import org.bukkit.NamespacedKey; @@ -105,7 +106,7 @@ public static Collection getDisabledRecipes() { public static void saveRecipes(boolean async){ if (!changesMade) return; - if (async) ValhallaMMO.getInstance().getServer().getScheduler().runTaskAsynchronously(ValhallaMMO.getInstance(), CustomRecipeRegistry::saveAllRecipeTypes); + if (async) Scheduling.runTaskAsync(ValhallaMMO.getInstance(), CustomRecipeRegistry::saveAllRecipeTypes); else saveAllRecipeTypes(); } @@ -132,54 +133,54 @@ private static void saveAllRecipeTypes(){ public static void loadBrewingRecipes(File file, boolean overwrite){ if (!file.exists()) return; ValhallaMMO.logInfo("Loading brewing recipes from " + file.getPath()); - ValhallaMMO.getInstance().getServer().getScheduler().runTaskAsynchronously(ValhallaMMO.getInstance(), () -> + Scheduling.runTaskAsync(ValhallaMMO.getInstance(), () -> brewingRecipePersistence.getRecipesFromFile(file).forEach((k, r) -> - ValhallaMMO.getInstance().getServer().getScheduler().runTask(ValhallaMMO.getInstance(), () -> register((DynamicBrewingRecipe) r, overwrite)) + Scheduling.runTask(ValhallaMMO.getInstance(), () -> register((DynamicBrewingRecipe) r, overwrite)) ) ); } public static void loadCauldronRecipes(File file, boolean overwrite){ if (!file.exists()) return; ValhallaMMO.logInfo("Loading cauldron recipes from " + file.getPath()); - ValhallaMMO.getInstance().getServer().getScheduler().runTaskAsynchronously(ValhallaMMO.getInstance(), () -> + Scheduling.runTaskAsync(ValhallaMMO.getInstance(), () -> cauldronRecipePersistence.getRecipesFromFile(file).forEach((k, r) -> - ValhallaMMO.getInstance().getServer().getScheduler().runTask(ValhallaMMO.getInstance(), () -> register((DynamicCauldronRecipe) r, overwrite)) + Scheduling.runTask(ValhallaMMO.getInstance(), () -> register((DynamicCauldronRecipe) r, overwrite)) ) ); } public static void loadCookingRecipes(File file, boolean overwrite){ if (!file.exists()) return; ValhallaMMO.logInfo("Loading cooking recipes from " + file.getPath()); - ValhallaMMO.getInstance().getServer().getScheduler().runTaskAsynchronously(ValhallaMMO.getInstance(), () -> + Scheduling.runTaskAsync(ValhallaMMO.getInstance(), () -> cookingRecipePersistence.getRecipesFromFile(file).forEach((k, r) -> - ValhallaMMO.getInstance().getServer().getScheduler().runTask(ValhallaMMO.getInstance(), () -> register((DynamicCookingRecipe) r, overwrite)) + Scheduling.runTask(ValhallaMMO.getInstance(), () -> register((DynamicCookingRecipe) r, overwrite)) ) ); } public static void loadGridRecipes(File file, boolean overwrite){ if (!file.exists()) return; ValhallaMMO.logInfo("Loading crafting grid recipes from " + file.getPath()); - ValhallaMMO.getInstance().getServer().getScheduler().runTaskAsynchronously(ValhallaMMO.getInstance(), () -> + Scheduling.runTaskAsync(ValhallaMMO.getInstance(), () -> gridRecipePersistence.getRecipesFromFile(file).forEach((k, r) -> - ValhallaMMO.getInstance().getServer().getScheduler().runTask(ValhallaMMO.getInstance(), () -> register((DynamicGridRecipe) r, overwrite)) + Scheduling.runTask(ValhallaMMO.getInstance(), () -> register((DynamicGridRecipe) r, overwrite)) ) ); } public static void loadSmithingRecipes(File file, boolean overwrite){ if (!file.exists()) return; ValhallaMMO.logInfo("Loading smithing recipes from " + file.getPath()); - ValhallaMMO.getInstance().getServer().getScheduler().runTaskAsynchronously(ValhallaMMO.getInstance(), () -> + Scheduling.runTaskAsync(ValhallaMMO.getInstance(), () -> smithingRecipePersistence.getRecipesFromFile(file).forEach((k, r) -> - ValhallaMMO.getInstance().getServer().getScheduler().runTask(ValhallaMMO.getInstance(), () -> register((DynamicSmithingRecipe) r, overwrite)) + Scheduling.runTask(ValhallaMMO.getInstance(), () -> register((DynamicSmithingRecipe) r, overwrite)) ) ); } public static void loadImmersiveRecipes(File file, boolean overwrite){ if (!file.exists()) return; ValhallaMMO.logInfo("Loading immersive recipes from " + file.getPath()); - ValhallaMMO.getInstance().getServer().getScheduler().runTaskAsynchronously(ValhallaMMO.getInstance(), () -> + Scheduling.runTaskAsync(ValhallaMMO.getInstance(), () -> immersiveRecipePersistence.getRecipesFromFile(file).forEach((k, r) -> - ValhallaMMO.getInstance().getServer().getScheduler().runTask(ValhallaMMO.getInstance(), () -> register((ImmersiveCraftingRecipe) r, overwrite)) + Scheduling.runTask(ValhallaMMO.getInstance(), () -> register((ImmersiveCraftingRecipe) r, overwrite)) ) ); } diff --git a/core/src/main/java/me/athlaeos/valhallammo/entities/Dummy.java b/core/src/main/java/me/athlaeos/valhallammo/entities/Dummy.java index 22e539af..7f73170b 100644 --- a/core/src/main/java/me/athlaeos/valhallammo/entities/Dummy.java +++ b/core/src/main/java/me/athlaeos/valhallammo/entities/Dummy.java @@ -5,6 +5,7 @@ import me.athlaeos.valhallammo.playerstats.EntityCache; import me.athlaeos.valhallammo.playerstats.EntityProperties; import me.athlaeos.valhallammo.utility.ItemUtils; +import me.athlaeos.valhallammo.utility.Scheduling; import org.bukkit.NamespacedKey; import org.bukkit.entity.AbstractArrow; import org.bukkit.entity.ArmorStand; @@ -70,11 +71,11 @@ public void onArrowHitDummy(ProjectileHitEvent e){ !isDummy(l)) return; ItemBuilder stored = ItemUtils.getStoredItem(a); if (stored == null) return; - ValhallaMMO.getInstance().getServer().getScheduler().runTaskLater(ValhallaMMO.getInstance(), () -> { + Scheduling.runEntityTask(ValhallaMMO.getInstance(), a, 2L, () -> { if (a.isValid()) { if (a.getPickupStatus() == AbstractArrow.PickupStatus.ALLOWED) a.getWorld().dropItem(a.getLocation(), stored.get()); a.remove(); } - }, 2L); + }); } } diff --git a/core/src/main/java/me/athlaeos/valhallammo/entities/MonsterScalingManager.java b/core/src/main/java/me/athlaeos/valhallammo/entities/MonsterScalingManager.java index 2b8b019d..663536f6 100644 --- a/core/src/main/java/me/athlaeos/valhallammo/entities/MonsterScalingManager.java +++ b/core/src/main/java/me/athlaeos/valhallammo/entities/MonsterScalingManager.java @@ -7,6 +7,7 @@ import me.athlaeos.valhallammo.playerstats.AccumulativeStatManager; import me.athlaeos.valhallammo.playerstats.profiles.ProfileCache; import me.athlaeos.valhallammo.playerstats.profiles.implementations.PowerProfile; +import me.athlaeos.valhallammo.utility.Scheduling; import me.athlaeos.valhallammo.utility.Timer; import me.athlaeos.valhallammo.utility.Utils; import org.apache.commons.lang.StringUtils; @@ -269,7 +270,7 @@ public static double getAreaDifficultyLevel(Location l, Player cacheFor){ public static double getCachedDifficultyLevel(Player from){ if (Timer.isCooldownPassed(from.getUniqueId(), "delay_regional_difficulty_cache_update")){ - ValhallaMMO.getInstance().getServer().getScheduler().runTask(ValhallaMMO.getInstance(), () -> getAreaDifficultyLevel(from.getLocation(), from)); + Scheduling.runLocationTask(ValhallaMMO.getInstance(), from.getLocation(), () -> getAreaDifficultyLevel(from.getLocation(), from)); Timer.setCooldown(from.getUniqueId(), 10000, "delay_regional_difficulty_cache_update"); } return regionalMonsterLevelCache.getOrDefault(from.getUniqueId(), 0D); diff --git a/core/src/main/java/me/athlaeos/valhallammo/entities/damageindicators/implementations/TextDisplayDPSIndicator.java b/core/src/main/java/me/athlaeos/valhallammo/entities/damageindicators/implementations/TextDisplayDPSIndicator.java index 70cf2b91..f7794764 100644 --- a/core/src/main/java/me/athlaeos/valhallammo/entities/damageindicators/implementations/TextDisplayDPSIndicator.java +++ b/core/src/main/java/me/athlaeos/valhallammo/entities/damageindicators/implementations/TextDisplayDPSIndicator.java @@ -9,10 +9,10 @@ import me.athlaeos.valhallammo.localization.TranslationManager; import me.athlaeos.valhallammo.skills.ChunkEXPNerf; import me.athlaeos.valhallammo.utility.Utils; +import me.athlaeos.valhallammo.utility.ValhallaRunnable; import org.bukkit.EntityEffect; import org.bukkit.entity.*; import org.bukkit.event.player.PlayerTeleportEvent; -import org.bukkit.scheduler.BukkitRunnable; import java.util.*; @@ -72,12 +72,12 @@ public static boolean update(LivingEntity damaged, CustomDamageType damageType, damageIndicatorMap.get(damaged.getUniqueId()).get(type).priority = index; index++; } - instance.runTaskTimer(ValhallaMMO.getInstance(), 0L, 1L); + instance.runEntity(ValhallaMMO.getInstance(), damaged, 0L, 1L); } return Dummy.isDummy(damaged); } - private static class DPSInstance extends BukkitRunnable { + private static class DPSInstance extends ValhallaRunnable { private final UUID id; private final LivingEntity damaged; private final CustomDamageType type; @@ -144,7 +144,7 @@ public void update(double damage, double mitigated, boolean crit){ DPSInstance newInstance = new DPSInstance(damaged, type, damage, mitigated, crit); instances.put(type, newInstance); damageIndicatorMap.put(damaged.getUniqueId(), instances); - newInstance.runTaskTimer(ValhallaMMO.getInstance(), 0L, 1L); + newInstance.runEntity(ValhallaMMO.getInstance(), damaged, 0L, 1L); int index = 0; for (CustomDamageType type : damageIndicatorMap.get(damaged.getUniqueId()).keySet()){ diff --git a/core/src/main/java/me/athlaeos/valhallammo/gui/implementations/BrewingRecipeEditor.java b/core/src/main/java/me/athlaeos/valhallammo/gui/implementations/BrewingRecipeEditor.java index a6a15fc6..86222a26 100644 --- a/core/src/main/java/me/athlaeos/valhallammo/gui/implementations/BrewingRecipeEditor.java +++ b/core/src/main/java/me/athlaeos/valhallammo/gui/implementations/BrewingRecipeEditor.java @@ -18,6 +18,7 @@ import me.athlaeos.valhallammo.item.ItemBuilder; import me.athlaeos.valhallammo.localization.TranslationManager; import me.athlaeos.valhallammo.utility.ItemUtils; +import me.athlaeos.valhallammo.utility.Scheduling; import me.athlaeos.valhallammo.utility.StringUtils; import me.athlaeos.valhallammo.utility.Utils; import me.athlaeos.valhallammo.version.EnchantmentMappings; @@ -445,7 +446,8 @@ public List getResultModifiers() { public void setRecipeOption(RecipeOption option) { this.selectedChoice = option; if (option == null) return; - ValhallaMMO.getInstance().getServer().getScheduler().runTaskLater(ValhallaMMO.getInstance(), () -> - playerMenuUtility.getOwner().setItemOnCursor(new ItemBuilder(option.getIcon()).stringTag(KEY_OPTION_ID, option.getName()).get()), 1L); + Scheduling.runEntityTask(ValhallaMMO.getInstance(), playerMenuUtility.getOwner(), 1L, () -> + playerMenuUtility.getOwner().setItemOnCursor(new ItemBuilder(option.getIcon()).stringTag(KEY_OPTION_ID, option.getName()).get()) + ); } } diff --git a/core/src/main/java/me/athlaeos/valhallammo/gui/implementations/GridRecipeEditor.java b/core/src/main/java/me/athlaeos/valhallammo/gui/implementations/GridRecipeEditor.java index 0723c29c..dfa37bfd 100644 --- a/core/src/main/java/me/athlaeos/valhallammo/gui/implementations/GridRecipeEditor.java +++ b/core/src/main/java/me/athlaeos/valhallammo/gui/implementations/GridRecipeEditor.java @@ -19,6 +19,7 @@ import me.athlaeos.valhallammo.item.ItemBuilder; import me.athlaeos.valhallammo.localization.TranslationManager; import me.athlaeos.valhallammo.utility.ItemUtils; +import me.athlaeos.valhallammo.utility.Scheduling; import me.athlaeos.valhallammo.utility.StringUtils; import me.athlaeos.valhallammo.utility.Utils; import me.athlaeos.valhallammo.version.EnchantmentMappings; @@ -632,8 +633,8 @@ public List getResultModifiers() { public void setRecipeOption(RecipeOption option) { this.selectedOption = option; if (option == null) return; - ValhallaMMO.getInstance().getServer().getScheduler().runTaskLater(ValhallaMMO.getInstance(), () -> - playerMenuUtility.getOwner().setItemOnCursor(new ItemBuilder(option.getIcon()).stringTag(KEY_OPTION_ID, option.getName()).get()), 1L); + Scheduling.runEntityTask(ValhallaMMO.getInstance(), playerMenuUtility.getOwner(), 1L, () -> + playerMenuUtility.getOwner().setItemOnCursor(new ItemBuilder(option.getIcon()).stringTag(KEY_OPTION_ID, option.getName()).get())); } @Override diff --git a/core/src/main/java/me/athlaeos/valhallammo/gui/implementations/ImmersiveRecipeSelectionMenu.java b/core/src/main/java/me/athlaeos/valhallammo/gui/implementations/ImmersiveRecipeSelectionMenu.java index 5e5aa641..23ba0694 100644 --- a/core/src/main/java/me/athlaeos/valhallammo/gui/implementations/ImmersiveRecipeSelectionMenu.java +++ b/core/src/main/java/me/athlaeos/valhallammo/gui/implementations/ImmersiveRecipeSelectionMenu.java @@ -19,6 +19,7 @@ import me.athlaeos.valhallammo.playerstats.profiles.ProfileCache; import me.athlaeos.valhallammo.playerstats.profiles.implementations.PowerProfile; import me.athlaeos.valhallammo.utility.ItemUtils; +import me.athlaeos.valhallammo.utility.Scheduling; import me.athlaeos.valhallammo.utility.StringUtils; import me.athlaeos.valhallammo.utility.Utils; import net.md_5.bungee.api.ChatMessageType; @@ -233,7 +234,7 @@ private void buildMenuItems(final ItemBuilderCallback callback){ List defaultFormat = TranslationManager.getListTranslation("immersive_recipe_button_format"); String ingredientFormat = TranslationManager.getTranslation("recipe_ingredient_format"); double craftingTimeReduction = AccumulativeStatManager.getCachedStats("CRAFTING_TIME_REDUCTION", playerMenuUtility.getOwner(), 10000, true); - ValhallaMMO.getInstance().getServer().getScheduler().runTaskAsynchronously(ValhallaMMO.getInstance(), () -> { + Scheduling.runEntityTaskAsync(ValhallaMMO.getInstance(), playerMenuUtility.getOwner(), () -> { List icons = new ArrayList<>(); for (ImmersiveCraftingRecipe recipe : recipes){ if (!view.shouldShow(playerMenuUtility.getOwner(), recipe)) continue; @@ -294,7 +295,7 @@ else if (recipe.getIngredients().keySet().stream().anyMatch(i -> recipe.getMetaR displayName)).lore(lore).stringTag(BUTTON_RECIPE_KEY, recipe.getName()).translate().get()); } - ValhallaMMO.getInstance().getServer().getScheduler().runTask(ValhallaMMO.getInstance(), () -> callback.onItemsBuilt(icons)); + Scheduling.runEntityTaskAsync(ValhallaMMO.getInstance(), playerMenuUtility.getOwner(), () -> callback.onItemsBuilt(icons)); }); } diff --git a/core/src/main/java/me/athlaeos/valhallammo/gui/implementations/SkillTreeMenu.java b/core/src/main/java/me/athlaeos/valhallammo/gui/implementations/SkillTreeMenu.java index a5ad161a..f4315fd0 100644 --- a/core/src/main/java/me/athlaeos/valhallammo/gui/implementations/SkillTreeMenu.java +++ b/core/src/main/java/me/athlaeos/valhallammo/gui/implementations/SkillTreeMenu.java @@ -23,6 +23,7 @@ import me.athlaeos.valhallammo.skills.skills.SkillRegistry; import me.athlaeos.valhallammo.skills.skills.implementations.PowerSkill; import me.athlaeos.valhallammo.utility.ItemUtils; +import me.athlaeos.valhallammo.utility.Scheduling; import me.athlaeos.valhallammo.utility.StringUtils; import me.athlaeos.valhallammo.utility.Utils; import me.athlaeos.valhallammo.version.ConventionUtils; @@ -175,7 +176,7 @@ public void handleMenu(InventoryClickEvent e) { // remove resources for (ResourceExpense expense : p.getExpenses()) expense.purchase(target, true); - ValhallaMMO.getInstance().getServer().getScheduler().runTaskLater(ValhallaMMO.getInstance(), this::setMenuItems, 2L); + Scheduling.runTaskLater(ValhallaMMO.getInstance(), 2L, this::setMenuItems); } else perkConfirmation = p.getName(); } else { for (ResourceExpense expense : p.getExpenses()){ @@ -413,7 +414,7 @@ private ItemStack[][] getSkillTreeView(Skill skill){ } private void buildSkillTrees(){ - ValhallaMMO.getInstance().getServer().getScheduler().runTaskAsynchronously(ValhallaMMO.getInstance(), () -> { + Scheduling.runTaskAsync(ValhallaMMO.getInstance(), () -> { List skills = new ArrayList<>(SkillRegistry.getAllSkills().values()); skills.sort(Comparator.comparingInt(Skill::getSkillTreeMenuOrderPriority)); for (Skill s : skills){ diff --git a/core/src/main/java/me/athlaeos/valhallammo/gui/implementations/SmithingRecipeEditor.java b/core/src/main/java/me/athlaeos/valhallammo/gui/implementations/SmithingRecipeEditor.java index e07eeb99..e332c500 100644 --- a/core/src/main/java/me/athlaeos/valhallammo/gui/implementations/SmithingRecipeEditor.java +++ b/core/src/main/java/me/athlaeos/valhallammo/gui/implementations/SmithingRecipeEditor.java @@ -17,6 +17,7 @@ import me.athlaeos.valhallammo.item.ItemBuilder; import me.athlaeos.valhallammo.localization.TranslationManager; import me.athlaeos.valhallammo.utility.ItemUtils; +import me.athlaeos.valhallammo.utility.Scheduling; import me.athlaeos.valhallammo.utility.StringUtils; import me.athlaeos.valhallammo.utility.Utils; import me.athlaeos.valhallammo.version.EnchantmentMappings; @@ -504,8 +505,9 @@ public List getResultModifiers() { public void setRecipeOption(RecipeOption option) { this.selectedChoice = option; if (option == null) return; - ValhallaMMO.getInstance().getServer().getScheduler().runTaskLater(ValhallaMMO.getInstance(), () -> - playerMenuUtility.getOwner().setItemOnCursor(new ItemBuilder(option.getIcon()).stringTag(KEY_OPTION_ID, option.getName()).get()), 1L); + Scheduling.runTaskLater(ValhallaMMO.getInstance(), 1L, () -> + playerMenuUtility.getOwner().setItemOnCursor(new ItemBuilder(option.getIcon()).stringTag(KEY_OPTION_ID, option.getName()).get()) + ); } @Override diff --git a/core/src/main/java/me/athlaeos/valhallammo/hooks/DecentHologramsHook.java b/core/src/main/java/me/athlaeos/valhallammo/hooks/DecentHologramsHook.java index 556b73b8..2cf58890 100644 --- a/core/src/main/java/me/athlaeos/valhallammo/hooks/DecentHologramsHook.java +++ b/core/src/main/java/me/athlaeos/valhallammo/hooks/DecentHologramsHook.java @@ -9,11 +9,11 @@ import me.athlaeos.valhallammo.localization.TranslationManager; import me.athlaeos.valhallammo.skills.ChunkEXPNerf; import me.athlaeos.valhallammo.utility.Utils; +import me.athlaeos.valhallammo.utility.ValhallaRunnable; import org.bukkit.entity.Entity; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.event.Listener; -import org.bukkit.scheduler.BukkitRunnable; import java.util.*; @@ -59,12 +59,12 @@ public static boolean update(LivingEntity damaged, CustomDamageType damageType, damageIndicatorMap.get(damaged.getUniqueId()).get(type).priority = index; index++; } - instance.runTaskTimer(ValhallaMMO.getInstance(), 0L, 1L); + instance.runEntity(ValhallaMMO.getInstance(), damaged,0L, 1L); } return Dummy.isDummy(damaged); } - private static class DPSInstance extends BukkitRunnable { + private static class DPSInstance extends ValhallaRunnable { private final UUID id; private final LivingEntity damaged; private final CustomDamageType type; diff --git a/core/src/main/java/me/athlaeos/valhallammo/item/PermanentPotionEffects.java b/core/src/main/java/me/athlaeos/valhallammo/item/PermanentPotionEffects.java index 3fd5b638..f6a83bff 100644 --- a/core/src/main/java/me/athlaeos/valhallammo/item/PermanentPotionEffects.java +++ b/core/src/main/java/me/athlaeos/valhallammo/item/PermanentPotionEffects.java @@ -4,6 +4,7 @@ import me.athlaeos.valhallammo.dom.Catch; import me.athlaeos.valhallammo.playerstats.EntityCache; import me.athlaeos.valhallammo.playerstats.EntityProperties; +import me.athlaeos.valhallammo.utility.Scheduling; import me.athlaeos.valhallammo.utility.StringUtils; import me.athlaeos.valhallammo.version.PotionEffectMappings; import org.bukkit.NamespacedKey; @@ -29,7 +30,8 @@ public class PermanentPotionEffects { private static final Collection entitiesWithPermanentEffects = new HashSet<>(); public static void initializeRunnable(){ - ValhallaMMO.getInstance().getServer().getScheduler().runTaskTimer(ValhallaMMO.getInstance(), () -> { + //todo check folia support + Scheduling.runTaskTimer(ValhallaMMO.getInstance(), 80L, 80L, () -> { for (UUID uuid : new HashSet<>(entitiesWithPermanentEffects)){ Entity e = ValhallaMMO.getInstance().getServer().getEntity(uuid); if (e == null || !e.isValid() || e.isDead() || !(e instanceof LivingEntity l) || (e instanceof Player p && !p.isOnline())) { @@ -44,7 +46,7 @@ public static void initializeRunnable(){ } for (PotionEffect effect : effects) l.addPotionEffect(effect); } - }, 80L, 80L); + }); } public static List fromString(String str){ diff --git a/core/src/main/java/me/athlaeos/valhallammo/item/arrow_attributes/implementations/NoGravityArrow.java b/core/src/main/java/me/athlaeos/valhallammo/item/arrow_attributes/implementations/NoGravityArrow.java index a49809c8..e1f06d7d 100644 --- a/core/src/main/java/me/athlaeos/valhallammo/item/arrow_attributes/implementations/NoGravityArrow.java +++ b/core/src/main/java/me/athlaeos/valhallammo/item/arrow_attributes/implementations/NoGravityArrow.java @@ -2,12 +2,12 @@ import me.athlaeos.valhallammo.ValhallaMMO; import me.athlaeos.valhallammo.item.item_attributes.ArrowBehavior; +import me.athlaeos.valhallammo.utility.ValhallaRunnable; import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityShootBowEvent; import org.bukkit.event.entity.ProjectileHitEvent; import org.bukkit.event.entity.ProjectileLaunchEvent; import org.bukkit.event.player.PlayerPickupArrowEvent; -import org.bukkit.scheduler.BukkitRunnable; public class NoGravityArrow extends ArrowBehavior { @@ -18,12 +18,12 @@ public NoGravityArrow(String name) { @Override public void onShoot(EntityShootBowEvent e, double... args) { e.getProjectile().setGravity(false); - new BukkitRunnable(){ + new ValhallaRunnable(){ @Override public void run() { e.getProjectile().remove(); } - }.runTaskLater(ValhallaMMO.getInstance(), 200); + }.runEntity(ValhallaMMO.getInstance(), e.getProjectile(), 200); } @Override diff --git a/core/src/main/java/me/athlaeos/valhallammo/item/arrow_attributes/implementations/VoidImmunityArrow.java b/core/src/main/java/me/athlaeos/valhallammo/item/arrow_attributes/implementations/VoidImmunityArrow.java index 5cb17279..5bfb3c45 100644 --- a/core/src/main/java/me/athlaeos/valhallammo/item/arrow_attributes/implementations/VoidImmunityArrow.java +++ b/core/src/main/java/me/athlaeos/valhallammo/item/arrow_attributes/implementations/VoidImmunityArrow.java @@ -4,6 +4,7 @@ import me.athlaeos.valhallammo.particle.implementations.GenericParticle; import me.athlaeos.valhallammo.item.item_attributes.ArrowBehavior; import me.athlaeos.valhallammo.utility.AnimationUtils; +import me.athlaeos.valhallammo.utility.ValhallaRunnable; import org.bukkit.Particle; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Projectile; @@ -12,7 +13,6 @@ import org.bukkit.event.entity.ProjectileHitEvent; import org.bukkit.event.entity.ProjectileLaunchEvent; import org.bukkit.event.player.PlayerPickupArrowEvent; -import org.bukkit.scheduler.BukkitRunnable; public class VoidImmunityArrow extends ArrowBehavior { @@ -38,12 +38,12 @@ public void onLaunch(ProjectileLaunchEvent e, double... args) { @Override public void onDamage(EntityDamageByEntityEvent e, double... args) { if (e.getEntity() instanceof LivingEntity l){ - new BukkitRunnable(){ + new ValhallaRunnable(){ @Override public void run() { l.setNoDamageTicks(0); } - }.runTaskLater(ValhallaMMO.getInstance(), 1L); + }.runEntity(ValhallaMMO.getInstance(), l, 1L); } } diff --git a/core/src/main/java/me/athlaeos/valhallammo/item/throwable_weapon_animations/ThrownItem.java b/core/src/main/java/me/athlaeos/valhallammo/item/throwable_weapon_animations/ThrownItem.java index 26789216..ebbe25d6 100644 --- a/core/src/main/java/me/athlaeos/valhallammo/item/throwable_weapon_animations/ThrownItem.java +++ b/core/src/main/java/me/athlaeos/valhallammo/item/throwable_weapon_animations/ThrownItem.java @@ -6,6 +6,7 @@ import me.athlaeos.valhallammo.item.item_attributes.AttributeWrapper; import me.athlaeos.valhallammo.utility.ItemUtils; import me.athlaeos.valhallammo.utility.MathUtils; +import me.athlaeos.valhallammo.utility.ValhallaRunnable; import org.bukkit.Location; import org.bukkit.NamespacedKey; import org.bukkit.entity.ArmorStand; @@ -13,7 +14,6 @@ import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.ItemStack; import org.bukkit.persistence.PersistentDataType; -import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.util.Vector; import java.util.Collection; @@ -29,7 +29,7 @@ public static UUID getThrownBy(ArmorStand a){ } private final ArmorStand stand; - private final BukkitRunnable runnable; + private final ValhallaRunnable runnable; private final ItemBuilder item; private final ThrowableItemStats stats; @@ -88,7 +88,7 @@ public ThrownItem(Player thrower, EquipmentSlot hand, ItemBuilder item, Throwabl } final ThrownItem instance = this; - runnable = new BukkitRunnable(){ + runnable = new ValhallaRunnable(){ @Override public void run() { animation.tick(instance); diff --git a/core/src/main/java/me/athlaeos/valhallammo/listeners/ArmorSwitchListener.java b/core/src/main/java/me/athlaeos/valhallammo/listeners/ArmorSwitchListener.java index 676c54e0..d3a67a36 100644 --- a/core/src/main/java/me/athlaeos/valhallammo/listeners/ArmorSwitchListener.java +++ b/core/src/main/java/me/athlaeos/valhallammo/listeners/ArmorSwitchListener.java @@ -6,6 +6,7 @@ import me.athlaeos.valhallammo.playerstats.AccumulativeStatManager; import me.athlaeos.valhallammo.playerstats.EntityCache; import me.athlaeos.valhallammo.utility.ItemUtils; +import me.athlaeos.valhallammo.utility.ValhallaRunnable; import org.bukkit.entity.Player; import org.bukkit.event.Event; import org.bukkit.event.EventHandler; @@ -17,7 +18,6 @@ import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.ItemStack; -import org.bukkit.scheduler.BukkitRunnable; import java.util.HashMap; import java.util.Map; @@ -82,7 +82,7 @@ public void onHandEquip(PlayerInteractEvent e){ updateArmor(e.getPlayer()); } - private static class DelayedArmorUpdate extends BukkitRunnable{ + private static class DelayedArmorUpdate extends ValhallaRunnable { private static final int delay = 30; // after 1.5 seconds update equipment private int timer = delay; private final Player who; diff --git a/core/src/main/java/me/athlaeos/valhallammo/listeners/BlockListener.java b/core/src/main/java/me/athlaeos/valhallammo/listeners/BlockListener.java index 566cc564..80d2ce4d 100644 --- a/core/src/main/java/me/athlaeos/valhallammo/listeners/BlockListener.java +++ b/core/src/main/java/me/athlaeos/valhallammo/listeners/BlockListener.java @@ -4,6 +4,7 @@ import me.athlaeos.valhallammo.playerstats.AccumulativeStatManager; import me.athlaeos.valhallammo.utility.BlockStore; import me.athlaeos.valhallammo.utility.BlockUtils; +import me.athlaeos.valhallammo.utility.Scheduling; import org.bukkit.GameMode; import org.bukkit.Location; import org.bukkit.block.Block; @@ -31,13 +32,25 @@ public class BlockListener implements Listener { public BlockListener(){ - ValhallaMMO.getInstance().getServer().getScheduler().runTaskTimer(ValhallaMMO.getInstance(), () -> { - for (Location b : blocksToConsiderBroken) { - BlockStore.setPlaced(b.getBlock(), false); - BlockStore.setBreakReason(b.getBlock(), BlockStore.BreakReason.MINED); - } - blocksToConsiderBroken.clear(); - }, 0L, 5L); + if (ValhallaMMO.getPlatform().supportsFolia()) { + Scheduling.runTaskTimerAsync(ValhallaMMO.getInstance(), 1L, 1L, ()-> { + for (Location b : blocksToConsiderBroken) { + Scheduling.runLocationTask(ValhallaMMO.getInstance(), b, () -> { + BlockStore.setPlaced(b.getBlock(), false); + BlockStore.setBreakReason(b.getBlock(), BlockStore.BreakReason.MINED); + }); + } + blocksToConsiderBroken.clear(); + }); + } else { + Scheduling.runTaskTimer(ValhallaMMO.getInstance(), 0L, 5L, () -> { + for (Location b : blocksToConsiderBroken) { + BlockStore.setPlaced(b.getBlock(), false); + BlockStore.setBreakReason(b.getBlock(), BlockStore.BreakReason.MINED); + } + blocksToConsiderBroken.clear(); + }); + } } @EventHandler(priority = EventPriority.MONITOR) diff --git a/core/src/main/java/me/athlaeos/valhallammo/listeners/BrewingStandListener.java b/core/src/main/java/me/athlaeos/valhallammo/listeners/BrewingStandListener.java index 1f3744bb..143e9948 100644 --- a/core/src/main/java/me/athlaeos/valhallammo/listeners/BrewingStandListener.java +++ b/core/src/main/java/me/athlaeos/valhallammo/listeners/BrewingStandListener.java @@ -11,9 +11,7 @@ import me.athlaeos.valhallammo.playerstats.AccumulativeStatManager; import me.athlaeos.valhallammo.playerstats.profiles.ProfileCache; import me.athlaeos.valhallammo.playerstats.profiles.implementations.PowerProfile; -import me.athlaeos.valhallammo.utility.BlockUtils; -import me.athlaeos.valhallammo.utility.ItemUtils; -import me.athlaeos.valhallammo.utility.Utils; +import me.athlaeos.valhallammo.utility.*; import me.athlaeos.valhallammo.version.BrewingPreventionListener; import org.bukkit.Location; import org.bukkit.Material; @@ -26,7 +24,6 @@ import org.bukkit.event.inventory.*; import org.bukkit.inventory.BrewerInventory; import org.bukkit.inventory.ItemStack; -import org.bukkit.scheduler.BukkitRunnable; import java.util.*; @@ -123,7 +120,7 @@ public void onBrew(BrewEvent e){ } private void updateStand(BrewerInventory inventory, Player p, boolean automated){ - ValhallaMMO.getInstance().getServer().getScheduler().runTaskLater(ValhallaMMO.getInstance(), () -> { + Scheduling.runEntityTask(ValhallaMMO.getInstance(), p, 1L, () -> { ItemStack i = inventory.getItem(ingredient); ActiveBrewingStand activeStand = activeStands.get(inventory.getLocation()); if (ItemUtils.isEmpty(i)) { @@ -152,13 +149,13 @@ private void updateStand(BrewerInventory inventory, Player p, boolean automated) double speedMultiplier = 1 + (p == null ? 0 : AccumulativeStatManager.getCachedStats("BREWING_SPEED_BONUS", p, 10000, true)); int duration = (int) (speedMultiplier <= 0 ? -1 : baseDuration / speedMultiplier); // negative speed = no brewing ActiveBrewingStand newStand = new ActiveBrewingStand(p, inventory, recipes, duration, automated); - newStand.runTaskTimer(ValhallaMMO.getInstance(), 0, 1); + newStand.runEntity(ValhallaMMO.getInstance(), p, 0, 1); activeStands.put(brewingStand.getLocation(), newStand); } - }, 1L); + }); } - private static class ActiveBrewingStand extends BukkitRunnable { + private static class ActiveBrewingStand extends ValhallaRunnable { private final boolean disabled; private final boolean automated; private final Player p; diff --git a/core/src/main/java/me/athlaeos/valhallammo/listeners/CauldronCraftingListener.java b/core/src/main/java/me/athlaeos/valhallammo/listeners/CauldronCraftingListener.java index 68940be5..09f963ba 100644 --- a/core/src/main/java/me/athlaeos/valhallammo/listeners/CauldronCraftingListener.java +++ b/core/src/main/java/me/athlaeos/valhallammo/listeners/CauldronCraftingListener.java @@ -16,8 +16,7 @@ import me.athlaeos.valhallammo.item.CustomFlag; import me.athlaeos.valhallammo.item.ItemBuilder; import me.athlaeos.valhallammo.item.SmithingItemPropertyManager; -import me.athlaeos.valhallammo.utility.ItemUtils; -import me.athlaeos.valhallammo.utility.StringUtils; +import me.athlaeos.valhallammo.utility.*; import me.athlaeos.valhallammo.utility.Timer; import org.bukkit.*; import org.bukkit.block.Block; @@ -37,7 +36,6 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.persistence.PersistentDataContainer; import org.bukkit.persistence.PersistentDataType; -import org.bukkit.scheduler.BukkitRunnable; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -61,7 +59,7 @@ public void onItemThrow(PlayerDropItemEvent e){ if (!entityThrowItemLimiter.containsKey(thrower.getUniqueId())){ CauldronInputTick runnable = new CauldronInputTick(thrower, e.getItemDrop()); entityThrowItemLimiter.put(thrower.getUniqueId(), runnable); - runnable.runTaskTimer(ValhallaMMO.getInstance(), 0L, 1L); + runnable.runEntity(ValhallaMMO.getInstance(), thrower, 0L, 1L); } else { entityThrowItemLimiter.get(thrower.getUniqueId()).resetTicks(); } @@ -74,14 +72,14 @@ public void onItemDispense(BlockDispenseEvent e){ if (e.isCancelled() || !(e.getBlock().getBlockData() instanceof Directional d)) return; if (!blockThrowItemLimiter.containsKey(b.getLocation())){ Collection entitiesBefore = b.getWorld().getNearbyEntities(b.getRelative(d.getFacing()).getLocation().add(0.5, 0.5, 0.5), 0.5, 0.5, 0.5, (i) -> i instanceof Item); - ValhallaMMO.getInstance().getServer().getScheduler().runTaskLater(ValhallaMMO.getInstance(), () -> { + Scheduling.runLocationTask(ValhallaMMO.getInstance(), b.getLocation(), 1L, () -> { Collection newEntities = b.getWorld().getNearbyEntities(b.getRelative(d.getFacing()).getLocation().add(0.5, 0.5, 0.5), 0.5, 0.5, 0.5, (i) -> i instanceof Item && !entitiesBefore.contains(i)); Item i = (Item) newEntities.stream().findAny().orElse(null); if (i == null) return; CauldronInputTick runnable = new CauldronInputTick(b, i); blockThrowItemLimiter.put(b.getLocation(), runnable); - runnable.runTaskTimer(ValhallaMMO.getInstance(), 0L, 1L); - }, 1L); + runnable.runLocation(ValhallaMMO.getInstance(), b.getLocation(), 0L, 1L); + }); } else { blockThrowItemLimiter.get(b.getLocation()).resetTicks(); } @@ -172,7 +170,7 @@ public static Pair updateCauldronRecipes(@Nullab if (recipe.isTimedRecipe()){ CauldronCookingTask task = new CauldronCookingTask(responsible, cauldron, recipe, count); activeCauldrons.put(cauldron.getLocation(), task); - task.runTaskTimer(ValhallaMMO.getInstance(), 0L, 1L); + task.runLocation(ValhallaMMO.getInstance(), cauldron.getLocation(), 0L, 1L); } else if (!ItemUtils.isEmpty(catalyst)){ ItemBuilder result = new ItemBuilder(recipe.tinkerCatalyst() ? catalyst : recipe.getResult()); if (recipe.requiresValhallaTools() && !SmithingItemPropertyManager.hasSmithingQuality(ItemUtils.getItemMeta(catalyst))) return null; @@ -408,7 +406,7 @@ public static boolean isCustomCauldron(Block cauldron){ return customBlockData.has(CAULDRON_STORAGE, PersistentDataType.STRING) && !getCauldronContents(cauldron).isEmpty(); } - private static class CauldronCookingTask extends BukkitRunnable{ + private static class CauldronCookingTask extends ValhallaRunnable { private int duration; private final UUID cooker; private final Location cauldron; @@ -467,7 +465,7 @@ private void stop(){ } } - private static class CauldronInputTick extends BukkitRunnable{ + private static class CauldronInputTick extends ValhallaRunnable{ private int ticks = ValhallaMMO.getPluginConfig().getInt("cauldron_item_duration"); private final UUID thrower; private final Location block; diff --git a/core/src/main/java/me/athlaeos/valhallammo/listeners/ChatListener.java b/core/src/main/java/me/athlaeos/valhallammo/listeners/ChatListener.java index 3d286b4d..c49d73f4 100644 --- a/core/src/main/java/me/athlaeos/valhallammo/listeners/ChatListener.java +++ b/core/src/main/java/me/athlaeos/valhallammo/listeners/ChatListener.java @@ -4,6 +4,7 @@ import me.athlaeos.valhallammo.ValhallaMMO; import me.athlaeos.valhallammo.dom.Question; import me.athlaeos.valhallammo.dom.Questionnaire; +import me.athlaeos.valhallammo.utility.Scheduling; import me.athlaeos.valhallammo.utility.Utils; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -20,7 +21,7 @@ public void onChat(AsyncPlayerChatEvent e){ Question q = questionaire.nextQuestion(); if (q != null) { e.setCancelled(true); - ValhallaMMO.getInstance().getServer().getScheduler().runTask(ValhallaMMO.getInstance(), () -> { + Scheduling.runEntityTask(ValhallaMMO.getInstance(), e.getPlayer(), () -> { q.answer(e.getPlayer(), e.getMessage()); if (questionaire.allAnswered()) questionaire.finish(); }); diff --git a/core/src/main/java/me/athlaeos/valhallammo/listeners/CraftingTableListener.java b/core/src/main/java/me/athlaeos/valhallammo/listeners/CraftingTableListener.java index 484b6e47..accf6ad6 100644 --- a/core/src/main/java/me/athlaeos/valhallammo/listeners/CraftingTableListener.java +++ b/core/src/main/java/me/athlaeos/valhallammo/listeners/CraftingTableListener.java @@ -22,6 +22,7 @@ import me.athlaeos.valhallammo.potioneffects.PotionEffectWrapper; import me.athlaeos.valhallammo.item.SmithingItemPropertyManager; import me.athlaeos.valhallammo.utility.ItemUtils; +import me.athlaeos.valhallammo.utility.Scheduling; import me.athlaeos.valhallammo.utility.Utils; import org.bukkit.EntityEffect; import org.bukkit.Keyed; @@ -150,11 +151,11 @@ public void onCraft(CraftItemEvent e){ null : inventory.getMatrix()[toolIndex].clone(); inventory.getMatrix()[toolIndex].setAmount(amountCrafted); int finalToolIndex = toolIndex; - ValhallaMMO.getInstance().getServer().getScheduler().runTaskLater(ValhallaMMO.getInstance(), () -> { + Scheduling.runTaskLater(ValhallaMMO.getInstance(), 1L, () -> { ItemStack[] m = inventory.getMatrix(); m[finalToolIndex] = tool; inventory.setMatrix(m); - }, 1L + } ); } } else { diff --git a/core/src/main/java/me/athlaeos/valhallammo/listeners/CustomBreakSpeedListener.java b/core/src/main/java/me/athlaeos/valhallammo/listeners/CustomBreakSpeedListener.java index 0f296d0f..74309f51 100644 --- a/core/src/main/java/me/athlaeos/valhallammo/listeners/CustomBreakSpeedListener.java +++ b/core/src/main/java/me/athlaeos/valhallammo/listeners/CustomBreakSpeedListener.java @@ -7,6 +7,8 @@ import me.athlaeos.valhallammo.event.PrepareBlockBreakEvent; import me.athlaeos.valhallammo.utility.EntityUtils; import me.athlaeos.valhallammo.utility.ItemUtils; +import me.athlaeos.valhallammo.utility.Scheduling; +import me.athlaeos.valhallammo.utility.ValhallaRunnable; import me.athlaeos.valhallammo.version.AttributeMappings; import me.athlaeos.valhallammo.version.PotionEffectMappings; import org.bukkit.GameMode; @@ -23,7 +25,6 @@ import org.bukkit.event.entity.EntityPotionEffectEvent; import org.bukkit.event.player.*; import org.bukkit.potion.PotionEffect; -import org.bukkit.scheduler.BukkitRunnable; import java.util.*; import java.util.concurrent.ConcurrentHashMap; @@ -52,7 +53,7 @@ public CustomBreakSpeedListener(){ disabled = false; fatigueEffect = new PotionEffect(PotionEffectMappings.MINING_FATIGUE.getPotionEffectType(), Integer.MAX_VALUE, -1, false, false, false); - new BukkitRunnable(){ + new ValhallaRunnable(){ @Override public void run() { for (Location l : new HashSet<>(blockDigProcesses.keySet())){ @@ -193,10 +194,10 @@ public void onWorldChange(PlayerChangedWorldEvent e){ @EventHandler(priority = EventPriority.MONITOR) public void onPlayerRespawn(PlayerRespawnEvent e){ - ValhallaMMO.getInstance().getServer().getScheduler().runTaskLater(ValhallaMMO.getInstance(), () -> { + Scheduling.runEntityTask(ValhallaMMO.getInstance(), e.getPlayer(), 10L, () -> { fatiguePlayer(e.getPlayer(), true); fatiguePlayer(e.getPlayer(), true); - }, 10L); + }); } @EventHandler(priority = EventPriority.MONITOR) @@ -212,7 +213,7 @@ public void onPotionEffect(EntityPotionEffectEvent e){ e.setOverride(true); } else if ((e.getAction() == EntityPotionEffectEvent.Action.REMOVED || e.getAction() == EntityPotionEffectEvent.Action.CLEARED) && e.getOldEffect() != null && e.getOldEffect().getType() == PotionEffectMappings.MINING_FATIGUE.getPotionEffectType() && (e.getOldEffect().getAmplifier() < 0 || e.getOldEffect().getAmplifier() > 4)) { - ValhallaMMO.getInstance().getServer().getScheduler().runTaskLater(ValhallaMMO.getInstance(), () -> fatiguePlayer(p, true), 2L); + Scheduling.runTaskLater(ValhallaMMO.getInstance(), 2L, () -> fatiguePlayer(p, true)); } } diff --git a/core/src/main/java/me/athlaeos/valhallammo/listeners/DeathListener.java b/core/src/main/java/me/athlaeos/valhallammo/listeners/DeathListener.java index 972eec58..7b219b08 100644 --- a/core/src/main/java/me/athlaeos/valhallammo/listeners/DeathListener.java +++ b/core/src/main/java/me/athlaeos/valhallammo/listeners/DeathListener.java @@ -9,6 +9,7 @@ import me.athlaeos.valhallammo.potioneffects.PotionEffectRegistry; import me.athlaeos.valhallammo.skills.ChunkEXPNerf; import me.athlaeos.valhallammo.utility.Bleeder; +import me.athlaeos.valhallammo.utility.Scheduling; import me.athlaeos.valhallammo.utility.StringUtils; import me.athlaeos.valhallammo.utility.Utils; import org.bukkit.entity.Entity; @@ -45,7 +46,7 @@ public void onPlayerDeath(PlayerDeathEvent e){ double lastDamageTaken = EntityDamagedListener.getLastDamageTaken(e.getEntity().getUniqueId()); CustomDamageType type = CustomDamageType.getCustomType(cause); - ValhallaMMO.getInstance().getServer().getScheduler().runTaskLater(ValhallaMMO.getInstance(), () -> { + Scheduling.runEntityTask(ValhallaMMO.getInstance(), e.getEntity(), 20L, () -> { if (type != null && !StringUtils.isEmpty(type.getTranslation())){ if (lastDamager == null) Utils.sendMessage(e.getEntity(), deathStatus .replace("%damage%", String.format("%.1f", lastDamageTaken)) @@ -61,7 +62,7 @@ public void onPlayerDeath(PlayerDeathEvent e){ .replace("%damage%", String.format("%.1f", lastDamageTaken)) .replace("%killer%", lastDamager.getName())); } - }, 20L); + }); List deathMessages = lastDamager != null ? TranslationManager.getListTranslation("death_message_" + cause.toLowerCase(java.util.Locale.US) + "_enemy") : diff --git a/core/src/main/java/me/athlaeos/valhallammo/listeners/EnchantmentListener.java b/core/src/main/java/me/athlaeos/valhallammo/listeners/EnchantmentListener.java index bfc2dc07..df3e85a8 100644 --- a/core/src/main/java/me/athlaeos/valhallammo/listeners/EnchantmentListener.java +++ b/core/src/main/java/me/athlaeos/valhallammo/listeners/EnchantmentListener.java @@ -5,6 +5,7 @@ import me.athlaeos.valhallammo.playerstats.AccumulativeStatManager; import me.athlaeos.valhallammo.utility.EntityUtils; import me.athlaeos.valhallammo.utility.ItemUtils; +import me.athlaeos.valhallammo.utility.Scheduling; import me.athlaeos.valhallammo.utility.Utils; import org.bukkit.GameMode; import org.bukkit.Material; @@ -45,7 +46,7 @@ public void onEnchant(EnchantItemEvent e){ if (e.getEnchanter().getGameMode() != GameMode.CREATIVE){ double saveChance = AccumulativeStatManager.getCachedStats("ENCHANTING_LAPIS_SAVE_CHANCE", enchanter, 10000, true); if (Utils.proc(enchanter, saveChance, false)){ - ValhallaMMO.getInstance().getServer().getScheduler().runTaskLater(ValhallaMMO.getInstance(), () -> { + Scheduling.runEntityTask(ValhallaMMO.getInstance(), e.getEnchanter(), 1L, () -> { ItemStack lapisSlot = e.getInventory().getItem(1); ItemStack newLapis = new ItemStack(Material.LAPIS_LAZULI, lapisConsumed); if (!ItemUtils.isEmpty(lapisSlot)){ @@ -64,7 +65,7 @@ public void onEnchant(EnchantItemEvent e){ } else { e.getInventory().setItem(1, newLapis); } - }, 1L); + }); } } diff --git a/core/src/main/java/me/athlaeos/valhallammo/listeners/EntityAttackListener.java b/core/src/main/java/me/athlaeos/valhallammo/listeners/EntityAttackListener.java index 83fa384e..74cf4d77 100644 --- a/core/src/main/java/me/athlaeos/valhallammo/listeners/EntityAttackListener.java +++ b/core/src/main/java/me/athlaeos/valhallammo/listeners/EntityAttackListener.java @@ -119,19 +119,19 @@ public void onAttack(EntityDamageByEntityEvent e){ if (v instanceof Player p && p.getCooldown(Material.SHIELD) <= 0 && p.isBlocking() && e.getFinalDamage() == 0 && (!(e.getDamager() instanceof Player a) || a.getAttackCooldown() >= 0.9)){ // Shield disabling may only occur if the shield is being held up int shieldDisabling = (int) Math.round(AccumulativeStatManager.getCachedAttackerRelationalStats("SHIELD_DISARMING", p, trueDamager, 10000, true)); - ValhallaMMO.getInstance().getServer().getScheduler().runTaskLater(ValhallaMMO.getInstance(), () -> { + Scheduling.runEntityTask(ValhallaMMO.getInstance(), p, 1L, () -> { p.setCooldown(Material.SHIELD, p.getCooldown(Material.SHIELD) + shieldDisabling); p.playEffect(EntityEffect.SHIELD_BREAK); ItemStack temp = ItemUtils.isEmpty(p.getInventory().getItemInMainHand()) ? null : p.getInventory().getItemInMainHand().clone(); p.getInventory().setItemInMainHand(p.getInventory().getItemInOffHand()); p.getInventory().setItemInOffHand(temp); - ValhallaMMO.getInstance().getServer().getScheduler().runTaskLater(ValhallaMMO.getInstance(), () -> { + Scheduling.runEntityTask(ValhallaMMO.getInstance(), p, 1L, () -> { ItemStack temp2 = ItemUtils.isEmpty(p.getInventory().getItemInMainHand()) ? null : p.getInventory().getItemInMainHand().clone(); p.getInventory().setItemInMainHand(p.getInventory().getItemInOffHand()); p.getInventory().setItemInOffHand(temp2); - }, 1L); - }, - 1L); + }); + } + ); } if (!sweep){ boolean facing = EntityUtils.isEntityFacing(v, e.getDamager().getLocation(), facingAngleCos) || (e.getDamager() instanceof LivingEntity le && EntityUtils.isEntityFacing(v, le.getEyeLocation(), facingAngleCos)); @@ -200,7 +200,7 @@ public void onAttack(EntityDamageByEntityEvent e){ if (knockbackResistance > 0) EntityUtils.addUniqueAttribute(v, EntityAttributeStats.NEGATIVE_KNOCKBACK, "valhalla_negative_knockback_taken", Attribute.GENERIC_KNOCKBACK_RESISTANCE, knockbackResistance, AttributeModifier.Operation.ADD_NUMBER); if (knockbackBonus != 0){ double finalKnockbackBonus = knockbackBonus; - ValhallaMMO.getInstance().getServer().getScheduler().runTaskLater(ValhallaMMO.getInstance(), () -> { + Scheduling.runEntityTask(ValhallaMMO.getInstance(), v, 1L, () -> { // finishing off custom knockback mechanics (removing attribute if placed, or changing velocity to comply with increased knockback) if (knockbackResistance > 0) EntityUtils.removeUniqueAttribute(v, "valhalla_negative_knockback_taken", Attribute.GENERIC_KNOCKBACK_RESISTANCE); else if (finalKnockbackBonus > 0){ @@ -211,7 +211,7 @@ else if (finalKnockbackBonus > 0){ lookingDirection.setZ(lookingDirection.getZ() * finalKnockbackBonus); v.setVelocity(v.getVelocity().add(lookingDirection)); } - }, 1L); + }); } // custom dismount mechanics @@ -294,7 +294,7 @@ else if (finalKnockbackBonus > 0){ } if (!damageInstances.isEmpty()) EntityDamagedListener.markNextDamageInstanceNoImmunity(v, e.getCause().toString()); - ValhallaMMO.getInstance().getServer().getScheduler().runTaskLater(ValhallaMMO.getInstance(), () -> { + Scheduling.runEntityTask(ValhallaMMO.getInstance(), e.getDamager(), 2L, () -> { // custom bleed mechanics if (attackCooldown >= 0.9F){ double bleedChance = AccumulativeStatManager.getCachedAttackerRelationalStats("BLEED_CHANCE", v, e.getDamager(), 10000, true); @@ -351,7 +351,7 @@ else if (finalKnockbackBonus > 0){ if (maxHealth != null) td.setHealth(Math.min(maxHealth.getValue(), td.getHealth() + lifeStealValue)); } } - }, 2L); + }); } } } @@ -387,7 +387,7 @@ public void onPotionAttack(EntityDamageByEntityEvent e){ if (hand.getType().isEdible() || weapon.getMeta() instanceof PotionMeta || !EquipmentClass.isHandHeld(weapon.getMeta())) return; - ValhallaMMO.getInstance().getServer().getScheduler().runTaskLater(ValhallaMMO.getInstance(), () -> { + Scheduling.runEntityTask(ValhallaMMO.getInstance(), e.getEntity(), 1L, () -> { if (!e.getEntity().isValid() || e.getEntity().isDead()) return; boolean updatedMeta = false; // apply potion effects @@ -402,7 +402,7 @@ public void onPotionAttack(EntityDamageByEntityEvent e){ hand.setItemMeta(weapon.getMeta()); a.getEquipment().setItemInMainHand(weapon.get(), true); } - }, 1L); + }); } } diff --git a/core/src/main/java/me/athlaeos/valhallammo/listeners/EntityDamagedListener.java b/core/src/main/java/me/athlaeos/valhallammo/listeners/EntityDamagedListener.java index 1cf3b539..b55ea367 100644 --- a/core/src/main/java/me/athlaeos/valhallammo/listeners/EntityDamagedListener.java +++ b/core/src/main/java/me/athlaeos/valhallammo/listeners/EntityDamagedListener.java @@ -10,6 +10,7 @@ import me.athlaeos.valhallammo.playerstats.profiles.ProfileCache; import me.athlaeos.valhallammo.playerstats.profiles.implementations.PowerProfile; import me.athlaeos.valhallammo.potioneffects.EffectResponsibility; +import me.athlaeos.valhallammo.utility.Scheduling; import me.athlaeos.valhallammo.utility.StringUtils; import me.athlaeos.valhallammo.utility.Timer; import me.athlaeos.valhallammo.utility.Utils; @@ -178,10 +179,10 @@ public void onDamageTaken(EntityDamageEvent e){ absorptionTracker.remove(l.getUniqueId()); damageProcesses.remove(l.getUniqueId()); }); - ValhallaMMO.getInstance().getServer().getScheduler().runTaskLater(ValhallaMMO.getInstance(), () -> { + Scheduling.runEntityTask(ValhallaMMO.getInstance(), l, 1L, () -> { Runnable r = damageProcesses.get(l.getUniqueId()); if (r != null) r.run(); - }, 1L); + }); } // else if (customDamageEnabled) { // // custom damage killed entity diff --git a/core/src/main/java/me/athlaeos/valhallammo/listeners/HandSwitchListener.java b/core/src/main/java/me/athlaeos/valhallammo/listeners/HandSwitchListener.java index 722702e0..ffac7655 100644 --- a/core/src/main/java/me/athlaeos/valhallammo/listeners/HandSwitchListener.java +++ b/core/src/main/java/me/athlaeos/valhallammo/listeners/HandSwitchListener.java @@ -3,8 +3,10 @@ import me.athlaeos.valhallammo.ValhallaMMO; import me.athlaeos.valhallammo.playerstats.AccumulativeStatManager; import me.athlaeos.valhallammo.utility.ItemUtils; +import me.athlaeos.valhallammo.utility.Scheduling; import me.athlaeos.valhallammo.utility.Timer; import me.athlaeos.valhallammo.playerstats.EntityCache; +import me.athlaeos.valhallammo.utility.ValhallaRunnable; import org.bukkit.Material; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; @@ -16,7 +18,6 @@ import org.bukkit.event.player.PlayerItemBreakEvent; import org.bukkit.event.player.PlayerItemHeldEvent; import org.bukkit.event.player.PlayerSwapHandItemsEvent; -import org.bukkit.scheduler.BukkitRunnable; import java.util.*; @@ -64,10 +65,10 @@ public void onSwapHands(PlayerSwapHandItemsEvent e){ @EventHandler(priority = EventPriority.MONITOR) public void onItemBreak(PlayerItemBreakEvent e){ - ValhallaMMO.getInstance().getServer().getScheduler().runTaskLater(ValhallaMMO.getInstance(), () -> { + Scheduling.runTaskLater(ValhallaMMO.getInstance(), 1L, () -> { reset(e.getPlayer()); playersWhoSwitchedItems.remove(e.getPlayer().getUniqueId()); - }, 1L); + }); } @EventHandler(priority = EventPriority.LOWEST) @@ -99,7 +100,7 @@ public void onAttack(EntityDamageByEntityEvent e){ } } - private static class DelayedHandUpdate extends BukkitRunnable { + private static class DelayedHandUpdate extends ValhallaRunnable { private static final int delay = 10; // after 0.5 seconds update hands private int timer = delay; private final Player who; diff --git a/core/src/main/java/me/athlaeos/valhallammo/listeners/InteractListener.java b/core/src/main/java/me/athlaeos/valhallammo/listeners/InteractListener.java index 90231e4f..13c7000f 100644 --- a/core/src/main/java/me/athlaeos/valhallammo/listeners/InteractListener.java +++ b/core/src/main/java/me/athlaeos/valhallammo/listeners/InteractListener.java @@ -9,10 +9,7 @@ import me.athlaeos.valhallammo.playerstats.AccumulativeStatManager; import me.athlaeos.valhallammo.playerstats.EntityCache; import me.athlaeos.valhallammo.playerstats.EntityProperties; -import me.athlaeos.valhallammo.utility.EntityUtils; -import me.athlaeos.valhallammo.utility.ItemUtils; -import me.athlaeos.valhallammo.utility.Parryer; -import me.athlaeos.valhallammo.utility.Timer; +import me.athlaeos.valhallammo.utility.*; import org.bukkit.FluidCollisionMode; import org.bukkit.Location; import org.bukkit.attribute.Attribute; diff --git a/core/src/main/java/me/athlaeos/valhallammo/listeners/ItemConsumptionListener.java b/core/src/main/java/me/athlaeos/valhallammo/listeners/ItemConsumptionListener.java index 15267729..1ea88390 100644 --- a/core/src/main/java/me/athlaeos/valhallammo/listeners/ItemConsumptionListener.java +++ b/core/src/main/java/me/athlaeos/valhallammo/listeners/ItemConsumptionListener.java @@ -11,6 +11,7 @@ import me.athlaeos.valhallammo.potioneffects.PotionEffectRegistry; import me.athlaeos.valhallammo.potioneffects.PotionEffectWrapper; import me.athlaeos.valhallammo.utility.ItemUtils; +import me.athlaeos.valhallammo.utility.Scheduling; import me.athlaeos.valhallammo.utility.Utils; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -60,7 +61,7 @@ public void onItemConsume(PlayerItemConsumeEvent e){ int finalFoodToReplenish = foodToReplenish; float finalSaturationToReplenish = saturationBefore + saturationToReplenish; - ValhallaMMO.getInstance().getServer().getScheduler().runTaskLater(ValhallaMMO.getInstance(), () -> { + Scheduling.runEntityTask(ValhallaMMO.getInstance(), e.getPlayer(), 1L, () -> { cancelNextFoodEffects.remove(e.getPlayer().getUniqueId()); cancelNextFoodEvent.remove(e.getPlayer().getUniqueId()); FoodLevelChangeEvent event = new FoodLevelChangeEvent(e.getPlayer(), Math.max(0, Math.min(20, hungerBefore + finalFoodToReplenish)), item); @@ -69,9 +70,9 @@ public void onItemConsume(PlayerItemConsumeEvent e){ e.getPlayer().setFoodLevel(Math.max(0, Math.min(20, event.getFoodLevel()))); e.getPlayer().setSaturation(Math.max(0, Math.min(20, finalSaturationToReplenish))); } - }, 1L); + }); } else { - ValhallaMMO.getInstance().getServer().getScheduler().runTaskLater(ValhallaMMO.getInstance(), () -> { + Scheduling.runEntityTask(ValhallaMMO.getInstance(), e.getPlayer(), 1L, () -> { int hungerDifference = e.getPlayer().getFoodLevel() - hungerBefore; float saturationDifference = e.getPlayer().getSaturation() - saturationBefore; int newFoodLevel = hungerBefore + (int) Math.round(hungerDifference * multiplier); @@ -82,7 +83,7 @@ public void onItemConsume(PlayerItemConsumeEvent e){ e.getPlayer().setFoodLevel(Math.max(0, Math.min(20, event.getFoodLevel()))); e.getPlayer().setSaturation(Math.max(0, Math.min(20, newSaturationLevel))); } - }, 1L); + }); } } diff --git a/core/src/main/java/me/athlaeos/valhallammo/listeners/JoinLeaveListener.java b/core/src/main/java/me/athlaeos/valhallammo/listeners/JoinLeaveListener.java index 010dc001..e7fa223a 100644 --- a/core/src/main/java/me/athlaeos/valhallammo/listeners/JoinLeaveListener.java +++ b/core/src/main/java/me/athlaeos/valhallammo/listeners/JoinLeaveListener.java @@ -10,6 +10,7 @@ import me.athlaeos.valhallammo.potioneffects.PotionEffectRegistry; import me.athlaeos.valhallammo.skills.perk_rewards.implementations.FlightReward; import me.athlaeos.valhallammo.utility.GlobalEffect; +import me.athlaeos.valhallammo.utility.Scheduling; import org.bukkit.NamespacedKey; import org.bukkit.attribute.Attribute; import org.bukkit.attribute.AttributeInstance; @@ -49,7 +50,7 @@ public void onPlayerJoin(PlayerJoinEvent e) { } } - ValhallaMMO.getInstance().getServer().getScheduler().runTaskLater(ValhallaMMO.getInstance(), () -> { + Scheduling.runTaskLater(ValhallaMMO.getInstance(), () -> { EntityAttributeStats.updateStats(e.getPlayer()); FlightReward.setFlight(e.getPlayer(), true); }, 40L); diff --git a/core/src/main/java/me/athlaeos/valhallammo/listeners/JumpListener.java b/core/src/main/java/me/athlaeos/valhallammo/listeners/JumpListener.java index 977d730b..3266fa88 100644 --- a/core/src/main/java/me/athlaeos/valhallammo/listeners/JumpListener.java +++ b/core/src/main/java/me/athlaeos/valhallammo/listeners/JumpListener.java @@ -8,6 +8,7 @@ import me.athlaeos.valhallammo.hooks.WorldGuardHook; import me.athlaeos.valhallammo.playerstats.AccumulativeStatManager; import me.athlaeos.valhallammo.utility.MathUtils; +import me.athlaeos.valhallammo.utility.Scheduling; import me.athlaeos.valhallammo.version.PotionEffectMappings; import org.bukkit.GameMode; import org.bukkit.Material; @@ -99,9 +100,9 @@ public void onToggleFlight(PlayerToggleFlightEvent e){ double motionY = 0.42 + (jumpLevel * 0.1F); double motionZ = e.getPlayer().getVelocity().getZ() + (e.getPlayer().isSprinting() ? MathUtils.cos(f) * 0.2 : 0); if (multiJumpAnimation != null) multiJumpAnimation.animate(e.getPlayer(), e.getPlayer().getLocation(), e.getPlayer().getEyeLocation().getDirection(), 0); - ValhallaMMO.getInstance().getServer().getScheduler().runTaskLater(ValhallaMMO.getInstance(), () -> - e.getPlayer().setVelocity(new Vector(motionX, motionY, motionZ).add(new Vector(0, (jumpHeightBonus * 0.1), 0))), - 1L); + Scheduling.runEntityTask(ValhallaMMO.getInstance(), e.getPlayer(), 1L, () -> + e.getPlayer().setVelocity(new Vector(motionX, motionY, motionZ).add(new Vector(0, (jumpHeightBonus * 0.1), 0))) + ); e.getPlayer().setFallDistance(0); } diff --git a/core/src/main/java/me/athlaeos/valhallammo/listeners/LootListener.java b/core/src/main/java/me/athlaeos/valhallammo/listeners/LootListener.java index 71f7fa0a..7ee922e5 100644 --- a/core/src/main/java/me/athlaeos/valhallammo/listeners/LootListener.java +++ b/core/src/main/java/me/athlaeos/valhallammo/listeners/LootListener.java @@ -212,7 +212,7 @@ public void onBlockDecay(LeavesDecayEvent e){ Player p = uuid == null ? null : ValhallaMMO.getInstance().getServer().getPlayer(uuid); if (p == null) { List nearby = EntityUtils.getNearbyPlayers(e.getBlock().getLocation(), 100); - if (!nearby.isEmpty()) p = nearby.getFirst(); + if (!nearby.isEmpty()) p = nearby.get(0); } Pair details = getFortuneAndLuck(p, e.getBlock()); int fortune = details.getTwo(); @@ -988,13 +988,13 @@ public void onBlockDrops(BlockDropItemEvent e){ } public static void clear(Block b){ - ValhallaMMO.getInstance().getServer().getScheduler().runTaskLater(ValhallaMMO.getInstance(), () -> { + Scheduling.runTaskLater(ValhallaMMO.getInstance(), 1L, () -> { transferToInventory.remove(b.getLocation()); preparedBlockDrops.remove(b.getLocation()); preparedLuckBuffs.remove(b.getLocation()); explodedBlocks.remove(b.getLocation()); exploded.remove(b); - }, 1L); + }); } @EventHandler(priority = EventPriority.MONITOR) diff --git a/core/src/main/java/me/athlaeos/valhallammo/listeners/MovementListener.java b/core/src/main/java/me/athlaeos/valhallammo/listeners/MovementListener.java index 8e656ebf..c3ce756b 100644 --- a/core/src/main/java/me/athlaeos/valhallammo/listeners/MovementListener.java +++ b/core/src/main/java/me/athlaeos/valhallammo/listeners/MovementListener.java @@ -4,6 +4,7 @@ import me.athlaeos.valhallammo.entities.EntityAttributeStats; import me.athlaeos.valhallammo.playerstats.AccumulativeStatManager; import me.athlaeos.valhallammo.utility.EntityUtils; +import me.athlaeos.valhallammo.utility.Scheduling; import me.athlaeos.valhallammo.utility.Timer; import org.bukkit.attribute.Attribute; import org.bukkit.attribute.AttributeInstance; @@ -24,34 +25,48 @@ public class MovementListener implements Listener { private static final Map lastMovementVectors = new HashMap<>(); public MovementListener(){ - ValhallaMMO.getInstance().getServer().getScheduler().runTaskTimer(ValhallaMMO.getInstance(), () -> { - for (Player p : ValhallaMMO.getInstance().getServer().getOnlinePlayers()){ - if (Timer.isCooldownPassed(p.getUniqueId(), "delay_combat_update")) { // combat status is checked every half second - EntityAttackListener.updateCombatStatus(p); - Timer.setCooldown(p.getUniqueId(), 500, "delay_combat_update"); + if (ValhallaMMO.getPlatform().supportsFolia()) { + Scheduling.runTaskTimerAsync(ValhallaMMO.getInstance(), 20L, 20L, () -> { + for (Player p : ValhallaMMO.getInstance().getServer().getOnlinePlayers()){ + Scheduling.runEntityTask(ValhallaMMO.getInstance(), p, () -> { + updatePlayer(p); + }); } - if (Timer.isCooldownPassed(p.getUniqueId(), "delay_movement_update")){ - if (ValhallaMMO.isWorldBlacklisted(p.getWorld().getName())){ - EntityAttributeStats.removeStats(p); - } else { - EntityAttributeStats.updateStats(p); + }); + } else { + Scheduling.runTaskTimer(ValhallaMMO.getInstance(), 20L, 20L, () -> { + for (Player p : ValhallaMMO.getInstance().getServer().getOnlinePlayers()){ + updatePlayer(p); + } + }); + } + } - AttributeInstance armorInstance = p.getAttribute(Attribute.GENERIC_ARMOR); - EntityUtils.removeUniqueAttribute(p, "armor_nullifier", Attribute.GENERIC_ARMOR); - EntityUtils.removeUniqueAttribute(p, "armor_display", Attribute.GENERIC_ARMOR); - if (armorInstance != null){ - double totalArmor = AccumulativeStatManager.getCachedStats("ARMOR_TOTAL", p, 10000, true); - int scale = ValhallaMMO.getPluginConfig().getInt("armor_scale", 50); - double newArmor = Math.max(0, Math.min(20, (totalArmor / scale) * 20)); - EntityUtils.addUniqueAttribute(p, EntityAttributeStats.ARMOR_NULLIFIER, "armor_nullifier", Attribute.GENERIC_ARMOR, -armorInstance.getValue(), AttributeModifier.Operation.ADD_NUMBER); // sets armor bar to 0 - EntityUtils.addUniqueAttribute(p, EntityAttributeStats.ARMOR_DISPLAY, "armor_display", Attribute.GENERIC_ARMOR, newArmor, AttributeModifier.Operation.ADD_NUMBER); // then increases armor to match a custom scale - } - } + private void updatePlayer(Player p) { + if (Timer.isCooldownPassed(p.getUniqueId(), "delay_combat_update")) { // combat status is checked every half second + EntityAttackListener.updateCombatStatus(p); + Timer.setCooldown(p.getUniqueId(), 500, "delay_combat_update"); + } + if (Timer.isCooldownPassed(p.getUniqueId(), "delay_movement_update")){ + if (ValhallaMMO.isWorldBlacklisted(p.getWorld().getName())){ + EntityAttributeStats.removeStats(p); + } else { + EntityAttributeStats.updateStats(p); - Timer.setCooldown(p.getUniqueId(), 10000, "delay_movement_update"); + AttributeInstance armorInstance = p.getAttribute(Attribute.GENERIC_ARMOR); + EntityUtils.removeUniqueAttribute(p, "armor_nullifier", Attribute.GENERIC_ARMOR); + EntityUtils.removeUniqueAttribute(p, "armor_display", Attribute.GENERIC_ARMOR); + if (armorInstance != null){ + double totalArmor = AccumulativeStatManager.getCachedStats("ARMOR_TOTAL", p, 10000, true); + int scale = ValhallaMMO.getPluginConfig().getInt("armor_scale", 50); + double newArmor = Math.max(0, Math.min(20, (totalArmor / scale) * 20)); + EntityUtils.addUniqueAttribute(p, EntityAttributeStats.ARMOR_NULLIFIER, "armor_nullifier", Attribute.GENERIC_ARMOR, -armorInstance.getValue(), AttributeModifier.Operation.ADD_NUMBER); // sets armor bar to 0 + EntityUtils.addUniqueAttribute(p, EntityAttributeStats.ARMOR_DISPLAY, "armor_display", Attribute.GENERIC_ARMOR, newArmor, AttributeModifier.Operation.ADD_NUMBER); // then increases armor to match a custom scale } } - }, 20L, 20L); + + Timer.setCooldown(p.getUniqueId(), 10000, "delay_movement_update"); + } } @EventHandler diff --git a/core/src/main/java/me/athlaeos/valhallammo/listeners/ProjectileListener.java b/core/src/main/java/me/athlaeos/valhallammo/listeners/ProjectileListener.java index 5abe5600..aa78cd91 100644 --- a/core/src/main/java/me/athlaeos/valhallammo/listeners/ProjectileListener.java +++ b/core/src/main/java/me/athlaeos/valhallammo/listeners/ProjectileListener.java @@ -14,6 +14,7 @@ import me.athlaeos.valhallammo.item.arrow_attributes.ArrowBehaviorRegistry; import me.athlaeos.valhallammo.utility.EntityUtils; import me.athlaeos.valhallammo.utility.ItemUtils; +import me.athlaeos.valhallammo.utility.Scheduling; import me.athlaeos.valhallammo.utility.Utils; import me.athlaeos.valhallammo.version.EnchantmentMappings; import org.bukkit.GameMode; @@ -142,7 +143,8 @@ public static void setBow(Projectile projectile, ItemBuilder bow){ } public static void removeBow(Projectile projectile){ - ValhallaMMO.getInstance().getServer().getScheduler().runTaskLater(ValhallaMMO.getInstance(), () -> projectileShotByMap.remove(projectile.getUniqueId()), 2L); + UUID uuid = projectile.getUniqueId(); + Scheduling.runTaskLater(ValhallaMMO.getInstance(), 2L, () -> projectileShotByMap.remove(uuid)); } private final Map crossbowReloads = new HashMap<>(); @@ -183,13 +185,13 @@ public void onShoot(EntityShootBowEvent e){ int currentReloads = crossbowReloads.getOrDefault(p.getUniqueId(), 0); // reload, increment magazine if (currentReloads + 1 <= allowedReloads){ crossbowReloads.put(p.getUniqueId(), currentReloads + 1); - ValhallaMMO.getInstance().getServer().getScheduler().runTaskLater(ValhallaMMO.getInstance(), () -> { + Scheduling.runEntityTask(ValhallaMMO.getInstance(), p, 1L, () -> { boolean mainHand = !ItemUtils.isEmpty(p.getInventory().getItemInMainHand()) && p.getInventory().getItemInMainHand().getType() == Material.CROSSBOW; ItemStack crossbow = mainHand ? p.getInventory().getItemInMainHand() : p.getInventory().getItemInOffHand(); if (ItemUtils.isEmpty(crossbow) || !(crossbow.getItemMeta() instanceof CrossbowMeta crossbowMeta)) return; crossbowMeta.addChargedProjectile(consumable); crossbow.setItemMeta(crossbowMeta); - }, 1L); + }); if (e.getProjectile() instanceof AbstractArrow a) a.setPickupStatus(AbstractArrow.PickupStatus.CREATIVE_ONLY); } else { crossbowReloads.remove(p.getUniqueId()); // do not reload, but reset magazine @@ -256,7 +258,7 @@ public void onHit(ProjectileHitEvent e){ int originalDamageTicks = l.getNoDamageTicks(); a.setDamage(a.getDamage() * ValhallaMMO.getPluginConfig().getDouble("multishot_damage_reduction", 0.5)); l.setNoDamageTicks(0); - ValhallaMMO.getInstance().getServer().getScheduler().runTaskLater(ValhallaMMO.getInstance(), () -> l.setNoDamageTicks(originalDamageTicks), 1L); + Scheduling.runEntityTask(ValhallaMMO.getInstance(), l, 1L, () -> l.setNoDamageTicks(originalDamageTicks)); } removeBow(e.getEntity()); // if an arrow hits anything, the bow it was shot from is forgotten @@ -297,7 +299,7 @@ public void onDamage(EntityDamageByEntityEvent e){ if (wrapper.isVanilla()) l.addPotionEffect(new PotionEffect(wrapper.getVanillaEffect(), duration, (int) wrapper.getAmplifier(), false)); else PotionEffectRegistry.addEffect(l, trueDamager, new CustomPotionEffect(wrapper, duration, wrapper.getAmplifier()), false, 1, EntityPotionEffectEvent.Cause.ARROW); } - ValhallaMMO.getInstance().getServer().getScheduler().runTaskLater(ValhallaMMO.getInstance(), () -> + Scheduling.runTaskLater(ValhallaMMO.getInstance(), () -> cancelNextArrowEffects.remove(e.getEntity().getUniqueId()), 1L ); } diff --git a/core/src/main/java/me/athlaeos/valhallammo/listeners/SmithingTableListener.java b/core/src/main/java/me/athlaeos/valhallammo/listeners/SmithingTableListener.java index d13bf80a..64e64e73 100644 --- a/core/src/main/java/me/athlaeos/valhallammo/listeners/SmithingTableListener.java +++ b/core/src/main/java/me/athlaeos/valhallammo/listeners/SmithingTableListener.java @@ -18,6 +18,7 @@ import me.athlaeos.valhallammo.playerstats.profiles.implementations.PowerProfile; import me.athlaeos.valhallammo.item.SmithingItemPropertyManager; import me.athlaeos.valhallammo.utility.ItemUtils; +import me.athlaeos.valhallammo.utility.Scheduling; import me.athlaeos.valhallammo.utility.Timer; import me.athlaeos.valhallammo.utility.Utils; import org.bukkit.entity.Player; @@ -115,8 +116,8 @@ public void onSmithingInteract(InventoryClickEvent e){ if (ItemUtils.isEmpty(finalAddition) || CustomFlag.hasFlag(addition.getMeta(), CustomFlag.UNCRAFTABLE) || ItemUtils.isEmpty(result.getItem()) || CustomFlag.hasFlag(result.getMeta(), CustomFlag.UNCRAFTABLE)){ e.setCancelled(true); } else { - ValhallaMMO.getInstance().getServer().getScheduler().runTaskLater(ValhallaMMO.getInstance(), () -> - e.getInventory().setItem(additionIndex, finalAddition), 1L + Scheduling.runEntityTask(ValhallaMMO.getInstance(), p, 1L, () -> + e.getInventory().setItem(additionIndex, finalAddition) ); } } else { @@ -134,7 +135,7 @@ public void onSmithingInteract(InventoryClickEvent e){ @SuppressWarnings("all") @EventHandler public void onPrepareSmithing(PrepareSmithingEvent e){ - ValhallaMMO.getInstance().getServer().getScheduler().runTaskLater(ValhallaMMO.getInstance(), () -> { + Scheduling.runTaskLater(ValhallaMMO.getInstance(), () -> { boolean isTemplateCompatible = MinecraftVersion.currentVersionNewerThan(MinecraftVersion.MINECRAFT_1_20); int baseIndex = isTemplateCompatible ? 1 : 0; int templateIndex = baseIndex - 1; diff --git a/core/src/main/java/me/athlaeos/valhallammo/listeners/WorldSaveListener.java b/core/src/main/java/me/athlaeos/valhallammo/listeners/WorldSaveListener.java index 78c28a41..3261147c 100644 --- a/core/src/main/java/me/athlaeos/valhallammo/listeners/WorldSaveListener.java +++ b/core/src/main/java/me/athlaeos/valhallammo/listeners/WorldSaveListener.java @@ -11,6 +11,7 @@ import me.athlaeos.valhallammo.playerstats.profiles.ProfileRegistry; import me.athlaeos.valhallammo.resourcepack.Host; import me.athlaeos.valhallammo.utility.GlobalEffect; +import me.athlaeos.valhallammo.utility.Scheduling; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -22,7 +23,7 @@ public class WorldSaveListener implements Listener { @EventHandler public void onWorldSave(WorldSaveEvent e){ if (e.getWorld().getName().equals(ValhallaMMO.getInstance().getServer().getWorlds().get(0).getName())) { - ValhallaMMO.getInstance().getServer().getScheduler().runTaskAsynchronously(ValhallaMMO.getInstance(), () -> { + Scheduling.runTaskAsync(ValhallaMMO.getInstance(), () -> { ProfileRegistry.saveAll(); CustomRecipeRegistry.saveRecipes(false); LootTableRegistry.saveAll(); diff --git a/core/src/main/java/me/athlaeos/valhallammo/loot/LootTableRegistry.java b/core/src/main/java/me/athlaeos/valhallammo/loot/LootTableRegistry.java index 4ad9801f..fd6887be 100644 --- a/core/src/main/java/me/athlaeos/valhallammo/loot/LootTableRegistry.java +++ b/core/src/main/java/me/athlaeos/valhallammo/loot/LootTableRegistry.java @@ -540,16 +540,18 @@ public static void setLootTable(Entity e, LootTable table){ } public static void setLootTable(Block b, LootTable table){ - PersistentDataContainer customBlockData = new CustomBlockData(b, ValhallaMMO.getInstance()); - if (table == null) customBlockData.remove(STORED_LOOT_TABLE); - else customBlockData.set(STORED_LOOT_TABLE, PersistentDataType.STRING, table.getKey()); + return; //todo fix for folia +// PersistentDataContainer customBlockData = new CustomBlockData(b, ValhallaMMO.getInstance()); +// if (table == null) customBlockData.remove(STORED_LOOT_TABLE); +// else customBlockData.set(STORED_LOOT_TABLE, PersistentDataType.STRING, table.getKey()); } public static void setFreeSelectionTable(ItemMeta meta, boolean freeSelection, boolean allowRepeats){ - if (freeSelection) meta.getPersistentDataContainer().set(FREE_SELECTION_TABLE, PersistentDataType.BYTE, (byte) 1); - else meta.getPersistentDataContainer().remove(FREE_SELECTION_TABLE); - if (allowRepeats) meta.getPersistentDataContainer().set(FREE_SELECTION_ALLOW_DUPLICATES, PersistentDataType.BYTE, (byte) 1); - else meta.getPersistentDataContainer().remove(FREE_SELECTION_ALLOW_DUPLICATES); + return; //todo fix for folia +// if (freeSelection) meta.getPersistentDataContainer().set(FREE_SELECTION_TABLE, PersistentDataType.BYTE, (byte) 1); +// else meta.getPersistentDataContainer().remove(FREE_SELECTION_TABLE); +// if (allowRepeats) meta.getPersistentDataContainer().set(FREE_SELECTION_ALLOW_DUPLICATES, PersistentDataType.BYTE, (byte) 1); +// else meta.getPersistentDataContainer().remove(FREE_SELECTION_ALLOW_DUPLICATES); } /** diff --git a/core/src/main/java/me/athlaeos/valhallammo/parties/PartyEXPGainListener.java b/core/src/main/java/me/athlaeos/valhallammo/parties/PartyEXPGainListener.java index c112a1d9..badaa926 100644 --- a/core/src/main/java/me/athlaeos/valhallammo/parties/PartyEXPGainListener.java +++ b/core/src/main/java/me/athlaeos/valhallammo/parties/PartyEXPGainListener.java @@ -3,6 +3,7 @@ import me.athlaeos.valhallammo.ValhallaMMO; import me.athlaeos.valhallammo.event.PlayerSkillExperienceGainEvent; import me.athlaeos.valhallammo.hooks.WorldGuardHook; +import me.athlaeos.valhallammo.utility.Scheduling; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -31,7 +32,7 @@ public void onEXPGain(PlayerSkillExperienceGainEvent e){ if (expSharingMultiplier <= 0) return; double fraction = (e.getAmount() / (nearbyMembers.size())) * expSharingMultiplier; e.setCancelled(true); - ValhallaMMO.getInstance().getServer().getScheduler().runTaskAsynchronously(ValhallaMMO.getInstance(), () -> { + Scheduling.runTaskAsync(ValhallaMMO.getInstance(), () -> { nearbyMembers.forEach(p -> e.getLeveledSkill().addEXP(p, fraction, false, PlayerSkillExperienceGainEvent.ExperienceGainReason.EXP_SHARE)); }); } diff --git a/core/src/main/java/me/athlaeos/valhallammo/persistence/implementations/PDC.java b/core/src/main/java/me/athlaeos/valhallammo/persistence/implementations/PDC.java index 8dcada07..c7f818a0 100644 --- a/core/src/main/java/me/athlaeos/valhallammo/persistence/implementations/PDC.java +++ b/core/src/main/java/me/athlaeos/valhallammo/persistence/implementations/PDC.java @@ -8,6 +8,7 @@ import me.athlaeos.valhallammo.playerstats.profiles.Profile; import me.athlaeos.valhallammo.playerstats.profiles.ProfileRegistry; import me.athlaeos.valhallammo.skills.skills.SkillRegistry; +import me.athlaeos.valhallammo.utility.Scheduling; import me.athlaeos.valhallammo.utility.Utils; import org.bukkit.entity.Player; import org.bukkit.persistence.PersistentDataType; @@ -54,7 +55,7 @@ public void onProfileRegistration(Profile profile) { @Override public void loadProfile(Player p) { if (persistentProfiles.containsKey(p.getUniqueId())) return; - ValhallaMMO.getInstance().getServer().getScheduler().runTaskAsynchronously(ValhallaMMO.getInstance(), () -> { + Scheduling.runTaskAsync(ValhallaMMO.getInstance(), () -> { Map, Profile> profiles = persistentProfiles.getOrDefault(p.getUniqueId(), new HashMap<>()); for (Profile pr : ProfileRegistry.getRegisteredProfiles().values()) { String jsonProfile = p.getPersistentDataContainer().get(pr.getKey(), PersistentDataType.STRING); diff --git a/core/src/main/java/me/athlaeos/valhallammo/persistence/implementations/SQL.java b/core/src/main/java/me/athlaeos/valhallammo/persistence/implementations/SQL.java index 537e4246..66f9b8a7 100644 --- a/core/src/main/java/me/athlaeos/valhallammo/persistence/implementations/SQL.java +++ b/core/src/main/java/me/athlaeos/valhallammo/persistence/implementations/SQL.java @@ -12,11 +12,12 @@ import me.athlaeos.valhallammo.playerstats.profiles.Profile; import me.athlaeos.valhallammo.playerstats.profiles.ProfileRegistry; import me.athlaeos.valhallammo.skills.skills.SkillRegistry; +import me.athlaeos.valhallammo.utility.Scheduling; import me.athlaeos.valhallammo.utility.Utils; +import me.athlaeos.valhallammo.utility.ValhallaRunnable; import org.bukkit.OfflinePlayer; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.Player; -import org.bukkit.scheduler.BukkitRunnable; import java.sql.*; import java.util.*; @@ -55,7 +56,7 @@ public Connection getConnection() { return null; } if (conn != null){ - new BukkitRunnable(){ + new ValhallaRunnable(){ @Override public void run() { try { @@ -65,7 +66,7 @@ public void run() { cancel(); } } - }.runTaskTimerAsynchronously(ValhallaMMO.getInstance(), ping_delay, ping_delay); + }.runTaskTimerAsync(ValhallaMMO.getInstance(), ping_delay, ping_delay); } return conn; } @@ -158,7 +159,7 @@ public static void createTable(Profile type, Database database) { public void loadProfile(Player p) { if (persistentProfiles.containsKey(p.getUniqueId())) return; // stats are presumably already loaded in and so they do not // need to be loaded in from the database again - ValhallaMMO.getInstance().getServer().getScheduler().runTaskAsynchronously(ValhallaMMO.getInstance(), () -> { + Scheduling.runTaskAsync(ValhallaMMO.getInstance(), () -> { boolean runPersistentStartingPerks = false; Map, Profile> profs = persistentProfiles.getOrDefault(p.getUniqueId(), new HashMap<>()); for (Class pr : ProfileRegistry.getRegisteredProfiles().keySet()){ @@ -259,7 +260,7 @@ public void saveAllProfiles() { @Override public void saveProfile(Player p) { if (persistentProfiles.containsKey(p.getUniqueId())){ - ValhallaMMO.getInstance().getServer().getScheduler().runTaskAsynchronously(ValhallaMMO.getInstance(), () -> { + Scheduling.runTaskAsync(ValhallaMMO.getInstance(), () -> { if (!JoinLeaveListener.getLoadedProfiles().contains(p.getUniqueId())) return; for (Profile profile : persistentProfiles.getOrDefault(p.getUniqueId(), new HashMap<>()).values()){ insertOrUpdateProfile(p.getUniqueId(), conn, profile); diff --git a/core/src/main/java/me/athlaeos/valhallammo/persistence/implementations/SQLite.java b/core/src/main/java/me/athlaeos/valhallammo/persistence/implementations/SQLite.java index 152a7f95..240d1927 100644 --- a/core/src/main/java/me/athlaeos/valhallammo/persistence/implementations/SQLite.java +++ b/core/src/main/java/me/athlaeos/valhallammo/persistence/implementations/SQLite.java @@ -11,10 +11,11 @@ import me.athlaeos.valhallammo.playerstats.profiles.Profile; import me.athlaeos.valhallammo.playerstats.profiles.ProfileRegistry; import me.athlaeos.valhallammo.skills.skills.SkillRegistry; +import me.athlaeos.valhallammo.utility.Scheduling; import me.athlaeos.valhallammo.utility.Utils; +import me.athlaeos.valhallammo.utility.ValhallaRunnable; import org.bukkit.OfflinePlayer; import org.bukkit.entity.Player; -import org.bukkit.scheduler.BukkitRunnable; import java.io.File; import java.io.IOException; @@ -106,7 +107,7 @@ public void onProfileRegistration(Profile profile) { public void loadProfile(Player p) { if (persistentProfiles.containsKey(p.getUniqueId())) return; // stats are presumably already loaded in, and so they do not // need to be loaded in from the database again - new BukkitRunnable(){ + new ValhallaRunnable(){ @Override public void run() { Map, Profile> profs = persistentProfiles.getOrDefault(p.getUniqueId(), new HashMap<>()); @@ -125,7 +126,7 @@ public void run() { JoinLeaveListener.getLoadedProfiles().add(p.getUniqueId()); SkillRegistry.updateSkillProgression(p, runPersistentStartingPerks); } - }.runTaskAsynchronously(ValhallaMMO.getInstance()); + }.runTaskAsync(ValhallaMMO.getInstance()); } @Override @@ -143,7 +144,7 @@ public void saveAllProfiles() { @Override public void saveProfile(Player p) { if (persistentProfiles.containsKey(p.getUniqueId())){ - ValhallaMMO.getInstance().getServer().getScheduler().runTaskAsynchronously(ValhallaMMO.getInstance(), () -> { + Scheduling.runTaskAsync(ValhallaMMO.getInstance(), () -> { for (Profile profile : persistentProfiles.getOrDefault(p.getUniqueId(), new HashMap<>()).values()){ if (!shouldPersist(profile)) continue; SQL.insertOrUpdateProfile(p.getUniqueId(), conn, profile); diff --git a/core/src/main/java/me/athlaeos/valhallammo/playerstats/AccumulativeStatManager.java b/core/src/main/java/me/athlaeos/valhallammo/playerstats/AccumulativeStatManager.java index df80b6b4..b119edb7 100644 --- a/core/src/main/java/me/athlaeos/valhallammo/playerstats/AccumulativeStatManager.java +++ b/core/src/main/java/me/athlaeos/valhallammo/playerstats/AccumulativeStatManager.java @@ -12,6 +12,7 @@ import me.athlaeos.valhallammo.playerstats.profiles.ProfileCache; import me.athlaeos.valhallammo.playerstats.profiles.implementations.*; import me.athlaeos.valhallammo.playerstats.statsources.*; +import me.athlaeos.valhallammo.utility.Scheduling; import me.athlaeos.valhallammo.utility.Utils; import me.athlaeos.valhallammo.version.EnchantmentMappings; import org.bukkit.Material; @@ -474,16 +475,35 @@ private static boolean isStatCached(Entity e, String stat){ } private static void attemptMapCleanup(){ - ValhallaMMO.getInstance().getServer().getScheduler().runTask(ValhallaMMO.getInstance(), () -> { + if (ValhallaMMO.getPlatform().supportsFolia()) { if (lastMapCleanup + 120000 < System.currentTimeMillis()){ // cleaning up map every 2 minutes - new HashSet<>(statCache.keySet()).stream().filter(u -> { + new HashSet<>(statCache.keySet()).stream().forEach(u -> { Entity entity = ValhallaMMO.getInstance().getServer().getEntity(u); - return entity == null || !entity.isValid(); - }).forEach(statCache::remove); + if (entity == null) { + statCache.remove(u); + return; + } + Scheduling.runEntityTask(ValhallaMMO.getInstance(), entity, () -> { + if (!entity.isValid()) { + statCache.remove(u); + } + }); + }); lastMapCleanup = System.currentTimeMillis(); } - }); + } else { + Scheduling.runTask(ValhallaMMO.getInstance(), () -> { + if (lastMapCleanup + 120000 < System.currentTimeMillis()){ + // cleaning up map every 2 minutes + new HashSet<>(statCache.keySet()).stream().filter(u -> { + Entity entity = ValhallaMMO.getInstance().getServer().getEntity(u); + return entity == null || !entity.isValid(); + }).forEach(statCache::remove); + lastMapCleanup = System.currentTimeMillis(); + } + }); + } } public static void resetCache(Entity e){ diff --git a/core/src/main/java/me/athlaeos/valhallammo/playerstats/EntityCache.java b/core/src/main/java/me/athlaeos/valhallammo/playerstats/EntityCache.java index e3e7f468..d30841f3 100644 --- a/core/src/main/java/me/athlaeos/valhallammo/playerstats/EntityCache.java +++ b/core/src/main/java/me/athlaeos/valhallammo/playerstats/EntityCache.java @@ -2,6 +2,7 @@ import me.athlaeos.valhallammo.ValhallaMMO; import me.athlaeos.valhallammo.utility.EntityUtils; +import me.athlaeos.valhallammo.utility.Scheduling; import org.bukkit.entity.Entity; import org.bukkit.entity.LivingEntity; @@ -44,18 +45,39 @@ public static void removeProperties(LivingEntity entity){ } public static void attemptCacheCleanup(){ - ValhallaMMO.getInstance().getServer().getScheduler().runTask(ValhallaMMO.getInstance(), () -> { + if (ValhallaMMO.getPlatform().supportsFolia()) { if (lastCacheCleanup + CACHE_CLEANUP_DELAY < System.currentTimeMillis()){ Collection uuids = new HashSet<>(cachedProperties.keySet()); uuids.forEach(u -> { Entity entity = ValhallaMMO.getInstance().getServer().getEntity(u); - if (entity == null || !entity.isValid()){ + if (entity == null) { cachedProperties.remove(u); lastCacheRefreshMap.remove(u); + return; } + Scheduling.runEntityTask(ValhallaMMO.getInstance(), entity, () -> { + if (!entity.isValid()){ + cachedProperties.remove(u); + lastCacheRefreshMap.remove(u); + } + }); }); lastCacheCleanup = System.currentTimeMillis(); } - }); + } else { + Scheduling.runTask(ValhallaMMO.getInstance(), () -> { + if (lastCacheCleanup + CACHE_CLEANUP_DELAY < System.currentTimeMillis()){ + Collection uuids = new HashSet<>(cachedProperties.keySet()); + uuids.forEach(u -> { + Entity entity = ValhallaMMO.getInstance().getServer().getEntity(u); + if (entity == null || !entity.isValid()){ + cachedProperties.remove(u); + lastCacheRefreshMap.remove(u); + } + }); + lastCacheCleanup = System.currentTimeMillis(); + } + }); + } } } diff --git a/core/src/main/java/me/athlaeos/valhallammo/playerstats/LeaderboardManager.java b/core/src/main/java/me/athlaeos/valhallammo/playerstats/LeaderboardManager.java index 33ca25e0..ba415abb 100644 --- a/core/src/main/java/me/athlaeos/valhallammo/playerstats/LeaderboardManager.java +++ b/core/src/main/java/me/athlaeos/valhallammo/playerstats/LeaderboardManager.java @@ -11,6 +11,7 @@ import me.athlaeos.valhallammo.playerstats.format.StatFormat; import me.athlaeos.valhallammo.playerstats.profiles.Profile; import me.athlaeos.valhallammo.playerstats.profiles.ProfileRegistry; +import me.athlaeos.valhallammo.utility.Scheduling; import me.athlaeos.valhallammo.utility.Utils; import org.bukkit.command.CommandSender; import org.bukkit.configuration.ConfigurationSection; @@ -100,7 +101,7 @@ public static void refreshLeaderboards(){ public static void fetchLeaderboard(String leaderboard, boolean cache, Action> callback, boolean reload){ Leaderboard l = leaderboards.get(leaderboard); if (l == null || !(ProfileRegistry.getPersistence() instanceof LeaderboardCompatible f)) return; - ValhallaMMO.getInstance().getServer().getScheduler().runTaskAsynchronously(ValhallaMMO.getInstance(), () -> { + Scheduling.runTaskAsync(ValhallaMMO.getInstance(), () -> { if (cachedLeaderboardsByRank.containsKey(l.key) && !reload) { if (callback != null) callback.act(cachedLeaderboardsByRank.get(l.key)); } else { @@ -114,7 +115,7 @@ public static void fetchLeaderboard(String leaderboard, boolean cache, Action callback){ Leaderboard l = leaderboards.get(leaderboard); if (l == null || !(ProfileRegistry.getPersistence() instanceof LeaderboardCompatible f)) return; - ValhallaMMO.getInstance().getServer().getScheduler().runTaskAsynchronously(ValhallaMMO.getInstance(), () -> { + Scheduling.runTaskAsync(ValhallaMMO.getInstance(), () -> { if (!cachedLeaderboardsByRank.containsKey(l.key)) cache(l, f.queryLeaderboardEntries(l)); LeaderboardEntry entry = cachedLeaderboardsByPlayer.getOrDefault(l.key, new HashMap<>()).get(uuid); if (entry == null) return; diff --git a/core/src/main/java/me/athlaeos/valhallammo/playerstats/profiles/ProfileRegistry.java b/core/src/main/java/me/athlaeos/valhallammo/playerstats/profiles/ProfileRegistry.java index 269fe8f1..21892b3b 100644 --- a/core/src/main/java/me/athlaeos/valhallammo/playerstats/profiles/ProfileRegistry.java +++ b/core/src/main/java/me/athlaeos/valhallammo/playerstats/profiles/ProfileRegistry.java @@ -14,6 +14,7 @@ import me.athlaeos.valhallammo.playerstats.format.StatFormat; import me.athlaeos.valhallammo.playerstats.profiles.implementations.*; import me.athlaeos.valhallammo.skills.skills.Skill; +import me.athlaeos.valhallammo.utility.Scheduling; import org.bukkit.entity.Player; import java.util.Collections; @@ -70,10 +71,10 @@ public static void setupDatabase(){ if (((Database) persistence).getConnection() == null) persistence = new SQLite(); // if SQL connection fails, choose SQLite if (((Database) persistence).getConnection() == null) persistence = new PDC(); // if SQLite fails, choose PDC - ValhallaMMO.getInstance().getServer().getScheduler().runTaskTimerAsynchronously(ValhallaMMO.getInstance(), () -> { + Scheduling.runTaskTimerAsync(ValhallaMMO.getInstance(), delay_profile_saving, delay_profile_saving, () -> { saveAll(); LeaderboardManager.refreshLeaderboards(); - }, delay_profile_saving, delay_profile_saving); + }); } public static void saveAll(){ diff --git a/core/src/main/java/me/athlaeos/valhallammo/playerstats/statsources/PotionEffectSingleUseSource.java b/core/src/main/java/me/athlaeos/valhallammo/playerstats/statsources/PotionEffectSingleUseSource.java index f8d33f44..0380e3f6 100644 --- a/core/src/main/java/me/athlaeos/valhallammo/playerstats/statsources/PotionEffectSingleUseSource.java +++ b/core/src/main/java/me/athlaeos/valhallammo/playerstats/statsources/PotionEffectSingleUseSource.java @@ -7,6 +7,7 @@ import me.athlaeos.valhallammo.playerstats.EntityCache; import me.athlaeos.valhallammo.potioneffects.CustomPotionEffect; import me.athlaeos.valhallammo.potioneffects.PotionEffectRegistry; +import me.athlaeos.valhallammo.utility.Scheduling; import org.bukkit.entity.Entity; import org.bukkit.entity.LivingEntity; import org.bukkit.event.entity.EntityPotionEffectEvent; @@ -35,7 +36,7 @@ public double fetch(Entity statPossessor, boolean use) { effect.setEffectiveUntil(0); PotionEffectRegistry.addEffect(l, null, effect, true, 1, EntityPotionEffectEvent.Cause.EXPIRATION, EntityPotionEffectEvent.Action.REMOVED); } - ValhallaMMO.getInstance().getServer().getScheduler().runTaskLater(ValhallaMMO.getInstance(), () -> AccumulativeStatManager.resetCache(l), 1L); + Scheduling.runTaskLater(ValhallaMMO.getInstance(), () -> AccumulativeStatManager.resetCache(l), 1L); return amplifier; } return 0; diff --git a/core/src/main/java/me/athlaeos/valhallammo/potioneffects/CustomEffectSidebarDisplay.java b/core/src/main/java/me/athlaeos/valhallammo/potioneffects/CustomEffectSidebarDisplay.java index 9613479c..823bad0b 100644 --- a/core/src/main/java/me/athlaeos/valhallammo/potioneffects/CustomEffectSidebarDisplay.java +++ b/core/src/main/java/me/athlaeos/valhallammo/potioneffects/CustomEffectSidebarDisplay.java @@ -5,6 +5,7 @@ import me.athlaeos.valhallammo.playerstats.EntityCache; import me.athlaeos.valhallammo.playerstats.profiles.ProfileCache; import me.athlaeos.valhallammo.playerstats.profiles.implementations.PowerProfile; +import me.athlaeos.valhallammo.utility.Scheduling; import me.athlaeos.valhallammo.utility.SideBarUtils; import me.athlaeos.valhallammo.utility.StringUtils; import me.athlaeos.valhallammo.utility.Utils; @@ -17,7 +18,7 @@ public class CustomEffectSidebarDisplay implements CustomEffectDisplay{ @Override public void start() { - ValhallaMMO.getInstance().getServer().getScheduler().runTaskTimer(ValhallaMMO.getInstance(), () -> { + Scheduling.runTaskTimer(ValhallaMMO.getInstance(), () -> { for (UUID uuid : new HashSet<>(PotionEffectRegistry.affectedEntityTracker())){ Entity e = ValhallaMMO.getInstance().getServer().getEntity(uuid); if (!(e instanceof Player p)) continue; diff --git a/core/src/main/java/me/athlaeos/valhallammo/potioneffects/implementations/Stun.java b/core/src/main/java/me/athlaeos/valhallammo/potioneffects/implementations/Stun.java index 996e1449..8e9dc775 100644 --- a/core/src/main/java/me/athlaeos/valhallammo/potioneffects/implementations/Stun.java +++ b/core/src/main/java/me/athlaeos/valhallammo/potioneffects/implementations/Stun.java @@ -12,10 +12,7 @@ import me.athlaeos.valhallammo.potioneffects.EffectClass; import me.athlaeos.valhallammo.potioneffects.PotionEffectRegistry; import me.athlaeos.valhallammo.potioneffects.PotionEffectWrapper; -import me.athlaeos.valhallammo.utility.ItemUtils; -import me.athlaeos.valhallammo.utility.StringUtils; -import me.athlaeos.valhallammo.utility.Timer; -import me.athlaeos.valhallammo.utility.Utils; +import me.athlaeos.valhallammo.utility.*; import me.athlaeos.valhallammo.version.ConventionUtils; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.YamlConfiguration; @@ -100,7 +97,7 @@ public void onInflict(LivingEntity p, LivingEntity causedBy, double amplifier, i * @param force true if the entity should be stunned regardless of immunity, false otherwise */ public static void stunTarget(LivingEntity entity, LivingEntity causedBy, int duration, boolean force){ - ValhallaMMO.getInstance().getServer().getScheduler().runTaskLater(ValhallaMMO.getInstance(), () -> { + Scheduling.runEntityTask(ValhallaMMO.getInstance(), entity, 1L, () -> { if (!entity.isValid() || entity.isDead()) return; double durationMultiplier = force ? 1 : Math.max(0, 1 - AccumulativeStatManager.getRelationalStats("STUN_RESISTANCE", entity, causedBy, true)); int newDuration = (int) Math.round(duration * durationMultiplier); @@ -118,7 +115,7 @@ public static void stunTarget(LivingEntity entity, LivingEntity causedBy, int du EntityCache.resetPotionEffects(l); // adding/removing an effect as a result of this method should reset the entity's potion effect cache Timer.setCooldown(entity.getUniqueId(), stunImmunityDuration * 50, "stun_immunity"); } - }, 1L); + }); } public static void attemptStun(LivingEntity entity, LivingEntity causedBy){ diff --git a/core/src/main/java/me/athlaeos/valhallammo/resourcepack/Host.java b/core/src/main/java/me/athlaeos/valhallammo/resourcepack/Host.java index cbed4853..9ab6ea02 100644 --- a/core/src/main/java/me/athlaeos/valhallammo/resourcepack/Host.java +++ b/core/src/main/java/me/athlaeos/valhallammo/resourcepack/Host.java @@ -1,7 +1,8 @@ package me.athlaeos.valhallammo.resourcepack; import me.athlaeos.valhallammo.ValhallaMMO; -import org.bukkit.scheduler.BukkitTask; +import me.athlaeos.valhallammo.platform.scheduler.TaskHolder; +import me.athlaeos.valhallammo.utility.Scheduling; import java.io.IOException; import java.net.ServerSocket; @@ -14,7 +15,7 @@ public class Host { private static boolean running = true; private static int port = ValhallaMMO.getPluginConfig().getInt("resourcepack_port"); private static String ip = ValhallaMMO.getPluginConfig().getString("server_ip"); - private static BukkitTask task = null; + private static TaskHolder task = null; public static boolean start(){ try { @@ -46,7 +47,7 @@ public static void stop(){ } private static void initializeTCP(){ - task = ValhallaMMO.getInstance().getServer().getScheduler().runTaskAsynchronously(ValhallaMMO.getInstance(), () -> { + task = Scheduling.runTaskAsync(ValhallaMMO.getInstance(), () -> { if (data != null) { try { Socket s = socket.accept(); diff --git a/core/src/main/java/me/athlaeos/valhallammo/skills/perk_rewards/PerkRewardRegistry.java b/core/src/main/java/me/athlaeos/valhallammo/skills/perk_rewards/PerkRewardRegistry.java index 711a24f5..b26929e9 100644 --- a/core/src/main/java/me/athlaeos/valhallammo/skills/perk_rewards/PerkRewardRegistry.java +++ b/core/src/main/java/me/athlaeos/valhallammo/skills/perk_rewards/PerkRewardRegistry.java @@ -9,6 +9,7 @@ import me.athlaeos.valhallammo.playerstats.profiles.implementations.*; import me.athlaeos.valhallammo.skills.perk_rewards.implementations.*; import me.athlaeos.valhallammo.skills.skills.implementations.AlchemySkill; +import me.athlaeos.valhallammo.utility.Scheduling; import org.bukkit.Material; import org.bukkit.Tag; import org.bukkit.entity.Player; @@ -25,12 +26,12 @@ public class PerkRewardRegistry { register(new ProgressReset("reset_" + type.toString().toLowerCase(java.util.Locale.US), type)); } - BiAction forget = (s, p) -> ValhallaMMO.getInstance().getServer().getScheduler().runTask(ValhallaMMO.getInstance(), () -> { + BiAction forget = (s, p) -> Scheduling.runEntityTask(ValhallaMMO.getInstance(), p, () -> { ValhallaKeyedRecipe recipe = CustomRecipeRegistry.getAllKeyedRecipesByName().get(s); if (recipe == null) return; p.undiscoverRecipe(recipe.getKey()); }); - BiAction discover = (s, p) -> ValhallaMMO.getInstance().getServer().getScheduler().runTask(ValhallaMMO.getInstance(), () -> { + BiAction discover = (s, p) -> Scheduling.runEntityTask(ValhallaMMO.getInstance(), p, () -> { ValhallaKeyedRecipe recipe = CustomRecipeRegistry.getAllKeyedRecipesByName().get(s); if (recipe == null) return; p.discoverRecipe(recipe.getKey()); diff --git a/core/src/main/java/me/athlaeos/valhallammo/skills/skills/Skill.java b/core/src/main/java/me/athlaeos/valhallammo/skills/skills/Skill.java index 14b9eaca..1df4f233 100644 --- a/core/src/main/java/me/athlaeos/valhallammo/skills/skills/Skill.java +++ b/core/src/main/java/me/athlaeos/valhallammo/skills/skills/Skill.java @@ -21,10 +21,7 @@ import me.athlaeos.valhallammo.skills.perkunlockconditions.UnlockCondition; import me.athlaeos.valhallammo.skills.perkunlockconditions.UnlockConditionRegistry; import me.athlaeos.valhallammo.skills.skills.implementations.PowerSkill; -import me.athlaeos.valhallammo.utility.BossBarUtils; -import me.athlaeos.valhallammo.utility.ItemUtils; -import me.athlaeos.valhallammo.utility.StringUtils; -import me.athlaeos.valhallammo.utility.Utils; +import me.athlaeos.valhallammo.utility.*; import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.chat.TextComponent; import org.bukkit.Bukkit; @@ -37,7 +34,6 @@ import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; -import org.bukkit.scheduler.BukkitRunnable; import java.util.*; @@ -633,7 +629,7 @@ private void changePlayerLevel(Player p, int from, int to, boolean silent) { ); } - ValhallaMMO.getInstance().getServer().getScheduler().runTaskAsynchronously(ValhallaMMO.getInstance(), () -> { + Scheduling.runTaskAsync(ValhallaMMO.getInstance(), () -> { for (int i = from; i > to; i--) { for (PerkReward reward : levelingPerks) { if (reward instanceof MultiplicativeReward || reward.isPersistent()) continue; @@ -714,7 +710,7 @@ private void changePlayerLevel(Player p, int from, int to, boolean silent) { ); } else { int finalDuration = lastDelay; - new BukkitRunnable(){ + new ValhallaRunnable(){ int timer = 0; @Override public void run() { @@ -733,7 +729,7 @@ public void run() { } } - ValhallaMMO.getInstance().getServer().getScheduler().runTaskAsynchronously(ValhallaMMO.getInstance(), () -> { + Scheduling.runTaskAsync(ValhallaMMO.getInstance(), () -> { for (int i = from + 1; i <= to; i++) { for (PerkReward reward : levelingPerks) { if (reward instanceof MultiplicativeReward) continue; @@ -802,7 +798,7 @@ public void updateSkillStats(Player p, boolean runPersistentStartingPerks) { reward.apply(p); } if (!perk.getExpenses().isEmpty()){ - ValhallaMMO.getInstance().getServer().getScheduler().runTask(ValhallaMMO.getInstance(), () -> { + Scheduling.runTask(ValhallaMMO.getInstance(), () -> { for (ResourceExpense expense : perk.getExpenses()) { expense.purchase(p, false); } @@ -811,8 +807,9 @@ public void updateSkillStats(Player p, boolean runPersistentStartingPerks) { } } - ValhallaMMO.getInstance().getServer().getScheduler().runTask(ValhallaMMO.getInstance(), () -> - ValhallaMMO.getInstance().getServer().getPluginManager().callEvent(new ValhallaUpdatedStatsEvent(p, getProfileType()))); + Scheduling.runTask(ValhallaMMO.getInstance(), () -> + ValhallaMMO.getInstance().getServer().getPluginManager().callEvent(new ValhallaUpdatedStatsEvent(p, getProfileType())) + ); } private final boolean perksForgettable = ConfigManager.getConfig("config.yml").reload().get().getBoolean("forgettable_perks"); diff --git a/core/src/main/java/me/athlaeos/valhallammo/skills/skills/SkillRegistry.java b/core/src/main/java/me/athlaeos/valhallammo/skills/skills/SkillRegistry.java index 72a49c5d..776cfc1d 100644 --- a/core/src/main/java/me/athlaeos/valhallammo/skills/skills/SkillRegistry.java +++ b/core/src/main/java/me/athlaeos/valhallammo/skills/skills/SkillRegistry.java @@ -9,6 +9,7 @@ import me.athlaeos.valhallammo.skills.perk_rewards.PerkRewardRegistry; import me.athlaeos.valhallammo.skills.perk_rewards.implementations.*; import me.athlaeos.valhallammo.skills.skills.implementations.*; +import me.athlaeos.valhallammo.utility.Scheduling; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.Player; @@ -89,7 +90,7 @@ public static void reload() { } public static void updateSkillProgression(Player p, boolean runPersistentStartingPerks){ - ValhallaMMO.getInstance().getServer().getScheduler().runTaskAsynchronously(ValhallaMMO.getInstance(), () -> { + Scheduling.runTaskAsync(ValhallaMMO.getInstance(), () -> { allSkills.values().forEach(s -> { ProfileRegistry.setSkillProfile(p, ProfileRegistry.getBlankProfile(p, s.getProfileType()), s.getProfileType()); }); diff --git a/core/src/main/java/me/athlaeos/valhallammo/skills/skills/implementations/ArcherySkill.java b/core/src/main/java/me/athlaeos/valhallammo/skills/skills/implementations/ArcherySkill.java index 6941cf7f..937ef6df 100644 --- a/core/src/main/java/me/athlaeos/valhallammo/skills/skills/implementations/ArcherySkill.java +++ b/core/src/main/java/me/athlaeos/valhallammo/skills/skills/implementations/ArcherySkill.java @@ -49,7 +49,6 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.PlayerInventory; import org.bukkit.inventory.meta.CrossbowMeta; -import org.bukkit.scheduler.BukkitRunnable; import java.util.*; @@ -217,7 +216,7 @@ else if (profile.doesCritOnStealth()) { } e.setDamage(damage); - ValhallaMMO.getInstance().getServer().getScheduler().runTaskLater(ValhallaMMO.getInstance(), () -> { + Scheduling.runLocationTask(ValhallaMMO.getInstance(), v.getLocation(), 2L, () -> { if (e.isCancelled() || !p.isOnline()) return; double damageTaken = EntityDamagedListener.getLastDamageTaken(v.getUniqueId(), e.getFinalDamage()); if (damageTaken > 1000000) return; @@ -233,7 +232,7 @@ else if (profile.doesCritOnStealth()) { false, PlayerSkillExperienceGainEvent.ExperienceGainReason.SKILL_ACTION); if (isChunkNerfed && !EntitySpawnListener.isTrialSpawned(v)) ChunkEXPNerf.increment(v.getLocation().getChunk(), p, "archery"); - }, 2L); + }); } @EventHandler(priority = EventPriority.MONITOR) @@ -265,25 +264,25 @@ public void onArrowShot(EntityShootBowEvent e){ if (user.noGravity) { a.setGravity(false); // make charged shot disappear after 10 seconds to prevent arrows staying in the air forever - new BukkitRunnable(){ + new ValhallaRunnable(){ @Override public void run() { e.getProjectile().remove(); } - }.runTaskLater(ValhallaMMO.getInstance(), 200); + }.runEntity(ValhallaMMO.getInstance(), e.getProjectile(), 200); } if (chargedShotFireAnimation != null) chargedShotFireAnimation.animate(p, p.getEyeLocation(), p.getEyeLocation().getDirection(), 0); if (chargedShotSonicBoomAnimation != null && a.getVelocity().lengthSquared() >= sonicBoomRequiredVelocity) chargedShotSonicBoomAnimation.animate(p, p.getEyeLocation(), p.getEyeLocation().getDirection(), 0); if (trail != null) AnimationUtils.trailProjectile(a, trail == Particle.valueOf(oldOrNew("REDSTONE", "DUST")) ? new RedstoneParticle(trailOptions) : new GenericParticle(trail), 60); if (user.crossbowInstantReload && bow.getType() == Material.CROSSBOW){ - ValhallaMMO.getInstance().getServer().getScheduler().runTaskLater(ValhallaMMO.getInstance(), () -> { + Scheduling.runEntityTask(ValhallaMMO.getInstance(), p, 1L, () -> { boolean mainHand = !ItemUtils.isEmpty(p.getInventory().getItemInMainHand()) && p.getInventory().getItemInMainHand().getType() == Material.CROSSBOW; ItemStack crossbow = mainHand ? p.getInventory().getItemInMainHand() : p.getInventory().getItemInOffHand(); if (ItemUtils.isEmpty(crossbow) || !(crossbow.getItemMeta() instanceof CrossbowMeta crossbowMeta)) return; crossbowMeta.addChargedProjectile(consumable); crossbow.setItemMeta(crossbowMeta); - }, 1L); + }); } } else { chargedShotUsers.remove(p.getUniqueId()); diff --git a/core/src/main/java/me/athlaeos/valhallammo/skills/skills/implementations/EnchantingSkill.java b/core/src/main/java/me/athlaeos/valhallammo/skills/skills/implementations/EnchantingSkill.java index c44881a8..05187fe3 100644 --- a/core/src/main/java/me/athlaeos/valhallammo/skills/skills/implementations/EnchantingSkill.java +++ b/core/src/main/java/me/athlaeos/valhallammo/skills/skills/implementations/EnchantingSkill.java @@ -311,7 +311,7 @@ public void onAttack(EntityDamageByEntityEvent e){ e.setDamage(e.getDamage() * (1 - conversion)); // damage is reduced by the fraction of it that is converted final boolean en = enhanced; - ValhallaMMO.getInstance().getServer().getScheduler().runTaskLater(ValhallaMMO.getInstance(), () -> { + Scheduling.runEntityTask(ValhallaMMO.getInstance(), p, 1L, () -> { for (String damageType : profile.getElementalDamageTypes()){ EntityUtils.damage(v, p, damagePerType, damageType, false); if (en) { @@ -319,7 +319,7 @@ public void onAttack(EntityDamageByEntityEvent e){ if (a != null) a.animate(v, e.getDamager() instanceof Projectile pr ? pr.getLocation() : v.getEyeLocation(), p.getEyeLocation().getDirection(), 0); } } - }, 1L); + }); } @SuppressWarnings("all") @@ -346,7 +346,7 @@ public void onHandSwap(PlayerSwapHandItemsEvent e){ if (elementalBladeActivationAnimation != null) elementalBladeActivationAnimation.animate(e.getPlayer(), e.getPlayer().getLocation(), e.getPlayer().getEyeLocation().getDirection(), 0); } e.setCancelled(true); - ValhallaMMO.getInstance().getServer().getScheduler().runTaskLater(ValhallaMMO.getInstance(), () -> e.getPlayer().updateInventory(), 1L); + Scheduling.runEntityTask(ValhallaMMO.getInstance(), e.getPlayer(), 1L, () -> e.getPlayer().updateInventory()); } @EventHandler(priority = EventPriority.HIGHEST) @@ -447,10 +447,11 @@ public void onAnvilUsage(PrepareAnvilEvent e) { } else { maxLevels = anvilMaxLevelCache.get(combiner.getUniqueId()); if (Timer.isCooldownPassed(combiner.getUniqueId(), "delay_anvil_cache_reset")){ - ValhallaMMO.getInstance().getServer().getScheduler().runTaskLater( + Scheduling.runEntityTask( ValhallaMMO.getInstance(), - () -> anvilMaxLevelCache.remove(combiner.getUniqueId()), - 5L); + combiner, 5L, () + -> anvilMaxLevelCache.remove(combiner.getUniqueId()) + ); Timer.setCooldown(combiner.getUniqueId(), 250, "delay_anvil_cache_reset"); } } diff --git a/core/src/main/java/me/athlaeos/valhallammo/skills/skills/implementations/FarmingSkill.java b/core/src/main/java/me/athlaeos/valhallammo/skills/skills/implementations/FarmingSkill.java index 47cb6ec8..c56404c7 100644 --- a/core/src/main/java/me/athlaeos/valhallammo/skills/skills/implementations/FarmingSkill.java +++ b/core/src/main/java/me/athlaeos/valhallammo/skills/skills/implementations/FarmingSkill.java @@ -241,7 +241,7 @@ public void onInteract(PlayerInteractEvent e){ } } if (clickedBlock.getBlockData() instanceof Beehive b && b.getHoneyLevel() >= b.getMaximumHoneyLevel()) { - ValhallaMMO.getInstance().getServer().getScheduler().runTaskLater(ValhallaMMO.getInstance(), () -> { + Scheduling.runLocationTask(ValhallaMMO.getInstance(), e.getClickedBlock().getLocation(), 5L, () -> { Beehive newHive = clickedBlock.getBlockData() instanceof Beehive bee ? bee : null; if (newHive == null) return; if (newHive.getHoneyLevel() < newHive.getMaximumHoneyLevel()){ @@ -262,7 +262,7 @@ public void onInteract(PlayerInteractEvent e){ clickedBlock.setBlockData(newHive); } } - }, 5L); + }); } } diff --git a/core/src/main/java/me/athlaeos/valhallammo/skills/skills/implementations/HeavyArmorSkill.java b/core/src/main/java/me/athlaeos/valhallammo/skills/skills/implementations/HeavyArmorSkill.java index b6f07528..fd2b5d38 100644 --- a/core/src/main/java/me/athlaeos/valhallammo/skills/skills/implementations/HeavyArmorSkill.java +++ b/core/src/main/java/me/athlaeos/valhallammo/skills/skills/implementations/HeavyArmorSkill.java @@ -107,7 +107,7 @@ public void onDamageTaken(EntityDamageByEntityEvent e){ HeavyArmorProfile profile = ProfileCache.getOrCache(p, HeavyArmorProfile.class); - ValhallaMMO.getInstance().getServer().getScheduler().runTaskLater(ValhallaMMO.getInstance(), () -> { + Scheduling.runEntityTask(ValhallaMMO.getInstance(), p, 2L, () -> { if (e.isCancelled() || !p.isOnline() || e.getDamage() <= 0) return; double chunkNerf = isChunkNerfed ? ChunkEXPNerf.getChunkEXPNerf(p.getLocation().getChunk(), p, "armors") : 1; int count = EntityCache.getAndCacheProperties(p).getHeavyArmorCount(); @@ -133,7 +133,7 @@ public void onDamageTaken(EntityDamageByEntityEvent e){ if (!Timer.isCooldownPassed(p.getUniqueId(), "cooldown_heavy_armor_rage")) Timer.sendCooldownStatus(p, "cooldown_heavy_armor_rage", TranslationManager.getTranslation("ability_rage")); } if (isChunkNerfed) ChunkEXPNerf.increment(p.getLocation().getChunk(), p, "armors"); - }, 2L); + }); } @EventHandler(priority = EventPriority.HIGHEST) diff --git a/core/src/main/java/me/athlaeos/valhallammo/skills/skills/implementations/HeavyWeaponsSkill.java b/core/src/main/java/me/athlaeos/valhallammo/skills/skills/implementations/HeavyWeaponsSkill.java index 64b6b1c8..fe6e44a4 100644 --- a/core/src/main/java/me/athlaeos/valhallammo/skills/skills/implementations/HeavyWeaponsSkill.java +++ b/core/src/main/java/me/athlaeos/valhallammo/skills/skills/implementations/HeavyWeaponsSkill.java @@ -25,10 +25,7 @@ import me.athlaeos.valhallammo.potioneffects.implementations.Stun; import me.athlaeos.valhallammo.skills.ChunkEXPNerf; import me.athlaeos.valhallammo.skills.skills.Skill; -import me.athlaeos.valhallammo.utility.Bleeder; -import me.athlaeos.valhallammo.utility.EntityUtils; -import me.athlaeos.valhallammo.utility.ItemUtils; -import me.athlaeos.valhallammo.utility.Timer; +import me.athlaeos.valhallammo.utility.*; import org.bukkit.Material; import org.bukkit.Sound; import org.bukkit.configuration.ConfigurationSection; @@ -162,7 +159,7 @@ public void onExpAttack(EntityDamageEvent e){ ItemBuilder weapon = damager instanceof Trident t ? new ItemBuilder(t.getItem()) : EntityCache.getAndCacheProperties(p).getMainHand(); if (weapon == null || WeightClass.getWeightClass(weapon.getMeta()) != WeightClass.HEAVY) return; - ValhallaMMO.getInstance().getServer().getScheduler().runTaskLater(ValhallaMMO.getInstance(), () -> { + Scheduling.runLocationTask(ValhallaMMO.getInstance(), l.getLocation(), 2L, () -> { if (e.isCancelled() || !p.isOnline()) return; if (e.getDamage() > 1000000) return; double chunkNerf = !isChunkNerfed || EntitySpawnListener.isTrialSpawned(l) ? 1 : ChunkEXPNerf.getChunkEXPNerf(l.getLocation().getChunk(), p, "weapons"); @@ -179,7 +176,7 @@ public void onExpAttack(EntityDamageEvent e){ false, PlayerSkillExperienceGainEvent.ExperienceGainReason.SKILL_ACTION); if (isChunkNerfed && !EntitySpawnListener.isTrialSpawned(l)) ChunkEXPNerf.increment(l.getLocation().getChunk(), p, "weapons"); - }, 2L); + }); } } diff --git a/core/src/main/java/me/athlaeos/valhallammo/skills/skills/implementations/LightArmorSkill.java b/core/src/main/java/me/athlaeos/valhallammo/skills/skills/implementations/LightArmorSkill.java index 9c29fceb..815e07a1 100644 --- a/core/src/main/java/me/athlaeos/valhallammo/skills/skills/implementations/LightArmorSkill.java +++ b/core/src/main/java/me/athlaeos/valhallammo/skills/skills/implementations/LightArmorSkill.java @@ -21,6 +21,7 @@ import me.athlaeos.valhallammo.skills.ChunkEXPNerf; import me.athlaeos.valhallammo.skills.skills.Skill; import me.athlaeos.valhallammo.utility.EntityUtils; +import me.athlaeos.valhallammo.utility.Scheduling; import me.athlaeos.valhallammo.utility.StringUtils; import me.athlaeos.valhallammo.utility.Timer; import me.athlaeos.valhallammo.version.PotionEffectMappings; @@ -114,7 +115,7 @@ public void onDamageTaken(EntityDamageByEntityEvent e){ LightArmorProfile profile = ProfileCache.getOrCache(p, LightArmorProfile.class); - ValhallaMMO.getInstance().getServer().getScheduler().runTaskLater(ValhallaMMO.getInstance(), () -> { + Scheduling.runEntityTask(ValhallaMMO.getInstance(), p, 2L, () -> { if (e.isCancelled() || !p.isOnline() || e.getDamage() <= 0) return; double chunkNerf = isChunkNerfed ? ChunkEXPNerf.getChunkEXPNerf(p.getLocation().getChunk(), p, "armors") : 1; int count = EntityCache.getAndCacheProperties(p).getLightArmorCount(); @@ -141,7 +142,7 @@ public void onDamageTaken(EntityDamageByEntityEvent e){ if (!Timer.isCooldownPassed(p.getUniqueId(), "cooldown_light_armor_adrenaline")) Timer.sendCooldownStatus(p, "cooldown_light_armor_adrenaline", TranslationManager.getTranslation("ability_adrenaline")); } if (isChunkNerfed) ChunkEXPNerf.increment(p.getLocation().getChunk(), p, "armors"); - }, 2L); + }); } @EventHandler(priority = EventPriority.HIGHEST) diff --git a/core/src/main/java/me/athlaeos/valhallammo/skills/skills/implementations/LightWeaponsSkill.java b/core/src/main/java/me/athlaeos/valhallammo/skills/skills/implementations/LightWeaponsSkill.java index b16da3cd..78ddf392 100644 --- a/core/src/main/java/me/athlaeos/valhallammo/skills/skills/implementations/LightWeaponsSkill.java +++ b/core/src/main/java/me/athlaeos/valhallammo/skills/skills/implementations/LightWeaponsSkill.java @@ -25,10 +25,7 @@ import me.athlaeos.valhallammo.potioneffects.implementations.Stun; import me.athlaeos.valhallammo.skills.ChunkEXPNerf; import me.athlaeos.valhallammo.skills.skills.Skill; -import me.athlaeos.valhallammo.utility.Bleeder; -import me.athlaeos.valhallammo.utility.EntityUtils; -import me.athlaeos.valhallammo.utility.ItemUtils; -import me.athlaeos.valhallammo.utility.Timer; +import me.athlaeos.valhallammo.utility.*; import org.bukkit.Material; import org.bukkit.Sound; import org.bukkit.configuration.ConfigurationSection; @@ -162,7 +159,7 @@ public void onExpAttack(EntityDamageEvent e){ ItemBuilder weapon = damager instanceof Trident t ? new ItemBuilder(t.getItem()) : EntityCache.getAndCacheProperties(p).getMainHand(); if (weapon == null || WeightClass.getWeightClass(weapon.getMeta()) != WeightClass.LIGHT) return; - ValhallaMMO.getInstance().getServer().getScheduler().runTaskLater(ValhallaMMO.getInstance(), () -> { + Scheduling.runLocationTask(ValhallaMMO.getInstance(), l.getLocation(), 2L, () -> { if (e.isCancelled() || !p.isOnline()) return; if (e.getDamage() > 1000000) return; double chunkNerf = !isChunkNerfed || EntitySpawnListener.isTrialSpawned(l) ? 1 : ChunkEXPNerf.getChunkEXPNerf(l.getLocation().getChunk(), p, "weapons"); @@ -179,7 +176,7 @@ public void onExpAttack(EntityDamageEvent e){ false, PlayerSkillExperienceGainEvent.ExperienceGainReason.SKILL_ACTION); if (isChunkNerfed && !EntitySpawnListener.isTrialSpawned(l)) ChunkEXPNerf.increment(l.getLocation().getChunk(), p, "weapons"); - }, 2L); + }); } } diff --git a/core/src/main/java/me/athlaeos/valhallammo/skills/skills/implementations/WoodcuttingSkill.java b/core/src/main/java/me/athlaeos/valhallammo/skills/skills/implementations/WoodcuttingSkill.java index 4d62500a..8631bacd 100644 --- a/core/src/main/java/me/athlaeos/valhallammo/skills/skills/implementations/WoodcuttingSkill.java +++ b/core/src/main/java/me/athlaeos/valhallammo/skills/skills/implementations/WoodcuttingSkill.java @@ -153,7 +153,7 @@ public void onBlockBreak(BlockBreakEvent e){ e.getPlayer().breakBlock(b); }, (b) -> { treeCapitatingPlayers.remove(e.getPlayer().getUniqueId()); - ValhallaMMO.getInstance().getServer().getScheduler().runTaskLater(ValhallaMMO.getInstance(), () -> { + Scheduling.runLocationTask(ValhallaMMO.getInstance(), e.getBlock().getLocation(), 20L, () -> { List leaves = leafOrigin == null ? new ArrayList<>() : new ArrayList<>(BlockUtils.getBlockVein(leafOrigin, treeCapitatorLeavesLimit, bl -> isLeaves(bl) && (!(bl.getBlockData() instanceof Leaves l) || l.getDistance() > 3), treeCapitatorLeavesScanArea)); Collections.shuffle(leaves); BlockUtils.processBlocksDelayed(e.getPlayer(), leaves, (p) -> true, bl -> { @@ -161,7 +161,7 @@ public void onBlockBreak(BlockBreakEvent e){ LootListener.setResponsibleBreaker(bl, e.getPlayer()); BlockUtils.decayBlock(bl); }, null); - }, 20L); + }); }); else BlockUtils.processBlocksPulse(e.getPlayer(), e.getBlock(), vein, p -> { @@ -173,7 +173,7 @@ public void onBlockBreak(BlockBreakEvent e){ e.getPlayer().breakBlock(b); }, (b) -> { treeCapitatingPlayers.remove(e.getPlayer().getUniqueId()); - ValhallaMMO.getInstance().getServer().getScheduler().runTaskLater(ValhallaMMO.getInstance(), () -> { + Scheduling.runLocationTask(ValhallaMMO.getInstance(), e.getBlock().getLocation(), 20L, () -> { List leaves = leafOrigin == null ? new ArrayList<>() : new ArrayList<>(BlockUtils.getBlockVein(leafOrigin, treeCapitatorLeavesLimit, bl -> isLeaves(bl) && (!(bl.getBlockData() instanceof Leaves l) || l.getDistance() > 3), treeCapitatorLeavesScanArea)); Collections.shuffle(leaves); BlockUtils.processBlocksDelayed(e.getPlayer(), leaves, (p) -> true, bl -> { @@ -181,7 +181,7 @@ public void onBlockBreak(BlockBreakEvent e){ LootListener.setResponsibleBreaker(bl, e.getPlayer()); BlockUtils.decayBlock(bl); }, null); - }, 20L); + }); }); Timer.setCooldownIgnoreIfPermission(e.getPlayer(), profile.getTreeCapitatorCooldown() * 50, "woodcutting_tree_capitator"); } else { diff --git a/core/src/main/java/me/athlaeos/valhallammo/utility/AnimationUtils.java b/core/src/main/java/me/athlaeos/valhallammo/utility/AnimationUtils.java index 5c9772ed..0ba26be8 100644 --- a/core/src/main/java/me/athlaeos/valhallammo/utility/AnimationUtils.java +++ b/core/src/main/java/me/athlaeos/valhallammo/utility/AnimationUtils.java @@ -7,13 +7,12 @@ import org.bukkit.Particle; import org.bukkit.block.Block; import org.bukkit.entity.Projectile; -import org.bukkit.scheduler.BukkitRunnable; import static me.athlaeos.valhallammo.utility.Utils.oldOrNew; public class AnimationUtils { public static void trailProjectile(Projectile projectile, ParticleWrapper particle, int duration){ - new BukkitRunnable(){ + new ValhallaRunnable(){ int count = 0; @Override public void run() { @@ -23,7 +22,7 @@ public void run() { count++; } - }.runTaskTimer(ValhallaMMO.getInstance(), 1L, 1L); + }.runEntity(ValhallaMMO.getInstance(), projectile, 1L, 1L); } public static void outlineBlock(Block b, int lineDensity, float particleSize, int red, int green, int blue){ diff --git a/core/src/main/java/me/athlaeos/valhallammo/utility/Bleeder.java b/core/src/main/java/me/athlaeos/valhallammo/utility/Bleeder.java index 7b440fed..823e2e38 100644 --- a/core/src/main/java/me/athlaeos/valhallammo/utility/Bleeder.java +++ b/core/src/main/java/me/athlaeos/valhallammo/utility/Bleeder.java @@ -3,7 +3,6 @@ import me.athlaeos.valhallammo.ValhallaMMO; import me.athlaeos.valhallammo.configuration.ConfigManager; import me.athlaeos.valhallammo.dom.CombatType; -import me.athlaeos.valhallammo.dom.MinecraftVersion; import me.athlaeos.valhallammo.event.EntityBleedEvent; import me.athlaeos.valhallammo.hooks.WorldGuardHook; import me.athlaeos.valhallammo.playerstats.AccumulativeStatManager; @@ -16,7 +15,6 @@ import org.bukkit.entity.Entity; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; -import org.bukkit.scheduler.BukkitRunnable; import java.util.HashMap; import java.util.Map; @@ -77,7 +75,7 @@ public static void inflictBleed(LivingEntity bleeder, Entity causedBy, int durat if (bleeder instanceof Player p && (p.getGameMode() == GameMode.CREATIVE || p.getGameMode() == GameMode.SPECTATOR)) return; if (bleeder instanceof Player p && WorldGuardHook.inDisabledRegion(p.getLocation(), p, WorldGuardHook.VMMO_COMBAT_BLEED)) return; else if (WorldGuardHook.inDisabledRegion(bleeder.getLocation(), WorldGuardHook.VMMO_COMBAT_BLEED)) return; - ValhallaMMO.getInstance().getServer().getScheduler().runTaskLater(ValhallaMMO.getInstance(), () -> { + Scheduling.runEntityTask(ValhallaMMO.getInstance(), bleeder, 1L, () -> { BleedingInstance instance = bleedingEntities.get(bleeder.getUniqueId()); double resistance = AccumulativeStatManager.getRelationalStats("BLEED_RESISTANCE", bleeder, causedBy, true); EntityBleedEvent event = new EntityBleedEvent(bleeder, causedBy, combatType, damage, resistance, duration, stacks); @@ -94,10 +92,10 @@ public static void inflictBleed(LivingEntity bleeder, Entity causedBy, int durat 25, 0.4, 0.4, 0.4, Material.REDSTONE_BLOCK.createBlockData()); if (!bleedingEntities.containsKey(bleeder.getUniqueId())) { bleedingEntities.put(bleeder.getUniqueId(), instance); - instance.runTaskTimer(ValhallaMMO.getInstance(), 1L, 1L); + instance.runEntity(ValhallaMMO.getInstance(), bleeder, 1L, 1L); } } - }, 1L); + }); } /** @@ -139,7 +137,7 @@ public static Map getBleedingEntities() { return bleedingEntities; } - public static class BleedingInstance extends BukkitRunnable { + public static class BleedingInstance extends ValhallaRunnable { private final LivingEntity bleedingEntity; private final Entity causedBy; private double bleedingDamage; diff --git a/core/src/main/java/me/athlaeos/valhallammo/utility/BlockUtils.java b/core/src/main/java/me/athlaeos/valhallammo/utility/BlockUtils.java index 4f4eed33..4d2c97f8 100644 --- a/core/src/main/java/me/athlaeos/valhallammo/utility/BlockUtils.java +++ b/core/src/main/java/me/athlaeos/valhallammo/utility/BlockUtils.java @@ -22,7 +22,6 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.persistence.PersistentDataContainer; import org.bukkit.persistence.PersistentDataType; -import org.bukkit.scheduler.BukkitRunnable; import java.util.*; import java.util.function.Predicate; @@ -180,16 +179,16 @@ public static void processBlocksPulse(Player responsible, Block origin, Collecti for (Double distance : sortedByDistance.keySet()){ int time = (int) MathUtils.sqrt(distance); if (time > highest) highest = time; - ValhallaMMO.getInstance().getServer().getScheduler().runTaskLater(ValhallaMMO.getInstance(), () -> processBlocks(responsible, sortedByDistance.get(distance), validation, process, null), time * PULSE_DELAY); + Scheduling.runTaskLater(ValhallaMMO.getInstance(), () -> processBlocks(responsible, sortedByDistance.get(distance), validation, process, null), time * PULSE_DELAY); } if (onFinish != null) { - ValhallaMMO.getInstance().getServer().getScheduler().runTaskLater(ValhallaMMO.getInstance(), () -> onFinish.act(responsible), (highest * PULSE_DELAY) + 1); + Scheduling.runTaskLater(ValhallaMMO.getInstance(), () -> onFinish.act(responsible), (highest * PULSE_DELAY) + 1); } } public static void processBlocksDelayed(Player responsible, Collection blocks, Predicate validation, Action process, Action onFinish){ Iterator iterator = blocks.iterator(); - new BukkitRunnable(){ + new ValhallaRunnable(){ @Override public void run() { if (iterator.hasNext()){ @@ -204,7 +203,7 @@ public void run() { cancel(); } } - }.runTaskTimer(ValhallaMMO.getInstance(), 0L, 1L); + }.runEntity(ValhallaMMO.getInstance(), responsible, 0L, 1L); } private static final Collection ageableExceptions = ItemUtils.getMaterialSet(Arrays.asList( diff --git a/core/src/main/java/me/athlaeos/valhallammo/utility/BossBarUtils.java b/core/src/main/java/me/athlaeos/valhallammo/utility/BossBarUtils.java index 6b55441e..fdaa79c3 100644 --- a/core/src/main/java/me/athlaeos/valhallammo/utility/BossBarUtils.java +++ b/core/src/main/java/me/athlaeos/valhallammo/utility/BossBarUtils.java @@ -5,7 +5,6 @@ import org.bukkit.boss.BarStyle; import org.bukkit.boss.BossBar; import org.bukkit.entity.Player; -import org.bukkit.scheduler.BukkitRunnable; import java.util.HashMap; import java.util.Map; @@ -47,7 +46,7 @@ public static void showBossBarToPlayer(final Player player, String title, double bossBar.setText(title); } - public static class TemporaryBossBar extends BukkitRunnable { + public static class TemporaryBossBar extends ValhallaRunnable { private int timer; private double fraction; private String text; diff --git a/core/src/main/java/me/athlaeos/valhallammo/utility/GlobalEffect.java b/core/src/main/java/me/athlaeos/valhallammo/utility/GlobalEffect.java index d80904b3..e4d2af59 100644 --- a/core/src/main/java/me/athlaeos/valhallammo/utility/GlobalEffect.java +++ b/core/src/main/java/me/athlaeos/valhallammo/utility/GlobalEffect.java @@ -8,12 +8,11 @@ import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.Player; -import org.bukkit.scheduler.BukkitRunnable; import java.util.*; import java.util.stream.Collectors; -public class GlobalEffect extends BukkitRunnable { +public class GlobalEffect extends ValhallaRunnable { private static GlobalEffect runnable = null; private static final Map activeGlobalEffects = new HashMap<>(); private static final Collection validEffects = new HashSet<>(); @@ -81,7 +80,7 @@ public void run() { public static void temporarilyRevealBossBar(Player p){ temporarilyExcludePlayers.add(p); - new BukkitRunnable(){ + new ValhallaRunnable(){ private List currentLoopEffects = new ArrayList<>(); private int currentLoopIndex = 0; private int timer = 0; diff --git a/core/src/main/java/me/athlaeos/valhallammo/utility/ItemUtils.java b/core/src/main/java/me/athlaeos/valhallammo/utility/ItemUtils.java index cbcd597a..07819a06 100644 --- a/core/src/main/java/me/athlaeos/valhallammo/utility/ItemUtils.java +++ b/core/src/main/java/me/athlaeos/valhallammo/utility/ItemUtils.java @@ -161,7 +161,7 @@ public static boolean usedMainHand(ItemBuilder mainHand, ItemBuilder offHand){ public static void startProjectileRunnableCache(){ // cleans up the stored projectile cache every 10 seconds, removing items if they've been in there for 10 seconds or longer - ValhallaMMO.getInstance().getServer().getScheduler().runTaskTimer(ValhallaMMO.getInstance(), () -> { + Scheduling.runTaskTimer(ValhallaMMO.getInstance(), () -> { for (UUID uuid : new HashMap<>(storedProjectileCache).keySet()){ if (storedProjectileCachedAt.get(uuid) + 10000 > System.currentTimeMillis()) { storedProjectileCachedAt.remove(uuid); @@ -822,10 +822,10 @@ public static void calculateDragEvent(InventoryDragEvent e, int maxAmount, Integ ItemStack oldCursor = e.getOldCursor().clone(); oldCursor.setAmount(newAmount); - ValhallaMMO.getInstance().getServer().getScheduler().runTaskLater(ValhallaMMO.getInstance(), () -> { + Scheduling.runEntityTask(ValhallaMMO.getInstance(), e.getWhoClicked(), 1L, () -> { if (oldCursor.getAmount() > 0) e.getWhoClicked().setItemOnCursor(oldCursor); else e.getWhoClicked().setItemOnCursor(null); - }, 1L); + }); } public static int timesContained(List inventory, Map ingredients, IngredientChoice matcher){ diff --git a/core/src/main/java/me/athlaeos/valhallammo/utility/Scheduling.java b/core/src/main/java/me/athlaeos/valhallammo/utility/Scheduling.java new file mode 100644 index 00000000..5b65c247 --- /dev/null +++ b/core/src/main/java/me/athlaeos/valhallammo/utility/Scheduling.java @@ -0,0 +1,118 @@ +package me.athlaeos.valhallammo.utility; + +import me.athlaeos.valhallammo.ValhallaMMO; +import me.athlaeos.valhallammo.platform.scheduler.TaskHolder; +import me.athlaeos.valhallammo.platform.scheduler.ValhallaScheduler; +import org.bukkit.Location; +import org.bukkit.entity.Entity; +import org.bukkit.plugin.Plugin; +import org.jetbrains.annotations.ApiStatus; + +@ApiStatus.Internal +public class Scheduling { + + private static ValhallaScheduler getScheduler() { + return ValhallaMMO.getPlatform().getScheduler(); + } + + /** + * Run a task on the main thread + */ + public static TaskHolder runTask(Plugin plugin, Runnable toRun) { + return getScheduler().runTask(plugin, toRun); + } + + /** + * Run a task after [delay] of ticks + */ + public static TaskHolder runTaskLater(Plugin plugin, long delay, Runnable toRun) { + return getScheduler().runTaskLater(plugin, delay, toRun); + } + + /** + * Run a task after [delay] of ticks + */ + public static TaskHolder runTaskLater(Plugin plugin, Runnable toRun, long delay) { + return getScheduler().runTaskLater(plugin, delay, toRun); + } + + /** + * Repeat a task every [repeat] ticks after [delay] ticks + */ + public static TaskHolder runTaskTimer(Plugin plugin, long delay, long repeat, Runnable toRun) { + return getScheduler().runTaskTimer(plugin, delay, repeat, toRun); + } + + /** + * Repeat a task every [repeat] ticks after [delay] ticks + */ + public static TaskHolder runTaskTimer(Plugin plugin, Runnable toRun, long delay, long repeat) { + return getScheduler().runTaskTimer(plugin, delay, repeat, toRun); + } + + /** + * Run a task on the async thread + */ + public static TaskHolder runTaskAsync(Plugin plugin, Runnable toRun) { + return getScheduler().runTaskAsync(plugin, toRun); + } + + /** + * Run a task after [delay] ticks on the async thread + */ + public static TaskHolder runTaskLaterAsync(Plugin plugin, long delay, Runnable toRun) { + return getScheduler().runTaskLaterAsync(plugin, delay, toRun); + } + + /** + * Repeat a task every [repeat] ticks after [delay] ticks on the async thread + */ + public static TaskHolder runTaskTimerAsync(Plugin plugin, long delay, long repeat, Runnable toRun) { + return getScheduler().runTaskTimerAsync(plugin, delay, repeat, toRun); + } + + public static TaskHolder runEntityTask(Plugin plugin, Entity entity, long delay, Runnable toRun) { + return getScheduler().runEntityTask(plugin, entity, delay, toRun); + } + + public static TaskHolder runEntityTask(Plugin plugin, Entity entity, long delay, long period, Runnable toRun) { + return getScheduler().runEntityTask(plugin, entity, delay, period, toRun); + } + + public static void runEntityTask(Plugin plugin, Entity entity, Runnable toRun) { + getScheduler().runEntityTask(plugin, entity, toRun); + } + + public static TaskHolder runLocationTask(Plugin plugin, Location location, long delay, Runnable toRun) { + return getScheduler().runLocationTask(plugin, location, delay, toRun); + } + + public static void runLocationTask(Plugin plugin, Location location, Runnable toRun) { + getScheduler().runLocationTask(plugin, location, toRun); + } + + public static TaskHolder runLocationTask(Plugin plugin, Location location, long delay, long period, Runnable toRun) { + return getScheduler().runLocationTask(plugin, location, delay, period, toRun); + } + + public static TaskHolder runEntityTaskAsync(Plugin plugin, Entity entity, long delay, Runnable toRun) { + return getScheduler().runEntityTaskAsync(plugin, entity, delay, toRun); + } + + public static void runEntityTaskAsync(Plugin plugin, Entity entity, Runnable toRun) { + getScheduler().runEntityTaskAsync(plugin, entity, toRun); + } + + public static TaskHolder runEntityTaskAsync(Plugin plugin, Entity entity, long delay, long period, Runnable toRun) { + return getScheduler().runEntityTaskAsync(plugin, entity, delay, period, toRun); + } + + public static TaskHolder runLocationTaskAsync(Plugin plugin, Location location, long delay, Runnable toRun) { + return getScheduler().runLocationTaskAsync(plugin, location, delay, toRun); + } + + public static void runLocationTaskAsync(Plugin plugin, Location location, Runnable toRun) { + getScheduler().runLocationTaskAsync(plugin, location, toRun); + } + +} diff --git a/core/src/main/java/me/athlaeos/valhallammo/utility/SideBarUtils.java b/core/src/main/java/me/athlaeos/valhallammo/utility/SideBarUtils.java index e0d16a52..091a8c71 100644 --- a/core/src/main/java/me/athlaeos/valhallammo/utility/SideBarUtils.java +++ b/core/src/main/java/me/athlaeos/valhallammo/utility/SideBarUtils.java @@ -19,6 +19,7 @@ public class SideBarUtils { * @param contents the contents the scoreboard should display */ public static void showSideBarToPlayer(final Player player, String key, String title, List contents, boolean force){ + if (!ValhallaMMO.getPlatform().supportsScoreboard()) return; Sidebar sideBar = activeSidebars.get(player.getUniqueId()); if (sideBar == null) sideBar = new Sidebar(player, key, title, contents); else sideBar.updateContents(contents); @@ -28,6 +29,7 @@ public static void showSideBarToPlayer(final Player player, String key, String t } public static void hideSideBarFromPlayer(final Player player, String key){ + if (!ValhallaMMO.getPlatform().supportsScoreboard()) return; if (player.getScoreboard().getObjective(key) != null && manager != null) { player.setScoreboard(manager.getMainScoreboard()); activeSidebars.remove(player.getUniqueId()); diff --git a/core/src/main/java/me/athlaeos/valhallammo/utility/Timer.java b/core/src/main/java/me/athlaeos/valhallammo/utility/Timer.java index 5506250a..121fbe53 100644 --- a/core/src/main/java/me/athlaeos/valhallammo/utility/Timer.java +++ b/core/src/main/java/me/athlaeos/valhallammo/utility/Timer.java @@ -8,7 +8,6 @@ import net.md_5.bungee.api.chat.TextComponent; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; -import org.bukkit.scheduler.BukkitRunnable; import java.util.HashMap; import java.util.Map; @@ -45,14 +44,14 @@ public static void setCooldownIgnoreIfPermission(Entity entity, int timems, Stri } } - private static final Map cooldownStatusRunnables = new HashMap<>(); + private static final Map cooldownStatusRunnables = new HashMap<>(); public static void sendCooldownStatus(Player player, String cooldownKey, String type){ int ticks = ConfigManager.getConfig("config.yml").get().getInt("cooldown_status_duration", 0); if (ticks > 0){ - BukkitRunnable existingRunnable = cooldownStatusRunnables.get(player.getUniqueId()); + ValhallaRunnable existingRunnable = cooldownStatusRunnables.get(player.getUniqueId()); if (existingRunnable != null) existingRunnable.cancel(); - existingRunnable = new BukkitRunnable() { + existingRunnable = new ValhallaRunnable() { int ticksRemaining = ticks; @Override public void run() { diff --git a/core/src/main/java/me/athlaeos/valhallammo/utility/ValhallaRunnable.java b/core/src/main/java/me/athlaeos/valhallammo/utility/ValhallaRunnable.java new file mode 100644 index 00000000..61eefab7 --- /dev/null +++ b/core/src/main/java/me/athlaeos/valhallammo/utility/ValhallaRunnable.java @@ -0,0 +1,93 @@ +package me.athlaeos.valhallammo.utility; + +import me.athlaeos.valhallammo.ValhallaMMO; +import me.athlaeos.valhallammo.platform.scheduler.TaskHolder; +import me.athlaeos.valhallammo.platform.scheduler.ValhallaScheduler; +import org.bukkit.Location; +import org.bukkit.entity.Entity; +import org.bukkit.plugin.Plugin; + +public abstract class ValhallaRunnable implements Runnable { + private TaskHolder task = null; + + public void cancel() { + if (task == null) return; + task.cancel(); + } + + public boolean isCanceled() { + if (task == null) return true; + return task.isCancelled(); + } + + private static ValhallaScheduler getScheduler() { + return ValhallaMMO.getPlatform().getScheduler(); + } + + /** + * Run a task on the main thread + */ + public void runTask(Plugin plugin) { + this.cancel(); + this.task = Scheduling.runTask(plugin, this); + } + + /** + * Run a task after [delay] of ticks + */ + public void runTaskLater(Plugin plugin, long delay) { + this.cancel(); + this.task = Scheduling.runTaskLater(plugin, delay, this); + } + + /** + * Repeat a task every [repeat] ticks after [delay] ticks + */ + public void runTaskTimer(Plugin plugin, long delay, long repeat) { + this.cancel(); + this.task = Scheduling.runTaskTimer(plugin, delay, repeat, this); + } + + /** + * Repeat a task every [repeat] ticks after [delay] ticks + */ + public void runLocation(Plugin plugin, Location location, long delay, long repeat) { + this.cancel(); + this.task = Scheduling.runLocationTask(plugin, location, delay, repeat, this); + } + + public void runEntity(Plugin plugin, Entity entity, long delay) { + this.cancel(); + this.task = Scheduling.runEntityTask(plugin, entity, delay, this); + } + + public void runEntity(Plugin plugin, Entity entity, long delay, long repeat) { + this.cancel(); + this.task = Scheduling.runEntityTask(plugin, entity, delay, repeat, this); + } + + /** + * Run a task on the async thread + */ + public void runTaskAsync(Plugin plugin) { + this.cancel(); + this.task = Scheduling.runTaskAsync(plugin, this); + } + + /** + * Run a task after [delay] ticks on the async thread + */ + public void runTaskLaterAsync(Plugin plugin, long delay) { + this.cancel(); + this.task = Scheduling.runTaskLaterAsync(plugin, delay, this); + } + + /** + * Repeat a task every [repeat] ticks after [delay] ticks on the async thread + */ + public void runTaskTimerAsync(Plugin plugin, long delay, long repeat) { + this.cancel(); + this.task = Scheduling.runTaskTimerAsync(plugin, delay, repeat, this); + } + +} diff --git a/core/src/main/java/me/athlaeos/valhallammo/version/AlphaToBetaConversionHandler.java b/core/src/main/java/me/athlaeos/valhallammo/version/AlphaToBetaConversionHandler.java index 6b7738f2..d4975a9d 100644 --- a/core/src/main/java/me/athlaeos/valhallammo/version/AlphaToBetaConversionHandler.java +++ b/core/src/main/java/me/athlaeos/valhallammo/version/AlphaToBetaConversionHandler.java @@ -6,6 +6,7 @@ import me.athlaeos.valhallammo.skills.skills.Skill; import me.athlaeos.valhallammo.skills.skills.SkillRegistry; import me.athlaeos.valhallammo.skills.skills.implementations.*; +import me.athlaeos.valhallammo.utility.Scheduling; import me.athlaeos.valhallammo.version.conversion_dto.AlphaDatabaseAdapter; import me.athlaeos.valhallammo.version.conversion_dto.AlphaPDCAdapter; import me.athlaeos.valhallammo.version.conversion_dto.DatabaseConnection; @@ -74,7 +75,7 @@ public static boolean shouldConvert(){ @EventHandler(priority = EventPriority.LOWEST) public void expConversion(PlayerJoinEvent e){ if (expConversion <= 0 || e.getPlayer().getPersistentDataContainer().has(CONVERTED_FROM_ALPHA_KEY, PersistentDataType.BYTE)) return; - ValhallaMMO.getInstance().getServer().getScheduler().runTaskLater(ValhallaMMO.getInstance(), () -> { + Scheduling.runEntityTask(ValhallaMMO.getInstance(), e.getPlayer(), 20L, () -> { if (!e.getPlayer().isOnline()) return; ValhallaMMO.logInfo("Player " + e.getPlayer().getName() + " had alpha data, converting to beta"); for (String profileType : alphaKeyMappings.keySet()){ @@ -96,7 +97,7 @@ public void expConversion(PlayerJoinEvent e){ e.getPlayer().getPersistentDataContainer().remove(key); } e.getPlayer().getPersistentDataContainer().set(CONVERTED_FROM_ALPHA_KEY, PersistentDataType.BYTE, (byte) 1); - }, 20L); + }); } } diff --git a/core/src/main/java/me/athlaeos/valhallammo/version/BrewingPreventionListener.java b/core/src/main/java/me/athlaeos/valhallammo/version/BrewingPreventionListener.java index ddccc3c2..10ce312a 100644 --- a/core/src/main/java/me/athlaeos/valhallammo/version/BrewingPreventionListener.java +++ b/core/src/main/java/me/athlaeos/valhallammo/version/BrewingPreventionListener.java @@ -3,6 +3,7 @@ import me.athlaeos.valhallammo.ValhallaMMO; import me.athlaeos.valhallammo.crafting.CustomRecipeRegistry; import me.athlaeos.valhallammo.hooks.WorldGuardHook; +import me.athlaeos.valhallammo.utility.Scheduling; import org.bukkit.Material; import org.bukkit.block.BrewingStand; import org.bukkit.event.EventHandler; @@ -17,10 +18,10 @@ public void onStartBrewing(BrewingStartEvent e){ ValhallaMMO.isWorldBlacklisted(e.getBlock().getWorld().getName()) || CustomRecipeRegistry.getBrewingRecipes().isEmpty()) return; e.setTotalBrewTime(Integer.MAX_VALUE); - ValhallaMMO.getInstance().getServer().getScheduler().runTaskLater(ValhallaMMO.getInstance(), () -> { + Scheduling.runLocationTask(ValhallaMMO.getInstance(), e.getBlock().getLocation(), 1L, () -> { if (e.getBlock().getType() != Material.BREWING_STAND || !(e.getBlock().getState() instanceof BrewingStand stand)) return; stand.setFuelLevel(stand.getFuelLevel() + 1); stand.update(); - }, 1L); + }); } } diff --git a/core/src/main/java/me/athlaeos/valhallammo/version/DiggingArchaeologyExtension.java b/core/src/main/java/me/athlaeos/valhallammo/version/DiggingArchaeologyExtension.java index 6d75fa46..af5ba482 100644 --- a/core/src/main/java/me/athlaeos/valhallammo/version/DiggingArchaeologyExtension.java +++ b/core/src/main/java/me/athlaeos/valhallammo/version/DiggingArchaeologyExtension.java @@ -10,10 +10,7 @@ import me.athlaeos.valhallammo.playerstats.profiles.ProfileCache; import me.athlaeos.valhallammo.playerstats.profiles.implementations.DiggingProfile; import me.athlaeos.valhallammo.skills.skills.implementations.DiggingSkill; -import me.athlaeos.valhallammo.utility.BlockStore; -import me.athlaeos.valhallammo.utility.ItemUtils; -import me.athlaeos.valhallammo.utility.StringUtils; -import me.athlaeos.valhallammo.utility.Utils; +import me.athlaeos.valhallammo.utility.*; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; @@ -199,7 +196,7 @@ public void onBrush(BlockDropItemEvent e){ LootTable previousTable = ArchaeologyListener.getSuspiciousLootTables().get(e.getBlock()); if (previousTable == null) return; - ValhallaMMO.getInstance().getServer().getScheduler().runTaskLater(ValhallaMMO.getInstance(), () -> { + Scheduling.runLocationTask(ValhallaMMO.getInstance(), b.getLocation(), 2L, () -> { e.getBlock().setType(previousMaterial); b.setLootTable(previousTable); b.update(); @@ -209,6 +206,6 @@ public void onBrush(BlockDropItemEvent e){ brushable.setDusted(0); e.getBlock().setBlockData(brushable); } - }, 2L); + }); } } diff --git a/core/src/main/java/me/athlaeos/valhallammo/version/conversion_dto/DatabaseConnection.java b/core/src/main/java/me/athlaeos/valhallammo/version/conversion_dto/DatabaseConnection.java index 80959435..f0e7771a 100644 --- a/core/src/main/java/me/athlaeos/valhallammo/version/conversion_dto/DatabaseConnection.java +++ b/core/src/main/java/me/athlaeos/valhallammo/version/conversion_dto/DatabaseConnection.java @@ -2,8 +2,8 @@ import me.athlaeos.valhallammo.ValhallaMMO; import me.athlaeos.valhallammo.configuration.ConfigManager; +import me.athlaeos.valhallammo.utility.ValhallaRunnable; import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.scheduler.BukkitRunnable; import java.sql.Connection; import java.sql.DriverManager; @@ -59,7 +59,7 @@ private Connection initializeConnection() { return null; } if (conn != null){ - new BukkitRunnable(){ + new ValhallaRunnable(){ @Override public void run() { try { @@ -69,7 +69,7 @@ public void run() { cancel(); } } - }.runTaskTimerAsynchronously(ValhallaMMO.getInstance(), ping_delay, ping_delay); + }.runTaskTimerAsync(ValhallaMMO.getInstance(), ping_delay, ping_delay); } return conn; } diff --git a/core/src/main/resources/plugin.yml b/core/src/main/resources/plugin.yml index ab9535ee..806adace 100644 --- a/core/src/main/resources/plugin.yml +++ b/core/src/main/resources/plugin.yml @@ -4,6 +4,7 @@ main: me.athlaeos.valhallammo.ValhallaMMO author: Athlaeos api-version: "1.16" load: POSTWORLD +folia-supported: true softdepend: - Vault - WorldEdit diff --git a/dependency-reduced-pom.xml b/dependency-reduced-pom.xml deleted file mode 100644 index a31facbd..00000000 --- a/dependency-reduced-pom.xml +++ /dev/null @@ -1,145 +0,0 @@ - - - 4.0.0 - me.athlaeos - valhallammo-parent - pom - ValhallaMMO - ${revision} - A very big skills/leveling plugin with plenty of useful tools to make a unique experience - - clean package - - - . - true - src/main/resources - - - ValhallaMMO_${revision} - - - maven-compiler-plugin - 3.10.1 - - ${javaVersion} - ${javaVersion} - - - - maven-jar-plugin - 3.3.0 - - ${outputDirectory} - - - - maven-shade-plugin - 3.5.1 - - - package - - shade - - - - - true - - - com.jeff_media.morepersistentdatatypes - ${shadedPackage}.com.jeff_media.morepersistentdatatypes - - - com.jeff_media.customblockdata - ${shadedPackage}.com.jeff_media.customblockdata - - - - - - - - - - exportToServer - - ${testServerPath} - - - - - valhallammo - dist - v1_19_R1 - - - - spigot-repo - https://hub.spigotmc.org/nexus/content/repositories/snapshots/ - - - jeff-media-public - https://hub.jeff-media.com/nexus/repository/jeff-media-public/ - - - jitpack.io - https://jitpack.io - - - enginehub - https://maven.enginehub.org/repo/ - - - placeholderapi - https://repo.extendedclip.com/content/repositories/placeholderapi/ - - - - - org.projectlombok - lombok - 1.18.24 - provided - - - com.github.MilkBowl - VaultAPI - 1.7 - provided - - - com.sk89q.worldedit - worldedit-bukkit - 7.3.0-SNAPSHOT - provided - - - com.sk89q.worldguard - worldguard-bukkit - 7.1.0-SNAPSHOT - provided - - - me.clip - placeholderapi - 2.11.2 - provided - - - commons-io - commons-io - 2.11.0 - provided - - - - C:\Users\Job\Desktop\paper 1.19\plugins - 17 - BETA-1.0 - UTF-8 - target - me.athlaeos.valhallammo.shaded - - diff --git a/dist/pom.xml b/dist/pom.xml deleted file mode 100644 index 5dddf2e9..00000000 --- a/dist/pom.xml +++ /dev/null @@ -1,136 +0,0 @@ - - - 4.0.0 - valhallammo-dist - - - me.athlaeos - valhallammo-parent - ${revision} - - - - - me.athlaeos - valhallammo-core - ${project.version} - - - me.athlaeos - valhallammo-v1_21_R4 - ${project.version} - - - me.athlaeos - valhallammo-v1_21_R3 - ${project.version} - - - me.athlaeos - valhallammo-v1_21_R2 - ${project.version} - - - me.athlaeos - valhallammo-v1_21_R1 - ${project.version} - - - me.athlaeos - valhallammo-v1_20_R4 - ${project.version} - - - me.athlaeos - valhallammo-v1_20_R3 - ${project.version} - - - me.athlaeos - valhallammo-v1_20_R2 - ${project.version} - - - me.athlaeos - valhallammo-v1_20_R1 - ${project.version} - - - me.athlaeos - valhallammo-v1_19_R3 - ${project.version} - - - me.athlaeos - valhallammo-v1_19_R2 - ${project.version} - - - me.athlaeos - valhallammo-v1_19_R1 - ${project.version} - - - - - clean package - ../target - ValhallaMMO_${revision} - - - org.apache.maven.plugins - maven-jar-plugin - 3.3.0 - - ${outputDirectory} - dummy - - - - org.apache.maven.plugins - maven-shade-plugin - 3.5.1 - - false - - - me.athlaeos:valhallammo-core - ** - - - false - - - - com.jeff_media.morepersistentdatatypes - ${shadedPackage}.com.jeff_media.morepersistentdatatypes - - - - - com.jeff_media.customblockdata - ${shadedPackage}.com.jeff_media.customblockdata - - - - - org.bstats - me.athlaeos.valhallammo.bstats - - - - - - - - shade - - package - - - - - - diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 00000000..21a56ed0 --- /dev/null +++ b/gradle.properties @@ -0,0 +1,9 @@ +# Project Meta +group=me.athlaeos +version=1.4.1 +description=A very big skills/leveling plugin with plenty of useful tools to make a unique experience + +# Gradle configuration +org.gradle.parallel=true +org.gradle.caching=true +org.gradle.configuration-cache=true diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 00000000..cea7a793 --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,7 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.12-bin.zip +networkTimeout=10000 +validateDistributionUrl=true +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew new file mode 100644 index 00000000..f5feea6d --- /dev/null +++ b/gradlew @@ -0,0 +1,252 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# SPDX-License-Identifier: Apache-2.0 +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s +' "$PWD" ) || exit + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 00000000..9d21a218 --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,94 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem +@rem SPDX-License-Identifier: Apache-2.0 +@rem + +@if "%DEBUG%"=="" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if %ERRORLEVEL% equ 0 goto execute + +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if %ERRORLEVEL% equ 0 goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/platform_api/build.gradle.kts b/platform_api/build.gradle.kts new file mode 100644 index 00000000..989befc3 --- /dev/null +++ b/platform_api/build.gradle.kts @@ -0,0 +1,23 @@ +plugins { + `maven-publish` +} + +dependencies { + compileOnly("org.spigotmc", "spigot-api", "1.20.1-R0.1-SNAPSHOT") + compileOnly("org.jetbrains:annotations:24.0.0") +} + +publishing { + publications { + create("maven") { + groupId = "${rootProject.group}" + artifactId = "valhallammo-platform-api" + version = "${rootProject.version}" + + pom { + name.set("ValhallaMMO Platform API") + description.set("A API used to support multiple platform") + } + } + } +} diff --git a/platform_api/src/main/java/me/athlaeos/valhallammo/platform/ValhallaPlatform.java b/platform_api/src/main/java/me/athlaeos/valhallammo/platform/ValhallaPlatform.java new file mode 100644 index 00000000..17524dda --- /dev/null +++ b/platform_api/src/main/java/me/athlaeos/valhallammo/platform/ValhallaPlatform.java @@ -0,0 +1,31 @@ +package me.athlaeos.valhallammo.platform; + +import me.athlaeos.valhallammo.platform.scheduler.ValhallaScheduler; + +/** + * Represents a platform specific functions implementation and feature flags + * @param The task type used by this playform + */ +public interface ValhallaPlatform { + /** + * @return If the default bukkit scoreboard is supported + */ + public boolean supportsScoreboard(); + + /** + * @return If this platform supports paper + */ + public boolean supportsPaper(); + + + /** + * @return If this platform supports folia + */ + public boolean supportsFolia(); + + /** + * @return Gets the platform specific scheduler + */ + public ValhallaScheduler getScheduler(); + +} diff --git a/platform_api/src/main/java/me/athlaeos/valhallammo/platform/bukkit/BukkitPlatform.java b/platform_api/src/main/java/me/athlaeos/valhallammo/platform/bukkit/BukkitPlatform.java new file mode 100644 index 00000000..86d69f69 --- /dev/null +++ b/platform_api/src/main/java/me/athlaeos/valhallammo/platform/bukkit/BukkitPlatform.java @@ -0,0 +1,29 @@ +package me.athlaeos.valhallammo.platform.bukkit; + +import me.athlaeos.valhallammo.platform.ValhallaPlatform; +import me.athlaeos.valhallammo.platform.scheduler.ValhallaScheduler; +import org.bukkit.scheduler.BukkitTask; + +public class BukkitPlatform implements ValhallaPlatform { + private final BukkitValhallaScheduler scheduler = new BukkitValhallaScheduler(); + + @Override + public boolean supportsScoreboard() { + return true; + } + + @Override + public boolean supportsPaper() { + return false; + } + + @Override + public boolean supportsFolia() { + return false; + } + + @Override + public ValhallaScheduler getScheduler() { + return scheduler; + } +} diff --git a/platform_api/src/main/java/me/athlaeos/valhallammo/platform/bukkit/BukkitTaskHolder.java b/platform_api/src/main/java/me/athlaeos/valhallammo/platform/bukkit/BukkitTaskHolder.java new file mode 100644 index 00000000..4d8e69cb --- /dev/null +++ b/platform_api/src/main/java/me/athlaeos/valhallammo/platform/bukkit/BukkitTaskHolder.java @@ -0,0 +1,29 @@ +package me.athlaeos.valhallammo.platform.bukkit; + +import me.athlaeos.valhallammo.platform.scheduler.TaskHolder; +import org.bukkit.scheduler.BukkitTask; +import javax.annotation.Nonnull; + +public class BukkitTaskHolder implements TaskHolder { + + private final BukkitTask parent; + + public BukkitTaskHolder(@Nonnull BukkitTask parent) { + this.parent = parent; + } + + @Override + public BukkitTask getParent() { + return parent; + } + + @Override + public void cancel() { + parent.cancel(); + } + + @Override + public boolean isCancelled() { + return parent.isCancelled(); + } +} diff --git a/platform_api/src/main/java/me/athlaeos/valhallammo/platform/bukkit/BukkitValhallaScheduler.java b/platform_api/src/main/java/me/athlaeos/valhallammo/platform/bukkit/BukkitValhallaScheduler.java new file mode 100644 index 00000000..8f0a6c6c --- /dev/null +++ b/platform_api/src/main/java/me/athlaeos/valhallammo/platform/bukkit/BukkitValhallaScheduler.java @@ -0,0 +1,139 @@ +package me.athlaeos.valhallammo.platform.bukkit; + +import me.athlaeos.valhallammo.platform.scheduler.TaskHolder; +import me.athlaeos.valhallammo.platform.scheduler.ValhallaScheduler; +import org.bukkit.Location; +import org.bukkit.entity.Entity; +import org.bukkit.plugin.Plugin; +import org.bukkit.scheduler.BukkitRunnable; +import org.bukkit.scheduler.BukkitTask; + +import javax.annotation.Nonnull; + +public class BukkitValhallaScheduler implements ValhallaScheduler { + + private BukkitTaskHolder of(@Nonnull BukkitTask task) { + return new BukkitTaskHolder(task); + } + + @Override + public TaskHolder runTask(Plugin plugin, Runnable toRun) { + BukkitTask task = new BukkitRunnable() { + @Override + public void run() { + toRun.run(); + } + }.runTask(plugin); + return of(task); + } + + @Override + public TaskHolder runTaskLater(Plugin plugin, long delay, Runnable toRun) { + BukkitTask task = new BukkitRunnable() { + @Override + public void run() { + toRun.run(); + } + }.runTaskLater(plugin, delay); + return of(task); + } + + @Override + public TaskHolder runTaskTimer(Plugin plugin, long delay, long repeat, Runnable toRun) { + BukkitTask task = new BukkitRunnable() { + @Override + public void run() { + toRun.run(); + } + }.runTaskTimer(plugin, delay, repeat); + return of(task); + } + + @Override + public TaskHolder runTaskAsync(Plugin plugin, Runnable toRun) { + BukkitTask task = new BukkitRunnable() { + @Override + public void run() { + toRun.run(); + } + }.runTaskAsynchronously(plugin); + return of(task); + } + + @Override + public TaskHolder runTaskLaterAsync(Plugin plugin, long delay, Runnable toRun) { + BukkitTask task = new BukkitRunnable() { + @Override + public void run() { + toRun.run(); + } + }.runTaskLaterAsynchronously(plugin, delay); + return of(task); + } + + @Override + public TaskHolder runTaskTimerAsync(Plugin plugin, long delay, long repeat, Runnable toRun) { + BukkitTask task = new BukkitRunnable() { + @Override + public void run() { + toRun.run(); + } + }.runTaskTimerAsynchronously(plugin, delay, repeat); + return of(task); + } + + @Override + public TaskHolder runEntityTask(Plugin plugin, Entity entity, long delay, Runnable toRun) { + return this.runTaskLater(plugin, delay, toRun); + } + + @Override + public TaskHolder runEntityTask(Plugin plugin, Entity entity, long delay, long period, Runnable toRun) { + return this.runTaskTimer(plugin, delay, period, toRun); + } + + @Override + public void runEntityTask(Plugin plugin, Entity entity, Runnable toRun) { + this.runTask(plugin, toRun); + } + + @Override + public TaskHolder runLocationTask(Plugin plugin, Location location, long delay, Runnable toRun) { + return this.runTaskLater(plugin, delay, toRun); + } + + @Override + public void runLocationTask(Plugin plugin, Location location, Runnable toRun) { + this.runTask(plugin, toRun); + } + + @Override + public TaskHolder runLocationTask(Plugin plugin, Location location, long delay, long period, Runnable toRun) { + return this.runTaskTimer(plugin, delay, period, toRun); + } + + @Override + public TaskHolder runEntityTaskAsync(Plugin plugin, Entity entity, long delay, Runnable toRun) { + return this.runTaskLaterAsync(plugin, delay, toRun); + } + + @Override + public TaskHolder runEntityTaskAsync(Plugin plugin, Entity entity, long delay, long period, Runnable toRun) { + return this.runTaskTimerAsync(plugin, delay, period, toRun); + } + + @Override + public void runEntityTaskAsync(Plugin plugin, Entity entity, Runnable toRun) { + this.runTaskAsync(plugin, toRun); + } + + @Override + public TaskHolder runLocationTaskAsync(Plugin plugin, Location location, long delay, Runnable toRun) { + return this.runTaskLaterAsync(plugin, delay, toRun); + } + + @Override + public void runLocationTaskAsync(Plugin plugin, Location location, Runnable toRun) { + this.runTaskAsync(plugin, toRun); + } +} diff --git a/platform_api/src/main/java/me/athlaeos/valhallammo/platform/paper/PaperPlatform.java b/platform_api/src/main/java/me/athlaeos/valhallammo/platform/paper/PaperPlatform.java new file mode 100644 index 00000000..0acd7dbf --- /dev/null +++ b/platform_api/src/main/java/me/athlaeos/valhallammo/platform/paper/PaperPlatform.java @@ -0,0 +1,39 @@ +package me.athlaeos.valhallammo.platform.paper; + +import me.athlaeos.valhallammo.platform.ValhallaPlatform; +import me.athlaeos.valhallammo.platform.bukkit.BukkitValhallaScheduler; +import me.athlaeos.valhallammo.platform.scheduler.ValhallaScheduler; +import org.bukkit.scheduler.BukkitTask; + +public class PaperPlatform implements ValhallaPlatform { + private final BukkitValhallaScheduler scheduler = new BukkitValhallaScheduler(); + + public static boolean usingPaper() { + try { + Class.forName("com.destroystokyo.paper.loottable.LootableInventory"); + return true; + } catch (Exception exception) { + return false; + } + } + + @Override + public boolean supportsScoreboard() { + return true; + } + + @Override + public boolean supportsPaper() { + return true; + } + + @Override + public boolean supportsFolia() { + return false; + } + + @Override + public ValhallaScheduler getScheduler() { + return scheduler; + } +} diff --git a/platform_api/src/main/java/me/athlaeos/valhallammo/platform/scheduler/AtomicTask.java b/platform_api/src/main/java/me/athlaeos/valhallammo/platform/scheduler/AtomicTask.java new file mode 100644 index 00000000..fc6e6321 --- /dev/null +++ b/platform_api/src/main/java/me/athlaeos/valhallammo/platform/scheduler/AtomicTask.java @@ -0,0 +1,27 @@ +package me.athlaeos.valhallammo.platform.scheduler; + +public class AtomicTask implements TaskHolder> { + private TaskHolder parent; + + public void setParent(TaskHolder task) { + if (task == null) return; + parent = (TaskHolder) task; + } + + @Override + public TaskHolder getParent() { + return parent; + } + + @Override + public void cancel() { + if (parent == null) return; + parent.cancel(); + } + + @Override + public boolean isCancelled() { + if (parent == null) return true; + return parent.isCancelled(); + } +} diff --git a/platform_api/src/main/java/me/athlaeos/valhallammo/platform/scheduler/TaskHolder.java b/platform_api/src/main/java/me/athlaeos/valhallammo/platform/scheduler/TaskHolder.java new file mode 100644 index 00000000..3e8f95c2 --- /dev/null +++ b/platform_api/src/main/java/me/athlaeos/valhallammo/platform/scheduler/TaskHolder.java @@ -0,0 +1,23 @@ +package me.athlaeos.valhallammo.platform.scheduler; + +/** + * Represents a holder for a platforms task + * @param The scheduled task for this platform + */ +public interface TaskHolder { + /** + * @return the parent task, for this platform + */ + T getParent(); + + /** + * Cancel this task + */ + void cancel(); + + /** + * Check if this task is canceled + * @return If the task has been canceled/ completed + */ + boolean isCancelled(); +} diff --git a/platform_api/src/main/java/me/athlaeos/valhallammo/platform/scheduler/ValhallaScheduler.java b/platform_api/src/main/java/me/athlaeos/valhallammo/platform/scheduler/ValhallaScheduler.java new file mode 100644 index 00000000..3627e6d9 --- /dev/null +++ b/platform_api/src/main/java/me/athlaeos/valhallammo/platform/scheduler/ValhallaScheduler.java @@ -0,0 +1,42 @@ +package me.athlaeos.valhallammo.platform.scheduler; + +import org.bukkit.Location; +import org.bukkit.entity.Entity; +import org.bukkit.plugin.Plugin; + +public interface ValhallaScheduler { + + public TaskHolder runTask(Plugin plugin, Runnable toRun); + + public TaskHolder runTaskLater(Plugin plugin, long delay, Runnable toRun); + + public TaskHolder runTaskTimer(Plugin plugin, long delay, long repeat, Runnable toRun); + + public TaskHolder runTaskAsync(Plugin plugin, Runnable toRun); + + public TaskHolder runTaskLaterAsync(Plugin plugin, long delay, Runnable toRun); + + public TaskHolder runTaskTimerAsync(Plugin plugin, long delay, long repeat, Runnable toRun); + + public TaskHolder runEntityTask(Plugin plugin, Entity entity, long delay, Runnable toRun); + + public TaskHolder runEntityTask(Plugin plugin, Entity entity, long delay, long period, Runnable toRun); + + public void runEntityTask(Plugin plugin, Entity entity, Runnable toRun); + + public TaskHolder runLocationTask(Plugin plugin, Location location, long delay, Runnable toRun); + + public TaskHolder runLocationTask(Plugin plugin, Location location, long delay, long period, Runnable toRun); + + public void runLocationTask(Plugin plugin, Location location, Runnable toRun); + + public TaskHolder runEntityTaskAsync(Plugin plugin, Entity entity, long delay, Runnable toRun); + + public TaskHolder runEntityTaskAsync(Plugin plugin, Entity entity, long delay, long period, Runnable toRun); + + public void runEntityTaskAsync(Plugin plugin, Entity entity, Runnable toRun); + + public TaskHolder runLocationTaskAsync(Plugin plugin, Location location, long delay, Runnable toRun); + + public void runLocationTaskAsync(Plugin plugin, Location location, Runnable toRun); +} diff --git a/platform_folia/build.gradle.kts b/platform_folia/build.gradle.kts new file mode 100644 index 00000000..ef4fb4ce --- /dev/null +++ b/platform_folia/build.gradle.kts @@ -0,0 +1,6 @@ +java.disableAutoTargetJvm() + +dependencies { + compileOnly("dev.folia:folia-api:1.20.1-R0.1-SNAPSHOT") + implementation(project(":platform_api")) +} \ No newline at end of file diff --git a/platform_folia/src/main/java/me/athlaeos/valhallammo/platform/folia/FoliaPlatform.java b/platform_folia/src/main/java/me/athlaeos/valhallammo/platform/folia/FoliaPlatform.java new file mode 100644 index 00000000..6f8e3734 --- /dev/null +++ b/platform_folia/src/main/java/me/athlaeos/valhallammo/platform/folia/FoliaPlatform.java @@ -0,0 +1,38 @@ +package me.athlaeos.valhallammo.platform.folia; + +import io.papermc.paper.threadedregions.scheduler.ScheduledTask; +import me.athlaeos.valhallammo.platform.ValhallaPlatform; +import me.athlaeos.valhallammo.platform.scheduler.ValhallaScheduler; + +public class FoliaPlatform implements ValhallaPlatform { + private FoliaValhallaScheduler scheduler = new FoliaValhallaScheduler(); + + public static boolean usingFolia() { + try { + Class.forName("io.papermc.paper.threadedregions.RegionizedServer"); + return true; + } catch (Exception exception) { + return false; + } + } + + @Override + public boolean supportsScoreboard() { + return false; + } + + @Override + public boolean supportsPaper() { + return true; + } + + @Override + public boolean supportsFolia() { + return true; + } + + @Override + public ValhallaScheduler getScheduler() { + return scheduler; + } +} diff --git a/platform_folia/src/main/java/me/athlaeos/valhallammo/platform/folia/FoliaTaskHolder.java b/platform_folia/src/main/java/me/athlaeos/valhallammo/platform/folia/FoliaTaskHolder.java new file mode 100644 index 00000000..dd3adc40 --- /dev/null +++ b/platform_folia/src/main/java/me/athlaeos/valhallammo/platform/folia/FoliaTaskHolder.java @@ -0,0 +1,29 @@ +package me.athlaeos.valhallammo.platform.folia; + +import io.papermc.paper.threadedregions.scheduler.ScheduledTask; +import me.athlaeos.valhallammo.platform.scheduler.TaskHolder; +import org.checkerframework.checker.nullness.qual.NonNull; + +public class FoliaTaskHolder implements TaskHolder { + + private final ScheduledTask parent; + + public FoliaTaskHolder(@NonNull ScheduledTask parent) { + this.parent = parent; + } + + @Override + public ScheduledTask getParent() { + return parent; + } + + @Override + public void cancel() { + parent.cancel(); + } + + @Override + public boolean isCancelled() { + return parent.isCancelled(); + } +} diff --git a/platform_folia/src/main/java/me/athlaeos/valhallammo/platform/folia/FoliaValhallaScheduler.java b/platform_folia/src/main/java/me/athlaeos/valhallammo/platform/folia/FoliaValhallaScheduler.java new file mode 100644 index 00000000..d3f3a2e0 --- /dev/null +++ b/platform_folia/src/main/java/me/athlaeos/valhallammo/platform/folia/FoliaValhallaScheduler.java @@ -0,0 +1,113 @@ +package me.athlaeos.valhallammo.platform.folia; + +import io.papermc.paper.threadedregions.scheduler.AsyncScheduler; +import io.papermc.paper.threadedregions.scheduler.GlobalRegionScheduler; +import io.papermc.paper.threadedregions.scheduler.RegionScheduler; +import io.papermc.paper.threadedregions.scheduler.ScheduledTask; +import me.athlaeos.valhallammo.platform.scheduler.TaskHolder; +import me.athlaeos.valhallammo.platform.scheduler.ValhallaScheduler; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.entity.Entity; +import org.bukkit.plugin.Plugin; + +import java.util.concurrent.TimeUnit; + +public class FoliaValhallaScheduler implements ValhallaScheduler { + private final AsyncScheduler async = Bukkit.getServer().getAsyncScheduler(); + private final GlobalRegionScheduler global = Bukkit.getServer().getGlobalRegionScheduler(); + private final RegionScheduler region = Bukkit.getServer().getRegionScheduler(); + + private FoliaTaskHolder holder(ScheduledTask task) { + return new FoliaTaskHolder(task); + } + + @Override + public TaskHolder runTask(Plugin plugin, Runnable toRun) { + return holder(global.run(plugin, scheduledTask -> toRun.run())); + } + + @Override + public TaskHolder runTaskLater(Plugin plugin, long delay, Runnable toRun) { + return holder(global.runDelayed(plugin, scheduledTask -> toRun.run(), delay)); + } + + @Override + public TaskHolder runTaskTimer(Plugin plugin, long delay, long repeat, Runnable toRun) { + return holder(global.runAtFixedRate(plugin, scheduledTask -> toRun.run(), minDelay(delay), repeat)); + } + + @Override + public TaskHolder runTaskAsync(Plugin plugin, Runnable toRun) { + return holder(async.runNow(plugin, scheduledTask -> toRun.run())); + } + + @Override + public TaskHolder runTaskLaterAsync(Plugin plugin, long delay, Runnable toRun) { + return holder(async.runDelayed(plugin, scheduledTask -> toRun.run(), delay * 20, TimeUnit.MILLISECONDS)); + } + + @Override + public TaskHolder runTaskTimerAsync(Plugin plugin, long delay, long repeat, Runnable toRun) { + return holder(async.runAtFixedRate(plugin, scheduledTask -> toRun.run(), delay * 20, repeat * 20, TimeUnit.MILLISECONDS)); + } + + @Override + public TaskHolder runEntityTask(Plugin plugin, Entity entity, long delay, Runnable toRun) { + return holder(entity.getScheduler().runDelayed(plugin, scheduledTask -> toRun.run(), null, delay)); + } + + @Override + public TaskHolder runEntityTask(Plugin plugin, Entity entity, long delay, long period, Runnable toRun) { + return holder(entity.getScheduler().runAtFixedRate(plugin, scheduledTask -> toRun.run(), null, delay, period)); + } + + @Override + public void runEntityTask(Plugin plugin, Entity entity, Runnable toRun) { + entity.getScheduler().run(plugin, scheduledTask -> toRun.run(), null); + } + + @Override + public TaskHolder runLocationTask(Plugin plugin, Location location, long delay, Runnable toRun) { + return holder(region.runDelayed(plugin, location, scheduledTask -> toRun.run(), delay)); + } + + @Override + public TaskHolder runLocationTask(Plugin plugin, Location location, long delay, long period, Runnable toRun) { + return holder(region.runAtFixedRate(plugin, location, scheduledTask -> toRun.run(), delay, period)); + } + + @Override + public void runLocationTask(Plugin plugin, Location location, Runnable toRun) { + region.run(plugin, location, scheduledTask -> toRun.run()); + } + + @Override + public TaskHolder runEntityTaskAsync(Plugin plugin, Entity entity, long delay, Runnable toRun) { + return runEntityTask(plugin, entity, delay, toRun); + } + + @Override + public TaskHolder runEntityTaskAsync(Plugin plugin, Entity entity, long delay, long period, Runnable toRun) { + return holder(entity.getScheduler().runAtFixedRate(plugin, scheduledTask -> toRun.run(), null, minDelay(delay), period)); + } + + @Override + public void runEntityTaskAsync(Plugin plugin, Entity entity, Runnable toRun) { + runEntityTask(plugin, entity, toRun); + } + + @Override + public TaskHolder runLocationTaskAsync(Plugin plugin, Location location, long delay, Runnable toRun) { + return runLocationTask(plugin, location, delay, toRun); + } + + @Override + public void runLocationTaskAsync(Plugin plugin, Location location, Runnable toRun) { + runLocationTask(plugin, location, toRun); + } + + private long minDelay(long delay) { + return Math.max(1, delay); + } +} diff --git a/pom.xml b/pom.xml deleted file mode 100644 index 02f8c640..00000000 --- a/pom.xml +++ /dev/null @@ -1,90 +0,0 @@ - - - 4.0.0 - - ValhallaMMO - me.athlaeos - valhallammo-parent - A very big skills/leveling plugin with plenty of useful tools to make a unique experience - ${revision} - pom - - - 1.4.4 - 17 - C:\Users\Athlaeos\Desktop\Minecraft Servers\1.21.4\plugins - me.athlaeos.valhallammo.shaded - - - target - UTF-8 - - - - core - dist - v1_20_R3 - v1_20_R2 - v1_20_R1 - v1_19_R3 - v1_19_R2 - v1_19_R1 - v1_20_R4 - v1_21_R1 - v1_21_R2 - v1_21_R3 - v1_21_R4 - - - - - exportToServer - - ${testServerPath} - - - - - - clean package - ValhallaMMO_${revision} - - - src/main/resources - true - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.10.1 - - ${javaVersion} - ${javaVersion} - - - - - - - - spigot-repo - https://hub.spigotmc.org/nexus/content/repositories/snapshots/ - - - jitpack.io - https://jitpack.io - - - - - - io.netty - netty-transport - 4.1.82.Final - provided - - - diff --git a/settings.gradle.kts b/settings.gradle.kts new file mode 100644 index 00000000..1a3f1c57 --- /dev/null +++ b/settings.gradle.kts @@ -0,0 +1,19 @@ +plugins { + id("org.gradle.toolchains.foojay-resolver-convention") version "0.8.0" +} + +rootProject.name = "ValhallaMMO" + +//Core Project +include("core") + +//paper / folia support +include("platform_api", "platform_folia") + +//NMS - Auto imports any new versions +File("$rootDir").listFiles()?.filter { + //check the file is a directory, it starts with the version notation and contains a build file + it.isDirectory && it.name.startsWith("v1_") && File("${it.path}/build.gradle.kts").exists() +}?.forEach { + include(it.name) +} diff --git a/v1_19_R1/build.gradle.kts b/v1_19_R1/build.gradle.kts new file mode 100644 index 00000000..e3318d3e --- /dev/null +++ b/v1_19_R1/build.gradle.kts @@ -0,0 +1,3 @@ +dependencies { + paperweight.paperDevBundle("1.19-R0.1-SNAPSHOT") +} diff --git a/v1_19_R1/pom.xml b/v1_19_R1/pom.xml deleted file mode 100644 index 416f9dfe..00000000 --- a/v1_19_R1/pom.xml +++ /dev/null @@ -1,82 +0,0 @@ - - - 4.0.0 - valhallammo-v1_19_R1 - - - me.athlaeos - valhallammo-parent - ${revision} - - - - 1.19 - - - - - org.spigotmc - spigot - ${spigotVersion}-R0.1-SNAPSHOT - remapped-mojang - provided - - - me.athlaeos - valhallammo-core - ${project.parent.version} - provided - - - - - - - - net.md-5 - specialsource-maven-plugin - 2.0.3 - - - package - - remap - - remap-obf - - org.spigotmc:minecraft-server:${spigotVersion}-R0.1-SNAPSHOT:txt:maps-mojang - true - org.spigotmc:spigot:${spigotVersion}-R0.1-SNAPSHOT:jar:remapped-mojang - true - remapped-obf - - - - package - - remap - - remap-spigot - - ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar - org.spigotmc:minecraft-server:${spigotVersion}-R0.1-SNAPSHOT:csrg:maps-spigot - org.spigotmc:spigot:${spigotVersion}-R0.1-SNAPSHOT:jar:remapped-obf - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.10.1 - - ${javaVersion} - ${javaVersion} - - - - - diff --git a/v1_19_R2/build.gradle.kts b/v1_19_R2/build.gradle.kts new file mode 100644 index 00000000..223b2186 --- /dev/null +++ b/v1_19_R2/build.gradle.kts @@ -0,0 +1,4 @@ +dependencies { + paperweight.paperDevBundle("1.19.3-R0.1-SNAPSHOT") + implementation(project(":v1_19_R1")) +} diff --git a/v1_19_R2/pom.xml b/v1_19_R2/pom.xml deleted file mode 100644 index b2cef41b..00000000 --- a/v1_19_R2/pom.xml +++ /dev/null @@ -1,88 +0,0 @@ - - - 4.0.0 - valhallammo-v1_19_R2 - - - me.athlaeos - valhallammo-parent - ${revision} - - - - 1.19.3 - - - - - org.spigotmc - spigot - ${spigotVersion}-R0.1-SNAPSHOT - remapped-mojang - provided - - - me.athlaeos - valhallammo-core - ${project.parent.version} - provided - - - me.athlaeos - valhallammo-v1_19_R1 - ${project.parent.version} - compile - - - - - - - - net.md-5 - specialsource-maven-plugin - 2.0.3 - - - package - - remap - - remap-obf - - org.spigotmc:minecraft-server:${spigotVersion}-R0.1-SNAPSHOT:txt:maps-mojang - true - org.spigotmc:spigot:${spigotVersion}-R0.1-SNAPSHOT:jar:remapped-mojang - true - remapped-obf - - - - package - - remap - - remap-spigot - - ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar - org.spigotmc:minecraft-server:${spigotVersion}-R0.1-SNAPSHOT:csrg:maps-spigot - org.spigotmc:spigot:${spigotVersion}-R0.1-SNAPSHOT:jar:remapped-obf - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.10.1 - - ${javaVersion} - ${javaVersion} - - - - - diff --git a/v1_19_R3/build.gradle.kts b/v1_19_R3/build.gradle.kts new file mode 100644 index 00000000..c4e7c61b --- /dev/null +++ b/v1_19_R3/build.gradle.kts @@ -0,0 +1,4 @@ +dependencies { + paperweight.paperDevBundle("1.19.4-R0.1-SNAPSHOT") + implementation(project(":v1_19_R1")) +} diff --git a/v1_19_R3/pom.xml b/v1_19_R3/pom.xml deleted file mode 100644 index 0c19c175..00000000 --- a/v1_19_R3/pom.xml +++ /dev/null @@ -1,88 +0,0 @@ - - - 4.0.0 - valhallammo-v1_19_R3 - - - me.athlaeos - valhallammo-parent - ${revision} - - - - 1.19.4 - - - - - org.spigotmc - spigot - ${spigotVersion}-R0.1-SNAPSHOT - remapped-mojang - provided - - - me.athlaeos - valhallammo-core - ${project.parent.version} - provided - - - me.athlaeos - valhallammo-v1_19_R1 - ${project.parent.version} - compile - - - - - - - - net.md-5 - specialsource-maven-plugin - 2.0.3 - - - package - - remap - - remap-obf - - org.spigotmc:minecraft-server:${spigotVersion}-R0.1-SNAPSHOT:txt:maps-mojang - true - org.spigotmc:spigot:${spigotVersion}-R0.1-SNAPSHOT:jar:remapped-mojang - true - remapped-obf - - - - package - - remap - - remap-spigot - - ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar - org.spigotmc:minecraft-server:${spigotVersion}-R0.1-SNAPSHOT:csrg:maps-spigot - org.spigotmc:spigot:${spigotVersion}-R0.1-SNAPSHOT:jar:remapped-obf - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.10.1 - - ${javaVersion} - ${javaVersion} - - - - - diff --git a/v1_20_R1/build.gradle.kts b/v1_20_R1/build.gradle.kts new file mode 100644 index 00000000..7e1ca84c --- /dev/null +++ b/v1_20_R1/build.gradle.kts @@ -0,0 +1,4 @@ +dependencies { + paperweight.paperDevBundle("1.20.1-R0.1-SNAPSHOT") + implementation(project(":v1_19_R1")) +} diff --git a/v1_20_R1/pom.xml b/v1_20_R1/pom.xml deleted file mode 100644 index bc6b1bd4..00000000 --- a/v1_20_R1/pom.xml +++ /dev/null @@ -1,88 +0,0 @@ - - - 4.0.0 - valhallammo-v1_20_R1 - - - me.athlaeos - valhallammo-parent - ${revision} - - - - 1.20.1 - - - - - org.spigotmc - spigot - ${spigotVersion}-R0.1-SNAPSHOT - remapped-mojang - provided - - - me.athlaeos - valhallammo-core - ${project.parent.version} - provided - - - me.athlaeos - valhallammo-v1_19_R1 - ${project.parent.version} - compile - - - - - - - - net.md-5 - specialsource-maven-plugin - 2.0.3 - - - package - - remap - - remap-obf - - org.spigotmc:minecraft-server:${spigotVersion}-R0.1-SNAPSHOT:txt:maps-mojang - true - org.spigotmc:spigot:${spigotVersion}-R0.1-SNAPSHOT:jar:remapped-mojang - true - remapped-obf - - - - package - - remap - - remap-spigot - - ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar - org.spigotmc:minecraft-server:${spigotVersion}-R0.1-SNAPSHOT:csrg:maps-spigot - org.spigotmc:spigot:${spigotVersion}-R0.1-SNAPSHOT:jar:remapped-obf - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.10.1 - - ${javaVersion} - ${javaVersion} - - - - - diff --git a/v1_20_R1/v1_20_R1.iml b/v1_20_R1/v1_20_R1.iml deleted file mode 100644 index ae1e01a3..00000000 --- a/v1_20_R1/v1_20_R1.iml +++ /dev/null @@ -1,99 +0,0 @@ - - - - - - - MCP - SPIGOT - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/v1_20_R1/v1_20_R2.iml b/v1_20_R1/v1_20_R2.iml deleted file mode 100644 index baa883fd..00000000 --- a/v1_20_R1/v1_20_R2.iml +++ /dev/null @@ -1,97 +0,0 @@ - - - - - - - MCP - SPIGOT - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/v1_20_R2/build.gradle.kts b/v1_20_R2/build.gradle.kts new file mode 100644 index 00000000..05d91c22 --- /dev/null +++ b/v1_20_R2/build.gradle.kts @@ -0,0 +1,4 @@ +dependencies { + paperweight.paperDevBundle("1.20.2-R0.1-SNAPSHOT") + implementation(project(":v1_19_R1")) +} diff --git a/v1_20_R2/pom.xml b/v1_20_R2/pom.xml deleted file mode 100644 index 94be815b..00000000 --- a/v1_20_R2/pom.xml +++ /dev/null @@ -1,88 +0,0 @@ - - - 4.0.0 - valhallammo-v1_20_R2 - - - me.athlaeos - valhallammo-parent - ${revision} - - - - 1.20.2 - - - - - org.spigotmc - spigot - ${spigotVersion}-R0.1-SNAPSHOT - remapped-mojang - provided - - - me.athlaeos - valhallammo-core - ${project.parent.version} - provided - - - me.athlaeos - valhallammo-v1_19_R1 - ${project.parent.version} - compile - - - - - - - - net.md-5 - specialsource-maven-plugin - 2.0.3 - - - package - - remap - - remap-obf - - org.spigotmc:minecraft-server:${spigotVersion}-R0.1-SNAPSHOT:txt:maps-mojang - true - org.spigotmc:spigot:${spigotVersion}-R0.1-SNAPSHOT:jar:remapped-mojang - true - remapped-obf - - - - package - - remap - - remap-spigot - - ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar - org.spigotmc:minecraft-server:${spigotVersion}-R0.1-SNAPSHOT:csrg:maps-spigot - org.spigotmc:spigot:${spigotVersion}-R0.1-SNAPSHOT:jar:remapped-obf - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.10.1 - - ${javaVersion} - ${javaVersion} - - - - - diff --git a/v1_20_R2/v1_20_R2.iml b/v1_20_R2/v1_20_R2.iml deleted file mode 100644 index 1bf597ca..00000000 --- a/v1_20_R2/v1_20_R2.iml +++ /dev/null @@ -1,98 +0,0 @@ - - - - - - - MCP - SPIGOT - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/v1_20_R3/build.gradle.kts b/v1_20_R3/build.gradle.kts new file mode 100644 index 00000000..ef5137e4 --- /dev/null +++ b/v1_20_R3/build.gradle.kts @@ -0,0 +1,10 @@ +import io.papermc.paperweight.userdev.ReobfArtifactConfiguration + +dependencies { + paperweight.paperDevBundle("1.20.4-R0.1-SNAPSHOT") + compileOnly(project(":v1_19_R1")) +} + +tasks.reobfJar { + paperweight.reobfArtifactConfiguration = ReobfArtifactConfiguration.REOBF_PRODUCTION +} diff --git a/v1_20_R3/pom.xml b/v1_20_R3/pom.xml deleted file mode 100644 index 566dc0fd..00000000 --- a/v1_20_R3/pom.xml +++ /dev/null @@ -1,88 +0,0 @@ - - - 4.0.0 - valhallammo-v1_20_R3 - - - me.athlaeos - valhallammo-parent - ${revision} - - - - 1.20.4 - - - - - org.spigotmc - spigot - ${spigotVersion}-R0.1-SNAPSHOT - remapped-mojang - provided - - - me.athlaeos - valhallammo-core - ${project.parent.version} - provided - - - me.athlaeos - valhallammo-v1_19_R1 - ${project.parent.version} - compile - - - - - - - - net.md-5 - specialsource-maven-plugin - 2.0.3 - - - package - - remap - - remap-obf - - org.spigotmc:minecraft-server:${spigotVersion}-R0.1-SNAPSHOT:txt:maps-mojang - true - org.spigotmc:spigot:${spigotVersion}-R0.1-SNAPSHOT:jar:remapped-mojang - true - remapped-obf - - - - package - - remap - - remap-spigot - - ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar - org.spigotmc:minecraft-server:${spigotVersion}-R0.1-SNAPSHOT:csrg:maps-spigot - org.spigotmc:spigot:${spigotVersion}-R0.1-SNAPSHOT:jar:remapped-obf - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.10.1 - - ${javaVersion} - ${javaVersion} - - - - - diff --git a/v1_20_R3/v1_20_R3.iml b/v1_20_R3/v1_20_R3.iml deleted file mode 100644 index 8e636e48..00000000 --- a/v1_20_R3/v1_20_R3.iml +++ /dev/null @@ -1,99 +0,0 @@ - - - - - - - MCP - SPIGOT - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/v1_20_R4/build.gradle.kts b/v1_20_R4/build.gradle.kts new file mode 100644 index 00000000..e0ff64e3 --- /dev/null +++ b/v1_20_R4/build.gradle.kts @@ -0,0 +1,15 @@ +import io.papermc.paperweight.userdev.ReobfArtifactConfiguration + +dependencies { + paperweight.paperDevBundle("1.20.6-R0.1-SNAPSHOT") + implementation(project(":v1_19_R1")) +} + +tasks { + reobfJar { + paperweight.reobfArtifactConfiguration = ReobfArtifactConfiguration.REOBF_PRODUCTION + } + withType().configureEach { + options.release = 21 + } +} diff --git a/v1_20_R4/pom.xml b/v1_20_R4/pom.xml deleted file mode 100644 index ca6726a3..00000000 --- a/v1_20_R4/pom.xml +++ /dev/null @@ -1,88 +0,0 @@ - - - 4.0.0 - valhallammo-v1_20_R4 - - - me.athlaeos - valhallammo-parent - ${revision} - - - - 1.20.6 - - - - - org.spigotmc - spigot - ${spigotVersion}-R0.1-SNAPSHOT - remapped-mojang - provided - - - me.athlaeos - valhallammo-core - ${project.parent.version} - provided - - - me.athlaeos - valhallammo-v1_19_R1 - ${project.parent.version} - compile - - - - - - - - net.md-5 - specialsource-maven-plugin - 2.0.3 - - - package - - remap - - remap-obf - - org.spigotmc:minecraft-server:${spigotVersion}-R0.1-SNAPSHOT:txt:maps-mojang - true - org.spigotmc:spigot:${spigotVersion}-R0.1-SNAPSHOT:jar:remapped-mojang - true - remapped-obf - - - - package - - remap - - remap-spigot - - ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar - org.spigotmc:minecraft-server:${spigotVersion}-R0.1-SNAPSHOT:csrg:maps-spigot - org.spigotmc:spigot:${spigotVersion}-R0.1-SNAPSHOT:jar:remapped-obf - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.10.1 - - ${javaVersion} - ${javaVersion} - - - - - diff --git a/v1_20_R4/src/main/java/me/athlaeos/valhallammo/nms/NMS_v1_20_R4.java b/v1_20_R4/src/main/java/me/athlaeos/valhallammo/nms/NMS_v1_20_R4.java index 67b6e139..1614c321 100644 --- a/v1_20_R4/src/main/java/me/athlaeos/valhallammo/nms/NMS_v1_20_R4.java +++ b/v1_20_R4/src/main/java/me/athlaeos/valhallammo/nms/NMS_v1_20_R4.java @@ -28,12 +28,12 @@ import org.bukkit.*; import org.bukkit.attribute.Attribute; import org.bukkit.attribute.AttributeModifier; -import org.bukkit.craftbukkit.v1_20_R4.CraftWorld; -import org.bukkit.craftbukkit.v1_20_R4.block.data.CraftBlockData; -import org.bukkit.craftbukkit.v1_20_R4.entity.CraftEntity; -import org.bukkit.craftbukkit.v1_20_R4.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_20_R4.generator.structure.CraftStructureType; -import org.bukkit.craftbukkit.v1_20_R4.inventory.CraftItemStack; +import org.bukkit.craftbukkit.CraftWorld; +import org.bukkit.craftbukkit.block.data.CraftBlockData; +import org.bukkit.craftbukkit.entity.CraftEntity; +import org.bukkit.craftbukkit.entity.CraftPlayer; +import org.bukkit.craftbukkit.generator.structure.CraftStructureType; +import org.bukkit.craftbukkit.inventory.CraftItemStack; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.EntityType; import org.bukkit.entity.LivingEntity; diff --git a/v1_20_R4/v1_20_R4.iml b/v1_20_R4/v1_20_R4.iml deleted file mode 100644 index 35b7532a..00000000 --- a/v1_20_R4/v1_20_R4.iml +++ /dev/null @@ -1,102 +0,0 @@ - - - - - - - MCP - SPIGOT - PAPER - ADVENTURE - BUKKIT - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/v1_21_R1/build.gradle.kts b/v1_21_R1/build.gradle.kts new file mode 100644 index 00000000..4ac47c77 --- /dev/null +++ b/v1_21_R1/build.gradle.kts @@ -0,0 +1,15 @@ +import io.papermc.paperweight.userdev.ReobfArtifactConfiguration + +dependencies { + paperweight.paperDevBundle("1.21.1-R0.1-SNAPSHOT") + implementation(project(":v1_20_R4")) +} + +tasks { + reobfJar { + paperweight.reobfArtifactConfiguration = ReobfArtifactConfiguration.REOBF_PRODUCTION + } + withType().configureEach { + options.release = 21 + } +} diff --git a/v1_21_R1/pom.xml b/v1_21_R1/pom.xml deleted file mode 100644 index 28208854..00000000 --- a/v1_21_R1/pom.xml +++ /dev/null @@ -1,88 +0,0 @@ - - - 4.0.0 - valhallammo-v1_21_R1 - - - me.athlaeos - valhallammo-parent - ${revision} - - - - 1.21.1 - - - - - org.spigotmc - spigot - ${spigotVersion}-R0.1-SNAPSHOT - remapped-mojang - provided - - - me.athlaeos - valhallammo-core - ${project.parent.version} - provided - - - me.athlaeos - valhallammo-v1_20_R4 - ${project.parent.version} - compile - - - - - - - - net.md-5 - specialsource-maven-plugin - 2.0.3 - - - package - - remap - - remap-obf - - org.spigotmc:minecraft-server:${spigotVersion}-R0.1-SNAPSHOT:txt:maps-mojang - true - org.spigotmc:spigot:${spigotVersion}-R0.1-SNAPSHOT:jar:remapped-mojang - true - remapped-obf - - - - package - - remap - - remap-spigot - - ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar - org.spigotmc:minecraft-server:${spigotVersion}-R0.1-SNAPSHOT:csrg:maps-spigot - org.spigotmc:spigot:${spigotVersion}-R0.1-SNAPSHOT:jar:remapped-obf - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.10.1 - - ${javaVersion} - ${javaVersion} - - - - - \ No newline at end of file diff --git a/v1_21_R1/src/main/java/me/athlaeos/valhallammo/nms/NMS_v1_21_R1.java b/v1_21_R1/src/main/java/me/athlaeos/valhallammo/nms/NMS_v1_21_R1.java index 49655956..496d4887 100644 --- a/v1_21_R1/src/main/java/me/athlaeos/valhallammo/nms/NMS_v1_21_R1.java +++ b/v1_21_R1/src/main/java/me/athlaeos/valhallammo/nms/NMS_v1_21_R1.java @@ -30,12 +30,12 @@ import org.bukkit.attribute.Attribute; import org.bukkit.attribute.AttributeInstance; import org.bukkit.attribute.AttributeModifier; -import org.bukkit.craftbukkit.v1_21_R1.CraftWorld; -import org.bukkit.craftbukkit.v1_21_R1.block.data.CraftBlockData; -import org.bukkit.craftbukkit.v1_21_R1.entity.CraftEntity; -import org.bukkit.craftbukkit.v1_21_R1.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_21_R1.generator.structure.CraftStructureType; -import org.bukkit.craftbukkit.v1_21_R1.inventory.CraftItemStack; +import org.bukkit.craftbukkit.CraftWorld; +import org.bukkit.craftbukkit.block.data.CraftBlockData; +import org.bukkit.craftbukkit.entity.CraftEntity; +import org.bukkit.craftbukkit.entity.CraftPlayer; +import org.bukkit.craftbukkit.generator.structure.CraftStructureType; +import org.bukkit.craftbukkit.inventory.CraftItemStack; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.EntityType; import org.bukkit.entity.LivingEntity; diff --git a/v1_21_R2/build.gradle.kts b/v1_21_R2/build.gradle.kts new file mode 100644 index 00000000..85b65584 --- /dev/null +++ b/v1_21_R2/build.gradle.kts @@ -0,0 +1,16 @@ +import io.papermc.paperweight.userdev.ReobfArtifactConfiguration + +dependencies { + paperweight.paperDevBundle("1.21.3-R0.1-SNAPSHOT") + implementation(project(":v1_20_R4")) + implementation(project(":v1_21_R1")) +} + +tasks { + reobfJar { + paperweight.reobfArtifactConfiguration = ReobfArtifactConfiguration.REOBF_PRODUCTION + } + withType().configureEach { + options.release = 21 + } +} diff --git a/v1_21_R2/pom.xml b/v1_21_R2/pom.xml deleted file mode 100644 index d5907cd6..00000000 --- a/v1_21_R2/pom.xml +++ /dev/null @@ -1,94 +0,0 @@ - - - 4.0.0 - valhallammo-v1_21_R2 - - - me.athlaeos - valhallammo-parent - ${revision} - - - - 1.21.3 - - - - - org.spigotmc - spigot - ${spigotVersion}-R0.1-SNAPSHOT - remapped-mojang - provided - - - me.athlaeos - valhallammo-core - ${project.parent.version} - provided - - - me.athlaeos - valhallammo-v1_20_R4 - ${project.parent.version} - compile - - - me.athlaeos - valhallammo-v1_21_R1 - ${project.parent.version} - compile - - - - - - - - net.md-5 - specialsource-maven-plugin - 2.0.3 - - - package - - remap - - remap-obf - - org.spigotmc:minecraft-server:${spigotVersion}-R0.1-SNAPSHOT:txt:maps-mojang - true - org.spigotmc:spigot:${spigotVersion}-R0.1-SNAPSHOT:jar:remapped-mojang - true - remapped-obf - - - - package - - remap - - remap-spigot - - ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar - org.spigotmc:minecraft-server:${spigotVersion}-R0.1-SNAPSHOT:csrg:maps-spigot - org.spigotmc:spigot:${spigotVersion}-R0.1-SNAPSHOT:jar:remapped-obf - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.10.1 - - ${javaVersion} - ${javaVersion} - - - - - \ No newline at end of file diff --git a/v1_21_R2/src/main/java/me/athlaeos/valhallammo/nms/NMS_v1_21_R2.java b/v1_21_R2/src/main/java/me/athlaeos/valhallammo/nms/NMS_v1_21_R2.java index 105d04a0..004abfed 100644 --- a/v1_21_R2/src/main/java/me/athlaeos/valhallammo/nms/NMS_v1_21_R2.java +++ b/v1_21_R2/src/main/java/me/athlaeos/valhallammo/nms/NMS_v1_21_R2.java @@ -31,12 +31,12 @@ import org.bukkit.*; import org.bukkit.attribute.Attribute; import org.bukkit.attribute.AttributeModifier; -import org.bukkit.craftbukkit.v1_21_R2.CraftWorld; -import org.bukkit.craftbukkit.v1_21_R2.block.data.CraftBlockData; -import org.bukkit.craftbukkit.v1_21_R2.entity.CraftEntity; -import org.bukkit.craftbukkit.v1_21_R2.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_21_R2.generator.structure.CraftStructureType; -import org.bukkit.craftbukkit.v1_21_R2.inventory.CraftItemStack; +import org.bukkit.craftbukkit.CraftWorld; +import org.bukkit.craftbukkit.block.data.CraftBlockData; +import org.bukkit.craftbukkit.entity.CraftEntity; +import org.bukkit.craftbukkit.entity.CraftPlayer; +import org.bukkit.craftbukkit.generator.structure.CraftStructureType; +import org.bukkit.craftbukkit.inventory.CraftItemStack; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.EntityType; import org.bukkit.entity.LivingEntity; diff --git a/v1_21_R3/build.gradle.kts b/v1_21_R3/build.gradle.kts new file mode 100644 index 00000000..8d679cce --- /dev/null +++ b/v1_21_R3/build.gradle.kts @@ -0,0 +1,17 @@ +import io.papermc.paperweight.userdev.ReobfArtifactConfiguration + +dependencies { + paperweight.paperDevBundle("1.21.4-R0.1-SNAPSHOT") + implementation(project(":v1_20_R4")) + implementation(project(":v1_21_R1")) + implementation(project(":v1_21_R2")) +} + +tasks { + reobfJar { + paperweight.reobfArtifactConfiguration = ReobfArtifactConfiguration.REOBF_PRODUCTION + } + withType().configureEach { + options.release = 21 + } +} diff --git a/v1_21_R3/pom.xml b/v1_21_R3/pom.xml deleted file mode 100644 index 25676a9c..00000000 --- a/v1_21_R3/pom.xml +++ /dev/null @@ -1,100 +0,0 @@ - - - 4.0.0 - valhallammo-v1_21_R3 - - - me.athlaeos - valhallammo-parent - ${revision} - - - - 1.21.4 - - - - - org.spigotmc - spigot - ${spigotVersion}-R0.1-SNAPSHOT - remapped-mojang - provided - - - me.athlaeos - valhallammo-core - ${project.parent.version} - provided - - - me.athlaeos - valhallammo-v1_20_R4 - ${project.parent.version} - compile - - - me.athlaeos - valhallammo-v1_21_R1 - ${project.parent.version} - compile - - - me.athlaeos - valhallammo-v1_21_R2 - ${project.parent.version} - compile - - - - - - - - net.md-5 - specialsource-maven-plugin - 2.0.3 - - - package - - remap - - remap-obf - - org.spigotmc:minecraft-server:${spigotVersion}-R0.1-SNAPSHOT:txt:maps-mojang - true - org.spigotmc:spigot:${spigotVersion}-R0.1-SNAPSHOT:jar:remapped-mojang - true - remapped-obf - - - - package - - remap - - remap-spigot - - ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar - org.spigotmc:minecraft-server:${spigotVersion}-R0.1-SNAPSHOT:csrg:maps-spigot - org.spigotmc:spigot:${spigotVersion}-R0.1-SNAPSHOT:jar:remapped-obf - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.10.1 - - ${javaVersion} - ${javaVersion} - - - - - \ No newline at end of file diff --git a/v1_21_R3/src/main/java/me/athlaeos/valhallammo/nms/NMS_v1_21_R3.java b/v1_21_R3/src/main/java/me/athlaeos/valhallammo/nms/NMS_v1_21_R3.java index 30bb76a0..4bdbd0e6 100644 --- a/v1_21_R3/src/main/java/me/athlaeos/valhallammo/nms/NMS_v1_21_R3.java +++ b/v1_21_R3/src/main/java/me/athlaeos/valhallammo/nms/NMS_v1_21_R3.java @@ -32,12 +32,12 @@ import org.bukkit.*; import org.bukkit.attribute.Attribute; import org.bukkit.attribute.AttributeModifier; -import org.bukkit.craftbukkit.v1_21_R3.CraftWorld; -import org.bukkit.craftbukkit.v1_21_R3.block.data.CraftBlockData; -import org.bukkit.craftbukkit.v1_21_R3.entity.CraftEntity; -import org.bukkit.craftbukkit.v1_21_R3.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_21_R3.generator.structure.CraftStructureType; -import org.bukkit.craftbukkit.v1_21_R3.inventory.CraftItemStack; +import org.bukkit.craftbukkit.CraftWorld; +import org.bukkit.craftbukkit.block.data.CraftBlockData; +import org.bukkit.craftbukkit.entity.CraftEntity; +import org.bukkit.craftbukkit.entity.CraftPlayer; +import org.bukkit.craftbukkit.generator.structure.CraftStructureType; +import org.bukkit.craftbukkit.inventory.CraftItemStack; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.EntityType; import org.bukkit.entity.LivingEntity; diff --git a/v1_21_R4/build.gradle.kts b/v1_21_R4/build.gradle.kts new file mode 100644 index 00000000..b7793c61 --- /dev/null +++ b/v1_21_R4/build.gradle.kts @@ -0,0 +1,17 @@ +import io.papermc.paperweight.userdev.ReobfArtifactConfiguration + +dependencies { + paperweight.paperDevBundle("1.21.5-R0.1-SNAPSHOT") + implementation(project(":v1_20_R4")) + implementation(project(":v1_21_R1")) + implementation(project(":v1_21_R2")) +} + +tasks { + reobfJar { + paperweight.reobfArtifactConfiguration = ReobfArtifactConfiguration.REOBF_PRODUCTION + } + withType().configureEach { + options.release = 21 + } +} diff --git a/v1_21_R4/pom.xml b/v1_21_R4/pom.xml deleted file mode 100644 index 75b6d714..00000000 --- a/v1_21_R4/pom.xml +++ /dev/null @@ -1,100 +0,0 @@ - - - 4.0.0 - valhallammo-v1_21_R4 - - - me.athlaeos - valhallammo-parent - ${revision} - - - - 1.21.5 - - - - - org.spigotmc - spigot - ${spigotVersion}-R0.1-SNAPSHOT - remapped-mojang - provided - - - me.athlaeos - valhallammo-core - ${project.parent.version} - provided - - - me.athlaeos - valhallammo-v1_20_R4 - ${project.parent.version} - compile - - - me.athlaeos - valhallammo-v1_21_R1 - ${project.parent.version} - compile - - - me.athlaeos - valhallammo-v1_21_R2 - ${project.parent.version} - compile - - - - - - - - net.md-5 - specialsource-maven-plugin - 2.0.3 - - - package - - remap - - remap-obf - - org.spigotmc:minecraft-server:${spigotVersion}-R0.1-SNAPSHOT:txt:maps-mojang - true - org.spigotmc:spigot:${spigotVersion}-R0.1-SNAPSHOT:jar:remapped-mojang - true - remapped-obf - - - - package - - remap - - remap-spigot - - ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar - org.spigotmc:minecraft-server:${spigotVersion}-R0.1-SNAPSHOT:csrg:maps-spigot - org.spigotmc:spigot:${spigotVersion}-R0.1-SNAPSHOT:jar:remapped-obf - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.10.1 - - ${javaVersion} - ${javaVersion} - - - - - \ No newline at end of file diff --git a/valhallammo-parent.iml b/valhallammo-parent.iml deleted file mode 100644 index be7aa730..00000000 --- a/valhallammo-parent.iml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - BUKKIT - SPIGOT - - - - - \ No newline at end of file