diff --git a/nms-patches/EntityFox.patch b/nms-patches/EntityFox.patch index 5256c140db..d003fa640b 100644 --- a/nms-patches/EntityFox.patch +++ b/nms-patches/EntityFox.patch @@ -1,5 +1,16 @@ --- a/net/minecraft/server/EntityFox.java +++ b/net/minecraft/server/EntityFox.java +@@ -17,8 +17,8 @@ + + private static final DataWatcherObject bw = DataWatcher.a(EntityFox.class, DataWatcherRegistry.b); + private static final DataWatcherObject bx = DataWatcher.a(EntityFox.class, DataWatcherRegistry.a); +- private static final DataWatcherObject> by = DataWatcher.a(EntityFox.class, DataWatcherRegistry.o); +- private static final DataWatcherObject> bz = DataWatcher.a(EntityFox.class, DataWatcherRegistry.o); ++ public static final DataWatcherObject> by = DataWatcher.a(EntityFox.class, DataWatcherRegistry.o); ++ public static final DataWatcherObject> bz = DataWatcher.a(EntityFox.class, DataWatcherRegistry.o); + private static final Predicate bA = (entityitem) -> { + return !entityitem.p() && entityitem.isAlive(); + }; @@ -263,8 +263,8 @@ private List eE() { List list = Lists.newArrayList(); diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftFox.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftFox.java index 2e2c253f4a..b6b41dbeec 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftFox.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftFox.java @@ -1,8 +1,11 @@ package org.bukkit.craftbukkit.entity; import com.google.common.base.Preconditions; +import java.util.Optional; +import java.util.UUID; import net.minecraft.server.EntityFox; import org.bukkit.craftbukkit.CraftServer; +import org.bukkit.entity.AnimalTamer; import org.bukkit.entity.EntityType; import org.bukkit.entity.Fox; @@ -63,4 +66,52 @@ public class CraftFox extends CraftAnimals implements Fox { public void setSleeping(boolean sleeping) { getHandle().setSleeping(sleeping); } + + @Override + public AnimalTamer getFirstTrustedPlayer() { + UUID uuid = getHandle().getDataWatcher().get(EntityFox.by).orElse(null); + if (uuid == null) { + return null; + } + + AnimalTamer player = getServer().getPlayer(uuid); + if (player == null) { + player = getServer().getOfflinePlayer(uuid); + } + + return player; + } + + @Override + public void setFirstTrustedPlayer(AnimalTamer player) { + if (player == null && getHandle().getDataWatcher().get(EntityFox.bz).isPresent()) { + throw new IllegalStateException("Must remove second trusted player first"); + } + + getHandle().getDataWatcher().set(EntityFox.by, player == null ? Optional.empty() : Optional.of(player.getUniqueId())); + } + + @Override + public AnimalTamer getSecondTrustedPlayer() { + UUID uuid = getHandle().getDataWatcher().get(EntityFox.bz).orElse(null); + if (uuid == null) { + return null; + } + + AnimalTamer player = getServer().getPlayer(uuid); + if (player == null) { + player = getServer().getOfflinePlayer(uuid); + } + + return player; + } + + @Override + public void setSecondTrustedPlayer(AnimalTamer player) { + if (player != null && !getHandle().getDataWatcher().get(EntityFox.by).isPresent()) { + throw new IllegalStateException("Must add first trusted player first"); + } + + getHandle().getDataWatcher().set(EntityFox.bz, player == null ? Optional.empty() : Optional.of(player.getUniqueId())); + } }