2024-02-22 11:33:50 +01:00
|
|
|
package fr.maxlego08.koth.loader;
|
|
|
|
|
2024-02-22 14:31:23 +01:00
|
|
|
import fr.maxlego08.koth.KothPlugin;
|
2024-02-22 11:33:50 +01:00
|
|
|
import fr.maxlego08.koth.ZKoth;
|
|
|
|
import fr.maxlego08.koth.api.Koth;
|
2024-02-22 19:43:52 +01:00
|
|
|
import fr.maxlego08.koth.api.KothLootType;
|
2024-02-22 11:44:35 +01:00
|
|
|
import fr.maxlego08.koth.api.KothType;
|
2024-02-22 19:04:09 +01:00
|
|
|
import fr.maxlego08.koth.api.discord.DiscordWebhookConfig;
|
2024-02-22 18:20:24 +01:00
|
|
|
import fr.maxlego08.koth.api.utils.HologramConfig;
|
2024-02-22 12:00:18 +01:00
|
|
|
import fr.maxlego08.koth.api.utils.ScoreboardConfiguration;
|
2024-02-22 11:33:50 +01:00
|
|
|
import fr.maxlego08.koth.zcore.utils.ZUtils;
|
|
|
|
import fr.maxlego08.koth.zcore.utils.loader.Loader;
|
2024-02-22 19:43:52 +01:00
|
|
|
import fr.maxlego08.koth.zcore.utils.nms.ItemStackUtils;
|
2024-02-22 11:33:50 +01:00
|
|
|
import org.bukkit.Location;
|
|
|
|
import org.bukkit.configuration.file.YamlConfiguration;
|
2024-02-22 19:43:52 +01:00
|
|
|
import org.bukkit.inventory.ItemStack;
|
2024-02-22 11:33:50 +01:00
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
import java.util.List;
|
2024-02-22 19:43:52 +01:00
|
|
|
import java.util.stream.Collectors;
|
2024-02-22 11:33:50 +01:00
|
|
|
|
|
|
|
public class KothLoader extends ZUtils implements Loader<Koth> {
|
|
|
|
|
2024-02-22 14:31:23 +01:00
|
|
|
private final KothPlugin plugin;
|
2024-02-22 11:33:50 +01:00
|
|
|
private final Loader<Location> locationLoader = new LocationLoader();
|
2024-02-22 12:00:18 +01:00
|
|
|
private final Loader<ScoreboardConfiguration> scoreboardLoaderLoader = new ScoreboardLoader();
|
2024-02-22 18:20:24 +01:00
|
|
|
private final Loader<HologramConfig> hologramConfigLoader = new HologramLoader();
|
2024-02-22 11:33:50 +01:00
|
|
|
|
2024-02-22 14:31:23 +01:00
|
|
|
public KothLoader(KothPlugin plugin) {
|
|
|
|
this.plugin = plugin;
|
|
|
|
}
|
|
|
|
|
2024-02-22 11:33:50 +01:00
|
|
|
@Override
|
|
|
|
public Koth load(YamlConfiguration configuration, String path, File file) {
|
|
|
|
|
|
|
|
String fileName = getFileNameWithoutExtension(file);
|
2024-02-22 19:43:52 +01:00
|
|
|
KothType kothType;
|
|
|
|
try {
|
|
|
|
kothType = KothType.valueOf(configuration.getString("type", KothType.CAPTURE.name()).toUpperCase());
|
|
|
|
} catch (IllegalArgumentException ignored) {
|
|
|
|
kothType = KothType.CAPTURE;
|
|
|
|
}
|
|
|
|
|
2024-02-22 11:33:50 +01:00
|
|
|
String name = configuration.getString("name");
|
|
|
|
int captureSeconds = configuration.getInt("capture");
|
2024-02-22 14:31:23 +01:00
|
|
|
int cooldownStart = configuration.getInt("cooldownStart");
|
|
|
|
int stopAfterSeconds = configuration.getInt("stopAfterSeconds");
|
|
|
|
boolean enableStartCapMessage = configuration.getBoolean("enableStartCapMessage", true);
|
|
|
|
boolean enableLooseCapMessage = configuration.getBoolean("enableLooseCapMessage", true);
|
|
|
|
boolean enableEverySecondsCapMessage = configuration.getBoolean("enableEverySecondsCapMessage", false);
|
2024-02-22 11:33:50 +01:00
|
|
|
List<String> startCommands = configuration.getStringList("startCommands");
|
|
|
|
List<String> endCommands = configuration.getStringList("endCommands");
|
|
|
|
Location minLocation = locationLoader.load(configuration, "minLocation.", file);
|
2024-02-22 16:23:25 +01:00
|
|
|
Location maxLocation = locationLoader.load(configuration, "maxLocation.", file);
|
2024-02-22 12:00:18 +01:00
|
|
|
ScoreboardConfiguration cooldownScoreboard = scoreboardLoaderLoader.load(configuration, "scoreboard.cooldown.", file);
|
|
|
|
ScoreboardConfiguration startScoreboard = scoreboardLoaderLoader.load(configuration, "scoreboard.start.", file);
|
2024-02-22 18:20:24 +01:00
|
|
|
HologramConfig hologramConfig = hologramConfigLoader.load(configuration, "hologram.", file);
|
2024-02-22 11:33:50 +01:00
|
|
|
|
2024-02-22 19:04:09 +01:00
|
|
|
DiscordWebhookConfig discordWebhookConfig = new DiscordWebhookConfig(configuration);
|
|
|
|
|
2024-02-22 19:43:52 +01:00
|
|
|
KothLootType kothLootType;
|
|
|
|
try {
|
|
|
|
kothLootType = KothLootType.valueOf(configuration.getString("loot.type", KothLootType.NONE.name()).toUpperCase());
|
|
|
|
} catch (IllegalArgumentException ignored) {
|
|
|
|
kothLootType = KothLootType.NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
List<ItemStack> itemStacks = configuration.getStringList("loot.items").stream().map(ItemStackUtils::deserializeItemStack).collect(Collectors.toList());
|
2024-02-22 19:58:18 +01:00
|
|
|
int randomItemStacks = configuration.getInt("loot.random", 0);
|
2024-02-22 19:43:52 +01:00
|
|
|
|
2024-02-22 16:23:25 +01:00
|
|
|
return new ZKoth(this.plugin, fileName, kothType, name, captureSeconds, minLocation, maxLocation, startCommands, endCommands, cooldownScoreboard,
|
2024-02-22 19:58:18 +01:00
|
|
|
startScoreboard, cooldownStart, stopAfterSeconds, enableStartCapMessage, enableLooseCapMessage, enableEverySecondsCapMessage, hologramConfig, itemStacks, kothLootType, discordWebhookConfig, randomItemStacks);
|
2024-02-22 11:33:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2024-02-22 12:00:18 +01:00
|
|
|
public void save(Koth koth, YamlConfiguration configuration, String path) {
|
|
|
|
|
|
|
|
configuration.set("type", koth.getKothType().name());
|
|
|
|
configuration.set("name", koth.getName());
|
|
|
|
configuration.set("capture", koth.getCaptureSeconds());
|
2024-02-22 14:31:23 +01:00
|
|
|
configuration.set("cooldownStart", koth.getCooldownStart());
|
|
|
|
configuration.set("stopAfterSeconds", koth.getStopAfterSeconds());
|
2024-02-22 12:00:18 +01:00
|
|
|
configuration.set("startCommands", koth.getStartCommands());
|
|
|
|
configuration.set("endCommands", koth.getEndCommands());
|
2024-02-22 14:31:23 +01:00
|
|
|
configuration.set("enableStartCapMessage", koth.isEnableStartCapMessage());
|
|
|
|
configuration.set("enableLooseCapMessage", koth.isEnableLooseCapMessage());
|
|
|
|
configuration.set("enableEverySecondsCapMessage", koth.isEnableEverySecondsCapMessage());
|
2024-02-22 12:00:18 +01:00
|
|
|
locationLoader.save(koth.getMinLocation(), configuration, "minLocation.");
|
2024-02-22 16:23:25 +01:00
|
|
|
locationLoader.save(koth.getMaxLocation(), configuration, "maxLocation.");
|
2024-02-22 12:00:18 +01:00
|
|
|
scoreboardLoaderLoader.save(koth.getCooldownScoreboard(), configuration, "scoreboard.cooldown.");
|
|
|
|
scoreboardLoaderLoader.save(koth.getStartScoreboard(), configuration, "scoreboard.start.");
|
2024-02-22 18:20:24 +01:00
|
|
|
hologramConfigLoader.save(koth.getHologramConfig(), configuration, "hologram.");
|
2024-02-22 11:33:50 +01:00
|
|
|
|
2024-02-22 19:43:52 +01:00
|
|
|
configuration.set("loot.type", koth.getLootType().name());
|
2024-02-22 19:58:18 +01:00
|
|
|
configuration.set("loot.random", koth.getRandomItemStack());
|
2024-02-22 19:43:52 +01:00
|
|
|
List<String> items = koth.getItemStacks().stream().map(ItemStackUtils::serializeItemStack).collect(Collectors.toList());
|
|
|
|
configuration.set("loot.items", items);
|
|
|
|
|
2024-02-22 11:33:50 +01:00
|
|
|
}
|
|
|
|
}
|