Add new zombiemodifier for professions

This commit is contained in:
fullwall 2016-07-20 00:49:00 +08:00
parent 212157d509
commit 495e8ad286
4 changed files with 29 additions and 4 deletions

View File

@ -1969,7 +1969,7 @@ public class NPCCommands {
@Command(
aliases = { "npc" },
usage = "zombiemod (-b(aby), -v(illager))",
usage = "zombiemod (-b(aby), -v(illager) --p(rofession) [profession])",
desc = "Sets a zombie NPC to be a baby or villager",
modifiers = { "zombie", "zombiemod" },
flags = "bv",
@ -1988,5 +1988,14 @@ public class NPCCommands {
Messaging.sendTr(sender, isVillager ? Messages.ZOMBIE_VILLAGER_SET : Messages.ZOMBIE_VILLAGER_UNSET,
npc.getName());
}
if (args.hasValueFlag("profession") || args.hasValueFlag("p")) {
Profession profession = Util.matchEnum(Profession.values(), args.getFlag("profession", args.getFlag("p")));
if (profession == null) {
throw new CommandException();
}
trait.setProfession(profession);
Messaging.sendTr(sender, Messages.ZOMBIE_VILLAGER_PROFESSION_SET, npc.getName(),
Util.prettyEnum(profession));
}
}
}

View File

@ -1,5 +1,6 @@
package net.citizensnpcs.trait;
import org.bukkit.entity.Villager.Profession;
import org.bukkit.entity.Zombie;
import net.citizensnpcs.api.persistence.Persist;
@ -11,6 +12,8 @@ public class ZombieModifier extends Trait {
@Persist
private boolean baby;
@Persist
private Profession profession;
@Persist
private boolean villager;
private boolean zombie;
@ -23,22 +26,33 @@ public class ZombieModifier extends Trait {
if (npc.getEntity() instanceof Zombie) {
((Zombie) npc.getEntity()).setVillager(villager);
((Zombie) npc.getEntity()).setBaby(baby);
((Zombie) npc.getEntity()).setVillagerProfession(profession);
zombie = true;
} else
} else {
zombie = false;
}
}
public void setProfession(Profession profession) {
this.profession = profession;
if (zombie) {
((Zombie) npc.getEntity()).setVillagerProfession(profession);
}
}
public boolean toggleBaby() {
baby = !baby;
if (zombie)
if (zombie) {
((Zombie) npc.getEntity()).setBaby(baby);
}
return baby;
}
public boolean toggleVillager() {
villager = !villager;
if (zombie)
if (zombie) {
((Zombie) npc.getEntity()).setVillager(villager);
}
return villager;
}
}

View File

@ -281,6 +281,7 @@ public class Messages {
public static final String WRITING_DEFAULT_SETTING = "citizens.settings.writing-default";
public static final String ZOMBIE_BABY_SET = "citizens.commands.npc.zombiemod.baby-set";
public static final String ZOMBIE_BABY_UNSET = "citizens.commands.npc.zombiemod.baby-unset";
public static final String ZOMBIE_VILLAGER_PROFESSION_SET = "citizens.commands.npc.zombiemod.villager-profession-set";
public static final String ZOMBIE_VILLAGER_SET = "citizens.commands.npc.zombiemod.villager-set";
public static final String ZOMBIE_VILLAGER_UNSET = "citizens.commands.npc.zombiemod.villager-unset";
}

View File

@ -142,6 +142,7 @@ citizens.commands.npc.zombiemod.villager-set=[[{0}]] is now a villager.
citizens.commands.npc.zombiemod.villager-unset=[[{0}]] is no longer a villager.
citizens.commands.npc.zombiemod.baby-set=[[{0}]] is now a baby.
citizens.commands.npc.zombiemod.baby-unset=[[{0}]] is no longer a baby.
citizens.commands.npc.zombiemod.villager-profession-set=[[{0}]]''s profession set to [[{1}]].
citizens.commands.page-missing=The page [[{0}]] does not exist.
citizens.commands.requirements.disallowed-mobtype=The NPC cannot be the mob type [[{0}]] for that command.
citizens.commands.requirements.living-entity=The NPC must be a living entity.