Skip to content

Commit ad6d5af

Browse files
committed
Treat tameables with offline owners as unknown causes.
Paper-only. Closes #1900.
1 parent 7ae7a04 commit ad6d5af

File tree

1 file changed

+25
-2
lines changed
  • worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/cause

1 file changed

+25
-2
lines changed

worldguard-bukkit/src/main/java/com/sk89q/worldguard/bukkit/cause/Cause.java

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@
2727
import com.sk89q.worldguard.bukkit.util.Entities;
2828
import io.papermc.lib.PaperLib;
2929
import org.bukkit.Bukkit;
30+
import org.bukkit.OfflinePlayer;
3031
import org.bukkit.block.Block;
32+
import org.bukkit.entity.AnimalTamer;
3133
import org.bukkit.entity.AreaEffectCloud;
3234
import org.bukkit.entity.Creature;
3335
import org.bukkit.entity.Entity;
@@ -107,6 +109,12 @@ public boolean isKnown() {
107109
return false;
108110
}
109111

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+
110118
if (object instanceof TNTPrimed || object instanceof Vehicle) {
111119
if (!PaperLib.isPaper()) {
112120
return false;
@@ -300,9 +308,24 @@ private void addAll(@Nullable Object... element) {
300308
} else if (o instanceof AreaEffectCloud) {
301309
indirect = true;
302310
addAll(((AreaEffectCloud) o).getSource());
303-
} else if (o instanceof Tameable) {
311+
} else if (o instanceof Tameable tameable) {
304312
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+
}
306329
} else if (o instanceof Creature && ((Creature) o).getTarget() != null) {
307330
indirect = true;
308331
addAll(((Creature) o).getTarget());

0 commit comments

Comments
 (0)