org.spongepowered.api.text.Text.of()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(5.6k)|赞(0)|评价(0)|浏览(98)

本文整理了Java中org.spongepowered.api.text.Text.of()方法的一些代码示例,展示了Text.of()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Text.of()方法的具体详情如下:
包路径:org.spongepowered.api.text.Text
类名称:Text
方法名:of

Text.of介绍

[英]Returns an empty, unformatted Text instance.
[中]返回一个空的、未格式化的文本实例。

代码示例

代码示例来源:origin: SpongePowered/SpongeAPI

/**
   * Return a usage message for this specific argument.
   *
   * @param src The source requesting usage
   * @return The formatted usage
   */
  public Text getUsage(CommandSource src) {
    return getKey() == null ? Text.of() : Text.of("<", getKey(), ">");
  }
}

代码示例来源:origin: SpongePowered/SpongeAPI

@Override
  public Text getUsage(CommandSource context) {
    return Text.of(this.element.getUsage(context), CommandMessageFormatting.STAR_TEXT);
  }
}

代码示例来源:origin: SpongePowered/SpongeAPI

@Override
  public Text getUsage(CommandSource src) {
    return Text.of("[", this.element.getUsage(src), "]");
  }
}

代码示例来源:origin: SpongePowered/SpongeAPI

@Override
  public Text getUsage(CommandSource src) {
    return Text.of(CommandMessageFormatting.LT_TEXT, getKey(), CommandMessageFormatting.ELLIPSIS_TEXT, CommandMessageFormatting.GT_TEXT);
  }
}

代码示例来源:origin: EngineHub/WorldEdit

@Override
public Optional<Text> getShortDescription(CommandSource source) {
  String description = command.getDescription().getDescription();
  if (description != null && !description.isEmpty()) {
    return Optional.of(Text.of(description));
  }
  return Optional.empty();
}

代码示例来源:origin: EngineHub/WorldEdit

@Override
public Optional<Text> getHelp(CommandSource source) {
  String help = command.getDescription().getHelp();
  if (help != null && !help.isEmpty()) {
    return Optional.of(Text.of(help));
  }
  return Optional.empty();
}

代码示例来源:origin: SpongePowered/SpongeAPI

@Nullable
@Override
protected Object parseValue(CommandSource source, CommandArgs args) throws ArgumentParseException {
  try {
    return UUID.fromString(args.next());
  } catch (IllegalArgumentException ex) {
    throw args.createError(Text.of("Invalid UUID!"));
  }
}

代码示例来源:origin: EngineHub/WorldEdit

private void sendColorized(String msg, TextColor formatting) {
  for (String part : msg.split("\n")) {
    this.player.sendMessage(Text.of(formatting, TextSerializers.FORMATTING_CODE.deserialize(part)));
  }
}

代码示例来源:origin: EngineHub/WorldEdit

private void sendColorized(String msg, TextColor formatting) {
  for (String part : msg.split("\n")) {
    sender.sendMessage(Text.of(formatting, TextSerializers.LEGACY_FORMATTING_CODE.deserialize(part)));
  }
}

代码示例来源:origin: SpongePowered/SpongeAPI

public int peek() throws ArgumentParseException {
  if (!hasMore()) {
    throw createException(Text.of("Buffer overrun while parsing args"));
  }
  return this.buffer.codePointAt(this.index + 1);
}

代码示例来源:origin: SpongePowered/SpongeAPI

public int next() throws ArgumentParseException {
  if (!hasMore()) {
    throw createException(Text.of("Buffer overrun while parsing args"));
  }
  return this.buffer.codePointAt(++this.index);
}

代码示例来源:origin: EngineHub/WorldEdit

@Override
  public Text getUsage(CommandSource source) {
    return Text.of(command.getDescription().getUsage());
  }
}

代码示例来源:origin: SpongePowered/SpongeAPI

@Override
  public Text getUsage(CommandSource src) {
    return src instanceof Entity && (this.returnSource || this.returnTarget) ? Text.of("[", this.getKey(), "]") : super.getUsage(src);
  }
}

代码示例来源:origin: SpongePowered/SpongeAPI

@Override
  public Text getUsage(CommandSource src) {
    return src instanceof Player && this.returnSource ? Text.of("[", super.getUsage(src), "]") : super.getUsage(src);
  }
}

代码示例来源:origin: SpongePowered/SpongeAPI

@Test
public void testToPlainTranslatables() {
  Text testText = Text.of(new FixedTranslation("This is a translated %s"), Text.of("string"));
  assertEquals("This is a translated string", testText.toPlain());
}

代码示例来源:origin: SpongePowered/SpongeAPI

@Test
public void testSimpleCompositeText() {
  Text text = Text.of(TextColors.YELLOW, Text.of("White"));
  assertThat(text.toPlain(), is("White"));
  text = findText(text, "White");
  assertThat(text.getColor(), is(TextColors.YELLOW));
}

代码示例来源:origin: SpongePowered/SpongeAPI

@Test
public void testGettingBothPlayers() throws Exception {
  CommandArgs args = new CommandArgs("test", Lists.newArrayList(new SingleArg("test", 0, 5)));
  CommandContext context = new CommandContext();
  CommandSource source = Mockito.mock(CommandSource.class);
  getPlayerElement().parse(source, args, context);
  Collection<Player> cpl = context.getAll(Text.of("player"));
  assertEquals(2, cpl.size());
  Collection<String> s = cpl.stream().map(User::getName).collect(Collectors.toList());
  assertTrue(s.contains("test1"));
  assertTrue(s.contains("test2"));
}

代码示例来源:origin: SpongePowered/SpongeAPI

@Test
public void testToPlainLiterals() {
  Text testText = Text.builder("Hello ").append(Text.of("world"), Text.of(", this is here")).build();
  assertEquals("Hello world, this is here", testText.toPlain());
}

代码示例来源:origin: SpongePowered/SpongeAPI

@Test
public void testGettingSinglePlayer() throws Exception {
  CommandArgs args = new CommandArgs("test1", Lists.newArrayList(new SingleArg("test1", 0, 5)));
  CommandContext context = new CommandContext();
  CommandSource source = Mockito.mock(CommandSource.class);
  getPlayerElement().parse(source, args, context);
  assertEquals("test1", context.<Player>getOne(Text.of("player")).get().getName());
}

代码示例来源:origin: SpongePowered/SpongeAPI

@Test
public void testTextOf() {
  Text text = Text.of(TextColors.RED, "Red");
  assertThat(text.toPlain(), is("Red"));
  text = findText(text, "Red");
  assertThat(text.getColor(), is(TextColors.RED));
  assertTrue(text.getStyle().isEmpty());
  assertThat(text.getChildren(), empty());
}

相关文章