// via a player
Player player = ...;
Arena arena = GameAPI.get().getArenaByPlayer(player); // is null when player is a spectator and not inside the match
Arena arena = BedwarsAPI.getGameAPI().getArenaByPlayer(player); // exact same thing as line above
if(arena != null){
player.sendMessage("Hi, you're currently playing inside " + arena.getDisplayName());
}else{
// not inside an arena :/
}
// via a spectator
Player spectator = ...;
Arena arena = GameAPI.get().getArenaBySpectator(spectator);
// via a location
Location location = ...;
Arena arena = GameAPI.get().getArenaByLocation(location);
// by its name
String name1 = "Sandstorm";
String name2 = "sandstorm";
String arenaPicker = "%best%";
Arena arena = GameAPI.get().getArenaByName(name1);
Arena arena = GameAPI.get().getArenaByName(name2); // getByName is not as aggressive as getByExactName
Arena arena = GameAPI.get().getArenaByName(arenaPicker); // even allows the usage of arena pickers
Arena arena = GameAPI..get().getArenaByExactName(name1); // this one doesn't tho...
// get all arenas
for(Arena arena:GameAPI.get().getArenas()){
}
It works exactly the same as if you'd want to listen for Bukkit's events.
public class MyClass extends JavaPlugin implements Listener {
@Override
public void onEnable(){
Bukkit.getPluginManager().registerEvents(this, this);
}
@EventHandler
public void onPlayerJoinArena(PlayerJoinArenaEvent event){
event.getPlayer().sendMessage("Hey, how are you doing?");
}
}
Player player = ...;
PlayerDataAPI.get().getStats(player, stats -> {
// The PlayerStats object is basically a map with a String as its key and a Number as its value
// It contains all the info that shall be stored permanently, such as the amount of wons, loses, kills, etc.
// The exact keys of these entries isn't directly accessible, as this is being handled by a PlayerStatSets.
// A PlayerStatSet is basically a registerable entry in /bw stats. It has a name and it will return a value when asked for it.
// There's a PlayerStatSet for each type, like the rank, wons, loses, w/l etc.
// You could create your own /bw stats the following way
for(PlayerStatSet set:PlayerDataAPI.get().getRegisteredStatSets()){
player.sendMessage(set.getName() + ": " + set.getDisplayValue(stats));
}
// Would you like to change the value of a PlayerStatSet?
DefaultPlayerStatSet.KILLS.addValue(stats, 1); // increments the amount of kills by 1
});
Internally, all all informations of stat simply get stored in a Map, with the key being a String and the value a number. You may directly access them all using the PlayerStats object. However, this Map is only used for storing them. For displaying them in e.g. /bw stats, we've added something called stat sets. For each type (such as kills, wins, k/d, play time, rank, etc.) there's one instance that handles the way of how it shall be displayed and how it shall be displayed, as you for instance don't need to store a k/d. We're creating our own stat set, that gets displayed in /bw stats, with the following example:
ExampleStatSet.java:
public class ExampleStatSet implements PlayerStatSet {
private static final String STORAGE_KEY = "example_bed_breaks_count";
private final Plugin plugin;
public ExampleStatSet(Plugin plugin) {
this.plugin = plugin;
}
@Override
public String getId() {
return "example_bed_breaks";
}
@Override
public Plugin getPlugin() {
return this.plugin;
}
@Override
public String getName(@Nullable CommandSender sender) {
return "Bed Breaks";
}
@Override
public String getDisplayedValue(PlayerStats stats) {
return formatInt/* Helper included in PlayerStatSet */(getValue(stats));
}
@Override
public Number getValue(PlayerStats stats) {
return stats.get(STORAGE_KEY);
}
////////////
// All the following methods are OPTIONAL. It's not a must to implement them, as it's sometimes not possible, such as for ranks.
@Override
public void setValue(PlayerStats stats, Number value) {
stats.set(STORAGE_KEY, value);
}
@Override
public void addValue(PlayerStats stats, Number amount){
stats.add(STORAGE_KEY, amount);
}
}
Within your main class:
@Override
public void onEnable() {
PlayerDataAPI.get().registerStatSet(new ExampleStatSet(this));
}
ExampleLobbyItemHandler.class:
public class ExampleLobbyItemHandler extends LobbyItemHandler {
public ExampleLobbyItemHandler(Plugin plugin) {
super("example" /* the id which will be specified in the configs */, plugin);
}
@Override
public void handleUse(Player player, Arena arena, LobbyItem item) {
// what shall happen when it's being used
player.sendMessage("Hello World");
}
@Override
public boolean isVisible(Player player, Arena arena, LobbyItem item) {
// in which cases it should be visible
return true;
// an other example:
// return player.hasPermission("xyz");
// player requires a specific permission to see the item
}
}
Within your main class:
@Override
public void onEnable() {
GameAPI.get().registerLobbyItemHandler(new ExampleLobbyItemHandler(this));
}
Within your lobby.cm2 file:
My Super Cool item {
material: dirt
slot: 3
special: example
}