Giter Site home page Giter Site logo

pustinek / interactivemessenger Goto Github PK

View Code? Open in Web Editor NEW

This project forked from nlthijs48/interactivemessenger

0.0 0.0 0.0 177 KB

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

Home Page: https://interactivemessenger.wiefferink.me/

License: Other

Java 100.00%

interactivemessenger's Introduction

InteractiveMessenger

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

Reason for this fork

The original repository was not maintained anymore and since I was personally using this library I decided to fork the project and add support for HEX colors and publish it to Github Packages.

Information

Original 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 dependency:

    <dependencies>
      <dependency>
         <groupId>me.pustinek</groupId>
         <artifactId>interactivemessenger</artifactId>
         <version>1.2.1</version>
         </dependency>
    </dependencies>
  2. 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.pustinek.interactivemessenger</pattern>
                                    <shadedPattern>your.package.here.shaded.interactivemessenger</shadedPattern>
                                </relocation>
                            </relocations>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
  3. 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%!"
  4. 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
    );
  5. Send a message:

    Message.fromKey("message-key").replacements(player.getName()).send(player);
  6. 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.

TODO:

  • Write tests for HEX colors
  • Add support for named variables in the message keys

interactivemessenger's People

Contributors

nlthijs48 avatar phoenixiv avatar pustinek avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.