Allow Rabbits to have their types set.

Added command and trait.
messages_de, messages_fr and messages_nl need
citizens.commands.npc.rabbittype.set
citizens.commands.npc.rabbittype.invalid-type
This commit is contained in:
sanjay900 2014-12-18 22:36:44 +13:00
parent 954a3bd27b
commit 249ef8ec41
4 changed files with 75 additions and 1 deletions

View File

@ -46,6 +46,8 @@ import net.citizensnpcs.trait.NPCSkeletonType;
import net.citizensnpcs.trait.OcelotModifiers;
import net.citizensnpcs.trait.Poses;
import net.citizensnpcs.trait.Powered;
import net.citizensnpcs.trait.RabbitType;
import net.citizensnpcs.trait.RabbitType.RabbitTypes;
import net.citizensnpcs.trait.SlimeSize;
import net.citizensnpcs.trait.VillagerProfession;
import net.citizensnpcs.trait.WolfModifiers;
@ -1081,7 +1083,26 @@ public class NPCCommands {
npc.destroy();
Messaging.sendTr(sender, Messages.NPC_REMOVED, npc.getName());
}
@Command(
aliases = { "npc" },
usage = "rabbittype [type]",
desc = "Set the Type of a Rabbit NPC",
modifiers = { "rabbittype" },
min = 2,
permission = "citizens.npc.rabbittype")
@Requirements(selected = true, ownership = true, types = { EntityType.RABBIT })
public void rabbitType(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
RabbitTypes type;
try {
type = RabbitTypes.valueOf(args.getString(1).toUpperCase());
} catch (IllegalArgumentException ex) {
throw new CommandException(Messages.INVALID_RABBIT_TYPE);
}
npc.getTrait(RabbitType.class).setType(type);
Messaging.sendTr(sender, Messages.RABBIT_TYPE_SET, npc.getName(), type.name());
}
@Command(
aliases = { "npc" },
usage = "rename [name]",

View File

@ -28,6 +28,7 @@ import net.citizensnpcs.trait.NPCSkeletonType;
import net.citizensnpcs.trait.OcelotModifiers;
import net.citizensnpcs.trait.Poses;
import net.citizensnpcs.trait.Powered;
import net.citizensnpcs.trait.RabbitType;
import net.citizensnpcs.trait.Saddle;
import net.citizensnpcs.trait.Sheared;
import net.citizensnpcs.trait.SlimeSize;
@ -61,6 +62,7 @@ public class CitizensTraitFactory implements TraitFactory {
registerTrait(TraitInfo.create(Owner.class).withName("owner"));
registerTrait(TraitInfo.create(Poses.class).withName("poses"));
registerTrait(TraitInfo.create(Powered.class).withName("powered"));
registerTrait(TraitInfo.create(RabbitType.class).withName("rabbittype"));
registerTrait(TraitInfo.create(Saddle.class).withName("saddle"));
registerTrait(TraitInfo.create(Sheared.class).withName("sheared"));
registerTrait(TraitInfo.create(NPCSkeletonType.class).withName("skeletontype"));

View File

@ -0,0 +1,49 @@
package net.citizensnpcs.trait;
import org.bukkit.craftbukkit.v1_8_R1.entity.CraftRabbit;
import org.bukkit.entity.Rabbit;
import net.citizensnpcs.api.persistence.Persist;
import net.citizensnpcs.api.trait.Trait;
import net.minecraft.server.v1_8_R1.EntityRabbit;
public class RabbitType extends Trait {
private Rabbit rabbit;
@Persist
private RabbitTypes type = RabbitTypes.BROWN;
public RabbitType() {
super("rabbittype");
}
@Override
public void onSpawn() {
rabbit = npc.getEntity() instanceof Rabbit ? (Rabbit) npc.getEntity() : null;
}
@Override
public void run() {
if (rabbit != null) {
((EntityRabbit)((CraftRabbit)rabbit).getHandle()).r(type.type);
}
}
public void setType(RabbitTypes type) {
this.type = type;
}
public enum RabbitTypes {
BROWN(0),
WHITE(1),
BLACK(2),
BLACKANDWHITE(3),
GOLD(4),
SALTANDPEPPER(5),
KILLER(99);
public int type;
RabbitTypes (int type) {
this.type = type;
}
}
}

View File

@ -99,6 +99,7 @@ public class Messages {
public static final String INVALID_OCELOT_TYPE = "citizens.commands.npc.ocelot.invalid-type";
public static final String INVALID_POSE_NAME = "citizens.commands.npc.pose.invalid-name";
public static final String INVALID_PROFESSION = "citizens.commands.npc.profession.invalid-profession";
public static final String INVALID_RABBIT_TYPE = "citizens.commands.npc.rabbittype.invalid-type";
public static final String INVALID_SKELETON_TYPE = "citizens.commands.npc.skeletontype.invalid-type";
public static final String INVALID_SOUND = "citizens.commands.npc.sound.invalid-sound";
public static final String INVALID_SPAWN_LOCATION = "citizens.commands.npc.create.invalid-location";
@ -166,6 +167,7 @@ public class Messages {
public static final String POWERED_SET = "citizens.commands.npc.powered.set";
public static final String POWERED_STOPPED = "citizens.commands.npc.powered.stopped";
public static final String PROFESSION_SET = "citizens.commands.npc.profession.set";
public static final String RABBIT_TYPE_SET = "citizens.commands.npc.rabbittype.type-set";
public static final String REMOVE_INCORRECT_SYNTAX = "citizens.commands.npc.remove.incorrect-syntax";
public static final String REMOVED_ALL_NPCS = "citizens.commands.npc.remove.removed-all";
public static final String REMOVED_FROM_PLAYERLIST = "citizens.commands.npc.playerlist.removed";