Skip to content

Developers API

Berke Akçen edited this page Jun 27, 2021 · 27 revisions

Table of contents

Documentation

More information can be found on the wiki page. The Javadoc can be browsed. Questions related to the usage of King of the Ladder should be posted on my Discord server.

Using King of the Ladder API

The project isn't in the Central Repository yet, so specifying a repository is needed.
To add this project as a dependency to your project, add the following to your pom.xml:

Maven dependency

<repository>
    <id>jitpack.io</id>
    <url>https://jitpack.io</url>
</repository>
<dependency>
    <groupId>com.github.Despical</groupId>
    <artifactId>KOTL</artifactId>
    <version>1.2.1</version>
    <scope>compile</scope>
</dependency>

Gradle dependency

repositories {
    maven { url 'https://jitpack.io' }
}
dependencies {
    compileOnly group: "com.github.Despical", name: "KOTL", version: "1.2.1";
}

Events

KOTLPlayerStatisticChangeEvent

The event is called when the player receives a new statistic.

Example:

    @EventHandler
    public void onStatChange(KOTLPlayerStatisticChangeEvent event){
        StatisticType stat = e.getStatisticType();
        int statNumber = e.getNumber();
        e.getPlayer().sendMessage("Your statistic " + stat.getName() + " has changed to " + statNumber);
    }

event#getPlayer() - returns player involved in this event

event#getArena() - returns arena player is playing (player is always in arena when this event is called)

event#getStatisticType() - returns statistic of StatsStorage.StatisticType enum

event#getNumber() - returns current value of statistic

Stats Storage

Table of contents

Retrieving online players stats

You can easily get online players stats using KOTL API - Stats Storage class.

Example:

    public int getScore(Player p){
        return StatsStorage.getUserStats(p, StatsStorage.StatisticType.SCORE);
    }

Very easy, right?

Requesting sorted statistics of all players

To access sorted statistics HashMap with players you must call it from StatsStorage
class.

Example:

    public void printBestStats(StatsStorage.StatisticType statistic){
        Map<UUID, Integer> statsMap = StatsStorage.getStats(statistic);
        UUID[] uuidsArray = (UUID[]) StatsStorage.getStats(statistic).keySet().toArray();
        for (int i = 0; i < 10; i++){
            Bukkit.broadcastMessage("#" + i + " UUID: " + uuidsArray[i] + ", stats: " + statsMap.get(uuidsArray[i]));
        }
    }

Imgur

Available statistic types

Statistic name (enum) Statistic identifier
(string) (for
advanced things)
Persistent Description
TOURS_PLAYED toursplayed true Played tours
amounts
SCORE score true Total score
amount
Clone this wiki locally