Skip to content

Commit

Permalink
simplepets integration
Browse files Browse the repository at this point in the history
for #363
  • Loading branch information
mcmonkey4eva committed Feb 26, 2021
1 parent 5cf0f6f commit 4b1146f
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -120,6 +120,7 @@ Sentinel integrates with a few external plugins, including:
- Factions, for faction targets! (Use `factions:FACTION_HERE`, `factionsenemy:NAME`, `factionsally:NAME`)
- SimpleClans, for clan targets! (Use `simpleclan:CLAN_NAME_HERE`)
- War, for war team targets! (Use `war_team:WAR_TEAM_NAME`)
- SimplePets, for pet type targets! (Use `simplepet:PET_NAME_REGEX` ... in particular useful for `/sentinel addignore simplepet:.*` to ignore all pets)
- CrackShot, to allow NPCs to fire CrackShot weapons (just put the weapon in their hand).

Sentinel is integrated into by external plugins as well, including:
Expand Down
Binary file added lib/SimplePets.jar
Binary file not shown.
7 changes: 7 additions & 0 deletions pom.xml
Expand Up @@ -111,6 +111,13 @@
<scope>system</scope>
<systemPath>${basedir}/lib/SimpleClans.jar</systemPath>
</dependency>
<dependency>
<groupId>simplepets.brainsynder</groupId>
<artifactId>SimplePets</artifactId>
<version>4.4</version>
<scope>system</scope>
<systemPath>${basedir}/lib/SimplePets.jar</systemPath>
</dependency>
</dependencies>

<ciManagement>
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/org/mcmonkey/sentinel/SentinelPlugin.java
Expand Up @@ -413,6 +413,15 @@ public void run() {
ex.printStackTrace();
}
}
if (Bukkit.getPluginManager().getPlugin("SimplePets") != null) {
try {
registerIntegration(new SentinelSimplePets());
getLogger().info("Sentinel found SimplePets! Adding support for it!");
}
catch (Throwable ex) {
ex.printStackTrace();
}
}
new BukkitRunnable() {
@Override
public void run() {
Expand Down
@@ -0,0 +1,39 @@
package org.mcmonkey.sentinel.integration;

import org.bukkit.entity.LivingEntity;
import org.mcmonkey.sentinel.SentinelIntegration;
import org.mcmonkey.sentinel.SentinelUtilities;
import simplepets.brainsynder.api.pet.IPet;
import simplepets.brainsynder.reflection.ReflectionUtil;

public class SentinelSimplePets extends SentinelIntegration {

@Override
public String getTargetHelp() {
return "simplepet:PET_NAME_REGEX";
}

@Override
public String[] getTargetPrefixes() {
return new String[] { "simplepet" };
}

@Override
public boolean isTarget(LivingEntity ent, String prefix, String value) {
try {
if (!prefix.equals("simplepet")) {
return false;
}
Object handle = ReflectionUtil.getEntityHandle(ent);
if (handle instanceof IPet) {
String name = ((IPet) handle).getPetType().getName();
return SentinelUtilities.regexFor(value).matcher(name).matches();
}
return false;
}
catch (Exception ex) {
ex.printStackTrace();
}
return false;
}
}

0 comments on commit 4b1146f

Please sign in to comment.