Fix /npc age for zombies

This commit is contained in:
fullwall 2017-04-03 01:18:13 +08:00
parent 7e6cf4f7cd
commit 5552bff4cf
2 changed files with 13 additions and 4 deletions

View File

@ -30,6 +30,7 @@ import org.bukkit.entity.Ocelot;
import org.bukkit.entity.Player;
import org.bukkit.entity.Rabbit;
import org.bukkit.entity.Villager.Profession;
import org.bukkit.entity.Zombie;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
import com.google.common.base.Joiner;
@ -114,8 +115,8 @@ public class NPCCommands {
max = 2,
permission = "citizens.npc.age")
public void age(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
if (!npc.isSpawned() || !(npc.getEntity() instanceof Ageable))
throw new CommandException(Messages.MOBTYPE_CANNOT_BE_AGED);
if (!npc.isSpawned() || (!(npc.getEntity() instanceof Ageable) && !(npc.getEntity() instanceof Zombie)))
throw new CommandException(Messages.MOBTYPE_CANNOT_BE_AGED, npc.getName());
Age trait = npc.getTrait(Age.class);
boolean toggleLock = args.hasFlag('l');

View File

@ -2,6 +2,7 @@ package net.citizensnpcs.trait;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Ageable;
import org.bukkit.entity.Zombie;
import net.citizensnpcs.api.persistence.Persist;
import net.citizensnpcs.api.trait.Trait;
@ -36,8 +37,12 @@ public class Age extends Trait implements Toggleable {
entity.setAge(age);
entity.setAgeLock(locked);
ageable = entity;
} else
} else if (npc.getEntity() instanceof Zombie) {
((Zombie) npc.getEntity()).setBaby(age < 0);
ageable = null;
} else {
ageable = null;
}
}
@Override
@ -51,14 +56,17 @@ public class Age extends Trait implements Toggleable {
this.age = age;
if (isAgeable()) {
ageable.setAge(age);
} else if (npc.getEntity() instanceof Zombie) {
((Zombie) npc.getEntity()).setBaby(age < 0);
}
}
@Override
public boolean toggle() {
locked = !locked;
if (isAgeable())
if (isAgeable()) {
ageable.setAgeLock(locked);
}
return locked;
}