Can not send title.

Discussion in 'Spigot Plugin Development' started by Kargond, Jun 10, 2015.

  1. Hi! I can't send title(or subtitle) to player. Here is line, where I send title.
    Code (Text):
    TitleLib(p, TITLE, "owh god this is awesome!", 10, 60, 10, ChatColor.GREEN);
    And here is my TitleLib function:
    Code (Text):

        public TitleLib(Player player, EnumTitleAction titleType, String text, int fadeInTime, int showTime, int fadeOutTime, ChatColor color)
            IChatBaseComponent chatTitle = ChatSerializer.a("{\"text\": \"" + text + "\",color:" + + "}");
            if(titleType != EnumTitleAction.TITLE && titleType != EnumTitleAction.SUBTITLE) return;
            PacketPlayOutTitle title = new PacketPlayOutTitle(titleType, chatTitle);
            PacketPlayOutTitle length = new PacketPlayOutTitle(fadeInTime, showTime ,fadeOutTime);
            ((CraftPlayer) player).getHandle().playerConnection.sendPacket(title);
            ((CraftPlayer) player).getHandle().playerConnection.sendPacket(length);
    It underlines TITLE word from 1st section of code and says:
    TITLE cannot be resolved to a variable

    Well, when I changed it to EnumTitleAction.TITLE . It underlined TitleLib and said The method TitleLib(Player, EnumTitleAction, String, int, int, int, ChatColor) is undefined for the type InviteSystem.
    How can I fix it?
  2. Your code can never get to that line.
    You have this line
    Code (Text):

    if(titleType != EnumTitleAction.TITLE && titleType != EnumTitleAction.SUBTITLE) return;
    Which can never be false. The title type cannot be both EnumTitleAction.TITLE and EnumTitleAction.SUBTITLE, so you will always return after this.

    You're also getting "undefined method" because TitleLib is a constructor, not a method
  3. Nope, that line is fine. It checks if the action is neither of the two.

    @Kargond why use a constructor? It makes more sense to make it a (static) method.
    • Agree Agree x 1
  4. Yeah, I did it. Thanks for help.

  5. You're right, misread his code. That's what I get for answering quickly. Thanks for the correction!
    • Friendly Friendly x 1