From bc8e3128fa4cba5ce42d54a4986954106650e732 Mon Sep 17 00:00:00 2001 From: fullwall Date: Sun, 20 Mar 2016 17:33:41 +0800 Subject: [PATCH] Add /npc collidable for players colliding with entities --- .../net/citizensnpcs/commands/NPCCommands.java | 16 ++++++++++++++++ .../citizensnpcs/npc/entity/EntityHumanNPC.java | 5 +++++ .../java/net/citizensnpcs/util/Messages.java | 2 ++ src/main/resources/messages_en.properties | 2 ++ 4 files changed, 25 insertions(+) diff --git a/src/main/java/net/citizensnpcs/commands/NPCCommands.java b/src/main/java/net/citizensnpcs/commands/NPCCommands.java index a113da759..10e1c1895 100644 --- a/src/main/java/net/citizensnpcs/commands/NPCCommands.java +++ b/src/main/java/net/citizensnpcs/commands/NPCCommands.java @@ -253,6 +253,22 @@ public class NPCCommands { } } + @Command( + aliases = { "npc" }, + usage = "collidable", + desc = "Copies an NPC", + modifiers = { "copy" }, + min = 1, + max = 1, + permission = "citizens.npc.collidable") + @Requirements(ownership = true, selected = true, types = { EntityType.PLAYER }) + public void collidable(CommandContext args, CommandSender sender, NPC npc) throws CommandException { + npc.data().setPersistent(NPC.COLLIDABLE_METADATA, !npc.data().get(NPC.COLLIDABLE_METADATA, true)); + Messaging.sendTr(sender, + npc.data().get(NPC.COLLIDABLE_METADATA) ? Messages.COLLIDABLE_SET : Messages.COLLIDABLE_UNSET, + npc.getName()); + } + @Command( aliases = { "npc" }, usage = "controllable|control (-m(ount),-y,-n,-o)", diff --git a/src/main/java/net/citizensnpcs/npc/entity/EntityHumanNPC.java b/src/main/java/net/citizensnpcs/npc/entity/EntityHumanNPC.java index 9fc8e4d17..9cd28229c 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/EntityHumanNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/EntityHumanNPC.java @@ -264,6 +264,11 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable setSkinFlags((byte) 0xFF); } + @Override + public boolean isCollidable() { + return npc == null ? super.isCollidable() : npc.data().get(NPC.COLLIDABLE_METADATA, true); + } + public boolean isNavigating() { return npc.getNavigator().isNavigating(); } diff --git a/src/main/java/net/citizensnpcs/util/Messages.java b/src/main/java/net/citizensnpcs/util/Messages.java index ef19ba36d..36b70a008 100644 --- a/src/main/java/net/citizensnpcs/util/Messages.java +++ b/src/main/java/net/citizensnpcs/util/Messages.java @@ -32,6 +32,8 @@ public class Messages { 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 COLLIDABLE_SET = "citizens.commands.npc.collidable.set"; + public static final String COLLIDABLE_UNSET = "citizens.commands.npc.collidable.unset"; 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/resources/messages_en.properties b/src/main/resources/messages_en.properties index 93f63f3c7..d32484c26 100644 --- a/src/main/resources/messages_en.properties +++ b/src/main/resources/messages_en.properties @@ -25,6 +25,8 @@ citizens.commands.npc.anchor.removed=Anchor removed. citizens.commands.npc.behaviour.added=Behaviours added. citizens.commands.npc.behaviour.help=The scripts argument is a comma-separated list of file names. Scripts will be loaded automatically and run every tick. Use the [[-r]] flag to remove behaviours. citizens.commands.npc.behaviour.removed=Behaviours removed. +citizens.commands.npc.collidable.set=[[{0}]] will now collide with entities. +citizens.commands.npc.collidable.unset=[[{0}]] will no longer collide with entities. citizens.commands.npc.controllable.not-controllable=[[{0}]] is not controllable. citizens.commands.npc.controllable.removed=[[{0}]] can no longer be controlled. citizens.commands.npc.controllable.set=[[{0}]] can now be controlled.