本文整理匯總了Java中org.spongepowered.api.text.Text.Builder方法的典型用法代碼示例。如果您正苦於以下問題:Java Text.Builder方法的具體用法?Java Text.Builder怎麽用?Java Text.Builder使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.spongepowered.api.text.Text
的用法示例。
在下文中一共展示了Text.Builder方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: generateAllyList
import org.spongepowered.api.text.Text; //導入方法依賴的package包/類
private Text generateAllyList(ClanImpl clan) {
Text.Builder allyList = Text.builder();
if (clan.getAlliesImpl().isEmpty()) {
allyList.color(TextColors.GRAY).append(Text.of("None")).build();
} else {
boolean first = true;
for (ClanImpl ally : clan.getAlliesImpl()) {
if (!first) {
allyList.append(Text.of(", ")).build();
}
first = false;
allyList.append(ally.getTagColored()).build();
}
}
return allyList.build();
}
示例2: getSpacesString
import org.spongepowered.api.text.Text; //導入方法依賴的package包/類
private Text getSpacesString(double numberOfSpaces) {
Text.Builder spaces = Text.builder();
if (Math.floor(numberOfSpaces) == 0) {
return Text.EMPTY;
}
double x = numberOfSpaces - Math.floor(numberOfSpaces);
int numberOfSpecialSpaces = (int) (x / 0.25);
int numberOfNormalSpaces = (int) (Math.floor(numberOfSpaces) - numberOfSpecialSpaces);
if (numberOfNormalSpaces < 0) {
if (numberOfSpecialSpaces == 3) {
numberOfSpecialSpaces = 0;
numberOfNormalSpaces = (int) Math.ceil(numberOfSpaces);
} else {
numberOfSpecialSpaces += numberOfNormalSpaces;
numberOfNormalSpaces = 0;
}
}
for (int k = 0; k < numberOfNormalSpaces; k++) {
spaces.append(Text.of(" "));
}
for (int l = 0; l < numberOfSpecialSpaces; l++) {
spaces.append(Text.builder().style(TextStyles.BOLD).append(Text.of(" ")).build());
}
return spaces.toText();
}
示例3: draw
import org.spongepowered.api.text.Text; //導入方法依賴的package包/類
private void draw() {
double s = size / Double.valueOf(pageSize);
int maxPages = (int) Math.ceil(s);
printHeader(page, maxPages);
for (int i = 0; i < pageSize; i++) {
if (i < rows.size()) {
double totalCount = 0;
Text.Builder row = Text.builder();
Row rowObject = rows.get(i);
for (Column column : this.columns) {
Text value = rows.get(i).getValue(column.key);
if (column.trim) {
value = new TextTrimmer(value, column.spacing).trim();
}
double numberOfSpaces = column.spacing - getSpaces(value);
Text spaces = getSpacesString(numberOfSpaces);
row.append(Text.of(value, spaces));
totalCount += numberOfSpaces + getSpaces(value);
}
rowObject.setSpaceLength(totalCount);
if (totalCount > largestColumn) {
largestColumn = totalCount;
}
rowMessage.add(row.build());
}
}
}
示例4: printHeader
import org.spongepowered.api.text.Text; //導入方法依賴的package包/類
private void printHeader(int currentPage, int maxPages) {
topMessage.add(Text.EMPTY);
topMessage.add(Text.join(Text.builder().color(TextColors.DARK_GRAY).append(Text.of("== ")).build(),
this.tableName,
Text.builder().color(TextColors.GREEN).append(Text.of(" "), Text.of(currentPage)).build(),
Text.builder().color(TextColors.GRAY).append(Text.of("/")).build(),
Text.builder().color(TextColors.GREEN).append(Text.of(maxPages)).build(),
Text.builder().color(TextColors.DARK_GRAY).append(Text.of(" ==")).build()));
if (maxPages > 1) {
topMessage.add(Text.builder().color(TextColors.GRAY).append(Text.of("Type /clan page <1-", maxPages, "> to scroll through pages")).build());
}
topMessage.add(Text.EMPTY);
if (message != null) {
topMessage.add(message);
topMessage.add(Text.EMPTY);
}
double totalCount = 0;
Text.Builder row = Text.builder();
for (Column column : this.columns) {
Text header = Text.builder(column.key + ":").color(TextColors.DARK_GREEN).build();
double numberOfSpaces = column.spacing - getSpaces(header);
Text spaces = getSpacesString(numberOfSpaces);
row.color(TextColors.DARK_GREEN).append(Text.of(header)).color(TextColors.RESET).append(Text.of(spaces));
double rowSize = (column.spacing - totalCount) + getSpaces(header);
totalCount += rowSize;
}
headerSpaceLength = totalCount;
largestColumn = totalCount;
headerMessage = row.build();
}
示例5: getSpacesString
import org.spongepowered.api.text.Text; //導入方法依賴的package包/類
private Text getSpacesString(double numberOfSpaces) {
Text.Builder spaces = Text.builder();
if (Math.floor(numberOfSpaces) == 0) {
return Text.EMPTY;
}
double x = numberOfSpaces - Math.floor(numberOfSpaces);
int numberOfSpecialSpaces = (int) (x / 0.25);
int numberOfNormalSpaces = (int) (Math.floor(numberOfSpaces) - numberOfSpecialSpaces);
if (numberOfNormalSpaces < 0) {
if (numberOfSpecialSpaces == 3) {
numberOfSpecialSpaces = 0;
numberOfNormalSpaces = (int) Math.ceil(numberOfSpaces);
} else {
numberOfSpecialSpaces += numberOfNormalSpaces;
numberOfNormalSpaces = 0;
}
}
for (int k = 0; k < numberOfNormalSpaces; k++) {
spaces.append(Text.of(" "));
}
for (int l = 0; l < numberOfSpecialSpaces; l++) {
spaces.append(Text.builder().style(TextStyles.BOLD).append(Text.of(" ")).build());
}
return spaces.build();
}
示例6: sendHelpPage
import org.spongepowered.api.text.Text; //導入方法依賴的package包/類
private void sendHelpPage(List<FilledCommand> commands, CommandSource commandSender, int page, String pageCommand) {
int id = page - 1;
int commandMinIndex = getMinIndexForPage(page);
int commandMaxIndex = getMaxIndexForPage(page, commands.size());
int maxPages = getMaxPagesForSize(commands.size());
if (id < maxPages && id >= 0) {
commandSender.sendMessage(Text.EMPTY);
Text header = Text.of(
Text.builder("== ").color(TextColors.DARK_GRAY).build(),
Text.builder("MC").color(TextColors.DARK_GREEN).build(),
Text.builder("Clans").color(TextColors.GREEN).build(),
Text.of(" Страница помощи "),
Text.builder(String.valueOf(page)).color(TextColors.GREEN).build(),
Text.builder("/").color(TextColors.GRAY).build(),
Text.builder(String.valueOf(maxPages)).color(TextColors.GREEN).build(),
Text.builder(" ==").color(TextColors.DARK_GRAY).build()
);
commandSender.sendMessage(header);
if (page < maxPages) {
Text subHeader = Text.of(
Text.builder("Напишите").color(TextColors.GRAY).build(),
Text.builder(String.format(" /clan %s %s", pageCommand, page + 1)).color(TextColors.DARK_GREEN),
Text.builder(" чтобы открыть следующую страницу").color(TextColors.GRAY)
);
commandSender.sendMessage(subHeader);
}
commandSender.sendMessage(Text.EMPTY);
List<FilledCommand> commandsSubList = commands.subList(commandMinIndex, commandMaxIndex);
for (FilledCommand baseCommand : commandsSubList) {
Text.Builder firstMessageLine = Text.builder();
if (baseCommand.getSpongePermission().startsWith("mcclans.admin")) {
firstMessageLine.append(
Text.of("["),
Text.builder("Admin").color(TextColors.RED).build(),
Text.of("] ")
);
}
firstMessageLine.append(Text.builder().color(TextColors.DARK_GREEN).append(Text.of("/" + baseCommand.getFullPath())).build());
List<FilledParameter> parameters = baseCommand.getParameters();
for (FilledParameter parameter : parameters) {
if (parameter instanceof NormalFilledParameter) {
NormalFilledParameter normalParameter = (NormalFilledParameter) parameter;
Text parameterText = Text.builder().onHover(TextActions.showText(getParameterDescription(normalParameter))).append(Text.of(normalParameter.getName())).build();
if (normalParameter.isOptional()) {
firstMessageLine.append(Text.of(Text.builder().color(TextColors.GREEN).append(Text.of(" {")).build(), parameterText, Text.builder().color(TextColors.GREEN).append(Text.of("}")).build()));
} else {
firstMessageLine.append(Text.of(Text.builder().color(TextColors.GREEN).append(Text.of(" <")).build(), parameterText, Text.builder().color(TextColors.GREEN).append(Text.of(">")).build()));
}
}
}
Text secondMessageLine = Text.of(
Text.of(" "),
Text.builder(baseCommand.getDescription()).color(TextColors.GRAY).build()
);
commandSender.sendMessage(firstMessageLine.build());
commandSender.sendMessage(secondMessageLine);
}
} else if (maxPages == 0) {
Messages.sendWarningMessage(commandSender, Messages.THIS_COMMAND_HAS_NO_INFORMATION_TO_DISPLAY);
} else {
Messages.sendWarningMessage(commandSender, Messages.PAGE_DOES_NOT_EXIST);
}
}
示例7: displayParameterHelpPage
import org.spongepowered.api.text.Text; //導入方法依賴的package包/類
private void displayParameterHelpPage(CommandSource commandSource, FilledCommand filledCommand) {
commandSource.sendMessage(Text.EMPTY);
commandSource.sendMessage(Text.builder("Не получилось выполнить команду").color(TextColors.RED).build());
commandSource.sendMessage(Text.builder("Команда требует параметр:").color(TextColors.RED).build());
Text title = Text.of(
Text.builder("MC").color(TextColors.DARK_GREEN).build(),
Text.builder("Clans").color(TextColors.GREEN).build(),
Text.of(" Помощь с параметром")
);
HorizontalTable<NormalFilledParameter> table = new HorizontalTable<>(title, 5, (TableAdapter<NormalFilledParameter>) (row, parameter, index) -> {
Text parameterName;
if (parameter.isOptional()) {
parameterName = Text.builder(String.format("{%s}", parameter.getName())).build();
} else {
parameterName = Text.builder(String.format("<%s>", parameter.getName())).build();
}
Text parameterDescription = getParameterDescription(parameter);
row.setValue("Parameter", parameterName);
row.setValue("Description", parameterDescription);
});
table.defineColumn("Parameter", 25);
table.defineColumn("Description", 30);
Text.Builder fullCommandString = Text.builder("/" + filledCommand.getFullPath());
List<FilledParameter> requiredParameters = filledCommand.getParameters();
List<NormalFilledParameter> normalParameters = new ArrayList<>();
requiredParameters.stream().filter(parameter -> parameter instanceof NormalFilledParameter).forEach(parameter -> {
NormalFilledParameter normalFilledParameter = (NormalFilledParameter) parameter;
normalParameters.add(normalFilledParameter);
if (normalFilledParameter.isOptional()) {
fullCommandString.append(Text.builder(" {" + normalFilledParameter.getName() + "}").color(TextColors.GREEN).build());
} else {
fullCommandString.append(Text.builder(" <" + normalFilledParameter.getName() + ">").color(TextColors.GREEN).build());
}
});
table.setMessage(fullCommandString.build());
table.draw(normalParameters, 1, commandSource);
}
示例8: addFormats
import org.spongepowered.api.text.Text; //導入方法依賴的package包/類
private static void addFormats(Text.Builder builder, TextColor color, List<TextStyle> styles, String s) {
if (color != null) {
if (styles.size() == 0) {
builder.append(Text.of(color, s));
}
if (styles.size() == 1) {
builder.append(Text.of(color, styles.get(0), s));
}
if (styles.size() == 2) {
builder.append(Text.of(color, styles.get(0), styles.get(1), s));
}
if (styles.size() == 3) {
builder.append(Text.of(color, styles.get(0), styles.get(1), styles.get(2), s));
}
if (styles.size() == 4) {
builder.append(Text.of(color, styles.get(0), styles.get(1), styles.get(2), styles.get(3), s));
}
if (styles.size() > 4) {
builder.append(Text.of(color, styles.get(0), styles.get(1), styles.get(2), styles.get(3), styles.get(4), s));
}
} else {
if (styles.size() == 0) {
builder.append(Text.of(s));
}
if (styles.size() == 1) {
builder.append(Text.of(styles.get(0), s));
}
if (styles.size() == 2) {
builder.append(Text.of(styles.get(0), styles.get(1), s));
}
if (styles.size() == 3) {
builder.append(Text.of(styles.get(0), styles.get(1), styles.get(2), s));
}
if (styles.size() == 4) {
builder.append(Text.of(styles.get(0), styles.get(1), styles.get(2), styles.get(3), s));
}
if (styles.size() > 4) {
builder.append(Text.of(styles.get(0), styles.get(1), styles.get(2), styles.get(3), styles.get(4), s));
}
}
}
示例9: replace
import org.spongepowered.api.text.Text; //導入方法依賴的package包/類
private Text replace(String string) {
if (lang==null)return Text.of(path);
List<Object> elements = new LinkedList<>();
Set<String> unusedPlaceholders = new HashSet<>();
unusedPlaceholders.addAll(replacements.keySet()); //for translators
elements.add(string);
boolean round=true;
while (round) {
round=false;
i: for (int i=0; i<elements.size(); i++) {
if (elements.get(i) instanceof String) {
String val = (String)elements.get(i);
for (Entry<String, Object> e : replacements.entrySet()) {
int pos=val.indexOf(e.getKey());
if (pos>=0) { round=true;
unusedPlaceholders.remove(e.getKey());
if (pos+e.getKey().length()<val.length())
elements.add(i+1, val.substring(pos+e.getKey().length()));
elements.add(i+1, e.getValue());
if (pos>0)
elements.add(i+1, val.substring(0, pos));
elements.remove(i);
break i;
}
}
}
}
}
if (!unusedPlaceholders.isEmpty())
LangSwitch.l("Localisation %s does not use the following placeholder: %s", path, StringUtils.join(unusedPlaceholders, ", "));
Text.Builder result = Text.builder();
for (Object o : elements)
if (o instanceof Text)
result.append((Text)o);
//not deserializing legacy code is the only thing that let's them work in this case, since they need to apply for the rest of the result
// else if (o instanceof String)
// result.append( TextSerializers.FORMATTING_CODE.deserializeUnchecked((String)o) );
// result.append( TextSerializers.LEGACY_FORMATTING_CODE.deserializeUnchecked((String)o) );
else
result.append(Text.of(o));
return result.build();
}