mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-12-30 13:09:10 +01:00
Add /npc zombiemod (-bv)
This commit is contained in:
parent
929256c61a
commit
4858bf2958
@ -39,6 +39,7 @@ import net.citizensnpcs.trait.Poses;
|
||||
import net.citizensnpcs.trait.Powered;
|
||||
import net.citizensnpcs.trait.SlimeSize;
|
||||
import net.citizensnpcs.trait.VillagerProfession;
|
||||
import net.citizensnpcs.trait.ZombieModifier;
|
||||
import net.citizensnpcs.util.Anchor;
|
||||
import net.citizensnpcs.util.Messages;
|
||||
import net.citizensnpcs.util.Messaging;
|
||||
@ -329,27 +330,27 @@ public class NPCCommands {
|
||||
if (parts.length > 0) {
|
||||
String worldName = args.getSenderLocation() != null ? args.getSenderLocation().getWorld()
|
||||
.getName() : "";
|
||||
int x = 0, y = 0, z = 0;
|
||||
float yaw = 0F, pitch = 0F;
|
||||
switch (parts.length) {
|
||||
case 6:
|
||||
pitch = Float.parseFloat(parts[5]);
|
||||
case 5:
|
||||
yaw = Float.parseFloat(parts[4]);
|
||||
case 4:
|
||||
worldName = parts[3];
|
||||
case 3:
|
||||
x = Integer.parseInt(parts[0]);
|
||||
y = Integer.parseInt(parts[1]);
|
||||
z = Integer.parseInt(parts[2]);
|
||||
break;
|
||||
default:
|
||||
throw new CommandException(Messages.INVALID_SPAWN_LOCATION);
|
||||
}
|
||||
World world = Bukkit.getWorld(worldName);
|
||||
if (world == null)
|
||||
throw new CommandException(Messages.INVALID_SPAWN_LOCATION);
|
||||
spawnLoc = new Location(world, x, y, z, yaw, pitch);
|
||||
int x = 0, y = 0, z = 0;
|
||||
float yaw = 0F, pitch = 0F;
|
||||
switch (parts.length) {
|
||||
case 6:
|
||||
pitch = Float.parseFloat(parts[5]);
|
||||
case 5:
|
||||
yaw = Float.parseFloat(parts[4]);
|
||||
case 4:
|
||||
worldName = parts[3];
|
||||
case 3:
|
||||
x = Integer.parseInt(parts[0]);
|
||||
y = Integer.parseInt(parts[1]);
|
||||
z = Integer.parseInt(parts[2]);
|
||||
break;
|
||||
default:
|
||||
throw new CommandException(Messages.INVALID_SPAWN_LOCATION);
|
||||
}
|
||||
World world = Bukkit.getWorld(worldName);
|
||||
if (world == null)
|
||||
throw new CommandException(Messages.INVALID_SPAWN_LOCATION);
|
||||
spawnLoc = new Location(world, x, y, z, yaw, pitch);
|
||||
} else {
|
||||
Player search = Bukkit.getPlayerExact(args.getFlag("at"));
|
||||
if (search == null)
|
||||
@ -613,16 +614,16 @@ public class NPCCommands {
|
||||
}
|
||||
|
||||
@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, " <a>ID: <e>" + npc.getId());
|
||||
Messaging.send(sender, " <a>Type: <e>" + npc.getTrait(MobType.class).getType());
|
||||
if (npc.isSpawned())
|
||||
Messaging.send(sender, " <a>Spawned at: <e>" +
|
||||
"X: " + npc.getBukkitEntity().getLocation().getBlockX() +
|
||||
" Y: " + npc.getBukkitEntity().getLocation().getBlockY() +
|
||||
" Z: " + npc.getBukkitEntity().getLocation().getBlockZ() +
|
||||
" in world " + npc.getBukkitEntity().getLocation().getWorld().getName());
|
||||
if (npc.isSpawned()) {
|
||||
Location loc = npc.getBukkitEntity().getLocation();
|
||||
String format = " <a>Spawned at: <e> %d, %d, %d in world %s";
|
||||
Messaging.send(sender, String.format(format, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(),
|
||||
loc.getWorld().getName()));
|
||||
}
|
||||
Messaging.send(sender, " <a>Traits<e>");
|
||||
for (Trait trait : npc.getTraits()) {
|
||||
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",
|
||||
"rem" }, min = 1, max = 2)
|
||||
"rem" }, min = 1, max = 2)
|
||||
@Requirements
|
||||
public void remove(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
|
||||
if (args.argsLength() == 2) {
|
||||
@ -900,10 +901,10 @@ public class NPCCommands {
|
||||
public void skeletonType(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
|
||||
SkeletonType type = (type = SkeletonType.getType(args.getInteger(1))) == null ? SkeletonType
|
||||
.valueOf(args.getString(1)) : type;
|
||||
if (type == null)
|
||||
throw new CommandException(Messages.INVALID_SKELETON_TYPE);
|
||||
npc.getTrait(NPCSkeletonType.class).setType(type);
|
||||
Messaging.sendTr(sender, Messages.SKELETON_TYPE_SET, npc.getName(), type);
|
||||
if (type == null)
|
||||
throw new CommandException(Messages.INVALID_SKELETON_TYPE);
|
||||
npc.getTrait(NPCSkeletonType.class).setType(type);
|
||||
Messaging.sendTr(sender, Messages.SKELETON_TYPE_SET, npc.getName(), type);
|
||||
}
|
||||
|
||||
@Command(
|
||||
@ -1034,4 +1035,28 @@ public class NPCCommands {
|
||||
String key = vulnerable ? Messages.VULNERABLE_STOPPED : Messages.VULNERABLE_SET;
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
@ -30,6 +30,7 @@ import net.citizensnpcs.trait.Sheared;
|
||||
import net.citizensnpcs.trait.SlimeSize;
|
||||
import net.citizensnpcs.trait.VillagerProfession;
|
||||
import net.citizensnpcs.trait.WoolColor;
|
||||
import net.citizensnpcs.trait.ZombieModifier;
|
||||
import net.citizensnpcs.trait.text.Text;
|
||||
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(Waypoints.class).withName("waypoints"));
|
||||
registerTrait(TraitInfo.create(WoolColor.class).withName("woolcolor"));
|
||||
registerTrait(TraitInfo.create(ZombieModifier.class).withName("zombiemodifier"));
|
||||
|
||||
for (String trait : registered.keySet())
|
||||
INTERNAL_TRAITS.add(trait);
|
||||
|
42
src/main/java/net/citizensnpcs/trait/ZombieModifier.java
Normal file
42
src/main/java/net/citizensnpcs/trait/ZombieModifier.java
Normal 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;
|
||||
}
|
||||
}
|
@ -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 WORLD_NOT_FOUND = "citizens.commands.errors.missing-world";
|
||||
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";
|
||||
}
|
||||
|
@ -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.vulnerable.set=[[{0}]] is now 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.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.
|
||||
|
Loading…
Reference in New Issue
Block a user