From 27230d5148ddd253d8ad72e91a51659ffc58b8e6 Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Thu, 22 Jun 2017 23:58:48 +1200 Subject: [PATCH] Added new config option for blown disguises --- config.yml | 10 +++---- .../disguise/DisguiseConfig.java | 27 +++++++++++++------ .../disguise/DisguiseListener.java | 20 +++++++------- .../disguise/utilities/DisguiseParser.java | 13 ++++----- 4 files changed, 40 insertions(+), 30 deletions(-) diff --git a/config.yml b/config.yml index cc7e79fc..7eaf51e3 100644 --- a/config.yml +++ b/config.yml @@ -106,11 +106,11 @@ ModifyBoundingBox: false # They will just ignore you unless provoked. MonstersIgnoreDisguises: false -# Sigh. People are going to want this. -# So lets make your disguise blown if you are attacked.. -# Works only for disguised players when attacked by a entity (arrow, monster. etc) -# This will blow all disguises he has on him -BlowDisguises: false +# This works only for players, disguised monsters and the like will not be undisguised +# Should the player's disguises be removed if he attacks something? +BlowDisguisesWhenAttacking: false +# Should the player's disguises be removed if he's attacked by something? +BlowDisguisesWhenAttacked: false #Stop shulker disguises from moving, they're weird. This option only effects PLAYERS that are disguised, other entities disguised as shulkers will NOT be effected! StopShulkerDisguisesFromMoving: true diff --git a/src/me/libraryaddict/disguise/DisguiseConfig.java b/src/me/libraryaddict/disguise/DisguiseConfig.java index 83a36c6a..32e1610b 100644 --- a/src/me/libraryaddict/disguise/DisguiseConfig.java +++ b/src/me/libraryaddict/disguise/DisguiseConfig.java @@ -6,7 +6,6 @@ import java.util.Map.Entry; import me.libraryaddict.disguise.utilities.TranslateType; import org.bukkit.Bukkit; -import org.bukkit.ChatColor; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.YamlConfiguration; @@ -17,12 +16,15 @@ import me.libraryaddict.disguise.utilities.PacketsManager; public class DisguiseConfig { public static enum DisguisePushing { // This enum has a really bad name.. - MODIFY_SCOREBOARD, IGNORE_SCOREBOARD, CREATE_SCOREBOARD; + MODIFY_SCOREBOARD, + IGNORE_SCOREBOARD, + CREATE_SCOREBOARD; } private static boolean animationEnabled; private static boolean bedEnabled; - private static boolean blowDisguisesOnAttack; + private static boolean blowDisguisesWhenAttacking; + private static boolean blowDisguisesWhenAttacked; private static boolean collectEnabled; private static boolean colorizeSheep; private static boolean colorizeWolf; @@ -154,7 +156,8 @@ public class DisguiseConfig { setNameAboveHeadAlwaysVisible(config.getBoolean("NameAboveHeadAlwaysVisible")); setModifyBoundingBox(config.getBoolean("ModifyBoundingBox")); setMonstersIgnoreDisguises(config.getBoolean("MonstersIgnoreDisguises")); - setDisguiseBlownOnAttack(config.getBoolean("BlowDisguises")); + setDisguiseBlownWhenAttacking(config.getBoolean("BlowDisguises", config.getBoolean("BlowDisguisesWhenAttacking"))); + setDisguiseBlownWhenAttacked(config.getBoolean("BlowDisguisesWhenAttacked")); setKeepDisguiseOnPlayerDeath(config.getBoolean("KeepDisguises.PlayerDeath")); setMiscDisguisesForLivingEnabled(config.getBoolean("MiscDisguisesForLiving")); setMovementPacketsEnabled(config.getBoolean("PacketsEnabled.Movement")); @@ -264,8 +267,12 @@ public class DisguiseConfig { return disableInvisibility; } - public static boolean isDisguiseBlownOnAttack() { - return blowDisguisesOnAttack; + public static boolean isDisguiseBlownWhenAttacking() { + return blowDisguisesWhenAttacking; + } + + public static boolean isDisguiseBlownWhenAttacked() { + return blowDisguisesWhenAttacked; } public static boolean isEntityAnimationsAdded() { @@ -419,8 +426,12 @@ public class DisguiseConfig { disableInvisibility = disableInvis; } - public static void setDisguiseBlownOnAttack(boolean blowDisguise) { - blowDisguisesOnAttack = blowDisguise; + public static void setDisguiseBlownWhenAttacking(boolean blowDisguise) { + blowDisguisesWhenAttacking = blowDisguise; + } + + public static void setDisguiseBlownWhenAttacked(boolean blowDisguise) { + blowDisguisesWhenAttacked = blowDisguise; } public static void setDisguiseCloneExpire(int newExpires) { diff --git a/src/me/libraryaddict/disguise/DisguiseListener.java b/src/me/libraryaddict/disguise/DisguiseListener.java index 9668d9b4..6da72926 100644 --- a/src/me/libraryaddict/disguise/DisguiseListener.java +++ b/src/me/libraryaddict/disguise/DisguiseListener.java @@ -132,16 +132,16 @@ public class DisguiseListener implements Listener { updaterTask.cancel(); } - private void checkPlayerCanBlowDisguise(Player entity) { - Disguise[] disguises = DisguiseAPI.getDisguises(entity); + private void checkPlayerCanBlowDisguise(Player player) { + Disguise[] disguises = DisguiseAPI.getDisguises(player); if (disguises.length > 0) { - DisguiseAPI.undisguiseToAll(entity); + DisguiseAPI.undisguiseToAll(player); String blown = LibsMsg.BLOWN_DISGUISE.get(); if (blown.length() > 0) { - entity.sendMessage(blown); + player.sendMessage(blown); } } } @@ -195,14 +195,12 @@ public class DisguiseListener implements Listener { @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public void onAttack(EntityDamageByEntityEvent event) { - if (DisguiseConfig.isDisguiseBlownOnAttack()) { - if (event.getEntity() instanceof Player) { - checkPlayerCanBlowDisguise((Player) event.getEntity()); - } + if (DisguiseConfig.isDisguiseBlownWhenAttacked() && event.getEntity() instanceof Player) { + checkPlayerCanBlowDisguise((Player) event.getEntity()); + } - if (event.getDamager() instanceof Player) { - checkPlayerCanBlowDisguise((Player) event.getDamager()); - } + if (DisguiseConfig.isDisguiseBlownWhenAttacking() && event.getDamager() instanceof Player) { + checkPlayerCanBlowDisguise((Player) event.getDamager()); } } diff --git a/src/me/libraryaddict/disguise/utilities/DisguiseParser.java b/src/me/libraryaddict/disguise/utilities/DisguiseParser.java index 0899e351..6b4f7770 100644 --- a/src/me/libraryaddict/disguise/utilities/DisguiseParser.java +++ b/src/me/libraryaddict/disguise/utilities/DisguiseParser.java @@ -7,6 +7,7 @@ import java.util.HashMap; import java.util.Map.Entry; import com.mojang.authlib.GameProfile; +import org.bukkit.Art; import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.block.BlockFace; @@ -758,23 +759,23 @@ public class DisguiseParser { } value = items; - } else if (param.getSimpleName().equals("Color")) { + } else if (param == Horse.Color.class) { // Parse to horse color value = callValueOf(param, valueString, methodName); - } else if (param.getSimpleName().equals("Style")) { + } else if (param == Horse.Style.class) { // Parse to horse style value = callValueOf(param, valueString, methodName); - } else if (param.getSimpleName().equals("Profession")) { + } else if (param == Villager.Profession.class) { // Parse to villager profession value = callValueOf(param, valueString, methodName); - } else if (param.getSimpleName().equals("Art")) { + } else if (param == Art.class) { // Parse to art type value = callValueOf(param, valueString, methodName); - } else if (param.getSimpleName().equals("Type")) { + } else if (param == Ocelot.Type.class) { // Parse to ocelot type value = callValueOf(param, valueString, methodName); } else if (param.getSimpleName().equals("TreeSpecies")) { - // Parse to ocelot type + // Parse to tree species value = callValueOf(param, valueString, methodName); } else if (param == PotionEffectType.class) { // Parse to potion effect