mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-16 15:46:14 +01:00
Add /npc passive
This commit is contained in:
parent
5765d80125
commit
d9f9861965
@ -13,6 +13,7 @@ import net.citizensnpcs.api.event.NPCCombustByEntityEvent;
|
||||
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;
|
||||
@ -152,8 +153,17 @@ public class EventListen implements Listener {
|
||||
@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);
|
||||
|
@ -807,6 +807,21 @@ public class NPCCommands {
|
||||
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]",
|
||||
@ -1196,7 +1211,7 @@ public class NPCCommands {
|
||||
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());
|
||||
|
@ -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";
|
||||
|
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user