Skip to content

Developers API

Berke Akçen edited this page Apr 14, 2023 · 5 revisions

Table of contents

Maven Repository

Maven repository usually contains latest releases, if not, please check in few days if
release is there.

How to accsess repo:
  1. Add repository
    <repositories>
        <repository>
            <id>jitpack.io</id>
            <url>https://jitpack.io</url>
        </repository>
    </repositories>
  1. Add the dependency
    <dependencies>
        <dependency>
            <groupId>com.github.Despical</groupId>
            <artifactId>OITC</artifactId>
            <version>2.2.9</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>

Events

Event name [since] [extra attributes]

OITCGameJoinEvent (Cancellable)

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

Example:

  @EventHandler
  public void onGameJoin(OITCGameJoinAttemptEvent 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 arena player is playing (player is always in arena when this event is called)

OITCGameStartEvent

The event is called when the arena starts.

Example:

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

event#getArena() - returns event arena

OITCGameLeaveAttemptEvent

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

Example:

  @EventHandler
  public void onGameQuit(OITCGameLeaveAttemptEvent 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

OITCGameStopEvent

The event is called when a game has ended.

Example:

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

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

OITCGameStateChangeEvent

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

Example:

  @EventHandler
  public void onGameStateChange(OITCGameStateChangeEvent event){
    ArenaState previous = event.getArena().getArenaState();
    ArenaState current = event.getArenaState();
    for(Player p : event.getArena().getPlayers()){
      p.sendMessage("Game state changed from " + previous.getFormattedName() + " to " + current.getFormattedName());
    }
  }

OITCPlayerStatisticChangeEvent

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

Example:

    @EventHandler
    public void onStatChange(OITCPlayerStatisticChangeEvent 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 OITC 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 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
KILLS kills true Kills
amount
DEATHS deaths true Deaths
amount
GAMES_PLAYED gamesplayed true Total games
played
HIGHEST_SCORE highestscore true Highest kills
in-game
WINS wins true Wins
amount
LOSES loses true Loses
amount
LOCAL_KILLS local_kills false In-game current
kills amount
LOCAL_DEATHS local_deaths false In-game current
deaths amount
LOCAL_KILL_STREAK local_kill_streak false In-Game current
killstreak amount

Manipulating player join/leave
attempts

Join attempt

To force player to join specified arena you can use our ArenaManager class.

  public void sendPlayerToArena(String arena, Player player){
    ArenaManager.joinAttempt(player, ArenaRegistry.getArena(arena));
  }

// or

  public void sendPlayerToArena(Arena arena, Player player){
    ArenaManager.joinAttempt(player, arena);
  }

Imgur
After that you can check for #isCancelled() if join attempt was cancelled or
not.

Leave attempt

You can also use ArenaManager class to force player to quit arena.

  public void forcePlayerQuit(Player player){
    Arena arena = ArenaRegistry.getArena(player);
    ArenaManager.leaveAttempt(player, arena);
  }

Imgur