Skip to content

Commit

Permalink
Fix compatibility with latest BQ, AS
Browse files Browse the repository at this point in the history
  • Loading branch information
Xiao-MoMi committed Aug 7, 2024
1 parent 44b7384 commit 228fc9a
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 45 deletions.
2 changes: 1 addition & 1 deletion compatibility/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ dependencies {
compileOnly(files("libs/BattlePass-4.0.6-api.jar"))
compileOnly(files("libs/ClueScrolls-4.8.7-api.jar"))
compileOnly(files("libs/notquests-5.17.1.jar"))
compileOnly("org.betonquest:betonquest:2.1.2")
compileOnly("org.betonquest:betonquest:2.1.3")
// item
compileOnly(files("libs/zaphkiel-2.0.24.jar"))
compileOnly("com.github.LoneDev6:API-ItemsAdder:3.6.1")
Expand Down
Binary file modified compatibility/libs/AdvancedSeasons-API.jar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@
import net.momirealms.customfishing.api.event.FishingResultEvent;
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;
Expand All @@ -43,38 +44,27 @@ public class BetonQuestQuest {

public static void register() {
BetonQuest ins1 = BetonQuest.getInstance();
if (ins1 != null) {
ins1.registerObjectives("customfishing_loot", IDObjective.class);
ins1.registerObjectives("customfishing_group", GroupObjective.class);
} else {
Bukkit.getScheduler().runTaskLater(BukkitCustomFishingPlugin.getInstance().getBoostrap(), () -> {
BetonQuest ins2 = BetonQuest.getInstance();
if (ins2 != null) {
ins2.registerObjectives("customfishing_loot", IDObjective.class);
ins2.registerObjectives("customfishing_group", GroupObjective.class);
}
}, 1);
}
ins1.registerObjectives("customfishing_loot", IDObjective.class);
ins1.registerObjectives("customfishing_group", GroupObjective.class);
}

public static class IDObjective extends CountingObjective implements Listener {

private final CompoundLocation playerLocation;
private final VariableLocation playerLocation;
private final VariableNumber rangeVar;
private final HashSet<String> loot_ids;

public IDObjective(Instruction instruction) throws InstructionParseException {
super(instruction, "loot_to_fish");
loot_ids = new HashSet<>();
Collections.addAll(loot_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;
Expand Down Expand Up @@ -105,12 +95,17 @@ private boolean isInvalidLocation(FishingResultEvent event, final Profile profil

final Location targetLocation;
try {
targetLocation = playerLocation.getLocation(profile);
targetLocation = playerLocation.getValue(profile);
} catch (final org.betonquest.betonquest.exceptions.QuestRuntimeException e) {
e.printStackTrace();
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;
}
Expand All @@ -128,22 +123,21 @@ public void stop() {

public static class GroupObjective extends CountingObjective implements Listener {

private final CompoundLocation playerLocation;
private final VariableLocation playerLocation;
private final VariableNumber rangeVar;
private final HashSet<String> loot_groups;

public GroupObjective(Instruction instruction) throws InstructionParseException {
super(instruction, "group_to_fish");
loot_groups = new HashSet<>();
Collections.addAll(loot_groups, 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;
Expand Down Expand Up @@ -179,12 +173,17 @@ private boolean isInvalidLocation(FishingResultEvent event, final Profile profil

final Location targetLocation;
try {
targetLocation = playerLocation.getLocation(profile);
targetLocation = playerLocation.getValue(profile);
} catch (final org.betonquest.betonquest.exceptions.QuestRuntimeException e) {
e.printStackTrace();
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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,26 @@

package net.momirealms.customfishing.bukkit.integration.season;

import net.advancedplugins.seasons.api.AdvancedSeasonsAPI;
import net.advancedplugins.seasons.Core;
import net.momirealms.customfishing.api.integration.SeasonProvider;
import net.momirealms.customfishing.api.mechanic.misc.season.Season;
import org.bukkit.World;
import org.jetbrains.annotations.NotNull;

public class AdvancedSeasonsProvider implements SeasonProvider {

private final AdvancedSeasonsAPI api;

public AdvancedSeasonsProvider() {
this.api = new AdvancedSeasonsAPI();
}

@NotNull
@Override
public Season getSeason(@NotNull World world) {
return switch (api.getSeason(world)) {
case "SPRING" -> Season.SPRING;
case "WINTER" -> Season.WINTER;
case "SUMMER" -> Season.SUMMER;
case "FALL" -> Season.AUTUMN;
default -> Season.DISABLE;
net.advancedplugins.seasons.enums.Season season = Core.getSeasonHandler().getSeason(world);
if (season == null) {
return Season.DISABLE;
}
return switch (season.getType()) {
case SPRING -> Season.SPRING;
case WINTER -> Season.WINTER;
case SUMMER -> Season.SUMMER;
case FALL -> Season.AUTUMN;
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@ public class BukkitIntegrationManager implements IntegrationManager {

public BukkitIntegrationManager(BukkitCustomFishingPlugin plugin) {
this.plugin = plugin;
this.load();
try {
this.load();
} catch (Exception e) {
plugin.getPluginLogger().warn("Failed to load integrations", e);
}
}

@Override
Expand Down Expand Up @@ -125,7 +129,7 @@ public void load() {
}
if (isHooked("RealisticSeasons")) {
registerSeasonProvider(new RealisticSeasonsProvider());
} else if (isHooked("AdvancedSeasons")) {
} else if (isHooked("AdvancedSeasons", "1.4", "1.5", "1.6")) {
registerSeasonProvider(new AdvancedSeasonsProvider());
} else if (isHooked("CustomCrops", "3.4", "3.5", "3.6")) {
registerSeasonProvider(new CustomCropsSeasonProvider());
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Project settings
# Rule: [major update].[feature update].[bug fix]
project_version=2.2.15
project_version=2.2.16
config_version=35
project_group=net.momirealms

Expand Down

0 comments on commit 228fc9a

Please sign in to comment.