From 3e8c63221d7aca3a2f3f33c8fa3bc86c7e09c417 Mon Sep 17 00:00:00 2001 From: Eva <66324759+evallll@users.noreply.github.com> Date: Fri, 11 Aug 2023 19:15:36 +0100 Subject: [PATCH] Overhaul of Patchwork and Registration system, fix-up for all plugin.yml files and removal of .negates(0 and .value() from DefaultNodes in turn for the .expiry() system removing the redundancies. (#21) Co-authored-by: eva <66324759+evax64@users.noreply.github.com> --- Corvo/src/main/java/fns/corvo/Corvo.java | 9 ++-- Corvo/src/main/resources/plugin.yml | 3 +- Datura/src/main/java/fns/datura/Datura.java | 24 ++++------ .../java/fns/datura/cmd/AdminChatCommand.java | 7 +-- .../fns/datura/cmd/ClearDropsCommand.java | 4 +- .../java/fns/datura/perms/DefaultNodes.java | 12 ++--- .../java/fns/datura/perms/FreedomGroup.java | 3 +- .../java/fns/datura/perms/FreedomUser.java | 13 ++--- .../java/fns/datura/punishment/Cager.java | 7 ++- .../java/fns/datura/punishment/Locker.java | 3 +- .../src/main/java/fns/datura/sql/MySQL.java | 17 +++---- .../java/fns/datura/user/SimpleUserData.java | 9 ++-- Datura/src/main/resources/plugin.yml | 3 +- Fossil/src/main/java/fns/fossil/Fossil.java | 12 ++--- .../java/fns/fossil/bouncypads/PadHolder.java | 10 ++-- Fossil/src/main/resources/plugin.yml | 3 +- .../java/fns/patchwork/base/Patchwork.java | 48 ++++++------------- .../java/fns/patchwork/base/Registration.java | 41 +++++++--------- .../java/fns/patchwork/base/Shortcuts.java | 12 ++--- .../display/adminchat/AdminChatDisplay.java | 13 +++-- .../patchwork/provider/ContextProvider.java | 1 - .../patchwork/service/FreedomExecutor.java | 6 +-- .../java/fns/patchwork/shop/ReactionTask.java | 8 ++-- Patchwork/src/main/resources/plugin.yml | 3 +- 24 files changed, 113 insertions(+), 158 deletions(-) diff --git a/Corvo/src/main/java/fns/corvo/Corvo.java b/Corvo/src/main/java/fns/corvo/Corvo.java index 8b021ec..69d9c7a 100644 --- a/Corvo/src/main/java/fns/corvo/Corvo.java +++ b/Corvo/src/main/java/fns/corvo/Corvo.java @@ -1,6 +1,7 @@ package fns.corvo; import fns.patchwork.base.Patchwork; +import fns.patchwork.base.Registration; import org.bukkit.plugin.java.JavaPlugin; public class Corvo extends JavaPlugin @@ -8,18 +9,14 @@ public class Corvo extends JavaPlugin @Override public void onDisable() { - Patchwork.getInstance() - .getRegistrations() - .getModuleRegistry() + Registration.getModuleRegistry() .removeModule(this); } @Override public void onEnable() { - Patchwork.getInstance() - .getRegistrations() - .getModuleRegistry() + Registration.getModuleRegistry() .addModule(this); } } diff --git a/Corvo/src/main/resources/plugin.yml b/Corvo/src/main/resources/plugin.yml index 557f40e..db2b827 100644 --- a/Corvo/src/main/resources/plugin.yml +++ b/Corvo/src/main/resources/plugin.yml @@ -1,5 +1,6 @@ name: Corvo -main: me.totalfreedom.corvo.Corvo +main: fns.corvo.Corvo +api-version: 1.20 version: 1.0.0 author: TotalFreedom description: Services and Listeners for the Freedom Network Suite diff --git a/Datura/src/main/java/fns/datura/Datura.java b/Datura/src/main/java/fns/datura/Datura.java index f28a9c1..cebc77e 100644 --- a/Datura/src/main/java/fns/datura/Datura.java +++ b/Datura/src/main/java/fns/datura/Datura.java @@ -6,7 +6,7 @@ import fns.datura.punishment.Cager; import fns.datura.punishment.Halter; import fns.datura.punishment.Locker; import fns.datura.sql.MySQL; -import fns.patchwork.base.Patchwork; +import fns.patchwork.base.Registration; import fns.patchwork.service.SubscriptionProvider; import org.bukkit.Bukkit; import org.bukkit.plugin.java.JavaPlugin; @@ -18,7 +18,7 @@ public class Datura extends JavaPlugin // Punishment private final Halter halter = new Halter(); private final Locker locker = new Locker(); - private final Cager cager = new Cager(); + private Cager cager; // Features private final CommandSpy commandSpy = new CommandSpy(); @@ -27,28 +27,22 @@ public class Datura extends JavaPlugin @Override public void onEnable() { - Patchwork.getInstance() - .getRegistrations() - .getModuleRegistry() - .addModule(this); + cager = new Cager(this); - Patchwork.getInstance() - .getRegistrations() - .getServiceTaskRegistry() + Registration.getServiceTaskRegistry() .registerService(SubscriptionProvider.syncService(this, locker)); - Patchwork.getInstance() - .getRegistrations() - .getServiceTaskRegistry() + Registration.getServiceTaskRegistry() .registerService(SubscriptionProvider.syncService(this, cager)); - Patchwork.getInstance() - .getRegistrations() - .getServiceTaskRegistry() + Registration.getServiceTaskRegistry() .registerService(SubscriptionProvider.syncService(this, fuckoff)); Bukkit.getPluginManager() .registerEvents(halter, this); Bukkit.getPluginManager() .registerEvents(commandSpy, this); + + Registration.getModuleRegistry() + .addModule(this); } public MySQL getSQL() diff --git a/Datura/src/main/java/fns/datura/cmd/AdminChatCommand.java b/Datura/src/main/java/fns/datura/cmd/AdminChatCommand.java index ab38001..aff79a4 100644 --- a/Datura/src/main/java/fns/datura/cmd/AdminChatCommand.java +++ b/Datura/src/main/java/fns/datura/cmd/AdminChatCommand.java @@ -1,6 +1,7 @@ package fns.datura.cmd; import fns.patchwork.base.Patchwork; +import fns.patchwork.base.Shortcuts; import fns.patchwork.command.Commander; import fns.patchwork.command.annotation.Base; import fns.patchwork.command.annotation.Info; @@ -38,11 +39,11 @@ public class AdminChatCommand extends Commander final Player player = (Player) sender; - Patchwork.getInstance() + Shortcuts.provideModule(Patchwork.class) .getAdminChatDisplay() .toggleChat(player); - final boolean toggled = Patchwork.getInstance() + final boolean toggled = Shortcuts.provideModule(Patchwork.class) .getAdminChatDisplay() .isToggled(player); @@ -57,7 +58,7 @@ public class AdminChatCommand extends Commander @Subcommand(permission = "patchwork.adminchat", args = {String.class}) public void sendMessage(final CommandSender sender, final String message) { - Patchwork.getInstance() + Shortcuts.provideModule(Patchwork.class) .getAdminChatDisplay() .adminChatMessage(sender, Component.text(message)); } diff --git a/Datura/src/main/java/fns/datura/cmd/ClearDropsCommand.java b/Datura/src/main/java/fns/datura/cmd/ClearDropsCommand.java index 99828f8..e0912cf 100644 --- a/Datura/src/main/java/fns/datura/cmd/ClearDropsCommand.java +++ b/Datura/src/main/java/fns/datura/cmd/ClearDropsCommand.java @@ -51,7 +51,7 @@ public class ClearDropsCommand extends Commander } final Player player = (Player) sender; - Patchwork.getInstance() + Shortcuts.provideModule(Patchwork.class) .getExecutor() .delayedExecutor(Shortcuts.provideModule(Datura.class), 20 * 10L) .execute(() -> @@ -73,7 +73,7 @@ public class ClearDropsCommand extends Commander @Subcommand(permission = "datura.cleardrops", args = {World.class}) public void clearDrops(final CommandSender sender, final World world) { - Patchwork.getInstance() + Shortcuts.provideModule(Patchwork.class) .getExecutor() .delayedExecutor(Shortcuts.provideModule(Datura.class), 20 * 10L) .execute(() -> diff --git a/Datura/src/main/java/fns/datura/perms/DefaultNodes.java b/Datura/src/main/java/fns/datura/perms/DefaultNodes.java index 71a9af4..fd85f65 100644 --- a/Datura/src/main/java/fns/datura/perms/DefaultNodes.java +++ b/Datura/src/main/java/fns/datura/perms/DefaultNodes.java @@ -7,30 +7,26 @@ public class DefaultNodes { public static final Node OP = new PermissionNodeBuilder() .key("freedom.master_key") - .value(true) + .expiry(-1) .type(NodeType.PERMISSION) - .negated(false) .wildcard(true) .build(); public static final Node NON_OP = new PermissionNodeBuilder() .key("freedom.default") - .value(true) + .expiry(-1) .type(NodeType.PERMISSION) - .negated(false) .wildcard(false) .build(); public static final Node ALL = new PermissionNodeBuilder() .key("*") - .value(true) + .expiry(-1) .type(NodeType.PERMISSION) - .negated(false) .wildcard(true) .build(); public static final Node NONE = new PermissionNodeBuilder() .key("freedom.none") - .value(true) + .expiry(-1) .type(NodeType.PERMISSION) - .negated(false) .wildcard(false) .build(); diff --git a/Datura/src/main/java/fns/datura/perms/FreedomGroup.java b/Datura/src/main/java/fns/datura/perms/FreedomGroup.java index 0077a5f..7694147 100644 --- a/Datura/src/main/java/fns/datura/perms/FreedomGroup.java +++ b/Datura/src/main/java/fns/datura/perms/FreedomGroup.java @@ -1,6 +1,7 @@ package fns.datura.perms; import fns.patchwork.base.Patchwork; +import fns.patchwork.base.Shortcuts; import fns.patchwork.security.Group; import fns.patchwork.security.Node; import java.util.HashSet; @@ -40,7 +41,7 @@ public class FreedomGroup implements Group this.isDefault = isDefault; this.isHidden = isHidden; this.permissions = new HashSet<>(); - this.attachment = new PermissionAttachment(Patchwork.getInstance(), this); + this.attachment = new PermissionAttachment(Shortcuts.provideModule(Patchwork.class), this); } @Override diff --git a/Datura/src/main/java/fns/datura/perms/FreedomUser.java b/Datura/src/main/java/fns/datura/perms/FreedomUser.java index 367ccd6..d246cad 100644 --- a/Datura/src/main/java/fns/datura/perms/FreedomUser.java +++ b/Datura/src/main/java/fns/datura/perms/FreedomUser.java @@ -3,6 +3,8 @@ package fns.datura.perms; import fns.datura.Datura; import fns.datura.user.SimpleUserData; import fns.patchwork.base.Patchwork; +import fns.patchwork.base.Registration; +import fns.patchwork.base.Shortcuts; import fns.patchwork.security.Node; import fns.patchwork.user.User; import fns.patchwork.user.UserData; @@ -41,11 +43,7 @@ public class FreedomUser implements User this.permissions = new HashSet<>(); this.displayName = player.displayName(); - final Datura datura = Patchwork.getInstance() - .getRegistrations() - .getModuleRegistry() - .getProvider(Datura.class) - .getModule(); + final Datura datura = Shortcuts.provideModule(Datura.class); UserData data = SimpleUserData.fromSQL(datura.getSQL(), uuid.toString()); @@ -56,8 +54,7 @@ public class FreedomUser implements User this.userData = data; - Patchwork.getInstance() - .getRegistrations() + Registration .getUserRegistry() .registerUserData(this, userData); } @@ -96,7 +93,7 @@ public class FreedomUser implements User public boolean addPermission(final Node node) { final boolean value = !node.isTemporary() || node.isExpired(); - final PermissionAttachment attachment = addAttachment(Patchwork.getInstance(), node.key(), value); + final PermissionAttachment attachment = addAttachment(Shortcuts.provideModule(Patchwork.class), node.key(), value); bukkitAttachments.put(node, attachment); return permissions().add(node); } diff --git a/Datura/src/main/java/fns/datura/punishment/Cager.java b/Datura/src/main/java/fns/datura/punishment/Cager.java index b411052..3a962d0 100644 --- a/Datura/src/main/java/fns/datura/punishment/Cager.java +++ b/Datura/src/main/java/fns/datura/punishment/Cager.java @@ -1,5 +1,6 @@ package fns.datura.punishment; +import fns.datura.Datura; import fns.patchwork.base.Patchwork; import fns.patchwork.service.Service; import fns.patchwork.utils.ShapeUtils; @@ -20,18 +21,20 @@ import org.bukkit.event.Listener; import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.player.PlayerQuitEvent; +import javax.sound.midi.Patch; + public class Cager extends Service { private final Set cagedPlayers; private final Map cageLocations; - public Cager() + public Cager(final Datura datura) { super("cager-service"); this.cagedPlayers = new HashSet<>(); this.cageLocations = new HashMap<>(); Bukkit.getPluginManager() - .registerEvents(new CageListener(), Patchwork.getInstance()); + .registerEvents(new CageListener(), datura); } /** diff --git a/Datura/src/main/java/fns/datura/punishment/Locker.java b/Datura/src/main/java/fns/datura/punishment/Locker.java index 71a0abd..4649ff0 100644 --- a/Datura/src/main/java/fns/datura/punishment/Locker.java +++ b/Datura/src/main/java/fns/datura/punishment/Locker.java @@ -1,6 +1,7 @@ package fns.datura.punishment; import fns.patchwork.base.Patchwork; +import fns.patchwork.base.Shortcuts; import fns.patchwork.service.Service; import java.util.HashSet; import java.util.Set; @@ -34,7 +35,7 @@ public class Locker extends Service @Override public void tick() { - lockedPlayers.removeIf(uuid -> !Patchwork.getInstance() + lockedPlayers.removeIf(uuid -> !Shortcuts.provideModule(Patchwork.class) .getServer() .getOfflinePlayer(uuid) .isOnline()); diff --git a/Datura/src/main/java/fns/datura/sql/MySQL.java b/Datura/src/main/java/fns/datura/sql/MySQL.java index e3485e7..57afd1b 100644 --- a/Datura/src/main/java/fns/datura/sql/MySQL.java +++ b/Datura/src/main/java/fns/datura/sql/MySQL.java @@ -1,6 +1,7 @@ package fns.datura.sql; import fns.patchwork.base.Patchwork; +import fns.patchwork.base.Shortcuts; import fns.patchwork.sql.SQL; import fns.patchwork.utils.container.Identity; import java.sql.Connection; @@ -74,7 +75,7 @@ public class MySQL implements SQL throw new CompletionException("Failed to prepare statement: " + query + "\n", ex); } - }, Patchwork.getInstance() + }, Shortcuts.provideModule(Patchwork.class) .getExecutor() .getAsync()); } @@ -91,7 +92,7 @@ public class MySQL implements SQL throw new CompletionException("Failed to connect to the database: " + url.toString() + "\n", ex); } - }, Patchwork.getInstance() + }, Shortcuts.provideModule(Patchwork.class) .getExecutor() .getAsync()); } @@ -111,7 +112,7 @@ public class MySQL implements SQL "Failed to retrieve a result set from query: " + query + "\n", ex); } - }, Patchwork.getInstance() + }, Shortcuts.provideModule(Patchwork.class) .getExecutor() .getAsync()); } @@ -130,7 +131,7 @@ public class MySQL implements SQL throw new CompletionException("Failed to execute update: " + query + "\n", ex); } - }, Patchwork.getInstance() + }, Shortcuts.provideModule(Patchwork.class) .getExecutor() .getAsync()); } @@ -149,7 +150,7 @@ public class MySQL implements SQL throw new CompletionException("Failed to execute statement: " + query + "\n", ex); } - }, Patchwork.getInstance() + }, Shortcuts.provideModule(Patchwork.class) .getExecutor() .getAsync()); } @@ -193,7 +194,7 @@ public class MySQL implements SQL ex); } return null; - }, Patchwork.getInstance() + }, Shortcuts.provideModule(Patchwork.class) .getExecutor() .getAsync()); } @@ -202,7 +203,7 @@ public class MySQL implements SQL final String key, final Identity identity) { return executeUpdate("UPDATE ? SET ? = ? WHERE ? = ?", table, column, value, key, identity.getId()) - .thenApplyAsync(result -> result > 0, Patchwork.getInstance() + .thenApplyAsync(result -> result > 0, Shortcuts.provideModule(Patchwork.class) .getExecutor() .getAsync()); } @@ -210,7 +211,7 @@ public class MySQL implements SQL public CompletableFuture deleteRow(final String table, final String key, final Identity identity) { return executeUpdate("DELETE FROM ? WHERE ? = ?", table, key, identity.getId()) - .thenApplyAsync(result -> result > 0, Patchwork.getInstance() + .thenApplyAsync(result -> result > 0, Shortcuts.provideModule(Patchwork.class) .getExecutor() .getAsync()); } diff --git a/Datura/src/main/java/fns/datura/user/SimpleUserData.java b/Datura/src/main/java/fns/datura/user/SimpleUserData.java index 234306d..f313ef3 100644 --- a/Datura/src/main/java/fns/datura/user/SimpleUserData.java +++ b/Datura/src/main/java/fns/datura/user/SimpleUserData.java @@ -3,6 +3,8 @@ package fns.datura.user; import fns.datura.event.UserDataUpdateEvent; import fns.datura.perms.FreedomUser; import fns.patchwork.base.Patchwork; +import fns.patchwork.base.Registration; +import fns.patchwork.base.Shortcuts; import fns.patchwork.display.adminchat.AdminChatFormat; import fns.patchwork.security.Group; import fns.patchwork.sql.SQL; @@ -38,7 +40,7 @@ public class SimpleUserData implements UserData this.username = player.getName(); this.user = new FreedomUser(player); - Patchwork.getInstance() + Shortcuts.provideModule(Patchwork.class) .getEventBus() .addEvent(event); } @@ -84,8 +86,7 @@ public class SimpleUserData implements UserData throw new IllegalStateException("Player should be online but they are not!"); final User user = new FreedomUser(player); - final Group group = Patchwork.getInstance() - .getRegistrations() + final Group group = Registration .getGroupRegistry() .getGroup(g); @@ -116,7 +117,7 @@ public class SimpleUserData implements UserData if (player == null) throw new IllegalStateException("Player should be online but they are not!"); return new SimpleUserData(player); - }, Patchwork.getInstance() + }, Shortcuts.provideModule(Patchwork.class) .getExecutor() .getAsync()) .join(); diff --git a/Datura/src/main/resources/plugin.yml b/Datura/src/main/resources/plugin.yml index 0455676..a70371e 100644 --- a/Datura/src/main/resources/plugin.yml +++ b/Datura/src/main/resources/plugin.yml @@ -1,5 +1,6 @@ name: Datura -main: me.totalfreedom.datura.Datura +main: fns.datura.Datura +api-version: 1.20 version: 1.0.0 author: TotalFreedom description: Data Manager for the Freedom Network Suite diff --git a/Fossil/src/main/java/fns/fossil/Fossil.java b/Fossil/src/main/java/fns/fossil/Fossil.java index e32ce9b..7a470b5 100644 --- a/Fossil/src/main/java/fns/fossil/Fossil.java +++ b/Fossil/src/main/java/fns/fossil/Fossil.java @@ -1,7 +1,6 @@ package fns.fossil; import fns.fossil.trail.Trailer; -import fns.patchwork.base.Patchwork; import fns.patchwork.base.Registration; import fns.patchwork.service.SubscriptionProvider; import org.bukkit.plugin.java.JavaPlugin; @@ -9,17 +8,14 @@ import org.bukkit.plugin.java.JavaPlugin; public class Fossil extends JavaPlugin { private final Trailer trailer = new Trailer(); - private final Registration registration = Patchwork.getInstance() - .getRegistrations(); - @Override public void onEnable() { - registration.getModuleRegistry() - .addModule(this); - - registration.getServiceTaskRegistry() + Registration.getServiceTaskRegistry() .registerService( SubscriptionProvider.syncService(this, trailer)); + + Registration.getModuleRegistry() + .addModule(this); } } diff --git a/Fossil/src/main/java/fns/fossil/bouncypads/PadHolder.java b/Fossil/src/main/java/fns/fossil/bouncypads/PadHolder.java index 93b5f91..487a263 100644 --- a/Fossil/src/main/java/fns/fossil/bouncypads/PadHolder.java +++ b/Fossil/src/main/java/fns/fossil/bouncypads/PadHolder.java @@ -1,11 +1,12 @@ package fns.fossil.bouncypads; import fns.fossil.Fossil; -import fns.patchwork.base.Patchwork; import java.util.HashMap; import java.util.Map; import java.util.UUID; import java.util.stream.Stream; + +import fns.patchwork.base.Shortcuts; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Tag; @@ -32,12 +33,7 @@ public class PadHolder implements Listener public PadHolder() { Bukkit.getPluginManager() - .registerEvents(this, Patchwork - .getInstance() - .getRegistrations() - .getModuleRegistry() - .getProvider(Fossil.class) - .getModule()); + .registerEvents(this, Shortcuts.provideModule(Fossil.class)); } /** diff --git a/Fossil/src/main/resources/plugin.yml b/Fossil/src/main/resources/plugin.yml index 99f537c..f3212a7 100644 --- a/Fossil/src/main/resources/plugin.yml +++ b/Fossil/src/main/resources/plugin.yml @@ -1,6 +1,7 @@ name: Fossil version: 1.0 -main: me.totalfreedom.fossil.Fossil +main: fns.fossil.Fossil +api-version: 1.20 author: TotalFreedom description: The Fun Module for the Freedom Network. depend: diff --git a/Patchwork/src/main/java/fns/patchwork/base/Patchwork.java b/Patchwork/src/main/java/fns/patchwork/base/Patchwork.java index 964180f..64d4099 100644 --- a/Patchwork/src/main/java/fns/patchwork/base/Patchwork.java +++ b/Patchwork/src/main/java/fns/patchwork/base/Patchwork.java @@ -15,52 +15,45 @@ public class Patchwork extends JavaPlugin /** * The {@link EventBus} for this plugin. */ - private final EventBus eventBus = new EventBus(this); - /** - * The {@link Registration} object for this plugin. - */ - private final Registration registration = new Registration(); + private EventBus eventBus; /** * The {@link FreedomExecutor} for this plugin. */ - private final FreedomExecutor executor = new FreedomExecutor(); + private FreedomExecutor executor; /** * The {@link AdminChatDisplay} for this plugin. */ - private final AdminChatDisplay acdisplay = new AdminChatDisplay(); - - /** - * Provides this plugin instance through a safe static method. This is effectively the same thing as using - * {@link JavaPlugin#getPlugin(Class)} - * - * @return the plugin instance - */ - public static Patchwork getInstance() - { - return JavaPlugin.getPlugin(Patchwork.class); - } + private AdminChatDisplay acdisplay; @Override public void onDisable() { Bukkit.getScheduler() - .runTaskLater(this, () -> getRegistrations() + .runTaskLater(this, () -> Registration .getServiceTaskRegistry() .stopAllServices(), 1L); - getRegistrations().getServiceTaskRegistry() + Registration.getServiceTaskRegistry() .unregisterService(EventBus.class); } @Override public void onEnable() { - getRegistrations().getServiceTaskRegistry() + eventBus = new EventBus(this); + executor = new FreedomExecutor(this); + acdisplay = new AdminChatDisplay(this); + + + Registration.getServiceTaskRegistry() .registerService(SubscriptionProvider.asyncService(this, eventBus)); + getExecutor().getSync() - .execute(() -> getRegistrations() + .execute(() -> Registration .getServiceTaskRegistry() .startAllServices()); + + Registration.getModuleRegistry().addModule(this); } /** @@ -73,17 +66,6 @@ public class Patchwork extends JavaPlugin return executor; } - /** - * Get's the Registration object for this plugin. This object contains every registry class for the various features - * provided by this plugin. - * - * @return the Registration object - */ - public Registration getRegistrations() - { - return registration; - } - /** * Gets the {@link EventBus} for this plugin. The EventBus is used to register and listen to custom events provided * by Freedom Network Suite. diff --git a/Patchwork/src/main/java/fns/patchwork/base/Registration.java b/Patchwork/src/main/java/fns/patchwork/base/Registration.java index c5aeee8..bbe5048 100644 --- a/Patchwork/src/main/java/fns/patchwork/base/Registration.java +++ b/Patchwork/src/main/java/fns/patchwork/base/Registration.java @@ -11,53 +11,44 @@ import fns.patchwork.data.UserRegistry; * This class is a holder for each registry in the data package. *
* Registries such as {@link ModuleRegistry} and {@link ServiceTaskRegistry} can be found as final objects in this - * class. These registries should only ever be accessed through the single Registration object in CommonsBase using - * {@link Patchwork#getRegistrations()} + * class. */ public class Registration { /** * The {@link EventRegistry} */ - private final EventRegistry eventRegistry; + private static final EventRegistry eventRegistry = new EventRegistry(); /** * The {@link UserRegistry} */ - private final UserRegistry userRegistry; + private static final UserRegistry userRegistry = new UserRegistry(); /** * The {@link ServiceTaskRegistry} */ - private final ServiceTaskRegistry serviceTaskRegistry; + private static final ServiceTaskRegistry serviceTaskRegistry = new ServiceTaskRegistry(); /** * The {@link ModuleRegistry} */ - private final ModuleRegistry moduleRegistry; + private static final ModuleRegistry moduleRegistry = new ModuleRegistry(); /** * The {@link GroupRegistry} */ - private final GroupRegistry groupRegistry; + private static final GroupRegistry groupRegistry = new GroupRegistry(); /** * The {@link ConfigRegistry} */ - private final ConfigRegistry configRegistry; + private static final ConfigRegistry configRegistry = new ConfigRegistry(); - /** - * Constructs a new Registration object and initializes all registries. - */ - Registration() + private Registration() { - this.eventRegistry = new EventRegistry(); - this.userRegistry = new UserRegistry(); - this.serviceTaskRegistry = new ServiceTaskRegistry(); - this.moduleRegistry = new ModuleRegistry(); - this.groupRegistry = new GroupRegistry(); - this.configRegistry = new ConfigRegistry(); + throw new AssertionError(); } /** * @return The {@link ModuleRegistry} */ - public ModuleRegistry getModuleRegistry() + public static ModuleRegistry getModuleRegistry() { return moduleRegistry; } @@ -65,7 +56,7 @@ public class Registration /** * @return The {@link EventRegistry} */ - public EventRegistry getEventRegistry() + public static EventRegistry getEventRegistry() { return eventRegistry; } @@ -73,7 +64,7 @@ public class Registration /** * @return The {@link UserRegistry} */ - public UserRegistry getUserRegistry() + public static UserRegistry getUserRegistry() { return userRegistry; } @@ -81,7 +72,7 @@ public class Registration /** * @return The {@link ServiceTaskRegistry} */ - public ServiceTaskRegistry getServiceTaskRegistry() + public static ServiceTaskRegistry getServiceTaskRegistry() { return serviceTaskRegistry; } @@ -89,7 +80,7 @@ public class Registration /** * @return The {@link GroupRegistry} */ - public GroupRegistry getGroupRegistry() + public static GroupRegistry getGroupRegistry() { return groupRegistry; } @@ -97,8 +88,8 @@ public class Registration /** * @return The {@link ConfigRegistry} */ - public ConfigRegistry getConfigRegistry() + public static ConfigRegistry getConfigRegistry() { return configRegistry; } -} +} \ No newline at end of file diff --git a/Patchwork/src/main/java/fns/patchwork/base/Shortcuts.java b/Patchwork/src/main/java/fns/patchwork/base/Shortcuts.java index 2e57e68..b591929 100644 --- a/Patchwork/src/main/java/fns/patchwork/base/Shortcuts.java +++ b/Patchwork/src/main/java/fns/patchwork/base/Shortcuts.java @@ -13,18 +13,14 @@ public final class Shortcuts public static T provideModule(final Class pluginClass) { - return Patchwork.getInstance() - .getRegistrations() - .getModuleRegistry() - .getProvider(pluginClass) - .getModule(); + return Registration.getModuleRegistry() + .getProvider(pluginClass) + .getModule(); } public static User getUser(final Player player) { - return Patchwork.getInstance() - .getRegistrations() - .getUserRegistry() + return Registration.getUserRegistry() .getUser(player); } } diff --git a/Patchwork/src/main/java/fns/patchwork/display/adminchat/AdminChatDisplay.java b/Patchwork/src/main/java/fns/patchwork/display/adminchat/AdminChatDisplay.java index 8e70100..3f6f250 100644 --- a/Patchwork/src/main/java/fns/patchwork/display/adminchat/AdminChatDisplay.java +++ b/Patchwork/src/main/java/fns/patchwork/display/adminchat/AdminChatDisplay.java @@ -1,6 +1,7 @@ package fns.patchwork.display.adminchat; import fns.patchwork.base.Patchwork; +import fns.patchwork.base.Registration; import fns.patchwork.base.Shortcuts; import fns.patchwork.security.Groups; import fns.patchwork.user.UserData; @@ -24,9 +25,9 @@ public class AdminChatDisplay private final Map adminChatFormat = new HashMap<>(); private final Set toggledChat = new HashSet<>(); - public AdminChatDisplay() + public AdminChatDisplay(final Patchwork patchwork) { - new ACListener(this); + new ACListener(this, patchwork); } public void addPlayer(final Player player, final AdminChatFormat format) @@ -101,11 +102,11 @@ public class AdminChatDisplay { private final AdminChatDisplay display; - public ACListener(final AdminChatDisplay display) + public ACListener(final AdminChatDisplay display, final Patchwork patchwork) { this.display = display; Bukkit.getPluginManager() - .registerEvents(this, Shortcuts.provideModule(Patchwork.class)); + .registerEvents(this, patchwork); } @EventHandler @@ -124,9 +125,7 @@ public class AdminChatDisplay final Player player = event.getPlayer(); if (player.hasPermission(ACPERM)) { - final UserData data = Patchwork.getInstance() - .getRegistrations() - .getUserRegistry() + final UserData data = Registration.getUserRegistry() .fromPlayer(player); if (data.hasCustomACFormat()) { diff --git a/Patchwork/src/main/java/fns/patchwork/provider/ContextProvider.java b/Patchwork/src/main/java/fns/patchwork/provider/ContextProvider.java index a33a7d9..01f1807 100644 --- a/Patchwork/src/main/java/fns/patchwork/provider/ContextProvider.java +++ b/Patchwork/src/main/java/fns/patchwork/provider/ContextProvider.java @@ -160,7 +160,6 @@ public class ContextProvider * * @param string The string to parse * @return A location object if xyz is valid - * @see BukkitDelegate#processSubCommands(String[], CommandSender, ContextProvider, Subcommand) */ private @Nullable Location toLocation(final String string, final Class clazz) { diff --git a/Patchwork/src/main/java/fns/patchwork/service/FreedomExecutor.java b/Patchwork/src/main/java/fns/patchwork/service/FreedomExecutor.java index a67d031..c957279 100644 --- a/Patchwork/src/main/java/fns/patchwork/service/FreedomExecutor.java +++ b/Patchwork/src/main/java/fns/patchwork/service/FreedomExecutor.java @@ -25,12 +25,12 @@ public class FreedomExecutor /** * Creates a new {@link FreedomExecutor} instance. */ - public FreedomExecutor() + public FreedomExecutor(final Patchwork patchwork) { syncExecutor = r -> Bukkit.getScheduler() - .runTask(Patchwork.getInstance(), r); + .runTask(patchwork, r); asyncExecutor = r -> Bukkit.getScheduler() - .runTaskAsynchronously(Patchwork.getInstance(), r); + .runTaskAsynchronously(patchwork, r); } /** diff --git a/Patchwork/src/main/java/fns/patchwork/shop/ReactionTask.java b/Patchwork/src/main/java/fns/patchwork/shop/ReactionTask.java index 3af5916..360781b 100644 --- a/Patchwork/src/main/java/fns/patchwork/shop/ReactionTask.java +++ b/Patchwork/src/main/java/fns/patchwork/shop/ReactionTask.java @@ -1,6 +1,8 @@ package fns.patchwork.shop; import fns.patchwork.base.Patchwork; +import fns.patchwork.base.Registration; +import fns.patchwork.base.Shortcuts; import fns.patchwork.display.BossBarDisplay; import fns.patchwork.display.BossBarTimer; import fns.patchwork.economy.EconomicEntity; @@ -36,7 +38,7 @@ public class ReactionTask extends Task implements Listener } final BossBarTimer timer = new BossBarTimer(bossBarDisplay, reaction.getReactionDuration()); - timer.runTaskTimer(Patchwork.getInstance(), 0L, timer.getInterval()); + timer.runTaskTimer(Shortcuts.provideModule(Patchwork.class), 0L, timer.getInterval()); } @EventHandler @@ -45,9 +47,7 @@ public class ReactionTask extends Task implements Listener if (event.message() .equals(reaction.getReactionMessage())) { - final EconomicEntity entity = Patchwork.getInstance() - .getRegistrations() - .getUserRegistry() + final EconomicEntity entity = Registration.getUserRegistry() .getUser(event.getPlayer()); reaction.onReact(entity); diff --git a/Patchwork/src/main/resources/plugin.yml b/Patchwork/src/main/resources/plugin.yml index 5cbde93..c51a0e3 100644 --- a/Patchwork/src/main/resources/plugin.yml +++ b/Patchwork/src/main/resources/plugin.yml @@ -1,5 +1,6 @@ name: Patchwork -main: me.totalfreedom.base.CommonsBase +main: fns.patchwork.base.Patchwork +api-version: 1.20 version: 1.0.0 author: TotalFreedom description: The Core of Freedom Network Suite \ No newline at end of file