Skip to content
William edited this page Dec 27, 2024 · 2 revisions

Creating An Extender

The BanPluginExtender interface uses generics, so you must first get some sort of Punishment object ready.

Some APIs provide one for you (such as AdvancedBan, you can see their Punishment class here).

If not, you will have to make one.

public class Punishment {

    private String targetName, executorName;
    // Etc...
}

Once you have one, you can make an extender:

public class ExampleExtender implements BanPluginExtender<Punishment> {
    @Override
    public List<CustomEntry> getHistory(UUID uuid) {
        /*
        As this is not a punishment plugin, I will just return a list of 10 CustomEntries.
        You will need to replace this with your own implementation with however you retrieve your player's punishment history.
         */
        List<CustomEntry> entries = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            entries.add(
                    /*
                    Use the createEntry method which is defined below.
                    Make sure to use the CUSTOM entry source!
                     */
                    createEntry(new ExampleObject(), CustomEntry.EntrySource.CUSTOM)
            );
        }
        return entries;
    }

    @Override
    public CustomEntry createEntry(Punishment punishment, CustomEntry.EntrySource entrySource) {
        /*
         You use the Punishment object (in this case Punishment) to get the data.
         You will need to pass this data to the CustomEntry constructor.

         In the example below I haven't used the Punishment object because I'm lazy. Instead, I've used random test data.
         */
        return new CustomEntry(
                1L,
                "ban",
                "testUiD",
                null,
                "cheating",
                null,
                "hey",
                null,
                null,
                null,
                100L,
                200L,
                null, null, false, false, false, 10L, entrySource
        );
    }
}

Registering your extender

Once you've created your extender, you must register it. Otherwise, HistoryX will default to searching for a punishment plugin loaded in your server.

You must register your extender in the #onLoad method of your plugin.

    /*
    You MUST set the extender in the onLoad method! Not in the onEnable method.
     */
    @Override
    public void onLoad() {
        HistoryX.getAPI().setExtender(new ExampleExtender());
    }

And that's it! Pretty simple. Build your plugin, drag and drop into your plugins folder, and make sure you have HistoryX installed.

Support

Having some trouble? Join our official Discord for support.

Clone this wiki locally