diff --git a/api/src/main/java/net/momirealms/customcrops/api/action/builtin/ActionConsumeWater.java b/api/src/main/java/net/momirealms/customcrops/api/action/builtin/ActionConsumeWater.java index 4895a70..33a626b 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/action/builtin/ActionConsumeWater.java +++ b/api/src/main/java/net/momirealms/customcrops/api/action/builtin/ActionConsumeWater.java @@ -21,22 +21,15 @@ import dev.dejvokep.boostedyaml.block.implementation.Section; import net.momirealms.customcrops.api.BukkitCustomCropsPlugin; import net.momirealms.customcrops.api.context.Context; import net.momirealms.customcrops.api.context.ContextKeys; -import net.momirealms.customcrops.api.core.BuiltInBlockMechanics; -import net.momirealms.customcrops.api.core.CustomForm; -import net.momirealms.customcrops.api.core.ExistenceForm; -import net.momirealms.customcrops.api.core.FurnitureRotation; import net.momirealms.customcrops.api.core.block.CropBlock; import net.momirealms.customcrops.api.core.block.PotBlock; -import net.momirealms.customcrops.api.core.mechanic.crop.VariationData; -import net.momirealms.customcrops.api.core.mechanic.fertilizer.Fertilizer; -import net.momirealms.customcrops.api.core.mechanic.fertilizer.FertilizerConfig; import net.momirealms.customcrops.api.core.world.CustomCropsBlockState; import net.momirealms.customcrops.api.core.world.CustomCropsWorld; import net.momirealms.customcrops.api.core.world.Pos3; import net.momirealms.customcrops.api.misc.value.MathValue; import org.bukkit.Location; -import java.util.*; +import java.util.Optional; import static java.util.Objects.requireNonNull; diff --git a/api/src/main/java/net/momirealms/customcrops/api/requirement/AbstractRequirementManager.java b/api/src/main/java/net/momirealms/customcrops/api/requirement/AbstractRequirementManager.java index 5a4d9e5..45deee6 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/requirement/AbstractRequirementManager.java +++ b/api/src/main/java/net/momirealms/customcrops/api/requirement/AbstractRequirementManager.java @@ -41,7 +41,6 @@ import org.bukkit.Location; import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.block.data.type.Farmland; -import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/compatibility-asp-r2/src/main/java/net/momirealms/customcrops/bukkit/integration/adaptor/asp_r2/SlimeWorldAdaptorR2.java b/compatibility-asp-r2/src/main/java/net/momirealms/customcrops/bukkit/integration/adaptor/asp_r2/SlimeWorldAdaptorR2.java index 11d3ec8..9a3cd5f 100644 --- a/compatibility-asp-r2/src/main/java/net/momirealms/customcrops/bukkit/integration/adaptor/asp_r2/SlimeWorldAdaptorR2.java +++ b/compatibility-asp-r2/src/main/java/net/momirealms/customcrops/bukkit/integration/adaptor/asp_r2/SlimeWorldAdaptorR2.java @@ -45,7 +45,6 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.lang.reflect.Method; import java.nio.ByteOrder; -import java.util.Arrays; import java.util.HashSet; import java.util.Map; import java.util.Optional; diff --git a/compatibility/build.gradle.kts b/compatibility/build.gradle.kts index fa11112..7baf896 100644 --- a/compatibility/build.gradle.kts +++ b/compatibility/build.gradle.kts @@ -46,7 +46,8 @@ dependencies { compileOnly(files("libs/BattlePass-4.0.6-api.jar")) compileOnly(files("libs/ClueScrolls-4.8.7-api.jar")) compileOnly("com.comphenix.packetwrapper:PacketWrapper:1.20-2.2.1") - compileOnly("org.betonquest:betonquest:2.2.1") +// compileOnly("org.betonquest:betonquest:3.0.0-SNAPSHOT") + compileOnly(files("libs/BetonQuest.jar")) // item compileOnly(files("libs/zaphkiel-2.0.24.jar")) compileOnly(files("libs/ExecutableItems-7.24.9.29.jar")) diff --git a/compatibility/libs/BetonQuest.jar b/compatibility/libs/BetonQuest.jar new file mode 100644 index 0000000..73562f6 Binary files /dev/null and b/compatibility/libs/BetonQuest.jar differ diff --git a/compatibility/src/main/java/net/momirealms/customcrops/bukkit/integration/quest/BetonQuestQuest.java b/compatibility/src/main/java/net/momirealms/customcrops/bukkit/integration/quest/BetonQuestQuest.java index b57fd83..f93dabb 100644 --- a/compatibility/src/main/java/net/momirealms/customcrops/bukkit/integration/quest/BetonQuestQuest.java +++ b/compatibility/src/main/java/net/momirealms/customcrops/bukkit/integration/quest/BetonQuestQuest.java @@ -17,179 +17,16 @@ package net.momirealms.customcrops.bukkit.integration.quest; -import net.momirealms.customcrops.api.event.CropBreakEvent; -import net.momirealms.customcrops.api.event.CropPlantEvent; +import net.momirealms.customcrops.bukkit.integration.quest.bq.HarvestCropObjectiveFactory; +import net.momirealms.customcrops.bukkit.integration.quest.bq.PlantCropObjectiveFactory; import org.betonquest.betonquest.BetonQuest; -import org.betonquest.betonquest.Instruction; -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.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.HandlerList; -import org.bukkit.event.Listener; - -import java.util.Collections; -import java.util.HashSet; @SuppressWarnings("DuplicatedCode") public class BetonQuestQuest { public static void register() { - BetonQuest.getInstance().registerObjectives("customcrops_harvest", HarvestObjective.class); - BetonQuest.getInstance().registerObjectives("customcrops_plant", PlantObjective.class); - } - - public static class HarvestObjective extends CountingObjective implements Listener { - - private final VariableLocation playerLocation; - private final VariableNumber rangeVar; - private final HashSet crop_ids; - - public HarvestObjective(Instruction instruction) throws InstructionParseException { - super(instruction, "crop_to_harvest"); - crop_ids = new HashSet<>(); - Collections.addAll(crop_ids, 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 VariableLocation(BetonQuest.getInstance().getVariableProcessor(), pack, loc); - rangeVar = new VariableNumber(BetonQuest.getInstance().getVariableProcessor(), pack, range); - } else { - playerLocation = null; - rangeVar = null; - } - } - - @EventHandler (ignoreCancelled = true) - public void onBreakCrop(CropBreakEvent event) { - if (!(event.entityBreaker() instanceof Player player)) { - return; - } - String id = event.cropStageItemID(); - - OnlineProfile onlineProfile = PlayerConverter.getID(player); - if (!containsPlayer(onlineProfile)) { - return; - } - if (isInvalidLocation(player, onlineProfile)) { - return; - } - if (this.crop_ids.contains(id) && this.checkConditions(onlineProfile)) { - getCountingData(onlineProfile).progress(1); - completeIfDoneOrNotify(onlineProfile); - } - } - - private boolean isInvalidLocation(Player player, final Profile profile) { - if (playerLocation == null || rangeVar == null) { - return false; - } - - final Location targetLocation; - try { - targetLocation = playerLocation.getValue(profile); - } catch (final org.betonquest.betonquest.exceptions.QuestRuntimeException e) { - return true; - } - int range; - try { - range = rangeVar.getValue(profile).intValue(); - } catch (QuestRuntimeException e) { - throw new RuntimeException(e); - } - final Location playerLoc = player.getLocation(); - return !playerLoc.getWorld().equals(targetLocation.getWorld()) || targetLocation.distanceSquared(playerLoc) > range * range; - } - - @Override - public void start() { - Bukkit.getPluginManager().registerEvents(this, BetonQuest.getInstance()); - } - - @Override - public void stop() { - HandlerList.unregisterAll(this); - } - } - - public static class PlantObjective extends CountingObjective implements Listener { - - private final VariableLocation playerLocation; - private final VariableNumber rangeVar; - private final HashSet crops; - - public PlantObjective(Instruction instruction) throws InstructionParseException { - super(instruction, "crop_to_plant"); - 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 VariableLocation(BetonQuest.getInstance().getVariableProcessor(), pack, loc); - rangeVar = new VariableNumber(BetonQuest.getInstance().getVariableProcessor(), pack, range); - } else { - playerLocation = null; - rangeVar = null; - } - } - - @EventHandler (ignoreCancelled = true) - public void onPlantCrop(CropPlantEvent event) { - OnlineProfile onlineProfile = PlayerConverter.getID(event.getPlayer()); - if (!containsPlayer(onlineProfile)) { - return; - } - if (isInvalidLocation(event.getPlayer(), onlineProfile)) { - return; - } - if (this.crops.contains(event.cropConfig().id()) && this.checkConditions(onlineProfile)) { - getCountingData(onlineProfile).progress(1); - completeIfDoneOrNotify(onlineProfile); - } - } - - private boolean isInvalidLocation(Player player, final Profile profile) { - if (playerLocation == null || rangeVar == null) { - return false; - } - - final Location targetLocation; - try { - targetLocation = playerLocation.getValue(profile); - } catch (final org.betonquest.betonquest.exceptions.QuestRuntimeException e) { - return true; - } - int range; - try { - range = rangeVar.getValue(profile).intValue(); - } catch (QuestRuntimeException e) { - throw new RuntimeException(e); - } - final Location playerLoc = player.getLocation(); - return !playerLoc.getWorld().equals(targetLocation.getWorld()) || targetLocation.distanceSquared(playerLoc) > range * range; - } - - @Override - public void start() { - Bukkit.getPluginManager().registerEvents(this, BetonQuest.getInstance()); - } - - @Override - public void stop() { - HandlerList.unregisterAll(this); - } + BetonQuest bq = BetonQuest.getInstance(); + bq.getQuestRegistries().objective().register("customcrops_harvest", new HarvestCropObjectiveFactory()); + bq.getQuestRegistries().objective().register("customcrops_plant", new PlantCropObjectiveFactory()); } } diff --git a/compatibility/src/main/java/net/momirealms/customcrops/bukkit/integration/quest/bq/HarvestCropObjective.java b/compatibility/src/main/java/net/momirealms/customcrops/bukkit/integration/quest/bq/HarvestCropObjective.java new file mode 100644 index 0000000..59dcf62 --- /dev/null +++ b/compatibility/src/main/java/net/momirealms/customcrops/bukkit/integration/quest/bq/HarvestCropObjective.java @@ -0,0 +1,42 @@ +package net.momirealms.customcrops.bukkit.integration.quest.bq; + +import net.momirealms.customcrops.api.event.CropBreakEvent; +import org.betonquest.betonquest.api.CountingObjective; +import org.betonquest.betonquest.api.QuestException; +import org.betonquest.betonquest.api.instruction.Instruction; +import org.betonquest.betonquest.api.instruction.variable.Variable; +import org.betonquest.betonquest.api.profile.OnlineProfile; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; + +import java.util.List; + +public class HarvestCropObjective extends CountingObjective implements Listener { + + private final Variable> identifiers; + + public HarvestCropObjective(final Instruction instruction, final Variable targetAmount, + final Variable> identifiers) throws QuestException { + super(instruction, targetAmount, "custom_crops_to_harvest"); + this.identifiers = identifiers; + } + + @EventHandler(ignoreCancelled = true) + public void onBreakCrop(CropBreakEvent event) throws QuestException { + if (!(event.entityBreaker() instanceof Player player)) { + return; + } + OnlineProfile profile = profileProvider.getProfile(player); + if (!containsPlayer(profile)) { + return; + } + if (!checkConditions(profile)) { + return; + } + if (this.identifiers.getValue(profile).contains(event.cropStageItemID())) { + getCountingData(profile).progress(); + completeIfDoneOrNotify(profile); + } + } +} diff --git a/compatibility/src/main/java/net/momirealms/customcrops/bukkit/integration/quest/bq/HarvestCropObjectiveFactory.java b/compatibility/src/main/java/net/momirealms/customcrops/bukkit/integration/quest/bq/HarvestCropObjectiveFactory.java new file mode 100644 index 0000000..999d7f9 --- /dev/null +++ b/compatibility/src/main/java/net/momirealms/customcrops/bukkit/integration/quest/bq/HarvestCropObjectiveFactory.java @@ -0,0 +1,23 @@ +package net.momirealms.customcrops.bukkit.integration.quest.bq; + +import org.betonquest.betonquest.api.Objective; +import org.betonquest.betonquest.api.QuestException; +import org.betonquest.betonquest.api.instruction.Instruction; +import org.betonquest.betonquest.api.instruction.argument.Argument; +import org.betonquest.betonquest.api.instruction.variable.Variable; +import org.betonquest.betonquest.api.quest.objective.ObjectiveFactory; + +import java.util.List; + +public class HarvestCropObjectiveFactory implements ObjectiveFactory { + + public HarvestCropObjectiveFactory() { + } + + @Override + public Objective parseInstruction(final Instruction instruction) throws QuestException { + final Variable> names = instruction.getList(Argument.STRING); + final Variable targetAmount = instruction.getValue("amount", Argument.NUMBER_NOT_LESS_THAN_ONE, 1); + return new HarvestCropObjective(instruction, targetAmount, names); + } +} diff --git a/compatibility/src/main/java/net/momirealms/customcrops/bukkit/integration/quest/bq/PlantCropObjective.java b/compatibility/src/main/java/net/momirealms/customcrops/bukkit/integration/quest/bq/PlantCropObjective.java new file mode 100644 index 0000000..07d68fe --- /dev/null +++ b/compatibility/src/main/java/net/momirealms/customcrops/bukkit/integration/quest/bq/PlantCropObjective.java @@ -0,0 +1,38 @@ +package net.momirealms.customcrops.bukkit.integration.quest.bq; + +import net.momirealms.customcrops.api.event.CropPlantEvent; +import org.betonquest.betonquest.api.CountingObjective; +import org.betonquest.betonquest.api.QuestException; +import org.betonquest.betonquest.api.instruction.Instruction; +import org.betonquest.betonquest.api.instruction.variable.Variable; +import org.betonquest.betonquest.api.profile.OnlineProfile; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; + +import java.util.List; + +public class PlantCropObjective extends CountingObjective implements Listener { + + private final Variable> identifiers; + + public PlantCropObjective(final Instruction instruction, final Variable targetAmount, + final Variable> identifiers) throws QuestException { + super(instruction, targetAmount, "custom_crops_to_plant"); + this.identifiers = identifiers; + } + + @EventHandler(ignoreCancelled = true) + public void onPlantCrop(CropPlantEvent event) throws QuestException { + OnlineProfile profile = profileProvider.getProfile(event.getPlayer()); + if (!containsPlayer(profile)) { + return; + } + if (!checkConditions(profile)) { + return; + } + if (this.identifiers.getValue(profile).contains(event.cropConfig().id())) { + getCountingData(profile).progress(); + completeIfDoneOrNotify(profile); + } + } +} diff --git a/compatibility/src/main/java/net/momirealms/customcrops/bukkit/integration/quest/bq/PlantCropObjectiveFactory.java b/compatibility/src/main/java/net/momirealms/customcrops/bukkit/integration/quest/bq/PlantCropObjectiveFactory.java new file mode 100644 index 0000000..bbb0000 --- /dev/null +++ b/compatibility/src/main/java/net/momirealms/customcrops/bukkit/integration/quest/bq/PlantCropObjectiveFactory.java @@ -0,0 +1,23 @@ +package net.momirealms.customcrops.bukkit.integration.quest.bq; + +import org.betonquest.betonquest.api.Objective; +import org.betonquest.betonquest.api.QuestException; +import org.betonquest.betonquest.api.instruction.Instruction; +import org.betonquest.betonquest.api.instruction.argument.Argument; +import org.betonquest.betonquest.api.instruction.variable.Variable; +import org.betonquest.betonquest.api.quest.objective.ObjectiveFactory; + +import java.util.List; + +public class PlantCropObjectiveFactory implements ObjectiveFactory { + + public PlantCropObjectiveFactory() { + } + + @Override + public Objective parseInstruction(final Instruction instruction) throws QuestException { + final Variable> names = instruction.getList(Argument.STRING); + final Variable targetAmount = instruction.getValue("amount", Argument.NUMBER_NOT_LESS_THAN_ONE, 1); + return new PlantCropObjective(instruction, targetAmount, names); + } +} diff --git a/plugin/src/main/java/net/momirealms/customcrops/bukkit/command/feature/GetSeasonCommand.java b/plugin/src/main/java/net/momirealms/customcrops/bukkit/command/feature/GetSeasonCommand.java index cf93c2f..c2e3fad 100644 --- a/plugin/src/main/java/net/momirealms/customcrops/bukkit/command/feature/GetSeasonCommand.java +++ b/plugin/src/main/java/net/momirealms/customcrops/bukkit/command/feature/GetSeasonCommand.java @@ -29,7 +29,6 @@ import org.bukkit.command.CommandSender; import org.checkerframework.checker.nullness.qual.NonNull; import org.incendo.cloud.Command; import org.incendo.cloud.CommandManager; -import org.incendo.cloud.bukkit.parser.WorldParser; import org.incendo.cloud.context.CommandContext; import org.incendo.cloud.context.CommandInput; import org.incendo.cloud.parser.standard.StringParser; diff --git a/plugin/src/main/java/net/momirealms/customcrops/bukkit/command/feature/SetDateCommand.java b/plugin/src/main/java/net/momirealms/customcrops/bukkit/command/feature/SetDateCommand.java index 1f98e2d..22feb4e 100644 --- a/plugin/src/main/java/net/momirealms/customcrops/bukkit/command/feature/SetDateCommand.java +++ b/plugin/src/main/java/net/momirealms/customcrops/bukkit/command/feature/SetDateCommand.java @@ -31,7 +31,6 @@ import org.bukkit.command.CommandSender; import org.checkerframework.checker.nullness.qual.NonNull; import org.incendo.cloud.Command; import org.incendo.cloud.CommandManager; -import org.incendo.cloud.bukkit.parser.WorldParser; import org.incendo.cloud.context.CommandContext; import org.incendo.cloud.context.CommandInput; import org.incendo.cloud.parser.standard.IntegerParser; diff --git a/plugin/src/main/java/net/momirealms/customcrops/bukkit/command/feature/SetSeasonCommand.java b/plugin/src/main/java/net/momirealms/customcrops/bukkit/command/feature/SetSeasonCommand.java index 2deefeb..fd2afc1 100644 --- a/plugin/src/main/java/net/momirealms/customcrops/bukkit/command/feature/SetSeasonCommand.java +++ b/plugin/src/main/java/net/momirealms/customcrops/bukkit/command/feature/SetSeasonCommand.java @@ -32,7 +32,6 @@ import org.bukkit.command.CommandSender; import org.checkerframework.checker.nullness.qual.NonNull; import org.incendo.cloud.Command; import org.incendo.cloud.CommandManager; -import org.incendo.cloud.bukkit.parser.WorldParser; import org.incendo.cloud.context.CommandContext; import org.incendo.cloud.context.CommandInput; import org.incendo.cloud.parser.standard.StringParser; diff --git a/plugin/src/main/java/net/momirealms/customcrops/bukkit/integration/BukkitIntegrationManager.java b/plugin/src/main/java/net/momirealms/customcrops/bukkit/integration/BukkitIntegrationManager.java index da19cab..b5e1124 100644 --- a/plugin/src/main/java/net/momirealms/customcrops/bukkit/integration/BukkitIntegrationManager.java +++ b/plugin/src/main/java/net/momirealms/customcrops/bukkit/integration/BukkitIntegrationManager.java @@ -86,7 +86,7 @@ public class BukkitIntegrationManager implements IntegrationManager { ClueScrollsQuest clueScrollsQuest = new ClueScrollsQuest(); clueScrollsQuest.register(); } - if (isHooked("BetonQuest", "2")) { + if (isHooked("BetonQuest", "3")) { BetonQuestQuest.register(); } if (isHooked("WorldGuard", "7")) { diff --git a/plugin/src/main/java/net/momirealms/customcrops/bukkit/item/BukkitItemManager.java b/plugin/src/main/java/net/momirealms/customcrops/bukkit/item/BukkitItemManager.java index 4531b1b..b61f1f4 100644 --- a/plugin/src/main/java/net/momirealms/customcrops/bukkit/item/BukkitItemManager.java +++ b/plugin/src/main/java/net/momirealms/customcrops/bukkit/item/BukkitItemManager.java @@ -25,7 +25,6 @@ import net.momirealms.customcrops.api.core.*; import net.momirealms.customcrops.api.core.block.BreakReason; import net.momirealms.customcrops.api.core.block.CustomCropsBlock; import net.momirealms.customcrops.api.core.item.CustomCropsItem; -import net.momirealms.customcrops.api.core.mechanic.crop.CropConfig; import net.momirealms.customcrops.api.core.world.CustomCropsBlockState; import net.momirealms.customcrops.api.core.world.CustomCropsWorld; import net.momirealms.customcrops.api.core.world.Pos3;