Skip to content

Commit

Permalink
EntityTag.shooter: include TNT source
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Jun 13, 2022
1 parent 5d51c2b commit 57d96d9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
Expand Up @@ -48,6 +48,7 @@
import org.bukkit.loot.LootTable;
import org.bukkit.loot.Lootable;
import org.bukkit.potion.*;
import org.bukkit.projectiles.ProjectileSource;
import org.bukkit.util.RayTraceResult;
import org.bukkit.util.Vector;

Expand Down Expand Up @@ -672,23 +673,32 @@ public boolean isProjectile() {
}

public EntityTag getShooter() {
if (hasShooter()) {
return new EntityTag((LivingEntity) getProjectile().getShooter());
if (getBukkitEntity() instanceof TNTPrimed) {
Entity source = ((TNTPrimed) getBukkitEntity()).getSource();
if (source != null) {
return new EntityTag(source);
}
}
else {
return null;
else if (isProjectile()) {
ProjectileSource shooter = getProjectile().getShooter();
if (shooter instanceof Entity) {
return new EntityTag((Entity) shooter);
}
}
return null;
}

public void setShooter(EntityTag shooter) {
if (isProjectile() && shooter.isLivingEntity()) {
if (getBukkitEntity() instanceof TNTPrimed) {
((TNTPrimed) getBukkitEntity()).setSource(shooter.getBukkitEntity());
}
else if (isProjectile() && shooter.isLivingEntity()) {
getProjectile().setShooter(shooter.getLivingEntity());
}
}

public boolean hasShooter() {
return isProjectile() && getProjectile().getShooter() != null && getProjectile().getShooter() instanceof LivingEntity;
// TODO: Handle other shooter source thingy types
return getShooter() != null;
}

public Inventory getBukkitInventory() {
Expand Down Expand Up @@ -1820,7 +1830,7 @@ else if (mtr.angle == BlockFace.EAST) {
// @mechanism EntityTag.shooter
// @synonyms EntityTag.arrow_firer,EntityTag.fishhook_shooter,EntityTag.snowball_thrower
// @description
// Returns the projectile's shooter, if any.
// Returns the projectile's shooter or TNT's priming source, if any.
// -->
registerSpawnedOnlyTag(EntityFormObject.class, "shooter", (attribute, object) -> {
EntityTag shooter = object.getShooter();
Expand Down Expand Up @@ -3043,7 +3053,7 @@ public void adjust(Mechanism mechanism) {
// @input EntityTag
// @synonyms EntityTag.arrow_firer,EntityTag.fishhook_shooter,EntityTag.snowball_thrower
// @description
// Sets the projectile's shooter.
// Sets the projectile's shooter or TNT's priming source.
// @tags
// <EntityTag.shooter>
// -->
Expand Down
Expand Up @@ -374,6 +374,7 @@ public static void registerTags() {
// @group conversion
// @description
// Shortens the element down to an itemscript hash ID, made of invisible color codes.
// This is considered a historical system, no longer relevant to modern Denizen.
// -->
PropertyParser.<BukkitElementProperties, ElementTag>registerTag(ElementTag.class, "to_itemscript_hash", (attribute, object) -> {
return new ElementTag(ItemScriptHelper.createItemScriptID(object.asString()));
Expand Down

0 comments on commit 57d96d9

Please sign in to comment.