# Custom Objectives

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:

```java
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.

```java
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:

```java
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:

{% hint style="warning" %}
You do **not** need to register the events in this class as this is done by XLT internally in the super class.
{% endhint %}

```java
public class PlaceObjective extends XLObjective {

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

    @EventHandler(priority = EventPriority.HIGH)
    public void onBlockPlace(BlockPlaceEvent event) {
        Player player = event.getPlayer();
        
        for(Tournament tournament : getTournaments()) {
            if(canExecute(tournament, player)) {
                tournament.addScore(player.getUniqueId(), 1);
            }
        }
    }

}
```

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.

```java
// Accessing the API
XLTournamentsAPI api = (XLTournamentsAPI) Bukkit.getPluginManager().getPlugin("XLTournaments");

// Register (internal) objective
api.registerObjective(new PlaceObjective());
```

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

```java
// Register objective requiring an external dependency
api.registerObjective(new PlaceObjective(), "RequiredPlugin");
```

{% hint style="danger" %}
Make sure XLTournaments has been added as a depend in your `plugin.yml` to ensure it loads correctly.
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.zithium.net/xl-series/xltournaments/developer-api/custom-objectives.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
