本文整理汇总了Java中org.bukkit.command.PluginCommand.getAliases方法的典型用法代码示例。如果您正苦于以下问题:Java PluginCommand.getAliases方法的具体用法?Java PluginCommand.getAliases怎么用?Java PluginCommand.getAliases使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bukkit.command.PluginCommand
的用法示例。
在下文中一共展示了PluginCommand.getAliases方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: unRegisterBukkitCommand
import org.bukkit.command.PluginCommand; //导入方法依赖的package包/类
public void unRegisterBukkitCommand(PluginCommand cmd) {
try {
Object result = getPrivateField(plugin.getServer().getPluginManager(), "commandMap");
SimpleCommandMap commandMap = (SimpleCommandMap) result;
Object map = getPrivateField(commandMap, "knownCommands");
@SuppressWarnings("unchecked")
HashMap<String, Command> knownCommands = (HashMap<String, Command>) map;
knownCommands.remove(cmd.getName());
for (String alias : cmd.getAliases()) {
if (knownCommands.containsKey(alias) && knownCommands.get(alias).toString().contains(plugin.getName())) {
knownCommands.remove(alias);
}
}
} catch (SecurityException | NoSuchFieldException | IllegalArgumentException | IllegalAccessException e) {
plugin.getLogger().severe(e.toString());
}
}
示例2: unRegisterBukkitCommand
import org.bukkit.command.PluginCommand; //导入方法依赖的package包/类
/**
* unregister a command, credits to zeeveener for his awesome code to unregister commands!
*
* @author zeeveener, xize
* @param cmd - the command to be unregistered
*/
public void unRegisterBukkitCommand(PluginCommand cmd) {
try {
Object result = getPrivateField(Bukkit.getServer().getPluginManager(), "commandMap");
SimpleCommandMap commandMap = (SimpleCommandMap) result;
Object map = getPrivateField(commandMap, "knownCommands");
@SuppressWarnings("unchecked")
HashMap<String, Command> knownCommands = (HashMap<String, Command>) map;
knownCommands.remove("xessentials"+":"+cmd.getName());
if(knownCommands.containsKey(cmd.getName()) && knownCommands.get(cmd.getName().toLowerCase()).toString().contains(pl.getName())) {
knownCommands.remove(cmd.getName());
}
for (String alias : cmd.getAliases()){
if(knownCommands.containsKey("xessentials:"+alias) && knownCommands.get("xessentials:"+alias).toString().contains(pl.getName())){
knownCommands.remove("xessentials:"+alias);
}
if(knownCommands.containsKey(alias) && knownCommands.get(alias).toString().contains(pl.getName())){
knownCommands.remove(alias);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
示例3: unregisterBukkitCommand
import org.bukkit.command.PluginCommand; //导入方法依赖的package包/类
public static void unregisterBukkitCommand(PluginCommand cmd) {
try {
Object result = getPrivateField(Bukkit.getServer().getPluginManager(), "commandMap");
SimpleCommandMap commandMap = (SimpleCommandMap) result;
Object map = getPrivateField(commandMap, "knownCommands");
@SuppressWarnings("unchecked")
HashMap<String, Command> knownCommands = (HashMap<String, Command>) map;
knownCommands.remove(cmd.getName());
for (String alias : cmd.getAliases()) {
if(knownCommands.containsKey(alias) && knownCommands.get(alias).toString().contains(Bukkit.getName())) {
knownCommands.remove(alias);
}
}
}
catch (Exception e) {
e.printStackTrace();
}
}
示例4: execute
import org.bukkit.command.PluginCommand; //导入方法依赖的package包/类
@Override
public void execute(Command command) {
CommandSender sender = command.getSender();
sender.sendMessage(ChatColor.GREEN + "==========[ MovieSets Help ]==========");
PluginCommand registeredCommand = Bukkit.getPluginCommand("moviesets");
String aliases = ChatColor.DARK_GREEN + "/" + registeredCommand.getLabel() + ChatColor.AQUA + ", ";
for (String alias : registeredCommand.getAliases()) {
aliases += ChatColor.DARK_GREEN + "/" + alias + ChatColor.AQUA + ", ";
}
aliases = aliases.substring(0, aliases.length() - 2);
sender.sendMessage("Aliases: " + ChatColor.DARK_GREEN + aliases);
List<CommandHandler> commandHandlers = ((CommandExecutor) registeredCommand.getExecutor()).getCommandHandlers();
for (CommandHandler commandHandler : commandHandlers) {
CommandInfo info = commandHandler.getInfo();
if (! (sender instanceof Player) || info.getPermission() == null || ((Player) sender).hasPermission(info.getPermission())) {
for (String label : info.getLabels()) {
String printLabel = "";
if (!label.equalsIgnoreCase("<empty>")) {
printLabel = " " + label;
}
String parameterUsage = "";
if (info.getParameterUsage() != null && !info.getParameterUsage().isEmpty()) {
parameterUsage = " " + info.getParameterUsage();
}
sender.sendMessage(ChatColor.GOLD + "/" + command.getGlobalLabel() + printLabel + parameterUsage);
}
sender.sendMessage(ChatColor.DARK_RED + " > " + ChatColor.GRAY + info.getDescription());
}
}
}
示例5: getEquivalentCommands
import org.bukkit.command.PluginCommand; //导入方法依赖的package包/类
/**
* Computes a list containing equivalent commands of an input command. For instance, if input is "/aach stats", the
* returned list is: ["aach stats", "advancedachievements stats", "aachievements stats", "aa stats"]
*
* @param command
* @return the list of commands have the same effect as the input one
*/
private List<String> getEquivalentCommands(String command) {
int firstSpaceIndex = command.indexOf(' ');
String commandName;
String commandParameters;
if (firstSpaceIndex >= 0) {
commandName = command.substring(1, firstSpaceIndex);
// Command parameters start with an initial space.
commandParameters = command.substring(firstSpaceIndex).toLowerCase();
} else {
commandName = command.substring(1);
commandParameters = "";
}
PluginCommand pluginCommand = plugin.getServer().getPluginCommand(commandName);
if (pluginCommand == null || pluginCommand.getAliases() == null) {
return Arrays.asList(commandName.toLowerCase() + commandParameters);
}
List<String> equivalentCommands = new ArrayList<>(pluginCommand.getAliases().size() + 1);
// Aliases don't contain the main plugin command, add it to the returned list.
equivalentCommands.add(pluginCommand.getName().toLowerCase() + commandParameters);
for (String alias : pluginCommand.getAliases()) {
equivalentCommands.add(alias.toLowerCase() + commandParameters);
}
return equivalentCommands;
}