diff --git a/build.gradle b/build.gradle index 2351a18..913b000 100644 --- a/build.gradle +++ b/build.gradle @@ -4,7 +4,7 @@ plugins { } group = 'net.momirealms' -version = '3.2.3.3' +version = '3.2.4.0' repositories { mavenCentral() @@ -30,7 +30,7 @@ dependencies { compileOnly ('dev.folia:folia-api:1.19.4-R0.1-SNAPSHOT') compileOnly ('io.papermc.paper:paper-api:1.19.4-R0.1-SNAPSHOT') compileOnly ('me.clip:placeholderapi:2.11.3') - compileOnly ('com.github.LoneDev6:api-itemsadder:3.4.1-r4') + compileOnly ('com.github.LoneDev6:api-itemsadder:3.4.1e') compileOnly ('io.lumine:Mythic-Dist:5.0.3-SNAPSHOT') //compileOnly ('com.willfp:EcoSkills:3.0.0-b2') No read access compileOnly ('com.willfp:eco:6.60.0') diff --git a/libs/BiomeAPI.jar b/libs/BiomeAPI.jar index a9c346d..00c0671 100644 Binary files a/libs/BiomeAPI.jar and b/libs/BiomeAPI.jar differ diff --git a/src/main/java/net/momirealms/customcrops/api/customplugin/PlatformManager.java b/src/main/java/net/momirealms/customcrops/api/customplugin/PlatformManager.java index 7615ebc..125f72f 100644 --- a/src/main/java/net/momirealms/customcrops/api/customplugin/PlatformManager.java +++ b/src/main/java/net/momirealms/customcrops/api/customplugin/PlatformManager.java @@ -804,6 +804,15 @@ public class PlatformManager extends Function { FertilizerConfig fertilizerConfig = plugin.getFertilizerManager().getConfigByItemID(item_in_hand_id); if (fertilizerConfig != null) { + if (fertilizerConfig.getRequirements() != null) { + CurrentState currentState = new CurrentState(location, player); + for (Requirement requirement : fertilizerConfig.getRequirements()) { + if (!requirement.isConditionMet(currentState)) { + return true; + } + } + } + FertilizerUseEvent fertilizerUseEvent = new FertilizerUseEvent(player, item_in_hand, fertilizerConfig, location); Bukkit.getPluginManager().callEvent(fertilizerUseEvent); if (fertilizerUseEvent.isCancelled()) { diff --git a/src/main/java/net/momirealms/customcrops/api/object/fertilizer/FertilizerConfig.java b/src/main/java/net/momirealms/customcrops/api/object/fertilizer/FertilizerConfig.java index 1799ffe..3b1d5bf 100644 --- a/src/main/java/net/momirealms/customcrops/api/object/fertilizer/FertilizerConfig.java +++ b/src/main/java/net/momirealms/customcrops/api/object/fertilizer/FertilizerConfig.java @@ -18,6 +18,7 @@ package net.momirealms.customcrops.api.object.fertilizer; import net.kyori.adventure.sound.Sound; +import net.momirealms.customcrops.api.object.requirement.Requirement; import org.bukkit.Particle; import org.jetbrains.annotations.Nullable; @@ -32,8 +33,9 @@ public abstract class FertilizerConfig { private final Particle particle; private final Sound sound; private final String icon; + private final Requirement[] requirements; - public FertilizerConfig(String key, FertilizerType fertilizerType, int times, double chance, @Nullable String[] pot_whitelist, boolean beforePlant, @Nullable Particle particle, @Nullable Sound sound, @Nullable String icon) { + public FertilizerConfig(String key, FertilizerType fertilizerType, int times, double chance, @Nullable String[] pot_whitelist, boolean beforePlant, @Nullable Particle particle, @Nullable Sound sound, @Nullable String icon, Requirement[] requirements) { this.times = times; this.chance = chance; this.key = key; @@ -43,6 +45,7 @@ public abstract class FertilizerConfig { this.particle = particle; this.sound = sound; this.icon = icon; + this.requirements = requirements; } public int getTimes() { @@ -87,4 +90,8 @@ public abstract class FertilizerConfig { public String getIcon() { return icon; } + + public Requirement[] getRequirements() { + return requirements; + } } diff --git a/src/main/java/net/momirealms/customcrops/api/object/fertilizer/FertilizerManager.java b/src/main/java/net/momirealms/customcrops/api/object/fertilizer/FertilizerManager.java index 9f58644..c196319 100644 --- a/src/main/java/net/momirealms/customcrops/api/object/fertilizer/FertilizerManager.java +++ b/src/main/java/net/momirealms/customcrops/api/object/fertilizer/FertilizerManager.java @@ -22,6 +22,7 @@ import net.kyori.adventure.sound.Sound; import net.momirealms.customcrops.CustomCrops; import net.momirealms.customcrops.api.object.Function; import net.momirealms.customcrops.api.object.Pair; +import net.momirealms.customcrops.api.object.requirement.Requirement; import net.momirealms.customcrops.api.util.AdventureUtils; import net.momirealms.customcrops.api.util.ConfigUtils; import org.bukkit.Particle; @@ -102,12 +103,13 @@ public class FertilizerManager extends Function { @Subst("namespace:key") String soundKey = fertilizerSec.getString("sound", "minecraft:item.hoe.till"); Sound sound = fertilizerSec.contains("sound") ? Sound.sound(Key.key(soundKey), Sound.Source.PLAYER, 1, 1) : null; String icon = fertilizerSec.getString("icon"); + Requirement[] requirements = ConfigUtils.getRequirementsWithMsg(fertilizerSec.getConfigurationSection("requirements")); switch (fertilizerType) { - case SPEED_GROW -> fertilizerConfig = new SpeedGrow(key, fertilizerType, times, getChancePair(fertilizerSec), pot_whitelist, beforePlant, particle, sound, icon); - case YIELD_INCREASE -> fertilizerConfig = new YieldIncrease(key, fertilizerType, times, fertilizerSec.getDouble("chance"), getChancePair(fertilizerSec), pot_whitelist, beforePlant, particle, sound, icon); - case VARIATION -> fertilizerConfig = new Variation(key, fertilizerType, times, fertilizerSec.getDouble("chance"), pot_whitelist, beforePlant, particle, sound, icon); - case QUALITY -> fertilizerConfig = new Quality(key, fertilizerType, times, fertilizerSec.getDouble("chance"), ConfigUtils.getQualityRatio(fertilizerSec.getString("ratio", "2/2/1")), pot_whitelist, beforePlant, particle, sound, icon); - case SOIL_RETAIN -> fertilizerConfig = new SoilRetain(key, fertilizerType, times, fertilizerSec.getDouble("chance"), pot_whitelist, beforePlant, particle, sound, icon); + case SPEED_GROW -> fertilizerConfig = new SpeedGrow(key, fertilizerType, times, getChancePair(fertilizerSec), pot_whitelist, beforePlant, particle, sound, icon, requirements); + case YIELD_INCREASE -> fertilizerConfig = new YieldIncrease(key, fertilizerType, times, fertilizerSec.getDouble("chance"), getChancePair(fertilizerSec), pot_whitelist, beforePlant, particle, sound, icon, requirements); + case VARIATION -> fertilizerConfig = new Variation(key, fertilizerType, times, fertilizerSec.getDouble("chance"), pot_whitelist, beforePlant, particle, sound, icon, requirements); + case QUALITY -> fertilizerConfig = new Quality(key, fertilizerType, times, fertilizerSec.getDouble("chance"), ConfigUtils.getQualityRatio(fertilizerSec.getString("ratio", "2/2/1")), pot_whitelist, beforePlant, particle, sound, icon, requirements); + case SOIL_RETAIN -> fertilizerConfig = new SoilRetain(key, fertilizerType, times, fertilizerSec.getDouble("chance"), pot_whitelist, beforePlant, particle, sound, icon, requirements); default -> fertilizerConfig = null; } String item = fertilizerSec.getString("item"); diff --git a/src/main/java/net/momirealms/customcrops/api/object/fertilizer/Quality.java b/src/main/java/net/momirealms/customcrops/api/object/fertilizer/Quality.java index 4fb8369..81c3d57 100644 --- a/src/main/java/net/momirealms/customcrops/api/object/fertilizer/Quality.java +++ b/src/main/java/net/momirealms/customcrops/api/object/fertilizer/Quality.java @@ -18,6 +18,7 @@ package net.momirealms.customcrops.api.object.fertilizer; import net.kyori.adventure.sound.Sound; +import net.momirealms.customcrops.api.object.requirement.Requirement; import org.bukkit.Particle; import org.jetbrains.annotations.Nullable; @@ -26,8 +27,8 @@ public class Quality extends FertilizerConfig { private final double[] ratio; public Quality(String key, FertilizerType fertilizerType, int times, double chance, double[] ratio, - @Nullable String[] pot_whitelist, boolean beforePlant, @Nullable Particle particle, @Nullable Sound sound, @Nullable String icon) { - super(key, fertilizerType, times, chance, pot_whitelist, beforePlant, particle, sound, icon); + @Nullable String[] pot_whitelist, boolean beforePlant, @Nullable Particle particle, @Nullable Sound sound, @Nullable String icon, Requirement[] requirements) { + super(key, fertilizerType, times, chance, pot_whitelist, beforePlant, particle, sound, icon, requirements); this.ratio = ratio; } diff --git a/src/main/java/net/momirealms/customcrops/api/object/fertilizer/SoilRetain.java b/src/main/java/net/momirealms/customcrops/api/object/fertilizer/SoilRetain.java index 9821530..72e6e4b 100644 --- a/src/main/java/net/momirealms/customcrops/api/object/fertilizer/SoilRetain.java +++ b/src/main/java/net/momirealms/customcrops/api/object/fertilizer/SoilRetain.java @@ -18,13 +18,14 @@ package net.momirealms.customcrops.api.object.fertilizer; import net.kyori.adventure.sound.Sound; +import net.momirealms.customcrops.api.object.requirement.Requirement; import org.bukkit.Particle; import org.jetbrains.annotations.Nullable; public class SoilRetain extends FertilizerConfig { public SoilRetain(String key, FertilizerType fertilizerType, int times, double chance, - @Nullable String[] pot_whitelist, boolean beforePlant, @Nullable Particle particle, @Nullable Sound sound, String icon) { - super(key, fertilizerType, times, chance, pot_whitelist, beforePlant, particle, sound, icon); + @Nullable String[] pot_whitelist, boolean beforePlant, @Nullable Particle particle, @Nullable Sound sound, String icon, Requirement[] requirements) { + super(key, fertilizerType, times, chance, pot_whitelist, beforePlant, particle, sound, icon, requirements); } } diff --git a/src/main/java/net/momirealms/customcrops/api/object/fertilizer/SpeedGrow.java b/src/main/java/net/momirealms/customcrops/api/object/fertilizer/SpeedGrow.java index 4483154..ce64137 100644 --- a/src/main/java/net/momirealms/customcrops/api/object/fertilizer/SpeedGrow.java +++ b/src/main/java/net/momirealms/customcrops/api/object/fertilizer/SpeedGrow.java @@ -19,6 +19,7 @@ package net.momirealms.customcrops.api.object.fertilizer; import net.kyori.adventure.sound.Sound; import net.momirealms.customcrops.api.object.Pair; +import net.momirealms.customcrops.api.object.requirement.Requirement; import org.bukkit.Particle; import org.jetbrains.annotations.Nullable; @@ -29,8 +30,8 @@ public class SpeedGrow extends FertilizerConfig { private final List> pairs; public SpeedGrow(String key, FertilizerType fertilizerType, int times, List> pairs, - @Nullable String[] pot_whitelist, boolean beforePlant, @Nullable Particle particle, @Nullable Sound sound, String icon) { - super(key, fertilizerType, times, 1, pot_whitelist, beforePlant, particle, sound, icon); + @Nullable String[] pot_whitelist, boolean beforePlant, @Nullable Particle particle, @Nullable Sound sound, String icon, Requirement[] requirements) { + super(key, fertilizerType, times, 1, pot_whitelist, beforePlant, particle, sound, icon, requirements); this.pairs = pairs; } diff --git a/src/main/java/net/momirealms/customcrops/api/object/fertilizer/Variation.java b/src/main/java/net/momirealms/customcrops/api/object/fertilizer/Variation.java index 1837efa..5454a96 100644 --- a/src/main/java/net/momirealms/customcrops/api/object/fertilizer/Variation.java +++ b/src/main/java/net/momirealms/customcrops/api/object/fertilizer/Variation.java @@ -18,6 +18,7 @@ package net.momirealms.customcrops.api.object.fertilizer; import net.kyori.adventure.sound.Sound; +import net.momirealms.customcrops.api.object.requirement.Requirement; import org.bukkit.Particle; import org.jetbrains.annotations.Nullable; @@ -25,7 +26,7 @@ public class Variation extends FertilizerConfig { public Variation(String key, FertilizerType fertilizerType, int times, double chance, @Nullable String[] pot_whitelist, boolean beforePlant, - @Nullable Particle particle, @Nullable Sound sound, String icon) { - super(key, fertilizerType, times, chance, pot_whitelist, beforePlant, particle, sound, icon); + @Nullable Particle particle, @Nullable Sound sound, String icon, Requirement[] requirements) { + super(key, fertilizerType, times, chance, pot_whitelist, beforePlant, particle, sound, icon, requirements); } } diff --git a/src/main/java/net/momirealms/customcrops/api/object/fertilizer/YieldIncrease.java b/src/main/java/net/momirealms/customcrops/api/object/fertilizer/YieldIncrease.java index 8a46b8d..3b93575 100644 --- a/src/main/java/net/momirealms/customcrops/api/object/fertilizer/YieldIncrease.java +++ b/src/main/java/net/momirealms/customcrops/api/object/fertilizer/YieldIncrease.java @@ -19,6 +19,7 @@ package net.momirealms.customcrops.api.object.fertilizer; import net.kyori.adventure.sound.Sound; import net.momirealms.customcrops.api.object.Pair; +import net.momirealms.customcrops.api.object.requirement.Requirement; import org.bukkit.Particle; import org.jetbrains.annotations.Nullable; @@ -30,8 +31,8 @@ public class YieldIncrease extends FertilizerConfig { public YieldIncrease(String key, FertilizerType fertilizerType, int times, double chance, List> pairs, @Nullable String[] pot_whitelist, boolean beforePlant, - @Nullable Particle particle, @Nullable Sound sound, String icon) { - super(key, fertilizerType, times, chance, pot_whitelist, beforePlant, particle, sound, icon); + @Nullable Particle particle, @Nullable Sound sound, String icon, Requirement[] requirements) { + super(key, fertilizerType, times, chance, pot_whitelist, beforePlant, particle, sound, icon, requirements); this.pairs = pairs; } diff --git a/src/main/java/net/momirealms/customcrops/api/object/requirement/AbstractRequirement.java b/src/main/java/net/momirealms/customcrops/api/object/requirement/AbstractRequirement.java index caacc0a..173ea44 100644 --- a/src/main/java/net/momirealms/customcrops/api/object/requirement/AbstractRequirement.java +++ b/src/main/java/net/momirealms/customcrops/api/object/requirement/AbstractRequirement.java @@ -17,6 +17,8 @@ package net.momirealms.customcrops.api.object.requirement; +import net.momirealms.customcrops.api.object.action.Action; +import net.momirealms.customcrops.api.object.world.SimpleLocation; import net.momirealms.customcrops.api.util.AdventureUtils; import org.bukkit.entity.Player; import org.jetbrains.annotations.Nullable; @@ -24,16 +26,24 @@ import org.jetbrains.annotations.Nullable; public abstract class AbstractRequirement { protected String[] msg; + protected Action[] actions; - protected AbstractRequirement(@Nullable String[] msg) { + protected AbstractRequirement(@Nullable String[] msg, @Nullable Action[] actions) { this.msg = msg; + this.actions = actions; } - public void notMetMessage(Player player) { + public void notMetMessage(CurrentState currentState) { + Player player = currentState.getPlayer(); if (msg != null && player != null) { for (String str : msg) { AdventureUtils.playerMessage(player, str); } } + if (actions != null) { + for (Action action : actions) { + action.doOn(player, SimpleLocation.getByBukkitLocation(currentState.getLocation()), null); + } + } } } diff --git a/src/main/java/net/momirealms/customcrops/api/object/requirement/BiomeImpl.java b/src/main/java/net/momirealms/customcrops/api/object/requirement/BiomeImpl.java index 0a72cbb..7876be5 100644 --- a/src/main/java/net/momirealms/customcrops/api/object/requirement/BiomeImpl.java +++ b/src/main/java/net/momirealms/customcrops/api/object/requirement/BiomeImpl.java @@ -18,6 +18,7 @@ package net.momirealms.customcrops.api.object.requirement; import net.momirealms.biomeapi.BiomeAPI; +import net.momirealms.customcrops.api.object.action.Action; import org.jetbrains.annotations.Nullable; import java.util.HashSet; @@ -26,8 +27,8 @@ public class BiomeImpl extends AbstractRequirement implements Requirement { private final HashSet biomes; - public BiomeImpl(@Nullable String[] msg, HashSet biomes) { - super(msg); + public BiomeImpl(@Nullable String[] msg, @Nullable Action[] actions, HashSet biomes) { + super(msg, actions); this.biomes = biomes; } @@ -37,7 +38,7 @@ public class BiomeImpl extends AbstractRequirement implements Requirement { if (biomes.contains(currentBiome)) { return true; } - notMetMessage(currentState.getPlayer()); + notMetMessage(currentState); return false; } } diff --git a/src/main/java/net/momirealms/customcrops/api/object/requirement/CurrentState.java b/src/main/java/net/momirealms/customcrops/api/object/requirement/CurrentState.java index 1034116..f99382d 100644 --- a/src/main/java/net/momirealms/customcrops/api/object/requirement/CurrentState.java +++ b/src/main/java/net/momirealms/customcrops/api/object/requirement/CurrentState.java @@ -25,8 +25,8 @@ public class CurrentState { private final Location location; private final Player player; - public CurrentState(Location crop_loc, Player player) { - this.location = crop_loc; + public CurrentState(Location location, Player player) { + this.location = location; this.player = player; } diff --git a/src/main/java/net/momirealms/customcrops/api/object/requirement/CustomPapi.java b/src/main/java/net/momirealms/customcrops/api/object/requirement/CustomPapi.java index 7d3878e..77e5ee0 100644 --- a/src/main/java/net/momirealms/customcrops/api/object/requirement/CustomPapi.java +++ b/src/main/java/net/momirealms/customcrops/api/object/requirement/CustomPapi.java @@ -17,9 +17,11 @@ package net.momirealms.customcrops.api.object.requirement; +import net.momirealms.customcrops.api.object.action.Action; import net.momirealms.customcrops.api.object.requirement.papi.*; import org.bukkit.configuration.MemorySection; import org.bukkit.entity.Player; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.List; @@ -29,8 +31,8 @@ public class CustomPapi extends AbstractRequirement implements Requirement { private final List papiRequirement; - public CustomPapi(String[] msg, Map expressions){ - super(msg); + public CustomPapi(String[] msg, @Nullable Action[] actions, Map expressions){ + super(msg, actions); papiRequirement = getRequirements(expressions); } @@ -40,7 +42,7 @@ public class CustomPapi extends AbstractRequirement implements Requirement { if (currentState.getPlayer() == null) return true; for (PapiRequirement requirement : papiRequirement) { if (!requirement.isMet(player)) { - notMetMessage(player); + notMetMessage(currentState); return false; } } diff --git a/src/main/java/net/momirealms/customcrops/api/object/requirement/DateImpl.java b/src/main/java/net/momirealms/customcrops/api/object/requirement/DateImpl.java index a65e339..7dd592f 100644 --- a/src/main/java/net/momirealms/customcrops/api/object/requirement/DateImpl.java +++ b/src/main/java/net/momirealms/customcrops/api/object/requirement/DateImpl.java @@ -17,6 +17,9 @@ package net.momirealms.customcrops.api.object.requirement; +import net.momirealms.customcrops.api.object.action.Action; +import org.jetbrains.annotations.Nullable; + import java.util.Calendar; import java.util.HashSet; @@ -24,8 +27,8 @@ public class DateImpl extends AbstractRequirement implements Requirement { private final HashSet dates; - public DateImpl(String[] msg, HashSet dates) { - super(msg); + public DateImpl(String[] msg, @Nullable Action[] actions, HashSet dates) { + super(msg, actions); this.dates = dates; } @@ -36,7 +39,7 @@ public class DateImpl extends AbstractRequirement implements Requirement { if (dates.contains(current)) { return true; } - notMetMessage(currentState.getPlayer()); + notMetMessage(currentState); return false; } } diff --git a/src/main/java/net/momirealms/customcrops/api/object/requirement/JobLevelImpl.java b/src/main/java/net/momirealms/customcrops/api/object/requirement/JobLevelImpl.java index 0edb2c1..7942d2e 100644 --- a/src/main/java/net/momirealms/customcrops/api/object/requirement/JobLevelImpl.java +++ b/src/main/java/net/momirealms/customcrops/api/object/requirement/JobLevelImpl.java @@ -18,6 +18,7 @@ package net.momirealms.customcrops.api.object.requirement; import net.momirealms.customcrops.CustomCrops; +import net.momirealms.customcrops.api.object.action.Action; import net.momirealms.customcrops.integration.JobInterface; import org.jetbrains.annotations.Nullable; @@ -26,8 +27,8 @@ public class JobLevelImpl extends AbstractRequirement implements Requirement { private final int level; private final String jobName; - public JobLevelImpl(@Nullable String[] msg, int level, String jobName) { - super(msg); + public JobLevelImpl(@Nullable String[] msg, @Nullable Action[] actions, int level, String jobName) { + super(msg, actions); this.level = level; this.jobName = jobName; } @@ -39,7 +40,7 @@ public class JobLevelImpl extends AbstractRequirement implements Requirement { if (jobInterface.getLevel(currentState.getPlayer(), jobName) >= level) { return true; } - notMetMessage(currentState.getPlayer()); + notMetMessage(currentState); return false; } } diff --git a/src/main/java/net/momirealms/customcrops/api/object/requirement/PermissionImpl.java b/src/main/java/net/momirealms/customcrops/api/object/requirement/PermissionImpl.java index 576b4d3..23c0818 100644 --- a/src/main/java/net/momirealms/customcrops/api/object/requirement/PermissionImpl.java +++ b/src/main/java/net/momirealms/customcrops/api/object/requirement/PermissionImpl.java @@ -17,14 +17,15 @@ package net.momirealms.customcrops.api.object.requirement; +import net.momirealms.customcrops.api.object.action.Action; import org.jetbrains.annotations.Nullable; public class PermissionImpl extends AbstractRequirement implements Requirement { private final String permission; - public PermissionImpl(@Nullable String[] msg, String permission) { - super(msg); + public PermissionImpl(@Nullable String[] msg, @Nullable Action[] actions, String permission) { + super(msg, actions); this.permission = permission; } @@ -37,7 +38,7 @@ public class PermissionImpl extends AbstractRequirement implements Requirement { if (currentState.getPlayer() == null || currentState.getPlayer().hasPermission(permission)) { return true; } - notMetMessage(currentState.getPlayer()); + notMetMessage(currentState); return false; } } \ No newline at end of file diff --git a/src/main/java/net/momirealms/customcrops/api/object/requirement/SeasonImpl.java b/src/main/java/net/momirealms/customcrops/api/object/requirement/SeasonImpl.java index c8f4e61..5615cd1 100644 --- a/src/main/java/net/momirealms/customcrops/api/object/requirement/SeasonImpl.java +++ b/src/main/java/net/momirealms/customcrops/api/object/requirement/SeasonImpl.java @@ -18,6 +18,7 @@ package net.momirealms.customcrops.api.object.requirement; import net.momirealms.customcrops.CustomCrops; +import net.momirealms.customcrops.api.object.action.Action; import net.momirealms.customcrops.api.object.basic.ConfigManager; import net.momirealms.customcrops.api.object.season.CCSeason; import net.momirealms.customcrops.api.object.world.SimpleLocation; @@ -31,8 +32,8 @@ public class SeasonImpl extends AbstractRequirement implements Requirement { private final List seasons; - public SeasonImpl(@Nullable String[] msg, List seasons) { - super(msg); + public SeasonImpl(@Nullable String[] msg, @Nullable Action[] actions, List seasons) { + super(msg, actions); this.seasons = seasons; } @@ -53,7 +54,7 @@ public class SeasonImpl extends AbstractRequirement implements Requirement { } } } - notMetMessage(currentState.getPlayer()); + notMetMessage(currentState); return false; } } \ No newline at end of file diff --git a/src/main/java/net/momirealms/customcrops/api/object/requirement/SkillLevelImpl.java b/src/main/java/net/momirealms/customcrops/api/object/requirement/SkillLevelImpl.java index 068fde2..f367fbe 100644 --- a/src/main/java/net/momirealms/customcrops/api/object/requirement/SkillLevelImpl.java +++ b/src/main/java/net/momirealms/customcrops/api/object/requirement/SkillLevelImpl.java @@ -18,6 +18,7 @@ package net.momirealms.customcrops.api.object.requirement; import net.momirealms.customcrops.CustomCrops; +import net.momirealms.customcrops.api.object.action.Action; import net.momirealms.customcrops.integration.SkillInterface; import org.jetbrains.annotations.Nullable; @@ -25,8 +26,8 @@ public class SkillLevelImpl extends AbstractRequirement implements Requirement { private final int level; - public SkillLevelImpl(@Nullable String[] msg, int level) { - super(msg); + public SkillLevelImpl(@Nullable String[] msg, @Nullable Action[] actions, int level) { + super(msg, actions); this.level = level; } @@ -37,7 +38,7 @@ public class SkillLevelImpl extends AbstractRequirement implements Requirement { if (skillInterface.getLevel(currentState.getPlayer()) >= level) { return true; } - notMetMessage(currentState.getPlayer()); + notMetMessage(currentState); return false; } } diff --git a/src/main/java/net/momirealms/customcrops/api/object/requirement/TimeImpl.java b/src/main/java/net/momirealms/customcrops/api/object/requirement/TimeImpl.java index e9ddd38..e35e422 100644 --- a/src/main/java/net/momirealms/customcrops/api/object/requirement/TimeImpl.java +++ b/src/main/java/net/momirealms/customcrops/api/object/requirement/TimeImpl.java @@ -17,6 +17,7 @@ package net.momirealms.customcrops.api.object.requirement; +import net.momirealms.customcrops.api.object.action.Action; import org.jetbrains.annotations.Nullable; import java.util.List; @@ -25,8 +26,8 @@ public class TimeImpl extends AbstractRequirement implements Requirement { private final List times; - public TimeImpl(@Nullable String[] msg, List times) { - super(msg); + public TimeImpl(@Nullable String[] msg, @Nullable Action[] actions, List times) { + super(msg, actions); this.times = times; } @@ -39,7 +40,7 @@ public class TimeImpl extends AbstractRequirement implements Requirement { return true; } } - notMetMessage(currentState.getPlayer()); + notMetMessage(currentState); return false; } } diff --git a/src/main/java/net/momirealms/customcrops/api/object/requirement/WeatherImpl.java b/src/main/java/net/momirealms/customcrops/api/object/requirement/WeatherImpl.java index d18252c..2764de4 100644 --- a/src/main/java/net/momirealms/customcrops/api/object/requirement/WeatherImpl.java +++ b/src/main/java/net/momirealms/customcrops/api/object/requirement/WeatherImpl.java @@ -17,6 +17,7 @@ package net.momirealms.customcrops.api.object.requirement; +import net.momirealms.customcrops.api.object.action.Action; import org.bukkit.World; import org.jetbrains.annotations.Nullable; @@ -24,8 +25,8 @@ public class WeatherImpl extends AbstractRequirement implements Requirement { private final String[] weathers; - public WeatherImpl(@Nullable String[] msg, String[] weathers) { - super(msg); + public WeatherImpl(@Nullable String[] msg, @Nullable Action[] actions, String[] weathers) { + super(msg, actions); this.weathers = weathers; } @@ -41,7 +42,7 @@ public class WeatherImpl extends AbstractRequirement implements Requirement { return true; } } - notMetMessage(currentState.getPlayer()); + notMetMessage(currentState); return false; } } diff --git a/src/main/java/net/momirealms/customcrops/api/object/requirement/WorldImpl.java b/src/main/java/net/momirealms/customcrops/api/object/requirement/WorldImpl.java index 06899f8..cf78f1a 100644 --- a/src/main/java/net/momirealms/customcrops/api/object/requirement/WorldImpl.java +++ b/src/main/java/net/momirealms/customcrops/api/object/requirement/WorldImpl.java @@ -17,6 +17,7 @@ package net.momirealms.customcrops.api.object.requirement; +import net.momirealms.customcrops.api.object.action.Action; import org.bukkit.World; import org.jetbrains.annotations.Nullable; @@ -26,8 +27,8 @@ public class WorldImpl extends AbstractRequirement implements Requirement { private final List worlds; - public WorldImpl(@Nullable String[] msg, List worlds) { - super(msg); + public WorldImpl(@Nullable String[] msg, @Nullable Action[] actions, List worlds) { + super(msg, actions); this.worlds = worlds; } @@ -37,7 +38,7 @@ public class WorldImpl extends AbstractRequirement implements Requirement { if (worlds.contains(world.getName())) { return true; } - notMetMessage(currentState.getPlayer()); + notMetMessage(currentState); return false; } } \ No newline at end of file diff --git a/src/main/java/net/momirealms/customcrops/api/object/requirement/YPosImpl.java b/src/main/java/net/momirealms/customcrops/api/object/requirement/YPosImpl.java index e92cefd..0a6975d 100644 --- a/src/main/java/net/momirealms/customcrops/api/object/requirement/YPosImpl.java +++ b/src/main/java/net/momirealms/customcrops/api/object/requirement/YPosImpl.java @@ -17,6 +17,7 @@ package net.momirealms.customcrops.api.object.requirement; +import net.momirealms.customcrops.api.object.action.Action; import org.jetbrains.annotations.Nullable; import java.util.List; @@ -25,8 +26,8 @@ public class YPosImpl extends AbstractRequirement implements Requirement { private final List yPos; - public YPosImpl(@Nullable String[] msg, List yPos) { - super(msg); + public YPosImpl(@Nullable String[] msg, @Nullable Action[] actions, List yPos) { + super(msg, actions); this.yPos = yPos; } @@ -39,7 +40,7 @@ public class YPosImpl extends AbstractRequirement implements Requirement { return true; } } - notMetMessage(currentState.getPlayer()); + notMetMessage(currentState); return false; } } \ No newline at end of file diff --git a/src/main/java/net/momirealms/customcrops/api/util/ConfigUtils.java b/src/main/java/net/momirealms/customcrops/api/util/ConfigUtils.java index 6f7442a..4d75dee 100644 --- a/src/main/java/net/momirealms/customcrops/api/util/ConfigUtils.java +++ b/src/main/java/net/momirealms/customcrops/api/util/ConfigUtils.java @@ -51,6 +51,7 @@ import org.bukkit.configuration.MemorySection; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; +import org.checkerframework.checker.units.qual.N; import org.intellij.lang.annotations.Subst; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -205,21 +206,22 @@ public class ConfigUtils { String type = innerSec.getString("type"); if (type == null) continue; String[] msg = innerSec.getStringList("message").size() == 0 ? (innerSec.getString("message") == null ? null : new String[]{innerSec.getString("message")}) : innerSec.getStringList("message").toArray(new String[0]); + ConfigurationSection actionSec = innerSec.getConfigurationSection("actions"); switch (type) { - case "biome" -> requirements.add(new BiomeImpl(msg, new HashSet<>(innerSec.getStringList("value")))); - case "weather" -> requirements.add(new WeatherImpl(msg, innerSec.getStringList("value").toArray(new String[0]))); - case "ypos" -> requirements.add(new YPosImpl(msg, innerSec.getStringList("value"))); + case "biome" -> requirements.add(new BiomeImpl(msg, getActions(actionSec), new HashSet<>(innerSec.getStringList("value")))); + case "weather" -> requirements.add(new WeatherImpl(msg, getActions(actionSec), innerSec.getStringList("value").toArray(new String[0]))); + case "ypos" -> requirements.add(new YPosImpl(msg, getActions(actionSec), innerSec.getStringList("value"))); case "season" -> { if (!ConfigManager.enableSeason) continue; - requirements.add(new SeasonImpl(msg, innerSec.getStringList("value").stream().map(str -> CCSeason.valueOf(str.toUpperCase(Locale.ENGLISH))).collect(Collectors.toList()))); + requirements.add(new SeasonImpl(msg, getActions(actionSec), innerSec.getStringList("value").stream().map(str -> CCSeason.valueOf(str.toUpperCase(Locale.ENGLISH))).collect(Collectors.toList()))); } - case "world" -> requirements.add(new WorldImpl(msg, innerSec.getStringList("value"))); - case "permission" -> requirements.add(new PermissionImpl(msg, innerSec.getString("value"))); - case "time" -> requirements.add(new TimeImpl(msg, innerSec.getStringList("value"))); - case "skill-level" -> requirements.add(new SkillLevelImpl(msg, innerSec.getInt("value"))); - case "job-level" -> requirements.add(new JobLevelImpl(msg, innerSec.getInt("value.level"), innerSec.getString("value.job"))); - case "date" -> requirements.add(new DateImpl(msg, new HashSet<>(innerSec.getStringList("value")))); - case "papi-condition" -> requirements.add(new CustomPapi(msg, Objects.requireNonNull(innerSec.getConfigurationSection("value")).getValues(false))); + case "world" -> requirements.add(new WorldImpl(msg, getActions(actionSec), innerSec.getStringList("value"))); + case "permission" -> requirements.add(new PermissionImpl(msg, getActions(actionSec), innerSec.getString("value"))); + case "time" -> requirements.add(new TimeImpl(msg, getActions(actionSec), innerSec.getStringList("value"))); + case "skill-level" -> requirements.add(new SkillLevelImpl(msg, getActions(actionSec), innerSec.getInt("value"))); + case "job-level" -> requirements.add(new JobLevelImpl(msg, getActions(actionSec), innerSec.getInt("value.level"), innerSec.getString("value.job"))); + case "date" -> requirements.add(new DateImpl(msg, getActions(actionSec), new HashSet<>(innerSec.getStringList("value")))); + case "papi-condition" -> requirements.add(new CustomPapi(msg, getActions(actionSec), Objects.requireNonNull(innerSec.getConfigurationSection("value")).getValues(false))); } } return requirements.toArray(new Requirement[0]); @@ -227,6 +229,11 @@ public class ConfigUtils { return null; } + @Nullable + public static Action[] getActions(ConfigurationSection section) { + return getActions(section, null); + } + @Nullable public static Action[] getActions(ConfigurationSection section, String model_id) { if (section != null) {