Skip to content
MathiasMC edited this page Dec 10, 2020 · 47 revisions

Getting the instance

You can get the api by using

PvPLevelsAPI api = PvPLevelsAPI.getInstance();

Methods

All methods

api.getPlayerConnect(uuid); # Returns a PlayerConnect and create one if no one found

Will save before removing or updating
api.unloadPlayerConnect(uuid); # Remove a PlayerConnect and PvPlevels will create a new one from the database, when requesting
api.updatePlayerConnect(uuid); # Remove and create new cached PlayerConnect with data from database.

api.removePlayerConnect(uuid); # Remove PlayerConnect from cache without save

api.deletePlayerConnect(uuid); # Deleting the data from the database and unload everything about this player.

api.listPlayerConnect(); # List of PlayerConnect

Managers:
api.getFileUtils(); # File Utils
api.getXPManager(); # XP Manager
api.getActionBarManager(); # ActionBar Manager
api.getKillSessionManager(); # KillSession Manager
api.getStatsManager(); # Stats Manager get stats with PlayerConnect
api.getPlaceholderManager(); # Placeholder Manager
api.getCalculateManager(); # Calculate Manager

api.getStartLevel(); # Returns start level

api.isDebug(); # Returns boolean (if debug enabled)

api.setDebug(boolean);

api.getVersion(); # Returns version of PvPLevels

api.unregisterAll(); # Unregister all events except required Level System Listeners

api.unregisterPlayerJoin(); # Unregister PlayerJoin Listener (used by starting multiplier again)

api.unregisterEntityDeath(); # Unregister EntityDeath Listener (used by the system to get and lose stats)

api.unregisterEntityDamageByEntity(); # Unregister EntityDamageByEntity Listener (used to keep track of hit entity (if thrown in void))

api.unregisterCreatureSpawn(); # Unregister CreatureSpawn Listener (used by spawners section in config.yml)

api.unregisterBlockBreak(); # Unregister BlockBreak Listener (used by get xp from blocks feature)

api.unregisterBlockPlace(); # Unregister BlockPlace Listener (used by get xp from blocks feature (fix duplicate xp by place and break block))

api.unregisterPlayerMove(); # Unregister PlayerMove Listener (used by instant death feature)

PlayerConnect

This class holds all information about the player and can be created or get by using

PlayerConnect playerConnect = PvPLevelsAPI.getInstance().getPlayerConnect(uuid);

getGroup();
getKills();
getDeaths();
getXp();
getLevel();
getKillstreak();
getKillstreakTop();
getMultiplier();
getMultiplierTime();
getMultiplierTimeLeft();
getTime();
getXpType();
getXpLast();
getXpLost();
getXpItem();
getSave();

setGroup(String);
setKills(long);
setDeaths(long);
setXp(long);
setLevel(long);
setKillstreak(long);
setKillstreakTop(long);
setMultiplier(double);
setMultiplierTime(long);
setMultiplierTimeLeft(long);
setTime();
setSave(long);
setXpType(String);
setXpLast(long);
setXpLost(long);
setXpItem(long);
save();

Events

Every event created you must use the execute(); to execute the event (dont do that if you listen on the event)

PlayerDeathEvent

## Create
final PlayerDeathEvent playerDeathEvent = new PlayerDeathEvent(player, entity or null, playerConnect, deathsToSet);

//You can run your own commands
final ArrayList<String> list = new ArrayList<>();
list.add("pvplevels message {player} Hey");
playerDeathEvent.setCommands(list);

playerDeathEvent.execute();


## Listen
@EventHandler
public void onEvent(PlayerDeathEvent e) {
    final long deaths = e.getDeaths();
    if (deaths == 5) {
        final Player player = e.getPlayer();

        final PlayerConnect playerConnect = e.getPlayerConnect();

        final Entity entity = e.getEntity(); // May return null

        //You can run your own commands
        final ArrayList<String> list = new ArrayList<>();
        list.add("pvplevels message {player} &7[&f&lPvPlevelsAPI&7] &f&l»");
        list.add("pvplevels message {player} \n");
        list.add("pvplevels message {player} &7You now have " + deaths + " deaths");
        list.add("pvplevels message {player} \n");
        e.setCommands(list);
    }
}

PlayerGetXPEvent

## Create
PlayerGetXPEvent playerGetXPEvent = new PlayerGetXPEvent(player, entity or null, playerConnect, xpToSet);

//You can run your own commands
final ArrayList<String> list = new ArrayList<>();
list.add("pvplevels message {player} Hey");
playerGetXPEvent.setCommands(list);

playerGetXPEvent.execute();


## Listen
@EventHandler
public void onEvent(PlayerGetXPEvent e) {
  final long setXP = e.getXp(); //Example 405

  final Player player = e.getPlayer();

  final PlayerConnect playerConnect = e.getPlayerConnect();

  if (api.getXPManager().isMaxLevel(playerConnect)) { // Dont need to check
    final ArrayList < String > list = new ArrayList < >();
    list.add("pvplevels message {player} &7[&f&lPvPlevelsAPI&7] &f&l»");
    list.add("pvplevels message {player} &7You cannot receive more xp, you have reached max level.");
    e.setCommands(list);
    return;
  }

  final Entity entity = e.getEntity(); // May return null

  final long currentXP = playerConnect.getXp(); // Will return xp before get xp event example 390

  final long got = setXP - currentXP; // 405 - 390 == 15

  final long extra = 10;

  e.setXp(setXP + extra);

  final long itemBoost = playerConnect.getXpItem(); // Will return 0 if no item boost

  final double multiplier = playerConnect.getMultiplier(); // Will return 0 if no multiplier

  String entityName = playerConnect.getXpType();
  if (entityName.length() == 0) {
    entityName = "Other source/command";
  }

  //You can run your own commands
  final ArrayList < String > list = new ArrayList < >();
  list.add("pvplevels message {player} &7[&f&lPvPlevelsAPI&7] &f&l»");
  list.add("pvplevels message {player} \n");
  list.add("pvplevels message {player} &7Amount before: &b" + currentXP);
  list.add("pvplevels message {player} &7You have got &b" + got + " &7xp");
  list.add("pvplevels message {player} &7+ &b" + extra + " &7extra xp");
  list.add("pvplevels message {player} &7Final amount got: &b" + e.getXp());
  list.add("pvplevels message {player} &7From &b" + entityName);
  list.add("pvplevels message {player} \n");

  if (multiplier != 0D) {
    final String setTime = api.getStatsManager().getMultiplierTime(playerConnect);
    final String timeLeft = api.getStatsManager().getMultiplierTimeLeft(playerConnect);
    list.add("pvplevels message {player} &7Multiplier: &b" + multiplier);
    list.add("pvplevels message {player} &7Time: &b" + setTime);
    list.add("pvplevels message {player} &7Time Left: &b" + timeLeft);
    list.add("pvplevels message {player} \n");
  }

  if (itemBoost != 0) {
    list.add("pvplevels message {player} &7Item boost: &b" + itemBoost + " &7xp");
    list.add("pvplevels message {player} \n");
  }

  e.setCommands(list);
}

PlayerKillEvent

## Create
final PlayerKillEvent playerKillEvent = new PlayerKillEvent(player, killed, playerConnect(player), killsToSet);

//You can run your own commands
final ArrayList<String> list = new ArrayList<>();
list.add("pvplevels message {player} Hey");
playerKillEvent.setCommands(list);

playerKillEvent.execute();


## Listen
@EventHandler
public void onEvent(PlayerKillEvent e) {
    final long kills = e.getKills();
    if (kills == 5) {
        final Player player = e.getPlayer();
        final PlayerConnect playerConnect = e.getPlayerConnect();

        final Player killed = e.getKilled();

        //You can run your own commands
        final ArrayList<String> list = new ArrayList<>();
        list.add("pvplevels message {player} &7[&f&lPvPlevelsAPI&7] &f&l»");
        list.add("pvplevels message {player} \n");
        list.add("pvplevels message {player} &7You now have " + kills + " kills");
        list.add("pvplevels message {player} \n");
        e.setCommands(list);
    }
}

PlayerKillStreakEvent

## Create
final PlayerKillStreakEvent playerKillStreakEvent = new PlayerKillStreakEvent(player, killed, playerConnect(player), killstreakToSet);

//You can run your own commands
final ArrayList<String> list = new ArrayList<>();
list.add("pvplevels message {player} Hey");
playerKillStreakEvent.setCommands(list);

playerKillStreakEvent.execute();


## Listen
@EventHandler
public void onEvent(PlayerKillStreakEvent e) {
  final long killstreak = e.getKillstreak()
  if (killstreak == 5) {
    final Player player = e.getPlayer();

    final PlayerConnect playerConnect = e.getPlayerConnect();

    //You can run your own commands
    final ArrayList < String > list = new ArrayList < >();
    list.add("pvplevels message {player} &7[&f&lPvPlevelsAPI&7] &f&l»");
    list.add("pvplevels message {player} \n");
    list.add("pvplevels message {player} &7You have got a kill streak of &b" + killstreak);
    list.add("pvplevels message {player} \n");
    e.setCommands(list);
  }
}

PlayerKillStreakTopEvent

## Create
final PlayerKillStreakTopEvent playerKillStreakTopEvent = new PlayerKillStreakTopEvent(player, killed, playerConnect(player), killstreakToSet);

//You can run your own commands
final ArrayList<String> list = new ArrayList<>();
list.add("pvplevels message {player} Hey");
playerKillStreakTopEvent.setCommands(list);

playerKillStreakTopEvent.execute();


## Listen
@EventHandler
public void onEvent(PlayerKillStreakTopEvent e) {
  final long killstreak = e.getKillstreak();
  if (killstreak == 5) {
    final Player player = e.getPlayer();

    final PlayerConnect playerConnect = e.getPlayerConnect();

    //You can run your own commands
    final ArrayList < String > list = new ArrayList < >();
    list.add("pvplevels message {player} &7[&f&lPvPlevelsAPI&7] &f&l»");
    list.add("pvplevels message {player} \n");
    list.add("pvplevels message {player} &7You have got a top kill streak of &b" + killstreak);
    list.add("pvplevels message {player} \n");
    e.setCommands(list);
  }
}

PlayerLevelDownEvent

## Create
final PlayerLevelDownEvent playerLevelDownEvent = new PlayerLevelDownEvent(player, entity or null, playerConnect, levelToSet);

//You can run your own commands
final ArrayList<String> list = new ArrayList<>();
list.add("pvplevels message {player} Hey");
playerLevelDownEvent.setCommands(list);

playerLevelDownEvent.execute();


## Listen
@EventHandler
public void onEvent(PlayerLevelDownEvent e) {
    final long level = e.getLevel();
    if (level == 4) {
        final Player player = e.getPlayer();

        final PlayerConnect playerConnect = e.getPlayerConnect();

        final Entity entity = e.getEntity(); // May return null

        //You can run your own commands
        final ArrayList<String> list = new ArrayList<>();
        list.add("pvplevels message {player} &7[&f&lPvPlevelsAPI&7] &f&l»");
        list.add("pvplevels message {player} \n");
        list.add("pvplevels message {player} &7You have lost a level");
        list.add("pvplevels message {player} &7You have got to level " + level); // return 4
        list.add("pvplevels message {player} &7Last level was " + playerConnect.getLevel()); // return 5
        list.add("pvplevels message {player} \n");
        e.setCommands(list);
    }
}

PlayerLevelUPEvent

## Create
final PlayerLevelUPEvent playerLevelUPEvent = new PlayerLevelUPEvent(player, entity or null, playerConnect, levelToSet);

//You can run your own commands
final ArrayList<String> list = new ArrayList<>();
list.add("pvplevels message {player} Hey");
playerLevelUPEvent.setCommands(list);

playerLevelUPEvent.execute();


## Listen
@EventHandler
public void onEvent(PlayerLevelUPEvent e) {
    final long level = e.getLevel();
    if (level == 5) {
        final Player player = e.getPlayer();

        final PlayerConnect playerConnect = e.getPlayerConnect();

        final Entity entity = e.getEntity(); // May return null

        //You can run your own commands
        final ArrayList<String> list = new ArrayList<>();
        list.add("pvplevels message {player} &7[&f&lPvPlevelsAPI&7] &f&l»");
        list.add("pvplevels message {player} \n");
        list.add("pvplevels message {player} &b{player} &7has leveled up to Level &b{level_next}&7!");
        list.add("pvplevels message {player} &7You have got to level " + level); // return 5
        list.add("pvplevels message {player} &7Last level was " + playerConnect.getLevel()); // return 4
        list.add("pvplevels message {player} \n");
        e.setCommands(list);
    }
}

PlayerLostKillStreakEvent

## Create
PlayerLostKillStreakEvent playerLostKillStreakEvent = new PlayerLostKillStreakEvent(player, playerConnect, killstreakToSet);

//You can run your own commands
final ArrayList<String> list = new ArrayList<>();
list.add("pvplevels message {player} Hey");
playerLostKillStreakEvent.setCommands(list);

playerLostKillStreakEvent.execute();


## Listen
@EventHandler
  public void onEvent(PlayerLostKillStreakEvent e) {
      final long killstreak = e.getKillstreak();
      if (killstreak == 6) {
          final Player player = e.getPlayer();
          final PlayerConnect playerConnect = e.getPlayerConnect();

          //You can run your own commands
          final ArrayList<String> list = new ArrayList<>();
          list.add("pvplevels message {player} Hey");
          e.setCommands(list);

          //You can change the killstreak, if you want by using e.setKillstreak(7);

          player.sendMessage("You have lost a kill streak of " + killstreak);
      }
  }

PlayerLostXPEvent

## Create
PlayerLostXPEvent playerLostXPEvent = new PlayerLostXPEvent(player, entity or null, playerConnect, xpToSet);

//You can run your own commands
final ArrayList<String> list = new ArrayList<>();
list.add("pvplevels message {player} Hey");
playerLostXPEvent.setCommands(list);

playerLostXPEvent.execute();


## Listen
@EventHandler
public void onEvent(PlayerLostXPEvent e) {
  final long setXP = e.getXp(); //Example 403

  final Player player = e.getPlayer();

  final PlayerConnect playerConnect = e.getPlayerConnect();

  final Entity entity = e.getEntity(); // May return null

  final long currentXP = playerConnect.getXp(); // Will return xp before lost xp event example 405 and lost amount is 2

  final long lost = currentXP - setXP; // 405 - 403 == 2

  final long extra = 10;

  e.setXp(setXP - extra);

  //You can run your own commands
  final ArrayList < String > list = new ArrayList < >();
  list.add("pvplevels message {player} &7[&f&lPvPlevelsAPI&7] &f&l»");
  list.add("pvplevels message {player} \n");
  list.add("pvplevels message {player} &7Amount before: &b" + currentXP);
  list.add("pvplevels message {player} &7You have lost &b" + lost + " &7xp");
  list.add("pvplevels message {player} &7- &b" + extra + " &7extra xp");
  list.add("pvplevels message {player} &7Final set amount: &b" + e.getXp());
  list.add("pvplevels message {player} &7From &b{source}");
  list.add("pvplevels message {player} \n");

  e.setCommands(list);
}
Clone this wiki locally