Custom Objectives

This guide will explain how to add your very own objective to XLTournaments.

Creating a custom objective is a fairly straight forward process. First of all, ensure you have the API dependency loaded into your project and set it as a depend in your plugin.yml file.


Create your objective class that extends XLObjective. In this example, I will create a class called PlaceObjective which will track block placement:

public class PlaceObjective extends XLObjective {
}

You will need to create a constructor matching the super class. Your IDE may prompt you to do so. Inside the super(...); you will add your objective identifier. In this case, it's called "BLOCK_PLACE" and you'd use this in the tournament configuration.

public class PlaceObjective extends XLObjective {

    public PlaceObjective() {
        super("BLOCK_PLACE");
    }
    
}

Next we'll need to add the loadTournament method, this will allow you to load any objective exclusive settings from each tournament configuration file:

public class PlaceObjective extends XLObjective {

    public PlaceObjective() {
        super("BLOCK_PLACE");
    }
    
    @Override
    public boolean loadTournament(FileConfiguration config) {
        // Load optional or required values from config
        
        // Return true if successful load, otherwise false and the tournament being loaded will be disabled
        return true;
    }
    
}

Finally, we add our event listener (and method contents) to track block placement:

We need to get all active tournaments which use the block place objective and using the canExecute method we if the user is a participant and has finished the challenge (if applicable) and if they are in a disabled world. We can then add the score directly to the tournament passing the UUID of the player and the amount of points to add. We add 1 point in this example as this is represents one block broken.

Register the objective

Now we simply need to register the objective as shown below.

If your objective requires an external plugin (we will check if the plugin is enabled) then use:

Last updated