本文整理汇总了Java中org.bukkit.util.ChatPaginator.GUARANTEED_NO_WRAP_CHAT_PAGE_WIDTH属性的典型用法代码示例。如果您正苦于以下问题:Java ChatPaginator.GUARANTEED_NO_WRAP_CHAT_PAGE_WIDTH属性的具体用法?Java ChatPaginator.GUARANTEED_NO_WRAP_CHAT_PAGE_WIDTH怎么用?Java ChatPaginator.GUARANTEED_NO_WRAP_CHAT_PAGE_WIDTH使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.bukkit.util.ChatPaginator
的用法示例。
在下文中一共展示了ChatPaginator.GUARANTEED_NO_WRAP_CHAT_PAGE_WIDTH属性的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getFullText
public String getFullText(CommandSender sender) {
StringBuilder sb = new StringBuilder();
if (preamble != null) {
sb.append(buildPreamble(sender));
sb.append("\n");
}
for (HelpTopic topic : allTopics) {
if (topic.canSee(sender)) {
String lineStr = buildIndexLine(sender, topic).replace("\n", ". ");
if (sender instanceof Player && lineStr.length() > ChatPaginator.GUARANTEED_NO_WRAP_CHAT_PAGE_WIDTH) {
sb.append(lineStr.substring(0, ChatPaginator.GUARANTEED_NO_WRAP_CHAT_PAGE_WIDTH - 3));
sb.append("...");
} else {
sb.append(lineStr);
}
sb.append("\n");
}
}
return sb.toString();
}
示例2: onCommand
@Override
public final boolean onCommand(final CommandSender sender, final Command command, final String label, String[] args) {
if(!sender.hasPermission("owngarden.command")) {
OwnGarden.log(ChatColor.RED, "You do not have the permission to execute this command.", sender);
return true;
}
final PluginDescriptionFile description = Bukkit.getPluginManager().getPlugin("OwnGarden").getDescription();
sender.sendMessage(ChatColor.GREEN + description.getName() + " v" + description.getVersion() + ChatColor.GOLD + " by " + Joiner.on(' ').join(description.getAuthors()));
final StringBuilder builder = new StringBuilder();
for(int i = 0; i != ChatPaginator.GUARANTEED_NO_WRAP_CHAT_PAGE_WIDTH - 2; i++) {
builder.append("=");
}
final String line = builder.toString();
sender.sendMessage(ChatColor.RESET + line);
sender.sendMessage(ChatColor.GOLD + "SCHEMATICS : ");
sender.sendMessage(ChatColor.RESET + "" + ChatColor.BOLD + "- Oak : " + ChatColor.RESET + Joiner.on(' ').join(OwnGarden.config.saplingOakSchematics));
sender.sendMessage(ChatColor.BOLD + "- Spruce : " + ChatColor.RESET + Joiner.on(' ').join(OwnGarden.config.saplingSpruceSchematics));
sender.sendMessage(ChatColor.BOLD + "- Jungle : " + ChatColor.RESET + Joiner.on(' ').join(OwnGarden.config.saplingJungleSchematics));
sender.sendMessage(ChatColor.BOLD + "- Acacia : " + ChatColor.RESET + Joiner.on(' ').join(OwnGarden.config.saplingAcaciaSchematics));
sender.sendMessage(ChatColor.BOLD + "- Dark Oak : " + ChatColor.RESET + Joiner.on(' ').join(OwnGarden.config.saplingDarkOakSchematics));
sender.sendMessage(line);
sender.sendMessage(ChatColor.GOLD + "PERMISSIONS : ");
for(final Permission permission : description.getPermissions()) {
sender.sendMessage(sender.hasPermission(permission) ?
(ChatColor.GREEN + "- You have the permission " + ChatColor.BOLD + permission.getName() + ChatColor.RESET + ChatColor.GREEN + ".") :
(ChatColor.RED + "- You do not have the permission " + ChatColor.BOLD + permission.getName() + ChatColor.RESET + ChatColor.RED + ".")
);
}
sender.sendMessage(ChatColor.RESET + line);
sender.sendMessage(ChatColor.AQUA + "" + ChatColor.ITALIC + "The above list is scrollable.");
return true;
}
示例3: sendHelp
/** TODO: Documentation */
public static void sendHelp(final CommandSender target, Message title, final Tuple<Object> tokens) {
Check.nonNulls("The target/title/Tokens<Object> cannot be null!", target, title, tokens);
title = Message.translateIfPossible(title, Utility.getLanguage(target), tokens);
final int restLength = ChatPaginator.GUARANTEED_NO_WRAP_CHAT_PAGE_WIDTH - 9 - 2 - title.length();
final MessageBuilder b = Message.builder()
.append(StringUtils.repeat("-", 9) + " ")
.append(title);
if (restLength > 0) { b.append(" " + StringUtils.repeat("-", restLength)); }
CraftoMessenger.sendMessage(target, b);
}
示例4: execute
@Override
public boolean execute(CommandSender sender, String currentAlias, String[] args) {
if (!testPermission(sender)) return true;
String command;
int pageNumber;
int pageHeight;
int pageWidth;
if (args.length == 0) {
command = "";
pageNumber = 1;
} else if (NumberUtils.isDigits(args[args.length - 1])) {
command = StringUtils.join(ArrayUtils.subarray(args, 0, args.length - 1), " ");
try {
pageNumber = NumberUtils.createInteger(args[args.length - 1]);
} catch (NumberFormatException exception) {
pageNumber = 1;
}
if (pageNumber <= 0) {
pageNumber = 1;
}
} else {
command = StringUtils.join(args, " ");
pageNumber = 1;
}
if (sender instanceof ConsoleCommandSender) {
pageHeight = ChatPaginator.UNBOUNDED_PAGE_HEIGHT;
pageWidth = ChatPaginator.UNBOUNDED_PAGE_WIDTH;
} else {
pageHeight = ChatPaginator.CLOSED_CHAT_PAGE_HEIGHT - 1;
pageWidth = ChatPaginator.GUARANTEED_NO_WRAP_CHAT_PAGE_WIDTH;
}
HelpMap helpMap = Bukkit.getServer().getHelpMap();
HelpTopic topic = helpMap.getHelpTopic(command);
if (topic == null) {
topic = helpMap.getHelpTopic("/" + command);
}
if (topic == null) {
topic = findPossibleMatches(command);
}
if (topic == null || !topic.canSee(sender)) {
sender.sendMessage(ChatColor.RED + "No help for " + command);
return true;
}
ChatPaginator.ChatPage page = ChatPaginator.paginate(topic.getFullText(sender), pageNumber, pageWidth, pageHeight);
StringBuilder header = new StringBuilder();
header.append(ChatColor.YELLOW);
header.append("--------- ");
header.append(ChatColor.WHITE);
header.append("Help: ");
header.append(topic.getName());
header.append(" ");
if (page.getTotalPages() > 1) {
header.append("(");
header.append(page.getPageNumber());
header.append("/");
header.append(page.getTotalPages());
header.append(") ");
}
header.append(ChatColor.YELLOW);
for (int i = header.length(); i < ChatPaginator.GUARANTEED_NO_WRAP_CHAT_PAGE_WIDTH; i++) {
header.append("-");
}
sender.sendMessage(header.toString());
sender.sendMessage(page.getLines());
return true;
}
示例5: onCommand
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
Map<String, Map<String, Object>> commands = plugin.getDescription().getCommands();
sender.sendMessage(ChatColor.AQUA + plugin.getName() + "-Help");
int maxWidth = ChatPaginator.GUARANTEED_NO_WRAP_CHAT_PAGE_WIDTH;
if (!(sender instanceof Player)) {
maxWidth = Integer.MAX_VALUE;
}
for (Entry<String, Map<String, Object>> entry : commands.entrySet()) {
String commandKey = entry.getKey();
Map<String, Object> value = entry.getValue();
String description = ' ' + value.getOrDefault("description", "No description").toString();
String usage = ((String) value.getOrDefault("usage", '/' + commandKey)).replace("<command>", commandKey);
TextComponent usageComponent = new TextComponent(usage);
usageComponent.setColor(ChatColor.DARK_AQUA);
TextComponent descriptionComponent = new TextComponent(description);
descriptionComponent.setColor(ChatColor.GOLD);
int totalLen = usage.length() + description.length();
if (totalLen > maxWidth) {
int newDescLeng = maxWidth - usage.length() - 3 - 1;
if (newDescLeng < 0) {
newDescLeng = 0;
}
String shortDesc = description.substring(0, newDescLeng) + "...";
descriptionComponent.setText(shortDesc);
ComponentBuilder hoverBuilder = new ComponentBuilder("");
String separated = WordUtils.wrap(description, HOVER_MAX_LENGTH, "\n", false);
for (String line : separated.split("\n")) {
hoverBuilder.append(line + '\n');
hoverBuilder.color(ChatColor.GOLD);
}
descriptionComponent
.setHoverEvent(new HoverEvent(Action.SHOW_TEXT, hoverBuilder.create()));
} else {
descriptionComponent.setText(description);
}
usageComponent.addExtra(descriptionComponent);
if (sender instanceof Player) {
Player player = (Player) sender;
player.spigot().sendMessage(usageComponent);
} else {
sender.sendMessage(usageComponent.toLegacyText());
}
}
return true;
}
示例6: sendHelp
public void sendHelp(final CommandSender target, final Help help, final int page, final int entriesPerPage) throws IllegalArgumentException {
Check.nonNulls("The target/help must not be null!", target, help);
final int pageCount = help.getPageCount(entriesPerPage);
if (page >= pageCount) { throw new IllegalArgumentException("The specified page " + page + " doesn't exist with " + entriesPerPage + " entries per page for help: " + help); }
final MessageBuilder header = Message.builder().append(StringUtils.repeat('-', 9) + " ");
final MessageBuilder newTitle = Message.builder();
// Left navigator
if (page > 0) {
newTitle.append('[').color(ChatColor.YELLOW).append('<')
.onClick(ClickAction.callback(player -> this.sendHelp(player, help, page - 1, entriesPerPage)))
.onHover(ChatColor.GRAY + "Click here to open page " + ChatColor.WHITE + (page - 1) + ChatColor.GRAY + "...")
.color(ChatColor.GOLD)
.append(']').color(ChatColor.YELLOW).appendSpace();
}
// Title
newTitle.append( this.parseContent(target, help.getTitle()) );
// Right navigator
if (page < (pageCount - 1)) {
newTitle.appendSpace().append('[').color(ChatColor.YELLOW).append('>')
.onClick(ClickAction.callback(player -> this.sendHelp(target, help, page + 1, entriesPerPage)))
.onHover(ChatColor.GRAY + "Click here to open page " + ChatColor.WHITE + (page + 1) + ChatColor.GRAY + "...")
.color(ChatColor.GOLD)
.append(']').color(ChatColor.YELLOW);
}
// Append newTitle to the header
header.append(newTitle);
// Right line
final int restLength = ChatPaginator.GUARANTEED_NO_WRAP_CHAT_PAGE_WIDTH - 9 - 2 - newTitle.length();
if (restLength > 0) { header.append(" " + StringUtils.repeat('-', restLength)); }
// Send header
this.sendMessage(target, header);
// Send description, if available
if (help.getDescription().isPresent()) { this.sendMessage(target, this.parseContent(target, help.getDescription().get().setColor(ChatColor.GRAY))); }
// Entries
final List<HelpEntry> entries = help.getEntries(page, entriesPerPage);
for (final HelpEntry entry : entries) {
final Message parsedKey = Message.builder().append( this.parseContent(target, entry.getKey()) ).append(": ").build().setColor(ChatColor.GOLD);
if (entry.getDescription().isPresent()) { parsedKey.setHoverText(entry.getDescription().get()); }
if (entry.getDestination().isPresent()) { parsedKey.setClickAction(ClickAction.callback(player -> this.sendHelp(player, entry.getDestination().get(), 0))); }
final Message parsedValue = this.parseContent(target, entry.getValue()).setColor(ChatColor.WHITE);
this.sendMessage(target, Message.builder().append(parsedKey).append(parsedValue));
}
}
示例7: sendMsg
/**
* Plugin method to easily send messages to players (and console too). This
* is the core of all the sender methods included here.
*
* @param sender The CommandSender to send the message to.
* @param msg The message to be sent.
* @param pagination Whether to paginate the message or not.
*
* @since 1.5
*/
public static void sendMsg(CommandSender sender, String msg, boolean pagination) {
String message = translateAlternateColorCodes('&', msg);
if (message.length() > ChatPaginator.GUARANTEED_NO_WRAP_CHAT_PAGE_WIDTH && pagination) {
String[] multiline = ChatPaginator.wordWrap(message, ChatPaginator.GUARANTEED_NO_WRAP_CHAT_PAGE_WIDTH);
sender.sendMessage(multiline);
} else {
sender.sendMessage(message);
}
}