Skip to content
A format for text in config files to make use of the fancy Minecraft chat features like click, hover, suggest, etc.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
LICENSE.txt
README.md
Specifications & Guidelines.md
pom.xml

README.md

InteractiveMessenger

A format for text in config files to make use of the fancy Minecraft chat features like click, hover, suggest, etc.

Information

Authors

  • Thijs aka NLThijs48: Initial code structure, refactoring and getting it production ready
  • Tobias aka Phoenix: Initial code structure and initial parser

Usage

  1. Add Maven repository:

    <repositories>
      <repository>
        <id>nlthijs48</id>
        <url>http://maven.wiefferink.me</url>
      </repository>
    </repositories>
  2. Add Maven dependency:

    <dependencies>
      <dependency>
        <groupId>me.wiefferink</groupId>
        <artifactId>interactivemessenger</artifactId>
        <version>1.1-SNAPSHOT</version>
      </dependency>
    </dependencies>
  3. 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>
  4. Setup a language:

    1. Create a languages folder in /src/main/resources of your project.

    2. Create the first language file in the languages folder, for example EN.yml.

    3. Add a message to the language file:

      message-key: "Hello %0%!"
  5. 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
    );
  6. Send a message:

    Message.fromKey("message-key").replacements(player.getName()).send(player);
  7. What happens when starting the plugin?

    1. 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).
    2. The language selected by the user and default language file are loaded.
    3. At Message.fromKey() the message will get loaded from the user-selected language file (falling back to the default language file).
    4. Message.replacements() indicates that %0% should get replaced by the users name.
    5. Message.send() executes the replacements and sends the message to the Player/CommandSender/Logger.

Example

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:

  • AreaShop.setupLanguageManager(): setup the library
  • AreaShop.message method used to send messages, could also be done by using Message.from() directly.
  • /lang: folder with the language files.
You can’t perform that action at this time.