mirror of
https://github.com/TotalFreedomMC/TF-ProjectKorra.git
synced 2025-02-11 19:50:37 +00:00
Merge pull request #417 from kingbirdy/bendingevents
Add AbilityDamageEntityEvent, AbilityStartEvent, AbilityEndEvent
This commit is contained in:
commit
4f4335e498
6 changed files with 177 additions and 87 deletions
|
@ -93,7 +93,7 @@ import com.projectkorra.projectkorra.command.Commands;
|
||||||
import com.projectkorra.projectkorra.configuration.ConfigManager;
|
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.BendingDamageEvent;
|
import com.projectkorra.projectkorra.event.AbilityDamageEntityEvent;
|
||||||
import com.projectkorra.projectkorra.event.BendingReloadEvent;
|
import com.projectkorra.projectkorra.event.BendingReloadEvent;
|
||||||
import com.projectkorra.projectkorra.event.BindChangeEvent;
|
import com.projectkorra.projectkorra.event.BindChangeEvent;
|
||||||
import com.projectkorra.projectkorra.event.EntityBendingDeathEvent;
|
import com.projectkorra.projectkorra.event.EntityBendingDeathEvent;
|
||||||
|
@ -359,23 +359,21 @@ public class GeneralMethods {
|
||||||
* @param ability The ability that is used to damage the entity
|
* @param ability The ability that is used to damage the entity
|
||||||
*/
|
*/
|
||||||
public static void damageEntity(Player player, Entity entity, double damage, String ability) {
|
public static void damageEntity(Player player, Entity entity, double damage, String ability) {
|
||||||
|
AbilityDamageEntityEvent damageEvent = new AbilityDamageEntityEvent(entity, CoreAbility.getAbility(player, CoreAbility.getAbility(ability).getClass()), damage);
|
||||||
|
Bukkit.getServer().getPluginManager().callEvent(damageEvent);
|
||||||
if (entity instanceof LivingEntity) {
|
if (entity instanceof LivingEntity) {
|
||||||
if (entity instanceof Player) {
|
if (entity instanceof Player && Commands.invincible.contains(entity.getName())) {
|
||||||
if (Commands.invincible.contains(entity.getName())) {
|
damageEvent.setCancelled(true);
|
||||||
return;
|
}
|
||||||
|
if (!damageEvent.isCancelled()) {
|
||||||
|
damage = damageEvent.getDamage();
|
||||||
|
if (Bukkit.getPluginManager().isPluginEnabled("NoCheatPlus")) {
|
||||||
|
NCPExemptionManager.exemptPermanently(player, CheckType.FIGHT_REACH);
|
||||||
|
}
|
||||||
|
if (((LivingEntity) entity).getHealth() - damage <= 0 && !entity.isDead()) {
|
||||||
|
EntityBendingDeathEvent deathEvent = new EntityBendingDeathEvent(entity, player, damage, ability);
|
||||||
|
Bukkit.getServer().getPluginManager().callEvent(deathEvent);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (Bukkit.getPluginManager().isPluginEnabled("NoCheatPlus")) {
|
|
||||||
NCPExemptionManager.exemptPermanently(player, CheckType.FIGHT_REACH);
|
|
||||||
}
|
|
||||||
if (((LivingEntity) entity).getHealth() - damage <= 0 && !entity.isDead()) {
|
|
||||||
EntityBendingDeathEvent event = new EntityBendingDeathEvent(entity, player, damage, ability);
|
|
||||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
|
||||||
}
|
|
||||||
BendingDamageEvent event = new BendingDamageEvent(player, entity, damage, ability);
|
|
||||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
|
||||||
|
|
||||||
if(!event.isCancelled()) {
|
|
||||||
((LivingEntity) entity).damage(damage, player);
|
((LivingEntity) entity).damage(damage, player);
|
||||||
entity.setLastDamageCause(new EntityDamageByEntityEvent(player, entity, DamageCause.CUSTOM, damage));
|
entity.setLastDamageCause(new EntityDamageByEntityEvent(player, entity, DamageCause.CUSTOM, damage));
|
||||||
if (Bukkit.getPluginManager().isPluginEnabled("NoCheatPlus")) {
|
if (Bukkit.getPluginManager().isPluginEnabled("NoCheatPlus")) {
|
||||||
|
|
|
@ -32,6 +32,8 @@ import com.projectkorra.projectkorra.ability.util.ComboManager;
|
||||||
import com.projectkorra.projectkorra.ability.util.MultiAbilityManager;
|
import com.projectkorra.projectkorra.ability.util.MultiAbilityManager;
|
||||||
import com.projectkorra.projectkorra.ability.util.MultiAbilityManager.MultiAbilityInfo;
|
import com.projectkorra.projectkorra.ability.util.MultiAbilityManager.MultiAbilityInfo;
|
||||||
import com.projectkorra.projectkorra.configuration.ConfigManager;
|
import com.projectkorra.projectkorra.configuration.ConfigManager;
|
||||||
|
import com.projectkorra.projectkorra.event.AbilityEndEvent;
|
||||||
|
import com.projectkorra.projectkorra.event.AbilityStartEvent;
|
||||||
|
|
||||||
import sun.reflect.ReflectionFactory;
|
import sun.reflect.ReflectionFactory;
|
||||||
|
|
||||||
|
@ -114,7 +116,12 @@ public abstract class CoreAbility implements Ability {
|
||||||
if (player == null) {
|
if (player == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
AbilityStartEvent event = new AbilityStartEvent(this);
|
||||||
|
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||||
|
if(event.isCancelled()) {
|
||||||
|
remove();
|
||||||
|
return;
|
||||||
|
}
|
||||||
this.started = true;
|
this.started = true;
|
||||||
this.startTime = System.currentTimeMillis();
|
this.startTime = System.currentTimeMillis();
|
||||||
Class<? extends CoreAbility> clazz = getClass();
|
Class<? extends CoreAbility> clazz = getClass();
|
||||||
|
@ -148,6 +155,7 @@ public abstract class CoreAbility implements Ability {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Bukkit.getServer().getPluginManager().callEvent(new AbilityEndEvent(this));
|
||||||
removed = true;
|
removed = true;
|
||||||
|
|
||||||
ConcurrentHashMap<UUID, ConcurrentHashMap<Integer, CoreAbility>> classMap = INSTANCES.get(getClass());
|
ConcurrentHashMap<UUID, ConcurrentHashMap<Integer, CoreAbility>> classMap = INSTANCES.get(getClass());
|
||||||
|
|
|
@ -0,0 +1,85 @@
|
||||||
|
package com.projectkorra.projectkorra.event;
|
||||||
|
|
||||||
|
import org.bukkit.entity.Entity;
|
||||||
|
import org.bukkit.event.Cancellable;
|
||||||
|
import org.bukkit.event.Event;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
|
import com.projectkorra.projectkorra.ability.Ability;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when an ability damages an {@link Entity}
|
||||||
|
* @author kingbirdy
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class AbilityDamageEntityEvent extends Event implements Cancellable {
|
||||||
|
|
||||||
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
|
||||||
|
private boolean cancelled = false;
|
||||||
|
private Entity entity;
|
||||||
|
private Ability ability;
|
||||||
|
double damage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new AbilityDamageEntityEvent
|
||||||
|
* @param entity The entity that was damaged
|
||||||
|
* @param ability The damaging ability
|
||||||
|
* @param damage The amount of damage done
|
||||||
|
*/
|
||||||
|
public AbilityDamageEntityEvent(Entity entity, Ability ability, double damage) {
|
||||||
|
this.entity = entity;
|
||||||
|
this.ability = ability;
|
||||||
|
this.damage = damage;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the damage dealt to the entity
|
||||||
|
* @return the amount of damage done
|
||||||
|
*/
|
||||||
|
public double getDamage() {
|
||||||
|
return damage;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the damage dealt to the entity
|
||||||
|
* @param damage the amount of damage done
|
||||||
|
*/
|
||||||
|
public void setDamage(double damage) {
|
||||||
|
this.damage = damage;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the entity that was damaged
|
||||||
|
* @return the damaged entity
|
||||||
|
*/
|
||||||
|
public Entity getEntity() {
|
||||||
|
return entity;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public Ability getAbility() {
|
||||||
|
return ability;
|
||||||
|
}
|
||||||
|
|
||||||
|
public HandlerList getHandlers() {
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static HandlerList getHandlerList() {
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isCancelled() {
|
||||||
|
return cancelled;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setCancelled(boolean cancelled) {
|
||||||
|
this.cancelled = cancelled;
|
||||||
|
}
|
||||||
|
}
|
22
src/com/projectkorra/projectkorra/event/AbilityEndEvent.java
Normal file
22
src/com/projectkorra/projectkorra/event/AbilityEndEvent.java
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
package com.projectkorra.projectkorra.event;
|
||||||
|
|
||||||
|
import org.bukkit.event.Event;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
|
import com.projectkorra.projectkorra.ability.Ability;
|
||||||
|
|
||||||
|
public class AbilityEndEvent extends Event {
|
||||||
|
private final HandlerList handlers = new HandlerList();
|
||||||
|
|
||||||
|
Ability ability;
|
||||||
|
|
||||||
|
public AbilityEndEvent(Ability ability) {
|
||||||
|
this.ability = ability;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HandlerList getHandlers() {
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,47 @@
|
||||||
|
package com.projectkorra.projectkorra.event;
|
||||||
|
|
||||||
|
import org.bukkit.event.Cancellable;
|
||||||
|
import org.bukkit.event.Event;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
|
import com.projectkorra.projectkorra.ability.Ability;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when an ability starts
|
||||||
|
* @author Philip
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class AbilityStartEvent extends Event implements Cancellable {
|
||||||
|
|
||||||
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
|
||||||
|
boolean cancelled = false;
|
||||||
|
Ability ability;
|
||||||
|
|
||||||
|
public AbilityStartEvent(Ability ability) {
|
||||||
|
this.ability = ability;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Ability getAbility() {
|
||||||
|
return ability;
|
||||||
|
}
|
||||||
|
|
||||||
|
public HandlerList getHandlers() {
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static HandlerList getHandlerList() {
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isCancelled() {
|
||||||
|
return cancelled;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setCancelled(boolean cancelled) {
|
||||||
|
this.cancelled = cancelled;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,70 +0,0 @@
|
||||||
package com.projectkorra.projectkorra.event;
|
|
||||||
|
|
||||||
import org.bukkit.entity.Entity;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.Cancellable;
|
|
||||||
import org.bukkit.event.Event;
|
|
||||||
import org.bukkit.event.HandlerList;
|
|
||||||
|
|
||||||
public class BendingDamageEvent extends Event implements Cancellable {
|
|
||||||
|
|
||||||
public static final HandlerList handlers = new HandlerList();
|
|
||||||
private boolean cancelled;
|
|
||||||
private Player attacker;
|
|
||||||
private Entity damaged;
|
|
||||||
private double damage;
|
|
||||||
private String ability;
|
|
||||||
|
|
||||||
public BendingDamageEvent(Player attacker, Entity damaged, double damage, String ability) {
|
|
||||||
this.cancelled = false;
|
|
||||||
this.attacker = attacker;
|
|
||||||
this.damaged = damaged;
|
|
||||||
this.damage = damage;
|
|
||||||
this.ability = ability;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getAbility() {
|
|
||||||
return ability;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAbility(String ability) {
|
|
||||||
this.ability = ability;
|
|
||||||
}
|
|
||||||
|
|
||||||
public double getDamage() {
|
|
||||||
return damage;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDamage(double damage) {
|
|
||||||
this.damage = damage;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Entity getDamaged() {
|
|
||||||
return damaged;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Player getAttacker() {
|
|
||||||
return attacker;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public HandlerList getHandlers() {
|
|
||||||
return handlers;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static HandlerList getHandlerList() {
|
|
||||||
return handlers;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isCancelled() {
|
|
||||||
return cancelled;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setCancelled(boolean cancel) {
|
|
||||||
this.cancelled = cancel;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
Loading…
Reference in a new issue