Skip to content

Commit

Permalink
Do not count non-creatures damage
Browse files Browse the repository at this point in the history
  • Loading branch information
Krakenied authored and LMBishop committed May 5, 2022
1 parent af8470a commit ec20c79
Showing 1 changed file with 12 additions and 4 deletions.
Expand Up @@ -9,6 +9,7 @@
import com.leonardobishop.quests.common.player.questprogressfile.TaskProgress;
import com.leonardobishop.quests.common.quest.Quest;
import com.leonardobishop.quests.common.quest.Task;
import org.bukkit.entity.Creature;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
Expand All @@ -33,17 +34,18 @@ public DealDamageTaskType(BukkitQuestsPlugin plugin) {
ArrayList<ConfigProblem> problems = new ArrayList<>();
if (TaskUtils.configValidateExists(root + ".amount", config.get("amount"), problems, "amount", super.getType()))
TaskUtils.configValidateInt(root + ".amount", config.get("amount"), problems, false, true, "amount");
TaskUtils.configValidateBoolean(root + ".allow-only-creatures", config.get("allow-only-creatures"), problems, true, "allow-only-creatures");
return problems;
}

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onDamage(EntityDamageByEntityEvent e) {
if (!(e.getDamager() instanceof Player)) {
public void onDamage(EntityDamageByEntityEvent event) {
if (!(event.getDamager() instanceof Player)) {
return;
}

Player player = (Player) e.getDamager();
double damage = e.getDamage();
Player player = (Player) event.getDamager();
double damage = event.getDamage();

if (player.hasMetadata("NPC")) return;

Expand All @@ -65,6 +67,12 @@ public void onDamage(EntityDamageByEntityEvent e) {
continue;
}

// Do not count non-creatures damage (e.g. ArmorStands)
boolean allowOnlyCreatures = (boolean) task.getConfigValue("allow-only-creatures", true);
if (allowOnlyCreatures && !(event.getEntity() instanceof Creature)) {
continue;
}

double progressDamage;
int damageNeeded = (int) task.getConfigValue("amount");

Expand Down

0 comments on commit ec20c79

Please sign in to comment.