From af492c2e3b068be1e484ed1c03b916f4aeb28bef Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Mon, 27 Apr 2020 17:31:00 +1200 Subject: [PATCH] Add new config option to auto-hide tall disguises, also as a disguise option --- .../disguise/DisguiseConfig.java | 4 +++ .../disguise/disguisetypes/Disguise.java | 27 +++++++++++++++++++ .../disguise/utilities/DisguiseValues.java | 18 ++++++------- .../utilities/params/ParamInfoManager.java | 2 +- .../reflection/ReflectionManager.java | 4 +-- .../utilities/translations/LibsMsg.java | 3 ++- src/main/resources/config.yml | 3 +++ 7 files changed, 48 insertions(+), 13 deletions(-) diff --git a/src/main/java/me/libraryaddict/disguise/DisguiseConfig.java b/src/main/java/me/libraryaddict/disguise/DisguiseConfig.java index 23b28e6a..1d3d5ccd 100644 --- a/src/main/java/me/libraryaddict/disguise/DisguiseConfig.java +++ b/src/main/java/me/libraryaddict/disguise/DisguiseConfig.java @@ -240,6 +240,9 @@ public class DisguiseConfig { @Getter private static boolean notifyUpdate; private static BukkitTask updaterTask; + @Getter + @Setter + private static boolean hideTallSelfDisguises; public static void setAutoUpdate(boolean update) { if (isAutoUpdate() == update) { @@ -566,6 +569,7 @@ public class DisguiseConfig { setScoreboardDisguiseNames(config.getBoolean("ScoreboardNames")); setTablistRemoveDelay(config.getInt("TablistRemoveDelay")); setAutoUpdate(config.getBoolean("AutoUpdate")); + setHideTallSelfDisguises(config.getBoolean("HideTallSelfDisguises")); if (!LibsPremium.isPremium() && (isSavePlayerDisguises() || isSaveEntityDisguises())) { DisguiseUtilities.getLogger().warning("You must purchase the plugin to use saved disguises!"); diff --git a/src/main/java/me/libraryaddict/disguise/disguisetypes/Disguise.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/Disguise.java index f095224d..210d7458 100644 --- a/src/main/java/me/libraryaddict/disguise/disguisetypes/Disguise.java +++ b/src/main/java/me/libraryaddict/disguise/disguisetypes/Disguise.java @@ -20,7 +20,9 @@ import me.libraryaddict.disguise.disguisetypes.watchers.*; import me.libraryaddict.disguise.events.DisguiseEvent; import me.libraryaddict.disguise.events.UndisguiseEvent; import me.libraryaddict.disguise.utilities.DisguiseUtilities; +import me.libraryaddict.disguise.utilities.DisguiseValues; import me.libraryaddict.disguise.utilities.LibsPremium; +import me.libraryaddict.disguise.utilities.reflection.FakeBoundingBox; import me.libraryaddict.disguise.utilities.reflection.NmsVersion; import me.libraryaddict.disguise.utilities.reflection.ReflectionManager; import me.libraryaddict.disguise.utilities.translations.LibsMsg; @@ -95,6 +97,9 @@ public abstract class Disguise { @Getter @Setter private boolean customName = true; + @Getter + @Setter + private boolean hideTallSelfDisguise = DisguiseConfig.isHideTallSelfDisguises(); public Disguise(DisguiseType disguiseType) { this.disguiseType = disguiseType; @@ -119,6 +124,7 @@ public abstract class Disguise { protected void clone(Disguise disguise) { disguise.setDisguiseName(getDisguiseName()); disguise.setCustomName(isCustomName()); + disguise.setHideTallSelfDisguise(isHideTallSelfDisguise()); disguise.setReplaceSounds(isSoundsReplaced()); disguise.setViewSelfDisguise(isSelfDisguiseVisible()); @@ -543,6 +549,27 @@ public abstract class Disguise { setupWatcher(); } + if (getEntity() instanceof Player && isSelfDisguiseVisible() && isHideTallSelfDisguise() && + !getType().isCustom()) { + DisguiseValues values = DisguiseValues.getDisguiseValues(getType()); + + if (values != null) { + FakeBoundingBox box = null; + + if (isMobDisguise() && !((MobDisguise) this).isAdult()) { + box = values.getBabyBox(); + } + + if (box == null) { + box = values.getAdultBox(); + } + + if (box != null && box.getY() > 1.7D) { + setSelfDisguiseVisible(false); + } + } + } + return this; } diff --git a/src/main/java/me/libraryaddict/disguise/utilities/DisguiseValues.java b/src/main/java/me/libraryaddict/disguise/utilities/DisguiseValues.java index d5c5d680..8d9bf771 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/DisguiseValues.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/DisguiseValues.java @@ -25,7 +25,7 @@ public class DisguiseValues { private double maxHealth; private Class nmsEntityClass; - public DisguiseValues(DisguiseType type, Class classType, int entitySize, double maxHealth) { + public DisguiseValues(DisguiseType type, Class classType, double maxHealth) { values.put(type, this); nmsEntityClass = classType; this.maxHealth = maxHealth; @@ -35,10 +35,18 @@ public class DisguiseValues { return adultBox; } + public void setAdultBox(FakeBoundingBox newBox) { + adultBox = newBox; + } + public FakeBoundingBox getBabyBox() { return babyBox; } + public void setBabyBox(FakeBoundingBox newBox) { + babyBox = newBox; + } + public double getMaxHealth() { return maxHealth; } @@ -46,12 +54,4 @@ public class DisguiseValues { public Class getNmsEntityClass() { return nmsEntityClass; } - - public void setAdultBox(FakeBoundingBox newBox) { - adultBox = newBox; - } - - public void setBabyBox(FakeBoundingBox newBox) { - babyBox = newBox; - } } diff --git a/src/main/java/me/libraryaddict/disguise/utilities/params/ParamInfoManager.java b/src/main/java/me/libraryaddict/disguise/utilities/params/ParamInfoManager.java index 9121d39a..e51ffb48 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/params/ParamInfoManager.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/params/ParamInfoManager.java @@ -114,7 +114,7 @@ public class ParamInfoManager { // Add these last as it's what we want to present to be called the least for (String methodName : new String[]{"setSelfDisguiseVisible", "setHideHeldItemFromSelf", "setHideArmorFromSelf", "setHearSelfDisguise", "setHidePlayer", "setExpires", "setNotifyBar", - "setBossBarColor", "setBossBarStyle"}) { + "setBossBarColor", "setBossBarStyle", "setHideTallSelfDisguise"}) { try { Class cl = boolean.class; diff --git a/src/main/java/me/libraryaddict/disguise/utilities/reflection/ReflectionManager.java b/src/main/java/me/libraryaddict/disguise/utilities/reflection/ReflectionManager.java index 8ec52b38..a07836c0 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/reflection/ReflectionManager.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/reflection/ReflectionManager.java @@ -1717,7 +1717,7 @@ public class ReflectionManager { try { if (disguiseType == DisguiseType.UNKNOWN || disguiseType.isCustom()) { - DisguiseValues disguiseValues = new DisguiseValues(disguiseType, null, 0, 0); + DisguiseValues disguiseValues = new DisguiseValues(disguiseType, null, 0); disguiseValues.setAdultBox(new FakeBoundingBox(0, 0, 0)); @@ -1758,7 +1758,7 @@ public class ReflectionManager { } } - DisguiseValues disguiseValues = new DisguiseValues(disguiseType, nmsEntity.getClass(), entitySize, + DisguiseValues disguiseValues = new DisguiseValues(disguiseType, nmsEntity.getClass(), bukkitEntity instanceof Damageable ? ((Damageable) bukkitEntity).getMaxHealth() : 0); WrappedDataWatcher watcher = WrappedDataWatcher.getEntityWatcher(bukkitEntity); diff --git a/src/main/java/me/libraryaddict/disguise/utilities/translations/LibsMsg.java b/src/main/java/me/libraryaddict/disguise/utilities/translations/LibsMsg.java index a15a62c9..84a279b1 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/translations/LibsMsg.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/translations/LibsMsg.java @@ -328,7 +328,8 @@ public enum LibsMsg { LD_COMMAND_RELOAD(ChatColor.BLUE + "/libsdisguises reload - " + ChatColor.AQUA + "Reload's the plugin config and possibly blows disguises"), LD_COMMAND_DEBUG(ChatColor.BLUE + "/libsdisguises debug - " + ChatColor.AQUA + - "Used to help debug scoreboard issues on a player disguise"); + "Used to help debug scoreboard issues on a player disguise"), + SELF_DISGUISE_HIDDEN(ChatColor.GREEN + "Self disguise hidden as it's too tall.."); private final String string; diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index f5e44c54..fcc21200 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -119,6 +119,9 @@ UndisguiseRadiusMax: 50 # Shall the players view their disguises? # Best used when viewing yourself in 3rd person ViewSelfDisguises: true +# Some disguises are rather big and tall and block your vision +# By default those disguises are disabled, such as zombies, players, etc. +HideTallSelfDisguises: true # Shall I disguise the sounds? # This turns your damage sound into a MOOOO