|
27 | 27 | import com.sk89q.worldguard.bukkit.util.Entities; |
28 | 28 | import io.papermc.lib.PaperLib; |
29 | 29 | import org.bukkit.Bukkit; |
| 30 | +import org.bukkit.OfflinePlayer; |
30 | 31 | import org.bukkit.block.Block; |
| 32 | +import org.bukkit.entity.AnimalTamer; |
31 | 33 | import org.bukkit.entity.AreaEffectCloud; |
32 | 34 | import org.bukkit.entity.Creature; |
33 | 35 | import org.bukkit.entity.Entity; |
@@ -107,6 +109,12 @@ public boolean isKnown() { |
107 | 109 | return false; |
108 | 110 | } |
109 | 111 |
|
| 112 | + if (object instanceof Tameable tameable && tameable.isTamed()) { |
| 113 | + // if they're tamed but also the root cause, the owner is offline |
| 114 | + // otherwise the owner will be the root cause (and known) |
| 115 | + return false; |
| 116 | + } |
| 117 | + |
110 | 118 | if (object instanceof TNTPrimed || object instanceof Vehicle) { |
111 | 119 | if (!PaperLib.isPaper()) { |
112 | 120 | return false; |
@@ -300,9 +308,24 @@ private void addAll(@Nullable Object... element) { |
300 | 308 | } else if (o instanceof AreaEffectCloud) { |
301 | 309 | indirect = true; |
302 | 310 | addAll(((AreaEffectCloud) o).getSource()); |
303 | | - } else if (o instanceof Tameable) { |
| 311 | + } else if (o instanceof Tameable tameable) { |
304 | 312 | indirect = true; |
305 | | - addAll(((Tameable) o).getOwner()); |
| 313 | + if (PaperLib.isPaper()) { |
| 314 | + UUID ownerId = tameable.getOwnerUniqueId(); |
| 315 | + if (ownerId != null) { |
| 316 | + Player owner = Bukkit.getPlayer(ownerId); |
| 317 | + if (owner != null) { |
| 318 | + addAll(owner); |
| 319 | + } |
| 320 | + } |
| 321 | + } else { |
| 322 | + // this will cause offline player loads if the player is offline |
| 323 | + // too bad for spigot users |
| 324 | + AnimalTamer owner = tameable.getOwner(); |
| 325 | + if (owner instanceof OfflinePlayer player) { |
| 326 | + addAll(player.getPlayer()); // player object if online, else null |
| 327 | + } |
| 328 | + } |
306 | 329 | } else if (o instanceof Creature && ((Creature) o).getTarget() != null) { |
307 | 330 | indirect = true; |
308 | 331 | addAll(((Creature) o).getTarget()); |
|
0 commit comments