SPIGOT-5413: Add TrustedPlayer API for foxes

This commit is contained in:
md_5 2019-12-23 12:34:53 +11:00
parent 062680a826
commit 817116de01
2 changed files with 62 additions and 0 deletions

View file

@ -1,5 +1,16 @@
--- a/net/minecraft/server/EntityFox.java
+++ b/net/minecraft/server/EntityFox.java
@@ -17,8 +17,8 @@
private static final DataWatcherObject<Integer> bw = DataWatcher.a(EntityFox.class, DataWatcherRegistry.b);
private static final DataWatcherObject<Byte> bx = DataWatcher.a(EntityFox.class, DataWatcherRegistry.a);
- private static final DataWatcherObject<Optional<UUID>> by = DataWatcher.a(EntityFox.class, DataWatcherRegistry.o);
- private static final DataWatcherObject<Optional<UUID>> bz = DataWatcher.a(EntityFox.class, DataWatcherRegistry.o);
+ public static final DataWatcherObject<Optional<UUID>> by = DataWatcher.a(EntityFox.class, DataWatcherRegistry.o);
+ public static final DataWatcherObject<Optional<UUID>> bz = DataWatcher.a(EntityFox.class, DataWatcherRegistry.o);
private static final Predicate<EntityItem> bA = (entityitem) -> {
return !entityitem.p() && entityitem.isAlive();
};
@@ -263,8 +263,8 @@
private List<UUID> eE() {
List<UUID> list = Lists.newArrayList();

View file

@ -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()));
}
}