Ejemplo n.º 1
0
 /**
  * Converts the components into a string without any formatting
  *
  * @param components the components to convert
  * @return the string as plain text
  */
 public static String toPlainText(BaseComponent... components) {
   StringBuilder builder = new StringBuilder();
   for (BaseComponent msg : components) {
     builder.append(msg.toPlainText());
   }
   return builder.toString();
 }
Ejemplo n.º 2
0
 void toLegacyText(StringBuilder builder) {
   if (extra != null) {
     for (BaseComponent e : extra) {
       e.toLegacyText(builder);
     }
   }
 }
Ejemplo n.º 3
0
  @Override
  public BaseComponent apply(
      final com.gotofinal.messages.api.chat.component.BaseComponent baseComponent) {
    final BaseComponent cpy;
    if (baseComponent instanceof com.gotofinal.messages.api.chat.component.TextComponent) {
      cpy =
          new TextComponent(
              ((com.gotofinal.messages.api.chat.component.TextComponent) baseComponent).getText());
    } else if (baseComponent
        instanceof com.gotofinal.messages.api.chat.component.TranslatableComponent) {
      final com.gotofinal.messages.api.chat.component.TranslatableComponent tmp =
          (com.gotofinal.messages.api.chat.component.TranslatableComponent) baseComponent;
      cpy = new TranslatableComponent(tmp.getTranslate(), tmp.getWith());
    } else {
      throw new UnsupportedChatElement(baseComponent.toString());
    }
    cpy.setBold(baseComponent.isBoldRaw());
    cpy.setItalic(baseComponent.isItalicRaw());
    cpy.setObfuscated(baseComponent.isObfuscatedRaw());
    cpy.setStrikethrough(baseComponent.isStrikethroughRaw());
    cpy.setUnderlined(baseComponent.isUnderlinedRaw());
    cpy.setColor(this.getColor(baseComponent.getColorRaw()));

    {
      final com.gotofinal.messages.api.chat.component.ClickEvent tmp =
          baseComponent.getClickEvent();
      if (tmp != null) {
        final ClickEvent cpyEvt = new ClickEvent(this.getAction(tmp.getAction()), tmp.getValue());
        cpy.setClickEvent(cpyEvt);
      }
    }
    {
      final com.gotofinal.messages.api.chat.component.HoverEvent tmp =
          baseComponent.getHoverEvent();
      if (tmp != null) {
        final HoverEvent cpyEvt =
            new HoverEvent(this.getAction(tmp.getAction()), this.apply(tmp.getValue()));
        cpy.setHoverEvent(cpyEvt);
      }
    }

    final List<com.gotofinal.messages.api.chat.component.BaseComponent> extra =
        baseComponent.getExtra();
    if ((extra == null) || extra.isEmpty()) {
      return cpy;
    }
    for (final com.gotofinal.messages.api.chat.component.BaseComponent ext : extra) {
      cpy.addExtra(this.apply(ext));
    }
    return cpy;
  }
Ejemplo n.º 4
0
 /**
  * Appends a component to the component. The text will inherit this component's formatting
  *
  * @param component the component to append
  */
 public void addExtra(BaseComponent component) {
   if (extra == null) {
     extra = new ArrayList<BaseComponent>();
   }
   component.parent = this;
   extra.add(component);
 }
Ejemplo n.º 5
0
 /**
  * Returns the color of this component. This uses the parent's color if this component doesn't
  * have one. {@link net.md_5.bungee.api.ChatColor#WHITE} is returned if no color is found.
  *
  * @return the color of this component
  */
 public ChatColor getColor() {
   if (color == null) {
     if (parent == null) {
       return ChatColor.WHITE;
     }
     return parent.getColor();
   }
   return color;
 }
Ejemplo n.º 6
0
 public synchronized void disconnect0(BaseComponent... reason) {
   if (ch.getHandle().isActive()) {
     bungee
         .getLogger()
         .log(
             Level.INFO,
             "[" + getName() + "] disconnected with: " + BaseComponent.toLegacyText(reason));
     unsafe().sendPacket(new Kick(ComponentSerializer.toString(reason)));
     ch.close();
     if (server != null) {
       server.disconnect("Quitting");
     }
   }
 }
Ejemplo n.º 7
0
  public void disconnect0(final BaseComponent... reason) {
    if (!ch.isClosed()) {
      bungee
          .getLogger()
          .log(
              Level.INFO,
              "[{0}] disconnected with: {1}",
              new Object[] {getName(), BaseComponent.toLegacyText(reason)});

      // Why do we have to delay this you might ask? Well the simple reason is MOJANG.
      // Despite many a bug report posted, ever since the 1.7 protocol rewrite, the client STILL has
      // a race condition upon switching protocols.
      // As such, despite the protocol switch packets already having been sent, there is the
      // possibility of a client side exception
      // To help combat this we will wait half a second before actually sending the disconnected
      // packet so that whoever is on the other
      // end has a somewhat better chance of receiving the proper packet.
      ch.getHandle()
          .eventLoop()
          .schedule(
              new Runnable() {

                @Override
                public void run() {
                  unsafe().sendPacket(new Kick(ComponentSerializer.toString(reason)));
                  ch.close();
                }
              },
              500,
              TimeUnit.MILLISECONDS);

      if (server != null) {
        server.disconnect("Quitting");
      }
    }
  }
Ejemplo n.º 8
0
 BaseComponent(BaseComponent old) {
   setColor(old.getColorRaw());
   setBold(old.isBoldRaw());
   setItalic(old.isItalicRaw());
   setUnderlined(old.isUnderlinedRaw());
   setStrikethrough(old.isStrikethroughRaw());
   setObfuscated(old.isObfuscatedRaw());
   setClickEvent(old.getClickEvent());
   setHoverEvent(old.getHoverEvent());
   if (old.getExtra() != null) {
     for (BaseComponent component : old.getExtra()) {
       addExtra(component.duplicate());
     }
   }
 }
Ejemplo n.º 9
0
 public void setExtra(List<BaseComponent> components) {
   for (BaseComponent component : components) {
     component.parent = this;
   }
   extra = components;
 }
Ejemplo n.º 10
0
 /**
  * Returns whether this component is obfuscated. This uses the parent's setting if this component
  * hasn't been set. false is returned if none of the parent chain has been set.
  *
  * @return whether the component is obfuscated
  */
 public boolean isObfuscated() {
   if (obfuscated == null) {
     return parent != null && parent.isObfuscated();
   }
   return obfuscated;
 }
Ejemplo n.º 11
0
 /**
  * Returns whether this component is strikethrough. This uses the parent's setting if this
  * component hasn't been set. false is returned if none of the parent chain has been set.
  *
  * @return whether the component is strikethrough
  */
 public boolean isStrikethrough() {
   if (strikethrough == null) {
     return parent != null && parent.isStrikethrough();
   }
   return strikethrough;
 }
Ejemplo n.º 12
0
 /**
  * Returns whether this component is underlined. This uses the parent's setting if this component
  * hasn't been set. false is returned if none of the parent chain has been set.
  *
  * @return whether the component is underlined
  */
 public boolean isUnderlined() {
   if (underlined == null) {
     return parent != null && parent.isUnderlined();
   }
   return underlined;
 }
Ejemplo n.º 13
0
 /**
  * Returns whether this component is italic. This uses the parent's setting if this component
  * hasn't been set. false is returned if none of the parent chain has been set.
  *
  * @return whether the component is italic
  */
 public boolean isItalic() {
   if (italic == null) {
     return parent != null && parent.isItalic();
   }
   return italic;
 }
Ejemplo n.º 14
0
 /**
  * Returns whether this component is bold. This uses the parent's setting if this component hasn't
  * been set. false is returned if none of the parent chain has been set.
  *
  * @return whether the component is bold
  */
 public boolean isBold() {
   if (bold == null) {
     return parent != null && parent.isBold();
   }
   return bold;
 }