Merge remote-tracking branch 'refs/remotes/ProjectKorra/master'

This commit is contained in:
Benford 2016-02-20 10:35:49 -05:00
commit 3c65d98139
7 changed files with 186 additions and 52 deletions

View file

@ -93,7 +93,7 @@ import com.projectkorra.projectkorra.command.Commands;
import com.projectkorra.projectkorra.configuration.ConfigManager;
import com.projectkorra.projectkorra.earthbending.EarthBlast;
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.BindChangeEvent;
import com.projectkorra.projectkorra.event.EntityBendingDeathEvent;
@ -359,25 +359,26 @@ public class GeneralMethods {
* @param ability The ability that is used to damage the entity
*/
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 Player) {
if (Commands.invincible.contains(entity.getName())) {
return;
if (entity instanceof Player && Commands.invincible.contains(entity.getName())) {
damageEvent.setCancelled(true);
}
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);
}
((LivingEntity) entity).damage(damage, player);
entity.setLastDamageCause(new EntityDamageByEntityEvent(player, entity, DamageCause.CUSTOM, damage));
if (Bukkit.getPluginManager().isPluginEnabled("NoCheatPlus")) {
NCPExemptionManager.unexempt(player);
}
}
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();
Bukkit.getServer().getPluginManager().callEvent(event);
((LivingEntity) entity).damage(damage, player);
entity.setLastDamageCause(new EntityDamageByEntityEvent(player, entity, DamageCause.CUSTOM, damage));
if (Bukkit.getPluginManager().isPluginEnabled("NoCheatPlus")) {
NCPExemptionManager.unexempt(player);
}
}
}

View file

@ -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.MultiAbilityInfo;
import com.projectkorra.projectkorra.configuration.ConfigManager;
import com.projectkorra.projectkorra.event.AbilityEndEvent;
import com.projectkorra.projectkorra.event.AbilityStartEvent;
import sun.reflect.ReflectionFactory;
@ -114,7 +116,12 @@ public abstract class CoreAbility implements Ability {
if (player == null) {
return;
}
AbilityStartEvent event = new AbilityStartEvent(this);
Bukkit.getServer().getPluginManager().callEvent(event);
if(event.isCancelled()) {
remove();
return;
}
this.started = true;
this.startTime = System.currentTimeMillis();
Class<? extends CoreAbility> clazz = getClass();
@ -148,6 +155,7 @@ public abstract class CoreAbility implements Ability {
return;
}
Bukkit.getServer().getPluginManager().callEvent(new AbilityEndEvent(this));
removed = true;
ConcurrentHashMap<UUID, ConcurrentHashMap<Integer, CoreAbility>> classMap = INSTANCES.get(getClass());
@ -346,6 +354,7 @@ public abstract class CoreAbility implements Ability {
* @see #getAbility(String)
*/
public static void registerPluginAbilities(JavaPlugin plugin, String packagePrefix) {
List<String> disabled = new ArrayList<String>(); //this way multiple classes with the same name only show once
if (plugin == null) {
return;
}
@ -373,8 +382,9 @@ public abstract class CoreAbility implements Ability {
if (ability == null || ability.getName() == null) {
continue;
} else if (!ability.isEnabled()) {
} else if (!ability.isEnabled() && !disabled.contains(ability.getName())) {
plugin.getLogger().info(ability.getName() + " is disabled");
disabled.add(ability.getName());
continue;
}

View file

@ -149,7 +149,7 @@ public class WhoCommand extends PKCommand {
//Player player = Bukkit.getPlayer(playerName);
@SuppressWarnings("deprecation")
final OfflinePlayer player = Bukkit.getOfflinePlayer(playerName);
if (player == null || !player.hasPlayedBefore()) {
if (player == null || !player.hasPlayedBefore() && !player.isOnline()) {
sender.sendMessage(ChatColor.RED + "Player not found!");
return;
}

View file

@ -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;
}
}

View 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;
}
}

View file

@ -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;
}
}

View file

@ -1,31 +0,0 @@
package com.projectkorra.projectkorra.event;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
public class BendingDamageEvent extends Event implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private boolean cancelled;
public BendingDamageEvent() {
this.cancelled = false;
}
@Override
public HandlerList getHandlers() {
return handlers;
}
@Override
public boolean isCancelled() {
return cancelled;
}
@Override
public void setCancelled(boolean cancel) {
this.cancelled = cancel;
}
}