mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-06-15 21:43:53 +00:00
Minor tweaks
This commit is contained in:
@ -20,17 +20,18 @@
|
||||
package com.sk89q.bukkit.util;
|
||||
|
||||
import com.sk89q.util.ReflectionUtil;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandMap;
|
||||
import org.bukkit.command.SimpleCommandMap;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandMap;
|
||||
import org.bukkit.command.PluginIdentifiableCommand;
|
||||
import org.bukkit.command.SimpleCommandMap;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
public class CommandRegistration {
|
||||
|
||||
@ -40,6 +41,7 @@ public class CommandRegistration {
|
||||
|
||||
protected final Plugin plugin;
|
||||
protected final CommandExecutor executor;
|
||||
private CommandMap serverCommandMap;
|
||||
private CommandMap fallbackCommands;
|
||||
|
||||
public CommandRegistration(Plugin plugin) {
|
||||
@ -51,6 +53,14 @@ public class CommandRegistration {
|
||||
this.executor = executor;
|
||||
}
|
||||
|
||||
public Plugin getCommandOwner(String label) {
|
||||
if (serverCommandMap == null) return null;
|
||||
Command command = serverCommandMap.getCommand(label);
|
||||
if (command instanceof PluginIdentifiableCommand) {
|
||||
return ((PluginIdentifiableCommand) command).getPlugin();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public boolean register(List<CommandInfo> registered) {
|
||||
CommandMap commandMap = getCommandMap();
|
||||
if (registered == null || commandMap == null) {
|
||||
@ -66,16 +76,20 @@ public class CommandRegistration {
|
||||
}
|
||||
|
||||
public CommandMap getCommandMap() {
|
||||
if (serverCommandMap != null) {
|
||||
return serverCommandMap;
|
||||
}
|
||||
if (fallbackCommands != null) {
|
||||
return fallbackCommands;
|
||||
}
|
||||
CommandMap commandMap = ReflectionUtil.getField(plugin.getServer().getPluginManager(), "commandMap");
|
||||
if (commandMap == null) {
|
||||
if (fallbackCommands != null) {
|
||||
commandMap = fallbackCommands;
|
||||
} else {
|
||||
Bukkit.getServer().getLogger().severe(plugin.getDescription().getName() +
|
||||
": Could not retrieve server CommandMap, using fallback instead!");
|
||||
fallbackCommands = commandMap = new SimpleCommandMap(Bukkit.getServer());
|
||||
Bukkit.getServer().getPluginManager().registerEvents(new FallbackRegistrationListener(fallbackCommands), plugin);
|
||||
}
|
||||
} else {
|
||||
serverCommandMap = commandMap;
|
||||
}
|
||||
return commandMap;
|
||||
}
|
||||
|
Reference in New Issue
Block a user