From 0d4ae267f81c06929429bfb4f56b08f3cca1daa4 Mon Sep 17 00:00:00 2001 From: IanTapply22 Date: Wed, 19 Jun 2024 15:43:52 -0400 Subject: [PATCH] Finalize the initial changes to change configuration structure --- .../bloons/commands/CommandForceEquip.java | 10 +++++----- .../configuration/ConfigConfiguration.java | 19 ++++++++++--------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/main/java/net/jeqo/bloons/commands/CommandForceEquip.java b/src/main/java/net/jeqo/bloons/commands/CommandForceEquip.java index 26be2405..773fa410 100644 --- a/src/main/java/net/jeqo/bloons/commands/CommandForceEquip.java +++ b/src/main/java/net/jeqo/bloons/commands/CommandForceEquip.java @@ -5,6 +5,7 @@ import net.jeqo.bloons.balloon.multipart.balloon.MultipartBalloon; import net.jeqo.bloons.balloon.multipart.balloon.MultipartBalloonBuilder; import net.jeqo.bloons.balloon.single.SingleBalloon; +import net.jeqo.bloons.balloon.single.SingleBalloonType; import net.jeqo.bloons.commands.manager.Command; import net.jeqo.bloons.commands.manager.types.CommandPermission; import net.jeqo.bloons.configuration.ConfigConfiguration; @@ -48,7 +49,7 @@ public boolean execute(CommandSender sender, String[] args) { } String balloonID = args[1]; - if (!this.getPlugin().getConfig().contains(ConfigConfiguration.SINGLE_BALLOON_SECTION + balloonID) && !this.getPlugin().getConfig().contains(ConfigConfiguration.MULTIPART_BALLOON_SECTION + balloonID)) { + if (!Bloons.getBalloonCore().containsSingleBalloon(balloonID) && !Bloons.getBalloonCore().containsMultipartBalloon(balloonID)) { Component balloonNotFoundMessage = messageTranslations.getSerializedString(messageTranslations.getMessage("prefix"), messageTranslations.getMessage("balloon-not-found")); sender.sendMessage(balloonNotFoundMessage); return false; @@ -80,10 +81,10 @@ public boolean execute(CommandSender sender, String[] args) { MultipartBalloonManagement.setPlayerBalloon(player.getUniqueId(), balloon); - String balloonName = messageTranslations.getString(ConfigConfiguration.MULTIPART_BALLOON_SECTION + balloonID + ".name"); - Component equippedMessage = messageTranslations.getSerializedString(messageTranslations.getMessage("prefix"), messageTranslations.getMessage("equipped", balloonName)); + Component equippedMessage = messageTranslations.getSerializedString(messageTranslations.getMessage("prefix"), messageTranslations.getMessage("equipped", type.getName())); player.sendMessage(equippedMessage); } else { + SingleBalloonType singleBalloonType = Bloons.getBalloonCore().getSingleBalloonByID(balloonID); // Call the equip event and check if it's cancelled, if it is, don't spawn the balloon or do anything SingleBalloonEquipEvent singleBalloonEquipEvent = new SingleBalloonEquipEvent(player, balloonID); @@ -95,8 +96,7 @@ public boolean execute(CommandSender sender, String[] args) { SingleBalloonManagement.removeBalloon(player, Bloons.getPlayerSingleBalloons().get(player.getUniqueId())); SingleBalloon.checkBalloonRemovalOrAdd(player, balloonID); - String balloonName = messageTranslations.getString(ConfigConfiguration.SINGLE_BALLOON_SECTION + balloonID + ".name"); - Component equippedMessage = messageTranslations.getSerializedString(messageTranslations.getMessage("prefix"), messageTranslations.getMessage("equipped", balloonName)); + Component equippedMessage = messageTranslations.getSerializedString(messageTranslations.getMessage("prefix"), messageTranslations.getMessage("equipped", singleBalloonType.getName())); player.sendMessage(equippedMessage); } diff --git a/src/main/java/net/jeqo/bloons/configuration/ConfigConfiguration.java b/src/main/java/net/jeqo/bloons/configuration/ConfigConfiguration.java index 6f6e1d47..bd3fee15 100644 --- a/src/main/java/net/jeqo/bloons/configuration/ConfigConfiguration.java +++ b/src/main/java/net/jeqo/bloons/configuration/ConfigConfiguration.java @@ -46,18 +46,19 @@ public static ArrayList getSingleBalloons() { // For every file in the balloon configuration folder, if a configuration type is single, add it to an array list for (File file : Objects.requireNonNull(new File(Bloons.getInstance().getDataFolder() + File.separator + BALLOON_CONFIGURATION_FOLDER).listFiles())) { // For every section in the configuration file - for (String section : Objects.requireNonNull(Bloons.getInstance().getConfig().getConfigurationSection(file.getName())).getKeys(false)) { + for (String key : Objects.requireNonNull(Bloons.getInstance().getConfig().getConfigurationSection(file.getName())).getKeys(false)) { // If the section is a single balloon type, add it to the array list - if (section.equals(BalloonConfiguration.SINGLE_BALLOON_TYPE_IDENTIFIER)) { + if (key.equals(BalloonConfiguration.SINGLE_BALLOON_TYPE_IDENTIFIER)) { // Add the single balloon type to the array list singleBalloons.add(new SingleBalloonType( - Bloons.getInstance().getConfig().getString(file.getName() + "." + section + ".id"), - Bloons.getInstance().getConfig().getString(file.getName() + "." + section + ".permission"), - Bloons.getInstance().getConfig().getString(file.getName() + "." + section + ".material"), - Bloons.getInstance().getConfig().getString(file.getName() + "." + section + ".color"), - Bloons.getInstance().getConfig().getInt(file.getName() + "." + section + ".customModelData"), - Bloons.getInstance().getConfig().getString(file.getName() + "." + section + ".name"), - Bloons.getInstance().getConfig().getStringList(file.getName() + "." + section + ".lore").toArray(new String[0]) + key, + Bloons.getInstance().getConfig().getString(file.getName() + "." + key + ".id"), + Bloons.getInstance().getConfig().getString(file.getName() + "." + key + ".permission"), + Bloons.getInstance().getConfig().getString(file.getName() + "." + key + ".material"), + Bloons.getInstance().getConfig().getString(file.getName() + "." + key + ".color"), + Bloons.getInstance().getConfig().getInt(file.getName() + "." + key + ".customModelData"), + Bloons.getInstance().getConfig().getString(file.getName() + "." + key + ".name"), + Bloons.getInstance().getConfig().getStringList(file.getName() + "." + key + ".lore").toArray(new String[0]) )); } }