Skip to content

Commit

Permalink
Add event target (pvp, pve, pvnpc), for #13
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Apr 18, 2016
1 parent 39e6db4 commit 623ce10
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ Sentinel NPCs: Combat NPCs for Spigot!

Created by mcmonkey4eva on behalf of the Citizens and Denizen teams.

**IMPORTANT:** NPC's won't do melee damage? In your config.yml file, toggle the setting that says "workaround damage" to true, and restart your server!

### Usage

- First, get acquainted with Citizens in general for best luck using Sentinel.
Expand Down Expand Up @@ -68,7 +70,7 @@ Created by mcmonkey4eva on behalf of the Citizens and Denizen teams.
These are all valid targets and ignores:

- Primary set: NPCS, OWNER, PASSIVE_MOB, MOBS, MONSTERS, PLAYERS, PIGS, OCELOTS, COWS, RABBITS, SHEEP, CHICKENS, HORSES, MUSHROOM_COW, IRON_GOLEMS, SQUIDS, VILLAGER, WOLF, SNOWMEN, WITCH, GUARDIANS, SHULKERS, CREERERS, SKELETONS, ZOMBIES, MAGMA_CUBES, ZOMBIE_PIGMEN, SILVERFISH, BATS, BLAZES, GHASTS, GIANTS, SLIME, SPIDER, CAVE_SPIDERS, ENDERMEN, ENDERMITES, WITHER, ENDERDRAGON
- Also allowed: player:NAME(REGEX), npc:NAME(REGEX), entityname:NAME(REGEX), helditem:MATERIALNAME(REGEX), group:GROUPNAME(EXACT)
- Also allowed: player:NAME(REGEX), npc:NAME(REGEX), entityname:NAME(REGEX), helditem:MATERIALNAME(REGEX), group:GROUPNAME(EXACT), event:pvp/pvnpc/pve

### Some random supported things

Expand Down
11 changes: 10 additions & 1 deletion src/main/java/org/mcmonkey/sentinel/SentinelPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,10 @@ else if (info[0].equalsIgnoreCase("group")) {
}
return true;
}
else if (info[0].equalsIgnoreCase("event")) {
info[1] = info[1].toLowerCase();
names = sentinel.eventTargets;
}
try {
if ("Sentinel".matches(info[1])) {
ignoreMe++;
Expand All @@ -199,7 +203,7 @@ else if (info[0].equalsIgnoreCase("group")) {
valid.append(poss.name()).append(", ");
}
sender.sendMessage(prefixGood + "Valid targets: " + valid.substring(0, valid.length() - 2));
sender.sendMessage(prefixGood + "Also allowed: player:NAME(REGEX), npc:NAME(REGEX), entityname:NAME(REGEX), helditem:MATERIALNAME(REGEX), group:GROUPNAME(EXACT)");
sender.sendMessage(prefixGood + "Also allowed: player:NAME(REGEX), npc:NAME(REGEX), entityname:NAME(REGEX), helditem:MATERIALNAME(REGEX), group:GROUPNAME(EXACT), event:pvp/pvnpc/pve");
}
else {
if (sentinel.targets.add(target)) {
Expand Down Expand Up @@ -239,6 +243,10 @@ else if (info[0].equalsIgnoreCase("group")) {
}
return true;
}
else if (info[0].equalsIgnoreCase("event")) {
info[1] = info[1].toLowerCase();
names = sentinel.eventTargets;
}
try {
if ("Sentinel".matches(info[1])) {
ignoreMe++;
Expand Down Expand Up @@ -624,6 +632,7 @@ else if (arg0.equals("targets") && sender.hasPermission("sentinel.info")) {
sender.sendMessage(prefixGood + "Entity Name Targets: " + ChatColor.AQUA + getNameTargetString(sentinel.entityNameTargets));
sender.sendMessage(prefixGood + "Held Item Targets: " + ChatColor.AQUA + getNameTargetString(sentinel.heldItemTargets));
sender.sendMessage(prefixGood + "Group Targets: " + ChatColor.AQUA + getNameTargetString(sentinel.groupTargets));
sender.sendMessage(prefixGood + "Event Targets: " + ChatColor.AQUA + getNameTargetString(sentinel.eventTargets));
sender.sendMessage(prefixGood + "Ignored Targets: " + ChatColor.AQUA + getTargetString(sentinel.ignores));
sender.sendMessage(prefixGood + "Ignored Player Name Targets: " + ChatColor.AQUA + getNameTargetString(sentinel.playerNameIgnores));
sender.sendMessage(prefixGood + "Ignored NPC Name Targets: " + ChatColor.AQUA + getNameTargetString(sentinel.npcNameIgnores));
Expand Down
22 changes: 22 additions & 0 deletions src/main/java/org/mcmonkey/sentinel/SentinelTrait.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ public SentinelTrait() {
@Persist("groupIgnores")
public List<String> groupIgnores = new ArrayList<String>();

@Persist("eventTargets")
public List<String> eventTargets = new ArrayList<String>();

@Persist("range")
public double range = 20.0;

Expand Down Expand Up @@ -239,6 +242,25 @@ else if (event.getDamager() instanceof Projectile) {
}
}
}
boolean isEventTarget = false;
if (eventTargets.contains("pvp")
&& event.getEntity() instanceof Player
&& !CitizensAPI.getNPCRegistry().isNPC(event.getEntity())) {
isEventTarget = true;
}
else if (eventTargets.contains("pve")
&& !(event.getEntity() instanceof Player)
&& event.getEntity() instanceof LivingEntity) {
isEventTarget = true;
}
else if (eventTargets.contains("pvnpc")
&& event.getEntity() instanceof LivingEntity
&& CitizensAPI.getNPCRegistry().isNPC(event.getEntity())) {
isEventTarget = true;
}
if (isEventTarget && canSee((LivingEntity) event.getDamager())) {
currentTargets.add(event.getDamager().getUniqueId());
}
}

@EventHandler
Expand Down

0 comments on commit 623ce10

Please sign in to comment.