mirror of
https://github.com/SimplexDevelopment/FreedomNetworkSuite.git
synced 2025-06-26 19:44:27 +00:00
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>
This commit is contained in:
@ -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.
|
||||
|
@ -11,53 +11,44 @@ import fns.patchwork.data.UserRegistry;
|
||||
* This class is a holder for each registry in the data package.
|
||||
* <br>
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
}
|
@ -13,18 +13,14 @@ public final class Shortcuts
|
||||
|
||||
public static <T extends JavaPlugin> T provideModule(final Class<T> 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);
|
||||
}
|
||||
}
|
||||
|
@ -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<UUID, AdminChatFormat> adminChatFormat = new HashMap<>();
|
||||
private final Set<UUID> 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())
|
||||
{
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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);
|
||||
|
@ -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
|
Reference in New Issue
Block a user