Skip to content
Plajer edited this page Aug 16, 2018 · 11 revisions

Developer API

Table of contents

❗️ Contents may be not up to date! Please use java docs instead. Here you can only get some simple examples.

Events

Event name [since] [extra attributes]


BBEvent (Generic)

The event is called everytime any Build Battle event is called because it's a generic event.

Example:

    @EventHandler
    public void onEventCall(BBEvent event){
        if(event instanceof BBGameChangeStateEvent){
            Bukkit.getConsoleSender().sendMessage("BBGameChangeStateEvent was called!");
        }
    }

event#getArena() - returns event arena for which event was called


BBGameJoinEvent (Cancellable)

The event is called when a player is trying to join an arena.

Example:

    @EventHandler
    public void onGameJoin(BBGameJoinEvent event){
        event.getPlayer().sendMessage("You have joined " + event.getArena().getID());
        event.setCancelled(true);
        event.getPlayer().sendMessage("Or maybe not? :D");
    }

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

event#getArena() - returns existing arena where player is attempting to join


BBGameStartEvent

The event is called when the arena starts.

Example:

    @EventHandler
    public void onGameStart(BBGameStartEvent event){
        for(Player p : event.getArena().getPlayers()){
            p.sendMessage("Game has started!");
        }
    }

event#getArena() - returns event arena


BBGameLeaveEvent

The event is called when a player is trying to leave an arena.

Example:

    @EventHandler
    public void onGameQuit(BBGameLeaveEvent event){
        event.getPlayer().sendMessage("You have quitted" + e.getArena().getID());
    }

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

event#getArena() - returns existing arena what player is attempting to leave


BBGameEndEvent

The event is called when a game has ended.

Example:

    @EventHandler
    public void onGameStop(BBGameStartEvent event){
        for(Player p : event.getArena().getPlayers()){
            p.sendMessage("Cool game? Maybe play again?");
        }
    }

event#getArena() - returns existing arena that is stopped


BBGameStateChangeEvent

The event is called when a game arena state has changed.

Example:

    @EventHandler
    public void onGameStop(BBGameStateChangeEvent event){
        ArenaState prev = event.getPreviousState();
        ArenaState curr = event.getState();
        for(Player p : event.getArena().getPlayers()){
            p.sendMessage("Game state changed from " + prev.getFormattedName() + " to " + curr.getFormattedName());
        }
    }

event.getPreviousState() - returns arena state before change

event.getState() - returns current arena state

event#getArena() - returns existing arena that is stopped


Stats storage

Table of contents

Retrieving online players stats

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

Example:

    public int getWins(Player p){
        return StatsStorage.getUserStats(p, StatsStorage.StatisticType.WINS);
    }

Very easy, right?


Requesting sorted statistics of all players

To access sorted statistics hMap 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]));
        }
    }

❗️ Be aware of IndexOutOfBoundsException as the list might be not enough big


Available statistic types

Statistic name (enum) Statistic identifier (string) (for advanced things) Type
BLOCKS_BROKEN blocksbroken int
BLOCKS_PLACED blocksplaced int
GAMES_PLAYED gamesplayed int
WINS wins int
LOSES loses int
HIGHEST_WIN highestwin int
PARTICLES_USED particles int