Adding cool chatblocks

Discussion in 'Plugin Development' started by harvmaster, Jul 30, 2015.

Thread Status:
Not open for further replies.
  1. Offline

    harvmaster

    Hi I am making a plugin and I could really use some help with getting it to print out to the player nicely. I don't know how to control how many spaces and hashtags I have on the top and bottom line and I don't know how to control the spaces either

    I want to do something like this;
    Code:
    Bukkit.broadcastMessage(ChatColor.GOLD + "#########################################");
    Bukkit.broadcastMessage(ChatColor.GOLD + "#                                                    #");
    Bukkit.broadcastMessage(ChatColor.GOLD + "#" + playerName + " has conquered the " + theChestName + "#");
    Bukkit.broadcastMessage(ChatColor.GOLD + "#                                                    #");
    Bukkit.broadcastMessage(ChatColor.GOLD + "#########################################");
    Any help with this would be greatly appreciated,
    Thanks in advanced, Harvmaster
     
  2. Code:
    String message = playerName + " has conquered the " + theChestName;
    int length = message.length();
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < length + 2; i++) sb.append(" ");
    String border = sb.toString();
    
    //broadcast border.replace(" ", "#") + "##"
    //broadcast "#" + border + "#"
    //broadcast "#" + message  + "#"
    //broadcast "#" + border + "#"
    //broadcast border.replace(" ", "#") + "##"
    1. Make the message
    2. Get the length of the message
    3. Define a new StringBuilder
    4. Loop through the message length + 2 (for " " at the start and end). Then add " " to the StringBuilder
    5. Get the content of the StringBuilder

    6. - 11. Display the messages
    This might not work 100% just try it out
     
  3. Offline

    harvmaster

    That printed perfectly into the console but for the client, line 8 and 10 were out of sync, I'm fairly sure its because a space is smaller than a # in game. Is there a way to Sync them?

    p.s. line 9 is 2 spaces short so I added spaced around each # to make it look a little nicer
     
  4. Offline

    teej107

    Doing this is a bad idea. Each texture pack could use a different font making your neat spaces not so neat any more.
     
  5. Offline

    harvmaster

    Do you know of any that could make this text look decent by getting rid of some lines?
    Or should I just broadcast a single line message?
     
  6. Offline

    teej107

    I would recommend to not try and align text. You could do something like this

    or even sandwiching the main message between two blank messages.
     
Thread Status:
Not open for further replies.

Share This Page