From 8930e25fbeee7a875598b3a520d36b38000e0b13 Mon Sep 17 00:00:00 2001 From: fullwall Date: Fri, 8 Mar 2013 17:47:03 +0800 Subject: [PATCH] /npc wolf command --- .../citizensnpcs/commands/NPCCommands.java | 27 +++++++++++++++++++ .../npc/ai/CitizensNavigator.java | 1 - .../net/citizensnpcs/trait/text/Text.java | 4 +-- .../java/net/citizensnpcs/util/Messages.java | 1 + src/main/java/net/citizensnpcs/util/NMS.java | 25 +++-------------- src/main/resources/messages_en.properties | 1 + src/main/resources/plugin.yml | 3 ++- 7 files changed, 36 insertions(+), 26 deletions(-) diff --git a/src/main/java/net/citizensnpcs/commands/NPCCommands.java b/src/main/java/net/citizensnpcs/commands/NPCCommands.java index 03ea61c1f..f6e89a90c 100644 --- a/src/main/java/net/citizensnpcs/commands/NPCCommands.java +++ b/src/main/java/net/citizensnpcs/commands/NPCCommands.java @@ -53,6 +53,7 @@ import net.citizensnpcs.util.StringHelper; import net.citizensnpcs.util.Util; import org.bukkit.Bukkit; +import org.bukkit.DyeColor; import org.bukkit.GameMode; import org.bukkit.Location; import org.bukkit.World; @@ -66,6 +67,7 @@ import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.entity.Skeleton.SkeletonType; import org.bukkit.entity.Villager.Profession; +import org.bukkit.entity.Wolf; import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; import com.google.common.base.Splitter; @@ -1147,6 +1149,31 @@ public class NPCCommands { Messaging.sendTr(sender, key, npc.getName()); } + @Command( + aliases = { "npc" }, + usage = "wolf (-s(itting) a(ngry) t(amed)) --collar [rgb color]", + desc = "Sets wolf modifiers", + modifiers = { "wolf" }, + min = 1, + max = 1, + flags = "sat", + permission = "citizens.npc.wolf") + @Requirements(selected = true, ownership = true, types = EntityType.WOLF) + public void wolf(CommandContext args, CommandSender sender, NPC npc) throws CommandException { + Wolf wolf = (Wolf) npc.getBukkitEntity(); + wolf.setAngry(args.hasFlag('a')); + wolf.setSitting(args.hasFlag('s')); + wolf.setTamed(args.hasFlag('t')); + if (args.hasValueFlag("collar")) { + String unparsed = args.getFlag("colour"); + int rgb = Integer.parseInt(unparsed.replace("#", "")); + DyeColor color = DyeColor.getByColor(org.bukkit.Color.fromRGB(rgb)); + if (color == null) + throw new CommandException(Messages.COLLAR_COLOUR_NOT_RECOGNISED); + wolf.setCollarColor(color); + } + } + @Command( aliases = { "npc" }, usage = "zombiemod (-b(aby), -v(illager))", diff --git a/src/main/java/net/citizensnpcs/npc/ai/CitizensNavigator.java b/src/main/java/net/citizensnpcs/npc/ai/CitizensNavigator.java index 75c34c631..f532f40d0 100644 --- a/src/main/java/net/citizensnpcs/npc/ai/CitizensNavigator.java +++ b/src/main/java/net/citizensnpcs/npc/ai/CitizensNavigator.java @@ -232,6 +232,5 @@ public class CitizensNavigator implements Navigator, Runnable { } private static final Location STATIONARY_LOCATION = new Location(null, 0, 0, 0); - private static int UNINITIALISED_SPEED = Integer.MIN_VALUE; } diff --git a/src/main/java/net/citizensnpcs/trait/text/Text.java b/src/main/java/net/citizensnpcs/trait/text/Text.java index 500ab6f3d..d3b084f28 100644 --- a/src/main/java/net/citizensnpcs/trait/text/Text.java +++ b/src/main/java/net/citizensnpcs/trait/text/Text.java @@ -183,7 +183,7 @@ public class Text extends Trait implements Runnable, Toggleable, Listener, Conve int index = 0; if (randomTalker) - index = new Random().nextInt(text.size()); + index = RANDOM.nextInt(text.size()); else { if (currentIndex > text.size() - 1) currentIndex = 0; @@ -191,8 +191,6 @@ public class Text extends Trait implements Runnable, Toggleable, Listener, Conve } npc.getDefaultSpeechController().speak(new SpeechContext(text.get(index), player)); - // Messaging.sendWithNPC(player, Setting.CHAT_PREFIX.asString() + - // text.get(index), npc); return true; } diff --git a/src/main/java/net/citizensnpcs/util/Messages.java b/src/main/java/net/citizensnpcs/util/Messages.java index d7a3c03b6..02a23d5f7 100644 --- a/src/main/java/net/citizensnpcs/util/Messages.java +++ b/src/main/java/net/citizensnpcs/util/Messages.java @@ -29,6 +29,7 @@ public class Messages { public static final String CITIZENS_RELOADING = "citizens.notifications.reloading"; 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 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"; diff --git a/src/main/java/net/citizensnpcs/util/NMS.java b/src/main/java/net/citizensnpcs/util/NMS.java index ef8cab2c0..7725a8553 100644 --- a/src/main/java/net/citizensnpcs/util/NMS.java +++ b/src/main/java/net/citizensnpcs/util/NMS.java @@ -7,7 +7,6 @@ import java.util.Collection; import java.util.List; import java.util.Map; import java.util.Random; -import java.util.Set; import java.util.WeakHashMap; import net.citizensnpcs.api.npc.NPC; @@ -32,7 +31,6 @@ import net.minecraft.server.v1_4_R1.World; import org.apache.commons.lang.Validate; import org.bukkit.Bukkit; import org.bukkit.Location; -import org.bukkit.Material; import org.bukkit.craftbukkit.v1_4_R1.CraftServer; import org.bukkit.craftbukkit.v1_4_R1.CraftWorld; import org.bukkit.craftbukkit.v1_4_R1.entity.CraftEntity; @@ -41,12 +39,9 @@ import org.bukkit.craftbukkit.v1_4_R1.entity.CraftPlayer; import org.bukkit.entity.EntityType; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; -import org.bukkit.material.Stairs; -import org.bukkit.material.Step; import org.bukkit.plugin.PluginLoadOrder; import com.google.common.collect.Maps; -import com.google.common.collect.Sets; @SuppressWarnings("unchecked") public class NMS { @@ -65,10 +60,7 @@ public class NMS { private static final Location packetCacheLocation = new Location(null, 0, 0, 0); private static Field PATHFINDING_RANGE; private static final Random RANDOM = Util.getFastRandom(); - private static Set SLAB_MATERIALS = Sets.newHashSet(); private static Field SPEED_FIELD; - private static Set STAIR_MATERIALS = Sets.newHashSet(); - private static Field THREAD_STOPPER; public static void addOrRemoveFromPlayerList(LivingEntity bukkitEntity, boolean remove) { @@ -223,6 +215,10 @@ public class NMS { ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); } + public static void sendPacketNearby(Location location, Packet packet) { + NMS.sendPacketsNearby(location, Arrays.asList(packet), 64); + } + public static void sendPacketsNearby(Location location, Collection packets) { NMS.sendPacketsNearby(location, packets, 64); } @@ -246,10 +242,6 @@ public class NMS { public static void sendPacketsNearby(Location location, Packet... packets) { NMS.sendPacketsNearby(location, Arrays.asList(packets), 64); } - - public static void sendPacketNearby(Location location, Packet packet) { - NMS.sendPacketsNearby(location, Arrays.asList(packet), 64); - } public static void sendToOnline(Packet... packets) { Validate.notNull(packets, "packets cannot be null"); @@ -397,13 +389,4 @@ public class NMS { Messaging.logTr(Messages.ERROR_GETTING_ID_MAPPING, e.getMessage()); } } - - static { - for (Material material : Material.values()) { - if (Step.class.isAssignableFrom(material.getData())) - SLAB_MATERIALS.add(material.getId()); - else if (Stairs.class.isAssignableFrom(material.getData())) - STAIR_MATERIALS.add(material.getId()); - } - } } diff --git a/src/main/resources/messages_en.properties b/src/main/resources/messages_en.properties index c3f1fe361..79fbc3fb3 100644 --- a/src/main/resources/messages_en.properties +++ b/src/main/resources/messages_en.properties @@ -85,6 +85,7 @@ 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.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. diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index c581c7471..2ecf1a29b 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -100,4 +100,5 @@ permissions: children: citizens.npc.trait: true citizens.npc.trait-configure: true - citizens.npc.vulnerable: true \ No newline at end of file + citizens.npc.vulnerable: true + citizens.npc.wolf: true \ No newline at end of file