From 52cb313f77c58330b1af4eacd118cd026d372e29 Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Sat, 11 Dec 2021 20:57:23 +1300 Subject: [PATCH] Fix up sounds and some other stuff --- .../libraryaddict/disguise/LibsDisguises.java | 18 +++++--- .../packetlisteners/PacketListenerSounds.java | 44 +++++++++---------- .../utilities/reflection/ClassMappings.java | 24 ++++++---- .../reflection/ReflectionManager.java | 2 + .../utilities/sounds/SoundManager.java | 2 - .../reflection/v1_17/ReflectionManager.java | 14 +++++- .../reflection/v1_18/ReflectionManager.java | 34 +++++++++----- 7 files changed, 86 insertions(+), 52 deletions(-) diff --git a/plugin/src/main/java/me/libraryaddict/disguise/LibsDisguises.java b/plugin/src/main/java/me/libraryaddict/disguise/LibsDisguises.java index 736dc426..360b3867 100644 --- a/plugin/src/main/java/me/libraryaddict/disguise/LibsDisguises.java +++ b/plugin/src/main/java/me/libraryaddict/disguise/LibsDisguises.java @@ -24,6 +24,7 @@ import me.libraryaddict.disguise.utilities.listeners.PaperDisguiseListener; import me.libraryaddict.disguise.utilities.listeners.PlayerSkinHandler; import me.libraryaddict.disguise.utilities.metrics.MetricsInitalizer; import me.libraryaddict.disguise.utilities.packets.PacketsManager; +import me.libraryaddict.disguise.utilities.params.ParamInfoManager; import me.libraryaddict.disguise.utilities.parser.DisguiseParser; import me.libraryaddict.disguise.utilities.reflection.NmsVersion; import me.libraryaddict.disguise.utilities.reflection.ReflectionManager; @@ -83,8 +84,8 @@ public class LibsDisguises extends JavaPlugin { getLogger().severe("Please restart the server to complete the ProtocolLib update!"); } } catch (Exception e) { - getLogger() - .severe("Looks like ProtocolLib's site may be down! MythicCraft/MythicMobs has a discord server https://discord.gg/EErRhJ4qgx you" + + getLogger().severe( + "Looks like ProtocolLib's site may be down! MythicCraft/MythicMobs has a discord server https://discord.gg/EErRhJ4qgx you" + " can " + "join. Check the pins in #libs-support for a ProtocolLib.jar you can download!"); e.printStackTrace(); } @@ -164,8 +165,8 @@ public class LibsDisguises extends JavaPlugin { LibsPremium.check(getDescription().getVersion(), getFile()); if (!LibsPremium.isPremium()) { - getLogger() - .info("You are running the free version, commands limited to non-players and operators. (Console," + " Command " + "Blocks, Admins)"); + getLogger().info( + "You are running the free version, commands limited to non-players and operators. (Console," + " Command " + "Blocks, Admins)"); } if (ReflectionManager.getVersion() == null) { @@ -185,8 +186,9 @@ public class LibsDisguises extends JavaPlugin { @Override public void run() { getLogger().severe("!! May I have your attention please !!"); - getLogger().severe("Update your ProtocolLib! You are running " + version + " but the minimum version you should be on is " + - requiredProtocolLib + "!"); + getLogger().severe( + "Update your ProtocolLib! You are running " + version + " but the minimum version you should be on is " + requiredProtocolLib + + "!"); getLogger().severe("https://ci.dmulloy2.net/job/ProtocolLib/lastSuccessfulBuild/artifact/target" + "/ProtocolLib" + ".jar"); getLogger().severe("Or! Use /ld protocollib - To update to the latest development build"); @@ -218,9 +220,11 @@ public class LibsDisguises extends JavaPlugin { PacketsManager.init(); DisguiseUtilities.init(); + new SoundManager().load(); + ReflectionManager.registerValues(); - new SoundManager().load(); + ParamInfoManager.getParamInfoSoundGroup().recalculate(); DisguiseConfig.loadConfig(); diff --git a/plugin/src/main/java/me/libraryaddict/disguise/utilities/packets/packetlisteners/PacketListenerSounds.java b/plugin/src/main/java/me/libraryaddict/disguise/utilities/packets/packetlisteners/PacketListenerSounds.java index 9162184d..53a5bb3d 100644 --- a/plugin/src/main/java/me/libraryaddict/disguise/utilities/packets/packetlisteners/PacketListenerSounds.java +++ b/plugin/src/main/java/me/libraryaddict/disguise/utilities/packets/packetlisteners/PacketListenerSounds.java @@ -110,8 +110,8 @@ public class PacketListenerSounds extends PacketAdapter { // Blocks null and CANCEL, HURT and DEATH are 100% handled by entity status! if (soundType != SoundType.STEP && soundType != SoundType.IDLE) { - event.setCancelled(true); - return; + //event.setCancelled(true); + // return; } if (disguisedEntity == observer && !disguise.isSelfDisguiseSoundsReplaced()) { @@ -141,35 +141,32 @@ public class PacketListenerSounds extends PacketAdapter { if (disguise instanceof MobDisguise && disguisedEntity instanceof LivingEntity && ((MobDisguise) disguise).doesDisguiseAge()) { if (((MobDisguise) disguise).isAdult()) { - pitch = (DisguiseUtilities.random.nextFloat() - DisguiseUtilities.random.nextFloat()) * 0.2F + 1.0F; + pitch = ((DisguiseUtilities.random.nextFloat() - DisguiseUtilities.random.nextFloat()) * 0.2F) + 1.0F; } else { - pitch = (DisguiseUtilities.random.nextFloat() - DisguiseUtilities.random.nextFloat()) * 0.2F + 1.4F; + pitch = ((DisguiseUtilities.random.nextFloat() - DisguiseUtilities.random.nextFloat()) * 0.2F) + 1.4F; } } - if (sound.getClass().getSimpleName().equals("MinecraftKey")) { - PacketContainer newPacket = new PacketContainer(Server.CUSTOM_SOUND_EFFECT); - StructureModifier newModifs = newPacket.getModifier(); + PacketContainer newPacket; - newModifs.write(0, sound); - newModifs.write(1, soundCat); + if (sound.getClass().getSimpleName().equals("MinecraftKey")) { + newPacket = new PacketContainer(Server.CUSTOM_SOUND_EFFECT); + StructureModifier newModifs = newPacket.getModifier(); newModifs.write(2, mods.read(2)); newModifs.write(3, mods.read(3)); newModifs.write(4, mods.read(4)); - newModifs.write(5, volume); - newModifs.write(6, pitch); - - event.setPacket(newPacket); } else { - event.setPacket(event.getPacket().shallowClone()); - mods = event.getPacket().getModifier(); - - mods.write(0, sound); - mods.write(1, soundCat); - mods.write(5, volume); - mods.write(6, pitch); + newPacket = event.getPacket().shallowClone(); + mods = newPacket.getModifier(); } + + mods.write(0, sound); + mods.write(1, soundCat); + mods.write(5, volume); + mods.write(6, pitch); + + event.setPacket(newPacket); } private void handleEntityStatus(PacketEvent event) { @@ -191,10 +188,12 @@ public class PacketListenerSounds extends PacketAdapter { if (disguise instanceof TargetedDisguise) { Set discs = DisguiseUtilities.getDisguises().get(entity.getEntityId()); + for (TargetedDisguise targetedDisguise : discs) { if (targetedDisguise != disguise) { continue; } + if (!targetedDisguise.canSee(observer)) { return; } @@ -203,7 +202,7 @@ public class PacketListenerSounds extends PacketAdapter { SoundType soundType = SoundType.HURT; - if (entity instanceof LivingEntity && ((LivingEntity) entity).getHealth() == 0) { + if (entity instanceof LivingEntity && ((LivingEntity) entity).getHealth() <= 0) { soundType = SoundType.DEATH; } @@ -230,8 +229,9 @@ public class PacketListenerSounds extends PacketAdapter { } SoundGroup disSound = SoundGroup.getGroup(disguise); + SoundGroup expectedGroup = SoundGroup.getGroup(disguise.getType().name()); - if (disSound == null || disSound == entitySoundGroup) { + if (disSound == null || disSound == expectedGroup) { return; } diff --git a/plugin/src/main/java/me/libraryaddict/disguise/utilities/reflection/ClassMappings.java b/plugin/src/main/java/me/libraryaddict/disguise/utilities/reflection/ClassMappings.java index 6ad67aa7..06dd6f1c 100644 --- a/plugin/src/main/java/me/libraryaddict/disguise/utilities/reflection/ClassMappings.java +++ b/plugin/src/main/java/me/libraryaddict/disguise/utilities/reflection/ClassMappings.java @@ -9,8 +9,9 @@ public class ClassMappings { public static String getClass(String packageHint, String className) { String location = classLocations.get(className); - if (location != null) + if (location != null) { return location; + } location = className; String[] arrayOfString; int i; @@ -35,14 +36,21 @@ public class ClassMappings { } private static String[] getPackages() { - String[] s = { - "net.minecraft.core", "net.minecraft.core.particles", "net.minecraft.nbt", "net.minecraft.network.chat", "net.minecraft.network.protocol.game", "net.minecraft.network.syncher", "net.minecraft.resources", "net.minecraft.server.level", "net.minecraft.server", "net.minecraft.server.network", - "net.minecraft.sounds", "net.minecraft.world.damagesource", "net.minecraft.world.effect", "net.minecraft.world.entity.ambient", "net.minecraft.world.entity.animal.axolotl", "net.minecraft.world.entity.animal", "net.minecraft.world.entity.animal.goat", "net.minecraft.world.entity.animal.horse", "net.minecraft.world.entity.boss.enderdragon", "net.minecraft.world.entity.boss.wither", - "net.minecraft.world.entity.decoration", "net.minecraft.world.entity", "net.minecraft.world.entity.item", "net.minecraft.world.entity.monster", "net.minecraft.world.entity.monster.hoglin", "net.minecraft.world.entity.monster.piglin", "net.minecraft.world.entity.npc", "net.minecraft.world.entity.player", "net.minecraft.world.entity.projectile", "net.minecraft.world.entity.vehicle", - "net.minecraft.world.inventory", "net.minecraft.world.item", "net.minecraft.world.level.block", "net.minecraft.world.level.block.state", "net.minecraft.world.level", "net.minecraft.world.phys", "org.bukkit.craftbukkit.$version$.block.data", "org.bukkit.craftbukkit.$version$", "org.bukkit.craftbukkit.$version$.entity", "org.bukkit.craftbukkit.$version$.inventory", - "org.bukkit.craftbukkit.$version$.util" }; - for (int i = 0; i < s.length; i++) + String[] s = {"net.minecraft.server.$version$", "net.minecraft.core", "net.minecraft.core.particles", "net.minecraft.nbt", "net.minecraft.network.chat", + "net.minecraft.network.protocol.game", "net.minecraft.network.syncher", "net.minecraft.resources", "net.minecraft.server.level", + "net.minecraft.server", "net.minecraft.server.network", "net.minecraft.sounds", "net.minecraft.world.damagesource", + "net.minecraft.world.effect", "net.minecraft.world.entity.ambient", "net.minecraft.world.entity.animal.axolotl", + "net.minecraft.world.entity.animal", "net.minecraft.world.entity.animal.goat", "net.minecraft.world.entity.animal.horse", + "net.minecraft.world.entity.boss.enderdragon", "net.minecraft.world.entity.boss.wither", "net.minecraft.world.entity.decoration", + "net.minecraft.world.entity", "net.minecraft.world.entity.item", "net.minecraft.world.entity.monster", + "net.minecraft.world.entity.monster.hoglin", "net.minecraft.world.entity.monster.piglin", "net.minecraft.world.entity.npc", + "net.minecraft.world.entity.player", "net.minecraft.world.entity.projectile", "net.minecraft.world.entity.vehicle", + "net.minecraft.world.inventory", "net.minecraft.world.item", "net.minecraft.world.level.block", "net.minecraft.world.level.block.state", + "net.minecraft.world.level", "net.minecraft.world.phys", "org.bukkit.craftbukkit.$version$.block.data", "org.bukkit.craftbukkit.$version$", + "org.bukkit.craftbukkit.$version$.entity", "org.bukkit.craftbukkit.$version$.inventory", "org.bukkit.craftbukkit.$version$.util"}; + for (int i = 0; i < s.length; i++) { s[i] = s[i].replace("$version$", ReflectionManager.getBukkitVersion()); + } return s; } } \ No newline at end of file diff --git a/plugin/src/main/java/me/libraryaddict/disguise/utilities/reflection/ReflectionManager.java b/plugin/src/main/java/me/libraryaddict/disguise/utilities/reflection/ReflectionManager.java index 0df8e0df..19cc18c7 100644 --- a/plugin/src/main/java/me/libraryaddict/disguise/utilities/reflection/ReflectionManager.java +++ b/plugin/src/main/java/me/libraryaddict/disguise/utilities/reflection/ReflectionManager.java @@ -699,6 +699,7 @@ public class ReflectionManager { Object o = aClass.getConstructor().newInstance(); return (ReflectionManagerAbstract) o; + } catch (ClassNotFoundException ignored) { } catch (ReflectiveOperationException e) { e.printStackTrace(); } @@ -1088,6 +1089,7 @@ public class ReflectionManager { return (Float) damageAndIdleSoundMethod.invoke(entity); } catch (Exception ignored) { } + return null; } diff --git a/plugin/src/main/java/me/libraryaddict/disguise/utilities/sounds/SoundManager.java b/plugin/src/main/java/me/libraryaddict/disguise/utilities/sounds/SoundManager.java index ec49c200..57cef9d5 100644 --- a/plugin/src/main/java/me/libraryaddict/disguise/utilities/sounds/SoundManager.java +++ b/plugin/src/main/java/me/libraryaddict/disguise/utilities/sounds/SoundManager.java @@ -24,8 +24,6 @@ public class SoundManager { loadSounds(); loadCustomSounds(); - - ParamInfoManager.getParamInfoSoundGroup().recalculate(); } private void loadCustomSounds() { diff --git a/v1_17_R1/src/main/java/me/libraryaddict/disguise/utilities/reflection/v1_17/ReflectionManager.java b/v1_17_R1/src/main/java/me/libraryaddict/disguise/utilities/reflection/v1_17/ReflectionManager.java index 9d7b938e..f2af28c1 100644 --- a/v1_17_R1/src/main/java/me/libraryaddict/disguise/utilities/reflection/v1_17/ReflectionManager.java +++ b/v1_17_R1/src/main/java/me/libraryaddict/disguise/utilities/reflection/v1_17/ReflectionManager.java @@ -25,6 +25,7 @@ import net.minecraft.world.damagesource.DamageSource; import net.minecraft.world.effect.MobEffect; import net.minecraft.world.effect.MobEffectInstance; import net.minecraft.world.entity.EntityDimensions; +import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.npc.VillagerData; import net.minecraft.world.entity.npc.VillagerProfession; import net.minecraft.world.entity.npc.VillagerType; @@ -35,7 +36,6 @@ import net.minecraft.world.phys.AABB; import net.minecraft.world.phys.Vec3; import org.bukkit.*; import org.bukkit.block.data.BlockData; -import org.bukkit.craftbukkit.libs.it.unimi.dsi.fastutil.ints.Int2ObjectFunction; import org.bukkit.craftbukkit.v1_17_R1.CraftArt; import org.bukkit.craftbukkit.v1_17_R1.CraftServer; import org.bukkit.craftbukkit.v1_17_R1.CraftSound; @@ -58,6 +58,7 @@ import org.bukkit.util.EulerAngle; import org.bukkit.util.Vector; import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.*; import java.util.concurrent.atomic.AtomicInteger; @@ -242,8 +243,17 @@ public class ReflectionManager implements ReflectionManagerAbstract { if (!(entity instanceof net.minecraft.world.entity.LivingEntity)) { return 0.0f; } else { - return ((net.minecraft.world.entity.LivingEntity) entity).getVoicePitch(); + try { + Method method = LivingEntity.class.getDeclaredMethod("getSoundVolume"); + method.setAccessible(true); + + return (Float) method.invoke(entity); + } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) { + e.printStackTrace(); + } } + + return 0f; } public void injectCallback(String playername, ProfileLookupCallback callback) { diff --git a/v1_18_R1/src/main/java/me/libraryaddict/disguise/utilities/reflection/v1_18/ReflectionManager.java b/v1_18_R1/src/main/java/me/libraryaddict/disguise/utilities/reflection/v1_18/ReflectionManager.java index a1b2a794..e94a1813 100644 --- a/v1_18_R1/src/main/java/me/libraryaddict/disguise/utilities/reflection/v1_18/ReflectionManager.java +++ b/v1_18_R1/src/main/java/me/libraryaddict/disguise/utilities/reflection/v1_18/ReflectionManager.java @@ -2,7 +2,6 @@ package me.libraryaddict.disguise.utilities.reflection.v1_18; import com.comphenix.protocol.wrappers.*; import com.comphenix.protocol.wrappers.EnumWrappers.Direction; -import com.comphenix.protocol.wrappers.nbt.NbtWrapper; import com.mojang.authlib.Agent; import com.mojang.authlib.GameProfile; import com.mojang.authlib.ProfileLookupCallback; @@ -30,8 +29,6 @@ import net.minecraft.world.entity.EntityDimensions; import net.minecraft.world.entity.npc.VillagerData; import net.minecraft.world.entity.npc.VillagerProfession; import net.minecraft.world.entity.npc.VillagerType; -import net.minecraft.world.entity.projectile.FishingHook; -import net.minecraft.world.entity.projectile.ThrownEnderpearl; import net.minecraft.world.level.GameType; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.state.BlockState; @@ -49,7 +46,10 @@ import org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer; import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftItemStack; import org.bukkit.craftbukkit.v1_18_R1.util.CraftMagicNumbers; import org.bukkit.craftbukkit.v1_18_R1.util.CraftNamespacedKey; -import org.bukkit.entity.*; +import org.bukkit.entity.Entity; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.Player; +import org.bukkit.entity.Villager; import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; @@ -58,6 +58,7 @@ import org.bukkit.util.EulerAngle; import org.bukkit.util.Vector; import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.*; import java.util.concurrent.atomic.AtomicInteger; @@ -214,7 +215,8 @@ public class ReflectionManager implements ReflectionManagerAbstract { } public ClientboundPlayerInfoPacket.PlayerUpdate getPlayerInfoData(WrappedGameProfile gameProfile) { - return new ClientboundPlayerInfoPacket.PlayerUpdate((GameProfile) gameProfile.getHandle(), 0, GameType.SURVIVAL, new TextComponent(gameProfile.getName())); + return new ClientboundPlayerInfoPacket.PlayerUpdate((GameProfile) gameProfile.getHandle(), 0, GameType.SURVIVAL, + new TextComponent(gameProfile.getName())); } public Object getNmsEntity(Entity entity) { @@ -241,8 +243,17 @@ public class ReflectionManager implements ReflectionManagerAbstract { if (!(entity instanceof net.minecraft.world.entity.LivingEntity)) { return 0.0f; } else { - return ((net.minecraft.world.entity.LivingEntity) entity).getVoicePitch(); + try { + Method method = net.minecraft.world.entity.LivingEntity.class.getDeclaredMethod("getSoundVolume"); + method.setAccessible(true); + + return (Float) method.invoke(entity); + } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) { + e.printStackTrace(); + } } + + return 0f; } public void injectCallback(String playername, ProfileLookupCallback callback) { @@ -252,9 +263,8 @@ public class ReflectionManager implements ReflectionManagerAbstract { public void setBoundingBox(Entity entity, double x, double y, double z) { Location loc = entity.getLocation(); - ((CraftEntity) entity).getHandle().setBoundingBox(new AABB( - loc.getX() - x / 2, loc.getY() - y / 2, loc.getZ() - z / 2, - loc.getX() + x / 2, loc.getY() + y / 2, loc.getZ() + z / 2)); + ((CraftEntity) entity).getHandle().setBoundingBox( + new AABB(loc.getX() - x / 2, loc.getY() - y / 2, loc.getZ() - z / 2, loc.getX() + x / 2, loc.getY() + y / 2, loc.getZ() + z / 2)); } public Enum getSoundCategory(String category) { @@ -370,11 +380,13 @@ public class ReflectionManager implements ReflectionManagerAbstract { } public net.minecraft.world.entity.EntityType getEntityType(EntityType entityType) { - return net.minecraft.world.entity.EntityType.byString(entityType.getName() == null ? entityType.name().toLowerCase(Locale.ENGLISH) : entityType.getName()).orElse(null); + return net.minecraft.world.entity.EntityType.byString( + entityType.getName() == null ? entityType.name().toLowerCase(Locale.ENGLISH) : entityType.getName()).orElse(null); } public Object registerEntityType(NamespacedKey key) { - net.minecraft.world.entity.EntityType newEntity = new net.minecraft.world.entity.EntityType<>(null, null, false, false, false, false, null, null, 0, 0); + net.minecraft.world.entity.EntityType newEntity = + new net.minecraft.world.entity.EntityType<>(null, null, false, false, false, false, null, null, 0, 0); Registry.register(Registry.ENTITY_TYPE, CraftNamespacedKey.toMinecraft(key), newEntity); newEntity.getDescriptionId(); return newEntity; // TODO ??? Some reflection in legacy that I'm unsure about