-
-
Notifications
You must be signed in to change notification settings - Fork 30
API
Full java documentation: https://plajer-lair.github.io/Village_Defense/
- API Events
- Stats storage
- Kit registry
- Manipulating player join/leave attempts (soon)
❗️ Contents may be not up to date! Please use java docs instead. Here you can only get some simple examples.
Event name [since] [extra attributes]
- VillageEvent [3.0.0] [Generic event]
- VillageGameJoinAttemptEvent [3.0.0] [Cancellable]
- VillageGameLeaveAttemptEvent [3.0.0]
- VillageGameStartEvent [3.0.0]
- VillageGameStopEvent [3.0.0]
- VillagePlayerChooseKitEvent [2.0.0] [Cancellable]
- VillageWaveEndEvent [3.0.0]
- VillageWaveStartEvent [3.0.0]
- VillageGameStateChangeEvent [3.8.0]
- VillagePlayerStatisticChangeEvent [3.8.0]
- VillageGolemUpgradeEvent [3.8.0]
- VillagePowerupPickEvent [3.8.0]
The event is called everytime any Village Defense event is called because it's a generic event
Example:
@EventHandler
public void onEventCall(VillageEvent event){
if(event instanceof VillagePowerupPickEvent){
Bukkit.getConsoleSender().sendMessage("VillagePowerupPickEvent was called!");
}
}
event#getArena() - returns event arena for which event was called
The event is called when a player is trying to join an arena.
Example:
@EventHandler
public void onGameJoin(VillageGameJoinAttemptEvent event){
e.getPlayer().sendMessage("You have joined " + e.getArena().getID());
e.setCancelled(true);
e.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
event#isCancelled() - returns true if event is cancelled
❗️ A message from language file is sent to the player when the attempt is cancelled (see In-Game.Join-Cancelled-Via-API in language.yml)
The event is called when the arena starts.
Example:
@EventHandler
public void onGameStart(VillageGameStartEvent event){
for(Player p : e.getArena().getPlayers()){
p.sendMessage("Game has started!");
}
}
event#getArena() - returns event arena
The event is called when a player is trying to leave an arena.
Example:
@EventHandler
public void onGameQuit(VillageGameLeaveAttemptEvent event){
e.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
The event is called when a game is stopped.
Example:
@EventHandler
public void onGameStop(VillageGameStopEvent event){
for(Player p : e.getArena().getPlayers()){
p.sendMessage("You've lost the game! Maybe play again?");
}
}
event#getArena() - returns existing arena that is stopped
The event is called when the player chose kit in game.
Example:
@EventHandler
public void onKitChoose(VillagePlayerChooseKitEvent event){
Kit kit = e.getKit();
if(kit.getName().contains("knight")){
e.getPlayer().sendMessage("Knight kits aren't for you mate! Use archer kit instead!");
e.setCancelled(true);
}
}
event#getArena() - returns arena player is playing (player is always in arena when this event is called)
event#getPlayer() - returns event player
event#getKit() - returns selected kit
event#isCancelled() - returns true if event is cancelled
❗️ Cancelling the event doesn't really influence the in-game kit chooser, #isCancelled() should be used for external add-ons
The event is called when the wave is finished (all zombies are killed).
Example:
@EventHandler
public void onWaveEnd(VillageWaveEndEvent event){
for(Player p : e.getArena().getPlayers()){
p.sendMessage("Wave has ended! You recived free diamond!");
p.getInventory().addItem(new ItemStack(Material.DIAMOND, 1);
}
}
event#getArena() - returns event arena
event#getWaveNumber() - returns number of current wave
The event is called when the wave starts.
Example:
@EventHandler
public void onWaveStart(VillageWaveStartEvent event){
for(Player p : e.getArena().getPlayers()){
p.sendMessage("Wave has started! Good luck.");
}
}
event#getArena() - returns event arena
event#getWaveNumber() - returns number of current wave
The event is called when arena game state changes.
Example:
@EventHandler
public void onGameStateChange(VillageGameStateChangeEvent event){
String state = e.getArenaState().getFormattedName();
for(Player p : e.getArena().getPlayers()){
p.sendMessage("Arena state changed to " + state);
}
}
event#getArena() - returns event arena
event#getArenaState() - returns current arena state
The event is called when the player receives a new statistic.
Example:
@EventHandler
public void onStatChange(VillagePlayerStatisticChangeEvent 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
The event is called when the player upgrades a golem.
Example:
@EventHandler
public void onGolemUpgrade(VillageGolemUpgradeEvent event){
double health = event.getIronGolem().getMaxHealth();
double originHealth = event.getOriginalHealth();
if(health == originHealth){
//Golem was healed
event.getPlayer().sendMessage("You've healed your golem!");
} else{
//Golem's health was upgraded
event.getPlayer().sendMessage("Your golem's maximum health has increased by " + (health - originHealth));
}
}
event#getIronGolem() - returns event iron golem entity
event#getOriginalHealth() - returns max health of iron golem before upgrade
event#getPlayer() - returns player who owns* and who has upgraded golem
* may change in the future
event#getArena() - returns arena where golem was upgraded
The event is called when the player picks up a power-up.
Example:
@EventHandler
public void onPowerupPick(VillagePowerupPickEvent event){
PowerupManager.PowerupType powerupType = event.getPowerupType();
event.getPlayer().sendMessage("You've picked up " + powerupType.getName() + "!");
}
event#getPowerupType() - returns power up type of PowerupManager.PowerupType enum
event#getPlayer() - returns player involved in this event
event#getArena() - returns arena player is playing
You can easily get online players stats using VD3 API - Stats Storage class.
Example:
public int getZombieKills(Player p){
return StatsStorage.getUserStats(p, StatsStorage.StatisticType.KILLS);
}
Very easy, right?
To access sorted statistics Map 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
❗️ Orbs statistic is temporary and shouldn't be used for out game usages
Statistic name (enum) | Statistic identifier (string) (for advanced things) | Type |
---|---|---|
ORBS (❗️non-persistent) | orbs | int |
KILLS | kills | int |
DEATHS | deaths | int |
GAMES_PLAYED | gamesplayed | int |
HIGHEST_WAVE | highestwave | int |
LEVEL | level | int |
XP | xp | int |
Registering new kit is quite simple. We need to implement all methods from abstract Kit class and edit it by yourself. After that just register it via KitRegistry.
Example:
//This kit will be premium
Kit supporter = new PremiumKit() {
//We need to implement methods from abstract Kit class
//Permissions needed to unlock it, if it is free just return true
@Override
public boolean isUnlockedByPlayer(Player p) {
return p.hasPermission("my.super.kit");
}
//Items given on game start
@Override
public void giveKitItems(Player player) {
player.getInventory().addItem(new ItemStack(Material.IRON_AXE, 1));
player.getInventory().addItem(new ItemStack(Material.GOLDEN_APPLE, 5));
}
//Material represented by this kit in the kit menu. Must be unique!
@Override
public Material getMaterial() {
return Material.GOLDEN_APPLE;
}
//Items given every next wave
@Override
public void reStock(Player player) {
player.getInventory().addItem(new ItemStack(Material.GOLDEN_APPLE, 1));
}
};
//Now just set kit name and description and register it via KitRegistry
supporter.setName("Supporter");
supporter.setDescription(new String[]{ChatColor.GREEN + "My super description"});
KitRegistry.registerKit(supporter);
© 2018 Village Defense 3 | Created by Plajer's Lair and maintained by Plajer