mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2025-02-17 04:51:25 +01:00
Some misc tidying up
This commit is contained in:
parent
05c9ca5951
commit
ad49508b74
@ -60,8 +60,6 @@ import me.lucko.luckperms.common.model.manager.user.StandardUserManager;
|
||||
import me.lucko.luckperms.common.plugin.AbstractLuckPermsPlugin;
|
||||
import me.lucko.luckperms.common.plugin.util.AbstractConnectionListener;
|
||||
import me.lucko.luckperms.common.sender.Sender;
|
||||
import me.lucko.luckperms.common.tasks.CacheHousekeepingTask;
|
||||
import me.lucko.luckperms.common.tasks.ExpireTemporaryTask;
|
||||
|
||||
import net.luckperms.api.LuckPerms;
|
||||
import net.luckperms.api.query.QueryOptions;
|
||||
@ -79,7 +77,6 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
@ -259,12 +256,6 @@ public class LPBukkitPlugin extends AbstractLuckPermsPlugin {
|
||||
this.bootstrap.getServer().getServicesManager().register(LuckPerms.class, api, this.bootstrap.getLoader(), ServicePriority.Normal);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerHousekeepingTasks() {
|
||||
this.bootstrap.getScheduler().asyncRepeating(new ExpireTemporaryTask(this), 3, TimeUnit.SECONDS);
|
||||
this.bootstrap.getScheduler().asyncRepeating(new CacheHousekeepingTask(this), 2, TimeUnit.MINUTES);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void performFinalSetup() {
|
||||
// register permissions
|
||||
|
@ -47,8 +47,6 @@ import me.lucko.luckperms.common.model.manager.user.StandardUserManager;
|
||||
import me.lucko.luckperms.common.plugin.AbstractLuckPermsPlugin;
|
||||
import me.lucko.luckperms.common.plugin.util.AbstractConnectionListener;
|
||||
import me.lucko.luckperms.common.sender.Sender;
|
||||
import me.lucko.luckperms.common.tasks.CacheHousekeepingTask;
|
||||
import me.lucko.luckperms.common.tasks.ExpireTemporaryTask;
|
||||
|
||||
import net.luckperms.api.LuckPerms;
|
||||
import net.luckperms.api.context.DefaultContextKeys;
|
||||
@ -57,7 +55,6 @@ import net.md_5.bungee.api.plugin.Plugin;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
@ -170,12 +167,6 @@ public class LPBungeePlugin extends AbstractLuckPermsPlugin {
|
||||
// BungeeCord doesn't have a services manager
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerHousekeepingTasks() {
|
||||
this.bootstrap.getScheduler().asyncRepeating(new ExpireTemporaryTask(this), 3, TimeUnit.SECONDS);
|
||||
this.bootstrap.getScheduler().asyncRepeating(new CacheHousekeepingTask(this), 2, TimeUnit.MINUTES);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void performFinalSetup() {
|
||||
|
||||
|
@ -115,13 +115,23 @@ public final class EventDispatcher {
|
||||
return this.eventBus;
|
||||
}
|
||||
|
||||
private <T extends LuckPermsEvent> void postAsync(Class<T> eventClass, Object... params) {
|
||||
// check against common mistakes - events with any sort of result shouldn't be posted async
|
||||
if (Cancellable.class.isAssignableFrom(eventClass)) {
|
||||
throw new RuntimeException("Cancellable event cannot be posted async (" + eventClass + ")");
|
||||
private LuckPermsEvent generate(Class<? extends LuckPermsEvent> eventClass, Object... params) {
|
||||
try {
|
||||
return GeneratedEventClass.generate(eventClass).newInstance(this.eventBus.getApiProvider(), params);
|
||||
} catch (Throwable e) {
|
||||
throw new RuntimeException("Exception occurred whilst generating event instance", e);
|
||||
}
|
||||
if (ResultEvent.class.isAssignableFrom(eventClass)) {
|
||||
throw new RuntimeException("ResultEvent event cannot be posted async (" + eventClass + ")");
|
||||
}
|
||||
|
||||
private void post(Class<? extends LuckPermsEvent> eventClass, Object... params) {
|
||||
LuckPermsEvent event = generate(eventClass, params);
|
||||
this.eventBus.post(event);
|
||||
}
|
||||
|
||||
private void postAsync(Class<? extends LuckPermsEvent> eventClass, Object... params) {
|
||||
// check against common mistakes - events with any sort of result shouldn't be posted async
|
||||
if (Cancellable.class.isAssignableFrom(eventClass) || ResultEvent.class.isAssignableFrom(eventClass)) {
|
||||
throw new RuntimeException("Event cannot be posted async (" + eventClass.getName() + ")");
|
||||
}
|
||||
|
||||
// if there aren't any handlers registered for the event, don't bother trying to post it
|
||||
@ -130,24 +140,24 @@ public final class EventDispatcher {
|
||||
}
|
||||
|
||||
// async: generate an event class and post it
|
||||
this.eventBus.getPlugin().getBootstrap().getScheduler().executeAsync(() -> {
|
||||
T event = generate(eventClass, params);
|
||||
this.eventBus.post(event);
|
||||
});
|
||||
this.eventBus.getPlugin().getBootstrap().getScheduler().executeAsync(() -> post(eventClass, params));
|
||||
}
|
||||
|
||||
private <T extends LuckPermsEvent> void postSync(Class<T> eventClass, Object... params) {
|
||||
private void postSync(Class<? extends LuckPermsEvent> eventClass, Object... params) {
|
||||
// if there aren't any handlers registered for our event, don't bother trying to post it
|
||||
if (!this.eventBus.shouldPost(eventClass)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// generate an event class and post it
|
||||
T event = generate(eventClass, params);
|
||||
this.eventBus.post(event);
|
||||
post(eventClass, params);
|
||||
}
|
||||
|
||||
private <T extends LuckPermsEvent & Cancellable> boolean postCancellable(Class<T> eventClass, Object... params) {
|
||||
private boolean postCancellable(Class<? extends LuckPermsEvent> eventClass, Object... params) {
|
||||
if (!Cancellable.class.isAssignableFrom(eventClass)) {
|
||||
throw new RuntimeException("Event is not cancellable: " + eventClass.getName());
|
||||
}
|
||||
|
||||
// extract the initial state from the first parameter
|
||||
boolean initialState = (boolean) params[0];
|
||||
|
||||
@ -159,23 +169,14 @@ public final class EventDispatcher {
|
||||
// otherwise:
|
||||
// - initialise an AtomicBoolean for the result with the initial state
|
||||
// - replace the boolean with the AtomicBoolean in the params array
|
||||
// - post the event
|
||||
// - generate an event class and post it
|
||||
AtomicBoolean cancel = new AtomicBoolean(initialState);
|
||||
params[0] = cancel;
|
||||
postSync(eventClass, params);
|
||||
post(eventClass, params);
|
||||
|
||||
// return the final status
|
||||
return cancel.get();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private <T extends LuckPermsEvent> T generate(Class<T> eventClass, Object... params) {
|
||||
try {
|
||||
return (T) GeneratedEventClass.generate(eventClass).newInstance(this.eventBus.getApiProvider(), params);
|
||||
} catch (Throwable e) {
|
||||
throw new RuntimeException("Exception occurred whilst generating event instance", e);
|
||||
}
|
||||
}
|
||||
|
||||
public void dispatchContextUpdate(Object subject) {
|
||||
postSync(ContextUpdateEvent.class, subject);
|
||||
@ -390,8 +391,9 @@ public final class EventDispatcher {
|
||||
}
|
||||
}
|
||||
|
||||
public static List<Class<? extends LuckPermsEvent>> getKnownEventTypes() {
|
||||
return ImmutableList.of(
|
||||
@SuppressWarnings("unchecked")
|
||||
public static Class<? extends LuckPermsEvent>[] getKnownEventTypes() {
|
||||
return new Class[]{
|
||||
ContextUpdateEvent.class,
|
||||
ExtensionLoadEvent.class,
|
||||
GroupCacheLoadEvent.class,
|
||||
@ -432,7 +434,7 @@ public final class EventDispatcher {
|
||||
UserUnloadEvent.class,
|
||||
UserDemoteEvent.class,
|
||||
UserPromoteEvent.class
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -52,6 +52,8 @@ import me.lucko.luckperms.common.storage.StorageFactory;
|
||||
import me.lucko.luckperms.common.storage.StorageType;
|
||||
import me.lucko.luckperms.common.storage.implementation.file.watcher.FileWatcher;
|
||||
import me.lucko.luckperms.common.storage.misc.DataConstraints;
|
||||
import me.lucko.luckperms.common.tasks.CacheHousekeepingTask;
|
||||
import me.lucko.luckperms.common.tasks.ExpireTemporaryTask;
|
||||
import me.lucko.luckperms.common.tasks.SyncTask;
|
||||
import me.lucko.luckperms.common.treeview.PermissionRegistry;
|
||||
import me.lucko.luckperms.common.verbose.VerboseHandler;
|
||||
@ -195,9 +197,9 @@ public abstract class AbstractLuckPermsPlugin implements LuckPermsPlugin {
|
||||
this.extensionManager.loadExtensions(getBootstrap().getConfigDirectory().resolve("extensions"));
|
||||
|
||||
// schedule update tasks
|
||||
int mins = getConfiguration().get(ConfigKeys.SYNC_TIME);
|
||||
if (mins > 0) {
|
||||
getBootstrap().getScheduler().asyncRepeating(() -> this.syncTaskBuffer.request(), mins, TimeUnit.MINUTES);
|
||||
int syncMins = getConfiguration().get(ConfigKeys.SYNC_TIME);
|
||||
if (syncMins > 0) {
|
||||
getBootstrap().getScheduler().asyncRepeating(() -> this.syncTaskBuffer.request(), syncMins, TimeUnit.MINUTES);
|
||||
}
|
||||
|
||||
// run an update instantly.
|
||||
@ -261,6 +263,8 @@ public abstract class AbstractLuckPermsPlugin implements LuckPermsPlugin {
|
||||
getLogger().info("Goodbye!");
|
||||
}
|
||||
|
||||
// hooks called during load
|
||||
|
||||
protected Set<Dependency> getGlobalDependencies() {
|
||||
return EnumSet.of(
|
||||
Dependency.ADVENTURE,
|
||||
@ -272,22 +276,11 @@ public abstract class AbstractLuckPermsPlugin implements LuckPermsPlugin {
|
||||
);
|
||||
}
|
||||
|
||||
protected Path resolveConfig(String fileName) {
|
||||
Path configFile = getBootstrap().getConfigDirectory().resolve(fileName);
|
||||
if (!Files.exists(configFile)) {
|
||||
try {
|
||||
Files.createDirectories(configFile.getParent());
|
||||
} catch (IOException e) {
|
||||
// ignore
|
||||
}
|
||||
// hooks called during enable
|
||||
|
||||
try (InputStream is = getBootstrap().getResourceStream(fileName)) {
|
||||
Files.copy(is, configFile);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
return configFile;
|
||||
protected void registerHousekeepingTasks() {
|
||||
getBootstrap().getScheduler().asyncRepeating(new ExpireTemporaryTask(this), 3, TimeUnit.SECONDS);
|
||||
getBootstrap().getScheduler().asyncRepeating(new CacheHousekeepingTask(this), 2, TimeUnit.MINUTES);
|
||||
}
|
||||
|
||||
protected abstract void setupSenderFactory();
|
||||
@ -301,11 +294,33 @@ public abstract class AbstractLuckPermsPlugin implements LuckPermsPlugin {
|
||||
protected abstract void setupPlatformHooks();
|
||||
protected abstract AbstractEventBus<?> provideEventBus(LuckPermsApiProvider apiProvider);
|
||||
protected abstract void registerApiOnPlatform(LuckPerms api);
|
||||
protected abstract void registerHousekeepingTasks();
|
||||
protected abstract void performFinalSetup();
|
||||
|
||||
// hooks called during disable
|
||||
|
||||
protected void removePlatformHooks() {}
|
||||
|
||||
protected Path resolveConfig(String fileName) {
|
||||
Path configFile = getBootstrap().getConfigDirectory().resolve(fileName);
|
||||
|
||||
// if the config doesn't exist, create it based on the template in the resources dir
|
||||
if (!Files.exists(configFile)) {
|
||||
try {
|
||||
Files.createDirectories(configFile.getParent());
|
||||
} catch (IOException e) {
|
||||
// ignore
|
||||
}
|
||||
|
||||
try (InputStream is = getBootstrap().getResourceStream(fileName)) {
|
||||
Files.copy(is, configFile);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
return configFile;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PluginLogger getLogger() {
|
||||
return getBootstrap().getPluginLogger();
|
||||
|
@ -40,8 +40,6 @@ import me.lucko.luckperms.common.model.manager.user.StandardUserManager;
|
||||
import me.lucko.luckperms.common.plugin.AbstractLuckPermsPlugin;
|
||||
import me.lucko.luckperms.common.sender.DummyConsoleSender;
|
||||
import me.lucko.luckperms.common.sender.Sender;
|
||||
import me.lucko.luckperms.common.tasks.CacheHousekeepingTask;
|
||||
import me.lucko.luckperms.common.tasks.ExpireTemporaryTask;
|
||||
import me.lucko.luckperms.fabric.context.FabricContextManager;
|
||||
import me.lucko.luckperms.fabric.context.FabricPlayerCalculator;
|
||||
import me.lucko.luckperms.fabric.listeners.FabricConnectionListener;
|
||||
@ -57,7 +55,6 @@ import net.minecraft.server.MinecraftServer;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class LPFabricPlugin extends AbstractLuckPermsPlugin {
|
||||
@ -160,12 +157,6 @@ public class LPFabricPlugin extends AbstractLuckPermsPlugin {
|
||||
protected void registerApiOnPlatform(LuckPerms api) {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerHousekeepingTasks() {
|
||||
this.bootstrap.getScheduler().asyncRepeating(new ExpireTemporaryTask(this), 3, TimeUnit.SECONDS);
|
||||
this.bootstrap.getScheduler().asyncRepeating(new CacheHousekeepingTask(this), 2, TimeUnit.MINUTES);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void performFinalSetup() {
|
||||
}
|
||||
|
@ -39,8 +39,6 @@ import me.lucko.luckperms.common.model.manager.user.StandardUserManager;
|
||||
import me.lucko.luckperms.common.plugin.AbstractLuckPermsPlugin;
|
||||
import me.lucko.luckperms.common.plugin.util.AbstractConnectionListener;
|
||||
import me.lucko.luckperms.common.sender.Sender;
|
||||
import me.lucko.luckperms.common.tasks.CacheHousekeepingTask;
|
||||
import me.lucko.luckperms.common.tasks.ExpireTemporaryTask;
|
||||
import me.lucko.luckperms.nukkit.calculator.NukkitCalculatorFactory;
|
||||
import me.lucko.luckperms.nukkit.context.NukkitContextManager;
|
||||
import me.lucko.luckperms.nukkit.context.NukkitPlayerCalculator;
|
||||
@ -70,7 +68,6 @@ import cn.nukkit.plugin.service.ServicePriority;
|
||||
import cn.nukkit.utils.Config;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
@ -182,12 +179,6 @@ public class LPNukkitPlugin extends AbstractLuckPermsPlugin {
|
||||
this.bootstrap.getServer().getServiceManager().register(LuckPerms.class, api, this.bootstrap.getLoader(), ServicePriority.NORMAL);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerHousekeepingTasks() {
|
||||
this.bootstrap.getScheduler().asyncRepeating(new ExpireTemporaryTask(this), 3, TimeUnit.SECONDS);
|
||||
this.bootstrap.getScheduler().asyncRepeating(new CacheHousekeepingTask(this), 2, TimeUnit.MINUTES);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void performFinalSetup() {
|
||||
// register permissions
|
||||
|
@ -40,8 +40,6 @@ import me.lucko.luckperms.common.model.manager.track.StandardTrackManager;
|
||||
import me.lucko.luckperms.common.plugin.AbstractLuckPermsPlugin;
|
||||
import me.lucko.luckperms.common.sender.DummyConsoleSender;
|
||||
import me.lucko.luckperms.common.sender.Sender;
|
||||
import me.lucko.luckperms.common.tasks.CacheHousekeepingTask;
|
||||
import me.lucko.luckperms.common.tasks.ExpireTemporaryTask;
|
||||
import me.lucko.luckperms.sponge.calculator.SpongeCalculatorFactory;
|
||||
import me.lucko.luckperms.sponge.commands.SpongeParentCommand;
|
||||
import me.lucko.luckperms.sponge.context.SpongeContextManager;
|
||||
@ -201,8 +199,7 @@ public class LPSpongePlugin extends AbstractLuckPermsPlugin {
|
||||
|
||||
@Override
|
||||
protected void registerHousekeepingTasks() {
|
||||
this.bootstrap.getScheduler().asyncRepeating(new ExpireTemporaryTask(this), 3, TimeUnit.SECONDS);
|
||||
this.bootstrap.getScheduler().asyncRepeating(new CacheHousekeepingTask(this), 2, TimeUnit.MINUTES);
|
||||
super.registerHousekeepingTasks();
|
||||
this.bootstrap.getScheduler().asyncRepeating(new ServiceCacheHousekeepingTask(this.service), 2, TimeUnit.MINUTES);
|
||||
}
|
||||
|
||||
|
@ -40,8 +40,6 @@ import me.lucko.luckperms.common.model.manager.user.StandardUserManager;
|
||||
import me.lucko.luckperms.common.plugin.AbstractLuckPermsPlugin;
|
||||
import me.lucko.luckperms.common.plugin.util.AbstractConnectionListener;
|
||||
import me.lucko.luckperms.common.sender.Sender;
|
||||
import me.lucko.luckperms.common.tasks.CacheHousekeepingTask;
|
||||
import me.lucko.luckperms.common.tasks.ExpireTemporaryTask;
|
||||
import me.lucko.luckperms.velocity.calculator.VelocityCalculatorFactory;
|
||||
import me.lucko.luckperms.velocity.context.VelocityContextManager;
|
||||
import me.lucko.luckperms.velocity.context.VelocityPlayerCalculator;
|
||||
@ -55,7 +53,6 @@ import net.luckperms.api.query.QueryOptions;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
@ -158,12 +155,6 @@ public class LPVelocityPlugin extends AbstractLuckPermsPlugin {
|
||||
// Velocity doesn't have a services manager
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerHousekeepingTasks() {
|
||||
this.bootstrap.getScheduler().asyncRepeating(new ExpireTemporaryTask(this), 3, TimeUnit.SECONDS);
|
||||
this.bootstrap.getScheduler().asyncRepeating(new CacheHousekeepingTask(this), 2, TimeUnit.MINUTES);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void performFinalSetup() {
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user