本文整理了Java中org.bukkit.command.Command.getAliases()
方法的一些代码示例,展示了Command.getAliases()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Command.getAliases()
方法的具体详情如下:
包路径:org.bukkit.command.Command
类名称:Command
方法名:getAliases
[英]Returns a list of active aliases of this command
[中]返回此命令的活动别名列表
代码示例来源:origin: Bukkit/Bukkit
/**
* {@inheritDoc}
*/
public boolean register(String label, String fallbackPrefix, Command command) {
label = label.toLowerCase().trim();
fallbackPrefix = fallbackPrefix.toLowerCase().trim();
boolean registered = register(label, command, false, fallbackPrefix);
Iterator<String> iterator = command.getAliases().iterator();
while (iterator.hasNext()) {
if (!register(iterator.next(), command, true, fallbackPrefix)) {
iterator.remove();
}
}
// If we failed to register under the real name, we need to set the command label to the direct address
if (!registered) {
command.setLabel(fallbackPrefix + ":" + label);
}
// Register to us so further updates of the commands label and aliases are postponed until its reregistered
command.register(this);
return registered;
}
代码示例来源:origin: EngineHub/WorldEdit
public boolean unregisterCommands() {
CommandMap commandMap = getCommandMap();
List<String> toRemove = new ArrayList<>();
Map<String, org.bukkit.command.Command> knownCommands = ReflectionUtil.getField(commandMap, "knownCommands");
Set<String> aliases = ReflectionUtil.getField(commandMap, "aliases");
if (knownCommands == null || aliases == null) {
return false;
}
for (Iterator<org.bukkit.command.Command> i = knownCommands.values().iterator(); i.hasNext();) {
org.bukkit.command.Command cmd = i.next();
if (cmd instanceof DynamicPluginCommand && ((DynamicPluginCommand) cmd).getOwner().equals(executor)) {
i.remove();
for (String alias : cmd.getAliases()) {
org.bukkit.command.Command aliasCmd = knownCommands.get(alias);
if (cmd.equals(aliasCmd)) {
aliases.remove(alias);
toRemove.add(alias);
}
}
}
}
for (String string : toRemove) {
knownCommands.remove(string);
}
return true;
}
代码示例来源:origin: Bukkit/Bukkit
sb.append(command.getUsage().replace("<command>", name.substring(1)));
if (command.getAliases().size() > 0) {
sb.append("\n");
sb.append(ChatColor.GOLD);
sb.append("Aliases: ");
sb.append(ChatColor.WHITE);
sb.append(ChatColor.WHITE + StringUtils.join(command.getAliases(), ", "));
代码示例来源:origin: GlowstoneMC/Glowstone
for (String alias : command.getAliases()) {
HelpTopic aliasTopic = new AliasTopic("/" + alias, original);
if (!helpTopics.containsKey(aliasTopic.getName())) {
代码示例来源:origin: EngineHub/CommandHelper
@Override
public List<String> getAliases() {
return cmd.getAliases();
}
代码示例来源:origin: NoCheatPlus/NoCheatPlus
/**
* Check if the checked set contains any trim+lower-case alias of the command.
* @param checked
* @param command
* @return
*/
private static final boolean containsAnyAliases(final Set<String> checked, final Command command) {
final Collection<String> aliases = command.getAliases();
if (aliases != null) {
for (final String alias : aliases) {
if (checked.contains(alias.trim().toLowerCase())) {
return true;
}
}
}
return false;
}
代码示例来源:origin: TotalFreedom/TotalFreedomMod
private static String buildDescription(Command command)
{
StringBuilder sb = new StringBuilder();
sb.append(
"<li><span class=\"commandName\">{$CMD_NAME}</span> - Usage: <span class=\"commandUsage\">{$CMD_USAGE}</span>"
.replace("{$CMD_NAME}", escapeHtml4(command.getName().trim()))
.replace("{$CMD_USAGE}", escapeHtml4(command.getUsage().trim())));
if (!command.getAliases().isEmpty())
{
sb.append(
" - Aliases: <span class=\"commandAliases\">{$CMD_ALIASES}</span>"
.replace("{$CMD_ALIASES}", escapeHtml4(StringUtils.join(command.getAliases(), ", "))));
}
sb.append(
"<br><span class=\"commandDescription\">{$CMD_DESC}</span></li>\r\n"
.replace("{$CMD_DESC}", escapeHtml4(command.getDescription().trim())));
return sb.toString();
}
代码示例来源:origin: lucko/commodore
/**
* Gets all of the aliases known for the given command.
*
* <p>This will include the main label, as well as defined aliases, and
* aliases including the fallback prefix added by Bukkit.</p>
*
* @param command the command
* @return the aliases
*/
static Collection<String> getAliases(Command command) {
Stream<String> aliasesStream = Stream.concat(
Stream.of(command.getLabel()),
command.getAliases().stream()
);
if (command instanceof PluginCommand) {
String fallbackPrefix = ((PluginCommand) command).getPlugin().getName().toLowerCase().trim();
aliasesStream = aliasesStream.flatMap(alias -> Stream.of(
alias,
fallbackPrefix + ":" + alias
));
}
return aliasesStream.distinct().collect(Collectors.toList());
}
代码示例来源:origin: OvercastNetwork/sk89q-command-framework
public boolean unregisterCommands() {
CommandMap commandMap = getCommandMap();
List<String> toRemove = new ArrayList<String>();
Map<String, org.bukkit.command.Command> knownCommands = ReflectionUtil.getField(commandMap, "knownCommands");
Set<String> aliases = ReflectionUtil.getField(commandMap, "aliases");
if (knownCommands == null || aliases == null) {
return false;
}
for (Iterator<org.bukkit.command.Command> i = knownCommands.values().iterator(); i.hasNext();) {
org.bukkit.command.Command cmd = i.next();
if (cmd instanceof DynamicPluginCommand && ((DynamicPluginCommand) cmd).getExecutor().equals(executor)) {
i.remove();
for (String alias : cmd.getAliases()) {
org.bukkit.command.Command aliasCmd = knownCommands.get(alias);
if (cmd.equals(aliasCmd)) {
aliases.remove(alias);
toRemove.add(alias);
}
}
}
}
for (String string : toRemove) {
knownCommands.remove(string);
}
return true;
}
}
代码示例来源:origin: SpigotMC/Spigot-API
/**
* {@inheritDoc}
*/
public boolean register(String label, String fallbackPrefix, Command command) {
label = label.toLowerCase().trim();
fallbackPrefix = fallbackPrefix.toLowerCase().trim();
boolean registered = register(label, command, false, fallbackPrefix);
Iterator<String> iterator = command.getAliases().iterator();
while (iterator.hasNext()) {
if (!register(iterator.next(), command, true, fallbackPrefix)) {
iterator.remove();
}
}
// If we failed to register under the real name, we need to set the command label to the direct address
if (!registered) {
command.setLabel(fallbackPrefix + ":" + label);
}
// Register to us so further updates of the commands label and aliases are postponed until its reregistered
command.register(this);
return registered;
}
代码示例来源:origin: games647/LagMonitor
private boolean isCommandWhitelisted(Command cmd, CommandSender sender) {
if (!(sender instanceof Player)) {
return true;
}
FileConfiguration config = plugin.getConfig();
Collection<String> aliases = new ArrayList<>(cmd.getAliases());
aliases.add(cmd.getName());
for (String alias : aliases) {
List<String> aliasWhitelist = config.getStringList("whitelist-" + alias);
if (aliasWhitelist != null && !aliasWhitelist.isEmpty()) {
return aliasWhitelist.contains(sender.getName());
}
}
//whitelist doesn't exist
return true;
}
代码示例来源:origin: SpigotMC/Spigot-API
sb.append(command.getUsage().replace("<command>", name.substring(1)));
if (command.getAliases().size() > 0) {
sb.append("\n");
sb.append(ChatColor.GOLD);
sb.append("Aliases: ");
sb.append(ChatColor.WHITE);
sb.append(ChatColor.WHITE + StringUtils.join(command.getAliases(), ", "));
代码示例来源:origin: BigScary/GriefPrevention
for(String alias : command.getAliases())
for(String alias : command.getAliases())
代码示例来源:origin: TotalFreedom/TotalFreedomMod
for (String alias : command.getAliases())
代码示例来源:origin: EngineHub/CommandBook
public void printCommandHelp(CommandSender sender, org.bukkit.command.Command cmd) {
sender.sendMessage(ChatColor.YELLOW + "Command: " + cmd.getName());
final String aliases = cmd.getAliases().toString().replaceAll("\\[(.*)\\]", "$1");
if (aliases.length() > 0) {
sender.sendMessage(ChatColor.YELLOW + "Aliases: " + aliases);
}
sender.sendMessage(ChatColor.YELLOW + "Description: " + cmd.getDescription());
sender.sendMessage(ChatColor.YELLOW + "Usage: " + cmd.getUsage());
if (cmd instanceof PluginCommand) {
sender.sendMessage(ChatColor.YELLOW + "Plugin: " +
((PluginCommand)cmd).getPlugin().getDescription().getName());
} else if (cmd instanceof DynamicPluginCommand) {
sender.sendMessage(ChatColor.YELLOW + "Owner: " +
((DynamicPluginCommand) cmd).getOwner().getClass().getSimpleName());
} else if (cmd instanceof VanillaCommand) {
sender.sendMessage(ChatColor.YELLOW + "Vanilla command");
}
}
内容来源于网络,如有侵权,请联系作者删除!