diff --git a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/cause/Cause.java b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/cause/Cause.java index 0c6003c3..f3847b33 100644 --- a/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/cause/Cause.java +++ b/worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/cause/Cause.java @@ -27,7 +27,9 @@ import com.sk89q.worldguard.bukkit.internal.WGMetadata; import com.sk89q.worldguard.bukkit.util.Entities; import io.papermc.lib.PaperLib; import org.bukkit.Bukkit; +import org.bukkit.OfflinePlayer; import org.bukkit.block.Block; +import org.bukkit.entity.AnimalTamer; import org.bukkit.entity.AreaEffectCloud; import org.bukkit.entity.Creature; import org.bukkit.entity.Entity; @@ -107,6 +109,12 @@ public final class Cause { return false; } + if (object instanceof Tameable tameable && tameable.isTamed()) { + // if they're tamed but also the root cause, the owner is offline + // otherwise the owner will be the root cause (and known) + return false; + } + if (object instanceof TNTPrimed || object instanceof Vehicle) { if (!PaperLib.isPaper()) { return false; @@ -300,9 +308,24 @@ public final class Cause { } else if (o instanceof AreaEffectCloud) { indirect = true; addAll(((AreaEffectCloud) o).getSource()); - } else if (o instanceof Tameable) { + } else if (o instanceof Tameable tameable) { indirect = true; - addAll(((Tameable) o).getOwner()); + if (PaperLib.isPaper()) { + UUID ownerId = tameable.getOwnerUniqueId(); + if (ownerId != null) { + Player owner = Bukkit.getPlayer(ownerId); + if (owner != null) { + addAll(owner); + } + } + } else { + // this will cause offline player loads if the player is offline + // too bad for spigot users + AnimalTamer owner = tameable.getOwner(); + if (owner instanceof OfflinePlayer player) { + addAll(player.getPlayer()); // player object if online, else null + } + } } else if (o instanceof Creature && ((Creature) o).getTarget() != null) { indirect = true; addAll(((Creature) o).getTarget());