Skip to content

Commit

Permalink
Merge pull request #810 from gundom0802/main
Browse files Browse the repository at this point in the history
Added lastdamagecause.attacker and changed signature in getTargetName to Entity
  • Loading branch information
Chronoken authored Dec 14, 2023
2 parents f798834 + c83210a commit 8db69b7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
5 changes: 4 additions & 1 deletion core/src/main/java/com/nisovin/magicspells/MagicSpells.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

import org.bukkit.*;
import org.bukkit.event.Event;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.entity.EntityType;
Expand Down Expand Up @@ -1704,9 +1705,11 @@ public static boolean requireReplacement(String message) {
return matcher.find();
}

public static String getTargetName(LivingEntity target) {
public static String getTargetName(Entity target) {
if (target instanceof Player) return target.getName();

if (target.customName() != null) return Util.getStrictStringFromComponent(target.customName());

EntityType type = target.getType();
String name = plugin.entityNames.get(type);
if (name != null) return name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
import org.bukkit.entity.Entity;
import org.bukkit.entity.SpawnCategory;
import org.bukkit.command.CommandSender;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent;

import com.nisovin.magicspells.util.Util;
import org.bukkit.event.entity.EntityDamageEvent;
import com.nisovin.magicspells.MagicSpells;

public class DataEntity {

Expand Down Expand Up @@ -41,6 +43,10 @@ public class DataEntity {
EntityDamageEvent event = entity.getLastDamageCause();
return event == null ? "" : event.getDamage() + "";
});
dataElements.put("lastdamagecause.attacker", entity -> {
if (!(entity.getLastDamageCause() instanceof EntityDamageByEntityEvent event)) return "";
return MagicSpells.getTargetName(event.getDamager());
});
dataElements.put("velocity", entity -> entity.getVelocity().toString());
dataElements.put("velocity.x", entity -> entity.getVelocity().getX() + "");
dataElements.put("velocity.y", entity -> entity.getVelocity().getY() + "");
Expand Down

0 comments on commit 8db69b7

Please sign in to comment.