BLEEDING EDGE 1.3_11

- Rename Addon to Module
 - Adjusted announcer to run every hour
 - Added Enchanting API, incomplete
This commit is contained in:
Paldiu 2021-03-23 23:36:28 -05:00
parent 71789fa39f
commit 99c19f0ff7
19 changed files with 132 additions and 66 deletions

View File

@ -1,5 +1,5 @@
pluginMain=SimplexCorePlugin pluginMain=SimplexCorePlugin
pluginMainPackage=io.github.simplexdev.simplexcore pluginMainPackage=io.github.simplexdev.simplexcore
pluginVersion=1.3_10 pluginVersion=1.3_11
pluginName=SimplexCore pluginName=SimplexCore
pluginJarClassifier=BLEEDING pluginJarClassifier=BLEEDING

View File

@ -0,0 +1,13 @@
package io.github.simplexdev.api;
import org.bukkit.NamespacedKey;
public interface IEnchant {
NamespacedKey getNamespacedKey();
String getName();
Integer getMaximumLevel();
Boolean isGlowing();
}

View File

@ -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;
}

View File

@ -3,13 +3,13 @@ package io.github.simplexdev.simplexcore;
import io.github.simplexdev.simplexcore.command.defaults.Command_info; import io.github.simplexdev.simplexcore.command.defaults.Command_info;
import io.github.simplexdev.simplexcore.config.Yaml; import io.github.simplexdev.simplexcore.config.Yaml;
import io.github.simplexdev.simplexcore.config.YamlFactory; 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.task.Announcer;
import io.github.simplexdev.simplexcore.listener.DependencyListener; import io.github.simplexdev.simplexcore.listener.DependencyListener;
import io.github.simplexdev.simplexcore.listener.SimplexListener; 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<SimplexCorePlugin> { public final class SimplexCorePlugin extends SimplexModule<SimplexCorePlugin> {
private static boolean debug = false; private static boolean debug = false;
private static boolean suspended = false; private static boolean suspended = false;
private static SimplexCorePlugin instance; private static SimplexCorePlugin instance;

View File

@ -2,7 +2,7 @@ package io.github.simplexdev.simplexcore.command;
import io.github.simplexdev.api.annotations.CommandInfo; import io.github.simplexdev.api.annotations.CommandInfo;
import io.github.simplexdev.simplexcore.command.defaults.DefaultCommand; 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 io.github.simplexdev.simplexcore.utils.ReflectionTools;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.command.*; 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. * @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 -> { reflections.getTypesAnnotatedWith(CommandInfo.class).forEach(annotated -> {
CommandInfo info = annotated.getDeclaredAnnotation(CommandInfo.class); CommandInfo info = annotated.getDeclaredAnnotation(CommandInfo.class);

View File

@ -3,7 +3,7 @@ package io.github.simplexdev.simplexcore.config;
import io.github.simplexdev.api.IConfig; import io.github.simplexdev.api.IConfig;
import io.github.simplexdev.api.func.Path; import io.github.simplexdev.api.func.Path;
import io.github.simplexdev.simplexcore.SimplexCorePlugin; 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.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
@ -14,7 +14,7 @@ import java.nio.file.NotDirectoryException;
import java.util.List; import java.util.List;
public final class Yaml implements IConfig { public final class Yaml implements IConfig {
private final SimplexAddon<?> plugin; private final SimplexModule<?> plugin;
private final String fileName; private final String fileName;
private final File directory; private final File directory;
private final String resourcePath; private final String resourcePath;
@ -22,7 +22,7 @@ public final class Yaml implements IConfig {
private File file; private File file;
// Package private ;) // Package private ;)
Yaml(SimplexAddon<?> plugin, String fileName, File directory, String resourcePath) { Yaml(SimplexModule<?> plugin, String fileName, File directory, String resourcePath) {
if (!fileName.endsWith(".yml")) { if (!fileName.endsWith(".yml")) {
fileName += ".yml"; fileName += ".yml";
} }

View File

@ -1,6 +1,6 @@
package io.github.simplexdev.simplexcore.config; 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 io.github.simplexdev.simplexcore.utils.Trio;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
@ -8,12 +8,12 @@ import org.bukkit.configuration.file.YamlConfiguration;
import java.io.File; import java.io.File;
public final class YamlFactory { public final class YamlFactory {
private final SimplexAddon<?> plugin; private final SimplexModule<?> plugin;
private String resourcePath; private String resourcePath;
private File directory; private File directory;
private String fileName; private String fileName;
public YamlFactory(SimplexAddon<?> plugin) { public YamlFactory(SimplexModule<?> plugin) {
this.plugin = plugin; this.plugin = plugin;
} }

View File

@ -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 <T extends SimplexEnch> void loadFrom(Class<T> 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 <T extends SimplexEnch> void load(T enchantment) {
EnchantmentWrapper.registerEnchantment(enchantment);
}
}

View File

@ -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);
}
}

View File

@ -3,18 +3,17 @@ package io.github.simplexdev.simplexcore.gui;
import io.github.simplexdev.api.func.ClickAction; import io.github.simplexdev.api.func.ClickAction;
import io.github.simplexdev.api.IGUI; import io.github.simplexdev.api.IGUI;
import io.github.simplexdev.simplexcore.listener.SimplexListener; 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.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent; import org.bukkit.event.inventory.InventoryCloseEvent;
import java.util.UUID; import java.util.UUID;
public final class GUIHandler extends SimplexListener { public final class GUIHandler extends SimplexListener {
public GUIHandler(SimplexAddon<?> plugin) { public GUIHandler(SimplexModule<?> plugin) {
register(this, plugin); register(this, plugin);
} }

View File

@ -1,7 +1,7 @@
package io.github.simplexdev.simplexcore.listener; package io.github.simplexdev.simplexcore.listener;
import io.github.simplexdev.simplexcore.SimplexCorePlugin; 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 org.bukkit.event.Listener;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
@ -14,7 +14,7 @@ public abstract class SimplexListener implements Listener {
* *
* @param cls The class to register. * @param cls The class to register.
*/ */
public static void registerFromClass(Class<? extends SimplexListener> cls, SimplexAddon<?> plugin) { public static void registerFromClass(Class<? extends SimplexListener> cls, SimplexModule<?> plugin) {
if (!SimplexListener.class.isAssignableFrom(cls)) { if (!SimplexListener.class.isAssignableFrom(cls)) {
SimplexCorePlugin.getInstance().getLogger().severe("You can only register subclasses of SimplexListener with this method."); SimplexCorePlugin.getInstance().getLogger().severe("You can only register subclasses of SimplexListener with this method.");
return; return;
@ -35,7 +35,7 @@ public abstract class SimplexListener implements Listener {
* @param plugin Your plugin instance * @param plugin Your plugin instance
* @param <T> Type of which extends SimplexListener. * @param <T> Type of which extends SimplexListener.
*/ */
public static <T extends SimplexListener> void register(T listener, SimplexAddon<?> plugin) { public static <T extends SimplexListener> void register(T listener, SimplexModule<?> plugin) {
SimplexCorePlugin.getInstance().getManager().registerEvents(listener, plugin); SimplexCorePlugin.getInstance().getManager().registerEvents(listener, plugin);
} }
} }

View File

@ -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.ProtocolLibrary;
import com.comphenix.protocol.ProtocolManager; import com.comphenix.protocol.ProtocolManager;

View File

@ -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);
}
}

View File

@ -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.ReqType;
import io.github.simplexdev.api.annotations.Requires; import io.github.simplexdev.api.annotations.Requires;
@ -7,18 +7,18 @@ import io.github.simplexdev.simplexcore.SimplexCorePlugin;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
public final class AddonRegistry { public final class ModuleRegistry {
private static final AddonRegistry instance = new AddonRegistry(); private static final ModuleRegistry instance = new ModuleRegistry();
private final Set<SimplexAddon<?>> components = new HashSet<>(); private final Set<SimplexModule<?>> modules = new HashSet<>();
protected AddonRegistry() { protected ModuleRegistry() {
} }
public static synchronized AddonRegistry getInstance() { public static synchronized ModuleRegistry getInstance() {
return instance; return instance;
} }
public <T extends SimplexAddon<T>> boolean isPaper(T addon) { public <T extends SimplexModule<T>> boolean isPaper(T addon) {
try { try {
Class.forName(com.destroystokyo.paper.Namespaced.class.getName()); Class.forName(com.destroystokyo.paper.Namespaced.class.getName());
return true; return true;
@ -29,7 +29,7 @@ public final class AddonRegistry {
} }
} }
private <T extends SimplexAddon<T>> boolean isBungee(T addon) { private <T extends SimplexModule<T>> boolean isBungee(T addon) {
try { try {
Class.forName(net.md_5.bungee.Util.class.getName()); Class.forName(net.md_5.bungee.Util.class.getName());
return true; return true;
@ -40,7 +40,7 @@ public final class AddonRegistry {
} }
} }
private <T extends SimplexAddon<T>> boolean isWaterfall(T addon) { private <T extends SimplexModule<T>> boolean isWaterfall(T addon) {
try { try {
Class.forName(io.github.waterfallmc.waterfall.utils.Hex.class.getName()); Class.forName(io.github.waterfallmc.waterfall.utils.Hex.class.getName());
return true; return true;
@ -55,7 +55,7 @@ public final class AddonRegistry {
return info.value() == type; return info.value() == type;
} }
public <T extends SimplexAddon<T>> void register(T addon) { public <T extends SimplexModule<T>> void register(T addon) {
if (addon.getClass().isAnnotationPresent(Requires.class)) { if (addon.getClass().isAnnotationPresent(Requires.class)) {
Requires info = addon.getClass().getDeclaredAnnotation(Requires.class); Requires info = addon.getClass().getDeclaredAnnotation(Requires.class);
if (checkAnnotation(info, ReqType.PAPER) if (checkAnnotation(info, ReqType.PAPER)
@ -71,10 +71,10 @@ public final class AddonRegistry {
return; return;
} }
} }
getComponents().add(addon); getModules().add(addon);
} }
public Set<SimplexAddon<?>> getComponents() { public Set<SimplexModule<?>> getModules() {
return components; return modules;
} }
} }

View File

@ -1,20 +1,18 @@
package io.github.simplexdev.simplexcore.plugin; package io.github.simplexdev.simplexcore.module;
import io.github.simplexdev.simplexcore.command.CommandLoader; import io.github.simplexdev.simplexcore.command.CommandLoader;
import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitScheduler; import org.bukkit.scheduler.BukkitScheduler;
import org.jetbrains.annotations.NotNull;
import java.io.File; import java.io.File;
import java.util.logging.Logger;
/** /**
* This class represents a SimplexCore module. * This class represents a SimplexCore module.
* You should extend this instead of JavaPlugin if you are using the core as a dependency. * You should extend this instead of JavaPlugin if you are using the core as a dependency.
* @param <T> * @param <T>
*/ */
public abstract class SimplexAddon<T extends SimplexAddon<T>> extends JavaPlugin { public abstract class SimplexModule<T extends SimplexModule<T>> extends JavaPlugin {
/** /**
* Gets your plugin as an addon. * Gets your plugin as an addon.
* *
@ -65,8 +63,8 @@ public abstract class SimplexAddon<T extends SimplexAddon<T>> extends JavaPlugin
return this.getDataFolder(); return this.getDataFolder();
} }
public synchronized AddonRegistry getRegistry() { public synchronized ModuleRegistry getRegistry() {
return AddonRegistry.getInstance(); return ModuleRegistry.getInstance();
} }
public synchronized CommandLoader getCommandLoader() { public synchronized CommandLoader getCommandLoader() {

View File

@ -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);
}
}

View File

@ -4,7 +4,7 @@ import io.github.simplexdev.api.IUsableSign;
import io.github.simplexdev.api.func.VoidSupplier; import io.github.simplexdev.api.func.VoidSupplier;
import io.github.simplexdev.simplexcore.SimplexCorePlugin; import io.github.simplexdev.simplexcore.SimplexCorePlugin;
import io.github.simplexdev.simplexcore.listener.SimplexListener; 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.Material;
import org.bukkit.block.Sign; import org.bukkit.block.Sign;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
@ -107,7 +107,7 @@ public class SignFactory {
} }
private static class SignData extends SimplexListener { private static class SignData extends SimplexListener {
public SignData(SimplexAddon<?> plugin) { public SignData(SimplexModule<?> plugin) {
register(this, plugin); register(this, plugin);
} }

View File

@ -2,6 +2,7 @@ package io.github.simplexdev.simplexcore.task;
import io.github.simplexdev.simplexcore.SimplexCorePlugin; import io.github.simplexdev.simplexcore.SimplexCorePlugin;
import io.github.simplexdev.simplexcore.chat.Messages; import io.github.simplexdev.simplexcore.chat.Messages;
import io.github.simplexdev.simplexcore.utils.TickedTime;
import org.apache.commons.lang.math.RandomUtils; import org.apache.commons.lang.math.RandomUtils;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.scheduler.BukkitTask; import org.bukkit.scheduler.BukkitTask;
@ -18,7 +19,7 @@ public class Announcer extends SimplexTask {
}}; }};
public Announcer() { public Announcer() {
super(20L); super(TickedTime.HOUR);
register(this, SimplexCorePlugin.getInstance(), true, false); register(this, SimplexCorePlugin.getInstance(), true, false);
} }

View File

@ -2,7 +2,7 @@ package io.github.simplexdev.simplexcore.task;
import io.github.simplexdev.api.func.VoidSupplier; import io.github.simplexdev.api.func.VoidSupplier;
import io.github.simplexdev.simplexcore.SimplexCorePlugin; 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 io.github.simplexdev.simplexcore.utils.TickedTime;
import org.bukkit.scheduler.BukkitTask; import org.bukkit.scheduler.BukkitTask;
@ -61,7 +61,7 @@ public abstract class SimplexTask implements Consumer<BukkitTask> {
* @param delayed Whether or not to delay the first time the task runs. * @param delayed Whether or not to delay the first time the task runs.
* @param <T> A subclass of SimplexTask. * @param <T> A subclass of SimplexTask.
*/ */
public <T extends SimplexTask> void register(T task, SimplexAddon<?> plugin, boolean repeating, boolean delayed) { public <T extends SimplexTask> void register(T task, SimplexModule<?> plugin, boolean repeating, boolean delayed) {
if (delayed && repeating) { if (delayed && repeating) {
SimplexCorePlugin.getInstance().getScheduler().runTaskTimer(plugin, task, DELAY, INTERVAL); SimplexCorePlugin.getInstance().getScheduler().runTaskTimer(plugin, task, DELAY, INTERVAL);
} else if (delayed) { } else if (delayed) {
@ -84,7 +84,7 @@ public abstract class SimplexTask implements Consumer<BukkitTask> {
* @param delayed Whether or not to delay the start of the task. * @param delayed Whether or not to delay the start of the task.
* @param <T> A subclass of SimplexTask. * @param <T> A subclass of SimplexTask.
*/ */
public <T extends SimplexTask> void register(T task, SimplexAddon<?> plugin, boolean delayed) { public <T extends SimplexTask> void register(T task, SimplexModule<?> plugin, boolean delayed) {
register(task, plugin, false, delayed); register(task, plugin, false, delayed);
} }
@ -97,7 +97,7 @@ public abstract class SimplexTask implements Consumer<BukkitTask> {
* @param plugin Your plugin instance. * @param plugin Your plugin instance.
* @param <T> A subclass of SimplexTask. * @param <T> A subclass of SimplexTask.
*/ */
public <T extends SimplexTask> void register(T task, SimplexAddon<?> plugin) { public <T extends SimplexTask> void register(T task, SimplexModule<?> plugin) {
register(task, plugin, false, false); register(task, plugin, false, false);
} }