From 206e42ddf2204edd71b46a3785e122908c4d09c6 Mon Sep 17 00:00:00 2001 From: Ryder Belserion Date: Wed, 18 Sep 2024 01:51:59 -0400 Subject: [PATCH] [ci-skip] stash dev environment features --- .../crazycrates/common/enums/Environment.java | 2 +- .../common/interfaces/Manifest.java | 16 +++++++++ .../badbones69/crazycrates/CrazyCrates.java | 3 +- .../managers/storage/StorageManager.java | 9 +++++ .../managers/storage/interfaces/Storage.java | 20 +++++++++++ .../storage/interfaces/YamlStorage.java | 34 +++++++++++++++++++ 6 files changed, 81 insertions(+), 3 deletions(-) create mode 100644 common/src/main/java/com/badbones69/crazycrates/common/interfaces/Manifest.java create mode 100644 paper/src/main/java/com/badbones69/crazycrates/managers/storage/StorageManager.java create mode 100644 paper/src/main/java/com/badbones69/crazycrates/managers/storage/interfaces/Storage.java create mode 100644 paper/src/main/java/com/badbones69/crazycrates/managers/storage/interfaces/YamlStorage.java diff --git a/common/src/main/java/com/badbones69/crazycrates/common/enums/Environment.java b/common/src/main/java/com/badbones69/crazycrates/common/enums/Environment.java index 80ef68184..2709eb46b 100644 --- a/common/src/main/java/com/badbones69/crazycrates/common/enums/Environment.java +++ b/common/src/main/java/com/badbones69/crazycrates/common/enums/Environment.java @@ -2,5 +2,5 @@ public enum Environment { PRODUCTION, - ENVIRONMENT + DEVELOPMENT } \ No newline at end of file diff --git a/common/src/main/java/com/badbones69/crazycrates/common/interfaces/Manifest.java b/common/src/main/java/com/badbones69/crazycrates/common/interfaces/Manifest.java new file mode 100644 index 000000000..9ef5a9066 --- /dev/null +++ b/common/src/main/java/com/badbones69/crazycrates/common/interfaces/Manifest.java @@ -0,0 +1,16 @@ +package com.badbones69.crazycrates.common.interfaces; + +import com.badbones69.crazycrates.common.enums.Environment; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +public @interface Manifest { + + Environment environment(); + +} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazycrates/CrazyCrates.java b/paper/src/main/java/com/badbones69/crazycrates/CrazyCrates.java index 71b730b9c..d0ca2ceeb 100644 --- a/paper/src/main/java/com/badbones69/crazycrates/CrazyCrates.java +++ b/paper/src/main/java/com/badbones69/crazycrates/CrazyCrates.java @@ -23,7 +23,6 @@ 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; @@ -59,7 +58,7 @@ public void onEnable() { this.instance = new Server(getDataFolder()); this.instance.apply(); - getFileManager().addFile(new File(getDataFolder(), "locations.yml")).addFile(new File(getDataFolder(),"data.yml")) + getFileManager().addFile(new File(getDataFolder(), "locations.yml")).addFile(new File(getDataFolder(), "data.yml")) .addFolder("crates") .addFolder("schematics") .init(); diff --git a/paper/src/main/java/com/badbones69/crazycrates/managers/storage/StorageManager.java b/paper/src/main/java/com/badbones69/crazycrates/managers/storage/StorageManager.java new file mode 100644 index 000000000..298cf5981 --- /dev/null +++ b/paper/src/main/java/com/badbones69/crazycrates/managers/storage/StorageManager.java @@ -0,0 +1,9 @@ +package com.badbones69.crazycrates.managers.storage; + +import com.badbones69.crazycrates.common.enums.Environment; +import com.badbones69.crazycrates.common.interfaces.Manifest; + +@Manifest(environment = Environment.DEVELOPMENT) +public class StorageManager { + +} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazycrates/managers/storage/interfaces/Storage.java b/paper/src/main/java/com/badbones69/crazycrates/managers/storage/interfaces/Storage.java new file mode 100644 index 000000000..046b4bfc5 --- /dev/null +++ b/paper/src/main/java/com/badbones69/crazycrates/managers/storage/interfaces/Storage.java @@ -0,0 +1,20 @@ +package com.badbones69.crazycrates.managers.storage.interfaces; + +import com.badbones69.crazycrates.common.enums.Environment; +import com.badbones69.crazycrates.common.interfaces.Manifest; +import java.io.File; + +@Manifest(environment = Environment.DEVELOPMENT) +public interface Storage { + + T getAccess(); + + default void start() {} + + default void save() {} + + default void reload() {} + + File getFile(); + +} \ No newline at end of file diff --git a/paper/src/main/java/com/badbones69/crazycrates/managers/storage/interfaces/YamlStorage.java b/paper/src/main/java/com/badbones69/crazycrates/managers/storage/interfaces/YamlStorage.java new file mode 100644 index 000000000..9ffa76634 --- /dev/null +++ b/paper/src/main/java/com/badbones69/crazycrates/managers/storage/interfaces/YamlStorage.java @@ -0,0 +1,34 @@ +package com.badbones69.crazycrates.managers.storage.interfaces; + +import com.badbones69.crazycrates.CrazyCrates; +import com.badbones69.crazycrates.common.enums.Environment; +import com.badbones69.crazycrates.common.interfaces.Manifest; +import com.ryderbelserion.vital.paper.api.files.FileManager; +import org.bukkit.configuration.file.YamlConfiguration; + +@Manifest(environment = Environment.DEVELOPMENT) +public abstract class YamlStorage implements Storage { + + protected CrazyCrates plugin = CrazyCrates.getPlugin(); + protected FileManager fileManager = this.plugin.getFileManager(); + + @Override + public void start() { + this.fileManager.addFile(getFile()); + } + + @Override + public void save() { + this.fileManager.saveFile(getFile().getName()); + } + + @Override + public void reload() { + this.fileManager.addFile(getFile()); + } + + @Override + public final YamlConfiguration getAccess() { + return this.fileManager.getFile(getFile().getName()).getConfiguration(); + } +} \ No newline at end of file