MessageAPI 1.0.2

v1.0.2

  1. CBPlugins
    Contributors:
    CBPlugins
    Note: This Plugin will no longer be supported!

    What is MessageAPI?

    MessageAPI is an API which allows you to send messages to a player in the language he has selected in his client. It's currently supporting every language!

    How do I use it?
    If you are not a developer, you must use it only if you have one or more plugins that need it. If you are a developer, you can see how you can use it right.
    Code (Text):
    private MessageManager manager = null;
    You create a variable, whatever you want to call it, of type MessageManager.
    Code (Text):
    private MessageManager manager = null;

    public void onEnable() {
         MessageAPI.getInstance().registerLanguage(this, "en_US");
         MessageAPI.getInstance().registerLanguage(this, "en_UK");
         MessageAPI.getInstance().registerLanguage(this, "de_DE");
         MessageAPI.getInstance().registerLanguage(this, "fr_FR");
         MessageAPI.getInstance().registerLanguage(this, "es_ES");
         manager = MessageAPI.getInstance().getMessageManager(this);
         manager.loadFiles();
    }
    In your onEnable method you register all the languages you use and you initialize the variable and load the language files. As you create this, I'll show you later. NOTE: If you want to do it that way, as shown below, you need to write all this in your main class.

    Now you can use these Methods to get a message:
    Code (Text):
    manager.getRawMessage(player, key);
    manager.getColoredMessage(player, key, char);
    manager.getReplacedMessage(player, key, HashMap<String, String>);
    manager.getReplacedColoredMessage(player, key, char, HashMap<String, String>);
    The variable player is always a variable of the type Player. The key tells the method where it finds the message. What you have to write in the key, I'll show you later.
    The char Variable is of the type char. It is the character to translate the color (like '&' or 'ยง').
    And in the HashMap you can define, what you want to replace in the message.

    How do I write the message files?
    You create a folder called MessageAPI in your plugins folder. In the folder MessageAPI you create a folder with the name of you plugin (the name you wrote in the plugin.yml). In this folder you create four new files. These files are called 'en_US.msg', 'de_DE.msg', 'fr_FR.msg', 'es_ES.msg' and 'sv_SE.msg'. You open these files with a normal text editor and write in the first line
    Code (Text):
    +++message-api-file_en_US+++
    Replace 'en_US' with the other languages. In the next line you can write the first message. It should look like this:
    Code (Text):
    this-is-the-key=this is the message.
    This line has to be in all four files but in the specified languages. If you did this, you finished with the setup and can use the plugin. NOTE: You have to create a new folder for each plugin.

    Source Code?
    You can find the source code here:
    http://www.github.com/CBPlugins/MessageAPI/
    Have fun with it :D
    Kagrurnaax, REZombieman and namke like this.