Title + variable

Discussion in 'Spigot Plugin Development' started by burizio, May 2, 2015.

  1. Hi;


    I´m doing a plugin and i want to know if it´s posible to send a title to a player adding a variable

    For example Yo loose 5 points. Where the 5 its a int variable.

    Thanks a lot for the help.
     
  2. gigosaurus

    Supporter

    You want to use string concatenation to create a string which contains the int variable.
    Code (Java):
    String title = "You lose " + points + " points.";
    Where points is your int variable. Then you just send a title with that string as its text.
    I'm going to guess you don't know how to send a title either or that your true question was how to make one, so the code for that is in this spoiler.
    WARNING: This uses NMS, which means it could break/change between minecraft versions.
    Code (Java):
    IChatBaseComponent title = ChatSerializer.a("{\"text\": \"You lose " + points + " points.\"}");
    PacketPlayOutTitle packet = new PacketPlayOutTitle(PacketPlayOutTitle.EnumTitleAction.TITLE, title);
    ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
     
    Where points is your int variable, and player is the player you want to show the title to.
     
    • Like Like x 2
  3. Increible, thank you that was all i want to know thank for your help really ussefull.