Add /npc zombiemod (-bv)

This commit is contained in:
fullwall 2012-12-10 11:13:51 +08:00
parent 929256c61a
commit 4858bf2958
5 changed files with 110 additions and 33 deletions

View File

@ -39,6 +39,7 @@ import net.citizensnpcs.trait.Poses;
import net.citizensnpcs.trait.Powered; import net.citizensnpcs.trait.Powered;
import net.citizensnpcs.trait.SlimeSize; import net.citizensnpcs.trait.SlimeSize;
import net.citizensnpcs.trait.VillagerProfession; import net.citizensnpcs.trait.VillagerProfession;
import net.citizensnpcs.trait.ZombieModifier;
import net.citizensnpcs.util.Anchor; import net.citizensnpcs.util.Anchor;
import net.citizensnpcs.util.Messages; import net.citizensnpcs.util.Messages;
import net.citizensnpcs.util.Messaging; import net.citizensnpcs.util.Messaging;
@ -613,16 +614,16 @@ public class NPCCommands {
} }
@Command(aliases = { "npc" }, desc = "Show basic NPC information", max = 0, permission = "npc.info") @Command(aliases = { "npc" }, desc = "Show basic NPC information", max = 0, permission = "npc.info")
public void npc(CommandContext args, CommandSender sender, final NPC npc) { public void npc(CommandContext args, CommandSender sender, NPC npc) {
Messaging.send(sender, StringHelper.wrapHeader(npc.getName())); Messaging.send(sender, StringHelper.wrapHeader(npc.getName()));
Messaging.send(sender, " <a>ID: <e>" + npc.getId()); Messaging.send(sender, " <a>ID: <e>" + npc.getId());
Messaging.send(sender, " <a>Type: <e>" + npc.getTrait(MobType.class).getType()); Messaging.send(sender, " <a>Type: <e>" + npc.getTrait(MobType.class).getType());
if (npc.isSpawned()) if (npc.isSpawned()) {
Messaging.send(sender, " <a>Spawned at: <e>" + Location loc = npc.getBukkitEntity().getLocation();
"X: " + npc.getBukkitEntity().getLocation().getBlockX() + String format = " <a>Spawned at: <e> %d, %d, %d in world %s";
" Y: " + npc.getBukkitEntity().getLocation().getBlockY() + Messaging.send(sender, String.format(format, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(),
" Z: " + npc.getBukkitEntity().getLocation().getBlockZ() + loc.getWorld().getName()));
" in world " + npc.getBukkitEntity().getLocation().getWorld().getName()); }
Messaging.send(sender, " <a>Traits<e>"); Messaging.send(sender, " <a>Traits<e>");
for (Trait trait : npc.getTraits()) { for (Trait trait : npc.getTraits()) {
if (CitizensAPI.getTraitFactory().isInternalTrait(trait)) if (CitizensAPI.getTraitFactory().isInternalTrait(trait))
@ -1034,4 +1035,28 @@ public class NPCCommands {
String key = vulnerable ? Messages.VULNERABLE_STOPPED : Messages.VULNERABLE_SET; String key = vulnerable ? Messages.VULNERABLE_STOPPED : Messages.VULNERABLE_SET;
Messaging.sendTr(sender, key, npc.getName()); Messaging.sendTr(sender, key, npc.getName());
} }
@Command(
aliases = { "npc" },
usage = "zombiemod (-b, -v)",
desc = "Sets the modifiers of a zombie",
modifiers = { "zombiemod" },
flags = "bv",
min = 1,
max = 1,
permission = "npc.zombiemodifier")
@Requirements(selected = true, ownership = true, types = EntityType.ZOMBIE)
public void zombieModifier(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
ZombieModifier trait = npc.getTrait(ZombieModifier.class);
if (args.hasFlag('b')) {
boolean isBaby = trait.toggleBaby();
Messaging.sendTr(sender, isBaby ? Messages.ZOMBIE_BABY_SET : Messages.ZOMBIE_BABY_UNSET,
npc.getName());
}
if (args.hasFlag('v')) {
boolean isVillager = trait.toggleVillager();
Messaging.sendTr(sender, isVillager ? Messages.ZOMBIE_VILLAGER_SET
: Messages.ZOMBIE_VILLAGER_UNSET, npc.getName());
}
}
} }

View File

@ -30,6 +30,7 @@ import net.citizensnpcs.trait.Sheared;
import net.citizensnpcs.trait.SlimeSize; import net.citizensnpcs.trait.SlimeSize;
import net.citizensnpcs.trait.VillagerProfession; import net.citizensnpcs.trait.VillagerProfession;
import net.citizensnpcs.trait.WoolColor; import net.citizensnpcs.trait.WoolColor;
import net.citizensnpcs.trait.ZombieModifier;
import net.citizensnpcs.trait.text.Text; import net.citizensnpcs.trait.text.Text;
import net.citizensnpcs.trait.waypoint.Waypoints; import net.citizensnpcs.trait.waypoint.Waypoints;
@ -63,6 +64,7 @@ public class CitizensTraitFactory implements TraitFactory {
registerTrait(TraitInfo.create(MobType.class).withName("type")); registerTrait(TraitInfo.create(MobType.class).withName("type"));
registerTrait(TraitInfo.create(Waypoints.class).withName("waypoints")); registerTrait(TraitInfo.create(Waypoints.class).withName("waypoints"));
registerTrait(TraitInfo.create(WoolColor.class).withName("woolcolor")); registerTrait(TraitInfo.create(WoolColor.class).withName("woolcolor"));
registerTrait(TraitInfo.create(ZombieModifier.class).withName("zombiemodifier"));
for (String trait : registered.keySet()) for (String trait : registered.keySet())
INTERNAL_TRAITS.add(trait); INTERNAL_TRAITS.add(trait);

View File

@ -0,0 +1,42 @@
package net.citizensnpcs.trait;
import net.citizensnpcs.api.persistence.Persist;
import net.citizensnpcs.api.trait.Trait;
import org.bukkit.entity.Zombie;
public class ZombieModifier extends Trait {
@Persist
private boolean baby;
@Persist
private boolean villager;
private boolean zombie;
public ZombieModifier() {
super("zombiemodifier");
}
@Override
public void onSpawn() {
if (npc.getBukkitEntity() instanceof Zombie) {
((Zombie) npc.getBukkitEntity()).setVillager(villager);
((Zombie) npc.getBukkitEntity()).setBaby(baby);
zombie = true;
} else
zombie = false;
}
public boolean toggleBaby() {
baby = !baby;
if (zombie)
((Zombie) npc.getBukkitEntity()).setBaby(baby);
return baby;
}
public boolean toggleVillager() {
villager = !villager;
if (zombie)
((Zombie) npc.getBukkitEntity()).setVillager(villager);
return villager;
}
}

View File

@ -210,4 +210,8 @@ public class Messages {
public static final String WAYPOINT_TRIGGER_TELEPORT_PROMPT = "citizens.editors.waypoints.triggers.teleport.prompt"; public static final String WAYPOINT_TRIGGER_TELEPORT_PROMPT = "citizens.editors.waypoints.triggers.teleport.prompt";
public static final String WORLD_NOT_FOUND = "citizens.commands.errors.missing-world"; public static final String WORLD_NOT_FOUND = "citizens.commands.errors.missing-world";
public static final String WRITING_DEFAULT_SETTING = "citizens.settings.writing-default"; 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_SET = "citizens.commands.npc.zombiemod.villager-set";
public static final String ZOMBIE_VILLAGER_UNSET = "citizens.commands.npc.zombiemod.villager-unset";
} }

View File

@ -82,6 +82,10 @@ citizens.commands.npc.type.set=[[{0}]]''s type set to [[{1}]].
citizens.commands.npc.type.invalid=[[{0}]] is not a valid type. citizens.commands.npc.type.invalid=[[{0}]] is not a valid type.
citizens.commands.npc.vulnerable.set=[[{0}]] is now vulnerable. citizens.commands.npc.vulnerable.set=[[{0}]] is now vulnerable.
citizens.commands.npc.vulnerable.stopped=[[{0}]] is no longer vulnerable. citizens.commands.npc.vulnerable.stopped=[[{0}]] is no longer vulnerable.
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.page-missing=The page [[{0}]] does not exist. citizens.commands.page-missing=The page [[{0}]] does not exist.
citizens.commands.requirements.disallowed-mobtype=The NPC cannot be the mob type {0} to use that command. citizens.commands.requirements.disallowed-mobtype=The NPC cannot be the mob type {0} to use that command.
citizens.commands.requirements.missing-permission=You don't have permission to execute that command. citizens.commands.requirements.missing-permission=You don't have permission to execute that command.