Skip to content

Commit

Permalink
Add /npc passive
Browse files Browse the repository at this point in the history
  • Loading branch information
fullwall committed Nov 16, 2013
1 parent b1b98c0 commit 0c403ed
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
12 changes: 11 additions & 1 deletion src/main/java/net/citizensnpcs/EventListen.java
Expand Up @@ -13,6 +13,7 @@
import net.citizensnpcs.api.event.NPCCombustEvent;
import net.citizensnpcs.api.event.NPCDamageByBlockEvent;
import net.citizensnpcs.api.event.NPCDamageByEntityEvent;
import net.citizensnpcs.api.event.NPCDamageEntityEvent;
import net.citizensnpcs.api.event.NPCDamageEvent;
import net.citizensnpcs.api.event.NPCDeathEvent;
import net.citizensnpcs.api.event.NPCDespawnEvent;
Expand Down Expand Up @@ -152,8 +153,17 @@ public void onEntityCombust(EntityCombustEvent event) {
@EventHandler
public void onEntityDamage(EntityDamageEvent event) {
NPC npc = npcRegistry.getNPC(event.getEntity());
if (npc == null)
if (npc == null) {
if (event instanceof EntityDamageByEntityEvent) {
npc = npcRegistry.getNPC(((EntityDamageByEntityEvent) event).getDamager());
if (npc == null)
return;
event.setCancelled(npc.data().get(NPC.DAMAGE_OTHERS_METADATA, true));
NPCDamageEntityEvent damageEvent = new NPCDamageEntityEvent(npc, (EntityDamageByEntityEvent) event);
Bukkit.getPluginManager().callEvent(damageEvent);
}
return;
}
event.setCancelled(npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true));
if (event instanceof EntityDamageByEntityEvent) {
NPCDamageByEntityEvent damageEvent = new NPCDamageByEntityEvent(npc, (EntityDamageByEntityEvent) event);
Expand Down
17 changes: 16 additions & 1 deletion src/main/java/net/citizensnpcs/commands/NPCCommands.java
Expand Up @@ -807,6 +807,21 @@ public void owner(CommandContext args, CommandSender sender, NPC npc) throws Com
Messaging.sendTr(sender, serverOwner ? Messages.OWNER_SET_SERVER : Messages.OWNER_SET, npc.getName(), name);
}

@Command(
aliases = { "npc" },
usage = "passive (--set [true|false])",
desc = "Sets whether an NPC damages other entities or not",
modifiers = { "passive" },
min = 1,
max = 1,
permission = "citizens.npc.passive")
public void passive(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
boolean passive = args.hasValueFlag("set") ? Boolean.parseBoolean(args.getFlag("set")) : npc.data().get(
NPC.DAMAGE_OTHERS_METADATA, true);
npc.data().setPersistent(NPC.DAMAGE_OTHERS_METADATA, !passive);
Messaging.sendTr(sender, passive ? Messages.PASSIVE_SET : Messages.PASSIVE_UNSET, npc.getName());
}

@Command(
aliases = { "npc" },
usage = "pathopt --avoid-water|aw [true|false]",
Expand Down Expand Up @@ -1196,7 +1211,7 @@ public void speed(CommandContext args, CommandSender sender, NPC npc) throws Com
max = 1,
permission = "citizens.npc.swim")
public void swim(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
boolean swim = args.hasValueFlag("set") ? Boolean.parseBoolean(args.getFlag("swim")) : !npc.data().get(
boolean swim = args.hasValueFlag("set") ? Boolean.parseBoolean(args.getFlag("set")) : !npc.data().get(
NPC.SWIMMING_METADATA, true);
npc.data().setPersistent(NPC.SWIMMING_METADATA, swim);
Messaging.sendTr(sender, swim ? Messages.SWIMMING_SET : Messages.SWIMMING_UNSET, npc.getName());
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/net/citizensnpcs/util/Messages.java
Expand Up @@ -150,6 +150,8 @@ public class Messages {
public static final String OVER_NPC_LIMIT = "citizens.limits.over-npc-limit";
public static final String OWNER_SET = "citizens.commands.npc.owner.set";
public static final String OWNER_SET_SERVER = "citizens.commands.npc.owner.set-server";
public static final String PASSIVE_SET = "citizens.commands.npc.passive.set";
public static final String PASSIVE_UNSET = "citizens.commands.npc.passive.unset";
public static final String PATHFINDING_OPTIONS_AVOID_WATER_SET = "citizens.commands.npc.pathopt.avoid-water-set";
public static final String PATHFINDING_OPTIONS_AVOID_WATER_UNSET = "citizens.commands.npc.pathopt.avoid-water-unset";
public static final String PATHFINDING_RANGE_SET = "citizens.commands.npc.pathfindingrange.set";
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/messages_en.properties
Expand Up @@ -64,6 +64,8 @@ citizens.commands.npc.owner.already-owner={0} is already the owner of {1}.
citizens.commands.npc.owner.owner=[[{0}]]''s owner is [[{1}]].
citizens.commands.npc.owner.set-server=[[The server]] is now the owner of {0}.
citizens.commands.npc.owner.set=[[{1}]] is now the owner of {0}.
citizens.commands.npc.passive.set=[[{0}]] will no longer damage entities.
citizens.commands.npc.passive.unset=[[{0}]] will now damage entities.
citizens.commands.npc.pathfindingrange.set=Pathfinding range set to [[{0}]].
citizens.commands.npc.pathopt.avoid-water-set=[[{0}]] will now avoid water.
citizens.commands.npc.pathopt.avoid-water-unset=[[{0}]] will no longer avoid water.
Expand Down

0 comments on commit 0c403ed

Please sign in to comment.