Skip to content
anerach edited this page May 27, 2012 · 1 revision

Introduction

This API is created to give plugin developers an easy way to localize their own plugin. This API comes with various functions that should make it easier for you to send messages in different languages to the whole server.

Usage

Set-up

First you need to place this somewhere in your main class. You must have access to this variable in order to receive a localisation.

public LocalisationAPI localisation;

Now, in the onEnable place something like this.

localisation = new LocalisationAPI(this);
localisation.addLanguage(Language.ENGLISH, getResource("resources/english.yml"), true);
localisation.addLanguage(Language.DUTCH, getResource("resources/dutch.yml"));

When adding languages make sure you set a default one. You do this by adding a true as the third argument.

Using

When you've finished adding the code abbove to your plugin you can start using the API.
To send a message to a player you need to use this code.

localisation.sendMessage(Player player, String message);
localisation.sendMessage(Player player, String message, HashMap<String, String> args);

The first code sends a message to the player without any custom variables.
Using the second code you can add variables to the localized message.
Whenever MultiLanguage finds a key from the HashMap surrounded by {} in the code it'll replace it with the value in the HashMap.

To send a message to every player online in their own language you should use the sendGlobalMessage function.

localisation.sendGlobalMessage(String message);
localisation.sendGlobalMessage(String message, Player player);
localisation.sendGlobalMessage(String message, HashMap<String, String> args);
localisation.sendGlobalMessage(String message, Player player, HashMap<String, String> args);

This function is almost the same as the sendMessage. The main difference is that this one will send a message to all the players online in their own language. The reason why it's possible to add a player argument to the function is to use the player variables. This might be useful when you want to send a message to everyone about a specific player.

Player Variables

There are some predefined player variables. These can be overwritten using a HashMap argument. This works in both the sendGlobalMessage and the sendMessage function.

The predefined player variables are

  • {player}
  • {health}
  • {hunger}
  • {level}
  • {exp}
  • {language}
  • {killer}
Clone this wiki locally