api/Create your own text modifiers (1.8+)

Attention: This is for the 1.8 update and will not work with earlier versions


Over here we will explain how you can add your own text converters for ServerCaster.

We will first show you the file and then try to explain what everything does.


In the next program we will show you how to create a plugin that adds warp as a code to the ServerCaster.
http://i.minus.com/itWCaj7Pe0dpQ.png
Your converter

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import me.servercaster.core.converter.CodeAction;

/**
 *
 * @author Patrick Beuks (killje) and Floris Huizinga (Flexo013)
 */
public class WarpAction extends CodeAction {

    public WarpAction() {
        super(1); //amount of arguments this converter needs
    }

    @Override
    protected String getKeyword() {
        return "WARP";
    }

    @Override
    public void doAction(String argument) {
        getJSONSaver().command("/warp " + argument);
    }

}

On line 7 you see us extending from CodeAction. This class does the most work for you. The two override-able functions you see here came from that class and you need to do something with them.
On line 10 you see a super with a number. This number indicates how many arguments this converter takes. Zero arguments is possible.
On line 14 and 15 you see the keyword for which the program will look for inside the ServerCaster messages. (All keywords are case independent here and in the ServerCaster messages)
On line 19 you see the doAction function. This function is called with an argument from the { } from ServerCaster messages. If you said that your class does not use arguments it will give a string back that is the same as the keyWord found.
On line 20 you see the use of getJSONSaver(). This function gives back the object FancyMessage (the library we use to convert a string to a JSON message). In this object you can add everything that is used within a minecraft JSON string.
http://i.minus.com/itWCaj7Pe0dpQ.png
Your main java plugin class

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
import me.servercaster.core.ServerCaster;
import org.bukkit.plugin.java.JavaPlugin;

/**
 *
 * @author Patrick Beuks (killje) and Floris Huizinga (Flexo013)
 */
public class AddWarp {

    public AddWarp(JavaPlugin instance) {
        ServerCaster.addAction(instance, new WarpAction());
    }
}

On line 11 you see how to add your CodeAction to the database of ServerCaster.
http://i.minus.com/itWCaj7Pe0dpQ.png
In you plugin.yml you also need to add the dependency of ServerCaster with:

depend: ServerCaster

http://i.minus.com/itWCaj7Pe0dpQ.png
Now the last thing to do is to use the code you added to a broadcast with the example above you cold do something like:

- 'our warps: &WARP;{spawn}{Spawn} &WARP{city}{City} &WARP;{pvp}{PVP Arena}'

And it will automatically convert all commands to warps with the displayed text.


Tips and Tricks

The doAction is called in two different places depending how many arguments you filled in inside the super(int);

  • When you filled in 0, doAction is called as soon as it discovered the keyWord.
  • when you filled in 1+, doAction is called when it has gone through a complete set of brackets.

The special codes are not only useful for adding things to the JSON string, but it gives your plugin a chance to perform an action. This can, for example, be a sound that is played to all players when a broadcast is executed. Do note that if you use it this way you still need a (empty) brackets after the code


Comments

Posts Quoted:
Reply
Clear All Quotes