From 98d7ffafe3313d10367c4fb6a4d2456457dac504 Mon Sep 17 00:00:00 2001 From: Paul Reilly Date: Fri, 12 May 2023 21:19:35 -0500 Subject: [PATCH] Update content --- .gitignore | 12 ++- .../me/totalfreedom/admin/AdminManager.java | 27 ------ .../me/totalfreedom/admin/Administrator.java | 22 ----- .../java/me/totalfreedom/api/Context.java | 84 ++++++++++++------- .../me/totalfreedom/api/Interruptable.java | 10 --- .../me/totalfreedom/api/Serializable.java | 15 ++++ .../me/totalfreedom/base/CommonsBase.java | 33 ++------ .../totalfreedom/base/CommonsJavaPlugin.java | 24 ------ .../me/totalfreedom/base/Registration.java | 25 ++---- .../me/totalfreedom/data/CommandRegistry.java | 11 +-- .../me/totalfreedom/data/EventRegistry.java | 34 ++++++++ .../me/totalfreedom/data/ModuleRegistry.java | 83 ++++-------------- .../me/totalfreedom/data/ServiceRegistry.java | 59 +++++++++++++ .../java/me/totalfreedom/event/EventBus.java | 36 +++++--- .../java/me/totalfreedom/event/FEvent.java | 11 ++- .../java/me/totalfreedom/module/Module.java | 28 ------- .../totalfreedom/provider/EventProvider.java | 9 ++ .../totalfreedom/provider/ModuleProvider.java | 9 ++ .../provider/ServiceProvider.java | 8 ++ .../{permission => security}/Group.java | 2 +- .../{permission => security}/Node.java | 7 +- .../{permission => security}/NodeBuilder.java | 2 +- .../{permission => security}/NodeType.java | 2 +- .../PermissionHolder.java | 5 +- .../totalfreedom/security/Verification.java | 12 --- .../java/me/totalfreedom/service/Service.java | 16 ++++ .../{FreedomService.java => Task.java} | 2 +- .../main/java/me/totalfreedom/sql/SQL.java | 6 -- .../me/totalfreedom/sql/SQLProperties.java | 9 +- .../main/java/me/totalfreedom/user/User.java | 4 +- 30 files changed, 300 insertions(+), 307 deletions(-) delete mode 100644 Commons/src/main/java/me/totalfreedom/admin/AdminManager.java delete mode 100644 Commons/src/main/java/me/totalfreedom/admin/Administrator.java delete mode 100644 Commons/src/main/java/me/totalfreedom/api/Interruptable.java create mode 100644 Commons/src/main/java/me/totalfreedom/api/Serializable.java delete mode 100644 Commons/src/main/java/me/totalfreedom/base/CommonsJavaPlugin.java delete mode 100644 Commons/src/main/java/me/totalfreedom/module/Module.java create mode 100644 Commons/src/main/java/me/totalfreedom/provider/EventProvider.java create mode 100644 Commons/src/main/java/me/totalfreedom/provider/ModuleProvider.java create mode 100644 Commons/src/main/java/me/totalfreedom/provider/ServiceProvider.java rename Commons/src/main/java/me/totalfreedom/{permission => security}/Group.java (87%) rename Commons/src/main/java/me/totalfreedom/{permission => security}/Node.java (73%) rename Commons/src/main/java/me/totalfreedom/{permission => security}/NodeBuilder.java (88%) rename Commons/src/main/java/me/totalfreedom/{permission => security}/NodeType.java (72%) rename Commons/src/main/java/me/totalfreedom/{permission => security}/PermissionHolder.java (71%) delete mode 100644 Commons/src/main/java/me/totalfreedom/security/Verification.java create mode 100644 Commons/src/main/java/me/totalfreedom/service/Service.java rename Commons/src/main/java/me/totalfreedom/service/{FreedomService.java => Task.java} (88%) diff --git a/.gitignore b/.gitignore index 88f99a3..4a5c692 100644 --- a/.gitignore +++ b/.gitignore @@ -42,4 +42,14 @@ bin/ .DS_Store .idea -/gradle \ No newline at end of file +/gradle +.idea/codeStyles/codeStyleConfig.xml +.idea/codeStyles/Project.xml +.idea/dbnavigator.xml +.idea/gradle.xml +.idea/inspectionProfiles/Project_Default.xml +.idea/misc.xml +.idea/sonarlint/issuestore/index.pb +.idea/sonarlint/securityhotspotstore/index.pb +.idea/uiDesigner.xml +.idea/vcs.xml diff --git a/Commons/src/main/java/me/totalfreedom/admin/AdminManager.java b/Commons/src/main/java/me/totalfreedom/admin/AdminManager.java deleted file mode 100644 index 5e9a37c..0000000 --- a/Commons/src/main/java/me/totalfreedom/admin/AdminManager.java +++ /dev/null @@ -1,27 +0,0 @@ -package me.totalfreedom.admin; - -import me.totalfreedom.permission.Group; -import me.totalfreedom.permission.Node; - -import java.util.Map; -import java.util.Set; -import java.util.UUID; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; - -public interface AdminManager -{ - Map getAdminMap(); - - Administrator getAdmin(UUID uuid); - - Administrator getAdmin(String name); - - Set getAdminsWithPermissions(Node... nodes); - - void addAdmin(Administrator admin); - - void removeAdmin(Administrator admin); - - CompletableFuture saveAdmin(Administrator admin, Consumer callback); -} diff --git a/Commons/src/main/java/me/totalfreedom/admin/Administrator.java b/Commons/src/main/java/me/totalfreedom/admin/Administrator.java deleted file mode 100644 index f7a9346..0000000 --- a/Commons/src/main/java/me/totalfreedom/admin/Administrator.java +++ /dev/null @@ -1,22 +0,0 @@ -package me.totalfreedom.admin; - -import me.totalfreedom.permission.Group; -import me.totalfreedom.permission.PermissionHolder; -import net.kyori.adventure.text.Component; -import org.bukkit.permissions.PermissionAttachment; - -import java.util.List; -import java.util.UUID; - -public interface Administrator extends Group -{ - boolean isActive(); - - void setActive(boolean active); - - void setWeight(int weight); - - Component getLoginMessage(); - - void setLoginMessage(Component loginMessage); -} diff --git a/Commons/src/main/java/me/totalfreedom/api/Context.java b/Commons/src/main/java/me/totalfreedom/api/Context.java index 5019e36..e5c870f 100644 --- a/Commons/src/main/java/me/totalfreedom/api/Context.java +++ b/Commons/src/main/java/me/totalfreedom/api/Context.java @@ -16,78 +16,106 @@ public interface Context { T get(); - default @Nullable Player asPlayer() { - if (get() instanceof Player player) { + default @Nullable Player asPlayer() + { + if (get() instanceof Player player) + { return player; - } else { + } else + { return null; } } - default @Nullable CommandSender asCommandSender() { - if (get() instanceof CommandSender commandSender) { + default @Nullable CommandSender asCommandSender() + { + if (get() instanceof CommandSender commandSender) + { return commandSender; - } else { + } else + { return null; } } - default @NotNull String asLiteral() { + default @NotNull String asLiteral() + { return get().toString(); } - default @Nullable World asWorld() { - if (get() instanceof World world) { + default @Nullable World asWorld() + { + if (get() instanceof World world) + { return world; - } else { + } else + { return null; } } - default @Nullable Location asLocation() { - if (get() instanceof Location location) { + default @Nullable Location asLocation() + { + if (get() instanceof Location location) + { return location; - } else { + } else + { return null; } } - default @Nullable LivingEntity asLivingEntity() { - if (get() instanceof LivingEntity livingEntity) { + default @Nullable LivingEntity asLivingEntity() + { + if (get() instanceof LivingEntity livingEntity) + { return livingEntity; - } else { + } else + { return null; } } - default @Nullable Component asComponent() { - if (get() instanceof Component component) { + default @Nullable Component asComponent() + { + if (get() instanceof Component component) + { return component; - } else { + } else + { return null; } } - default @Nullable Projectile asProjectile() { - if (get() instanceof Projectile projectile) { + default @Nullable Projectile asProjectile() + { + if (get() instanceof Projectile projectile) + { return projectile; - } else { + } else + { return null; } } - default @Nullable Action asAction() { - if (get() instanceof Action action) { + default @Nullable Action asAction() + { + if (get() instanceof Action action) + { return action; - } else { + } else + { return null; } } - default @Nullable U asCustom(Class clazz) { - if (clazz.isInstance(get())) { + default @Nullable U asCustom(Class clazz) + { + if (clazz.isInstance(get())) + { return clazz.cast(get()); - } else { + } else + { return null; } } diff --git a/Commons/src/main/java/me/totalfreedom/api/Interruptable.java b/Commons/src/main/java/me/totalfreedom/api/Interruptable.java deleted file mode 100644 index 66a9e13..0000000 --- a/Commons/src/main/java/me/totalfreedom/api/Interruptable.java +++ /dev/null @@ -1,10 +0,0 @@ -package me.totalfreedom.api; - -import java.util.function.Consumer; - -public interface Interruptable -{ - boolean canInterrupt(); - - void interrupt(Consumer callback); -} diff --git a/Commons/src/main/java/me/totalfreedom/api/Serializable.java b/Commons/src/main/java/me/totalfreedom/api/Serializable.java new file mode 100644 index 0000000..499841b --- /dev/null +++ b/Commons/src/main/java/me/totalfreedom/api/Serializable.java @@ -0,0 +1,15 @@ +package me.totalfreedom.api; + +public interface Serializable +{ + /** + * Serialize an object to a string. + * Ideally, this should serialize to an SQL query for easy data transfer. + * + * @param object The object to serialize + * @return The serialized object + */ + String serialize(T object); + + T deserialize(Context... contexts); +} diff --git a/Commons/src/main/java/me/totalfreedom/base/CommonsBase.java b/Commons/src/main/java/me/totalfreedom/base/CommonsBase.java index d593616..fb9d489 100644 --- a/Commons/src/main/java/me/totalfreedom/base/CommonsBase.java +++ b/Commons/src/main/java/me/totalfreedom/base/CommonsBase.java @@ -1,52 +1,37 @@ package me.totalfreedom.base; import me.totalfreedom.event.EventBus; -import me.totalfreedom.module.Module; -import me.totalfreedom.utils.Identity; import org.bukkit.Bukkit; import org.bukkit.plugin.RegisteredServiceProvider; import org.bukkit.plugin.ServicePriority; import org.bukkit.plugin.java.JavaPlugin; -public class CommonsBase implements Module +public class CommonsBase extends JavaPlugin { private final EventBus eventBus = new EventBus(this); + public static CommonsBase getInstance() + { + return JavaPlugin.getPlugin(CommonsBase.class); + } @Override - public void enable() + public void onEnable() { Bukkit.getServicesManager().register(EventBus.class, eventBus, - JavaPlugin.getPlugin(CommonsJavaPlugin.class), + this, ServicePriority.High); } @Override - public void disable() + public void onDisable() { } - @Override - public Identity getIdentity() + public RegisteredServiceProvider getEventBus() { - return null; - } - - @Override - public Class getRuntimeClass() - { - return CommonsBase.class; - } - - @Override - public CommonsBase getRuntimeInstance() - { - return this; - } - - public RegisteredServiceProvider getEventBus() { return Bukkit.getServicesManager().getRegistration(EventBus.class); } } diff --git a/Commons/src/main/java/me/totalfreedom/base/CommonsJavaPlugin.java b/Commons/src/main/java/me/totalfreedom/base/CommonsJavaPlugin.java deleted file mode 100644 index e84f06f..0000000 --- a/Commons/src/main/java/me/totalfreedom/base/CommonsJavaPlugin.java +++ /dev/null @@ -1,24 +0,0 @@ -package me.totalfreedom.base; - -import org.bukkit.plugin.java.JavaPlugin; - -import java.io.File; - -public class CommonsJavaPlugin extends JavaPlugin -{ - private final File moduleFolder = new File(getDataFolder(), "modules"); - - @Override - public void onEnable() - { - - } - - @Override - public void onDisable() - { - Registration.getInstance() - .getModuleRegistry() - .unloadModules(moduleFolder); - } -} diff --git a/Commons/src/main/java/me/totalfreedom/base/Registration.java b/Commons/src/main/java/me/totalfreedom/base/Registration.java index ea44dbf..65195fa 100644 --- a/Commons/src/main/java/me/totalfreedom/base/Registration.java +++ b/Commons/src/main/java/me/totalfreedom/base/Registration.java @@ -1,32 +1,23 @@ package me.totalfreedom.base; -import me.totalfreedom.data.*; +import me.totalfreedom.data.CommandRegistry; +import me.totalfreedom.data.EventRegistry; +import me.totalfreedom.data.ServiceRegistry; +import me.totalfreedom.data.UserRegistry; public class Registration { - private static final Registration INSTANCE = new Registration(); - private final ModuleRegistry moduleRegistry; private final CommandRegistry commandRegistry; private final EventRegistry eventRegistry; private final UserRegistry userRegistry; private final ServiceRegistry serviceRegistry; - private Registration() { + public Registration() + { this.commandRegistry = new CommandRegistry(); this.eventRegistry = new EventRegistry(); this.userRegistry = new UserRegistry(); this.serviceRegistry = new ServiceRegistry(); - this.moduleRegistry = new ModuleRegistry(); - } - - public static Registration getInstance() - { - return INSTANCE; - } - - public ModuleRegistry getModuleRegistry() - { - return moduleRegistry; } public CommandRegistry getCommandRegistry() @@ -48,8 +39,4 @@ public class Registration { return serviceRegistry; } - - public CommonsBase getCommonsBase() { - return getModuleRegistry().getModule(CommonsBase.class); - } } diff --git a/Commons/src/main/java/me/totalfreedom/data/CommandRegistry.java b/Commons/src/main/java/me/totalfreedom/data/CommandRegistry.java index 2d9513f..a766969 100644 --- a/Commons/src/main/java/me/totalfreedom/data/CommandRegistry.java +++ b/Commons/src/main/java/me/totalfreedom/data/CommandRegistry.java @@ -1,8 +1,7 @@ package me.totalfreedom.data; import co.aikar.commands.*; -import me.totalfreedom.base.CommonsJavaPlugin; -import org.bukkit.plugin.java.JavaPlugin; +import me.totalfreedom.base.CommonsBase; public class CommandRegistry { @@ -16,7 +15,7 @@ public class CommandRegistry public CommandRegistry() { - this.manager = new PaperCommandManager(JavaPlugin.getPlugin(CommonsJavaPlugin.class)); + this.manager = new PaperCommandManager(CommonsBase.getInstance()); this.contexts = new PaperCommandContexts(manager); this.completions = new PaperCommandCompletions(manager); this.replacements = manager.getCommandReplacements(); @@ -50,11 +49,13 @@ public class CommandRegistry return conditions; } - public void register(BaseCommand cmd) { + public void register(BaseCommand cmd) + { manager.registerCommand(cmd); } - public void unregister(BaseCommand cmd) { + public void unregister(BaseCommand cmd) + { manager.unregisterCommand(cmd); } } diff --git a/Commons/src/main/java/me/totalfreedom/data/EventRegistry.java b/Commons/src/main/java/me/totalfreedom/data/EventRegistry.java index 610aff7..ae0f0f1 100644 --- a/Commons/src/main/java/me/totalfreedom/data/EventRegistry.java +++ b/Commons/src/main/java/me/totalfreedom/data/EventRegistry.java @@ -1,5 +1,39 @@ package me.totalfreedom.data; +import me.totalfreedom.event.FEvent; +import me.totalfreedom.provider.EventProvider; + +import java.util.ArrayList; +import java.util.List; + public class EventRegistry { + private final List events; + + public EventRegistry() + { + this.events = new ArrayList<>(); + } + + public void register(final FEvent event) + { + this.events.add(event); + } + + public void unregister(final FEvent event) + { + this.events.remove(event); + } + + public EventProvider getEvent(final Class clazz) + { + for (final FEvent event : this.events) + { + if (clazz.isInstance(event)) + { + return () -> (T) event; + } + } + return null; + } } diff --git a/Commons/src/main/java/me/totalfreedom/data/ModuleRegistry.java b/Commons/src/main/java/me/totalfreedom/data/ModuleRegistry.java index f242103..1fd11d2 100644 --- a/Commons/src/main/java/me/totalfreedom/data/ModuleRegistry.java +++ b/Commons/src/main/java/me/totalfreedom/data/ModuleRegistry.java @@ -1,89 +1,40 @@ package me.totalfreedom.data; -import me.totalfreedom.module.Module; -import org.yaml.snakeyaml.Yaml; +import me.totalfreedom.provider.ModuleProvider; +import org.bukkit.plugin.java.JavaPlugin; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.net.URL; -import java.net.URLClassLoader; -import java.nio.file.InvalidPathException; -import java.util.*; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.CompletionException; -import java.util.jar.JarEntry; -import java.util.jar.JarFile; +import java.util.ArrayList; +import java.util.List; public class ModuleRegistry { - private final Set> moduleSet; + private final List plugins; public ModuleRegistry() { - this.moduleSet = new HashSet<>(); + this.plugins = new ArrayList<>(); } - public Set> getModuleSet() + public void addModule(final JavaPlugin plugin) { - return moduleSet; - } - - public void addModule(Module module) - { - moduleSet.add(module); - } - - public void removeModule(Module module) - { - moduleSet.remove(module); + if (this.plugins.contains(plugin)) + { + return; + } + this.plugins.add(plugin); } @SuppressWarnings("unchecked") - public T getModule(Class clazz) + public ModuleProvider getModule(Class clazz) { - for (Module module : moduleSet) + for (JavaPlugin plugin : plugins) { - if (module.getRuntimeClass().equals(clazz)) + if (clazz.isInstance(plugin)) { - // We know that because the runtime class matches, - // we can safely infer the type. - return (T) module.getRuntimeInstance(); + return () -> (T) plugin; } } - return null; - } - public void enableModules() - { - for (Module module : moduleSet) - { - module.enable(); - } - } - - public void disableModules() - { - for (Module module : moduleSet) - { - module.disable(); - } - } - - public boolean isLoaded(Class> module) - { - return moduleSet.stream() - .anyMatch(m -> - m.getRuntimeClass().equals(module)); - } - - public void unloadModules(File dataFolder) - { - if (dataFolder.mkdirs()) return; - for (Module module : moduleSet) - { - module.disable(); - moduleSet.remove(module); - } + return () -> null; } } diff --git a/Commons/src/main/java/me/totalfreedom/data/ServiceRegistry.java b/Commons/src/main/java/me/totalfreedom/data/ServiceRegistry.java index d0bb8b9..fd157ed 100644 --- a/Commons/src/main/java/me/totalfreedom/data/ServiceRegistry.java +++ b/Commons/src/main/java/me/totalfreedom/data/ServiceRegistry.java @@ -1,5 +1,64 @@ package me.totalfreedom.data; +import me.totalfreedom.service.Service; +import org.bukkit.Bukkit; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.RegisteredServiceProvider; +import org.bukkit.plugin.ServicePriority; + +import java.util.ArrayList; +import java.util.List; + public class ServiceRegistry { + private final List services; + + public ServiceRegistry() + { + this.services = new ArrayList<>(); + } + + public void startAll() + { + for (Service service : this.services) + { + service.start(); + } + } + + public void stopAll() + { + for (Service service : this.services) + { + service.stop(); + } + } + + @SuppressWarnings("unchecked") + // Suppressing is fine here; we know that the service is of type T extends Service, + // and calling getClass() on this object would effectively be Class, though we may lose + // the identity of the code signature in the process. + // In this case, that is fine. + public void register(Plugin plugin, final T service) + { + this.services.add(service); + if (!service.getClass().isInstance(service)) + { + throw new UnknownError(""" + A critical issue has been encountered: + The service %s is not an instance of itself. + This is a critical issue and should be reported immediately. + """.formatted(service.getClass().getName())); + } + Bukkit.getServicesManager().register( + (Class) service.getClass(), + service, + plugin, + ServicePriority.Normal); + } + + public RegisteredServiceProvider getService(Class clazz) + { + return Bukkit.getServicesManager().getRegistration(clazz); + } } diff --git a/Commons/src/main/java/me/totalfreedom/event/EventBus.java b/Commons/src/main/java/me/totalfreedom/event/EventBus.java index 14420cc..918dea8 100644 --- a/Commons/src/main/java/me/totalfreedom/event/EventBus.java +++ b/Commons/src/main/java/me/totalfreedom/event/EventBus.java @@ -1,14 +1,9 @@ package me.totalfreedom.event; import me.totalfreedom.base.CommonsBase; -import me.totalfreedom.base.CommonsJavaPlugin; -import org.bukkit.Bukkit; -import org.bukkit.event.Event; import org.bukkit.event.Listener; -import org.bukkit.plugin.java.JavaPlugin; import java.lang.reflect.Executable; -import java.lang.reflect.Method; import java.util.*; import java.util.stream.Collectors; @@ -18,11 +13,13 @@ public class EventBus private final Map> listenerEventMap = new HashMap<>(); private final CommonsBase plugin; - public EventBus(CommonsBase plugin) { + public EventBus(CommonsBase plugin) + { this.plugin = plugin; } - void registerListener(Listener listener) { + void registerListener(Listener listener) + { Set eventSet = Arrays.stream(listener.getClass().getDeclaredMethods()) .filter(m -> m.isAnnotationPresent(Handler.class)) .map(Executable::getParameters) @@ -33,7 +30,8 @@ public class EventBus try { return (FEvent) p[0].getType().getDeclaredConstructor().newInstance(); - } catch (Exception exception) { + } catch (Exception exception) + { exception.printStackTrace(); return null; } @@ -44,19 +42,33 @@ public class EventBus listenerEventMap.put(listener, eventSet); } - void unregisterListener(Listener listener) { + void unregisterListener(Listener listener) + { listenerEventMap.remove(listener); } - public void startListening() { + public void startListening() + { listenerSet().forEach(this::registerListener); } - public void stopListening() { + public void stopListening() + { listenerSet().forEach(this::unregisterListener); } - public Set listenerSet() { + public Set listenerSet() + { return listenerSet; } + + public Map> listenerEventMap() + { + return listenerEventMap; + } + + public CommonsBase getCommonsBase() + { + return plugin; + } } diff --git a/Commons/src/main/java/me/totalfreedom/event/FEvent.java b/Commons/src/main/java/me/totalfreedom/event/FEvent.java index a9f3bd6..418d1a4 100644 --- a/Commons/src/main/java/me/totalfreedom/event/FEvent.java +++ b/Commons/src/main/java/me/totalfreedom/event/FEvent.java @@ -1,11 +1,14 @@ package me.totalfreedom.event; import me.totalfreedom.api.Context; -import org.bukkit.event.Cancellable; -public interface FEvent +public abstract class FEvent { - void call(Context... contexts); + protected FEvent() + { + } - void cancel(); + public abstract void call(Context... contexts); + + public abstract void cancel(); } diff --git a/Commons/src/main/java/me/totalfreedom/module/Module.java b/Commons/src/main/java/me/totalfreedom/module/Module.java deleted file mode 100644 index da4e828..0000000 --- a/Commons/src/main/java/me/totalfreedom/module/Module.java +++ /dev/null @@ -1,28 +0,0 @@ -package me.totalfreedom.module; - -import me.totalfreedom.utils.Identity; - -import java.util.HashSet; -import java.util.Set; - -public interface Module> -{ - Identity getIdentity(); - - Class getRuntimeClass(); - - T getRuntimeInstance(); - - default void enable() - { - } - - default void disable() - { - } - - default Set dependencies() - { - return new HashSet<>(); - } -} diff --git a/Commons/src/main/java/me/totalfreedom/provider/EventProvider.java b/Commons/src/main/java/me/totalfreedom/provider/EventProvider.java new file mode 100644 index 0000000..242fc10 --- /dev/null +++ b/Commons/src/main/java/me/totalfreedom/provider/EventProvider.java @@ -0,0 +1,9 @@ +package me.totalfreedom.provider; + +import me.totalfreedom.event.FEvent; + +@FunctionalInterface +public interface EventProvider +{ + T getEvent(); +} diff --git a/Commons/src/main/java/me/totalfreedom/provider/ModuleProvider.java b/Commons/src/main/java/me/totalfreedom/provider/ModuleProvider.java new file mode 100644 index 0000000..65c9bd1 --- /dev/null +++ b/Commons/src/main/java/me/totalfreedom/provider/ModuleProvider.java @@ -0,0 +1,9 @@ +package me.totalfreedom.provider; + +import org.bukkit.plugin.java.JavaPlugin; + +@FunctionalInterface +public interface ModuleProvider +{ + T getModule(); +} diff --git a/Commons/src/main/java/me/totalfreedom/provider/ServiceProvider.java b/Commons/src/main/java/me/totalfreedom/provider/ServiceProvider.java new file mode 100644 index 0000000..e9a3387 --- /dev/null +++ b/Commons/src/main/java/me/totalfreedom/provider/ServiceProvider.java @@ -0,0 +1,8 @@ +package me.totalfreedom.provider; + +import me.totalfreedom.service.Service; + +public interface ServiceProvider +{ + T getService(); +} diff --git a/Commons/src/main/java/me/totalfreedom/permission/Group.java b/Commons/src/main/java/me/totalfreedom/security/Group.java similarity index 87% rename from Commons/src/main/java/me/totalfreedom/permission/Group.java rename to Commons/src/main/java/me/totalfreedom/security/Group.java index 87375d0..d09ba61 100644 --- a/Commons/src/main/java/me/totalfreedom/permission/Group.java +++ b/Commons/src/main/java/me/totalfreedom/security/Group.java @@ -1,4 +1,4 @@ -package me.totalfreedom.permission; +package me.totalfreedom.security; import net.kyori.adventure.text.Component; diff --git a/Commons/src/main/java/me/totalfreedom/permission/Node.java b/Commons/src/main/java/me/totalfreedom/security/Node.java similarity index 73% rename from Commons/src/main/java/me/totalfreedom/permission/Node.java rename to Commons/src/main/java/me/totalfreedom/security/Node.java index c75866b..0519b39 100644 --- a/Commons/src/main/java/me/totalfreedom/permission/Node.java +++ b/Commons/src/main/java/me/totalfreedom/security/Node.java @@ -1,7 +1,6 @@ -package me.totalfreedom.permission; +package me.totalfreedom.security; import org.bukkit.permissions.Permission; -import org.bukkit.permissions.PermissionAttachment; import javax.annotation.concurrent.Immutable; @@ -12,7 +11,7 @@ public interface Node boolean getValue(); - Permission spigot(); + Permission bukkit(); NodeType getType(); @@ -29,6 +28,4 @@ public interface Node boolean isWildcard(); boolean isNegated(); - - NodeBuilder builder(); } diff --git a/Commons/src/main/java/me/totalfreedom/permission/NodeBuilder.java b/Commons/src/main/java/me/totalfreedom/security/NodeBuilder.java similarity index 88% rename from Commons/src/main/java/me/totalfreedom/permission/NodeBuilder.java rename to Commons/src/main/java/me/totalfreedom/security/NodeBuilder.java index 07fd488..c0503ff 100644 --- a/Commons/src/main/java/me/totalfreedom/permission/NodeBuilder.java +++ b/Commons/src/main/java/me/totalfreedom/security/NodeBuilder.java @@ -1,4 +1,4 @@ -package me.totalfreedom.permission; +package me.totalfreedom.security; public interface NodeBuilder { diff --git a/Commons/src/main/java/me/totalfreedom/permission/NodeType.java b/Commons/src/main/java/me/totalfreedom/security/NodeType.java similarity index 72% rename from Commons/src/main/java/me/totalfreedom/permission/NodeType.java rename to Commons/src/main/java/me/totalfreedom/security/NodeType.java index 7f5a3d1..11293a9 100644 --- a/Commons/src/main/java/me/totalfreedom/permission/NodeType.java +++ b/Commons/src/main/java/me/totalfreedom/security/NodeType.java @@ -1,4 +1,4 @@ -package me.totalfreedom.permission; +package me.totalfreedom.security; public enum NodeType { diff --git a/Commons/src/main/java/me/totalfreedom/permission/PermissionHolder.java b/Commons/src/main/java/me/totalfreedom/security/PermissionHolder.java similarity index 71% rename from Commons/src/main/java/me/totalfreedom/permission/PermissionHolder.java rename to Commons/src/main/java/me/totalfreedom/security/PermissionHolder.java index 2404217..8095794 100644 --- a/Commons/src/main/java/me/totalfreedom/permission/PermissionHolder.java +++ b/Commons/src/main/java/me/totalfreedom/security/PermissionHolder.java @@ -1,16 +1,13 @@ -package me.totalfreedom.permission; +package me.totalfreedom.security; import org.bukkit.entity.Player; import org.bukkit.permissions.Permissible; -import org.bukkit.permissions.Permission; import java.util.Set; import java.util.UUID; public interface PermissionHolder extends Permissible { - PermissionHolder fromPlayer(Player player); - UUID getUniqueId(); Set permissions(); diff --git a/Commons/src/main/java/me/totalfreedom/security/Verification.java b/Commons/src/main/java/me/totalfreedom/security/Verification.java deleted file mode 100644 index 5851d5e..0000000 --- a/Commons/src/main/java/me/totalfreedom/security/Verification.java +++ /dev/null @@ -1,12 +0,0 @@ -package me.totalfreedom.security; - -public interface Verification -{ - public boolean verify(String input); - - public String getVerificationMessage(); - - public String getVerificationFailedMessage(); - - public String generateVerificationCode(); -} diff --git a/Commons/src/main/java/me/totalfreedom/service/Service.java b/Commons/src/main/java/me/totalfreedom/service/Service.java new file mode 100644 index 0000000..7f2f6e2 --- /dev/null +++ b/Commons/src/main/java/me/totalfreedom/service/Service.java @@ -0,0 +1,16 @@ +package me.totalfreedom.service; + +public abstract class Service +{ + private final String name; + + protected Service(String name) + { + this.name = name; + + } + + public abstract void start(); + + public abstract void stop(); +} diff --git a/Commons/src/main/java/me/totalfreedom/service/FreedomService.java b/Commons/src/main/java/me/totalfreedom/service/Task.java similarity index 88% rename from Commons/src/main/java/me/totalfreedom/service/FreedomService.java rename to Commons/src/main/java/me/totalfreedom/service/Task.java index db01152..941ae6f 100644 --- a/Commons/src/main/java/me/totalfreedom/service/FreedomService.java +++ b/Commons/src/main/java/me/totalfreedom/service/Task.java @@ -1,6 +1,6 @@ package me.totalfreedom.service; -public interface FreedomService +public interface Task extends Runnable { void start(); diff --git a/Commons/src/main/java/me/totalfreedom/sql/SQL.java b/Commons/src/main/java/me/totalfreedom/sql/SQL.java index 39f1674..ac0858c 100644 --- a/Commons/src/main/java/me/totalfreedom/sql/SQL.java +++ b/Commons/src/main/java/me/totalfreedom/sql/SQL.java @@ -8,16 +8,10 @@ public interface SQL { CompletableFuture getConnection(String url); - CompletableFuture executeQuery(String query); - CompletableFuture executeQuery(String query, Object... args); - CompletableFuture executeUpdate(String query); - CompletableFuture executeUpdate(String query, Object... args); - CompletableFuture execute(String query); - CompletableFuture execute(String query, Object... args); CompletableFuture createTable(String table, String... columns); diff --git a/Commons/src/main/java/me/totalfreedom/sql/SQLProperties.java b/Commons/src/main/java/me/totalfreedom/sql/SQLProperties.java index 022beb6..8d16faf 100644 --- a/Commons/src/main/java/me/totalfreedom/sql/SQLProperties.java +++ b/Commons/src/main/java/me/totalfreedom/sql/SQLProperties.java @@ -7,7 +7,8 @@ public interface SQLProperties { Properties getProperties(File propertiesFile); - default Properties getDefaultProperties() { + default Properties getDefaultProperties() + { Properties properties = new Properties(); properties.setProperty("driver", "sqlite"); properties.setProperty("host", "localhost"); @@ -30,7 +31,8 @@ public interface SQLProperties String getPassword(); - default String toURLPlain() { + default String toURLPlain() + { return String.format("jdbc:%s://%s:%s/%s", this.getDriver(), this.getHost(), @@ -38,7 +40,8 @@ public interface SQLProperties this.getDatabase()); } - default String toURLWithLogin() { + default String toURLWithLogin() + { return String.format("jdbc:%s://%s:%s/%s?user=%s&password=%s", this.getDriver(), this.getHost(), diff --git a/Commons/src/main/java/me/totalfreedom/user/User.java b/Commons/src/main/java/me/totalfreedom/user/User.java index b88846a..82cff23 100644 --- a/Commons/src/main/java/me/totalfreedom/user/User.java +++ b/Commons/src/main/java/me/totalfreedom/user/User.java @@ -1,10 +1,8 @@ package me.totalfreedom.user; -import me.totalfreedom.permission.PermissionHolder; +import me.totalfreedom.security.PermissionHolder; import net.kyori.adventure.text.Component; -import java.util.UUID; - public interface User extends PermissionHolder { Component getDisplayName();