mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-10-24 05:20:55 +02:00
Merge pull request #155 from sanjay900/master
Allow Rabbits to have their types set. Fix lots of broken commands. Add enums to commands.
This commit is contained in:
commit
574faefa09
@ -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;
|
||||
@ -56,6 +58,7 @@ import net.citizensnpcs.util.NMS;
|
||||
import net.citizensnpcs.util.StringHelper;
|
||||
import net.citizensnpcs.util.Util;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.GameMode;
|
||||
@ -1039,7 +1042,7 @@ public class NPCCommands {
|
||||
String profession = args.getString(1);
|
||||
Profession parsed = Util.matchEnum(Profession.values(), profession.toUpperCase());
|
||||
if (parsed == null) {
|
||||
throw new CommandException(Messages.INVALID_PROFESSION);
|
||||
throw new CommandException(Messages.INVALID_PROFESSION,args.getString(1),StringUtils.join(Profession.values(), ","));
|
||||
}
|
||||
npc.getTrait(VillagerProfession.class).setProfession(parsed);
|
||||
Messaging.sendTr(sender, Messages.PROFESSION_SET, npc.getName(), profession);
|
||||
@ -1084,6 +1087,25 @@ public class NPCCommands {
|
||||
Messaging.sendTr(sender, Messages.NPC_REMOVED, npc.getName());
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = { "npc" },
|
||||
usage = "rabbittype [type]",
|
||||
desc = "Set the Type of a Rabbit NPC",
|
||||
modifiers = { "rabbittype","rbtype" },
|
||||
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,StringUtils.join(RabbitTypes.values(), ","));
|
||||
}
|
||||
npc.getTrait(RabbitType.class).setType(type);
|
||||
Messaging.sendTr(sender, Messages.RABBIT_TYPE_SET, npc.getName(), type.name());
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = { "npc" },
|
||||
usage = "rename [name]",
|
||||
@ -1178,9 +1200,12 @@ public class NPCCommands {
|
||||
"skeletontype", "sktype" }, min = 2, max = 2, permission = "citizens.npc.skeletontype")
|
||||
@Requirements(selected = true, ownership = true, types = EntityType.SKELETON)
|
||||
public void skeletonType(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
|
||||
SkeletonType type = SkeletonType.valueOf(args.getString(1).toUpperCase());
|
||||
if (type == null)
|
||||
throw new CommandException(Messages.INVALID_SKELETON_TYPE);
|
||||
SkeletonType type;
|
||||
try {
|
||||
type = SkeletonType.valueOf(args.getString(1).toUpperCase());
|
||||
} catch (IllegalArgumentException ex) {
|
||||
throw new CommandException(Messages.INVALID_SKELETON_TYPE,StringUtils.join(SkeletonType.values(), ","));
|
||||
}
|
||||
npc.getTrait(NPCSkeletonType.class).setType(type);
|
||||
Messaging.sendTr(sender, Messages.SKELETON_TYPE_SET, npc.getName(), type);
|
||||
}
|
||||
@ -1563,13 +1588,18 @@ public class NPCCommands {
|
||||
try {
|
||||
color = DyeColor.valueOf(unparsed.toUpperCase().replace(' ', '_'));
|
||||
} catch (IllegalArgumentException e) {
|
||||
try {
|
||||
int rgb = Integer.parseInt(unparsed.replace("#", ""), 16);
|
||||
color = DyeColor.getByColor(org.bukkit.Color.fromRGB(rgb));
|
||||
} catch (NumberFormatException ex) {
|
||||
throw new CommandException(Messages.COLLAR_COLOUR_NOT_RECOGNISED,unparsed);
|
||||
}
|
||||
}
|
||||
if (color == null)
|
||||
throw new CommandException(Messages.COLLAR_COLOUR_NOT_RECOGNISED);
|
||||
throw new CommandException(Messages.COLLAR_COLOUR_NOT_SUPPORTED,unparsed);
|
||||
trait.setCollarColor(color);
|
||||
}
|
||||
Messaging.sendTr(sender, Messages.WOLF_TRAIT_UPDATED, npc.getName(), args.hasFlag('a'), args.hasFlag('s'), args.hasFlag('t'),trait.getCollarColor().name());
|
||||
}
|
||||
|
||||
@Command(
|
||||
|
@ -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"));
|
||||
|
45
src/main/java/net/citizensnpcs/trait/RabbitType.java
Normal file
45
src/main/java/net/citizensnpcs/trait/RabbitType.java
Normal file
@ -0,0 +1,45 @@
|
||||
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;
|
||||
setType(type);
|
||||
}
|
||||
|
||||
public void setType(RabbitTypes type) {
|
||||
this.type = type;
|
||||
if (rabbit != null && rabbit.isValid()) {
|
||||
((EntityRabbit)((CraftRabbit)rabbit).getHandle()).r(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;
|
||||
}
|
||||
}
|
||||
}
|
@ -54,4 +54,8 @@ public class WolfModifiers extends Trait {
|
||||
wolf.setTamed(tamed);
|
||||
}
|
||||
}
|
||||
|
||||
public DyeColor getCollarColor() {
|
||||
return collarColor;
|
||||
}
|
||||
}
|
||||
|
@ -30,6 +30,7 @@ public class Messages {
|
||||
public static final String CITIZENS_SAVED = "citizens.notifications.saved";
|
||||
public static final String CITIZENS_SAVING = "citizens.notifications.saving";
|
||||
public static final String COLLAR_COLOUR_NOT_RECOGNISED = "citizens.commands.npc.wolf.unknown-collar-color";
|
||||
public static final String COLLAR_COLOUR_NOT_SUPPORTED = "citizens.commands.npc.wolf.collar-color-unsupported";
|
||||
public static final String COMMAND_AGE_HELP = "citizens.commands.npc.age.help";
|
||||
public static final String COMMAND_HELP_HEADER = "citizens.commands.help.header";
|
||||
public static final String COMMAND_INVALID_MOBTYPE = "citizens.commands.invalid-mobtype";
|
||||
@ -99,6 +100,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 +168,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";
|
||||
@ -256,6 +259,7 @@ public class Messages {
|
||||
public static final String WAYPOINT_TRIGGER_REMOVE_PROMPT = "citizens.editors.waypoints.triggers.remove.prompt";
|
||||
public static final String WAYPOINT_TRIGGER_REMOVE_REMOVED = "citizens.editors.waypoints.triggers.remove.removed";
|
||||
public static final String WAYPOINT_TRIGGER_TELEPORT_PROMPT = "citizens.editors.waypoints.triggers.teleport.prompt";
|
||||
public static final String WOLF_TRAIT_UPDATED="citizens.commands.wolf.traits-updated";
|
||||
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";
|
||||
|
@ -81,8 +81,10 @@ citizens.commands.npc.pose.missing=The pose [[{0}]] does not exist.
|
||||
citizens.commands.npc.pose.removed=Pose removed.
|
||||
citizens.commands.npc.powered.set=[[{0}]] will now be powered.
|
||||
citizens.commands.npc.powered.stopped=[[{0}]] will no longer be powered.
|
||||
citizens.commands.npc.profession.invalid-profession={0} is not a valid profession.
|
||||
citizens.commands.npc.profession.invalid-profession=[[{0}]] is not a valid profession. Try one of the following: [[{1}]].
|
||||
citizens.commands.npc.profession.set=[[{0}]] is now a [[{1}]].
|
||||
citizens.commands.npc.rabbittype.invalid-type=Invalid rabbit type. Try one of the following: [[{0}]].
|
||||
citizens.commands.npc.rabbittype.type-set=[[{0}]]''s rabbit type has been set to [[{1}]]
|
||||
citizens.commands.npc.remove.incorrect-syntax=Incorrect syntax. /npc remove (all)
|
||||
citizens.commands.npc.remove.removed-all=You permanently removed all NPCs.
|
||||
citizens.commands.npc.remove.removed=You permanently removed [[{0}]].
|
||||
@ -98,7 +100,7 @@ citizens.commands.npc.sound.invalid-sound=Invalid sound.
|
||||
citizens.commands.npc.sound.set={0}''s sounds are now: ambient - [[{1}]] hurt - [[{2}]] and death - [[{3}]].
|
||||
citizens.commands.npc.sound.info={0}''s sounds are: ambient - [[{1}]] hurt - [[{2}]] and death - [[{3}]].<br><br>Valid sounds are {4}.
|
||||
citizens.commands.npc.skeletontype.set={0}''s skeleton type set to [[{1}]].
|
||||
citizens.commands.npc.skeletontype.invalid-type=Invalid skeleton type.
|
||||
citizens.commands.npc.skeletontype.invalid-type=Invalid skeleton type. Try one of the following: [[{0}]].
|
||||
citizens.commands.npc.spawn.already-spawned=[[{0}]] is already spawned at another location. Use ''/npc tphere'' to teleport the NPC to your location.
|
||||
citizens.commands.npc.spawn.missing-npc-id=No NPC with the ID {0} exists.
|
||||
citizens.commands.npc.spawn.no-location=No stored location available - command must be used ingame.
|
||||
@ -120,7 +122,8 @@ 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.wolf.unknown-collar-color=[[{0}]] is not an RGB-formatted collar color.
|
||||
citizens.commands.npc.wolf.unknown-collar-color=[[{0}]] is not an RGB-formatted collar color or the name of a DyeColor.
|
||||
citizens.commands.npc.wolf.collar-color-unsupported=[[{0}]] is not a RGB color code that can be used on a wolf's collar.
|
||||
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.
|
||||
@ -153,6 +156,7 @@ citizens.commands.traitc.missing=Trait not found.
|
||||
citizens.commands.traitc.not-configurable=That trait is not configurable.
|
||||
citizens.commands.traitc.not-on-npc=The NPC doesn''t have that trait.
|
||||
citizens.commands.unknown-command=Unknown command. Did you mean:
|
||||
citizens.commands.wolf.traits-updated=[[{0}]]''s Traits were updated. Angry:[[{1}]], Sitting:[[{2}]], Tamed:[[{3}]], Collar Color:[[{4}]]
|
||||
citizens.conversations.selection.invalid-choice=[[{0}]] is not a valid option.
|
||||
citizens.economy.error-loading=Unable to use economy handling. Has Vault been enabled?
|
||||
citizens.economy.minimum-cost-required=Need at least [[{0}]].
|
||||
|
Loading…
Reference in New Issue
Block a user