Fix up sounds and some other stuff

This commit is contained in:
libraryaddict 2021-12-11 20:57:23 +13:00
parent 42cd210fc7
commit 52cb313f77
7 changed files with 86 additions and 52 deletions

View File

@ -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();

View File

@ -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;
}
}
PacketContainer newPacket;
if (sound.getClass().getSimpleName().equals("MinecraftKey")) {
PacketContainer newPacket = new PacketContainer(Server.CUSTOM_SOUND_EFFECT);
newPacket = new PacketContainer(Server.CUSTOM_SOUND_EFFECT);
StructureModifier<Object> newModifs = newPacket.getModifier();
newModifs.write(0, sound);
newModifs.write(1, soundCat);
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();
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<TargetedDisguise> 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;
}

View File

@ -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;
}
}

View File

@ -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;
}

View File

@ -24,8 +24,6 @@ public class SoundManager {
loadSounds();
loadCustomSounds();
ParamInfoManager.getParamInfoSoundGroup().recalculate();
}
private void loadCustomSounds() {

View File

@ -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,10 +243,19 @@ 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) {
Agent agent = Agent.MINECRAFT;
getMinecraftServer().getProfileRepository().findProfilesByNames(new String[]{playername}, agent, callback);

View File

@ -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,10 +243,19 @@ 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) {
Agent agent = Agent.MINECRAFT;
getMinecraftServer().getProfileRepository().findProfilesByNames(new String[]{playername}, agent, 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<net.minecraft.world.entity.Entity> newEntity = new net.minecraft.world.entity.EntityType<>(null, null, false, false, false, false, null, null, 0, 0);
net.minecraft.world.entity.EntityType<net.minecraft.world.entity.Entity> 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