Accessing the API

Since 1.0.0

The easier way to access the MCUtils API is to extend MCPlugin instead of JavaPlugin on your main class, functionality remains the same but doing this provides easy access to all of MCUtils features directly from your main class, here is an example.

import net.codersky.mcutils.MCPlugin;

public class TestPlugin extends MCPlugin {

    @Override
    public void onEnable() {
        logCol("&aPlugin enabled using &eMCUtils&a!");
    }

    @Override
    public void onDisable() {
        logCol("&cPlugin disabled&8.");
    }
}

Once your plugin is extending the MCPlugin class, you can register commands, events, files, GUIs and so on directly from your main plugin class. As a first step we are going to check if the server is on 1.12 or higher, you can obviously use whatever version is the lowest that your plugin supports.

import net.codersky.mcutils.MCPlugin;

public class TestPlugin extends MCPlugin {

    @Override
    public void onEnable() {
        if (!serverSupports("1.12")) {
            // Server doesn't support 1.12, we should disable the plugin here. 
        }
        // Server is using 1.12 or higher, we can continue...
        String version = getServerVersion();
        logCol("&aPlugin enabled for your &e" + version + " &aserver!");
    }

    @Override
    public void onDisable() {
        logCol("&cPlugin disabled&8.");
    }
}

Note that both methods used here are static, this is because some classes may benefit from this methods by changing behaviour depending on server version but may not want to store an instance of the plugin for this one purpose only. Don't get used to static methods on MCUtils though, these are pretty much the only two, excluding of course utility only classes such as MCStrings, MCLists and MCNumbers.

Last updated