2023-09-10 21:58:50 +00:00
|
|
|
package com.alttd.fishingevent.config;
|
|
|
|
|
|
|
|
|
|
import com.alttd.fishingevent.FishingEvent;
|
|
|
|
|
import com.alttd.fishingevent.fish.Fish;
|
|
|
|
|
import com.alttd.fishingevent.fish.LavaFish;
|
|
|
|
|
import com.alttd.fishingevent.fish.WaterFish;
|
|
|
|
|
import com.alttd.fishingevent.objects.Rarity;
|
|
|
|
|
import com.alttd.fishingevent.util.FishConfigHelper;
|
|
|
|
|
import com.alttd.fishingevent.util.Logger;
|
|
|
|
|
import org.bukkit.configuration.ConfigurationSection;
|
|
|
|
|
import org.bukkit.inventory.ItemStack;
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Optional;
|
|
|
|
|
|
|
|
|
|
public class Fishes extends AbstractConfig {
|
|
|
|
|
|
|
|
|
|
static Fishes config;
|
|
|
|
|
private final Logger logger;
|
2023-09-21 23:33:36 +00:00
|
|
|
private final FishingEvent fishingEvent;
|
2023-09-10 21:58:50 +00:00
|
|
|
|
|
|
|
|
Fishes(FishingEvent fishingEvent, Logger logger) {
|
|
|
|
|
super(fishingEvent, "fishes.yml", logger);
|
2023-09-21 23:33:36 +00:00
|
|
|
this.fishingEvent = fishingEvent;
|
2023-09-10 21:58:50 +00:00
|
|
|
this.logger = logger;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void reload(FishingEvent fishingEvent, Logger logger) {
|
|
|
|
|
logger.debug("Reloading config [fishes.yml]");
|
|
|
|
|
config = new Fishes(fishingEvent, logger);
|
|
|
|
|
config.readConfig(Fishes.class, null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static class FORMAT {
|
|
|
|
|
private static final String prefix = "format.";
|
|
|
|
|
|
|
|
|
|
public static String DISPLAY_NAME = "<gold><fish_name></gold>";
|
|
|
|
|
public static List<String> LORE = List.of(
|
|
|
|
|
"<gray>Length: <gold><length></gold>cm</gray>",
|
|
|
|
|
"<gray>Caught by: <player></gray>"
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings("unused")
|
|
|
|
|
private static void load() {
|
|
|
|
|
DISPLAY_NAME = config.getString(prefix, "display-name", DISPLAY_NAME);
|
|
|
|
|
LORE = config.getStringList(prefix, "lore", LORE);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static class LAVA_FISH {
|
|
|
|
|
|
|
|
|
|
public static List<Fish> FISH = new ArrayList<>();
|
|
|
|
|
public static HashMap<Rarity, List<Fish>> RARITY_FISH_MAP = new HashMap<>();
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings("unused")
|
|
|
|
|
private static void load() {
|
|
|
|
|
FISH.clear();
|
|
|
|
|
ConfigurationSection configurationSection = config.getConfigurationSection("lava-fish");
|
|
|
|
|
if (configurationSection == null) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
for (String key : configurationSection.getKeys(false)) {
|
|
|
|
|
ConfigurationSection fishSection = configurationSection.getConfigurationSection(key);
|
|
|
|
|
if (fishSection == null) {
|
|
|
|
|
config.logger.warning("Invalid lava fish section: " + configurationSection.getCurrentPath() + "." + key);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
loadLavaFish(fishSection);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void loadLavaFish(ConfigurationSection fishSection) {
|
|
|
|
|
Optional<Rarity> rarity = FishConfigHelper.getRarity(config.logger, fishSection);
|
|
|
|
|
if (rarity.isEmpty())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
Optional<ItemStack> optionalItemStack = FishConfigHelper.loadFishItem(config.logger, fishSection);
|
|
|
|
|
if (optionalItemStack.isEmpty()) {
|
|
|
|
|
config.logger.warning("Invalid lava fish item for " + fishSection.getCurrentPath());
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FISH.add(new LavaFish(
|
2023-09-21 23:46:14 +00:00
|
|
|
config.fishingEvent,
|
|
|
|
|
config.logger,
|
2023-09-10 21:58:50 +00:00
|
|
|
(float) fishSection.getDouble("min-length", 0),
|
|
|
|
|
(float) fishSection.getDouble("max-length", 0),
|
|
|
|
|
fishSection.getString("fish-name", "default name"),
|
|
|
|
|
rarity.get(),
|
|
|
|
|
optionalItemStack.get(),
|
|
|
|
|
null) //TODO implement particles or make them hardcoded
|
|
|
|
|
);
|
|
|
|
|
for (Fish fish : FISH) {
|
|
|
|
|
RARITY_FISH_MAP.computeIfAbsent(fish.getRarity(), list -> new ArrayList<>()).add(fish);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static class WATER_FISH {
|
|
|
|
|
|
|
|
|
|
public static List<Fish> FISH = new ArrayList<>();
|
|
|
|
|
public static HashMap<Rarity, List<Fish>> RARITY_FISH_MAP = new HashMap<>();
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings("unused")
|
|
|
|
|
private static void load() {
|
|
|
|
|
FISH.clear();
|
|
|
|
|
RARITY_FISH_MAP.clear();
|
|
|
|
|
ConfigurationSection configurationSection = config.getConfigurationSection("water-fish");
|
|
|
|
|
if (configurationSection == null) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
for (String key : configurationSection.getKeys(false)) {
|
|
|
|
|
ConfigurationSection fishSection = configurationSection.getConfigurationSection(key);
|
|
|
|
|
if (fishSection == null) {
|
|
|
|
|
config.logger.warning("Invalid water fish section: " + configurationSection.getCurrentPath() + "." + key);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
loadWaterFish(fishSection);
|
|
|
|
|
}
|
|
|
|
|
for (Fish fish : FISH) {
|
|
|
|
|
config.logger.debug("Adding fish [%] with rarity [%]", fish.normalFishName(), fish.getRarity().toString());
|
|
|
|
|
RARITY_FISH_MAP.computeIfAbsent(fish.getRarity(), list -> new ArrayList<>()).add(fish);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void loadWaterFish(ConfigurationSection fishSection) {
|
|
|
|
|
Optional<Rarity> rarity = FishConfigHelper.getRarity(config.logger, fishSection);
|
|
|
|
|
if (rarity.isEmpty())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
Optional<ItemStack> optionalItemStack = FishConfigHelper.loadFishItem(config.logger, fishSection);
|
|
|
|
|
if (optionalItemStack.isEmpty()) {
|
|
|
|
|
config.logger.warning("Invalid water fish item for " + fishSection.getCurrentPath());
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FISH.add(new WaterFish(
|
2023-09-21 23:33:36 +00:00
|
|
|
config.fishingEvent,
|
|
|
|
|
config.logger,
|
2023-09-10 21:58:50 +00:00
|
|
|
(float) fishSection.getDouble("min-length", 0),
|
|
|
|
|
(float) fishSection.getDouble("max-length", 0),
|
|
|
|
|
fishSection.getString("fish-name", "default name"),
|
|
|
|
|
rarity.get(),
|
|
|
|
|
optionalItemStack.get())
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|