Misc cleanup

This commit is contained in:
Luck 2018-07-29 17:12:05 -07:00
parent 952e41ad3d
commit b1ab465991
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
15 changed files with 91 additions and 49 deletions

View File

@ -193,6 +193,7 @@ public interface LuckPermsApi {
* @return the action logger
* @since 4.1
*/
@Nonnull
ActionLogger getActionLogger();
/**
@ -218,6 +219,7 @@ public interface LuckPermsApi {
* @return the context manager
* @since 4.0
*/
@Nonnull
ContextManager getContextManager();
/**

View File

@ -27,7 +27,7 @@ package me.lucko.luckperms.bukkit;
import me.lucko.luckperms.api.Tristate;
import me.lucko.luckperms.bukkit.compat.BukkitJsonMessageHandler;
import me.lucko.luckperms.bukkit.compat.ReflectionUtil;
import me.lucko.luckperms.bukkit.compat.CraftBukkitUtil;
import me.lucko.luckperms.bukkit.compat.SpigotJsonMessageHandler;
import me.lucko.luckperms.common.command.CommandManager;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
@ -84,7 +84,7 @@ public class BukkitSenderFactory extends SenderFactory<CommandSender> {
@Override
protected void sendMessage(CommandSender sender, Component message) {
if (ReflectionUtil.isChatCompatible() && sender instanceof Player) {
if (CraftBukkitUtil.isChatCompatible() && sender instanceof Player) {
Player player = (Player) sender;
String json = ComponentSerializers.JSON.serialize(message);

View File

@ -72,7 +72,6 @@ import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.ServicePriority;
import java.io.File;
import java.util.Arrays;
import java.util.EnumSet;
import java.util.Map;
import java.util.Optional;
@ -137,11 +136,9 @@ public class LPBukkitPlugin extends AbstractLuckPermsPlugin {
@Override
protected void registerCommands() {
this.commandManager = new BukkitCommandExecutor(this);
PluginCommand main = this.bootstrap.getServer().getPluginCommand("luckperms");
main.setExecutor(this.commandManager);
main.setTabCompleter(this.commandManager);
main.setDescription("Manage permissions");
main.setAliases(Arrays.asList("lp", "perm", "perms", "permission", "permissions"));
PluginCommand cmd = this.bootstrap.getCommand("luckperms");
cmd.setExecutor(this.commandManager);
cmd.setTabCompleter(this.commandManager);
}
@Override

View File

@ -60,7 +60,7 @@ public class BukkitJsonMessageHandler {
}
}
Class<?> packetChatClass = ReflectionUtil.nmsClass("PacketPlayOutChat");
Class<?> packetChatClass = CraftBukkitUtil.nmsClass("PacketPlayOutChat");
Constructor[] packetConstructors = packetChatClass.getDeclaredConstructors();
for (Constructor c : packetConstructors) {
Class<?>[] parameters = c.getParameterTypes();
@ -70,14 +70,14 @@ public class BukkitJsonMessageHandler {
}
}
Class<?> baseComponentClass = ReflectionUtil.nmsClass("IChatBaseComponent");
Class<?> baseComponentClass = CraftBukkitUtil.nmsClass("IChatBaseComponent");
Class<?> chatSerializerClass;
if (baseComponentClass.getClasses().length > 0) {
chatSerializerClass = baseComponentClass.getClasses()[0];
} else {
// 1.7 class is here instead.
chatSerializerClass = ReflectionUtil.nmsClass("ChatSerializer");
chatSerializerClass = CraftBukkitUtil.nmsClass("ChatSerializer");
}
SERIALIZE_METHOD = chatSerializerClass.getDeclaredMethod("a", String.class);

View File

@ -27,7 +27,7 @@ package me.lucko.luckperms.bukkit.compat;
import org.bukkit.Bukkit;
public final class ReflectionUtil {
public final class CraftBukkitUtil {
private static final String SERVER_VERSION = getServerVersion();
private static final boolean CHAT_COMPATIBLE = !SERVER_VERSION.startsWith(".v1_7_");
@ -65,6 +65,6 @@ public final class ReflectionUtil {
return Class.forName(obc(className));
}
private ReflectionUtil() {}
private CraftBukkitUtil() {}
}

View File

@ -75,8 +75,6 @@ public class BukkitConnectionListener extends AbstractConnectionListener impleme
this.plugin.getLogger().info("Processing pre-login for " + e.getUniqueId() + " - " + e.getName());
}
recordConnection(e.getUniqueId());
/* Actually process the login for the connection.
We do this here to delay the login until the data is ready.
If the login gets cancelled later on, then this will be cleaned up.
@ -89,13 +87,14 @@ public class BukkitConnectionListener extends AbstractConnectionListener impleme
try {
User user = loadUser(e.getUniqueId(), e.getName());
this.plugin.getEventFactory().handleUserLoginProcess(e.getUniqueId(), e.getName(), user);
recordConnection(e.getUniqueId());
} catch (Exception ex) {
this.plugin.getLogger().severe("Exception occurred whilst loading data for " + e.getUniqueId() + " - " + e.getName());
ex.printStackTrace();
// deny the connection
this.deniedAsyncLogin.add(e.getUniqueId());
e.disallow(AsyncPlayerPreLoginEvent.Result.KICK_OTHER, Message.LOADING_ERROR.asString(this.plugin.getLocaleManager()));
e.disallow(AsyncPlayerPreLoginEvent.Result.KICK_OTHER, Message.LOADING_DATABASE_ERROR.asString(this.plugin.getLocaleManager()));
}
}
@ -131,10 +130,19 @@ public class BukkitConnectionListener extends AbstractConnectionListener impleme
/* User instance is null for whatever reason. Could be that it was unloaded between asyncpre and now. */
if (user == null) {
this.deniedLogin.add(e.getPlayer().getUniqueId());
this.deniedLogin.add(player.getUniqueId());
this.plugin.getLogger().warn("User " + player.getUniqueId() + " - " + player.getName() + " doesn't have data pre-loaded. - denying login.");
e.disallow(PlayerLoginEvent.Result.KICK_OTHER, Message.LOADING_ERROR.asString(this.plugin.getLocaleManager()));
if (!getUniqueConnections().contains(player.getUniqueId())) {
this.plugin.getLogger().warn("User " + player.getUniqueId() + " - " + player.getName() +
" doesn't have data pre-loaded, they have never need processed during pre-login in this session." +
" - denying login.");
} else {
this.plugin.getLogger().warn("User " + player.getUniqueId() + " - " + player.getName() +
" doesn't currently have data pre-loaded, but they have been processed before in this session." +
" - denying login.");
}
e.disallow(PlayerLoginEvent.Result.KICK_OTHER, Message.LOADING_STATE_ERROR.asString(this.plugin.getLocaleManager()));
return;
}
@ -148,7 +156,12 @@ public class BukkitConnectionListener extends AbstractConnectionListener impleme
PermissibleInjector.inject(player, lpPermissible);
} catch (Throwable t) {
this.plugin.getLogger().warn("Exception thrown when setting up permissions for " +
player.getUniqueId() + " - " + player.getName() + " - denying login.");
t.printStackTrace();
e.disallow(PlayerLoginEvent.Result.KICK_OTHER, Message.LOADING_SETUP_ERROR.asString(this.plugin.getLocaleManager()));
return;
}
this.plugin.refreshAutoOp(player);

View File

@ -25,7 +25,7 @@
package me.lucko.luckperms.bukkit.model.permissible;
import me.lucko.luckperms.bukkit.compat.ReflectionUtil;
import me.lucko.luckperms.bukkit.compat.CraftBukkitUtil;
import me.lucko.luckperms.bukkit.model.dummy.DummyPermissibleBase;
import org.bukkit.entity.Player;
@ -62,7 +62,7 @@ public final class PermissibleInjector {
Field humanEntityPermissibleField;
try {
// craftbukkit
humanEntityPermissibleField = ReflectionUtil.obcClass("entity.CraftHumanEntity").getDeclaredField("perm");
humanEntityPermissibleField = CraftBukkitUtil.obcClass("entity.CraftHumanEntity").getDeclaredField("perm");
humanEntityPermissibleField.setAccessible(true);
} catch (Exception e) {
// glowstone

View File

@ -26,7 +26,7 @@
package me.lucko.luckperms.bukkit.model.permissible;
import me.lucko.luckperms.bukkit.LPBukkitPlugin;
import me.lucko.luckperms.bukkit.compat.ReflectionUtil;
import me.lucko.luckperms.bukkit.compat.CraftBukkitUtil;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.permissions.PermissibleBase;
@ -84,7 +84,7 @@ public class PermissibleMonitoringInjector implements Runnable {
ConsoleCommandSender consoleSender = this.plugin.getBootstrap().getServer().getConsoleSender();
// get the ServerCommandSender class
Class<?> serverCommandSenderClass = ReflectionUtil.obcClass("command.ServerCommandSender");
Class<?> serverCommandSenderClass = CraftBukkitUtil.obcClass("command.ServerCommandSender");
// get the perm field
Field permField = serverCommandSenderClass.getDeclaredField("perm");
@ -102,7 +102,7 @@ public class PermissibleMonitoringInjector implements Runnable {
private void injectCommandBlock() throws Exception {
// get the ServerCommandSender class
Class<?> serverCommandSenderClass = ReflectionUtil.obcClass("command.ServerCommandSender");
Class<?> serverCommandSenderClass = CraftBukkitUtil.obcClass("command.ServerCommandSender");
// get the blockPermInst field
Field permField = serverCommandSenderClass.getDeclaredField("blockPermInst");
@ -126,7 +126,7 @@ public class PermissibleMonitoringInjector implements Runnable {
private void injectEntity() throws Exception {
// get the CraftEntity class
Class<?> entityClass = ReflectionUtil.obcClass("entity.CraftEntity");
Class<?> entityClass = CraftBukkitUtil.obcClass("entity.CraftEntity");
// get the method used to obtain a PermissibleBase
// this method will initialise a new PB instance if one doesn't yet exist

View File

@ -71,8 +71,6 @@ public class BungeeConnectionListener extends AbstractConnectionListener impleme
}
this.plugin.getBootstrap().getScheduler().executeAsync(() -> {
recordConnection(c.getUniqueId());
/* Actually process the login for the connection.
We do this here to delay the login until the data is ready.
If the login gets cancelled later on, then this will be cleaned up.
@ -85,6 +83,7 @@ public class BungeeConnectionListener extends AbstractConnectionListener impleme
try {
User user = loadUser(c.getUniqueId(), c.getName());
this.plugin.getEventFactory().handleUserLoginProcess(c.getUniqueId(), c.getName(), user);
recordConnection(c.getUniqueId());
} catch (Exception ex) {
this.plugin.getLogger().severe("Exception occurred whilst loading data for " + c.getUniqueId() + " - " + c.getName());
ex.printStackTrace();
@ -92,7 +91,7 @@ public class BungeeConnectionListener extends AbstractConnectionListener impleme
// there was some error loading
if (this.plugin.getConfiguration().get(ConfigKeys.CANCEL_FAILED_LOGINS)) {
// cancel the login attempt
e.setCancelReason(TextComponent.fromLegacyText(Message.LOADING_ERROR.asString(this.plugin.getLocaleManager())));
e.setCancelReason(TextComponent.fromLegacyText(Message.LOADING_DATABASE_ERROR.asString(this.plugin.getLocaleManager())));
e.setCancelled(true);
}
}
@ -112,10 +111,17 @@ public class BungeeConnectionListener extends AbstractConnectionListener impleme
}
if (user == null) {
if (!getUniqueConnections().contains(player.getUniqueId())) {
this.plugin.getLogger().warn("User " + player.getUniqueId() + " - " + player.getName() +
" doesn't have data pre-loaded, they have never need processed during pre-login in this session.");
} else {
this.plugin.getLogger().warn("User " + player.getUniqueId() + " - " + player.getName() +
" doesn't currently have data pre-loaded, but they have been processed before in this session.");
}
if (this.plugin.getConfiguration().get(ConfigKeys.CANCEL_FAILED_LOGINS)) {
// disconnect the user
this.plugin.getLogger().warn("User " + player.getUniqueId() + " - " + player.getName() + " doesn't have data pre-loaded - cancelling login.");
e.getPlayer().disconnect(TextComponent.fromLegacyText(Message.LOADING_ERROR.asString(this.plugin.getLocaleManager())));
e.getPlayer().disconnect(TextComponent.fromLegacyText(Message.LOADING_STATE_ERROR.asString(this.plugin.getLocaleManager())));
} else {
// just send a message
this.plugin.getBootstrap().getProxy().getScheduler().schedule(this.plugin.getBootstrap(), () -> {
@ -123,7 +129,7 @@ public class BungeeConnectionListener extends AbstractConnectionListener impleme
return;
}
player.sendMessage(TextComponent.fromLegacyText(Message.LOADING_ERROR.asString(this.plugin.getLocaleManager())));
player.sendMessage(TextComponent.fromLegacyText(Message.LOADING_STATE_ERROR.asString(this.plugin.getLocaleManager())));
}, 1, TimeUnit.SECONDS);
}
}

View File

@ -56,7 +56,7 @@ public class AssignmentExpression {
this.expression = generateExpression(expression);
}
public boolean parse(PermissionHolder holder, Tristate tristate) throws IllegalArgumentException {
public boolean eval(PermissionHolder holder, Tristate tristate) throws IllegalArgumentException {
ScriptEngine engine = Scripting.getScriptEngine();
if (engine == null) {
throw new NullPointerException("script engine");

View File

@ -54,7 +54,7 @@ public class AssignmentRule {
public boolean apply(User user) {
if (this.hasTrueExpression != null) {
try {
boolean b = this.hasTrueExpression.parse(user, Tristate.TRUE);
boolean b = this.hasTrueExpression.eval(user, Tristate.TRUE);
if (!b) {
// The holder does not meet this requirement
return false;
@ -68,7 +68,7 @@ public class AssignmentRule {
if (this.hasFalseExpression != null) {
try {
boolean b = this.hasFalseExpression.parse(user, Tristate.FALSE);
boolean b = this.hasFalseExpression.eval(user, Tristate.FALSE);
if (!b) {
// The holder does not meet this requirement
return false;
@ -82,7 +82,7 @@ public class AssignmentRule {
if (this.lacksExpression != null) {
try {
boolean b = this.lacksExpression.parse(user, Tristate.UNDEFINED);
boolean b = this.lacksExpression.eval(user, Tristate.UNDEFINED);
if (!b) {
// The holder does not meet this requirement
return false;

View File

@ -63,7 +63,9 @@ public enum Message {
EMPTY("{}", true),
PLAYER_ONLINE("&aOnline", false),
PLAYER_OFFLINE("&cOffline", false),
LOADING_ERROR("&cPermissions data could not be loaded. Please try again later.", true),
LOADING_DATABASE_ERROR("&cA database error occurred whilst loading permissions data. Please try again later.", true),
LOADING_STATE_ERROR("&cPermissions data for your user was not loaded during the pre-login stage - unable to continue. Please try again later.", true),
LOADING_SETUP_ERROR("&cAn unexpected error occurred whilst setting up your permissions data. Please try again later.", true),
OP_DISABLED("&bThe vanilla OP system is disabled on this server.", false),
OP_DISABLED_SPONGE("&2Please note that Server Operator status has no effect on Sponge permission checks when a permission plugin is installed. Please edit user data directly.", true),

View File

@ -133,8 +133,8 @@ public class LPNukkitPlugin extends AbstractLuckPermsPlugin {
@Override
protected void registerCommands() {
this.commandManager = new NukkitCommandExecutor(this);
PluginCommand main = (PluginCommand) this.bootstrap.getServer().getPluginCommand("luckperms");
main.setExecutor(this.commandManager);
PluginCommand cmd = (PluginCommand) this.bootstrap.getServer().getPluginCommand("luckperms");
cmd.setExecutor(this.commandManager);
}
@Override

View File

@ -66,8 +66,6 @@ public class NukkitConnectionListener extends AbstractConnectionListener impleme
this.plugin.getLogger().info("Processing pre-login for " + e.getUuid() + " - " + e.getName());
}
recordConnection(e.getUuid());
/* Actually process the login for the connection.
We do this here to delay the login until the data is ready.
If the login gets cancelled later on, then this will be cleaned up.
@ -80,13 +78,14 @@ public class NukkitConnectionListener extends AbstractConnectionListener impleme
try {
User user = loadUser(e.getUuid(), e.getName());
this.plugin.getEventFactory().handleUserLoginProcess(e.getUuid(), e.getName(), user);
recordConnection(e.getUuid());
} catch (Exception ex) {
this.plugin.getLogger().severe("Exception occurred whilst loading data for " + e.getUuid() + " - " + e.getName());
ex.printStackTrace();
// deny the connection
this.deniedAsyncLogin.add(e.getUuid());
e.disAllow(Message.LOADING_ERROR.asString(this.plugin.getLocaleManager()));
e.disAllow(Message.LOADING_DATABASE_ERROR.asString(this.plugin.getLocaleManager()));
}
}
@ -122,11 +121,20 @@ public class NukkitConnectionListener extends AbstractConnectionListener impleme
/* User instance is null for whatever reason. Could be that it was unloaded between asyncpre and now. */
if (user == null) {
this.deniedLogin.add(e.getPlayer().getUniqueId());
this.deniedLogin.add(player.getUniqueId());
if (!getUniqueConnections().contains(player.getUniqueId())) {
this.plugin.getLogger().warn("User " + player.getUniqueId() + " - " + player.getName() +
" doesn't have data pre-loaded, they have never need processed during pre-login in this session." +
" - denying login.");
} else {
this.plugin.getLogger().warn("User " + player.getUniqueId() + " - " + player.getName() +
" doesn't currently have data pre-loaded, but they have been processed before in this session." +
" - denying login.");
}
this.plugin.getLogger().warn("User " + player.getUniqueId() + " - " + player.getName() + " doesn't have data pre-loaded. - denying login.");
e.setCancelled();
e.setKickMessage(Message.LOADING_ERROR.asString(this.plugin.getLocaleManager()));
e.setKickMessage(Message.LOADING_STATE_ERROR.asString(this.plugin.getLocaleManager()));
return;
}
@ -140,7 +148,13 @@ public class NukkitConnectionListener extends AbstractConnectionListener impleme
PermissibleInjector.inject(player, lpPermissible);
} catch (Throwable t) {
this.plugin.getLogger().warn("Exception thrown when setting up permissions for " +
player.getUniqueId() + " - " + player.getName() + " - denying login.");
t.printStackTrace();
e.setCancelled();
e.setKickMessage(Message.LOADING_SETUP_ERROR.asString(this.plugin.getLocaleManager()));
return;
}
this.plugin.refreshAutoOp(player);

View File

@ -69,8 +69,6 @@ public class SpongeConnectionListener extends AbstractConnectionListener {
this.plugin.getLogger().info("Processing auth event for " + profile.getUniqueId() + " - " + profile.getName());
}
recordConnection(profile.getUniqueId());
/* Actually process the login for the connection.
We do this here to delay the login until the data is ready.
If the login gets cancelled later on, then this will be cleaned up.
@ -83,6 +81,7 @@ public class SpongeConnectionListener extends AbstractConnectionListener {
try {
User user = loadUser(profile.getUniqueId(), username);
this.plugin.getEventFactory().handleUserLoginProcess(profile.getUniqueId(), username, user);
recordConnection(profile.getUniqueId());
} catch (Exception ex) {
this.plugin.getLogger().severe("Exception occurred whilst loading data for " + profile.getUniqueId() + " - " + profile.getName());
ex.printStackTrace();
@ -92,7 +91,7 @@ public class SpongeConnectionListener extends AbstractConnectionListener {
e.setCancelled(true);
e.setMessageCancelled(false);
//noinspection deprecation
e.setMessage(TextSerializers.LEGACY_FORMATTING_CODE.deserialize(Message.LOADING_ERROR.asString(this.plugin.getLocaleManager())));
e.setMessage(TextSerializers.LEGACY_FORMATTING_CODE.deserialize(Message.LOADING_DATABASE_ERROR.asString(this.plugin.getLocaleManager())));
}
}
@ -132,11 +131,20 @@ public class SpongeConnectionListener extends AbstractConnectionListener {
if (user == null) {
this.deniedLogin.add(profile.getUniqueId());
this.plugin.getLogger().warn("User " + profile.getUniqueId() + " - " + profile.getName() + " doesn't have data pre-loaded. - denying login.");
if (!getUniqueConnections().contains(profile.getUniqueId())) {
this.plugin.getLogger().warn("User " + profile.getUniqueId() + " - " + profile.getName() +
" doesn't have data pre-loaded, they have never need processed during pre-login in this session." +
" - denying login.");
} else {
this.plugin.getLogger().warn("User " + profile.getUniqueId() + " - " + profile.getName() +
" doesn't currently have data pre-loaded, but they have been processed before in this session." +
" - denying login.");
}
e.setCancelled(true);
e.setMessageCancelled(false);
//noinspection deprecation
e.setMessage(TextSerializers.LEGACY_FORMATTING_CODE.deserialize(Message.LOADING_ERROR.asString(this.plugin.getLocaleManager())));
e.setMessage(TextSerializers.LEGACY_FORMATTING_CODE.deserialize(Message.LOADING_STATE_ERROR.asString(this.plugin.getLocaleManager())));
}
}