diff --git a/gradle.properties b/gradle.properties index fbc5b5e..0b0d930 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ pluginMain=SimplexCorePlugin pluginMainPackage=io.github.simplexdev.simplexcore -pluginVersion=1.3_10 +pluginVersion=1.3_11 pluginName=SimplexCore pluginJarClassifier=BLEEDING diff --git a/src/main/java/io/github/simplexdev/api/IEnchant.java b/src/main/java/io/github/simplexdev/api/IEnchant.java new file mode 100644 index 0000000..88cb036 --- /dev/null +++ b/src/main/java/io/github/simplexdev/api/IEnchant.java @@ -0,0 +1,13 @@ +package io.github.simplexdev.api; + +import org.bukkit.NamespacedKey; + +public interface IEnchant { + NamespacedKey getNamespacedKey(); + + String getName(); + + Integer getMaximumLevel(); + + Boolean isGlowing(); +} diff --git a/src/main/java/io/github/simplexdev/api/annotations/Enchant.java b/src/main/java/io/github/simplexdev/api/annotations/Enchant.java new file mode 100644 index 0000000..4ab21d3 --- /dev/null +++ b/src/main/java/io/github/simplexdev/api/annotations/Enchant.java @@ -0,0 +1,12 @@ +package io.github.simplexdev.api.annotations; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +public @interface Enchant { + boolean glow() default true; +} diff --git a/src/main/java/io/github/simplexdev/simplexcore/SimplexCorePlugin.java b/src/main/java/io/github/simplexdev/simplexcore/SimplexCorePlugin.java index 8a4be05..9feb92b 100644 --- a/src/main/java/io/github/simplexdev/simplexcore/SimplexCorePlugin.java +++ b/src/main/java/io/github/simplexdev/simplexcore/SimplexCorePlugin.java @@ -3,13 +3,13 @@ package io.github.simplexdev.simplexcore; import io.github.simplexdev.simplexcore.command.defaults.Command_info; import io.github.simplexdev.simplexcore.config.Yaml; import io.github.simplexdev.simplexcore.config.YamlFactory; -import io.github.simplexdev.simplexcore.plugin.DependencyManagement; +import io.github.simplexdev.simplexcore.module.DependencyManagement; import io.github.simplexdev.simplexcore.task.Announcer; import io.github.simplexdev.simplexcore.listener.DependencyListener; import io.github.simplexdev.simplexcore.listener.SimplexListener; -import io.github.simplexdev.simplexcore.plugin.SimplexAddon; +import io.github.simplexdev.simplexcore.module.SimplexModule; -public final class SimplexCorePlugin extends SimplexAddon { +public final class SimplexCorePlugin extends SimplexModule { private static boolean debug = false; private static boolean suspended = false; private static SimplexCorePlugin instance; diff --git a/src/main/java/io/github/simplexdev/simplexcore/command/CommandLoader.java b/src/main/java/io/github/simplexdev/simplexcore/command/CommandLoader.java index 844e3a3..7a2689c 100644 --- a/src/main/java/io/github/simplexdev/simplexcore/command/CommandLoader.java +++ b/src/main/java/io/github/simplexdev/simplexcore/command/CommandLoader.java @@ -2,7 +2,7 @@ package io.github.simplexdev.simplexcore.command; import io.github.simplexdev.api.annotations.CommandInfo; import io.github.simplexdev.simplexcore.command.defaults.DefaultCommand; -import io.github.simplexdev.simplexcore.plugin.SimplexAddon; +import io.github.simplexdev.simplexcore.module.SimplexModule; import io.github.simplexdev.simplexcore.utils.ReflectionTools; import org.bukkit.Bukkit; import org.bukkit.command.*; @@ -69,7 +69,7 @@ public final class CommandLoader { * * @param plugin An instance of your plugin to assign as the parent plugin for each command. */ - public void load(SimplexAddon plugin) { + public void load(SimplexModule plugin) { reflections.getTypesAnnotatedWith(CommandInfo.class).forEach(annotated -> { CommandInfo info = annotated.getDeclaredAnnotation(CommandInfo.class); diff --git a/src/main/java/io/github/simplexdev/simplexcore/config/Yaml.java b/src/main/java/io/github/simplexdev/simplexcore/config/Yaml.java index f79a941..5f423b7 100644 --- a/src/main/java/io/github/simplexdev/simplexcore/config/Yaml.java +++ b/src/main/java/io/github/simplexdev/simplexcore/config/Yaml.java @@ -3,7 +3,7 @@ package io.github.simplexdev.simplexcore.config; import io.github.simplexdev.api.IConfig; import io.github.simplexdev.api.func.Path; import io.github.simplexdev.simplexcore.SimplexCorePlugin; -import io.github.simplexdev.simplexcore.plugin.SimplexAddon; +import io.github.simplexdev.simplexcore.module.SimplexModule; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; @@ -14,7 +14,7 @@ import java.nio.file.NotDirectoryException; import java.util.List; public final class Yaml implements IConfig { - private final SimplexAddon plugin; + private final SimplexModule plugin; private final String fileName; private final File directory; private final String resourcePath; @@ -22,7 +22,7 @@ public final class Yaml implements IConfig { private File file; // Package private ;) - Yaml(SimplexAddon plugin, String fileName, File directory, String resourcePath) { + Yaml(SimplexModule plugin, String fileName, File directory, String resourcePath) { if (!fileName.endsWith(".yml")) { fileName += ".yml"; } diff --git a/src/main/java/io/github/simplexdev/simplexcore/config/YamlFactory.java b/src/main/java/io/github/simplexdev/simplexcore/config/YamlFactory.java index 6dc2748..86f0f60 100644 --- a/src/main/java/io/github/simplexdev/simplexcore/config/YamlFactory.java +++ b/src/main/java/io/github/simplexdev/simplexcore/config/YamlFactory.java @@ -1,6 +1,6 @@ package io.github.simplexdev.simplexcore.config; -import io.github.simplexdev.simplexcore.plugin.SimplexAddon; +import io.github.simplexdev.simplexcore.module.SimplexModule; import io.github.simplexdev.simplexcore.utils.Trio; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; @@ -8,12 +8,12 @@ import org.bukkit.configuration.file.YamlConfiguration; import java.io.File; public final class YamlFactory { - private final SimplexAddon plugin; + private final SimplexModule plugin; private String resourcePath; private File directory; private String fileName; - public YamlFactory(SimplexAddon plugin) { + public YamlFactory(SimplexModule plugin) { this.plugin = plugin; } diff --git a/src/main/java/io/github/simplexdev/simplexcore/enchanting/EnchUtils.java b/src/main/java/io/github/simplexdev/simplexcore/enchanting/EnchUtils.java new file mode 100644 index 0000000..20b5755 --- /dev/null +++ b/src/main/java/io/github/simplexdev/simplexcore/enchanting/EnchUtils.java @@ -0,0 +1,31 @@ +package io.github.simplexdev.simplexcore.enchanting; + +import io.github.simplexdev.api.annotations.Enchant; +import io.github.simplexdev.simplexcore.utils.ReflectionTools; +import org.bukkit.enchantments.EnchantmentWrapper; + +import java.lang.reflect.Constructor; + +public class EnchUtils { + public SimplexEnch enchantment; + + public void loadFrom(Class clz) { + Enchant info = clz.getDeclaredAnnotation(Enchant.class); + + if (info == null) { + // TODO + return; + } + + ReflectionTools.reflect(clz).getTypesAnnotatedWith(info).forEach(cls -> { + Constructor c = ReflectionTools.getDeclaredConstructor(cls); + if (c == null) return; + SimplexEnch ench = (SimplexEnch) ReflectionTools.initConstructor(c); + load(ench); + }); + } + + public void load(T enchantment) { + EnchantmentWrapper.registerEnchantment(enchantment); + } +} diff --git a/src/main/java/io/github/simplexdev/simplexcore/enchanting/SimplexEnch.java b/src/main/java/io/github/simplexdev/simplexcore/enchanting/SimplexEnch.java new file mode 100644 index 0000000..551f242 --- /dev/null +++ b/src/main/java/io/github/simplexdev/simplexcore/enchanting/SimplexEnch.java @@ -0,0 +1,12 @@ +package io.github.simplexdev.simplexcore.enchanting; + +import io.github.simplexdev.api.IEnchant; +import org.bukkit.NamespacedKey; +import org.bukkit.enchantments.Enchantment; +import org.jetbrains.annotations.NotNull; + +public abstract class SimplexEnch extends Enchantment implements IEnchant { + public SimplexEnch(@NotNull NamespacedKey key) { + super(key); + } +} diff --git a/src/main/java/io/github/simplexdev/simplexcore/gui/GUIHandler.java b/src/main/java/io/github/simplexdev/simplexcore/gui/GUIHandler.java index e58189e..744fcce 100644 --- a/src/main/java/io/github/simplexdev/simplexcore/gui/GUIHandler.java +++ b/src/main/java/io/github/simplexdev/simplexcore/gui/GUIHandler.java @@ -3,18 +3,17 @@ package io.github.simplexdev.simplexcore.gui; import io.github.simplexdev.api.func.ClickAction; import io.github.simplexdev.api.IGUI; import io.github.simplexdev.simplexcore.listener.SimplexListener; -import io.github.simplexdev.simplexcore.plugin.SimplexAddon; +import io.github.simplexdev.simplexcore.module.SimplexModule; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; -import org.bukkit.event.Listener; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryCloseEvent; import java.util.UUID; public final class GUIHandler extends SimplexListener { - public GUIHandler(SimplexAddon plugin) { + public GUIHandler(SimplexModule plugin) { register(this, plugin); } diff --git a/src/main/java/io/github/simplexdev/simplexcore/listener/SimplexListener.java b/src/main/java/io/github/simplexdev/simplexcore/listener/SimplexListener.java index 30e2332..ed09fd4 100644 --- a/src/main/java/io/github/simplexdev/simplexcore/listener/SimplexListener.java +++ b/src/main/java/io/github/simplexdev/simplexcore/listener/SimplexListener.java @@ -1,7 +1,7 @@ package io.github.simplexdev.simplexcore.listener; import io.github.simplexdev.simplexcore.SimplexCorePlugin; -import io.github.simplexdev.simplexcore.plugin.SimplexAddon; +import io.github.simplexdev.simplexcore.module.SimplexModule; import org.bukkit.event.Listener; import java.lang.reflect.Constructor; @@ -14,7 +14,7 @@ public abstract class SimplexListener implements Listener { * * @param cls The class to register. */ - public static void registerFromClass(Class cls, SimplexAddon plugin) { + public static void registerFromClass(Class cls, SimplexModule plugin) { if (!SimplexListener.class.isAssignableFrom(cls)) { SimplexCorePlugin.getInstance().getLogger().severe("You can only register subclasses of SimplexListener with this method."); return; @@ -35,7 +35,7 @@ public abstract class SimplexListener implements Listener { * @param plugin Your plugin instance * @param Type of which extends SimplexListener. */ - public static void register(T listener, SimplexAddon plugin) { + public static void register(T listener, SimplexModule plugin) { SimplexCorePlugin.getInstance().getManager().registerEvents(listener, plugin); } } diff --git a/src/main/java/io/github/simplexdev/simplexcore/plugin/DependencyManagement.java b/src/main/java/io/github/simplexdev/simplexcore/module/DependencyManagement.java similarity index 94% rename from src/main/java/io/github/simplexdev/simplexcore/plugin/DependencyManagement.java rename to src/main/java/io/github/simplexdev/simplexcore/module/DependencyManagement.java index 084e376..bed7c85 100644 --- a/src/main/java/io/github/simplexdev/simplexcore/plugin/DependencyManagement.java +++ b/src/main/java/io/github/simplexdev/simplexcore/module/DependencyManagement.java @@ -1,4 +1,4 @@ -package io.github.simplexdev.simplexcore.plugin; +package io.github.simplexdev.simplexcore.module; import com.comphenix.protocol.ProtocolLibrary; import com.comphenix.protocol.ProtocolManager; diff --git a/src/main/java/io/github/simplexdev/simplexcore/module/ModuleManager.java b/src/main/java/io/github/simplexdev/simplexcore/module/ModuleManager.java new file mode 100644 index 0000000..737ce30 --- /dev/null +++ b/src/main/java/io/github/simplexdev/simplexcore/module/ModuleManager.java @@ -0,0 +1,21 @@ +package io.github.simplexdev.simplexcore.module; + +import io.github.simplexdev.simplexcore.SimplexCorePlugin; + +public final class ModuleManager { + public ModuleManager() { + } + + public void disable(SimplexModule simplexModule) { + SimplexCorePlugin.getInstance().getManager().disablePlugin(simplexModule); + } + + public void enable(SimplexModule simplexModule) { + SimplexCorePlugin.getInstance().getManager().enablePlugin(simplexModule); + } + + public void reload(SimplexModule simplexModule) { + disable(simplexModule); + enable(simplexModule); + } +} diff --git a/src/main/java/io/github/simplexdev/simplexcore/plugin/AddonRegistry.java b/src/main/java/io/github/simplexdev/simplexcore/module/ModuleRegistry.java similarity index 74% rename from src/main/java/io/github/simplexdev/simplexcore/plugin/AddonRegistry.java rename to src/main/java/io/github/simplexdev/simplexcore/module/ModuleRegistry.java index 5f7a6fa..4b1b7a3 100644 --- a/src/main/java/io/github/simplexdev/simplexcore/plugin/AddonRegistry.java +++ b/src/main/java/io/github/simplexdev/simplexcore/module/ModuleRegistry.java @@ -1,4 +1,4 @@ -package io.github.simplexdev.simplexcore.plugin; +package io.github.simplexdev.simplexcore.module; import io.github.simplexdev.api.annotations.ReqType; import io.github.simplexdev.api.annotations.Requires; @@ -7,18 +7,18 @@ import io.github.simplexdev.simplexcore.SimplexCorePlugin; import java.util.HashSet; import java.util.Set; -public final class AddonRegistry { - private static final AddonRegistry instance = new AddonRegistry(); - private final Set> components = new HashSet<>(); +public final class ModuleRegistry { + private static final ModuleRegistry instance = new ModuleRegistry(); + private final Set> modules = new HashSet<>(); - protected AddonRegistry() { + protected ModuleRegistry() { } - public static synchronized AddonRegistry getInstance() { + public static synchronized ModuleRegistry getInstance() { return instance; } - public > boolean isPaper(T addon) { + public > boolean isPaper(T addon) { try { Class.forName(com.destroystokyo.paper.Namespaced.class.getName()); return true; @@ -29,7 +29,7 @@ public final class AddonRegistry { } } - private > boolean isBungee(T addon) { + private > boolean isBungee(T addon) { try { Class.forName(net.md_5.bungee.Util.class.getName()); return true; @@ -40,7 +40,7 @@ public final class AddonRegistry { } } - private > boolean isWaterfall(T addon) { + private > boolean isWaterfall(T addon) { try { Class.forName(io.github.waterfallmc.waterfall.utils.Hex.class.getName()); return true; @@ -55,7 +55,7 @@ public final class AddonRegistry { return info.value() == type; } - public > void register(T addon) { + public > void register(T addon) { if (addon.getClass().isAnnotationPresent(Requires.class)) { Requires info = addon.getClass().getDeclaredAnnotation(Requires.class); if (checkAnnotation(info, ReqType.PAPER) @@ -71,10 +71,10 @@ public final class AddonRegistry { return; } } - getComponents().add(addon); + getModules().add(addon); } - public Set> getComponents() { - return components; + public Set> getModules() { + return modules; } } \ No newline at end of file diff --git a/src/main/java/io/github/simplexdev/simplexcore/plugin/SimplexAddon.java b/src/main/java/io/github/simplexdev/simplexcore/module/SimplexModule.java similarity index 81% rename from src/main/java/io/github/simplexdev/simplexcore/plugin/SimplexAddon.java rename to src/main/java/io/github/simplexdev/simplexcore/module/SimplexModule.java index 564e052..1e91c4e 100644 --- a/src/main/java/io/github/simplexdev/simplexcore/plugin/SimplexAddon.java +++ b/src/main/java/io/github/simplexdev/simplexcore/module/SimplexModule.java @@ -1,20 +1,18 @@ -package io.github.simplexdev.simplexcore.plugin; +package io.github.simplexdev.simplexcore.module; import io.github.simplexdev.simplexcore.command.CommandLoader; import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.scheduler.BukkitScheduler; -import org.jetbrains.annotations.NotNull; import java.io.File; -import java.util.logging.Logger; /** * This class represents a SimplexCore module. * You should extend this instead of JavaPlugin if you are using the core as a dependency. * @param */ -public abstract class SimplexAddon> extends JavaPlugin { +public abstract class SimplexModule> extends JavaPlugin { /** * Gets your plugin as an addon. * @@ -65,8 +63,8 @@ public abstract class SimplexAddon> extends JavaPlugin return this.getDataFolder(); } - public synchronized AddonRegistry getRegistry() { - return AddonRegistry.getInstance(); + public synchronized ModuleRegistry getRegistry() { + return ModuleRegistry.getInstance(); } public synchronized CommandLoader getCommandLoader() { diff --git a/src/main/java/io/github/simplexdev/simplexcore/plugin/AddonManager.java b/src/main/java/io/github/simplexdev/simplexcore/plugin/AddonManager.java deleted file mode 100644 index efcb584..0000000 --- a/src/main/java/io/github/simplexdev/simplexcore/plugin/AddonManager.java +++ /dev/null @@ -1,21 +0,0 @@ -package io.github.simplexdev.simplexcore.plugin; - -import io.github.simplexdev.simplexcore.SimplexCorePlugin; - -public final class AddonManager { - public AddonManager() { - } - - public void disable(SimplexAddon simplexAddon) { - SimplexCorePlugin.getInstance().getManager().disablePlugin(simplexAddon); - } - - public void enable(SimplexAddon simplexAddon) { - SimplexCorePlugin.getInstance().getManager().enablePlugin(simplexAddon); - } - - public void reload(SimplexAddon simplexAddon) { - disable(simplexAddon); - enable(simplexAddon); - } -} diff --git a/src/main/java/io/github/simplexdev/simplexcore/sign/SignFactory.java b/src/main/java/io/github/simplexdev/simplexcore/sign/SignFactory.java index 1f5a657..b56feea 100644 --- a/src/main/java/io/github/simplexdev/simplexcore/sign/SignFactory.java +++ b/src/main/java/io/github/simplexdev/simplexcore/sign/SignFactory.java @@ -4,7 +4,7 @@ import io.github.simplexdev.api.IUsableSign; import io.github.simplexdev.api.func.VoidSupplier; import io.github.simplexdev.simplexcore.SimplexCorePlugin; import io.github.simplexdev.simplexcore.listener.SimplexListener; -import io.github.simplexdev.simplexcore.plugin.SimplexAddon; +import io.github.simplexdev.simplexcore.module.SimplexModule; import org.bukkit.Material; import org.bukkit.block.Sign; import org.bukkit.event.EventHandler; @@ -107,7 +107,7 @@ public class SignFactory { } private static class SignData extends SimplexListener { - public SignData(SimplexAddon plugin) { + public SignData(SimplexModule plugin) { register(this, plugin); } diff --git a/src/main/java/io/github/simplexdev/simplexcore/task/Announcer.java b/src/main/java/io/github/simplexdev/simplexcore/task/Announcer.java index 8d705cb..cac4bc8 100644 --- a/src/main/java/io/github/simplexdev/simplexcore/task/Announcer.java +++ b/src/main/java/io/github/simplexdev/simplexcore/task/Announcer.java @@ -2,6 +2,7 @@ package io.github.simplexdev.simplexcore.task; import io.github.simplexdev.simplexcore.SimplexCorePlugin; import io.github.simplexdev.simplexcore.chat.Messages; +import io.github.simplexdev.simplexcore.utils.TickedTime; import org.apache.commons.lang.math.RandomUtils; import org.bukkit.Bukkit; import org.bukkit.scheduler.BukkitTask; @@ -18,7 +19,7 @@ public class Announcer extends SimplexTask { }}; public Announcer() { - super(20L); + super(TickedTime.HOUR); register(this, SimplexCorePlugin.getInstance(), true, false); } diff --git a/src/main/java/io/github/simplexdev/simplexcore/task/SimplexTask.java b/src/main/java/io/github/simplexdev/simplexcore/task/SimplexTask.java index 387401a..b540096 100644 --- a/src/main/java/io/github/simplexdev/simplexcore/task/SimplexTask.java +++ b/src/main/java/io/github/simplexdev/simplexcore/task/SimplexTask.java @@ -2,7 +2,7 @@ package io.github.simplexdev.simplexcore.task; import io.github.simplexdev.api.func.VoidSupplier; import io.github.simplexdev.simplexcore.SimplexCorePlugin; -import io.github.simplexdev.simplexcore.plugin.SimplexAddon; +import io.github.simplexdev.simplexcore.module.SimplexModule; import io.github.simplexdev.simplexcore.utils.TickedTime; import org.bukkit.scheduler.BukkitTask; @@ -61,7 +61,7 @@ public abstract class SimplexTask implements Consumer { * @param delayed Whether or not to delay the first time the task runs. * @param A subclass of SimplexTask. */ - public void register(T task, SimplexAddon plugin, boolean repeating, boolean delayed) { + public void register(T task, SimplexModule plugin, boolean repeating, boolean delayed) { if (delayed && repeating) { SimplexCorePlugin.getInstance().getScheduler().runTaskTimer(plugin, task, DELAY, INTERVAL); } else if (delayed) { @@ -84,7 +84,7 @@ public abstract class SimplexTask implements Consumer { * @param delayed Whether or not to delay the start of the task. * @param A subclass of SimplexTask. */ - public void register(T task, SimplexAddon plugin, boolean delayed) { + public void register(T task, SimplexModule plugin, boolean delayed) { register(task, plugin, false, delayed); } @@ -97,7 +97,7 @@ public abstract class SimplexTask implements Consumer { * @param plugin Your plugin instance. * @param A subclass of SimplexTask. */ - public void register(T task, SimplexAddon plugin) { + public void register(T task, SimplexModule plugin) { register(task, plugin, false, false); }