Skip to content
Permalink
Browse files

Add health above/below targets!

  • Loading branch information...
mcmonkey4eva committed Dec 4, 2016
1 parent 1a73389 commit 58cb30fbbad64541db966a4e115941cd6bf7e11a
@@ -103,7 +103,8 @@ 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, event:pvp/pvnpc/pve/pvsentinel
- Also, sbteam:SCOREBOARD_TEAM_HERE
- Also, sbteam:SCOREBOARD\_TEAM\_HERE
- Also, healthabove:PERCENTAGE and healthbelow:PERCENTAGE
- Also anything listed in the integrations section above!

### Some random supported things
@@ -20,6 +20,7 @@
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;
import org.mcmonkey.sentinel.integration.SentinelFactions;
import org.mcmonkey.sentinel.integration.SentinelHealth;
import org.mcmonkey.sentinel.integration.SentinelSBTeams;
import org.mcmonkey.sentinel.integration.SentinelTowny;

@@ -103,6 +104,7 @@ public void run() {
e.printStackTrace();
}
tryGetPerms();
integrations.add(new SentinelHealth());
integrations.add(new SentinelSBTeams());
if (Bukkit.getPluginManager().getPlugin("Towny") != null) {
try {
@@ -0,0 +1,43 @@
package org.mcmonkey.sentinel.integration;

import org.bukkit.Bukkit;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.scoreboard.Team;
import org.mcmonkey.sentinel.SentinelIntegration;

public class SentinelHealth extends SentinelIntegration {

@Override
public String getTargetHelp() {
return "healthabove:PERCENTAGE, healthbelow:PERCENTAGE";
}

@Override
public boolean isTarget(LivingEntity ent, String text) {
try {
if (text.startsWith("healthabove:")) {
String haText = text.substring("healthabove:".length());
double haVal = Double.parseDouble(haText);
if (ent.getHealth() / ent.getMaxHealth() > haVal * 0.01) {
return true;
}
}
else if (text.startsWith("healthbelow:")) {
String haText = text.substring("healthbelow:".length());
double haVal = Double.parseDouble(haText);
if (ent.getHealth() / ent.getMaxHealth() < haVal * 0.01) {
return true;
}
}
}
catch (NumberFormatException ex) {
// Do nothing.
// TODO: Maybe show a one-time warning?
}
catch (Exception ex) {
ex.printStackTrace();
}
return false;
}
}

0 comments on commit 58cb30f

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