· 6 years ago · Nov 15, 2019, 04:38 PM
1API
2
3This is my first API ever, if you are confused about something feel free to pm me
4
5Don't forget to check if SurvivalGames is installed before taking any action!
6
7Code (Text):
8package me.wazup.apitest;
9
10import java.sql.SQLException;
11import java.util.List;
12import java.util.Map.Entry;
13
14import org.bukkit.Bukkit;
15import org.bukkit.command.Command;
16import org.bukkit.command.CommandSender;
17import org.bukkit.entity.Player;
18import org.bukkit.plugin.java.JavaPlugin;
19
20import me.wazup.survivalgames.PlayerData;
21import me.wazup.survivalgames.SurvivalGamesAPI;
22import me.wazup.survivalgames.SurvivalGamesAPI.StatType;
23
24public class Main extends JavaPlugin {
25
26public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
27
28if(commandLabel.equalsIgnoreCase("test")){
29if(sender instanceof Player){
30Player p = (Player) sender;
31
32//This is used to get the player data, which gives you access to view the player stats
33PlayerData data = SurvivalGamesAPI.getStats(p);
34sender.sendMessage("Your SurvivalGames playtime is " + data.getPlayTime());
35
36
37
38//This method gets the top players from survivalgames data base
39//In this example, 10 is the amount of top players we want to get, the amount must be above 0 otherwise the plugin will throw an error.
40//The method returns a list of entries of <String, Integer>
41//The key is the player name, and the value is their score.
42
43try {
44List<Entry<String, Integer>> top = SurvivalGamesAPI.getTopPlayers(StatType.Coins, 10);
45
46for(int i = 0; i < 10; i++){
47Bukkit.broadcastMessage("Number " + (i+1) + " is the player " + top.get(i).getKey() + " with a score of " + top.get(i).getValue());
48}
49
50} catch (SQLException e) {
51e.printStackTrace();
52}
53
54
55} else {
56sender.sendMessage("You must be a player to execute this command!");
57}
58}
59
60return false;
61}
62
63}
64
65=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-