diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/GlobalSettings.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/GlobalSettings.java index 2b2e35b0..0192b1d9 100644 --- a/api/src/main/java/net/momirealms/customfishing/api/mechanic/GlobalSettings.java +++ b/api/src/main/java/net/momirealms/customfishing/api/mechanic/GlobalSettings.java @@ -21,6 +21,7 @@ import net.momirealms.customfishing.api.CustomFishingPlugin; import net.momirealms.customfishing.api.mechanic.action.Action; import net.momirealms.customfishing.api.mechanic.action.ActionTrigger; import net.momirealms.customfishing.api.mechanic.condition.Condition; +import net.momirealms.customfishing.api.mechanic.effect.EffectModifier; import org.bukkit.configuration.ConfigurationSection; import java.util.HashMap; @@ -31,17 +32,18 @@ import java.util.Map; */ public class GlobalSettings { - public static HashMap lootActions = new HashMap<>(); - public static HashMap rodActions = new HashMap<>(); - public static HashMap baitActions = new HashMap<>(); - public static HashMap hookActions = new HashMap<>(); + private static HashMap lootActions = new HashMap<>(); + private static HashMap rodActions = new HashMap<>(); + private static HashMap baitActions = new HashMap<>(); + private static HashMap hookActions = new HashMap<>(); + private static EffectModifier[] effectModifiers; /** * Loads global settings from a configuration section. * * @param section The configuration section to load settings from. */ - public static void load(ConfigurationSection section) { + public static void loadEvents(ConfigurationSection section) { if (section == null) return; for (Map.Entry entry : section.getValues(false).entrySet()) { if (entry.getValue() instanceof ConfigurationSection inner) { @@ -56,6 +58,14 @@ public class GlobalSettings { } } + public static EffectModifier[] getEffectModifiers() { + return effectModifiers; + } + + public static void setEffects(EffectModifier[] modifiers) { + effectModifiers = modifiers; + } + /** * Unloads global settings, clearing all action maps. */ diff --git a/api/src/main/java/net/momirealms/customfishing/api/mechanic/condition/FishingPreparation.java b/api/src/main/java/net/momirealms/customfishing/api/mechanic/condition/FishingPreparation.java index 646abdef..12bf065d 100644 --- a/api/src/main/java/net/momirealms/customfishing/api/mechanic/condition/FishingPreparation.java +++ b/api/src/main/java/net/momirealms/customfishing/api/mechanic/condition/FishingPreparation.java @@ -162,6 +162,9 @@ public class FishingPreparation extends Condition { * @param effect The FishingEffect to merge into this rod. */ public void mergeEffect(FishingEffect effect) { + for (EffectModifier modifier : GlobalSettings.getEffectModifiers()) { + modifier.modify(effect, this); + } for (EffectCarrier effectCarrier : effects) { for (EffectModifier modifier : effectCarrier.getEffectModifiers()) { modifier.modify(effect, this); diff --git a/plugin/build.gradle.kts b/plugin/build.gradle.kts index 15084041..e1b12925 100644 --- a/plugin/build.gradle.kts +++ b/plugin/build.gradle.kts @@ -34,7 +34,7 @@ dependencies { compileOnly("com.h2database:h2:2.2.224") compileOnly("org.mongodb:mongodb-driver-sync:4.11.1") compileOnly("com.zaxxer:HikariCP:5.0.1") - compileOnly("redis.clients:jedis:5.0.2") + compileOnly("redis.clients:jedis:5.1.0") // others compileOnly("com.github.LoneDev6:api-itemsadder:3.5.0c-r5") @@ -80,7 +80,6 @@ tasks { relocate ("de.tr7zw.changeme", "net.momirealms.customfishing.libraries") relocate ("de.tr7zw.annotations", "net.momirealms.customfishing.libraries.annotations") relocate ("net.kyori", "net.momirealms.customfishing.libraries") - relocate ("net.wesjd", "net.momirealms.customfishing.libraries") relocate ("org.bstats", "net.momirealms.customfishing.libraries.bstats") relocate ("net.momirealms.biomeapi", "net.momirealms.customfishing.libraries.biomeapi") } diff --git a/plugin/src/main/java/net/momirealms/customfishing/CustomFishingPluginImpl.java b/plugin/src/main/java/net/momirealms/customfishing/CustomFishingPluginImpl.java index e6461daa..cc5cf9be 100644 --- a/plugin/src/main/java/net/momirealms/customfishing/CustomFishingPluginImpl.java +++ b/plugin/src/main/java/net/momirealms/customfishing/CustomFishingPluginImpl.java @@ -206,7 +206,7 @@ public class CustomFishingPluginImpl extends CustomFishingPlugin { "https://maven.aliyun.com/repository/public/" : "https://repo.maven.apache.org/maven2/"; LibraryLoader.loadDependencies( "org.apache.commons:commons-pool2:2.12.0", mavenRepo, - "redis.clients:jedis:5.0.2", mavenRepo, + "redis.clients:jedis:5.1.0", mavenRepo, "dev.dejvokep:boosted-yaml:1.3.1", mavenRepo, "com.zaxxer:HikariCP:5.0.1", mavenRepo, "net.objecthunter:exp4j:0.4.8", mavenRepo, diff --git a/plugin/src/main/java/net/momirealms/customfishing/mechanic/action/ActionManagerImpl.java b/plugin/src/main/java/net/momirealms/customfishing/mechanic/action/ActionManagerImpl.java index a7edddb9..ae795e34 100644 --- a/plugin/src/main/java/net/momirealms/customfishing/mechanic/action/ActionManagerImpl.java +++ b/plugin/src/main/java/net/momirealms/customfishing/mechanic/action/ActionManagerImpl.java @@ -115,7 +115,7 @@ public class ActionManagerImpl implements ActionManager { // Method to load global event actions from the plugin's configuration file. private void loadGlobalEventActions() { YamlConfiguration config = plugin.getConfig("config.yml"); - GlobalSettings.load(config.getConfigurationSection("mechanics.global-events")); + GlobalSettings.loadEvents(config.getConfigurationSection("mechanics.global-events")); } /** diff --git a/plugin/src/main/java/net/momirealms/customfishing/mechanic/effect/EffectManagerImpl.java b/plugin/src/main/java/net/momirealms/customfishing/mechanic/effect/EffectManagerImpl.java index e8b62e13..a724d6b0 100644 --- a/plugin/src/main/java/net/momirealms/customfishing/mechanic/effect/EffectManagerImpl.java +++ b/plugin/src/main/java/net/momirealms/customfishing/mechanic/effect/EffectManagerImpl.java @@ -21,6 +21,7 @@ import net.momirealms.customfishing.api.CustomFishingPlugin; import net.momirealms.customfishing.api.common.Key; import net.momirealms.customfishing.api.common.Pair; import net.momirealms.customfishing.api.manager.EffectManager; +import net.momirealms.customfishing.api.mechanic.GlobalSettings; import net.momirealms.customfishing.api.mechanic.effect.EffectCarrier; import net.momirealms.customfishing.api.mechanic.effect.EffectModifier; import net.momirealms.customfishing.api.mechanic.effect.FishingEffect; @@ -101,13 +102,18 @@ public class EffectManagerImpl implements EffectManager { return effectMap.get(Key.of(namespace, id)); } + public void load() { + this.loadFiles(); + this.loadGlobalEffects(); + } + /** * Loads EffectCarrier configurations from YAML files in different content folders. * EffectCarrier configurations are organized by type (rod, bait, enchant, util, totem, hook) in separate folders. * Each YAML file within these folders is processed to populate the effectMap. */ @SuppressWarnings("DuplicatedCode") - public void load() { + private void loadFiles() { Deque fileDeque = new ArrayDeque<>(); for (String type : List.of("rod", "bait", "enchant", "util", "totem", "hook")) { File typeFolder = new File(plugin.getDataFolder() + File.separator + "contents" + File.separator + type); @@ -234,6 +240,12 @@ public class EffectManagerImpl implements EffectManager { return modifiers.toArray(new EffectModifier[0]); } + private void loadGlobalEffects() { + YamlConfiguration config = plugin.getConfig("config.yml"); + ConfigurationSection section = config.getConfigurationSection("mechanics.global-effects"); + GlobalSettings.setEffects(getEffectModifiers(section)); + } + /** * Parses a ConfigurationSection to create an EffectModifier based on the specified type and configuration. * diff --git a/plugin/src/main/java/net/momirealms/customfishing/mechanic/fishing/HookCheckTimerTask.java b/plugin/src/main/java/net/momirealms/customfishing/mechanic/fishing/HookCheckTimerTask.java index 0f593aa4..780a0851 100644 --- a/plugin/src/main/java/net/momirealms/customfishing/mechanic/fishing/HookCheckTimerTask.java +++ b/plugin/src/main/java/net/momirealms/customfishing/mechanic/fishing/HookCheckTimerTask.java @@ -297,8 +297,8 @@ public class HookCheckTimerTask implements Runnable { double initialTime = ThreadLocalRandom.current().nextInt(CFConfig.waterMaxTime - CFConfig.waterMinTime + 1) + CFConfig.waterMinTime; fishHook.setWaitTime(Math.max(1, (int) (initialTime * initialEffect.getWaitTimeMultiplier() + initialEffect.getWaitTime()))); } else { - fishHook.setMaxWaitTime(Math.max(2, (int) (fishHook.getMaxWaitTime() * initialEffect.getWaitTimeMultiplier() + initialEffect.getWaitTime()))); fishHook.setMinWaitTime(Math.max(1, (int) (fishHook.getMinWaitTime() * initialEffect.getWaitTimeMultiplier() + initialEffect.getWaitTime()))); + fishHook.setMaxWaitTime(Math.max(2, (int) (fishHook.getMaxWaitTime() * initialEffect.getWaitTimeMultiplier() + initialEffect.getWaitTime()))); } } } diff --git a/plugin/src/main/java/net/momirealms/customfishing/mechanic/loot/LootManagerImpl.java b/plugin/src/main/java/net/momirealms/customfishing/mechanic/loot/LootManagerImpl.java index 83ca2ca2..46810533 100644 --- a/plugin/src/main/java/net/momirealms/customfishing/mechanic/loot/LootManagerImpl.java +++ b/plugin/src/main/java/net/momirealms/customfishing/mechanic/loot/LootManagerImpl.java @@ -175,7 +175,6 @@ public class LootManagerImpl implements LootManager { @Override public Map getPossibleLootKeysWithWeight(Effect initialEffect, Condition condition) { Map lootWithWeight = ((RequirementManagerImpl) plugin.getRequirementManager()).getLootWithWeight(condition); - Player player = condition.getPlayer(); for (Pair pair : initialEffect.getWeightModifier()) { Double previous = lootWithWeight.get(pair.left()); diff --git a/plugin/src/main/java/net/momirealms/customfishing/mechanic/requirement/RequirementManagerImpl.java b/plugin/src/main/java/net/momirealms/customfishing/mechanic/requirement/RequirementManagerImpl.java index 2150d519..cc19fb60 100644 --- a/plugin/src/main/java/net/momirealms/customfishing/mechanic/requirement/RequirementManagerImpl.java +++ b/plugin/src/main/java/net/momirealms/customfishing/mechanic/requirement/RequirementManagerImpl.java @@ -198,6 +198,7 @@ public class RequirementManagerImpl implements RequirementManager { this.registerHookRequirement(); this.registerCompetitionRequirement(); this.registerListRequirement(); + this.registerEnvironmentRequirement(); } public HashMap getLootWithWeight(Condition condition) { @@ -1018,6 +1019,27 @@ public class RequirementManagerImpl implements RequirementManager { }); } + private void registerEnvironmentRequirement() { + registerRequirement("environment", (args, actions, advanced) -> { + List environments = ConfigUtils.stringListArgs(args); + return condition -> { + var name = condition.getLocation().getWorld().getEnvironment().name().toLowerCase(Locale.ENGLISH); + if (environments.contains(name)) return true; + if (advanced) triggerActions(actions, condition); + return false; + }; + }); + registerRequirement("!environment", (args, actions, advanced) -> { + List environments = ConfigUtils.stringListArgs(args); + return condition -> { + var name = condition.getLocation().getWorld().getEnvironment().name().toLowerCase(Locale.ENGLISH); + if (!environments.contains(name)) return true; + if (advanced) triggerActions(actions, condition); + return false; + }; + }); + } + private void registerHookRequirement() { registerRequirement("hook", (args, actions, advanced) -> { List hooks = ConfigUtils.stringListArgs(args); diff --git a/plugin/src/main/java/net/momirealms/customfishing/setting/CFConfig.java b/plugin/src/main/java/net/momirealms/customfishing/setting/CFConfig.java index 8d9cdacc..90b65806 100644 --- a/plugin/src/main/java/net/momirealms/customfishing/setting/CFConfig.java +++ b/plugin/src/main/java/net/momirealms/customfishing/setting/CFConfig.java @@ -40,7 +40,7 @@ import java.util.Objects; public class CFConfig { // config version - public static String configVersion = "29"; + public static String configVersion = "30"; // Debug mode public static boolean debug; // language @@ -114,6 +114,7 @@ public class CFConfig { .setVersioning(new BasicVersioning("config-version")) .addIgnoredRoute(configVersion, "mechanics.mechanic-requirements", '.') .addIgnoredRoute(configVersion, "mechanics.global-events", '.') + .addIgnoredRoute(configVersion, "mechanics.global-effects", '.') .addIgnoredRoute(configVersion, "other-settings.placeholder-register", '.') .build() ); @@ -165,7 +166,6 @@ public class CFConfig { durabilityLore = config.getStringList("other-settings.custom-durability-format").stream().map(it -> "" + it).toList(); - OffsetUtils.loadConfig(config.getConfigurationSection("other-settings.offset-characters")); } } diff --git a/plugin/src/main/resources/config.yml b/plugin/src/main/resources/config.yml index ed579977..464ef7ca 100644 --- a/plugin/src/main/resources/config.yml +++ b/plugin/src/main/resources/config.yml @@ -1,6 +1,6 @@ # Developer: @Xiao-MoMi # Wiki: https://mo-mi.gitbook.io/xiaomomi-plugins/ -config-version: '29' +config-version: '30' # Debug debug: false @@ -26,6 +26,20 @@ mechanics: value: - blacklist_world + # Configures global effects. This is useful if you want to give all the players certain effects based on certain conditions + global-effects: + effect_1: + type: conditional + conditions: + competition: + ongoing: true + id: + - weekend_competition + effects: + effect_1: + type: wait-time-multiplier + value: 0.85 + # Configures global events for hook/bait/rod/loot # which would help you reduce duplicated lines global-events: diff --git a/plugin/src/main/resources/contents/bait/default.yml b/plugin/src/main/resources/contents/bait/default.yml index b2419fe7..482643f5 100644 --- a/plugin/src/main/resources/contents/bait/default.yml +++ b/plugin/src/main/resources/contents/bait/default.yml @@ -36,7 +36,7 @@ simple_bait: - '' custom-model-data: 50001 effects: - difficulty: + effect_1: type: difficulty value: -10 @@ -59,10 +59,10 @@ magnetic_bait: - '' custom-model-data: 50002 effects: - hooktime: + effect_1: type: wait-time-multiplier value: 0.9 - gametime: + effect_2: type: game-time value: 2 @@ -84,12 +84,12 @@ wild_bait: - '' custom-model-data: 50003 effects: - difficulty: + effect_1: type: difficulty value: +20 - size: + effect_2: type: size-multiplier value: 1.5 - gametime: + effect_3: type: game-time value: -2 \ No newline at end of file diff --git a/plugin/src/main/resources/contents/enchant/default.yml b/plugin/src/main/resources/contents/enchant/default.yml index a2ae5b63..d41bf12e 100644 --- a/plugin/src/main/resources/contents/enchant/default.yml +++ b/plugin/src/main/resources/contents/enchant/default.yml @@ -9,7 +9,7 @@ minecraft:luck_of_the_sea:1: requirements: {} effects: - group: + effect_1: type: group-mod value: - silver_star:+2 @@ -17,7 +17,7 @@ minecraft:luck_of_the_sea:1: minecraft:luck_of_the_sea:2: requirements: {} effects: - group: + effect_1: type: group-mod value: - silver_star:+4 @@ -25,7 +25,7 @@ minecraft:luck_of_the_sea:2: minecraft:luck_of_the_sea:3: requirements: {} effects: - group: + effect_1: type: group-mod value: - silver_star:+6 diff --git a/plugin/src/main/resources/contents/hook/default.yml b/plugin/src/main/resources/contents/hook/default.yml index 9558274a..65f467c9 100644 --- a/plugin/src/main/resources/contents/hook/default.yml +++ b/plugin/src/main/resources/contents/hook/default.yml @@ -26,7 +26,7 @@ delicate_hook: - '<#7FFFAA>Equipped hook:' - ' - Delicate hook: {dur} times left' effects: - group: + effect_1: type: group-mod value: - silver_star:+1 diff --git a/plugin/src/main/resources/contents/rod/default.yml b/plugin/src/main/resources/contents/rod/default.yml index 163a75ec..27c9c8fa 100644 --- a/plugin/src/main/resources/contents/rod/default.yml +++ b/plugin/src/main/resources/contents/rod/default.yml @@ -9,7 +9,7 @@ FISHING_ROD: tag: false material: fishing_rod effects: - time_effect: + effect_1: type: wait-time-multiplier value: 1.5 @@ -31,10 +31,10 @@ beginner_rod: custom-model-data: 50001 max-durability: 64 effects: - time_effect: + effect_1: type: wait-time-multiplier value: 1.8 - difficulty: + effect_2: type: difficulty value: -8 @@ -54,7 +54,7 @@ silver_rod: custom-model-data: 50002 max-durability: 96 effects: - group: + effect_1: type: group-mod value: - silver_star:+8 @@ -75,7 +75,7 @@ golden_rod: custom-model-data: 50003 max-durability: 80 effects: - group: + effect_1: type: group-mod value: - golden_star:+3 @@ -98,7 +98,7 @@ star_rod: custom-model-data: 50004 max-durability: 128 effects: - time_effect: + effect_1: type: game-time value: 15 @@ -122,7 +122,7 @@ bone_rod: custom-model-data: 50005 max-durability: 32 effects: - lava: + effect_1: type: lava-fishing magical_rod: @@ -152,7 +152,7 @@ magical_rod: type: level value: 10 not-met-actions: - action_message: + action_1: type: message value: - 'You don''t have enough levels to control the rod.' @@ -171,11 +171,11 @@ magical_rod: type: level value: -10 effects: - weight_effect: + effect_1: type: group-mod-ignore-conditions value: - enchantments:+10 - time_effect: + effect_2: type: wait-time-multiplier value: 3 @@ -199,13 +199,13 @@ master_rod: custom-model-data: 50007 max-durability: 128 effects: - time_effect: + effect_1: type: wait-time-multiplier value: 0.95 - difficulty: + effect_2: type: difficulty value: +10 - group: + effect_3: type: group-mod value: - silver_star:+5 diff --git a/plugin/src/main/resources/contents/totem/default.yml b/plugin/src/main/resources/contents/totem/default.yml index 5818bfbd..fdd7fd25 100644 --- a/plugin/src/main/resources/contents/totem/default.yml +++ b/plugin/src/main/resources/contents/totem/default.yml @@ -13,7 +13,7 @@ double_loot_totem: 1: - 'AIR||GRASS||SNOW ANVIL AIR||GRASS||SNOW' effects: - double_loot: + effect_1: type: multiple-loot value: 1.0 requirements: @@ -242,7 +242,7 @@ golden_star_totem: period: 5 delay: 0 effects: - golden_weight_increase: + effect_1: type: group-mod value: - golden_star:+15 diff --git a/plugin/src/main/resources/effect-conditions.yml b/plugin/src/main/resources/effect-conditions.yml deleted file mode 100644 index e69de29b..00000000 diff --git a/plugin/src/main/resources/loot-conditions.yml b/plugin/src/main/resources/loot-conditions.yml index 38485358..0ef65229 100644 --- a/plugin/src/main/resources/loot-conditions.yml +++ b/plugin/src/main/resources/loot-conditions.yml @@ -6,8 +6,8 @@ global-group: loots_in_water: conditions: lava-fishing: false - world: - - world + environment: + - normal '!rod': - magical_rod list: @@ -115,8 +115,8 @@ global-group: - 'sturgeon_fish:+9' - 'sturgeon_fish_silver_star:+3' - 'sturgeon_fish_golden_star:+1' - # Skeletons might appear if player holds the skeleton_rod and fish at night - curse_rod: + # Skeletons might appear if player holds the bone_rod and fish at night + skeleton_group: conditions: rod: - bone_rod @@ -129,10 +129,10 @@ global-group: lava-fishing: true list: [] sub-groups: - overworld_loots: + world_loots: conditions: - world: - - world + environment: + - normal list: - 'cobblestone:+50' - 'stone:+30' @@ -141,8 +141,8 @@ global-group: - 'flint:+6' nether_loots: conditions: - world: - - world_nether + environment: + - nether list: - 'netherrack:+20' - 'nether_brick:+12' @@ -154,11 +154,9 @@ global-group: - 'salmon_void_fish_silver_star:+3' - 'salmon_void_fish_golden_star:+1' sub-groups: - curse_rod: + skeleton_group: conditions: rod: - bone_rod - time: - - 14000~22000 list: - 'wither_skeleton:+30' \ No newline at end of file