當前位置: 首頁>>代碼示例>>Java>>正文


Java KeybindComponent類代碼示例

本文整理匯總了Java中net.kyori.text.KeybindComponent的典型用法代碼示例。如果您正苦於以下問題:Java KeybindComponent類的具體用法?Java KeybindComponent怎麽用?Java KeybindComponent使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


KeybindComponent類屬於net.kyori.text包,在下文中一共展示了KeybindComponent類的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: serialize

import net.kyori.text.KeybindComponent; //導入依賴的package包/類
@Override
public JsonElement serialize(final Component component, final Type type, final JsonSerializationContext context) {
  final JsonObject object = new JsonObject();
  if(component instanceof TextComponent) {
    object.addProperty("text", ((TextComponent) component).content());
  } else if(component instanceof TranslatableComponent) {
    final TranslatableComponent tc = (TranslatableComponent) component;
    object.addProperty("translate", tc.key());
    if(!tc.args().isEmpty()) {
      final JsonArray with = new JsonArray();
      for(final Component arg : tc.args()) {
        with.add(this.serialize(arg, arg.getClass(), context));
      }
      object.add("with", with);
    }
  } else if(component instanceof ScoreComponent) {
    final ScoreComponent sc = (ScoreComponent) component;
    final JsonObject score = new JsonObject();
    score.addProperty("name", sc.name());
    score.addProperty("objective", sc.objective());
    // score component value is optional
    if(sc.value() != null) score.addProperty("value", sc.value());
    object.add("score", score);
  } else if(component instanceof SelectorComponent) {
    object.addProperty("selector", ((SelectorComponent) component).pattern());
  } else if(component instanceof KeybindComponent) {
    object.addProperty("keybind", ((KeybindComponent) component).keybind());
  } else {
    throw new IllegalArgumentException("Don't know how to serialize " + component + " as a Component");
  }

  if(!component.children().isEmpty()) {
    final JsonArray extra = new JsonArray();
    for(final Component child : component.children()) {
      extra.add(this.serialize(child, child.getClass(), context));
    }
    object.add("extra", extra);
  }

  if(component.hasStyling()) {
    for(final TextDecoration decoration : TextDecoration.values()) {
      final TextDecoration.State flag = component.decoration(decoration);
      if(flag != TextDecoration.State.NOT_SET) object.addProperty(decoration.toString(), flag == TextDecoration.State.TRUE);
    }
    if(component.color() != null) object.add("color", context.serialize(component.color()));
    if(component.insertion() != null) object.add("insertion", context.serialize(component.insertion()));
    @Nullable final ClickEvent clickEvent = component.clickEvent();
    if(clickEvent != null) {
      final JsonObject clickEventO = new JsonObject();
      clickEventO.add("action", context.serialize(clickEvent.action()));
      clickEventO.addProperty("value", clickEvent.value());
      object.add("clickEvent", clickEventO);
    }
    @Nullable final HoverEvent hoverEvent = component.hoverEvent();
    if(hoverEvent != null) {
      final JsonObject hoverEventO = new JsonObject();
      hoverEventO.add("action", context.serialize(hoverEvent.action()));
      hoverEventO.add("value", this.serialize(hoverEvent.value(), type, context));
      object.add("hoverEvent", hoverEventO);
    }
  }

  return object;
}
 
開發者ID:KyoriPowered,項目名稱:text,代碼行數:65,代碼來源:GsonComponentSerializer.java

示例2: getReadableComponentSingle

import net.kyori.text.KeybindComponent; //導入依賴的package包/類
public static void getReadableComponentSingle(StringBuilder sb, Component component) {
  if (component.color() != null) {
    sb.append(textColorToBukkit(component.color()));
  }
  if (component instanceof TextComponent) {
    sb.append(((TextComponent) component).content());
  } else if (component instanceof KeybindComponent) {
    sb.append(((KeybindComponent) component).keybind());
  } else if (component instanceof SelectorComponent) {
    sb.append(((SelectorComponent) component).pattern());
  } else {
    throw new UnsupportedOperationException("Cannot parse " + component.getClass());
  }
}
 
開發者ID:SupaHam,項目名稱:SupaCommons,代碼行數:15,代碼來源:ChatUtils.java

示例3: testKeybind

import net.kyori.text.KeybindComponent; //導入依賴的package包/類
@Test
public void testKeybind() {
    Component component = TextParsers.XML_PARSER.parse("<keybind key=\"key.forward\">foo</keybind>");
    TextComponent expected = TextComponent.of("").append(KeybindComponent.of("key.forward").append(TextComponent.of("foo")));
    Assert.assertEquals(expected, component);
}
 
開發者ID:BlurEngine,項目名稱:Blur,代碼行數:7,代碼來源:XmlParserTest.java

示例4: createBuilder

import net.kyori.text.KeybindComponent; //導入依賴的package包/類
@Override public BuildableComponent.Builder<KeybindComponent, KeybindComponent.Builder> createBuilder() {
  return KeybindComponent.builder().keybind(this.key);
}
 
開發者ID:SupaHam,項目名稱:SupaCommons,代碼行數:4,代碼來源:Tags.java

示例5: testKeybind

import net.kyori.text.KeybindComponent; //導入依賴的package包/類
@Test
public void testKeybind() {
    Component component = TextParsers.XML.parse("<keybind key=\"key.forward\">foo</keybind>");
    TextComponent expected = TextComponent.of("").append(KeybindComponent.of("key.forward").append(TextComponent.of("foo")));
    Assert.assertEquals(expected, component);
}
 
開發者ID:SupaHam,項目名稱:SupaCommons,代碼行數:7,代碼來源:XmlParserTest.java


注:本文中的net.kyori.text.KeybindComponent類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。