diff --git a/api/src/main/java/net/momirealms/customcrops/api/CustomCropsPlugin.java b/api/src/main/java/net/momirealms/customcrops/api/CustomCropsPlugin.java index 78cf379..a24ef6e 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/CustomCropsPlugin.java +++ b/api/src/main/java/net/momirealms/customcrops/api/CustomCropsPlugin.java @@ -121,6 +121,8 @@ public abstract class CustomCropsPlugin extends JavaPlugin { public abstract void reload(); + public abstract boolean isHookedPluginEnabled(String hooked, String... versionPrefix); + public abstract boolean doesHookedPluginExist(String plugin); public abstract String getServerVersion(); diff --git a/api/src/main/java/net/momirealms/customcrops/api/mechanic/item/custom/AbstractCustomListener.java b/api/src/main/java/net/momirealms/customcrops/api/mechanic/item/custom/AbstractCustomListener.java index ce921bc..2d173e6 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/mechanic/item/custom/AbstractCustomListener.java +++ b/api/src/main/java/net/momirealms/customcrops/api/mechanic/item/custom/AbstractCustomListener.java @@ -31,6 +31,7 @@ import net.momirealms.customcrops.api.mechanic.world.level.WorldCrop; import net.momirealms.customcrops.api.mechanic.world.level.WorldGlass; import net.momirealms.customcrops.api.mechanic.world.level.WorldPot; import net.momirealms.customcrops.api.util.EventUtils; +import net.momirealms.customcrops.api.util.LogUtils; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; @@ -166,12 +167,7 @@ public abstract class AbstractCustomListener implements Listener { final Location location = block.getLocation(); Optional customCropsBlock = CustomCropsPlugin.get().getWorldManager().getBlockAt(SimpleLocation.of(location)); if (customCropsBlock.isPresent()) { - if (customCropsBlock.get() instanceof WorldPot || customCropsBlock.get() instanceof WorldGlass) { - CustomCropsPlugin.get().getWorldManager().removeAnythingAt(SimpleLocation.of(location)); - } else { - event.setCancelled(true); - return; - } + CustomCropsPlugin.get().getWorldManager().removeAnythingAt(SimpleLocation.of(location)); } this.onPlaceBlock( event.getPlayer(), @@ -273,12 +269,12 @@ public abstract class AbstractCustomListener implements Listener { } } - @EventHandler (ignoreCancelled = true) + @EventHandler (ignoreCancelled = true, priority = EventPriority.HIGHEST) public void onExplosion(EntityExplodeEvent event) { this.itemManager.handleExplosion(event.getEntity(), event.blockList(), event); } - @EventHandler (ignoreCancelled = true) + @EventHandler (ignoreCancelled = true, priority = EventPriority.HIGHEST) public void onExplosion(BlockExplodeEvent event) { this.itemManager.handleExplosion(null, event.blockList(), event); } diff --git a/build.gradle.kts b/build.gradle.kts index aad2952..683b23a 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -8,7 +8,7 @@ plugins { allprojects { project.group = "net.momirealms" - project.version = "3.5.7.4" + project.version = "3.5.9" apply() apply(plugin = "java") diff --git a/plugin/build.gradle.kts b/plugin/build.gradle.kts index ef52618..4ee5625 100644 --- a/plugin/build.gradle.kts +++ b/plugin/build.gradle.kts @@ -1,18 +1,18 @@ dependencies { // Platform - compileOnly("dev.folia:folia-api:1.20.1-R0.1-SNAPSHOT") + compileOnly("dev.folia:folia-api:1.20.4-R0.1-SNAPSHOT") compileOnly("com.infernalsuite.aswm:api:1.20.4-R0.1-SNAPSHOT") // Command - compileOnly("dev.jorel:commandapi-bukkit-core:9.4.1") + compileOnly("dev.jorel:commandapi-bukkit-core:9.5.3") // Common hooks - compileOnly("me.clip:placeholderapi:2.11.5") + compileOnly("me.clip:placeholderapi:2.11.6") compileOnly("com.comphenix.protocol:ProtocolLib:5.1.0") compileOnly("com.github.MilkBowl:VaultAPI:1.7") // Utils - compileOnly("dev.dejvokep:boosted-yaml:1.3.4") + compileOnly("dev.dejvokep:boosted-yaml:1.3.6") compileOnly("commons-io:commons-io:2.15.1") compileOnly("com.google.code.gson:gson:2.10.1") compileOnly("net.objecthunter:exp4j:0.4.8") @@ -34,11 +34,11 @@ dependencies { compileOnly("pers.neige.neigeitems:NeigeItems:1.16.24") compileOnly("net.Indyuce:MMOItems-API:6.9.2-SNAPSHOT") compileOnly("io.lumine:MythicLib-dist:1.6-SNAPSHOT") - compileOnly("io.lumine:Mythic-Dist:5.3.5") + compileOnly("io.lumine:Mythic-Dist:5.6.1") compileOnly("io.lumine:MythicCrucible-Dist:2.1.0-SNAPSHOT") // Quests - compileOnly("org.betonquest:betonquest:2.0.0") + compileOnly("org.betonquest:betonquest:2.1.3") compileOnly(files("libs/BattlePass-4.0.6-api.jar")) compileOnly(files("libs/ClueScrolls-api.jar")) @@ -53,17 +53,17 @@ dependencies { implementation(project(":oraxen-j21")) implementation(project(":legacy-api")) - implementation(files("libs/Sparrow-Heart-0.19.jar")) + implementation("net.kyori:adventure-api:4.17.0") implementation("net.kyori:adventure-platform-bukkit:4.3.3") implementation("net.kyori:adventure-text-minimessage:4.17.0") implementation("net.kyori:adventure-text-serializer-legacy:4.17.0") implementation("com.github.Xiao-MoMi:AntiGriefLib:0.12") -// implementation("com.github.Xiao-MoMi:Sparrow-Heart:0.16") + implementation("com.github.Xiao-MoMi:Sparrow-Heart:0.35") implementation("com.flowpowered:flow-nbt:2.0.2") - implementation("com.saicone.rtag:rtag:1.5.4") - implementation("com.saicone.rtag:rtag-item:1.5.4") - implementation("com.github.luben:zstd-jni:1.5.6-2") + implementation("com.saicone.rtag:rtag:1.5.5") + implementation("com.saicone.rtag:rtag-item:1.5.5") + implementation("com.github.luben:zstd-jni:1.5.6-4") } tasks { diff --git a/plugin/libs/AdvancedSeasons-API.jar b/plugin/libs/AdvancedSeasons-API.jar index 19ddf21..0d84a7d 100644 Binary files a/plugin/libs/AdvancedSeasons-API.jar and b/plugin/libs/AdvancedSeasons-API.jar differ diff --git a/plugin/src/main/java/net/momirealms/customcrops/CustomCropsPluginImpl.java b/plugin/src/main/java/net/momirealms/customcrops/CustomCropsPluginImpl.java index 844e747..4999768 100644 --- a/plugin/src/main/java/net/momirealms/customcrops/CustomCropsPluginImpl.java +++ b/plugin/src/main/java/net/momirealms/customcrops/CustomCropsPluginImpl.java @@ -40,6 +40,7 @@ import net.momirealms.customcrops.mechanic.world.WorldManagerImpl; import net.momirealms.customcrops.scheduler.SchedulerImpl; import org.bstats.bukkit.Metrics; import org.bukkit.Bukkit; +import org.bukkit.plugin.Plugin; import java.util.ArrayList; import java.util.List; @@ -93,7 +94,11 @@ public class CustomCropsPluginImpl extends CustomCropsPlugin { this.placeholderManager = new PlaceholderManagerImpl(this); this.hologramManager = new HologramManager(this); this.commandManager.init(); - this.integrationManager.init(); + try { + this.integrationManager.init(); + } catch (Exception e) { + e.printStackTrace(); + } BukkitItemFactory.create(this); Migration.tryUpdating(); this.reload(); @@ -161,6 +166,20 @@ public class CustomCropsPluginImpl extends CustomCropsPlugin { return Bukkit.getPluginManager().isPluginEnabled(plugin); } + @Override + public boolean isHookedPluginEnabled(String hooked, String... versionPrefix) { + Plugin p = Bukkit.getPluginManager().getPlugin(hooked); + if (p != null) { + String ver = p.getDescription().getVersion(); + for (String prefix : versionPrefix) { + if (ver.startsWith(prefix)) { + return true; + } + } + } + return false; + } + @Override public boolean doesHookedPluginExist(String plugin) { return Bukkit.getPluginManager().getPlugin(plugin) != null; diff --git a/plugin/src/main/java/net/momirealms/customcrops/compatibility/IntegrationManagerImpl.java b/plugin/src/main/java/net/momirealms/customcrops/compatibility/IntegrationManagerImpl.java index fefb4ed..73fdd60 100644 --- a/plugin/src/main/java/net/momirealms/customcrops/compatibility/IntegrationManagerImpl.java +++ b/plugin/src/main/java/net/momirealms/customcrops/compatibility/IntegrationManagerImpl.java @@ -111,7 +111,7 @@ public class IntegrationManagerImpl implements IntegrationManager { if (plugin.isHookedPluginEnabled("RealisticSeasons")) { this.seasonInterface = new RealisticSeasonsImpl(); hookMessage("RealisticSeasons"); - } else if (plugin.isHookedPluginEnabled("AdvancedSeasons")) { + } else if (plugin.isHookedPluginEnabled("AdvancedSeasons", "1.4", "1.5")) { this.seasonInterface = new AdvancedSeasonsImpl(); hookMessage("AdvancedSeasons"); } else { diff --git a/plugin/src/main/java/net/momirealms/customcrops/compatibility/quest/BattlePassHook.java b/plugin/src/main/java/net/momirealms/customcrops/compatibility/quest/BattlePassHook.java index b0b6c90..f1fb6b7 100644 --- a/plugin/src/main/java/net/momirealms/customcrops/compatibility/quest/BattlePassHook.java +++ b/plugin/src/main/java/net/momirealms/customcrops/compatibility/quest/BattlePassHook.java @@ -26,6 +26,7 @@ import net.momirealms.customcrops.api.event.CropBreakEvent; import net.momirealms.customcrops.api.event.CropPlantEvent; import net.momirealms.customcrops.api.mechanic.item.Crop; import net.momirealms.customcrops.api.mechanic.world.level.WorldCrop; +import net.momirealms.customcrops.api.util.LogUtils; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -54,7 +55,7 @@ public class BattlePassHook implements Listener { } @EventHandler (ignoreCancelled = true) - public void onBreakCrop(CropBreakEvent event){ + public void onBreakCrop(CropBreakEvent event) { Player player = event.getPlayer(); if (player == null) return; @@ -62,6 +63,10 @@ public class BattlePassHook implements Listener { if (worldCrop == null) return; String id = worldCrop.getConfig().getStageItemByPoint(worldCrop.getPoint()); + if (id.contains(":")) { + id = id.split(":")[1]; + } + // Harvest crops this.executionBuilder("harvest") .player(player) diff --git a/plugin/src/main/java/net/momirealms/customcrops/compatibility/quest/BetonQuestHook.java b/plugin/src/main/java/net/momirealms/customcrops/compatibility/quest/BetonQuestHook.java index c9c56df..21461ae 100644 --- a/plugin/src/main/java/net/momirealms/customcrops/compatibility/quest/BetonQuestHook.java +++ b/plugin/src/main/java/net/momirealms/customcrops/compatibility/quest/BetonQuestHook.java @@ -23,14 +23,15 @@ import net.momirealms.customcrops.api.mechanic.world.level.WorldCrop; import net.momirealms.customcrops.api.util.LogUtils; import org.betonquest.betonquest.BetonQuest; import org.betonquest.betonquest.Instruction; -import org.betonquest.betonquest.VariableNumber; import org.betonquest.betonquest.api.CountingObjective; import org.betonquest.betonquest.api.config.quest.QuestPackage; import org.betonquest.betonquest.api.profiles.OnlineProfile; import org.betonquest.betonquest.api.profiles.Profile; import org.betonquest.betonquest.exceptions.InstructionParseException; +import org.betonquest.betonquest.exceptions.QuestRuntimeException; +import org.betonquest.betonquest.instruction.variable.VariableNumber; +import org.betonquest.betonquest.instruction.variable.location.VariableLocation; import org.betonquest.betonquest.utils.PlayerConverter; -import org.betonquest.betonquest.utils.location.CompoundLocation; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.event.EventHandler; @@ -50,7 +51,7 @@ public class BetonQuestHook { public static class HarvestObjective extends CountingObjective implements Listener { - private final CompoundLocation playerLocation; + private final VariableLocation playerLocation; private final VariableNumber rangeVar; private final HashSet crop_ids; @@ -58,14 +59,13 @@ public class BetonQuestHook { super(instruction, "crop_to_harvest"); crop_ids = new HashSet<>(); Collections.addAll(crop_ids, instruction.getArray()); - targetAmount = instruction.getVarNum(); - preCheckAmountNotLessThanOne(targetAmount); + targetAmount = instruction.getVarNum(VariableNumber.NOT_LESS_THAN_ONE_CHECKER); final QuestPackage pack = instruction.getPackage(); final String loc = instruction.getOptional("playerLocation"); final String range = instruction.getOptional("range"); if (loc != null && range != null) { - playerLocation = new CompoundLocation(pack, loc); - rangeVar = new VariableNumber(pack, range); + playerLocation = new VariableLocation(BetonQuest.getInstance().getVariableProcessor(), pack, loc); + rangeVar = new VariableNumber(BetonQuest.getInstance().getVariableProcessor(), pack, range); } else { playerLocation = null; rangeVar = null; @@ -100,12 +100,17 @@ public class BetonQuestHook { final Location targetLocation; try { - targetLocation = playerLocation.getLocation(profile); + targetLocation = playerLocation.getValue(profile); } catch (final org.betonquest.betonquest.exceptions.QuestRuntimeException e) { LogUtils.warn(e.getMessage()); return true; } - final int range = rangeVar.getInt(profile); + int range; + try { + range = rangeVar.getValue(profile).intValue(); + } catch (QuestRuntimeException e) { + throw new RuntimeException(e); + } final Location playerLoc = event.getPlayer().getLocation(); return !playerLoc.getWorld().equals(targetLocation.getWorld()) || targetLocation.distanceSquared(playerLoc) > range * range; } @@ -123,22 +128,21 @@ public class BetonQuestHook { public static class PlantObjective extends CountingObjective implements Listener { - private final CompoundLocation playerLocation; + private final VariableLocation playerLocation; private final VariableNumber rangeVar; - private final HashSet loot_groups; + private final HashSet crops; public PlantObjective(Instruction instruction) throws InstructionParseException { super(instruction, "crop_to_plant"); - loot_groups = new HashSet<>(); - Collections.addAll(loot_groups, instruction.getArray()); - targetAmount = instruction.getVarNum(); - preCheckAmountNotLessThanOne(targetAmount); + crops = new HashSet<>(); + Collections.addAll(crops, instruction.getArray()); + targetAmount = instruction.getVarNum(VariableNumber.NOT_LESS_THAN_ONE_CHECKER); final QuestPackage pack = instruction.getPackage(); final String loc = instruction.getOptional("playerLocation"); final String range = instruction.getOptional("range"); if (loc != null && range != null) { - playerLocation = new CompoundLocation(pack, loc); - rangeVar = new VariableNumber(pack, range); + playerLocation = new VariableLocation(BetonQuest.getInstance().getVariableProcessor(), pack, loc); + rangeVar = new VariableNumber(BetonQuest.getInstance().getVariableProcessor(), pack, range); } else { playerLocation = null; rangeVar = null; @@ -154,7 +158,7 @@ public class BetonQuestHook { if (isInvalidLocation(event, onlineProfile)) { return; } - if (this.loot_groups.contains(event.getCrop().getKey()) && this.checkConditions(onlineProfile)) { + if (this.crops.contains(event.getCrop().getKey()) && this.checkConditions(onlineProfile)) { getCountingData(onlineProfile).progress(1); completeIfDoneOrNotify(onlineProfile); } @@ -167,12 +171,17 @@ public class BetonQuestHook { final Location targetLocation; try { - targetLocation = playerLocation.getLocation(profile); + targetLocation = playerLocation.getValue(profile); } catch (final org.betonquest.betonquest.exceptions.QuestRuntimeException e) { LogUtils.warn(e.getMessage()); return true; } - final int range = rangeVar.getInt(profile); + int range; + try { + range = rangeVar.getValue(profile).intValue(); + } catch (QuestRuntimeException e) { + throw new RuntimeException(e); + } final Location playerLoc = event.getPlayer().getLocation(); return !playerLoc.getWorld().equals(targetLocation.getWorld()) || targetLocation.distanceSquared(playerLoc) > range * range; } diff --git a/plugin/src/main/java/net/momirealms/customcrops/compatibility/season/AdvancedSeasonsImpl.java b/plugin/src/main/java/net/momirealms/customcrops/compatibility/season/AdvancedSeasonsImpl.java index f46538c..ee32d8e 100644 --- a/plugin/src/main/java/net/momirealms/customcrops/compatibility/season/AdvancedSeasonsImpl.java +++ b/plugin/src/main/java/net/momirealms/customcrops/compatibility/season/AdvancedSeasonsImpl.java @@ -17,27 +17,25 @@ package net.momirealms.customcrops.compatibility.season; -import net.advancedplugins.seasons.api.AdvancedSeasonsAPI; +import net.advancedplugins.seasons.Core; import net.momirealms.customcrops.api.integration.SeasonInterface; import net.momirealms.customcrops.api.mechanic.world.season.Season; import org.bukkit.World; +import org.jetbrains.annotations.NotNull; public class AdvancedSeasonsImpl implements SeasonInterface { - private final AdvancedSeasonsAPI api; - - public AdvancedSeasonsImpl() { - this.api = new AdvancedSeasonsAPI(); - } - @Override - public Season getSeason(World world) { - return switch (api.getSeason(world)) { - case "SPRING" -> Season.SPRING; - case "WINTER" -> Season.WINTER; - case "SUMMER" -> Season.SUMMER; - case "FALL" -> Season.AUTUMN; - default -> null; + public Season getSeason(@NotNull World world) { + net.advancedplugins.seasons.enums.Season season = Core.getSeasonHandler().getSeason(world); + if (season == null) { + return null; + } + return switch (season.getType()) { + case SPRING -> Season.SPRING; + case WINTER -> Season.WINTER; + case SUMMER -> Season.SUMMER; + case FALL -> Season.AUTUMN; }; } @@ -54,7 +52,7 @@ public class AdvancedSeasonsImpl implements SeasonInterface { case SUMMER -> "SUMMER"; case SPRING -> "SPRING"; }; - api.setSeason(seasonName, world); + Core.getSeasonHandler().setSeason(net.advancedplugins.seasons.enums.Season.valueOf(seasonName), world.getName()); } @Override diff --git a/plugin/src/main/java/net/momirealms/customcrops/libraries/dependencies/Dependency.java b/plugin/src/main/java/net/momirealms/customcrops/libraries/dependencies/Dependency.java index 6f76bf5..6f6c7e3 100644 --- a/plugin/src/main/java/net/momirealms/customcrops/libraries/dependencies/Dependency.java +++ b/plugin/src/main/java/net/momirealms/customcrops/libraries/dependencies/Dependency.java @@ -63,7 +63,7 @@ public enum Dependency { COMMAND_API( "dev{}jorel", "commandapi-bukkit-shade", - "9.5.1", + "9.5.3", null, "commandapi-bukkit", Relocation.of("commandapi", "dev{}jorel{}commandapi") @@ -71,7 +71,7 @@ public enum Dependency { COMMAND_API_MOJMAP( "dev{}jorel", "commandapi-bukkit-shade-mojang-mapped", - "9.5.1", + "9.5.3", null, "commandapi-bukkit-mojang-mapped", Relocation.of("commandapi", "dev{}jorel{}commandapi") @@ -79,7 +79,7 @@ public enum Dependency { BOOSTED_YAML( "dev{}dejvokep", "boosted-yaml", - "1.3.4", + "1.3.6", null, "boosted-yaml", Relocation.of("boostedyaml", "dev{}dejvokep{}boostedyaml") diff --git a/plugin/src/main/java/net/momirealms/customcrops/libraries/dependencies/DependencyManagerImpl.java b/plugin/src/main/java/net/momirealms/customcrops/libraries/dependencies/DependencyManagerImpl.java index 28f2c8c..dc8ee83 100644 --- a/plugin/src/main/java/net/momirealms/customcrops/libraries/dependencies/DependencyManagerImpl.java +++ b/plugin/src/main/java/net/momirealms/customcrops/libraries/dependencies/DependencyManagerImpl.java @@ -155,9 +155,6 @@ public class DependencyManagerImpl implements DependencyManager { if (forceRepo == null) { // attempt to download the dependency from each repo in order. for (DependencyRepository repo : DependencyRepository.values()) { - if (repo.getId().equals("maven") && TimeZone.getDefault().getID().startsWith("Asia")) { - continue; - } try { LogUtils.info("Downloading dependency(" + fileName + ") from " + repo.getUrl() + dependency.getMavenRepoPath()); repo.download(dependency, file); diff --git a/plugin/src/main/java/net/momirealms/customcrops/mechanic/item/ItemManagerImpl.java b/plugin/src/main/java/net/momirealms/customcrops/mechanic/item/ItemManagerImpl.java index 0472a93..035cd66 100644 --- a/plugin/src/main/java/net/momirealms/customcrops/mechanic/item/ItemManagerImpl.java +++ b/plugin/src/main/java/net/momirealms/customcrops/mechanic/item/ItemManagerImpl.java @@ -2141,6 +2141,7 @@ public class ItemManagerImpl implements ItemManager { int itemAmount = itemInHand.getAmount(); // get water in pot int waterInPot = plugin.getWorldManager().getPotAt(simpleLocation).map(WorldPot::getWater).orElse(0); + for (PassiveFillMethod method : pot.getPassiveFillMethods()) { if (method.getUsed().equals(itemID) && itemAmount >= method.getUsedAmount()) { if (method.canFill(state)) { @@ -2162,7 +2163,7 @@ public class ItemManagerImpl implements ItemManager { plugin.getWorldManager().addWaterToPot(pot, method.getAmount(), simpleLocation); } else { pot.trigger(ActionTrigger.FULL, state); - return FunctionResult.CANCEL_EVENT_AND_RETURN; + return FunctionResult.RETURN; } } return FunctionResult.RETURN; diff --git a/plugin/src/main/java/net/momirealms/customcrops/mechanic/world/WorldManagerImpl.java b/plugin/src/main/java/net/momirealms/customcrops/mechanic/world/WorldManagerImpl.java index 7a96567..542e177 100644 --- a/plugin/src/main/java/net/momirealms/customcrops/mechanic/world/WorldManagerImpl.java +++ b/plugin/src/main/java/net/momirealms/customcrops/mechanic/world/WorldManagerImpl.java @@ -62,10 +62,11 @@ public class WorldManagerImpl implements WorldManager, Listener { this.plugin = plugin; this.loadedWorlds = new ConcurrentHashMap<>(); this.worldSettingMap = new HashMap<>(); - try { - Class.forName("com.infernalsuite.aswm.api.world.SlimeWorld"); - this.worldAdaptor = new SlimeWorldAdaptor(this); - } catch (ClassNotFoundException ignore) { + if (Bukkit.getPluginManager().isPluginEnabled("SlimeWorldManager")) { + this.worldAdaptor = new SlimeWorldAdaptor(this, 1); + } else if (Bukkit.getPluginManager().isPluginEnabled("SlimeWorldPlugin")) { + this.worldAdaptor = new SlimeWorldAdaptor(this, 2); + } else { this.worldAdaptor = new BukkitWorldAdaptor(this); } } @@ -98,7 +99,7 @@ public class WorldManagerImpl implements WorldManager, Listener { for (World world : Bukkit.getWorlds()) { unloadWorld(world); } - if (this.loadedWorlds.size() != 0) { + if (!this.loadedWorlds.isEmpty()) { LogUtils.severe("Detected that some worlds are not properly unloaded. " + "You can safely ignore this if you are editing \"worlds.list\" and restarting to apply it"); for (String world : this.loadedWorlds.keySet()) { diff --git a/plugin/src/main/java/net/momirealms/customcrops/mechanic/world/adaptor/BukkitWorldAdaptor.java b/plugin/src/main/java/net/momirealms/customcrops/mechanic/world/adaptor/BukkitWorldAdaptor.java index 482a6aa..be37945 100644 --- a/plugin/src/main/java/net/momirealms/customcrops/mechanic/world/adaptor/BukkitWorldAdaptor.java +++ b/plugin/src/main/java/net/momirealms/customcrops/mechanic/world/adaptor/BukkitWorldAdaptor.java @@ -276,7 +276,7 @@ public class BukkitWorldAdaptor extends AbstractWorldAdaptor { } } - @EventHandler (ignoreCancelled = true, priority = EventPriority.HIGH) + @EventHandler (ignoreCancelled = true, priority = EventPriority.LOW) public void onWorldUnload(WorldUnloadEvent event) { if (worldManager.isMechanicEnabled(event.getWorld())) worldManager.unloadWorld(event.getWorld()); diff --git a/plugin/src/main/java/net/momirealms/customcrops/mechanic/world/adaptor/SlimeWorldAdaptor.java b/plugin/src/main/java/net/momirealms/customcrops/mechanic/world/adaptor/SlimeWorldAdaptor.java index f72ffc0..66345e5 100644 --- a/plugin/src/main/java/net/momirealms/customcrops/mechanic/world/adaptor/SlimeWorldAdaptor.java +++ b/plugin/src/main/java/net/momirealms/customcrops/mechanic/world/adaptor/SlimeWorldAdaptor.java @@ -37,20 +37,51 @@ import net.momirealms.customcrops.scheduler.task.TickTask; import org.bukkit.Bukkit; import org.bukkit.World; import org.bukkit.event.EventHandler; +import org.bukkit.plugin.Plugin; +import java.lang.reflect.Method; import java.util.HashSet; import java.util.Map; import java.util.Optional; import java.util.PriorityQueue; import java.util.concurrent.ConcurrentHashMap; +import java.util.function.Function; public class SlimeWorldAdaptor extends BukkitWorldAdaptor { - private final SlimePlugin slimePlugin; + private final Function getSlimeWorldFunction; - public SlimeWorldAdaptor(WorldManager worldManager) { + public SlimeWorldAdaptor(WorldManager worldManager, int version) { super(worldManager); - this.slimePlugin = (SlimePlugin) Bukkit.getPluginManager().getPlugin("SlimeWorldManager"); + try { + if (version == 1) { + Plugin plugin = Bukkit.getPluginManager().getPlugin("SlimeWorldManager"); + Class slimeClass = Class.forName("com.infernalsuite.aswm.api.SlimePlugin"); + Method method = slimeClass.getMethod("getWorld", String.class); + this.getSlimeWorldFunction = (name) -> { + try { + return (SlimeWorld) method.invoke(plugin, name); + } catch (ReflectiveOperationException e) { + throw new RuntimeException(e); + } + }; + } else if (version == 2) { + Class apiClass = Class.forName("com.infernalsuite.aswm.api.AdvancedSlimePaperAPI"); + Object apiInstance = apiClass.getMethod("instance").invoke(null); + Method method = apiClass.getMethod("getLoadedWorld", String.class); + this.getSlimeWorldFunction = (name) -> { + try { + return (SlimeWorld) method.invoke(apiInstance, name); + } catch (ReflectiveOperationException e) { + throw new RuntimeException(e); + } + }; + } else { + throw new IllegalArgumentException("Unsupported version: " + version); + } + } catch (ReflectiveOperationException e) { + throw new RuntimeException(e); + } } @EventHandler (ignoreCancelled = true) @@ -67,7 +98,7 @@ public class SlimeWorldAdaptor extends BukkitWorldAdaptor { @Override public void saveInfoData(CustomCropsWorld customCropsWorld) { - SlimeWorld slimeWorld = slimePlugin.getWorld(customCropsWorld.getWorldName()); + SlimeWorld slimeWorld = getSlimeWorldFunction.apply(customCropsWorld.getWorldName()); if (slimeWorld == null) { super.saveInfoData(customCropsWorld); return; @@ -85,7 +116,7 @@ public class SlimeWorldAdaptor extends BukkitWorldAdaptor { @Override public void unload(CustomCropsWorld customCropsWorld) { - SlimeWorld slimeWorld = slimePlugin.getWorld(customCropsWorld.getWorldName()); + SlimeWorld slimeWorld = getSlimeWorldFunction.apply(customCropsWorld.getWorldName()); if (slimeWorld == null) { super.unload(customCropsWorld); return; @@ -95,7 +126,7 @@ public class SlimeWorldAdaptor extends BukkitWorldAdaptor { @Override public void init(CustomCropsWorld customCropsWorld) { - SlimeWorld slimeWorld = slimePlugin.getWorld(customCropsWorld.getWorldName()); + SlimeWorld slimeWorld = getSlimeWorldFunction.apply(customCropsWorld.getWorldName()); if (slimeWorld == null) { super.init(customCropsWorld); return; @@ -117,7 +148,7 @@ public class SlimeWorldAdaptor extends BukkitWorldAdaptor { @Override public void loadChunkData(CustomCropsWorld customCropsWorld, ChunkPos chunkPos) { - SlimeWorld slimeWorld = slimePlugin.getWorld(customCropsWorld.getWorldName()); + SlimeWorld slimeWorld = getSlimeWorldFunction.apply(customCropsWorld.getWorldName()); if (slimeWorld == null) { super.loadChunkData(customCropsWorld, chunkPos); return; @@ -203,7 +234,7 @@ public class SlimeWorldAdaptor extends BukkitWorldAdaptor { } private SlimeWorld getSlimeWorld(String name) { - return slimePlugin.getWorld(name); + return getSlimeWorldFunction.apply(name); } private CompoundTag chunkToTag(SerializableChunk serializableChunk) { @@ -212,7 +243,7 @@ public class SlimeWorldAdaptor extends BukkitWorldAdaptor { map.put(new IntTag("z", serializableChunk.getZ())); map.put(new IntTag("loadedSeconds", serializableChunk.getLoadedSeconds())); map.put(new LongTag("lastLoadedTime", serializableChunk.getLastLoadedTime())); - map.put(new IntArrayTag("queued", serializableChunk.getTicked())); + map.put(new IntArrayTag("queued", serializableChunk.getQueuedTasks())); map.put(new IntArrayTag("ticked", serializableChunk.getTicked())); CompoundMap sectionMap = new CompoundMap(); for (SerializableSection section : serializableChunk.getSections()) {