Skip to content

Commit

Permalink
update file manager
Browse files Browse the repository at this point in the history
  • Loading branch information
ryderbelserion committed Aug 20, 2024
1 parent 44370d4 commit 4015958
Show file tree
Hide file tree
Showing 28 changed files with 117 additions and 119 deletions.
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/java-plugin.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ repositories {

maven("https://repo.oraxen.com/releases")

maven(Repository.CrazyCrewReleases.url)
maven(Repository.CrazyCrewSnapshots.url)

maven(Repository.Jitpack.url)

Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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
Expand Down
36 changes: 18 additions & 18 deletions src/main/java/com/badbones69/crazycrates/CrazyCrates.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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();
Expand Down Expand Up @@ -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()) {
Expand All @@ -124,15 +131,7 @@ public void onEnable() {
getComponentLogger().info(AdvUtil.parse("<bold><gold>" + value.getName() + " <red>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));
Expand Down Expand Up @@ -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;
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,19 @@
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;
import io.papermc.paper.threadedregions.scheduler.ScheduledTask;
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;
Expand Down Expand Up @@ -252,7 +251,7 @@ public final boolean isCosmicCrate() {
/**
* @return file configuration of crate.
*/
public FileConfiguration getFile() {
public YamlConfiguration getFile() {
return this.crate.getFile();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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");

Expand Down
10 changes: 5 additions & 5 deletions src/main/java/com/badbones69/crazycrates/api/enums/Files.java
Original file line number Diff line number Diff line change
@@ -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 {

Expand All @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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;

Expand Down Expand Up @@ -58,7 +58,7 @@ public final boolean isCheckHand() {
return this.checkHand;
}

public @NotNull final FileConfiguration getConfiguration() {
public @NotNull final YamlConfiguration getConfiguration() {
return this.configuration;
}

Expand Down
14 changes: 7 additions & 7 deletions src/main/java/com/badbones69/crazycrates/api/objects/Crate.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -64,7 +64,7 @@ public class Crate {
private Particle particle;

private final CrateType crateType;
private FileConfiguration file;
private YamlConfiguration file;
private ArrayList<Prize> prizes;
private String crateName;
private boolean giveNewPlayerKeys;
Expand Down Expand Up @@ -104,7 +104,7 @@ public Crate(@NotNull final String name,
@NotNull final ItemBuilder key,
@NotNull final String keyName,
@NotNull final ArrayList<Prize> prizes,
@NotNull final FileConfiguration file,
@NotNull final YamlConfiguration file,
final int newPlayerKeys,
@NotNull final List<Tier> tiers,
final int maxMassOpen,
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -68,6 +68,7 @@ public Prize(@NotNull final ConfigurationSection section, List<ItemStack> 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -13,17 +11,15 @@
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;

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");

Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
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;
import org.bukkit.inventory.ItemStack;
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;
Expand Down
Loading

0 comments on commit 4015958

Please sign in to comment.