9
0
mirror of https://github.com/Xiao-MoMi/Custom-Crops.git synced 2025-12-26 10:29:10 +00:00
This commit is contained in:
XiaoMoMi
2024-08-13 15:11:01 +08:00
parent 207b56a073
commit 8aac425480
16 changed files with 139 additions and 80 deletions

View File

@@ -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;

View File

@@ -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 {

View File

@@ -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)

View File

@@ -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<String> 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<String> loot_groups;
private final HashSet<String> 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;
}

View File

@@ -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

View File

@@ -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")

View File

@@ -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);

View File

@@ -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;

View File

@@ -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()) {

View File

@@ -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());

View File

@@ -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<String, SlimeWorld> 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()) {