mirror of
https://github.com/Xiao-MoMi/Custom-Crops.git
synced 2025-12-28 19:39:20 +00:00
Add BetonQuest 3 compatibility
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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"))
|
||||
|
||||
BIN
compatibility/libs/BetonQuest.jar
Normal file
BIN
compatibility/libs/BetonQuest.jar
Normal file
Binary file not shown.
@@ -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<String> 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<String> 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());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<List<String>> identifiers;
|
||||
|
||||
public HarvestCropObjective(final Instruction instruction, final Variable<Number> targetAmount,
|
||||
final Variable<List<String>> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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<List<String>> names = instruction.getList(Argument.STRING);
|
||||
final Variable<Number> targetAmount = instruction.getValue("amount", Argument.NUMBER_NOT_LESS_THAN_ONE, 1);
|
||||
return new HarvestCropObjective(instruction, targetAmount, names);
|
||||
}
|
||||
}
|
||||
@@ -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<List<String>> identifiers;
|
||||
|
||||
public PlantCropObjective(final Instruction instruction, final Variable<Number> targetAmount,
|
||||
final Variable<List<String>> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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<List<String>> names = instruction.getList(Argument.STRING);
|
||||
final Variable<Number> targetAmount = instruction.getValue("amount", Argument.NUMBER_NOT_LESS_THAN_ONE, 1);
|
||||
return new PlantCropObjective(instruction, targetAmount, names);
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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")) {
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user