HomeJavaModsChatLib
ModsJava

ChatLib

Description: - it's made to create the JSON message more easily. Mostly just for my own plugins, but you can use it too if you are willing to. - Supports…

⬇ Download on Spigot
Description:

https://github.com/wysohn/ChatLib

- it's made to create the JSON message more easily. Mostly just for my own plugins, but you can use it too if you are willing to.

- Supports PlaceholderAPI

- If this plugin is problematic with other plugin such as DeluxChat, disable enableChatModification in config.yml.

API:

  1. getInfo(Player) -- get Player Info. This is correspond to the player info section. There are name, group, and click to whisper by default. You can add up any other string if you want.
  2. toJsonString(JsonMessage[]) -- convert array of JsonMessages into one single string. All messages in the array will be converted into single JSON message.
  3. toJsonString(JsonMessage) -- just conver JsonMessage into JSON message.
  4. sendJsonMessage(Player, String) -- send the converted JSON messaged to the target player. Or you can create your own JSON message if you want to.
  5. getSuffixes(Player) -- get Suffix for player. You can add your own suffix with your custom JSON messages. Unfortunately, you cannot change the order of the prefixes. This is the reference to the actual Prefix Map, so do anything that you can think of.
  6. getPrefixes(Player) -- get Prefix for player. Similar to getSuffix().
Examples:

Spoiler: Creating Json Message
Using JsonMessagePlain class, you can easily make the JSON message.
Code (Text):
        JsonMessagePlain playerInfo = new JsonMessagePlain(e.getPlayer().getName());
        playerInfo.setClickEvent(new JsonMessageClickEvent(ClickAction.suggest_command, "/w "+e.getPlayer().getName()+" "));
        playerInfo.setHoverEvent(new JsonMessageHoverEvent(HoverAction.show_text, new String[]{user.toString()}));
This is very basic example.

First, you instanciate the JsonMessagePlain class and give a String parameter. This parameter is the actually message you want.

Then you can access the methods of JsonMessagePlain to create any awesome stuff in your mind.

Spoiler: Creating JSON Message with more than one JSON Message
it's really up to you to how to utilize this, but I will give you my example
Code (Text):
        List<JsonMessage> list = new ArrayList<JsonMessage>();
        //build prefixes first
        for(JsonMessage[] prefixes : user.getPrefixes().values()){
            for(JsonMessage msg : prefixes) list.add(msg);
        }
        list.add(new JsonMessagePlain(split[0]));
        list.add(playerInfo);
        for(JsonMessage[] suffixes : user.getSuffixes().values()){
            for(JsonMessage msg : suffixes) list.add(msg);
        }
        list.add(new JsonMessagePlain(split[1]));
        for(String str : e.getMessage().split(" ")){
            if(str.contains("http://") || str.contains("https://")){
                JsonMessagePlain msg = new JsonMessagePlain(str+" ");
                msg.setClickEvent(new JsonMessageClickEvent(ClickAction.open_url, str));
                msg.setHoverEvent(new JsonMessageHoverEvent(HoverAction.show_text,
                        ChatLib.getLang().parseFirstString(Languages.HoverMesssage_Url_Warning)));
                list.add(msg);
            }else{
                list.add(new JsonMessagePlain(str+" "));
            }
        }
        String json = ChatLibAPI.toJsonString(list.toArray(new JsonMessagePlain[list.size()]));
pretty simple. You create the ArrayList of JsonMessage, and just insert the JSON message in order.

when you are done, you can convert it into one JSON message by using toJsonString(JsonMessage[]) in the API. It will return the JSON message combined.

Spoiler: Sending JSON Message
use sendJsonMessage(Player, String) method in API. Fairly simple.

Spoiler: Modifying Player Info Section
[​IMG]

This is called Info Section, and you can obtain it by getInfo(Player) method.

the method will return Map<String, Object>, and this Map will add any other information after the [Click to whisper] part.

the key will be the left part, and the value will be the right part. if you have noticed, the value is an Object, so you can pass your own object, but obviously you have to override the toString() method (that's what is used for the right part).

Spoiler: Adding prefixes and suffixes
[​IMG]

This is the example of prefix. The suffix will be inserted between the name and the another suffixes(like ranks).

Similar thing is happening as player Info Section.

Commands

Plugin details

Read from the plugin's own plugin.yml.

Quick facts

Install steps are the general flow for this file type — How to install Minecraft Java mods & modpacks walks through it step by step.

ChatLib is a free Minecraft Java mod. Compatible with Minecraft 1.9, 1.10, 1.11. Downloaded 5,745 times (via Spigot). Download it and open it directly in the game.

Explore more