mirror of
https://github.com/Xiao-MoMi/Custom-Fishing.git
synced 2025-12-29 11:59:11 +00:00
1.3.0.1
This commit is contained in:
@@ -24,11 +24,20 @@ import dev.dejvokep.boostedyaml.settings.general.GeneralSettings;
|
||||
import dev.dejvokep.boostedyaml.settings.loader.LoaderSettings;
|
||||
import dev.dejvokep.boostedyaml.settings.updater.UpdaterSettings;
|
||||
import net.momirealms.customfishing.CustomFishing;
|
||||
import net.momirealms.customfishing.fishing.Effect;
|
||||
import net.momirealms.customfishing.fishing.action.*;
|
||||
import net.momirealms.customfishing.fishing.requirements.*;
|
||||
import net.momirealms.customfishing.helper.Log;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class ConfigUtil {
|
||||
@@ -73,4 +82,116 @@ public class ConfigUtil {
|
||||
}
|
||||
return YamlConfiguration.loadConfiguration(file);
|
||||
}
|
||||
|
||||
public static RequirementInterface[] getRequirements(ConfigurationSection section) {
|
||||
if (section != null) {
|
||||
List<RequirementInterface> requirements = new ArrayList<>();
|
||||
for (String type : section.getKeys(false)) {
|
||||
switch (type) {
|
||||
case "biome" -> requirements.add(new BiomeImpl(null, section.getStringList(type)));
|
||||
case "weather" -> requirements.add(new WeatherImpl(null, section.getStringList(type)));
|
||||
case "ypos" -> requirements.add(new YPosImpl(null, section.getStringList(type)));
|
||||
case "season" -> requirements.add(new SeasonImpl(null, section.getStringList(type)));
|
||||
case "world" -> requirements.add(new WorldImpl(null, section.getStringList(type)));
|
||||
case "permission" -> requirements.add(new PermissionImpl(null, section.getString(type)));
|
||||
case "time" -> requirements.add(new TimeImpl(null, section.getStringList(type)));
|
||||
case "skill-level" -> requirements.add(new SkillLevelImpl(null, section.getInt(type)));
|
||||
case "job-level" -> requirements.add(new JobLevelImpl(null, section.getInt(type)));
|
||||
case "papi-condition" -> requirements.add(new CustomPapi(null, Objects.requireNonNull(section.getConfigurationSection(type)).getValues(false)));
|
||||
}
|
||||
}
|
||||
return requirements.toArray(new RequirementInterface[0]);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static RequirementInterface[] getRequirementsWithMsg(ConfigurationSection section) {
|
||||
if (section != null) {
|
||||
List<RequirementInterface> requirements = new ArrayList<>();
|
||||
for (String id : section.getKeys(false)) {
|
||||
ConfigurationSection innerSec = section.getConfigurationSection(id);
|
||||
if (innerSec == null) continue;
|
||||
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]);
|
||||
switch (type) {
|
||||
case "biome" -> requirements.add(new BiomeImpl(msg, innerSec.getStringList("value")));
|
||||
case "weather" -> requirements.add(new WeatherImpl(msg, innerSec.getStringList("value")));
|
||||
case "ypos" -> requirements.add(new YPosImpl(msg, innerSec.getStringList("value")));
|
||||
case "season" -> requirements.add(new SeasonImpl(msg, innerSec.getStringList("value")));
|
||||
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")));
|
||||
case "papi-condition" -> requirements.add(new CustomPapi(msg, Objects.requireNonNull(innerSec.getConfigurationSection("value")).getValues(false)));
|
||||
}
|
||||
}
|
||||
return requirements.toArray(new RequirementInterface[0]);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Action[] getActions(ConfigurationSection section, String nick) {
|
||||
if (section != null) {
|
||||
List<Action> actions = new ArrayList<>();
|
||||
for (String action : section.getKeys(false)) {
|
||||
switch (action) {
|
||||
case "message" -> actions.add(new MessageActionImpl(section.getStringList(action).toArray(new String[0]), nick));
|
||||
case "command" -> actions.add(new CommandActionImpl(section.getStringList(action).toArray(new String[0]), nick));
|
||||
case "exp" -> actions.add(new VanillaXPImpl(section.getInt(action), false));
|
||||
case "mending" -> actions.add(new VanillaXPImpl(section.getInt(action), true));
|
||||
case "skill-xp" -> actions.add(new SkillXPImpl(section.getDouble(action)));
|
||||
case "job-xp" -> actions.add(new JobXPImpl(section.getDouble(action)));
|
||||
case "sound" -> actions.add(new SoundActionImpl(
|
||||
section.getString(action + ".source"),
|
||||
section.getString(action + ".key"),
|
||||
(float) section.getDouble(action + ".volume"),
|
||||
(float) section.getDouble(action + ".pitch")
|
||||
));
|
||||
case "potion-effect" -> {
|
||||
List<PotionEffect> potionEffectList = new ArrayList<>();
|
||||
for (String key : section.getConfigurationSection(action).getKeys(false)) {
|
||||
PotionEffectType type = PotionEffectType.getByName(section.getString(action + "." + key + ".type", "BLINDNESS").toUpperCase());
|
||||
if (type == null) AdventureUtil.consoleMessage("<red>[CustomFishing] Potion effect " + section.getString(action + "." + key + ".type", "BLINDNESS") + " doesn't exists");
|
||||
potionEffectList.add(new PotionEffect(
|
||||
type == null ? PotionEffectType.LUCK : type,
|
||||
section.getInt(action + "." + key + ".duration"),
|
||||
section.getInt(action + "." + key + ".amplifier")
|
||||
));
|
||||
}
|
||||
actions.add(new PotionEffectImpl(potionEffectList.toArray(new PotionEffect[0])));
|
||||
}
|
||||
}
|
||||
}
|
||||
return actions.toArray(new Action[0]);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Effect getEffect(ConfigurationSection section) {
|
||||
Effect effect = new Effect();
|
||||
if (section == null) return effect;
|
||||
for (String modifier : section.getKeys(false)) {
|
||||
switch (modifier) {
|
||||
case "weight-add" -> {
|
||||
HashMap<String, Integer> as = new HashMap<>();
|
||||
Objects.requireNonNull(section.getConfigurationSection(modifier)).getValues(false).forEach((group, value) -> as.put(group, (Integer) value));
|
||||
effect.setWeightAS(as);
|
||||
}
|
||||
case "weight-multiply" -> {
|
||||
HashMap<String, Double> md = new HashMap<>();
|
||||
Objects.requireNonNull(section.getConfigurationSection(modifier)).getValues(false).forEach((group, value) -> md.put(group, Double.parseDouble(String.valueOf(value))-1));
|
||||
effect.setWeightMD(md);
|
||||
}
|
||||
case "time" -> effect.setTimeModifier(section.getDouble(modifier));
|
||||
case "difficulty" -> effect.setDifficulty(section.getInt(modifier));
|
||||
case "double-loot" -> effect.setDoubleLootChance(section.getDouble(modifier));
|
||||
case "score" -> effect.setScoreMultiplier(section.getDouble(modifier));
|
||||
case "size-multiply" -> effect.setSizeMultiplier(section.getDouble(modifier));
|
||||
case "lava-fishing" -> effect.setCanLavaFishing(section.getBoolean(modifier, false));
|
||||
}
|
||||
}
|
||||
return effect;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user