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;
@ -329,27 +330,27 @@ public class NPCCommands {
if (parts.length > 0) { if (parts.length > 0) {
String worldName = args.getSenderLocation() != null ? args.getSenderLocation().getWorld() String worldName = args.getSenderLocation() != null ? args.getSenderLocation().getWorld()
.getName() : ""; .getName() : "";
int x = 0, y = 0, z = 0; int x = 0, y = 0, z = 0;
float yaw = 0F, pitch = 0F; float yaw = 0F, pitch = 0F;
switch (parts.length) { switch (parts.length) {
case 6: case 6:
pitch = Float.parseFloat(parts[5]); pitch = Float.parseFloat(parts[5]);
case 5: case 5:
yaw = Float.parseFloat(parts[4]); yaw = Float.parseFloat(parts[4]);
case 4: case 4:
worldName = parts[3]; worldName = parts[3];
case 3: case 3:
x = Integer.parseInt(parts[0]); x = Integer.parseInt(parts[0]);
y = Integer.parseInt(parts[1]); y = Integer.parseInt(parts[1]);
z = Integer.parseInt(parts[2]); z = Integer.parseInt(parts[2]);
break; break;
default: default:
throw new CommandException(Messages.INVALID_SPAWN_LOCATION); throw new CommandException(Messages.INVALID_SPAWN_LOCATION);
} }
World world = Bukkit.getWorld(worldName); World world = Bukkit.getWorld(worldName);
if (world == null) if (world == null)
throw new CommandException(Messages.INVALID_SPAWN_LOCATION); throw new CommandException(Messages.INVALID_SPAWN_LOCATION);
spawnLoc = new Location(world, x, y, z, yaw, pitch); spawnLoc = new Location(world, x, y, z, yaw, pitch);
} else { } else {
Player search = Bukkit.getPlayerExact(args.getFlag("at")); Player search = Bukkit.getPlayerExact(args.getFlag("at"));
if (search == null) if (search == null)
@ -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))
@ -780,7 +781,7 @@ public class NPCCommands {
} }
@Command(aliases = { "npc" }, usage = "remove|rem (all)", desc = "Remove a NPC", modifiers = { "remove", @Command(aliases = { "npc" }, usage = "remove|rem (all)", desc = "Remove a NPC", modifiers = { "remove",
"rem" }, min = 1, max = 2) "rem" }, min = 1, max = 2)
@Requirements @Requirements
public void remove(CommandContext args, CommandSender sender, NPC npc) throws CommandException { public void remove(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
if (args.argsLength() == 2) { if (args.argsLength() == 2) {
@ -900,10 +901,10 @@ public class NPCCommands {
public void skeletonType(CommandContext args, CommandSender sender, NPC npc) throws CommandException { public void skeletonType(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
SkeletonType type = (type = SkeletonType.getType(args.getInteger(1))) == null ? SkeletonType SkeletonType type = (type = SkeletonType.getType(args.getInteger(1))) == null ? SkeletonType
.valueOf(args.getString(1)) : type; .valueOf(args.getString(1)) : type;
if (type == null) if (type == null)
throw new CommandException(Messages.INVALID_SKELETON_TYPE); throw new CommandException(Messages.INVALID_SKELETON_TYPE);
npc.getTrait(NPCSkeletonType.class).setType(type); npc.getTrait(NPCSkeletonType.class).setType(type);
Messaging.sendTr(sender, Messages.SKELETON_TYPE_SET, npc.getName(), type); Messaging.sendTr(sender, Messages.SKELETON_TYPE_SET, npc.getName(), type);
} }
@Command( @Command(
@ -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.