geforkt von Mirrors/Paper
AnimalTamer implementations, refactor and clean-up of code
Dieser Commit ist enthalten in:
Ursprung
02d7f32e8f
Commit
83eecfbd4e
@ -3,10 +3,14 @@ package org.bukkit.craftbukkit.entity;
|
|||||||
|
|
||||||
import net.minecraft.server.EntityWolf;
|
import net.minecraft.server.EntityWolf;
|
||||||
import org.bukkit.craftbukkit.CraftServer;
|
import org.bukkit.craftbukkit.CraftServer;
|
||||||
|
import org.bukkit.entity.AnimalTamer;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.entity.Wolf;
|
import org.bukkit.entity.Wolf;
|
||||||
import net.minecraft.server.PathEntity;
|
import net.minecraft.server.PathEntity;
|
||||||
|
|
||||||
public class CraftWolf extends CraftAnimals implements Wolf {
|
public class CraftWolf extends CraftAnimals implements Wolf {
|
||||||
|
private AnimalTamer owner;
|
||||||
|
|
||||||
public CraftWolf(CraftServer server, EntityWolf wolf) {
|
public CraftWolf(CraftServer server, EntityWolf wolf) {
|
||||||
super(server, wolf);
|
super(server, wolf);
|
||||||
}
|
}
|
||||||
@ -25,41 +29,85 @@ public class CraftWolf extends CraftAnimals implements Wolf {
|
|||||||
|
|
||||||
public void setSitting(boolean sitting) {
|
public void setSitting(boolean sitting) {
|
||||||
getHandle().setSitting(sitting);
|
getHandle().setSitting(sitting);
|
||||||
|
// TODO determine what the following would do - it is affected every time a player makes their wolf sit or stand
|
||||||
|
//getHandle().ay = false;
|
||||||
|
setPath((PathEntity) null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isTame() {
|
public boolean isTamed() {
|
||||||
return getHandle().m_();
|
return getHandle().m_();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTame(boolean tame) {
|
public void setTamed(boolean tame) {
|
||||||
getHandle().d(tame);
|
getHandle().d(tame);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getOwner() {
|
public AnimalTamer getOwner() {
|
||||||
|
// If the wolf has a previously set owner use that, otherwise try and find the player who owns it
|
||||||
|
if (owner == null) {
|
||||||
|
// TODO try and recover owner from persistence store before defaulting to playername
|
||||||
|
owner = getServer().getPlayer(getOwnerName());
|
||||||
|
}
|
||||||
|
return owner;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOwner(AnimalTamer tamer) {
|
||||||
|
owner = tamer;
|
||||||
|
if (owner != null) {
|
||||||
|
setTamed(true); /* Make him tame */
|
||||||
|
setPath((PathEntity) null); /* Clear path */
|
||||||
|
/* Set owner */
|
||||||
|
// TODO persist owner to the persistence store
|
||||||
|
if (owner instanceof Player) {
|
||||||
|
setOwnerName(((Player) owner).getName());
|
||||||
|
} else {
|
||||||
|
setOwnerName("");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
setTamed(false); /* Make him not tame */
|
||||||
|
setOwnerName(""); /* Clear owner */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The owner's name is how MC knows and persists the Wolf's owner. Since we choose to instead use an AnimalTamer, this functionality
|
||||||
|
* is used only as a backup. If the animal tamer is a player, we will store their name, otherwise we store an empty string.
|
||||||
|
* @return the owner's name, if they are a player; otherwise, the empty string or null.
|
||||||
|
*/
|
||||||
|
String getOwnerName() {
|
||||||
return getHandle().x();
|
return getHandle().x();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setOwner(String player) {
|
void setOwnerName(String ownerName) {
|
||||||
EntityWolf e = getHandle();
|
getHandle().a(ownerName);
|
||||||
|
}
|
||||||
|
|
||||||
if ((player != null) && (player.length() > 0)) {
|
/**
|
||||||
e.d(true); /* Make him tame */
|
* Only used internally at the moment, and there to set the path to null (that is stop the thing from running around)
|
||||||
e.a((PathEntity)null); /* Clear path */
|
* TODO use this later to extend the API, when we have Path classes in Bukkit
|
||||||
e.a(player); /* Set owner */
|
* @param pathentity currently the MC defined PathEntity class. Should be replaced with an API interface at some point.
|
||||||
}
|
*/
|
||||||
else {
|
private void setPath(PathEntity pathentity) {
|
||||||
e.d(false); /* Make him not tame */
|
getHandle().a(pathentity);
|
||||||
e.a(""); /* Clear owner */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This method requires a(boolean) to be made visible. It will allow for hearts to be animated on a successful taming.
|
||||||
|
* TODO add this to the API, and make it visible
|
||||||
|
private void playTamingAnimation(boolean successful){
|
||||||
|
getHandle().a(successful);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EntityWolf getHandle() {
|
public EntityWolf getHandle() {
|
||||||
|
// It's somewhat easier to override this here, as many internal methods rely on EntityWolf specific methods.
|
||||||
|
// Doing this has no impact on anything outside this class.
|
||||||
return (EntityWolf) entity;
|
return (EntityWolf) entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "CraftWolf[anger=" + isAngry() + ",owner=" + getOwner() + ",tame=" + isTame() + ",sitting=" + isSitting() + "]";
|
return "CraftWolf[anger=" + isAngry() + ",owner=" + getOwner() + ",tame=" + isTamed() + ",sitting=" + isSitting() + "]";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren