- Added BindingUpdateEvent

This commit is contained in:
BuildTools 2016-02-09 20:27:25 -05:00
parent 1193d2cb3c
commit 212c079058
3 changed files with 105 additions and 13 deletions

View file

@ -94,6 +94,7 @@ import com.projectkorra.projectkorra.configuration.ConfigManager;
import com.projectkorra.projectkorra.earthbending.EarthBlast;
import com.projectkorra.projectkorra.earthbending.EarthPassive;
import com.projectkorra.projectkorra.event.BendingReloadEvent;
import com.projectkorra.projectkorra.event.BindingUpdateEvent;
import com.projectkorra.projectkorra.event.PlayerBendingDeathEvent;
import com.projectkorra.projectkorra.firebending.Combustion;
import com.projectkorra.projectkorra.firebending.FireBlast;
@ -163,7 +164,10 @@ public class GeneralMethods {
*/
public static void bindAbility(Player player, String ability) {
int slot = player.getInventory().getHeldItemSlot() + 1;
bindAbility(player, ability, slot);
BindingUpdateEvent event = new BindingUpdateEvent(player, ability, slot, true);
Bukkit.getServer().getPluginManager().callEvent(event);
if(!event.isCancelled())
bindAbility(player, ability, slot);
}
/**
@ -180,18 +184,22 @@ public class GeneralMethods {
return;
}
BendingPlayer bPlayer = BendingPlayer.getBendingPlayer(player.getName());
CoreAbility coreAbil = CoreAbility.getAbility(ability);
if (bPlayer == null) {
return;
BindingUpdateEvent event = new BindingUpdateEvent(player, ability, slot, true);
Bukkit.getServer().getPluginManager().callEvent(event);
if(!event.isCancelled()) {
BendingPlayer bPlayer = BendingPlayer.getBendingPlayer(player.getName());
CoreAbility coreAbil = CoreAbility.getAbility(ability);
if (bPlayer == null) {
return;
}
bPlayer.getAbilities().put(slot, ability);
if (coreAbil != null) {
player.sendMessage(coreAbil.getElement().getColor() + "Succesfully bound " + ability + " to slot " + slot);
}
saveAbility(bPlayer, slot, ability);
}
bPlayer.getAbilities().put(slot, ability);
if (coreAbil != null) {
player.sendMessage(coreAbil.getElement().getColor() + "Succesfully bound " + ability + " to slot " + slot);
}
saveAbility(bPlayer, slot, ability);
}
/**

View file

@ -4,7 +4,9 @@ import com.projectkorra.projectkorra.BendingPlayer;
import com.projectkorra.projectkorra.Element;
import com.projectkorra.projectkorra.GeneralMethods;
import com.projectkorra.projectkorra.ProjectKorra;
import com.projectkorra.projectkorra.event.BindingUpdateEvent;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
@ -40,6 +42,11 @@ public class MultiAbilityManager {
* @param multiAbility
*/
public static void bindMultiAbility(Player player, String multiAbility) {
BindingUpdateEvent event = new BindingUpdateEvent(player, multiAbility, true);
Bukkit.getServer().getPluginManager().callEvent(event);
if(event.isCancelled())
return;
if (playerAbilities.containsKey(player))
unbindMultiAbility(player);
playerSlot.put(player, player.getInventory().getHeldItemSlot());
@ -187,7 +194,7 @@ public class MultiAbilityManager {
*
* @param player
*/
public static void unbindMultiAbility(Player player) {
public static void unbindMultiAbility(Player player) {
if (playerAbilities.containsKey(player)) {
HashMap<Integer, String> prevBinds = playerAbilities.get(player);
BendingPlayer bPlayer = BendingPlayer.getBendingPlayer(player);

View file

@ -0,0 +1,77 @@
package com.projectkorra.projectkorra.event;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import com.projectkorra.projectkorra.ability.CoreAbility;
/**
* Called when a player binds or unbinds an ability
*
* @author savior67
*/
public class BindingUpdateEvent extends Event{
private static final HandlerList handlers = new HandlerList();
private Player player;
private String ability;
private int slot; //slot is -1 if it is a multiability
private boolean isBinding; //true if the ability is being binded, otherwise false
private boolean isMultiAbility; //true if the ability is a multiability
private boolean cancelled;
//bind event for abilities
public BindingUpdateEvent(Player player, String ability, int slot, boolean isBinding) {
this.player = player;
this.ability = ability;
this.slot = slot;
this.isBinding = isBinding;
this.cancelled = false;
this.isMultiAbility = false;
}
//used for multi abilities
public BindingUpdateEvent(Player player, String ability, boolean isBinding) {
this.player = player;
this.ability = ability;
this.slot = -1;
this.isBinding = isBinding;
this.cancelled = false;
this.isMultiAbility = true;
}
public void setCancelled(boolean cancelled) {
this.cancelled = cancelled;
}
public boolean isCancelled() {
return cancelled;
}
public Player getPlayer() {
return player;
}
public String getAbility() {
return ability;
}
public int getSlot() {
return slot;
}
public boolean isBinding() {
return isBinding;
}
@Override
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
}