Add in the long awaited feature to have monsters ignore disguises

This commit is contained in:
libraryaddict 2014-01-20 09:25:29 +13:00
parent 5e5c132aa0
commit 58ee6f37b7
5 changed files with 36 additions and 2 deletions

View File

@ -44,4 +44,7 @@ NameAboveHeadAlwaysVisible: true
# This modifys the bounding box, This is stuff like can a arrow hit them.
# If you turn this to true, arrows will act like they hit the disguise in the right place!
# So someone disguised as a enderdragon will easily get shot down by arrows!
# This may have conflicts with some plugins, such as nocheatplus
ModifyBoundingBox: false
# This prevents disguised players from being targeted by monsters.
MonstersIgnoreDisguises: false

View File

@ -64,7 +64,7 @@
<version>3.1.0</version>
</dependency>
</dependencies>
<version>7.9.5</version>
<version>7.9.5-SNAPSHOT</version>
<distributionManagement>
<repository>

View File

@ -14,6 +14,7 @@ import me.libraryaddict.disguise.utilities.PacketsManager;
import me.libraryaddict.disguise.utilities.ReflectionManager;
import org.bukkit.Bukkit;
import org.bukkit.entity.Creature;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
@ -27,6 +28,7 @@ public class DisguiseAPI {
private static boolean sendVelocity;
private static boolean showNameAboveHead;
private static boolean showNameAboveHeadAlwaysVisible;
private static boolean targetDisguises;
@Deprecated
public static boolean canHearSelfDisguise() {
@ -62,6 +64,16 @@ public class DisguiseAPI {
DisguiseUtilities.refreshTrackers((TargetedDisguise) disguise);
// If he is a player, then self disguise himself
DisguiseUtilities.setupFakeDisguise(disguise);
// If the disguised is a player and you can't target disguised players..
if (isMonstersIgnoreDisguises() && entity instanceof Player) {
for (Entity monster : entity.getWorld().getEntities()) {
if (monster instanceof Creature) {
if (((Creature) monster).getTarget() == entity) {
((Creature) monster).setTarget(null);
}
}
}
}
}
public static void disguiseIgnorePlayers(Entity entity, Disguise disguise, List<String> playersToNotSeeDisguise) {
@ -205,6 +217,10 @@ public class DisguiseAPI {
return modifyBoundingBox;
}
public static boolean isMonstersIgnoreDisguises() {
return targetDisguises;
}
public static boolean isNameAboveHeadAlwaysVisible() {
return showNameAboveHeadAlwaysVisible;
}
@ -279,6 +295,10 @@ public class DisguiseAPI {
modifyBoundingBox = modifyBounding;
}
public static void setMonstersIgnoreDisguises(boolean ignore) {
targetDisguises = ignore;
}
public static void setNameAboveHeadAlwaysVisible(boolean alwaysVisible) {
showNameAboveHeadAlwaysVisible = alwaysVisible;
}

View File

@ -14,6 +14,8 @@ import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityTargetEvent;
import org.bukkit.event.entity.EntityTargetEvent.TargetReason;
import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
@ -109,6 +111,14 @@ public class DisguiseListener implements Listener {
}
}
@EventHandler
public void onTarget(EntityTargetEvent event) {
if (DisguiseAPI.isMonstersIgnoreDisguises() && event.getReason() != TargetReason.CUSTOM && event.getTarget() != null
&& event.getTarget() instanceof Player && DisguiseAPI.isDisguised(event.getTarget())) {
event.setCancelled(true);
}
}
@EventHandler(priority = EventPriority.MONITOR)
public void onVechileEnter(VehicleEnterEvent event) {
if (event.isCancelled())

View File

@ -68,6 +68,7 @@ public class LibsDisguises extends JavaPlugin {
DisguiseAPI.setNameOfPlayerShownAboveDisguise(getConfig().getBoolean("ShowNamesAboveDisguises"));
DisguiseAPI.setNameAboveHeadAlwaysVisible(getConfig().getBoolean("NameAboveHeadAlwaysVisible"));
DisguiseAPI.setModifyBoundingBox(getConfig().getBoolean("ModifyBoundingBox"));
DisguiseAPI.setMonstersIgnoreDisguises(getConfig().getBoolean("MonstersIgnoreDisguises"));
try {
// Here I use reflection to set the plugin for Disguise..
// Kind of stupid but I don't want open API calls for a commonly used object.