[Resource] Easy Help Messages!

Discussion in 'Resources' started by JPG2000, Nov 15, 2013.

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

    JPG2000

    Hello,

    I've created a very simple resource that allows you to create Help Messages with easy:

    Code:java
    1.  
    2. HelpMessages.addMessage("heal", "Line 1", "Line 2");
    3. //Creates a help message, so you can 'get' the string 'heal' and it will return the lines
    4.  
    5. HelpMessages.get("heal");
    6. //Gets the message, in order, on separate lines.
    7.  
    8. //Usefull for things like:
    9. player.sendMessage(HelpMessages.get("heal");
    10.  



    It is very easy to use, and its a nice way to handle messages. If you want a whole help message for a command, when ever someone uses incorrect syntax, just do sender.sendMessage(helpMessages.get("command"); and thats it!

    HelpMessages:
    Code:java
    1. package testapp;
    2.  
    3. import java.util.HashMap;
    4.  
    5. /**
    6. *
    7. * @Author Jake
    8. */
    9. public class HelpMessages {
    10.  
    11. //HashMap for the Base and the HelpMessage associated with it
    12. private static HashMap<String, String[]> helpMap = new HashMap<String, String[]>();
    13.  
    14.  
    15. //Add message method
    16. public static void addMessage(String base, String ... message) {
    17. helpMap.put(base, message); //'puts' the base and the infinite message in the hash map
    18. }
    19.  
    20. public static String get(String base) {
    21. if (helpMap.get(base) != null) { //If its in the map
    22. String holder = ""; //Blank string
    23.  
    24. for (String s: helpMap.containsKey(base)) {
    25. holder += "\n" + s;
    26. }
    27. return holder; //Returns the new string
    28. }
    29. return null; //Base is not in map, return null
    30. }
    31.  
    32. }
    33.  


    Paste version: http://pastebin.com/F497VAKy

    - Jake
     
  2. Offline

    The_Doctor_123

    I don't know.. this seems a little pointless when you could just do
    Code:java
    1.  
    2. String[] message = new String[] {"Line 1", "Line 2"};
    3. player.sendMessage(message);
    4.  
     
    Ultimate_n00b likes this.
  3. Offline

    JPG2000

    The_Doctor_123 Not really, since I can initialize mine, and make it multiple times, and get it multiple times.

    Of course you can make that static, but mine just makes it simple.
     
  4. Offline

    The_Doctor_123

    JPG2000
    It just seems like this is really something too small to be using an API.
     
  5. Offline

    JPG2000

    The_Doctor_123 Its not an API, its one class. And your correct, its small.

    Its something universally that can be used, to shorten down some code, and make it look nice in the procces.
     
  6. Offline

    The_Doctor_123

    JPG2000
    Meh, okay then. I just think it's not really shortening anything.
     
  7. Offline

    JPG2000

  8. Offline

    xTrollxDudex

    JPG2000 likes this.
  9. Offline

    breezeyboy

    Great idea! Maybe grab strings from config like lang.yml
     
    JPG2000 likes this.
  10. Offline

    samosaara

    I was almost giving up of documenting my plugin them JPG2000 comes with my solution, thanks pal.
     
    JPG2000 likes this.
  11. Offline

    Chew

    Wow this is really cool. Thanks for making this. C:
     
  12. Offline

    Onlineids

    Glad I found this was using the_doctors method actually for quite some time, this will make it much easier when documenting help for my multiple classes.
     
Thread Status:
Not open for further replies.

Share This Page