From b77ec36cee6b338db3f4ec77540cc93863c7266d Mon Sep 17 00:00:00 2001 From: Paldiu Date: Mon, 25 Jan 2021 12:51:29 -0600 Subject: [PATCH] Initial commit --- .gitattributes | 2 + .gitignore | 23 ++++ .idea/.gitignore | 3 + .idea/compiler.xml | 16 +++ .idea/encodings.xml | 7 + .idea/inspectionProfiles/Project_Default.xml | 54 ++++++++ .idea/jarRepositories.xml | 30 +++++ ...o_paper_paper_api_1_16_4_R0_1_SNAPSHOT.xml | 13 ++ ..._com_google_code_findbugs_jsr305_1_3_9.xml | 13 ++ ...Maven__com_google_code_gson_gson_2_8_0.xml | 13 ++ .../Maven__com_google_guava_guava_21_0.xml | 13 ++ ...oglecode_json_simple_json_simple_1_1_1.xml | 13 ++ .../Maven__commons_lang_commons_lang_2_6.xml | 13 ++ .idea/libraries/Maven__junit_junit_4_10.xml | 13 ++ ...en__net_md_5_bungeecord_chat_1_16_R0_3.xml | 13 ++ .../Maven__org_hamcrest_hamcrest_core_1_1.xml | 13 ++ ...ven__org_javassist_javassist_3_26_0_GA.xml | 13 ++ ...aven__org_jetbrains_annotations_20_1_0.xml | 13 ++ .../Maven__org_ow2_asm_asm_8_0_1.xml | 13 ++ .../Maven__org_ow2_asm_asm_analysis_8_0_1.xml | 13 ++ .../Maven__org_ow2_asm_asm_commons_8_0_1.xml | 13 ++ .../Maven__org_ow2_asm_asm_tree_8_0_1.xml | 13 ++ ...en__org_reflections_reflections_0_9_12.xml | 13 ++ .../Maven__org_slf4j_slf4j_api_1_7_25.xml | 13 ++ .../Maven__org_yaml_snakeyaml_1_26.xml | 13 ++ .idea/misc.xml | 18 +++ .idea/modules.xml | 8 ++ .idea/uiDesigner.xml | 124 ++++++++++++++++++ LICENSE | 21 +++ SimplexCore.iml | 43 ++++++ pom.xml | 87 ++++++++++++ .../github/paldiu/simplexcore/Constants.java | 42 ++++++ .../paldiu/simplexcore/SimplexCore.java | 19 +++ .../simplexcore/command/CommandInfo.java | 17 +++ .../simplexcore/command/CommandLoader.java | 120 +++++++++++++++++ .../paldiu/simplexcore/registry/Addon.java | 51 +++++++ .../simplexcore/registry/AddonRegistry.java | 19 +++ src/main/resources/plugin.yml | 7 + 38 files changed, 945 insertions(+) create mode 100644 .gitattributes create mode 100644 .gitignore create mode 100644 .idea/.gitignore create mode 100644 .idea/compiler.xml create mode 100644 .idea/encodings.xml create mode 100644 .idea/inspectionProfiles/Project_Default.xml create mode 100644 .idea/jarRepositories.xml create mode 100644 .idea/libraries/Maven__com_destroystokyo_paper_paper_api_1_16_4_R0_1_SNAPSHOT.xml create mode 100644 .idea/libraries/Maven__com_google_code_findbugs_jsr305_1_3_9.xml create mode 100644 .idea/libraries/Maven__com_google_code_gson_gson_2_8_0.xml create mode 100644 .idea/libraries/Maven__com_google_guava_guava_21_0.xml create mode 100644 .idea/libraries/Maven__com_googlecode_json_simple_json_simple_1_1_1.xml create mode 100644 .idea/libraries/Maven__commons_lang_commons_lang_2_6.xml create mode 100644 .idea/libraries/Maven__junit_junit_4_10.xml create mode 100644 .idea/libraries/Maven__net_md_5_bungeecord_chat_1_16_R0_3.xml create mode 100644 .idea/libraries/Maven__org_hamcrest_hamcrest_core_1_1.xml create mode 100644 .idea/libraries/Maven__org_javassist_javassist_3_26_0_GA.xml create mode 100644 .idea/libraries/Maven__org_jetbrains_annotations_20_1_0.xml create mode 100644 .idea/libraries/Maven__org_ow2_asm_asm_8_0_1.xml create mode 100644 .idea/libraries/Maven__org_ow2_asm_asm_analysis_8_0_1.xml create mode 100644 .idea/libraries/Maven__org_ow2_asm_asm_commons_8_0_1.xml create mode 100644 .idea/libraries/Maven__org_ow2_asm_asm_tree_8_0_1.xml create mode 100644 .idea/libraries/Maven__org_reflections_reflections_0_9_12.xml create mode 100644 .idea/libraries/Maven__org_slf4j_slf4j_api_1_7_25.xml create mode 100644 .idea/libraries/Maven__org_yaml_snakeyaml_1_26.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/uiDesigner.xml create mode 100644 LICENSE create mode 100644 SimplexCore.iml create mode 100644 pom.xml create mode 100644 src/main/java/io/github/paldiu/simplexcore/Constants.java create mode 100644 src/main/java/io/github/paldiu/simplexcore/SimplexCore.java create mode 100644 src/main/java/io/github/paldiu/simplexcore/command/CommandInfo.java create mode 100644 src/main/java/io/github/paldiu/simplexcore/command/CommandLoader.java create mode 100644 src/main/java/io/github/paldiu/simplexcore/registry/Addon.java create mode 100644 src/main/java/io/github/paldiu/simplexcore/registry/AddonRegistry.java create mode 100644 src/main/resources/plugin.yml diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..dfe0770 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +# Auto detect text files and perform LF normalization +* text=auto diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a1c2a23 --- /dev/null +++ b/.gitignore @@ -0,0 +1,23 @@ +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..d7afc93 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..aa00ffa --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..7ae5ed7 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,54 @@ + + + + \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml new file mode 100644 index 0000000..4f3d965 --- /dev/null +++ b/.idea/jarRepositories.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__com_destroystokyo_paper_paper_api_1_16_4_R0_1_SNAPSHOT.xml b/.idea/libraries/Maven__com_destroystokyo_paper_paper_api_1_16_4_R0_1_SNAPSHOT.xml new file mode 100644 index 0000000..1ae0fed --- /dev/null +++ b/.idea/libraries/Maven__com_destroystokyo_paper_paper_api_1_16_4_R0_1_SNAPSHOT.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__com_google_code_findbugs_jsr305_1_3_9.xml b/.idea/libraries/Maven__com_google_code_findbugs_jsr305_1_3_9.xml new file mode 100644 index 0000000..0e66824 --- /dev/null +++ b/.idea/libraries/Maven__com_google_code_findbugs_jsr305_1_3_9.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__com_google_code_gson_gson_2_8_0.xml b/.idea/libraries/Maven__com_google_code_gson_gson_2_8_0.xml new file mode 100644 index 0000000..6e5d5b7 --- /dev/null +++ b/.idea/libraries/Maven__com_google_code_gson_gson_2_8_0.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__com_google_guava_guava_21_0.xml b/.idea/libraries/Maven__com_google_guava_guava_21_0.xml new file mode 100644 index 0000000..a923456 --- /dev/null +++ b/.idea/libraries/Maven__com_google_guava_guava_21_0.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__com_googlecode_json_simple_json_simple_1_1_1.xml b/.idea/libraries/Maven__com_googlecode_json_simple_json_simple_1_1_1.xml new file mode 100644 index 0000000..f3f3738 --- /dev/null +++ b/.idea/libraries/Maven__com_googlecode_json_simple_json_simple_1_1_1.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__commons_lang_commons_lang_2_6.xml b/.idea/libraries/Maven__commons_lang_commons_lang_2_6.xml new file mode 100644 index 0000000..2ec8376 --- /dev/null +++ b/.idea/libraries/Maven__commons_lang_commons_lang_2_6.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__junit_junit_4_10.xml b/.idea/libraries/Maven__junit_junit_4_10.xml new file mode 100644 index 0000000..ed8bf5f --- /dev/null +++ b/.idea/libraries/Maven__junit_junit_4_10.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__net_md_5_bungeecord_chat_1_16_R0_3.xml b/.idea/libraries/Maven__net_md_5_bungeecord_chat_1_16_R0_3.xml new file mode 100644 index 0000000..2019f9a --- /dev/null +++ b/.idea/libraries/Maven__net_md_5_bungeecord_chat_1_16_R0_3.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_1.xml b/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_1.xml new file mode 100644 index 0000000..acdf443 --- /dev/null +++ b/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_1.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_javassist_javassist_3_26_0_GA.xml b/.idea/libraries/Maven__org_javassist_javassist_3_26_0_GA.xml new file mode 100644 index 0000000..e150186 --- /dev/null +++ b/.idea/libraries/Maven__org_javassist_javassist_3_26_0_GA.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_jetbrains_annotations_20_1_0.xml b/.idea/libraries/Maven__org_jetbrains_annotations_20_1_0.xml new file mode 100644 index 0000000..de125e3 --- /dev/null +++ b/.idea/libraries/Maven__org_jetbrains_annotations_20_1_0.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_ow2_asm_asm_8_0_1.xml b/.idea/libraries/Maven__org_ow2_asm_asm_8_0_1.xml new file mode 100644 index 0000000..5a04654 --- /dev/null +++ b/.idea/libraries/Maven__org_ow2_asm_asm_8_0_1.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_ow2_asm_asm_analysis_8_0_1.xml b/.idea/libraries/Maven__org_ow2_asm_asm_analysis_8_0_1.xml new file mode 100644 index 0000000..33917b7 --- /dev/null +++ b/.idea/libraries/Maven__org_ow2_asm_asm_analysis_8_0_1.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_ow2_asm_asm_commons_8_0_1.xml b/.idea/libraries/Maven__org_ow2_asm_asm_commons_8_0_1.xml new file mode 100644 index 0000000..5e98909 --- /dev/null +++ b/.idea/libraries/Maven__org_ow2_asm_asm_commons_8_0_1.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_ow2_asm_asm_tree_8_0_1.xml b/.idea/libraries/Maven__org_ow2_asm_asm_tree_8_0_1.xml new file mode 100644 index 0000000..a5adaf2 --- /dev/null +++ b/.idea/libraries/Maven__org_ow2_asm_asm_tree_8_0_1.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_reflections_reflections_0_9_12.xml b/.idea/libraries/Maven__org_reflections_reflections_0_9_12.xml new file mode 100644 index 0000000..bedc96e --- /dev/null +++ b/.idea/libraries/Maven__org_reflections_reflections_0_9_12.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_slf4j_slf4j_api_1_7_25.xml b/.idea/libraries/Maven__org_slf4j_slf4j_api_1_7_25.xml new file mode 100644 index 0000000..20e8163 --- /dev/null +++ b/.idea/libraries/Maven__org_slf4j_slf4j_api_1_7_25.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_yaml_snakeyaml_1_26.xml b/.idea/libraries/Maven__org_yaml_snakeyaml_1_26.xml new file mode 100644 index 0000000..e998675 --- /dev/null +++ b/.idea/libraries/Maven__org_yaml_snakeyaml_1_26.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..17bca28 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..ff5c20e --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000..e96534f --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..b70ed60 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2021 Paldiu + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/SimplexCore.iml b/SimplexCore.iml new file mode 100644 index 0000000..90857c1 --- /dev/null +++ b/SimplexCore.iml @@ -0,0 +1,43 @@ + + + + + + + PAPER + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..2077802 --- /dev/null +++ b/pom.xml @@ -0,0 +1,87 @@ + + + 4.0.0 + + io.github.paldiu.simplexcore + SimplexCore + 1.0.0-BLEEDING + jar + + SimplexCore + + Core for a group of plugins designed to enhance gameplay to the max + + 11 + UTF-8 + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + ${java.version} + ${java.version} + + + + org.apache.maven.plugins + maven-shade-plugin + 3.2.4 + + + package + + shade + + + false + + + + + + + + src/main/resources + true + + + + + + + papermc-repo + https://papermc.io/repo/repository/maven-public/ + + + sonatype + https://oss.sonatype.org/content/groups/public/ + + + + + + com.destroystokyo.paper + paper-api + 1.16.4-R0.1-SNAPSHOT + provided + + + org.jetbrains + annotations + 20.1.0 + compile + + + org.reflections + reflections + 0.9.12 + compile + + + diff --git a/src/main/java/io/github/paldiu/simplexcore/Constants.java b/src/main/java/io/github/paldiu/simplexcore/Constants.java new file mode 100644 index 0000000..ab58a75 --- /dev/null +++ b/src/main/java/io/github/paldiu/simplexcore/Constants.java @@ -0,0 +1,42 @@ +package io.github.paldiu.simplexcore; + +import io.github.paldiu.simplexcore.registry.AddonRegistry; +import org.bukkit.Server; +import org.bukkit.plugin.PluginManager; +import org.bukkit.plugin.java.JavaPlugin; +import org.bukkit.scheduler.BukkitScheduler; + +import java.util.logging.Logger; + +public final class Constants { + private static final SimplexCore plugin = JavaPlugin.getPlugin(SimplexCore.class); + private static final Server server = plugin.getServer(); + private static final Logger logger = plugin.getLogger(); + private static final PluginManager manager = server.getPluginManager(); + private static final BukkitScheduler scheduler = server.getScheduler(); + private static final AddonRegistry registry = new AddonRegistry(); + + public static SimplexCore getPlugin() { + return plugin; + } + + public static Server getServer() { + return server; + } + + public static Logger getLogger() { + return logger; + } + + public static PluginManager getManager() { + return manager; + } + + public static BukkitScheduler getScheduler() { + return scheduler; + } + + public static AddonRegistry getRegistry() { + return registry; + } +} diff --git a/src/main/java/io/github/paldiu/simplexcore/SimplexCore.java b/src/main/java/io/github/paldiu/simplexcore/SimplexCore.java new file mode 100644 index 0000000..024e1f8 --- /dev/null +++ b/src/main/java/io/github/paldiu/simplexcore/SimplexCore.java @@ -0,0 +1,19 @@ +package io.github.paldiu.simplexcore; + +import io.github.paldiu.simplexcore.registry.Addon; + +public final class SimplexCore extends Addon { + protected SimplexCore(SimplexCore plugin) { + super(plugin); + } + + @Override + public void start() { + + } + + @Override + public void stop() { + + } +} \ No newline at end of file diff --git a/src/main/java/io/github/paldiu/simplexcore/command/CommandInfo.java b/src/main/java/io/github/paldiu/simplexcore/command/CommandInfo.java new file mode 100644 index 0000000..905e5e2 --- /dev/null +++ b/src/main/java/io/github/paldiu/simplexcore/command/CommandInfo.java @@ -0,0 +1,17 @@ +package io.github.paldiu.simplexcore.command; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +@Retention(RetentionPolicy.RUNTIME) +public @interface CommandInfo { + String name(); + + String description(); + + String usage(); + + String aliases() default ""; + + String permission() default "simplex.core"; +} diff --git a/src/main/java/io/github/paldiu/simplexcore/command/CommandLoader.java b/src/main/java/io/github/paldiu/simplexcore/command/CommandLoader.java new file mode 100644 index 0000000..d7c6551 --- /dev/null +++ b/src/main/java/io/github/paldiu/simplexcore/command/CommandLoader.java @@ -0,0 +1,120 @@ +package io.github.paldiu.simplexcore.command; + +import io.github.paldiu.simplexcore.Constants; +import org.bukkit.Bukkit; +import org.bukkit.command.*; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.SimplePluginManager; +import org.jetbrains.annotations.NotNull; +import org.reflections.Reflections; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.util.*; + +public class CommandLoader { + private final Reflections reflections; + + public CommandLoader(Class clazz) { + if (!clazz.isAnnotationPresent(CommandInfo.class)) { + throw new MissingResourceException("Cannot register this class as the main resource location!", clazz.getSimpleName(), "@CommandInfo"); + } + + if (!clazz.isAssignableFrom(CommandExecutor.class)) { + throw new RuntimeException("Unable to assign an executor!"); + } + + reflections = new Reflections(clazz); + } + + public void load() { + reflections.getTypesAnnotatedWith(CommandInfo.class).forEach(annotated -> { + CommandInfo info = annotated.getDeclaredAnnotation(CommandInfo.class); + + if (info == null) return; + if (!CommandExecutor.class.isAssignableFrom(annotated)) return; + + PluginCommand objectToRegister = Registry.create(Constants.getPlugin(), info.name()); + objectToRegister.setDescription(info.description()); + objectToRegister.setUsage(info.usage()); + objectToRegister.setAliases(Arrays.asList(info.aliases().split(","))); + objectToRegister.setPermission(info.permission()); + objectToRegister.setExecutor(getFromSetName(info.name())); + Registry.registerCommand(objectToRegister); + }); + } + + public CommandExecutor getFromSetName(String name) { + for (Class obj : reflections.getSubTypesOf(CommandExecutor.class)) { + if (name.equalsIgnoreCase(obj.getSimpleName())) { + try { + Constructor constr = obj.getDeclaredConstructor(); + return constr.newInstance(); + } catch (NoSuchMethodException | IllegalAccessException | InstantiationException | InvocationTargetException e) { + throw new RuntimeException(e); + } + } + } + throw new RuntimeException("Unable to get a command executor! Terminating!"); + } + + @SuppressWarnings("unchecked") + private static class Registry { + private static final Constructor constructor; + private static final Field cmdMapField; + private static final Field knownCmdsField; + + static { + Constructor temp; + try { + temp = PluginCommand.class.getDeclaredConstructor(String.class, Plugin.class); + temp.setAccessible(true); + } catch (NoSuchMethodException e) { + throw new RuntimeException(e); + } + constructor = temp; + + Field cmf; + try { + cmf = SimplePluginManager.class.getDeclaredField("commandMap"); + cmf.setAccessible(true); + } catch (NoSuchFieldException e) { + throw new RuntimeException(e); + } + cmdMapField = cmf; + + Field kcf; + try { + kcf = SimpleCommandMap.class.getDeclaredField("knownCommands"); + kcf.setAccessible(true); + } catch (NoSuchFieldException e) { + throw new RuntimeException(e); + } + knownCmdsField = kcf; + } + + public static PluginCommand create(@NotNull Plugin plugin, @NotNull String name) { + try { + return constructor.newInstance(name, plugin); + } catch (IllegalAccessException | InstantiationException | InvocationTargetException e) { + throw new RuntimeException(e); + } + } + + public static void registerCommand(PluginCommand command) { + try { + CommandMap map = (CommandMap) cmdMapField.get(Bukkit.getPluginManager()); + Map knownCommands = map.getKnownCommands(); + + if (knownCommands.containsKey(command.getName())) { + knownCommands.replace(command.getName(), command); + } + + map.register(command.getName(), command); + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } + } + } +} diff --git a/src/main/java/io/github/paldiu/simplexcore/registry/Addon.java b/src/main/java/io/github/paldiu/simplexcore/registry/Addon.java new file mode 100644 index 0000000..fbd400c --- /dev/null +++ b/src/main/java/io/github/paldiu/simplexcore/registry/Addon.java @@ -0,0 +1,51 @@ +package io.github.paldiu.simplexcore.registry; + +import org.bukkit.plugin.java.JavaPlugin; + +public abstract class Addon> extends JavaPlugin { + private final T plugin; + + protected Addon(T plugin) { + this.plugin = plugin; + } + + /** + * Gets your plugin as an addon. + * + * @return The addon. + */ + public T getPlugin() { + return plugin; + } + + @Override + public void onLoad() { + init(); + } + + @Override + public void onEnable() { + start(); + } + + @Override + public void onDisable() { + stop(); + } + + /** + * Plugin startup logic. + */ + public abstract void start(); + + /** + * Plugin shutdown logic. + */ + public abstract void stop(); + + /** + * Plugin initialization logic. + */ + public void init() { + } +} diff --git a/src/main/java/io/github/paldiu/simplexcore/registry/AddonRegistry.java b/src/main/java/io/github/paldiu/simplexcore/registry/AddonRegistry.java new file mode 100644 index 0000000..264ca6a --- /dev/null +++ b/src/main/java/io/github/paldiu/simplexcore/registry/AddonRegistry.java @@ -0,0 +1,19 @@ +package io.github.paldiu.simplexcore.registry; + +import java.util.HashSet; +import java.util.Set; + +public class AddonRegistry { + private final Set> components = new HashSet<>(); + + public AddonRegistry() { + } + + public void register(Addon addon) { + getComponents().add(addon); + } + + public Set> getComponents() { + return components; + } +} \ No newline at end of file diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml new file mode 100644 index 0000000..6801325 --- /dev/null +++ b/src/main/resources/plugin.yml @@ -0,0 +1,7 @@ +name: SimplexCore +version: ${project.version} +main: pw.coomer.simplexcore.SimplexCore +api-version: 1.16 +prefix: Simplex +authors: [ Paldiu ] +description: Core for a group of plugins designed to enhance gameplay to the max