diff --git a/buildSrc/src/main/kotlin/java-plugin.gradle.kts b/buildSrc/src/main/kotlin/java-plugin.gradle.kts index 7f0f291d0..5adc9062a 100644 --- a/buildSrc/src/main/kotlin/java-plugin.gradle.kts +++ b/buildSrc/src/main/kotlin/java-plugin.gradle.kts @@ -15,7 +15,7 @@ repositories { maven("https://repo.oraxen.com/releases") - maven(Repository.CrazyCrewReleases.url) + maven(Repository.CrazyCrewSnapshots.url) maven(Repository.Jitpack.url) diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index a4413138c..09523c0e5 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/src/main/java/com/badbones69/crazycrates/CrazyCrates.java b/src/main/java/com/badbones69/crazycrates/CrazyCrates.java index cf4b69982..0c4a2a50c 100644 --- a/src/main/java/com/badbones69/crazycrates/CrazyCrates.java +++ b/src/main/java/com/badbones69/crazycrates/CrazyCrates.java @@ -7,6 +7,8 @@ import com.badbones69.crazycrates.api.objects.other.Server; import com.badbones69.crazycrates.api.utils.MiscUtils; import com.badbones69.crazycrates.commands.CommandManager; +import com.badbones69.crazycrates.config.ConfigManager; +import com.badbones69.crazycrates.config.impl.ConfigKeys; import com.badbones69.crazycrates.listeners.BrokeLocationsListener; import com.badbones69.crazycrates.listeners.CrateControlListener; import com.badbones69.crazycrates.listeners.MiscListener; @@ -22,19 +24,20 @@ import com.badbones69.crazycrates.tasks.BukkitUserManager; import com.badbones69.crazycrates.tasks.InventoryManager; import com.badbones69.crazycrates.tasks.crates.CrateManager; +import com.ryderbelserion.vital.paper.Vital; import com.ryderbelserion.vital.paper.api.enums.Support; -import com.ryderbelserion.vital.paper.files.config.FileManager; import com.ryderbelserion.vital.paper.util.AdvUtil; import me.arcaniax.hdb.api.HeadDatabaseAPI; import org.bukkit.plugin.java.JavaPlugin; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.io.File; import java.util.List; import java.util.Locale; import java.util.Timer; import static com.badbones69.crazycrates.api.utils.MiscUtils.registerPermissions; -public class CrazyCrates extends JavaPlugin { +public class CrazyCrates extends Vital { public static CrazyCrates getPlugin() { return JavaPlugin.getPlugin(CrazyCrates.class); @@ -53,18 +56,16 @@ public CrazyCrates() { private InventoryManager inventoryManager; private BukkitUserManager userManager; private CrateManager crateManager; - private FileManager fileManager; private HeadDatabaseAPI api; private Server instance; @Override public void onEnable() { - this.instance = new Server(this, getDataFolder()); + this.instance = new Server(getDataFolder()); this.instance.apply(); - this.fileManager = new FileManager(); - this.fileManager.addFile("locations.yml").addFile("data.yml") + getFileManager().addFile(new File(getDataFolder(), "locations.yml")).addFile(new File(getDataFolder(),"data.yml")) .addFolder("crates") .addFolder("schematics") .init(); @@ -115,6 +116,12 @@ public void onEnable() { new MiscListener() ).forEach(listener -> getServer().getPluginManager().registerEvents(listener, this)); + if (Support.placeholder_api.isEnabled()) { + if (MiscUtils.isLogging()) getComponentLogger().info("PlaceholderAPI support is enabled!"); + + new PlaceholderAPISupport().register(); + } + if (MiscUtils.isLogging()) { // Print dependency garbage for (final Support value : Support.values()) { @@ -124,15 +131,7 @@ public void onEnable() { getComponentLogger().info(AdvUtil.parse("" + value.getName() + " NOT FOUND")); } } - } - - if (Support.placeholder_api.isEnabled()) { - if (MiscUtils.isLogging()) getComponentLogger().info("PlaceholderAPI support is enabled!"); - new PlaceholderAPISupport().register(); - } - - if (MiscUtils.isLogging()) { getComponentLogger().info("You can disable logging by going to the plugin-config.yml and setting verbose to false."); getComponentLogger().info("Done ({})!", String.format(Locale.ROOT, "%.3fs", (double) (System.nanoTime() - this.startTime) / 1.0E9D)); @@ -176,10 +175,6 @@ public void onDisable() { return this.crateManager; } - public @NotNull final FileManager getFileManager() { - return this.fileManager; - } - public @Nullable final HeadDatabaseAPI getApi() { if (this.api == null) { return null; @@ -195,4 +190,9 @@ public void onDisable() { public @NotNull final Timer getTimer() { return this.timer; } + + @Override + public final boolean isLegacy() { + return !ConfigManager.getConfig().getProperty(ConfigKeys.minimessage_toggle); + } } \ No newline at end of file diff --git a/src/main/java/com/badbones69/crazycrates/api/builders/CrateBuilder.java b/src/main/java/com/badbones69/crazycrates/api/builders/CrateBuilder.java index f823a60cd..2e7660c9e 100644 --- a/src/main/java/com/badbones69/crazycrates/api/builders/CrateBuilder.java +++ b/src/main/java/com/badbones69/crazycrates/api/builders/CrateBuilder.java @@ -4,7 +4,6 @@ import com.badbones69.crazycrates.api.objects.Crate; import com.badbones69.crazycrates.api.objects.Tier; import com.badbones69.crazycrates.tasks.crates.CrateManager; -import com.badbones69.crazycrates.api.builders.ItemBuilder; import com.ryderbelserion.vital.paper.util.scheduler.FoliaRunnable; import com.badbones69.crazycrates.tasks.crates.effects.SoundEffect; import com.google.common.base.Preconditions; @@ -12,12 +11,12 @@ import net.kyori.adventure.sound.Sound; import org.bukkit.Location; import org.bukkit.Material; -import org.bukkit.configuration.ConfigurationSection; -import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; +import org.simpleyaml.configuration.ConfigurationSection; +import org.simpleyaml.configuration.file.YamlConfiguration; import us.crazycrew.crazycrates.api.enums.types.CrateType; import us.crazycrew.crazycrates.api.enums.types.KeyType; import com.badbones69.crazycrates.CrazyCrates; @@ -252,7 +251,7 @@ public final boolean isCosmicCrate() { /** * @return file configuration of crate. */ - public FileConfiguration getFile() { + public YamlConfiguration getFile() { return this.crate.getFile(); } diff --git a/src/main/java/com/badbones69/crazycrates/api/builders/types/CrateMainMenu.java b/src/main/java/com/badbones69/crazycrates/api/builders/types/CrateMainMenu.java index 0a7017ec4..76125b687 100644 --- a/src/main/java/com/badbones69/crazycrates/api/builders/types/CrateMainMenu.java +++ b/src/main/java/com/badbones69/crazycrates/api/builders/types/CrateMainMenu.java @@ -13,8 +13,6 @@ import net.kyori.adventure.sound.Sound; import org.bukkit.Location; import org.bukkit.Material; -import org.bukkit.configuration.ConfigurationSection; -import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.entity.Player; import org.bukkit.event.inventory.InventoryAction; import org.bukkit.event.inventory.InventoryClickEvent; @@ -24,6 +22,8 @@ import com.badbones69.crazycrates.config.ConfigManager; import com.badbones69.crazycrates.config.impl.ConfigKeys; import com.badbones69.crazycrates.api.builders.InventoryBuilder; +import org.simpleyaml.configuration.ConfigurationSection; +import org.simpleyaml.configuration.file.YamlConfiguration; import us.crazycrew.crazycrates.api.enums.types.KeyType; import java.text.NumberFormat; import java.util.List; @@ -106,7 +106,7 @@ public InventoryBuilder build() { } for (Crate crate : this.crateManager.getUsableCrates()) { - final FileConfiguration file = crate.getFile(); + final YamlConfiguration file = crate.getFile(); final ConfigurationSection section = file.getConfigurationSection("Crate"); diff --git a/src/main/java/com/badbones69/crazycrates/api/enums/Files.java b/src/main/java/com/badbones69/crazycrates/api/enums/Files.java index 296015e41..8cc31c77b 100644 --- a/src/main/java/com/badbones69/crazycrates/api/enums/Files.java +++ b/src/main/java/com/badbones69/crazycrates/api/enums/Files.java @@ -1,10 +1,10 @@ package com.badbones69.crazycrates.api.enums; import com.badbones69.crazycrates.CrazyCrates; -import com.ryderbelserion.vital.paper.files.config.FileManager; -import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.plugin.java.JavaPlugin; +import com.ryderbelserion.vital.common.managers.files.FileManager; import org.jetbrains.annotations.NotNull; +import org.simpleyaml.configuration.file.YamlConfiguration; +import java.io.File; public enum Files { @@ -27,11 +27,11 @@ public enum Files { } public final YamlConfiguration getConfiguration() { - return this.fileManager.getFile(this.fileName); + return this.fileManager.getFile(this.fileName).getConfiguration(); } public void reload() { - this.fileManager.reloadFile(this.fileName); + this.fileManager.addFile(new File(this.plugin.getDataFolder(), this.fileName)); } public void save() { diff --git a/src/main/java/com/badbones69/crazycrates/api/events/CrateOpenEvent.java b/src/main/java/com/badbones69/crazycrates/api/events/CrateOpenEvent.java index 76c44eb55..2ca902e2b 100644 --- a/src/main/java/com/badbones69/crazycrates/api/events/CrateOpenEvent.java +++ b/src/main/java/com/badbones69/crazycrates/api/events/CrateOpenEvent.java @@ -1,12 +1,12 @@ package com.badbones69.crazycrates.api.events; import com.badbones69.crazycrates.api.objects.Crate; -import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.entity.Player; import org.bukkit.event.Cancellable; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; import org.jetbrains.annotations.NotNull; +import org.simpleyaml.configuration.file.YamlConfiguration; import us.crazycrew.crazycrates.api.enums.types.KeyType; public class CrateOpenEvent extends Event implements Cancellable { @@ -15,11 +15,11 @@ public class CrateOpenEvent extends Event implements Cancellable { private final Crate crate; private final KeyType keyType; private final boolean checkHand; - private final FileConfiguration configuration; + private final YamlConfiguration configuration; private boolean isCancelled; - public CrateOpenEvent(@NotNull final Player player, @NotNull final Crate crate, @NotNull final KeyType keyType, final boolean checkHand, @NotNull final FileConfiguration configuration) { + public CrateOpenEvent(@NotNull final Player player, @NotNull final Crate crate, @NotNull final KeyType keyType, final boolean checkHand, @NotNull final YamlConfiguration configuration) { this.player = player; this.crate = crate; @@ -58,7 +58,7 @@ public final boolean isCheckHand() { return this.checkHand; } - public @NotNull final FileConfiguration getConfiguration() { + public @NotNull final YamlConfiguration getConfiguration() { return this.configuration; } diff --git a/src/main/java/com/badbones69/crazycrates/api/objects/Crate.java b/src/main/java/com/badbones69/crazycrates/api/objects/Crate.java index a427ba18d..6ad5fb152 100644 --- a/src/main/java/com/badbones69/crazycrates/api/objects/Crate.java +++ b/src/main/java/com/badbones69/crazycrates/api/objects/Crate.java @@ -9,19 +9,19 @@ import com.badbones69.crazycrates.tasks.crates.CrateManager; import com.badbones69.crazycrates.tasks.crates.effects.SoundEffect; import com.badbones69.crazycrates.api.builders.ItemBuilder; -import com.ryderbelserion.vital.paper.files.config.CustomFile; +import com.ryderbelserion.vital.common.managers.files.CustomFile; import com.ryderbelserion.vital.paper.util.DyeUtil; import com.ryderbelserion.vital.paper.util.ItemUtil; import net.kyori.adventure.sound.Sound; import org.bukkit.Color; import org.bukkit.Particle; -import org.bukkit.configuration.ConfigurationSection; -import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.enchantments.Enchantment; import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.persistence.PersistentDataContainer; import org.bukkit.persistence.PersistentDataType; import org.jetbrains.annotations.Nullable; +import org.simpleyaml.configuration.ConfigurationSection; +import org.simpleyaml.configuration.file.YamlConfiguration; import us.crazycrew.crazycrates.api.enums.types.CrateType; import com.badbones69.crazycrates.CrazyCrates; import com.badbones69.crazycrates.tasks.crates.other.CosmicCrateManager; @@ -64,7 +64,7 @@ public class Crate { private Particle particle; private final CrateType crateType; - private FileConfiguration file; + private YamlConfiguration file; private ArrayList prizes; private String crateName; private boolean giveNewPlayerKeys; @@ -104,7 +104,7 @@ public Crate(@NotNull final String name, @NotNull final ItemBuilder key, @NotNull final String keyName, @NotNull final ArrayList prizes, - @NotNull final FileConfiguration file, + @NotNull final YamlConfiguration file, final int newPlayerKeys, @NotNull final List tiers, final int maxMassOpen, @@ -539,7 +539,7 @@ public final CrateType getCrateType() { /** * @return the crates file. */ - public @NotNull final FileConfiguration getFile() { + public @NotNull final YamlConfiguration getFile() { return this.file; } @@ -745,7 +745,7 @@ private void setItem(@Nullable final ItemStack itemStack, @NotNull final String private void saveFile() { if (this.name.isEmpty()) return; - CustomFile customFile = this.plugin.getFileManager().getCustomFile(this.name); + CustomFile customFile = this.plugin.getFileManager().getFile(true, this.name); if (customFile != null) customFile.save(); diff --git a/src/main/java/com/badbones69/crazycrates/api/objects/Prize.java b/src/main/java/com/badbones69/crazycrates/api/objects/Prize.java index 563e8f401..499d3ca1d 100644 --- a/src/main/java/com/badbones69/crazycrates/api/objects/Prize.java +++ b/src/main/java/com/badbones69/crazycrates/api/objects/Prize.java @@ -14,12 +14,12 @@ import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer; import org.bukkit.ChatColor; import org.bukkit.Material; -import org.bukkit.configuration.ConfigurationSection; import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.simpleyaml.configuration.ConfigurationSection; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -68,6 +68,7 @@ public Prize(@NotNull final ConfigurationSection section, List editor this.prizeName = section.getString("DisplayName", ""); this.maxRange = section.getInt("MaxRange", 100); this.chance = section.getInt("Chance", 50); + this.firework = section.getBoolean("Firework", false); this.messages = section.getStringList("Messages"); // this returns an empty list if not found anyway. diff --git a/src/main/java/com/badbones69/crazycrates/api/objects/Tier.java b/src/main/java/com/badbones69/crazycrates/api/objects/Tier.java index b0242595d..61a3fe0a5 100644 --- a/src/main/java/com/badbones69/crazycrates/api/objects/Tier.java +++ b/src/main/java/com/badbones69/crazycrates/api/objects/Tier.java @@ -2,11 +2,11 @@ import com.badbones69.crazycrates.api.enums.PersistentKeys; import com.badbones69.crazycrates.api.builders.ItemBuilder; -import org.bukkit.configuration.ConfigurationSection; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.simpleyaml.configuration.ConfigurationSection; import java.util.List; public class Tier { diff --git a/src/main/java/com/badbones69/crazycrates/api/objects/other/Server.java b/src/main/java/com/badbones69/crazycrates/api/objects/other/Server.java index 3835daca8..8ec9b2884 100644 --- a/src/main/java/com/badbones69/crazycrates/api/objects/other/Server.java +++ b/src/main/java/com/badbones69/crazycrates/api/objects/other/Server.java @@ -1,8 +1,6 @@ package com.badbones69.crazycrates.api.objects.other; -import com.badbones69.crazycrates.config.impl.ConfigKeys; import com.ryderbelserion.vital.common.utils.FileUtil; -import com.ryderbelserion.vital.paper.VitalPaper; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; import us.crazycrew.crazycrates.CratesProvider; @@ -13,7 +11,7 @@ import java.io.File; import java.util.List; -public class Server extends VitalPaper implements IServer { +public class Server implements IServer { private final File directory; private final File crates; @@ -21,9 +19,7 @@ public class Server extends VitalPaper implements IServer { private UserManager userManager; private Options options; - public Server(@NotNull final JavaPlugin plugin, @NotNull final File directory) { - super(plugin); - + public Server(@NotNull final File directory) { this.directory = directory; this.crates = new File(this.directory, "crates"); @@ -104,14 +100,4 @@ public void reload() { public @NotNull final ISettings getSettings() { return this.options; } - - @Override - public final boolean isLegacy() { - return !ConfigManager.getConfig().getProperty(ConfigKeys.minimessage_toggle); - } - - @Override - public final boolean isVerbose() { - return ConfigManager.getConfig().getProperty(ConfigKeys.verbose_logging); - } } \ No newline at end of file diff --git a/src/main/java/com/badbones69/crazycrates/api/utils/ItemUtils.java b/src/main/java/com/badbones69/crazycrates/api/utils/ItemUtils.java index 96b1e6d5b..11cd3c720 100644 --- a/src/main/java/com/badbones69/crazycrates/api/utils/ItemUtils.java +++ b/src/main/java/com/badbones69/crazycrates/api/utils/ItemUtils.java @@ -11,7 +11,6 @@ import org.bukkit.DyeColor; import org.bukkit.Material; import org.bukkit.block.banner.PatternType; -import org.bukkit.configuration.ConfigurationSection; import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemFlag; @@ -19,6 +18,7 @@ import org.bukkit.persistence.PersistentDataContainer; import org.bukkit.persistence.PersistentDataType; import org.jetbrains.annotations.NotNull; +import org.simpleyaml.configuration.ConfigurationSection; import java.util.List; import java.util.Optional; import java.util.stream.Collectors; diff --git a/src/main/java/com/badbones69/crazycrates/commands/crates/types/BaseCommand.java b/src/main/java/com/badbones69/crazycrates/commands/crates/types/BaseCommand.java index ac1bad91f..1e4d075a9 100644 --- a/src/main/java/com/badbones69/crazycrates/commands/crates/types/BaseCommand.java +++ b/src/main/java/com/badbones69/crazycrates/commands/crates/types/BaseCommand.java @@ -5,12 +5,11 @@ import com.badbones69.crazycrates.api.enums.Messages; import com.badbones69.crazycrates.api.events.PlayerReceiveKeyEvent; import com.badbones69.crazycrates.api.objects.Crate; -import com.badbones69.crazycrates.api.objects.Prize; import com.badbones69.crazycrates.api.utils.MiscUtils; import com.badbones69.crazycrates.tasks.BukkitUserManager; import com.badbones69.crazycrates.tasks.InventoryManager; import com.badbones69.crazycrates.tasks.crates.CrateManager; -import com.ryderbelserion.vital.paper.files.config.FileManager; +import com.ryderbelserion.vital.common.managers.files.FileManager; import dev.triumphteam.cmd.core.annotations.Command; import org.bukkit.OfflinePlayer; import org.bukkit.command.CommandSender; diff --git a/src/main/java/com/badbones69/crazycrates/commands/crates/types/admin/CommandReload.java b/src/main/java/com/badbones69/crazycrates/commands/crates/types/admin/CommandReload.java index b4d019712..f49853648 100644 --- a/src/main/java/com/badbones69/crazycrates/commands/crates/types/admin/CommandReload.java +++ b/src/main/java/com/badbones69/crazycrates/commands/crates/types/admin/CommandReload.java @@ -6,9 +6,9 @@ import dev.triumphteam.cmd.bukkit.annotation.Permission; import dev.triumphteam.cmd.core.annotations.Command; import org.bukkit.command.CommandSender; -import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.permissions.PermissionDefault; import com.badbones69.crazycrates.config.impl.ConfigKeys; +import org.simpleyaml.configuration.file.YamlConfiguration; public class CommandReload extends BaseCommand { diff --git a/src/main/java/com/badbones69/crazycrates/commands/crates/types/admin/crates/CommandTeleport.java b/src/main/java/com/badbones69/crazycrates/commands/crates/types/admin/crates/CommandTeleport.java index 92c54407c..6eb00e16a 100644 --- a/src/main/java/com/badbones69/crazycrates/commands/crates/types/admin/crates/CommandTeleport.java +++ b/src/main/java/com/badbones69/crazycrates/commands/crates/types/admin/crates/CommandTeleport.java @@ -11,11 +11,11 @@ import dev.triumphteam.cmd.core.annotations.Suggestion; import org.bukkit.Location; import org.bukkit.World; -import org.bukkit.configuration.ConfigurationSection; -import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.Player; import org.bukkit.permissions.PermissionDefault; import org.jetbrains.annotations.NotNull; +import org.simpleyaml.configuration.ConfigurationSection; +import org.simpleyaml.configuration.file.YamlConfiguration; import java.util.Objects; public class CommandTeleport extends BaseCommand { diff --git a/src/main/java/com/badbones69/crazycrates/commands/crates/types/admin/crates/migrator/ICrateMigrator.java b/src/main/java/com/badbones69/crazycrates/commands/crates/types/admin/crates/migrator/ICrateMigrator.java index b8a5f58b4..ff8e09124 100644 --- a/src/main/java/com/badbones69/crazycrates/commands/crates/types/admin/crates/migrator/ICrateMigrator.java +++ b/src/main/java/com/badbones69/crazycrates/commands/crates/types/admin/crates/migrator/ICrateMigrator.java @@ -8,14 +8,14 @@ import com.badbones69.crazycrates.config.ConfigManager; import com.badbones69.crazycrates.config.impl.ConfigKeys; import com.badbones69.crazycrates.tasks.crates.CrateManager; +import com.ryderbelserion.vital.common.managers.files.CustomFile; +import com.ryderbelserion.vital.common.managers.files.FileManager; import com.ryderbelserion.vital.common.utils.StringUtil; -import com.ryderbelserion.vital.paper.files.config.CustomFile; -import com.ryderbelserion.vital.paper.files.config.FileManager; import com.ryderbelserion.vital.paper.util.ItemUtil; import org.apache.commons.lang.StringUtils; import org.bukkit.command.CommandSender; -import org.bukkit.configuration.ConfigurationSection; -import org.bukkit.configuration.file.YamlConfiguration; +import org.simpleyaml.configuration.ConfigurationSection; +import org.simpleyaml.configuration.file.YamlConfiguration; import java.io.File; import java.util.ArrayList; import java.util.HashMap; @@ -77,11 +77,13 @@ public void sendMessage(List files, final int success, final int failed) public void migrate(final CustomFile customFile, final String crateName) { final YamlConfiguration configuration = customFile.getConfiguration(); + if (configuration == null) return; + final ConfigurationSection crate = configuration.getConfigurationSection("Crate"); if (crate == null) { Messages.error_migrating.sendMessage(sender, new HashMap<>() {{ - put("{file}", crateName.isEmpty() ? customFile.getStrippedName() : crateName); + put("{file}", crateName.isEmpty() ? customFile.getCleanName() : crateName); put("{type}", type.getName()); put("{reason}", "File could not be found in our data, likely invalid yml file that didn't load properly."); }}); @@ -147,7 +149,7 @@ public void migrate(final CustomFile customFile, final String crateName) { } customFile.save(); - customFile.reload(); + customFile.load(); } public final String time() { diff --git a/src/main/java/com/badbones69/crazycrates/commands/crates/types/admin/crates/migrator/types/MojangMappedMigratorMultiple.java b/src/main/java/com/badbones69/crazycrates/commands/crates/types/admin/crates/migrator/types/MojangMappedMigratorMultiple.java index ee2971ef4..5f0b6151b 100644 --- a/src/main/java/com/badbones69/crazycrates/commands/crates/types/admin/crates/migrator/types/MojangMappedMigratorMultiple.java +++ b/src/main/java/com/badbones69/crazycrates/commands/crates/types/admin/crates/migrator/types/MojangMappedMigratorMultiple.java @@ -2,9 +2,9 @@ import com.badbones69.crazycrates.commands.crates.types.admin.crates.migrator.ICrateMigrator; import com.badbones69.crazycrates.commands.crates.types.admin.crates.migrator.enums.MigrationType; -import com.ryderbelserion.vital.paper.files.config.CustomFile; +import com.ryderbelserion.vital.common.managers.files.CustomFile; import org.bukkit.command.CommandSender; -import org.bukkit.configuration.ConfigurationSection; +import org.simpleyaml.configuration.ConfigurationSection; import java.io.File; import java.util.ArrayList; import java.util.List; @@ -18,7 +18,7 @@ public MojangMappedMigratorMultiple(final CommandSender sender, final MigrationT @Override public void run() { - final Set customFiles = this.plugin.getFileManager().getCustomFiles(); + final Set customFiles = (Set) this.plugin.getFileManager().getCustomFiles().values(); final List failed = new ArrayList<>(); final List success = new ArrayList<>(); @@ -27,9 +27,9 @@ public void run() { try { migrate(customFile, ""); - success.add("⤷ " + customFile.getStrippedName()); + success.add("⤷ " + customFile.getCleanName()); } catch (Exception exception) { - failed.add("⤷ " + customFile.getStrippedName()); + failed.add("⤷ " + customFile.getCleanName()); } }); diff --git a/src/main/java/com/badbones69/crazycrates/commands/crates/types/admin/crates/migrator/types/MojangMappedMigratorSingle.java b/src/main/java/com/badbones69/crazycrates/commands/crates/types/admin/crates/migrator/types/MojangMappedMigratorSingle.java index 2c6f4fced..5c214097a 100644 --- a/src/main/java/com/badbones69/crazycrates/commands/crates/types/admin/crates/migrator/types/MojangMappedMigratorSingle.java +++ b/src/main/java/com/badbones69/crazycrates/commands/crates/types/admin/crates/migrator/types/MojangMappedMigratorSingle.java @@ -4,9 +4,9 @@ import com.badbones69.crazycrates.api.objects.Crate; import com.badbones69.crazycrates.commands.crates.types.admin.crates.migrator.ICrateMigrator; import com.badbones69.crazycrates.commands.crates.types.admin.crates.migrator.enums.MigrationType; -import com.ryderbelserion.vital.paper.files.config.CustomFile; +import com.ryderbelserion.vital.common.managers.files.CustomFile; import org.bukkit.command.CommandSender; -import org.bukkit.configuration.ConfigurationSection; +import org.simpleyaml.configuration.ConfigurationSection; import java.io.File; import java.util.ArrayList; import java.util.HashMap; @@ -26,7 +26,7 @@ public void run() { return; } - final CustomFile customFile = this.plugin.getFileManager().getCustomFile(this.crateName); + final CustomFile customFile = this.plugin.getFileManager().getFile(true, this.crateName); if (customFile == null) { Messages.error_migrating.sendMessage(this.sender, new HashMap<>() {{ diff --git a/src/main/java/com/badbones69/crazycrates/commands/crates/types/admin/crates/migrator/types/deprecation/DeprecatedCrateMigrator.java b/src/main/java/com/badbones69/crazycrates/commands/crates/types/admin/crates/migrator/types/deprecation/DeprecatedCrateMigrator.java index 9dd8cd8b8..1af563544 100644 --- a/src/main/java/com/badbones69/crazycrates/commands/crates/types/admin/crates/migrator/types/deprecation/DeprecatedCrateMigrator.java +++ b/src/main/java/com/badbones69/crazycrates/commands/crates/types/admin/crates/migrator/types/deprecation/DeprecatedCrateMigrator.java @@ -2,14 +2,14 @@ import com.badbones69.crazycrates.commands.crates.types.admin.crates.migrator.ICrateMigrator; import com.badbones69.crazycrates.commands.crates.types.admin.crates.migrator.enums.MigrationType; -import com.ryderbelserion.vital.paper.files.config.CustomFile; +import com.ryderbelserion.vital.common.managers.files.CustomFile; import org.bukkit.command.CommandSender; -import org.bukkit.configuration.ConfigurationSection; -import org.bukkit.configuration.file.YamlConfiguration; +import org.simpleyaml.configuration.ConfigurationSection; +import org.simpleyaml.configuration.file.YamlConfiguration; import java.io.File; import java.util.ArrayList; +import java.util.Collection; import java.util.List; -import java.util.Set; public class DeprecatedCrateMigrator extends ICrateMigrator { @@ -19,7 +19,7 @@ public DeprecatedCrateMigrator(final CommandSender sender, final MigrationType t @Override public void run() { - final Set customFiles = this.plugin.getFileManager().getCustomFiles(); + final Collection customFiles = this.plugin.getFileManager().getCustomFiles().values(); final List failed = new ArrayList<>(); final List success = new ArrayList<>(); @@ -28,6 +28,8 @@ public void run() { try { final YamlConfiguration configuration = customFile.getConfiguration(); + if (configuration == null) return; + final ConfigurationSection section = configuration.getConfigurationSection("Crate"); if (section == null) return; @@ -74,9 +76,9 @@ public void run() { customFile.save(); } - success.add("⤷ " + customFile.getStrippedName()); + success.add("⤷ " + customFile.getCleanName()); } catch (Exception exception) { - failed.add("⤷ " + customFile.getStrippedName()); + failed.add("⤷ " + customFile.getCleanName()); } }); diff --git a/src/main/java/com/badbones69/crazycrates/commands/crates/types/admin/crates/migrator/types/plugins/ExcellentCratesMigrator.java b/src/main/java/com/badbones69/crazycrates/commands/crates/types/admin/crates/migrator/types/plugins/ExcellentCratesMigrator.java index 8867ba5fc..46a037983 100644 --- a/src/main/java/com/badbones69/crazycrates/commands/crates/types/admin/crates/migrator/types/plugins/ExcellentCratesMigrator.java +++ b/src/main/java/com/badbones69/crazycrates/commands/crates/types/admin/crates/migrator/types/plugins/ExcellentCratesMigrator.java @@ -3,14 +3,13 @@ import com.badbones69.crazycrates.api.enums.Files; import com.badbones69.crazycrates.commands.crates.types.admin.crates.migrator.ICrateMigrator; import com.badbones69.crazycrates.commands.crates.types.admin.crates.migrator.enums.MigrationType; -import com.ryderbelserion.vital.paper.files.config.CustomFile; +import com.ryderbelserion.vital.common.managers.files.CustomFile; import com.ryderbelserion.vital.paper.util.ItemUtil; import org.bukkit.command.CommandSender; -import org.bukkit.configuration.ConfigurationSection; -import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; +import org.simpleyaml.configuration.ConfigurationSection; import su.nightexpress.excellentcrates.CratesAPI; import su.nightexpress.excellentcrates.crate.impl.Crate; import su.nightexpress.excellentcrates.key.CrateKey; @@ -40,7 +39,7 @@ public void run() { final List failed = new ArrayList<>(); final List success = new ArrayList<>(); - FileConfiguration locationData = Files.locations.getConfiguration(); + org.simpleyaml.configuration.file.YamlConfiguration locationData = Files.locations.getConfiguration(); for (final Crate crate : CratesAPI.getCrateManager().getCrates()) { final String crateName = crate.getFile().getName(); @@ -63,9 +62,11 @@ public void run() { failed.add("⤷ " + crateName); } - final CustomFile customFile = new CustomFile(directory).apply(crateName); + final CustomFile customFile = new CustomFile(crateName, crateFile); - final YamlConfiguration configuration = customFile.getConfiguration(); + final org.simpleyaml.configuration.file.YamlConfiguration configuration = customFile.getConfiguration(); + + if (configuration == null) return; set(configuration, "Crate.CrateType", "CSGO"); @@ -120,7 +121,7 @@ public void run() { set(root, "Name", previewName); set(root, "Lore", previewLore); - final ConfigurationSection section = menuFile.getConfigurationSection("Crate.Slots"); + final org.bukkit.configuration.ConfigurationSection section = menuFile.getConfigurationSection("Crate.Slots"); if (section != null) { for (String key : section.getKeys(false)) { @@ -268,7 +269,7 @@ public void run() { customFile.save(); - this.fileManager.addCustomFile(customFile); + this.fileManager.addFile(true, customFile); success.add("⤷ " + crateName); } diff --git a/src/main/java/com/badbones69/crazycrates/listeners/crates/CosmicCrateListener.java b/src/main/java/com/badbones69/crazycrates/listeners/crates/CosmicCrateListener.java index 489912dc9..4c8b0e9d0 100644 --- a/src/main/java/com/badbones69/crazycrates/listeners/crates/CosmicCrateListener.java +++ b/src/main/java/com/badbones69/crazycrates/listeners/crates/CosmicCrateListener.java @@ -8,7 +8,6 @@ import com.ryderbelserion.vital.paper.util.ItemUtil; import me.clip.placeholderapi.PlaceholderAPI; import net.kyori.adventure.sound.Sound; -import org.bukkit.configuration.file.FileConfiguration; import com.badbones69.crazycrates.config.ConfigManager; import com.badbones69.crazycrates.config.impl.ConfigKeys; import com.badbones69.crazycrates.api.PrizeManager; @@ -29,6 +28,7 @@ import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.persistence.PersistentDataContainer; import org.jetbrains.annotations.NotNull; +import org.simpleyaml.configuration.file.YamlConfiguration; import us.crazycrew.crazycrates.api.enums.types.CrateType; import us.crazycrew.crazycrates.api.enums.types.KeyType; import com.badbones69.crazycrates.CrazyCrates; @@ -322,7 +322,7 @@ public void onMysteryBoxClick(InventoryClickEvent event) { // Clear the top inventory. view.getTopInventory().clear(); - FileConfiguration configuration = crate.getFile(); + YamlConfiguration configuration = crate.getFile(); final String broadcastMessage = configuration.getString("Crate.BroadCast", ""); final boolean broadcastToggle = configuration.getBoolean("Crate.OpeningBroadCast", false); diff --git a/src/main/java/com/badbones69/crazycrates/listeners/crates/CrateOpenListener.java b/src/main/java/com/badbones69/crazycrates/listeners/crates/CrateOpenListener.java index eeec7d4c9..24750da90 100644 --- a/src/main/java/com/badbones69/crazycrates/listeners/crates/CrateOpenListener.java +++ b/src/main/java/com/badbones69/crazycrates/listeners/crates/CrateOpenListener.java @@ -12,11 +12,11 @@ import com.ryderbelserion.vital.paper.util.AdvUtil; import com.ryderbelserion.vital.paper.util.ItemUtil; import me.clip.placeholderapi.PlaceholderAPI; -import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.jetbrains.annotations.NotNull; +import org.simpleyaml.configuration.file.YamlConfiguration; import us.crazycrew.crazycrates.api.enums.types.CrateType; import com.badbones69.crazycrates.api.utils.MsgUtils; import java.util.List; @@ -65,7 +65,7 @@ public void onCrateOpen(CrateOpenEvent event) { if (crate.getCrateType() != CrateType.cosmic) this.userManager.addOpenedCrate(player.getUniqueId(), fileName); - final FileConfiguration configuration = event.getConfiguration(); + final YamlConfiguration configuration = event.getConfiguration(); final String broadcastMessage = configuration.getString("Crate.BroadCast", ""); final boolean broadcastToggle = configuration.getBoolean("Crate.OpeningBroadCast", false); diff --git a/src/main/java/com/badbones69/crazycrates/tasks/BukkitUserManager.java b/src/main/java/com/badbones69/crazycrates/tasks/BukkitUserManager.java index fe3fc3fc0..d31b7dcd3 100644 --- a/src/main/java/com/badbones69/crazycrates/tasks/BukkitUserManager.java +++ b/src/main/java/com/badbones69/crazycrates/tasks/BukkitUserManager.java @@ -8,9 +8,10 @@ import com.badbones69.crazycrates.config.impl.ConfigKeys; import com.badbones69.crazycrates.tasks.crates.CrateManager; import com.badbones69.crazycrates.api.builders.ItemBuilder; -import org.bukkit.configuration.ConfigurationSection; -import org.bukkit.configuration.file.YamlConfiguration; import org.jetbrains.annotations.Nullable; +import org.simpleyaml.configuration.ConfigurationSection; +import org.simpleyaml.configuration.file.YamlConfiguration; +import org.simpleyaml.configuration.file.YamlFile; import us.crazycrew.crazycrates.api.enums.types.CrateType; import us.crazycrew.crazycrates.api.enums.types.KeyType; import com.badbones69.crazycrates.CrazyCrates; @@ -32,7 +33,7 @@ public class BukkitUserManager extends UserManager { - private @NotNull final CrazyCrates plugin = JavaPlugin.getPlugin(CrazyCrates.class); + private @NotNull final CrazyCrates plugin = CrazyCrates.getPlugin(); private @NotNull final CrateManager crateManager = this.plugin.getCrateManager(); diff --git a/src/main/java/com/badbones69/crazycrates/tasks/crates/CrateManager.java b/src/main/java/com/badbones69/crazycrates/tasks/crates/CrateManager.java index e45608e16..ae7bc6cac 100644 --- a/src/main/java/com/badbones69/crazycrates/tasks/crates/CrateManager.java +++ b/src/main/java/com/badbones69/crazycrates/tasks/crates/CrateManager.java @@ -24,16 +24,13 @@ import com.badbones69.crazycrates.tasks.crates.types.WarCrate; import com.badbones69.crazycrates.tasks.crates.types.WheelCrate; import com.badbones69.crazycrates.tasks.crates.types.WonderCrate; +import com.ryderbelserion.vital.common.managers.files.CustomFile; +import com.ryderbelserion.vital.common.managers.files.FileManager; import com.ryderbelserion.vital.common.utils.FileUtil; import com.badbones69.crazycrates.api.builders.ItemBuilder; import com.ryderbelserion.vital.paper.api.enums.Support; -import com.ryderbelserion.vital.paper.files.config.CustomFile; -import com.ryderbelserion.vital.paper.files.config.FileManager; import io.papermc.paper.threadedregions.scheduler.ScheduledTask; import net.kyori.adventure.text.logger.slf4j.ComponentLogger; -import org.bukkit.configuration.ConfigurationSection; -import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.permissions.Permission; import org.bukkit.permissions.PermissionDefault; @@ -41,6 +38,9 @@ import org.bukkit.persistence.PersistentDataType; import org.bukkit.plugin.PluginManager; import org.jetbrains.annotations.Nullable; +import org.simpleyaml.configuration.ConfigurationSection; +import org.simpleyaml.configuration.file.FileConfiguration; +import org.simpleyaml.configuration.file.YamlConfiguration; import us.crazycrew.crazycrates.api.enums.types.CrateType; import us.crazycrew.crazycrates.api.enums.types.KeyType; import com.badbones69.crazycrates.api.enums.PersistentKeys; @@ -79,7 +79,7 @@ public class CrateManager { private @NotNull final CrazyCrates plugin = CrazyCrates.getPlugin(); private @NotNull final InventoryManager inventoryManager = this.plugin.getInventoryManager(); - private @NotNull final FileManager yamlManager = this.plugin.getFileManager(); + private @NotNull final FileManager fileManager = this.plugin.getFileManager(); private final List crateLocations = new ArrayList<>(); private final List crateSchematics = new ArrayList<>(); @@ -283,12 +283,14 @@ public void loadCrates() { for (final String crateName : getCrateNames()) { try { - final @Nullable CustomFile customFile = this.yamlManager.getCustomFile(crateName); + final CustomFile customFile = this.fileManager.getFile(true, crateName); - if (customFile == null) return; + if (customFile == null) continue; final YamlConfiguration file = customFile.getConfiguration(); + if (file == null) continue; + final CrateType crateType = CrateType.getFromName(file.getString("Crate.CrateType", "CSGO")); final ArrayList prizes = new ArrayList<>(); @@ -939,6 +941,11 @@ public void addCrate(@NotNull final Crate crate) { this.crates.add(crate); } + /** + * Adds a crate location. + * + * @param crateLocation {@link CrateLocation} + */ public void addLocation(@NotNull final CrateLocation crateLocation) { this.crateLocations.add(crateLocation); } diff --git a/src/main/java/com/badbones69/crazycrates/tasks/crates/effects/SoundEffect.java b/src/main/java/com/badbones69/crazycrates/tasks/crates/effects/SoundEffect.java index 1b74e0356..0d9cce997 100644 --- a/src/main/java/com/badbones69/crazycrates/tasks/crates/effects/SoundEffect.java +++ b/src/main/java/com/badbones69/crazycrates/tasks/crates/effects/SoundEffect.java @@ -3,9 +3,9 @@ import net.kyori.adventure.key.Key; import net.kyori.adventure.sound.Sound; import org.bukkit.Location; -import org.bukkit.configuration.ConfigurationSection; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; +import org.simpleyaml.configuration.ConfigurationSection; public class SoundEffect { diff --git a/src/main/java/com/badbones69/crazycrates/tasks/crates/other/CosmicCrateManager.java b/src/main/java/com/badbones69/crazycrates/tasks/crates/other/CosmicCrateManager.java index 08ae756cd..137003d28 100644 --- a/src/main/java/com/badbones69/crazycrates/tasks/crates/other/CosmicCrateManager.java +++ b/src/main/java/com/badbones69/crazycrates/tasks/crates/other/CosmicCrateManager.java @@ -4,7 +4,6 @@ import com.badbones69.crazycrates.api.objects.Crate; import com.badbones69.crazycrates.api.objects.Tier; import com.badbones69.crazycrates.api.builders.ItemBuilder; -import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; @@ -13,6 +12,7 @@ import org.bukkit.persistence.PersistentDataType; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.simpleyaml.configuration.file.YamlConfiguration; import java.util.Collections; import java.util.HashMap; import java.util.Map; @@ -22,7 +22,7 @@ public class CosmicCrateManager extends AbstractCrateManager { private final ItemBuilder mysteryCrate; private final ItemBuilder pickedCrate; - private final FileConfiguration file; + private final YamlConfiguration file; private final int totalPrizes; private final Map> prizes = new HashMap<>(); @@ -32,7 +32,7 @@ public class CosmicCrateManager extends AbstractCrateManager { * * @param file the crate configuration. */ - public CosmicCrateManager(@NotNull final FileConfiguration file) { + public CosmicCrateManager(@NotNull final YamlConfiguration file) { this.file = file; String path = "Crate.Crate-Type-Settings."; @@ -59,7 +59,7 @@ public CosmicCrateManager(@NotNull final FileConfiguration file) { /** * @return crate file configuration. */ - public @NotNull final FileConfiguration getFile() { + public @NotNull final YamlConfiguration getFile() { return this.file; } diff --git a/src/main/java/com/badbones69/crazycrates/tasks/crates/types/CasinoCrate.java b/src/main/java/com/badbones69/crazycrates/tasks/crates/types/CasinoCrate.java index 720b7d75a..0459852fb 100644 --- a/src/main/java/com/badbones69/crazycrates/tasks/crates/types/CasinoCrate.java +++ b/src/main/java/com/badbones69/crazycrates/tasks/crates/types/CasinoCrate.java @@ -11,12 +11,12 @@ import com.badbones69.crazycrates.tasks.crates.CrateManager; import net.kyori.adventure.sound.Sound; import net.kyori.adventure.text.logger.slf4j.ComponentLogger; -import org.bukkit.configuration.ConfigurationSection; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.persistence.PersistentDataContainer; import org.jetbrains.annotations.NotNull; +import org.simpleyaml.configuration.ConfigurationSection; import us.crazycrew.crazycrates.api.enums.types.KeyType; import java.util.List; import java.util.UUID; diff --git a/src/main/java/com/badbones69/crazycrates/tasks/crates/types/QuadCrate.java b/src/main/java/com/badbones69/crazycrates/tasks/crates/types/QuadCrate.java index e7cb72dae..94ccc3fa5 100644 --- a/src/main/java/com/badbones69/crazycrates/tasks/crates/types/QuadCrate.java +++ b/src/main/java/com/badbones69/crazycrates/tasks/crates/types/QuadCrate.java @@ -5,9 +5,9 @@ import com.badbones69.crazycrates.api.objects.other.CrateLocation; import com.ryderbelserion.vital.paper.util.structures.StructureManager; import org.bukkit.Location; -import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; +import org.simpleyaml.configuration.file.YamlConfiguration; import us.crazycrew.crazycrates.api.enums.types.KeyType; import com.badbones69.crazycrates.CrazyCrates; import com.badbones69.crazycrates.api.builders.CrateBuilder; @@ -37,7 +37,7 @@ public void open(@NotNull final KeyType type, final boolean checkHand) { return; } - final FileConfiguration config = getFile(); + final YamlConfiguration config = getFile(); final List schematics = this.crateManager.getCrateSchematics(); final CrateSchematic crateSchematic = config.getBoolean("Crate.structure.random", true) ? schematics.get(ThreadLocalRandom.current().nextInt(schematics.size())) : this.crateManager.getCrateSchematic(config.getString("Crate.structure.file", ""));