Skip to content

Commit

Permalink
[release] add option for hurt-by-entity only.
Browse files Browse the repository at this point in the history
  • Loading branch information
Librazy committed Apr 5, 2019
1 parent ee7b423 commit 6eb1fb2
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 42 deletions.
16 changes: 4 additions & 12 deletions src/main/java/think/rpgitems/power/impl/PowerAOEDamage.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
package think.rpgitems.power.impl;

import org.bukkit.Effect;
import org.bukkit.attribute.Attribute;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LightningStrike;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.player.PlayerInteractEvent;
Expand All @@ -15,17 +11,13 @@
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import think.rpgitems.I18n;
import think.rpgitems.item.RPGItem;
import think.rpgitems.power.*;
import think.rpgitems.utils.PotionEffectUtils;

import java.util.List;

import static java.lang.Double.max;
import static java.lang.Double.min;
import static think.rpgitems.power.Utils.*;
import static think.rpgitems.power.Utils.getLivingEntitiesInCone;

/**
* Power AOEDamage.
Expand Down Expand Up @@ -126,8 +118,8 @@ public PowerResult<Void> sneak(Player player, ItemStack stack, PlayerToggleSneak
}

@Override
public PowerResult<Double> hurt(Player target, ItemStack stack, double damage, EntityDamageEvent event) {
return fire(target, stack).with(damage);
public PowerResult<Void> hurt(Player target, ItemStack stack, EntityDamageEvent event) {
return fire(target, stack);
}

@Override
Expand All @@ -153,8 +145,8 @@ public PowerResult<Void> fire(Player player, ItemStack stack) {
for (int i = 0; i < c && i < entities.length; ++i) {
LivingEntity e = entities[i];
if ((mustsee && !player.hasLineOfSight(e))
|| (e == player)
|| (!incluePlayers && e instanceof Player)
|| (e == player)
|| (!incluePlayers && e instanceof Player)
) {
++count;
continue;
Expand Down
44 changes: 27 additions & 17 deletions src/main/java/think/rpgitems/power/impl/PowerCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.bukkit.ChatColor;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerToggleSneakEvent;
Expand Down Expand Up @@ -52,6 +53,12 @@ public class PowerCommand extends BasePower implements PowerRightClick, PowerLef
@Property
public int cost = 0;

/**
* Whether to require hurt by entity for HURT trigger
*/
@Property
public boolean requireHurtByEntity = true;

@Override
public void init(ConfigurationSection section) {
if (section.isBoolean("isRight")) {
Expand All @@ -61,6 +68,19 @@ public void init(ConfigurationSection section) {
super.init(section);
}

@Override
public PowerResult<Void> rightClick(Player player, ItemStack stack, PlayerInteractEvent event) {
return fire(player, stack);
}

@Override
public PowerResult<Void> fire(Player target, ItemStack stack) {
if (!checkCooldownByString(this, target, command, cooldown, true, false))
return PowerResult.cd();
if (!getItem().consumeDurability(stack, cost)) return PowerResult.cost();
return executeCommand(target);
}

/**
* Execute command
*
Expand All @@ -71,7 +91,7 @@ protected PowerResult<Void> executeCommand(Player player) {
if (!player.isOnline()) return PowerResult.noop();

String cmd = handlePlayerPlaceHolder(player, command);
if (permission.equals("console")){
if (permission.equals("console")) {
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), cmd);
} else {
boolean wasOp = player.isOp();
Expand Down Expand Up @@ -104,11 +124,6 @@ public static String handlePlayerPlaceHolder(Player player, String cmd) {
return cmd;
}

@Override
public PowerResult<Void> rightClick(Player player, ItemStack stack, PlayerInteractEvent event) {
return fire(player, stack);
}

@Override
public PowerResult<Void> leftClick(Player player, ItemStack stack, PlayerInteractEvent event) {
return fire(player, stack);
Expand All @@ -126,24 +141,19 @@ public PowerResult<Void> sprint(Player player, ItemStack stack, PlayerToggleSpri

@Override
public PowerResult<Void> hurt(Player target, ItemStack stack, EntityDamageEvent event) {
return fire(target, stack);
if (!requireHurtByEntity || event instanceof EntityDamageByEntityEvent) {
return fire(target, stack);
}
return PowerResult.noop();
}

@Override
public PowerResult<Void> fire(Player target, ItemStack stack) {
if (!checkCooldownByString(this, target, command, cooldown, true, false))
return PowerResult.cd();
if (!getItem().consumeDurability(stack, cost)) return PowerResult.cost();
return executeCommand(target);
public String getName() {
return "command";
}

@Override
public String displayText() {
return ChatColor.GREEN + display;
}

@Override
public String getName() {
return "command";
}
}
36 changes: 23 additions & 13 deletions src/main/java/think/rpgitems/power/impl/PowerDummy.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package think.rpgitems.power.impl;

import org.bukkit.NamespacedKey;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
Expand All @@ -11,8 +13,6 @@
import org.bukkit.event.player.PlayerToggleSneakEvent;
import org.bukkit.event.player.PlayerToggleSprintEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.NamespacedKey;
import think.rpgitems.power.*;

import static think.rpgitems.power.Utils.checkCooldownByString;
Expand Down Expand Up @@ -46,7 +46,7 @@ public class PowerDummy extends BasePower implements PowerHit, PowerHitTaken, Po
*/
@Property
public String display;

/**
* Whether enchantments can determine cost
*/
Expand All @@ -65,7 +65,7 @@ public class PowerDummy extends BasePower implements PowerHit, PowerHitTaken, Po
*/
@Property
public double enchCostPercentage = 6;

/**
* Type of enchantment that reduces cost
*/
Expand All @@ -78,6 +78,12 @@ public class PowerDummy extends BasePower implements PowerHit, PowerHitTaken, Po
@Property
public boolean costByDamage = false;

/**
* Whether to require hurt by entity for HURT trigger
*/
@Property
public boolean requireHurtByEntity = true;

@Property
public String cooldownKey = "dummy";

Expand All @@ -89,18 +95,19 @@ public class PowerDummy extends BasePower implements PowerHit, PowerHitTaken, Po

@Property
public TriggerResult cooldownResult = TriggerResult.COOLDOWN;

@Property
public boolean showCDWarning = true;

@Override
public PowerResult<Void> fire(Player player, ItemStack stack){
return fire(player, stack);
public PowerResult<Void> fire(Player player, ItemStack stack) {
return fire(player, stack, null, null);
}

@Override
public PowerResult<Void> fire(Player player, ItemStack stack, LivingEntity entity, Double damage) {
if (!checkCooldownByString(this, player, cooldownKey, cooldown, showCDWarning, false)) return PowerResult.of(cooldownResult);
if (!checkCooldownByString(this, player, cooldownKey, cooldown, showCDWarning, false))
return PowerResult.of(cooldownResult);
int damageCost = cost;
if (damage != null && costByDamage) {
if (damage < 0) damage = 0d;
Expand Down Expand Up @@ -140,19 +147,22 @@ public String displayText() {

@Override
public PowerResult<Double> hit(Player player, ItemStack stack, LivingEntity entity, double damage, EntityDamageByEntityEvent event) {
return fire(player, stack).with(damage);
return fire(player, stack, entity, damage).with(damage);
}

@Override
public PowerResult<Double> takeHit(Player target, ItemStack stack, double damage, EntityDamageEvent event) {
return fire(target, stack).with(damage);
return fire(target, stack, null, damage).with(damage);
}

@Override
public PowerResult<Void> hurt(Player target, ItemStack stack, EntityDamageEvent event) {
return fire(target, stack);
if (!requireHurtByEntity || event instanceof EntityDamageByEntityEvent) {
return fire(target, stack, null, event.getDamage());
}
return PowerResult.noop();
}

@Override
public PowerResult<Void> offhandClick(Player player, ItemStack stack, PlayerInteractEvent event) {
return fire(player, stack);
Expand Down

0 comments on commit 6eb1fb2

Please sign in to comment.