Skip to content

Commit

Permalink
Fix /npc age for zombies
Browse files Browse the repository at this point in the history
  • Loading branch information
fullwall committed Apr 2, 2017
1 parent 7e6cf4f commit 5552bff
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
5 changes: 3 additions & 2 deletions main/src/main/java/net/citizensnpcs/commands/NPCCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
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;
Expand Down Expand Up @@ -114,8 +115,8 @@ public NPCCommands(Citizens plugin) {
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');
Expand Down
12 changes: 10 additions & 2 deletions main/src/main/java/net/citizensnpcs/trait/Age.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

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;
Expand Down Expand Up @@ -36,8 +37,12 @@ public void onSpawn() {
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
Expand All @@ -51,14 +56,17 @@ public void setAge(int age) {
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;
}

Expand Down

0 comments on commit 5552bff

Please sign in to comment.