Skip to content
WesJD edited this page Mar 19, 2016 · 13 revisions

Note: For obvious reasons, the plugin NetworkUtilities must be running on your server for this to work. As a result, you do not need to compile your plugin with NU included. This will break Bukkit!

Making a Network Utilities Plugin

To begin your plugin, setup a basic Bukkit project. Ensure your Main class extends JavaPlugin and Bukkit is in your classpath. Remember to "depend: [NetworkUtilities]" in your plugin.yml Also, don't forget your onEnable method. It'll look a little bit like this:

public class Test extends JavaPlugin {

    public void onEnable(){

    }
}

Next, add Network Utilities to your classpath. You can find the latest download on my website.

Let's start really simple. To send a message through the Library, use the following:

NetworkUtilities.log("YOUR MESSAGE");

This will output the message specified to the console via the library.

Commands

The NetworkUtilities command system is super easy too! Let's say we want to make a "/feed" command. Firstly, we need to get the CommandManager

CommandManager manager = NetworkUtilities.getCommandManager();

We also need to tell the manager to check our object for commands. Do this with the following:

manager.registerCommands(this);

You could use any class here. In future, I'd suggest making an individual commands class.

Now, we just need to make the command.

@Command(label= "feed")
public void feed(Player player, List<String> args){
    player.setFoodLevel(20);
}

The method name (feed) is completely unfixed. Set it to anything, and the performance of the plugin won't alter. For the command to be valid, you'll need the @Command annotation. The (command = "feed") section is where the manager looks to find the actual command name.

If you'd like to set a permission for this command, that's easy too! Just use the following:

@Command(label = "feed", permission = "hello.world.permission")

If you'd like to set a priority for this command, that's also quite easy! (Higher priority methods will be called first) Just use the following:

@Command(label = "feed", permission = "hello.world.permission", priority = 2)

Aliases are very simple to add. Just call: manager.addAlias("newcommand", "oldcommand");

Serialization

Serialization of Bukkit objects is very easy with NetworkUtilities. Simply call the following on an object (we'll use a null location, just for the sake of this example):

Location loc = null;
String locString = LocationSerialization.serializeLocationAsString(loc);

To gain the location back from locString:

Location newLocation = LocationSerialization.getLocationMeta(locString);

Saving Bukkit objects really is this easy! You can use this system with Books, ItemStacks, Inventories and even player stats!

The Serialization system is a fork of the TacoSerialization System

The all new MessageAPI

Messaging has always been clunky, and generally each plugin handles the system a different way. NetworkUtilities version 1.1 implements a new system for the fast development of Messaging systems.

To send a basic message, first, create a message object:

Message m = new Message(Message.INFO)

Message.INFO is simply a predefined String, for the prefix. You can also use Message.BLANK (equivalent to ""), or your own String. Use %m to indicate where the message will appear, and %p to show the recipient's name.

Now, add recipients:

m.addRecipient(Player)

Finally, send the message:

m.send("This is a NetworkUtilities message")

What makes the Messaging system unique is the ability to add MessageDisplay enums. The following are valid enum states: ACTIONBAR, TITLE, SUBTITLE, and CHAT. Following this system, you can very easily craft TITLE's, SUBTITLE's and ACTIONBAR messages without ever touching Minecraft packets.

Game API

Click on the sidebar to the right to see more about the GameAPI. It's amazing!

https://github.com/olivervscreeper/NetworkUtilities/wiki/The-GameAPI