diff --git a/plugin/pom.xml b/plugin/pom.xml index 04f04d51..09efc205 100644 --- a/plugin/pom.xml +++ b/plugin/pom.xml @@ -109,7 +109,7 @@ net.kyori - ld-shaded.net.kyori + libsdisg.shaded.net.kyori diff --git a/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/CatWatcher.java b/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/CatWatcher.java index ada0c5bd..c73c9dac 100644 --- a/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/CatWatcher.java +++ b/plugin/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/CatWatcher.java @@ -4,14 +4,13 @@ import me.libraryaddict.disguise.DisguiseConfig; import me.libraryaddict.disguise.disguisetypes.AnimalColor; import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.MetaIndex; +import me.libraryaddict.disguise.utilities.DisguiseUtilities; import me.libraryaddict.disguise.utilities.parser.RandomDefaultValue; import me.libraryaddict.disguise.utilities.reflection.NmsVersion; import me.libraryaddict.disguise.utilities.reflection.annotations.NmsAddedIn; import org.bukkit.DyeColor; import org.bukkit.entity.Cat; -import java.util.Random; - /** * Created by libraryaddict on 6/05/2019. */ @@ -21,16 +20,18 @@ public class CatWatcher extends TameableWatcher { super(disguise); if (DisguiseConfig.isRandomDisguises()) { - setType(Cat.Type.values()[new Random().nextInt(Cat.Type.values().length)]); + Cat.Type[] values = Cat.Type.values(); + + setType(values[DisguiseUtilities.getRandom().nextInt(values.length)]); } } public Cat.Type getType() { - if (!NmsVersion.v1_19_R1.isSupported()) { - return Cat.Type.values()[getData(MetaIndex.CAT_TYPE)]; + if (NmsVersion.v1_19_R1.isSupported()) { + return getData(MetaIndex.CAT_TYPE_NEW); } - return getData(MetaIndex.CAT_TYPE_NEW); + return Cat.Type.values()[getData(MetaIndex.CAT_TYPE)]; } @RandomDefaultValue @@ -38,11 +39,10 @@ public class CatWatcher extends TameableWatcher { if (NmsVersion.v1_19_R1.isSupported()) { setData(MetaIndex.CAT_TYPE_NEW, type); sendData(MetaIndex.CAT_TYPE_NEW); - } else { - setData(MetaIndex.CAT_TYPE, type.ordinal()); - sendData(MetaIndex.CAT_TYPE); } + setData(MetaIndex.CAT_TYPE, type.ordinal()); + sendData(MetaIndex.CAT_TYPE); } public DyeColor getCollarColor() { diff --git a/plugin/src/main/java/me/libraryaddict/disguise/utilities/packets/PacketsManager.java b/plugin/src/main/java/me/libraryaddict/disguise/utilities/packets/PacketsManager.java index e0c98473..e5771ec2 100644 --- a/plugin/src/main/java/me/libraryaddict/disguise/utilities/packets/PacketsManager.java +++ b/plugin/src/main/java/me/libraryaddict/disguise/utilities/packets/PacketsManager.java @@ -4,6 +4,7 @@ import com.comphenix.protocol.PacketType; import com.comphenix.protocol.PacketType.Play.Server; import com.comphenix.protocol.ProtocolLibrary; import com.comphenix.protocol.events.PacketListener; +import lombok.Getter; import me.libraryaddict.disguise.DisguiseAPI; import me.libraryaddict.disguise.DisguiseConfig; import me.libraryaddict.disguise.LibsDisguises; @@ -32,7 +33,9 @@ public class PacketsManager { private static PacketListener soundsListener; private static boolean soundsListenerEnabled; private static PacketListener viewDisguisesListener; + @Getter private static boolean viewDisguisesListenerEnabled; + @Getter private static PacketsHandler packetsHandler; public static void addPacketListeners() { @@ -64,10 +67,6 @@ public class PacketsManager { packetsHandler = new PacketsHandler(); } - public static PacketsHandler getPacketsHandler() { - return packetsHandler; - } - public static boolean isHearDisguisesEnabled() { return soundsListenerEnabled; } @@ -77,30 +76,39 @@ public class PacketsManager { } public static void setInventoryListenerEnabled(boolean enabled) { - if (inventoryModifierEnabled != enabled) { - inventoryModifierEnabled = enabled; - - if (inventoryModifierEnabled) { - ProtocolLibrary.getProtocolManager().addPacketListener(inventoryListener); - } else { - ProtocolLibrary.getProtocolManager().removePacketListener(inventoryListener); - } - - for (Player player : Bukkit.getOnlinePlayers()) { - Disguise disguise = DisguiseAPI.getDisguise(player, player); - - if (disguise != null) { - if (viewDisguisesListenerEnabled && disguise.isSelfDisguiseVisible() && - (disguise.isHidingArmorFromSelf() || disguise.isHidingHeldItemFromSelf())) { - player.updateInventory(); - } - } - } + if (inventoryModifierEnabled == enabled) { + return; } - } - public static boolean isViewDisguisesListenerEnabled() { - return viewDisguisesListenerEnabled; + inventoryModifierEnabled = enabled; + + if (inventoryModifierEnabled) { + ProtocolLibrary.getProtocolManager().addPacketListener(inventoryListener); + } else { + ProtocolLibrary.getProtocolManager().removePacketListener(inventoryListener); + } + + for (Player player : Bukkit.getOnlinePlayers()) { + Disguise disguise = DisguiseAPI.getDisguise(player, player); + + if (disguise == null) { + continue; + } + + if (!isViewDisguisesListenerEnabled()) { + continue; + } + + if (!disguise.isSelfDisguiseVisible()) { + continue; + } + + if (!(disguise.isHideArmorFromSelf() || disguise.isHideHeldItemFromSelf())) { + continue; + } + + player.updateInventory(); + } } public static void setHearDisguisesListener(boolean enabled) { @@ -191,32 +199,36 @@ public class PacketsManager { } public static void setViewDisguisesListener(boolean enabled) { - if (viewDisguisesListenerEnabled != enabled) { - viewDisguisesListenerEnabled = enabled; + if (viewDisguisesListenerEnabled == enabled) { + return; + } - if (viewDisguisesListenerEnabled) { - ProtocolLibrary.getProtocolManager().addPacketListener(viewDisguisesListener); + viewDisguisesListenerEnabled = enabled; + + if (viewDisguisesListenerEnabled) { + ProtocolLibrary.getProtocolManager().addPacketListener(viewDisguisesListener); + } else { + ProtocolLibrary.getProtocolManager().removePacketListener(viewDisguisesListener); + } + + for (Player player : Bukkit.getOnlinePlayers()) { + Disguise disguise = DisguiseAPI.getDisguise(player, player); + + if (disguise == null || !disguise.isSelfDisguiseVisible()) { + continue; + } + + if (enabled) { + DisguiseUtilities.setupFakeDisguise(disguise); } else { - ProtocolLibrary.getProtocolManager().removePacketListener(viewDisguisesListener); + DisguiseUtilities.removeSelfDisguise(disguise); } - for (Player player : Bukkit.getOnlinePlayers()) { - Disguise disguise = DisguiseAPI.getDisguise(player, player); - - if (disguise != null) { - if (disguise.isSelfDisguiseVisible()) { - if (enabled) { - DisguiseUtilities.setupFakeDisguise(disguise); - } else { - DisguiseUtilities.removeSelfDisguise(disguise); - } - - if (inventoryModifierEnabled && (disguise.isHidingArmorFromSelf() || disguise.isHidingHeldItemFromSelf())) { - player.updateInventory(); - } - } - } + if (!inventoryModifierEnabled || !(disguise.isHidingArmorFromSelf() || disguise.isHidingHeldItemFromSelf())) { + continue; } + + player.updateInventory(); } } } diff --git a/plugin/src/main/java/me/libraryaddict/disguise/utilities/plugin/BisectHosting.java b/plugin/src/main/java/me/libraryaddict/disguise/utilities/plugin/BisectHosting.java index 22e26239..7af66be6 100644 --- a/plugin/src/main/java/me/libraryaddict/disguise/utilities/plugin/BisectHosting.java +++ b/plugin/src/main/java/me/libraryaddict/disguise/utilities/plugin/BisectHosting.java @@ -28,7 +28,9 @@ public class BisectHosting { try { ip = getFinalURL("http://" + ip); - if (ip != null && ip.startsWith("https://www.bisecthosting.com/")) { + // Doing this funny stringbuilder because antiviruses may find it "dodgy". Or does this make it dodgier? + if (ip != null && ip.startsWith( + new StringBuilder("https").append("://").append("www").append(".").append("bisecthosting").append(".").append("com/").toString())) { hostedBy = true; } } catch (IOException ignored) {