Skip to content

Adding your leaderboards

AlonsoAliaga edited this page Feb 27, 2023 · 2 revisions

Adding your leaderboards

This is only for developers.
This is only for developers.
This is only for developers.
This is only for developers.
This is only for developers.
This is only for developers.

To add leaderboard from your plugin import our jar to your project.

We don't support maven/gradle at this moment.
You'll have to use jar dependency to import jar.

Steps to provide statistics to AlonsoLeaderboards

1) Create a class that extends LeaderboardExpansion.

Find the class from the next package

com.alonsoaliaga.alonsoleaderboards.api.LeaderboardExpansion

2) Create constructor matching super

We have 2 constructors available.
Constructors

  1. Used for leaderboards with numbers as score.
  • This requires a hashmap with String as key and Number as value.
    Key must be playername and value must be player score for leaderboard.
    🔰 AlonsoLeaderboards will order provided data when using this constructor based on values
  1. Used for leaderboards with strings as score.
  • This requires a treemap with String as key and map entry of String as key and String as value.
    Key must be rank index starting from 1, key entry must be playername and value must be player score for leaderboard.
    AlonsoLeaderboards will not order provided data when using this constructor.
package com.alonsoaliaga.exampleplugin;

import com.alonsoaliaga.alonsoleaderboards.api.LeaderboardExpansion;
import com.alonsoaliaga.alonsoleaderboards.enums.OrderType;
import org.bukkit.Location;
import org.bukkit.plugin.java.JavaPlugin;

import javax.annotation.Nonnull;
import java.util.HashMap;
import java.util.List;

public class LeaderboardExample extends LeaderboardExpansion {
    public LeaderboardExample(@Nonnull JavaPlugin javaPlugin, @Nonnull String leaderboardIdentifier, @Nonnull HashMap<String, ? extends Number> data, 
                              @Nonnull OrderType orderType, @Nonnull List<String> lines, @Nonnull List<String> emptyLines, @Nonnull String entryAvailable, 
                              @Nonnull String noDataAvailable, @Nonnull String noNameAvailable, @Nonnull String noScoreAvailable,
                              int firstUpdateDelay, int updateInterval) {
        super(javaPlugin, leaderboardIdentifier, data, orderType, lines, emptyLines, entryAvailable, noDataAvailable,
                noNameAvailable, noScoreAvailable, firstUpdateDelay, updateInterval);
    }

    @Override
    public void playEffect(Location location) {

    }
}

I know, it might look complex, but you'll see it's really simple.

We can choose now how to pass parameters.
We can make it configurable from our own plugin so players can edit it or you can hard code them.

For this example we will hardcode everything.\

package com.alonsoaliaga.exampleplugin;

import com.alonsoaliaga.alonsoleaderboards.api.LeaderboardExpansion;
import com.alonsoaliaga.alonsoleaderboards.enums.OrderType;
import org.bukkit.Effect;
import org.bukkit.Location;
import org.bukkit.plugin.java.JavaPlugin;

import javax.annotation.Nonnull;
import java.util.Arrays;
import java.util.HashMap;

public class LeaderboardExample extends LeaderboardExpansion {
    public LeaderboardExample(@Nonnull JavaPlugin javaPlugin, @Nonnull HashMap<String, ? extends Number> data) {
        super(javaPlugin, "myplugin-score", data, OrderType.DESCENDING,
                Arrays.asList("§c--§e #{RANKING} §c--","§f{PLAYER}","§b{SCORE}","§c-------------"),
                Arrays.asList("§c--§e #{RANKING} §c--","§cNo player","§bUnknown","§c-------------"),
                "§e{RANKING}. &§{PLAYER} §7- §e{SCORE}", "§7No data available", "§7Unknown", "§7Unknown",
                3, 10);
        register(); //We register the leaderboard expansion
    }
    @Override
    public void playEffect(Location location) {
        location.getWorld().playEffect(location, Effect.MOBSPAWNER_FLAMES,50);
    }
}

We also added a cool effect in the location where sign is updated.
You can do whatever you want there, we provide the location of the sign 😃

⚠️ Don't forget to call register() method to register your leaderboard!

We need to initialize the class now providing the correct parameters!

If we initialize the class in our main class we can simply use

    @Override
    public void onEnable(){
        //This is an example, you can do this in any other class.
        
        HashMap<String,Integer> dataMap = new HashMap<>();
        //We need to modify data from dataMap with our statistics.
        //AlonsoLeaderboards saves a reference to this map so modifying dataMap directly affects statistics.
        //This was made so you don't need to submit updates for changes.
        //Just update the original dataMap.
        
        dataMap.put("AlonsoAliaga",200); //Example, use your own values.
        dataMap.put("JustOneSoup",950); //Example, use your own values.
        dataMap.put("RevelationCraft",10); //Example, use your own values.
        
        new LeaderboardExample(this,dataMap); //We create a new instance. Make sure you DON'T create more than one instance.
    }


Congratulations! Your plugin is now providing statistics to AlonsoLeaderboards!

You should be able to create leaderboards now!
Follow this guide to use and test your leaderboards.