mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-11-27 21:29:47 +01:00
Fix Bukkit command map access (#2229)
This commit is contained in:
parent
c03aca35d6
commit
eb0d758efc
@ -27,6 +27,7 @@ package me.lucko.luckperms.bukkit;
|
||||
|
||||
import com.destroystokyo.paper.event.server.AsyncTabCompleteEvent;
|
||||
|
||||
import me.lucko.luckperms.bukkit.util.CommandMapUtil;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentTokenizer;
|
||||
import me.lucko.luckperms.common.sender.Sender;
|
||||
|
||||
@ -62,7 +63,7 @@ public class BukkitAsyncCommandExecutor extends BukkitCommandExecutor {
|
||||
}
|
||||
|
||||
String commandLabel = buffer.substring(0, firstSpace);
|
||||
Command command = this.plugin.getBootstrap().getServer().getCommandMap().getCommand(commandLabel);
|
||||
Command command = CommandMapUtil.getCommandMap(this.plugin.getBootstrap().getServer()).getCommand(commandLabel);
|
||||
if (command != this.command) {
|
||||
return;
|
||||
}
|
||||
|
@ -25,6 +25,7 @@
|
||||
|
||||
package me.lucko.luckperms.bukkit;
|
||||
|
||||
import me.lucko.luckperms.bukkit.util.CommandMapUtil;
|
||||
import me.lucko.luckperms.common.command.CommandManager;
|
||||
import me.lucko.luckperms.common.command.utils.ArgumentTokenizer;
|
||||
import me.lucko.luckperms.common.config.ConfigKeys;
|
||||
@ -113,7 +114,7 @@ public class BukkitCommandExecutor extends CommandManager implements CommandExec
|
||||
commandLabel = buffer.substring(0, firstSpace);
|
||||
}
|
||||
|
||||
Command command = this.plugin.getBootstrap().getServer().getCommandMap().getCommand(commandLabel);
|
||||
Command command = CommandMapUtil.getCommandMap(this.plugin.getBootstrap().getServer()).getCommand(commandLabel);
|
||||
if (command != this.command) {
|
||||
return;
|
||||
}
|
||||
|
@ -0,0 +1,56 @@
|
||||
/*
|
||||
* 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.util;
|
||||
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.command.CommandMap;
|
||||
import org.bukkit.plugin.SimplePluginManager;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
public final class CommandMapUtil {
|
||||
private CommandMapUtil() {}
|
||||
|
||||
private static final Field COMMAND_MAP_FIELD;
|
||||
|
||||
static {
|
||||
try {
|
||||
COMMAND_MAP_FIELD = SimplePluginManager.class.getDeclaredField("commandMap");
|
||||
COMMAND_MAP_FIELD.setAccessible(true);
|
||||
} catch (NoSuchFieldException e) {
|
||||
throw new ExceptionInInitializerError(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static CommandMap getCommandMap(Server server) {
|
||||
try {
|
||||
return (CommandMap) COMMAND_MAP_FIELD.get(server.getPluginManager());
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Could not get CommandMap", e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user