A format for text in config files to make use of the fancy Minecraft chat features like click, hover, suggest, etc.
- Thijs aka NLThijs48: Initial code structure, refactoring and getting it production ready
- Tobias aka Phoenix: Initial code structure and initial parser
-
Add Maven repository:
<repositories> <repository> <id>nlthijs48</id> <url>http://maven.wiefferink.me</url> </repository> </repositories>
-
Add Maven dependency:
<dependencies> <dependency> <groupId>me.wiefferink</groupId> <artifactId>interactivemessenger</artifactId> <version>1.1-SNAPSHOT</version> </dependency> </dependencies>
-
Relocate the library (compatibility with other plugins):
<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-shade-plugin</artifactId> <version>2.4.3</version> <executions> <execution> <phase>package</phase> <goals> <goal>shade</goal> </goals> <configuration> <relocations> <!-- Relocate InteractiveMessenger --> <relocation> <pattern>me.wiefferink.interactivemessenger</pattern> <shadedPattern>your.package.here.shaded.interactivemessenger</shadedPattern> </relocation> </relocations> </configuration> </execution> </executions> </plugin> </plugins> </build>
-
Setup a language:
-
Create a
languages
folder in/src/main/resources
of your project. -
Create the first language file in the
languages
folder, for exampleEN.yml
. -
Add a message to the language file:
message-key: "Hello %0%!"
-
-
Setup the LanguageManager:
At the startup of your plugin (in
onEnable
) create a LanguageManager instance:LanguageManager languageManager = new LanguageManager( this, // The plugin (used to get the languages bundled in the jar file) "languages", // Folder where the languages are stored getConfig().getString("language"), // The language to use indicated by the plugin user "EN", // The default language, expected to be shipped with the plugin and should be complete, fills in gaps in the user-selected language Collections.singletonList("[MyPlugin] ") // Chat prefix to use with Message#prefix(), could of course come from the config file );
-
Send a message:
Message.fromKey("message-key").replacements(player.getName()).send(player);
-
What happens when starting the plugin?
- The LanguageManager will write all language files to the
languages
folder in the directory of your plugin (this keeps included languages up-to-date, while allowing the user to copy and edit the languages). - The language selected by the user and default language file are loaded.
- At
Message.fromKey()
the message will get loaded from the user-selected language file (falling back to the default language file). Message.replacements()
indicates that%0%
should get replaced by the users name.Message.send()
executes the replacements and sends the message to the Player/CommandSender/Logger.
- The LanguageManager will write all language files to the
The plugin AreaShop is using this library and can be checked for advanced usage of this library. The following parts of AreaShop use this library: