Skip to content
Permalink
Browse files

Add GROUP target option, fixes #13

  • Loading branch information...
mcmonkey4eva committed Apr 18, 2016
1 parent a243369 commit 39e6db4d244ac2551866470ea9cb3abc4156ee54
@@ -68,7 +68,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)
- Also allowed: player:NAME(REGEX), npc:NAME(REGEX), entityname:NAME(REGEX), helditem:MATERIALNAME(REGEX), group:GROUPNAME(EXACT)

### Some random supported things

10 pom.xml
@@ -19,6 +19,10 @@
</properties>

<repositories>
<repository>
<id>vault-repo</id>
<url>http://nexus.theyeticave.net/content/repositories/pub_releases/</url>
</repository>
<repository>
<id>citizens-repo</id>
<url>http://repo.citizensnpcs.co</url>
@@ -47,6 +51,12 @@
<type>jar</type>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>net.milkbowl.vault</groupId>
<artifactId>Vault</artifactId>
<version>1.5.6</version>
<scope>provided</scope>
</dependency>
</dependencies>

<ciManagement>
@@ -4,6 +4,7 @@
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.api.trait.TraitInfo;
import net.citizensnpcs.api.trait.trait.Owner;
import net.milkbowl.vault.permission.Permission;
import org.bukkit.*;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
@@ -12,9 +13,9 @@
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;

@@ -36,6 +37,22 @@

public static SentinelPlugin instance;

public Permission vaultPerms;

public void tryGetPerms() {
if (Bukkit.getServer().getPluginManager().getPlugin("Vault") == null) {
return;
}
try {
RegisteredServiceProvider<Permission> rsp = Bukkit.getServer().getServicesManager().getRegistration(Permission.class);
vaultPerms = rsp.getProvider();
getLogger().info("Vault linked! Group targets will work.");
}
catch (Exception e) {
e.printStackTrace();
}
}

public int tickRate = 10;

static {
@@ -77,6 +94,7 @@ public void run() {
catch (Exception e) {
e.printStackTrace();
}
tryGetPerms();

}

@@ -144,6 +162,17 @@ else if (info[0].equalsIgnoreCase("entityname")) {
else if (info[0].equalsIgnoreCase("helditem")) {
names = sentinel.heldItemTargets;
}
else if (info[0].equalsIgnoreCase("group")) {
names = sentinel.groupTargets;
if (names.contains(info[1])) {
sender.sendMessage(prefixBad + "Already tracking that name target!");
}
else {
names.add(info[1]);
sender.sendMessage(prefixGood + "Tracking new target!");
}
return true;
}
try {
if ("Sentinel".matches(info[1])) {
ignoreMe++;
@@ -170,7 +199,7 @@ else if (info[0].equalsIgnoreCase("helditem")) {
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)");
sender.sendMessage(prefixGood + "Also allowed: player:NAME(REGEX), npc:NAME(REGEX), entityname:NAME(REGEX), helditem:MATERIALNAME(REGEX), group:GROUPNAME(EXACT)");
}
else {
if (sentinel.targets.add(target)) {
@@ -200,6 +229,16 @@ else if (info[0].equalsIgnoreCase("entityname")) {
else if (info[0].equalsIgnoreCase("helditem")) {
names = sentinel.heldItemTargets;
}
else if (info[0].equalsIgnoreCase("group")) {
names = sentinel.groupTargets;
if (!names.remove(info[1])) {
sender.sendMessage(prefixBad + "Not tracking that target!");
}
else {
sender.sendMessage(prefixGood + "No longer tracking that target!");
}
return true;
}
try {
if ("Sentinel".matches(info[1])) {
ignoreMe++;
@@ -211,7 +250,7 @@ else if (info[0].equalsIgnoreCase("helditem")) {
}
if (names != null) {
if (!names.remove(info[1])) {
sender.sendMessage(prefixBad + "Not tracking that name target!");
sender.sendMessage(prefixBad + "Not tracking that target!");
}
else {
sender.sendMessage(prefixGood + "No longer tracking that target!");
@@ -250,6 +289,17 @@ else if (info[0].equalsIgnoreCase("entityname")) {
else if (info[0].equalsIgnoreCase("helditem")) {
names = sentinel.heldItemIgnores;
}
else if (info[0].equalsIgnoreCase("group")) {
names = sentinel.groupIgnores;
if (!names.contains(info[1])) {
sender.sendMessage(prefixBad + "Already ignoring that target!");
}
else {
names.add(info[1]);
sender.sendMessage(prefixGood + "Ignoring new target!");
}
return true;
}
try {
if ("Sentinel".matches(info[1])) {
ignoreMe++;
@@ -261,7 +311,7 @@ else if (info[0].equalsIgnoreCase("helditem")) {
}
if (names != null) {
if (!names.contains(info[1])) {
sender.sendMessage(prefixBad + "Already ignoring that name target!");
sender.sendMessage(prefixBad + "Already ignoring that target!");
}
else {
names.add(info[1]);
@@ -301,6 +351,16 @@ else if (info[0].equalsIgnoreCase("entityname")) {
else if (info[0].equalsIgnoreCase("helditem")) {
names = sentinel.heldItemIgnores;
}
else if (info[0].equalsIgnoreCase("group")) {
names = sentinel.groupIgnores;
if (!names.remove(info[1])) {
sender.sendMessage(prefixBad + "Was not ignoring that target!");
}
else {
sender.sendMessage(prefixGood + "Not ignoring that target along longer!");
}
return true;
}
try {
if ("Sentinel".matches(info[1])) {
ignoreMe++;
@@ -312,7 +372,7 @@ else if (info[0].equalsIgnoreCase("helditem")) {
}
if (names != null) {
if (!names.remove(info[1])) {
sender.sendMessage(prefixBad + "Was not ignoring that name target!");
sender.sendMessage(prefixBad + "Was not ignoring that target!");
}
else {
sender.sendMessage(prefixGood + "Not ignoring that target along longer!");
@@ -563,11 +623,13 @@ else if (arg0.equals("targets") && sender.hasPermission("sentinel.info")) {
sender.sendMessage(prefixGood + "NPC Name Targets: " + ChatColor.AQUA + getNameTargetString(sentinel.npcNameTargets));
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 + "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));
sender.sendMessage(prefixGood + "Ignored Entity Name Targets: " + ChatColor.AQUA + getNameTargetString(sentinel.entityNameIgnores));
sender.sendMessage(prefixGood + "Ignored Held Item Targets: " + ChatColor.AQUA + getNameTargetString(sentinel.heldItemIgnores));
sender.sendMessage(prefixGood + "Ignored Group Targets: " + ChatColor.AQUA + getNameTargetString(sentinel.groupIgnores));
return true;
}
else if (arg0.equals("info") && sender.hasPermission("sentinel.info")) {
@@ -94,6 +94,12 @@ public SentinelTrait() {
@Persist("heldItemIgnores")
public List<String> heldItemIgnores = new ArrayList<String>();

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

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

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

@@ -798,6 +804,13 @@ else if (entity instanceof Player) {
if (isRegexTargeted(((Player) entity).getName(), playerNameIgnores)) {
return true;
}
if (SentinelPlugin.instance.vaultPerms != null) {
for (String group : groupIgnores) {
if (SentinelPlugin.instance.vaultPerms.playerInGroup((Player) entity, group)) {
return true;
}
}
}
}
else if (isRegexTargeted(entity.getCustomName() == null ? entity.getType().name(): entity.getCustomName(), entityNameIgnores)) {
return true;
@@ -830,6 +843,13 @@ public boolean isTargeted(LivingEntity entity) {
if (isRegexTargeted(((Player) entity).getName(), playerNameTargets)) {
return true;
}
if (SentinelPlugin.instance.vaultPerms != null) {
for (String group : groupTargets) {
if (SentinelPlugin.instance.vaultPerms.playerInGroup((Player) entity, group)) {
return true;
}
}
}
}
else if (isRegexTargeted(entity.getCustomName() == null ? entity.getType().name(): entity.getCustomName(), entityNameTargets)) {
return true;
@@ -3,6 +3,7 @@ authors: ['mcmonkey']
version: ${project.version} (build ${BUILD_NUMBER})
main: org.mcmonkey.sentinel.SentinelPlugin
depend: [Citizens]
softdepend: [Vault]

commands:
sentinel:

0 comments on commit 39e6db4

Please sign in to comment.
You can’t perform that action at this time.