mirror of
https://github.com/TotalFreedomMC/TF-ProjectKorra.git
synced 2025-02-12 03:59:06 +00:00
- Added BindingUpdateEvent
This commit is contained in:
parent
1193d2cb3c
commit
212c079058
3 changed files with 105 additions and 13 deletions
|
@ -94,6 +94,7 @@ import com.projectkorra.projectkorra.configuration.ConfigManager;
|
||||||
import com.projectkorra.projectkorra.earthbending.EarthBlast;
|
import com.projectkorra.projectkorra.earthbending.EarthBlast;
|
||||||
import com.projectkorra.projectkorra.earthbending.EarthPassive;
|
import com.projectkorra.projectkorra.earthbending.EarthPassive;
|
||||||
import com.projectkorra.projectkorra.event.BendingReloadEvent;
|
import com.projectkorra.projectkorra.event.BendingReloadEvent;
|
||||||
|
import com.projectkorra.projectkorra.event.BindingUpdateEvent;
|
||||||
import com.projectkorra.projectkorra.event.PlayerBendingDeathEvent;
|
import com.projectkorra.projectkorra.event.PlayerBendingDeathEvent;
|
||||||
import com.projectkorra.projectkorra.firebending.Combustion;
|
import com.projectkorra.projectkorra.firebending.Combustion;
|
||||||
import com.projectkorra.projectkorra.firebending.FireBlast;
|
import com.projectkorra.projectkorra.firebending.FireBlast;
|
||||||
|
@ -163,6 +164,9 @@ public class GeneralMethods {
|
||||||
*/
|
*/
|
||||||
public static void bindAbility(Player player, String ability) {
|
public static void bindAbility(Player player, String ability) {
|
||||||
int slot = player.getInventory().getHeldItemSlot() + 1;
|
int slot = player.getInventory().getHeldItemSlot() + 1;
|
||||||
|
BindingUpdateEvent event = new BindingUpdateEvent(player, ability, slot, true);
|
||||||
|
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||||
|
if(!event.isCancelled())
|
||||||
bindAbility(player, ability, slot);
|
bindAbility(player, ability, slot);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -180,6 +184,9 @@ public class GeneralMethods {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BindingUpdateEvent event = new BindingUpdateEvent(player, ability, slot, true);
|
||||||
|
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||||
|
if(!event.isCancelled()) {
|
||||||
BendingPlayer bPlayer = BendingPlayer.getBendingPlayer(player.getName());
|
BendingPlayer bPlayer = BendingPlayer.getBendingPlayer(player.getName());
|
||||||
CoreAbility coreAbil = CoreAbility.getAbility(ability);
|
CoreAbility coreAbil = CoreAbility.getAbility(ability);
|
||||||
|
|
||||||
|
@ -193,6 +200,7 @@ public class GeneralMethods {
|
||||||
}
|
}
|
||||||
saveAbility(bPlayer, slot, ability);
|
saveAbility(bPlayer, slot, ability);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cycles through a list of ability names to check if any instances of the
|
* Cycles through a list of ability names to check if any instances of the
|
||||||
|
|
|
@ -4,7 +4,9 @@ import com.projectkorra.projectkorra.BendingPlayer;
|
||||||
import com.projectkorra.projectkorra.Element;
|
import com.projectkorra.projectkorra.Element;
|
||||||
import com.projectkorra.projectkorra.GeneralMethods;
|
import com.projectkorra.projectkorra.GeneralMethods;
|
||||||
import com.projectkorra.projectkorra.ProjectKorra;
|
import com.projectkorra.projectkorra.ProjectKorra;
|
||||||
|
import com.projectkorra.projectkorra.event.BindingUpdateEvent;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
@ -40,6 +42,11 @@ public class MultiAbilityManager {
|
||||||
* @param multiAbility
|
* @param multiAbility
|
||||||
*/
|
*/
|
||||||
public static void bindMultiAbility(Player player, String 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))
|
if (playerAbilities.containsKey(player))
|
||||||
unbindMultiAbility(player);
|
unbindMultiAbility(player);
|
||||||
playerSlot.put(player, player.getInventory().getHeldItemSlot());
|
playerSlot.put(player, player.getInventory().getHeldItemSlot());
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue