fix build, refactor Bukkit model classes
This commit is contained in:
parent
2bc56de1c3
commit
0cc1c4e5a7
@ -34,10 +34,11 @@ import me.lucko.luckperms.bukkit.contexts.WorldCalculator;
|
||||
import me.lucko.luckperms.bukkit.listeners.BukkitConnectionListener;
|
||||
import me.lucko.luckperms.bukkit.listeners.BukkitPlatformListener;
|
||||
import me.lucko.luckperms.bukkit.messaging.BukkitMessagingFactory;
|
||||
import me.lucko.luckperms.bukkit.model.LPPermissible;
|
||||
import me.lucko.luckperms.bukkit.model.PermissibleInjector;
|
||||
import me.lucko.luckperms.bukkit.model.PermissibleMonitoringInjector;
|
||||
import me.lucko.luckperms.bukkit.model.PermissionMapInjector;
|
||||
import me.lucko.luckperms.bukkit.model.SubscriptionMapInjector;
|
||||
import me.lucko.luckperms.bukkit.model.permissible.LPPermissible;
|
||||
import me.lucko.luckperms.bukkit.model.permissible.PermissibleInjector;
|
||||
import me.lucko.luckperms.bukkit.model.permissible.PermissibleMonitoringInjector;
|
||||
import me.lucko.luckperms.bukkit.processors.BukkitProcessorsSetupTask;
|
||||
import me.lucko.luckperms.bukkit.processors.ChildPermissionProvider;
|
||||
import me.lucko.luckperms.bukkit.processors.DefaultsProvider;
|
||||
@ -197,13 +198,10 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
|
||||
Set<StorageType> storageTypes = storageFactory.getRequiredTypes(StorageType.H2);
|
||||
this.dependencyManager.loadStorageDependencies(storageTypes);
|
||||
|
||||
// setup the Bukkit defaults hook
|
||||
// init the Bukkit model providers
|
||||
this.defaultsProvider = new DefaultsProvider();
|
||||
this.childPermissionProvider = new ChildPermissionProvider();
|
||||
|
||||
// give all plugins a chance to load their permissions, then refresh.
|
||||
this.scheduler.syncLater(new BukkitProcessorsSetupTask(this), 1L);
|
||||
|
||||
// register events
|
||||
BukkitConnectionListener connectionListener = new BukkitConnectionListener(this);
|
||||
getServer().getPluginManager().registerEvents(connectionListener, this);
|
||||
@ -248,12 +246,22 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
|
||||
this.contextManager.registerCalculator(new WorldCalculator(this));
|
||||
this.contextManager.registerStaticCalculator(new LuckPermsCalculator(getConfiguration()));
|
||||
|
||||
// inject our own subscription map
|
||||
new SubscriptionMapInjector(this).run();
|
||||
// inject our own custom permission maps
|
||||
SubscriptionMapInjector subscriptionMapInjector = new SubscriptionMapInjector(this);
|
||||
subscriptionMapInjector.run();
|
||||
|
||||
PermissionMapInjector permissionMapInjector = new PermissionMapInjector(this);
|
||||
permissionMapInjector.run();
|
||||
|
||||
// setup the bukkit processors
|
||||
BukkitProcessorsSetupTask bukkitProcessorsSetupTask = new BukkitProcessorsSetupTask(this);
|
||||
bukkitProcessorsSetupTask.run();
|
||||
|
||||
// schedule another injection after all plugins have loaded - the entire pluginmanager instance
|
||||
// is replaced by some plugins :(
|
||||
this.scheduler.asyncLater(new SubscriptionMapInjector(this), 2L);
|
||||
this.scheduler.asyncLater(subscriptionMapInjector, 1L);
|
||||
this.scheduler.asyncLater(permissionMapInjector, 1L);
|
||||
this.scheduler.syncLater(bukkitProcessorsSetupTask, 1L);
|
||||
|
||||
// inject verbose handlers into internal bukkit objects
|
||||
new PermissibleMonitoringInjector(this).run();
|
||||
@ -367,8 +375,9 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
// uninject subscription map
|
||||
// uninject custom maps
|
||||
SubscriptionMapInjector.uninject();
|
||||
PermissionMapInjector.uninject();
|
||||
|
||||
getLog().info("Closing storage...");
|
||||
this.storage.shutdown();
|
||||
|
@ -26,8 +26,8 @@
|
||||
package me.lucko.luckperms.bukkit.listeners;
|
||||
|
||||
import me.lucko.luckperms.bukkit.LPBukkitPlugin;
|
||||
import me.lucko.luckperms.bukkit.model.LPPermissible;
|
||||
import me.lucko.luckperms.bukkit.model.PermissibleInjector;
|
||||
import me.lucko.luckperms.bukkit.model.permissible.LPPermissible;
|
||||
import me.lucko.luckperms.bukkit.model.permissible.PermissibleInjector;
|
||||
import me.lucko.luckperms.common.config.ConfigKeys;
|
||||
import me.lucko.luckperms.common.locale.Message;
|
||||
import me.lucko.luckperms.common.model.User;
|
||||
@ -90,7 +90,7 @@ public class BukkitConnectionListener extends AbstractLoginListener implements L
|
||||
User user = loadUser(e.getUniqueId(), e.getName());
|
||||
this.plugin.getEventFactory().handleUserLoginProcess(e.getUniqueId(), e.getName(), user);
|
||||
} catch (Exception ex) {
|
||||
this.plugin.getLog().severe("Exception occured whilst loading data for " + e.getUniqueId() + " - " + e.getName());
|
||||
this.plugin.getLog().severe("Exception occurred whilst loading data for " + e.getUniqueId() + " - " + e.getName());
|
||||
ex.printStackTrace();
|
||||
|
||||
// deny the connection
|
||||
|
@ -0,0 +1,72 @@
|
||||
/*
|
||||
* This file is part of LuckPerms, licensed under the MIT License.
|
||||
*
|
||||
* Copyright (c) lucko (Luck) <luck@lucko.me>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.bukkit.model;
|
||||
|
||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.common.treeview.PermissionVault;
|
||||
|
||||
import org.bukkit.permissions.Permission;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* A replacement map for the 'permissions' instance in Bukkit's SimplePluginManager.
|
||||
*
|
||||
* This instance allows LuckPerms to intercept calls to
|
||||
* {@link PluginManager#addPermission(Permission)} and record permissions in the
|
||||
* {@link PermissionVault}.
|
||||
*
|
||||
* Injected by {@link PermissionMapInjector}.
|
||||
*/
|
||||
public class LPPermissionMap extends HashMap<String, Permission> {
|
||||
final LuckPermsPlugin plugin;
|
||||
|
||||
public LPPermissionMap(LuckPermsPlugin plugin, Map<String, Permission> existingData) {
|
||||
this.plugin = plugin;
|
||||
putAll(existingData);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Permission put(String key, Permission value) {
|
||||
this.plugin.getPermissionVault().offer(key);
|
||||
return super.put(key, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putAll(Map<? extends String, ? extends Permission> m) {
|
||||
this.plugin.getPermissionVault().offerAll(m.keySet());
|
||||
super.putAll(m);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Permission putIfAbsent(String key, Permission value) {
|
||||
this.plugin.getPermissionVault().offer(key);
|
||||
return super.putIfAbsent(key, value);
|
||||
}
|
||||
|
||||
}
|
@ -65,11 +65,13 @@ import javax.annotation.Nonnull;
|
||||
* 2) inject it's own map instance to proxy calls to {@link PluginManager#getPermissionSubscriptions(String)} back to LuckPerms.
|
||||
*
|
||||
* This class implements option 2 above. It is preferred because it is faster & uses less memory
|
||||
*
|
||||
* Injected by {@link SubscriptionMapInjector}.
|
||||
*/
|
||||
public class LPSubscriptionMap extends HashMap<String, Map<Permissible, Boolean>> {
|
||||
|
||||
// the plugin instance
|
||||
private final LPBukkitPlugin plugin;
|
||||
final LPBukkitPlugin plugin;
|
||||
|
||||
public LPSubscriptionMap(LPBukkitPlugin plugin, Map<String, Map<Permissible, Boolean>> existingData) {
|
||||
super(existingData);
|
||||
|
@ -0,0 +1,117 @@
|
||||
/*
|
||||
* This file is part of LuckPerms, licensed under the MIT License.
|
||||
*
|
||||
* Copyright (c) lucko (Luck) <luck@lucko.me>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.bukkit.model;
|
||||
|
||||
import me.lucko.luckperms.bukkit.LPBukkitPlugin;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.permissions.Permission;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.SimplePluginManager;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Injects a {@link LPPermissionMap} into the {@link PluginManager}.
|
||||
*/
|
||||
public class PermissionMapInjector implements Runnable {
|
||||
private static final Field PERMISSIONS_FIELD;
|
||||
|
||||
static {
|
||||
Field permissionsField = null;
|
||||
try {
|
||||
permissionsField = SimplePluginManager.class.getDeclaredField("permissions");
|
||||
permissionsField.setAccessible(true);
|
||||
} catch (Exception e) {
|
||||
// ignore
|
||||
}
|
||||
PERMISSIONS_FIELD = permissionsField;
|
||||
}
|
||||
|
||||
private final LPBukkitPlugin plugin;
|
||||
|
||||
public PermissionMapInjector(LPBukkitPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
inject();
|
||||
} catch (Exception e) {
|
||||
this.plugin.getLog().severe("Exception occurred whilst injecting LuckPerms Permission map.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void inject() throws Exception {
|
||||
Objects.requireNonNull(PERMISSIONS_FIELD, "PERMISSIONS_FIELD");
|
||||
PluginManager pluginManager = this.plugin.getServer().getPluginManager();
|
||||
|
||||
if (!(pluginManager instanceof SimplePluginManager)) {
|
||||
this.plugin.getLog().severe("PluginManager instance is not a 'SimplePluginManager', instead: " + pluginManager.getClass());
|
||||
this.plugin.getLog().severe("Unable to inject LuckPerms Permission map.");
|
||||
return;
|
||||
}
|
||||
|
||||
Object map = PERMISSIONS_FIELD.get(pluginManager);
|
||||
if (map instanceof LPPermissionMap && ((LPPermissionMap) map).plugin == this.plugin) {
|
||||
return;
|
||||
}
|
||||
|
||||
//noinspection unchecked
|
||||
Map<String, Permission> castedMap = (Map<String, Permission>) map;
|
||||
|
||||
// make a new map
|
||||
LPPermissionMap newMap = new LPPermissionMap(this.plugin, castedMap);
|
||||
|
||||
// inject it
|
||||
PERMISSIONS_FIELD.set(pluginManager, newMap);
|
||||
}
|
||||
|
||||
public static void uninject() {
|
||||
try {
|
||||
Objects.requireNonNull(PERMISSIONS_FIELD, "PERMISSIONS_FIELD");
|
||||
|
||||
PluginManager pluginManager = Bukkit.getServer().getPluginManager();
|
||||
if (!(pluginManager instanceof SimplePluginManager)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Object map = PERMISSIONS_FIELD.get(pluginManager);
|
||||
if (map instanceof LPPermissionMap) {
|
||||
LPPermissionMap lpMap = (LPPermissionMap) map;
|
||||
PERMISSIONS_FIELD.set(pluginManager, new HashMap<>(lpMap));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -34,17 +34,23 @@ import org.bukkit.plugin.SimplePluginManager;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Injects a {@link LPSubscriptionMap} into the {@link PluginManager}.
|
||||
*/
|
||||
public class SubscriptionMapInjector implements Runnable {
|
||||
private static final Field PERM_SUBS_FIELD;
|
||||
|
||||
static {
|
||||
Field permSubsField = null;
|
||||
try {
|
||||
PERM_SUBS_FIELD = SimplePluginManager.class.getDeclaredField("permSubs");
|
||||
PERM_SUBS_FIELD.setAccessible(true);
|
||||
} catch (NoSuchFieldException e) {
|
||||
throw new ExceptionInInitializerError(e);
|
||||
permSubsField = SimplePluginManager.class.getDeclaredField("permSubs");
|
||||
permSubsField.setAccessible(true);
|
||||
} catch (Exception e) {
|
||||
// ignore
|
||||
}
|
||||
PERM_SUBS_FIELD = permSubsField;
|
||||
}
|
||||
|
||||
private final LPBukkitPlugin plugin;
|
||||
@ -64,6 +70,7 @@ public class SubscriptionMapInjector implements Runnable {
|
||||
}
|
||||
|
||||
private void inject() throws Exception {
|
||||
Objects.requireNonNull(PERM_SUBS_FIELD, "PERM_SUBS_FIELD");
|
||||
PluginManager pluginManager = this.plugin.getServer().getPluginManager();
|
||||
|
||||
if (!(pluginManager instanceof SimplePluginManager)) {
|
||||
@ -74,7 +81,11 @@ public class SubscriptionMapInjector implements Runnable {
|
||||
|
||||
Object map = PERM_SUBS_FIELD.get(pluginManager);
|
||||
if (map instanceof LPSubscriptionMap) {
|
||||
return; // already injected
|
||||
if (((LPSubscriptionMap) map).plugin == this.plugin) {
|
||||
return;
|
||||
}
|
||||
|
||||
map = ((LPSubscriptionMap) map).detach();
|
||||
}
|
||||
|
||||
//noinspection unchecked
|
||||
@ -89,6 +100,8 @@ public class SubscriptionMapInjector implements Runnable {
|
||||
|
||||
public static void uninject() {
|
||||
try {
|
||||
Objects.requireNonNull(PERM_SUBS_FIELD, "PERM_SUBS_FIELD");
|
||||
|
||||
PluginManager pluginManager = Bukkit.getServer().getPluginManager();
|
||||
if (!(pluginManager instanceof SimplePluginManager)) {
|
||||
return;
|
||||
|
@ -23,7 +23,7 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.bukkit.model;
|
||||
package me.lucko.luckperms.bukkit.model.dummy;
|
||||
|
||||
import org.bukkit.permissions.Permissible;
|
||||
import org.bukkit.permissions.Permission;
|
@ -23,7 +23,7 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.bukkit.model;
|
||||
package me.lucko.luckperms.bukkit.model.dummy;
|
||||
|
||||
import org.bukkit.permissions.PermissibleBase;
|
||||
import org.bukkit.permissions.Permission;
|
@ -23,7 +23,7 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.bukkit.model;
|
||||
package me.lucko.luckperms.bukkit.model.dummy;
|
||||
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.command.Command;
|
@ -23,7 +23,7 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.bukkit.model;
|
||||
package me.lucko.luckperms.bukkit.model.permissible;
|
||||
|
||||
import me.lucko.luckperms.api.Contexts;
|
||||
import me.lucko.luckperms.api.Tristate;
|
@ -23,11 +23,12 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.bukkit.model;
|
||||
package me.lucko.luckperms.bukkit.model.permissible;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
import me.lucko.luckperms.api.Node;
|
||||
import me.lucko.luckperms.bukkit.model.dummy.DummyPlugin;
|
||||
import me.lucko.luckperms.common.config.ConfigKeys;
|
||||
import me.lucko.luckperms.common.model.User;
|
||||
import me.lucko.luckperms.common.node.ImmutableTransientNode;
|
@ -23,10 +23,12 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.bukkit.model;
|
||||
package me.lucko.luckperms.bukkit.model.permissible;
|
||||
|
||||
import me.lucko.luckperms.api.Tristate;
|
||||
import me.lucko.luckperms.api.context.ContextSet;
|
||||
import me.lucko.luckperms.bukkit.model.dummy.DummyPermissibleBase;
|
||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.common.verbose.CheckOrigin;
|
||||
import me.lucko.luckperms.common.verbose.VerboseHandler;
|
||||
|
||||
@ -45,7 +47,7 @@ import java.util.Set;
|
||||
* Method calls are forwarded to the delegate permissible.
|
||||
*/
|
||||
public class MonitoredPermissibleBase extends PermissibleBase {
|
||||
private final VerboseHandler verboseHandler;
|
||||
private final LuckPermsPlugin plugin;
|
||||
private final PermissibleBase delegate;
|
||||
private final String name;
|
||||
|
||||
@ -54,11 +56,11 @@ public class MonitoredPermissibleBase extends PermissibleBase {
|
||||
@SuppressWarnings("UnusedAssignment")
|
||||
private boolean initialised = false;
|
||||
|
||||
public MonitoredPermissibleBase(VerboseHandler verboseHandler, PermissibleBase delegate, String name) {
|
||||
public MonitoredPermissibleBase(LuckPermsPlugin plugin, PermissibleBase delegate, String name) {
|
||||
super(null);
|
||||
DummyPermissibleBase.nullFields(this);
|
||||
|
||||
this.verboseHandler = verboseHandler;
|
||||
this.plugin = plugin;
|
||||
this.delegate = delegate;
|
||||
this.name = name;
|
||||
this.initialised = true;
|
||||
@ -69,7 +71,8 @@ public class MonitoredPermissibleBase extends PermissibleBase {
|
||||
}
|
||||
|
||||
private void logCheck(CheckOrigin origin, String permission, boolean result) {
|
||||
this.verboseHandler.offerCheckData(origin, this.name, ContextSet.empty(), permission, Tristate.fromBoolean(result));
|
||||
this.plugin.getVerboseHandler().offerCheckData(origin, this.name, ContextSet.empty(), permission, Tristate.fromBoolean(result));
|
||||
this.plugin.getPermissionVault().offer(permission);
|
||||
}
|
||||
|
||||
PermissibleBase getDelegate() {
|
@ -23,9 +23,10 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.bukkit.model;
|
||||
package me.lucko.luckperms.bukkit.model.permissible;
|
||||
|
||||
import me.lucko.luckperms.bukkit.compat.ReflectionUtil;
|
||||
import me.lucko.luckperms.bukkit.model.dummy.DummyPermissibleBase;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.PermissibleBase;
|
@ -23,7 +23,7 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.bukkit.model;
|
||||
package me.lucko.luckperms.bukkit.model.permissible;
|
||||
|
||||
import me.lucko.luckperms.bukkit.LPBukkitPlugin;
|
||||
import me.lucko.luckperms.bukkit.compat.ReflectionUtil;
|
||||
@ -77,7 +77,7 @@ public class PermissibleMonitoringInjector implements Runnable {
|
||||
}
|
||||
|
||||
// create a monitored instance which delegates to the previous PermissibleBase
|
||||
return new MonitoredPermissibleBase(this.plugin.getVerboseHandler(), permBase, name);
|
||||
return new MonitoredPermissibleBase(this.plugin, permBase, name);
|
||||
}
|
||||
|
||||
private void injectConsole() throws Exception {
|
@ -27,9 +27,6 @@ package me.lucko.luckperms.bukkit.processors;
|
||||
|
||||
import me.lucko.luckperms.bukkit.LPBukkitPlugin;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Performs the initial setup for Bukkit permission processors
|
||||
*/
|
||||
@ -44,13 +41,5 @@ public class BukkitProcessorsSetupTask implements Runnable {
|
||||
public void run() {
|
||||
this.plugin.getDefaultsProvider().refresh();
|
||||
this.plugin.getChildPermissionProvider().setup();
|
||||
|
||||
Set<String> perms = new HashSet<>();
|
||||
this.plugin.getServer().getPluginManager().getPermissions().forEach(p -> {
|
||||
perms.add(p.getName());
|
||||
perms.addAll(p.getChildren().keySet());
|
||||
});
|
||||
|
||||
perms.forEach(p -> this.plugin.getPermissionVault().offer(p));
|
||||
}
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ package me.lucko.luckperms.bukkit.processors;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
import me.lucko.luckperms.api.Tristate;
|
||||
import me.lucko.luckperms.bukkit.model.DummyPermissible;
|
||||
import me.lucko.luckperms.bukkit.model.dummy.DummyPermissible;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.permissions.Permission;
|
||||
@ -79,15 +79,6 @@ public class DefaultsProvider {
|
||||
return Tristate.fromNullableBoolean(map.get(permission));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the number of default permissions held by the provider.
|
||||
*
|
||||
* @return the number of permissions held
|
||||
*/
|
||||
public int size() {
|
||||
return this.opDefaults.size() + this.nonOpDefaults.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Refreshes the op data in this provider.
|
||||
*/
|
||||
|
@ -86,7 +86,7 @@ public class BungeeConnectionListener extends AbstractLoginListener implements L
|
||||
User user = loadUser(c.getUniqueId(), c.getName());
|
||||
this.plugin.getEventFactory().handleUserLoginProcess(c.getUniqueId(), c.getName(), user);
|
||||
} catch (Exception ex) {
|
||||
this.plugin.getLog().severe("Exception occured whilst loading data for " + c.getUniqueId() + " - " + c.getName());
|
||||
this.plugin.getLog().severe("Exception occurred whilst loading data for " + c.getUniqueId() + " - " + c.getName());
|
||||
ex.printStackTrace();
|
||||
|
||||
// there was some error loading
|
||||
|
@ -37,6 +37,8 @@ import me.lucko.luckperms.api.event.cause.CreationCause;
|
||||
import me.lucko.luckperms.api.event.cause.DeletionCause;
|
||||
import me.lucko.luckperms.api.event.log.LogBroadcastEvent;
|
||||
import me.lucko.luckperms.common.api.LuckPermsApiProvider;
|
||||
import me.lucko.luckperms.common.api.delegates.model.ApiPermissionHolder;
|
||||
import me.lucko.luckperms.common.api.delegates.model.ApiUser;
|
||||
import me.lucko.luckperms.common.commands.sender.Sender;
|
||||
import me.lucko.luckperms.common.event.impl.EventConfigReload;
|
||||
import me.lucko.luckperms.common.event.impl.EventGroupCacheLoad;
|
||||
@ -164,17 +166,17 @@ public final class EventFactory {
|
||||
}
|
||||
|
||||
public void handleNodeAdd(Node node, PermissionHolder target, Collection<Node> before, Collection<Node> after) {
|
||||
EventNodeAdd event = new EventNodeAdd(node, target.getDelegate(), ImmutableSet.copyOf(before), ImmutableSet.copyOf(after));
|
||||
EventNodeAdd event = new EventNodeAdd(node, getDelegate(target), ImmutableSet.copyOf(before), ImmutableSet.copyOf(after));
|
||||
fireEventAsync(event);
|
||||
}
|
||||
|
||||
public void handleNodeClear(PermissionHolder target, Collection<Node> before, Collection<Node> after) {
|
||||
EventNodeClear event = new EventNodeClear(target.getDelegate(), ImmutableSet.copyOf(before), ImmutableSet.copyOf(after));
|
||||
EventNodeClear event = new EventNodeClear(getDelegate(target), ImmutableSet.copyOf(before), ImmutableSet.copyOf(after));
|
||||
fireEventAsync(event);
|
||||
}
|
||||
|
||||
public void handleNodeRemove(Node node, PermissionHolder target, Collection<Node> before, Collection<Node> after) {
|
||||
EventNodeRemove event = new EventNodeRemove(node, target.getDelegate(), ImmutableSet.copyOf(before), ImmutableSet.copyOf(after));
|
||||
EventNodeRemove event = new EventNodeRemove(node, getDelegate(target), ImmutableSet.copyOf(before), ImmutableSet.copyOf(after));
|
||||
fireEventAsync(event);
|
||||
}
|
||||
|
||||
@ -238,12 +240,12 @@ public final class EventFactory {
|
||||
}
|
||||
|
||||
public void handleUserCacheLoad(User user, UserData data) {
|
||||
EventUserCacheLoad event = new EventUserCacheLoad(user.getDelegate(), data);
|
||||
EventUserCacheLoad event = new EventUserCacheLoad(new ApiUser(user), data);
|
||||
fireEventAsync(event);
|
||||
}
|
||||
|
||||
public void handleUserDataRecalculate(User user, UserData data) {
|
||||
EventUserDataRecalculate event = new EventUserDataRecalculate(user.getDelegate(), data);
|
||||
EventUserDataRecalculate event = new EventUserDataRecalculate(new ApiUser(user), data);
|
||||
fireEventAsync(event);
|
||||
}
|
||||
|
||||
@ -253,23 +255,33 @@ public final class EventFactory {
|
||||
}
|
||||
|
||||
public void handleUserLoad(User user) {
|
||||
EventUserLoad event = new EventUserLoad(user.getDelegate());
|
||||
EventUserLoad event = new EventUserLoad(new ApiUser(user));
|
||||
fireEventAsync(event);
|
||||
}
|
||||
|
||||
public void handleUserLoginProcess(UUID uuid, String username, User user) {
|
||||
EventUserLoginProcess event = new EventUserLoginProcess(uuid, username, user.getDelegate());
|
||||
EventUserLoginProcess event = new EventUserLoginProcess(uuid, username, new ApiUser(user));
|
||||
fireEvent(event);
|
||||
}
|
||||
|
||||
public void handleUserDemote(User user, Track track, String from, String to) {
|
||||
EventUserDemote event = new EventUserDemote(track.getApiDelegate(), user.getDelegate(), from, to);
|
||||
EventUserDemote event = new EventUserDemote(track.getApiDelegate(), new ApiUser(user), from, to);
|
||||
fireEventAsync(event);
|
||||
}
|
||||
|
||||
public void handleUserPromote(User user, Track track, String from, String to) {
|
||||
EventUserPromote event = new EventUserPromote(track.getApiDelegate(), user.getDelegate(), from, to);
|
||||
EventUserPromote event = new EventUserPromote(track.getApiDelegate(), new ApiUser(user), from, to);
|
||||
fireEventAsync(event);
|
||||
}
|
||||
|
||||
private static ApiPermissionHolder getDelegate(PermissionHolder holder) {
|
||||
if (holder instanceof Group) {
|
||||
return ((Group) holder).getApiDelegate();
|
||||
} else if (holder instanceof User) {
|
||||
return new ApiUser(((User) holder));
|
||||
} else {
|
||||
throw new AssertionError();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -28,6 +28,7 @@ package me.lucko.luckperms.common.treeview;
|
||||
import com.google.common.base.Splitter;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Queue;
|
||||
@ -99,6 +100,10 @@ public class PermissionVault implements Runnable {
|
||||
this.queue.offer(permission);
|
||||
}
|
||||
|
||||
public void offerAll(Collection<? extends String> permissions) {
|
||||
this.queue.addAll(permissions);
|
||||
}
|
||||
|
||||
public Set<String> getKnownPermissions() {
|
||||
return ImmutableSet.copyOf(this.knownPermissions);
|
||||
}
|
||||
|
@ -84,7 +84,7 @@ public class SpongeConnectionListener extends AbstractLoginListener {
|
||||
User user = loadUser(p.getUniqueId(), username);
|
||||
this.plugin.getEventFactory().handleUserLoginProcess(p.getUniqueId(), username, user);
|
||||
} catch (Exception ex) {
|
||||
this.plugin.getLog().severe("Exception occured whilst loading data for " + p.getUniqueId() + " - " + p.getName());
|
||||
this.plugin.getLog().severe("Exception occurred whilst loading data for " + p.getUniqueId() + " - " + p.getName());
|
||||
ex.printStackTrace();
|
||||
|
||||
this.deniedAsyncLogin.add(p.getUniqueId());
|
||||
|
Loading…
Reference in New Issue
Block a user