use of me.libraryaddict.disguise.utilities.sounds.SoundGroup in project LibsDisguises by libraryaddict.
the class ReflectionManager method createNMSValues.
private static void createNMSValues(DisguiseType disguiseType) {
String nmsEntityName = toReadable(disguiseType.name());
Class nmsClass = ReflectionManager.getNmsClassIgnoreErrors("Entity" + nmsEntityName);
if (nmsClass == null || Modifier.isAbstract(nmsClass.getModifiers())) {
String[] split = splitReadable(disguiseType.name());
ArrayUtils.reverse(split);
nmsEntityName = StringUtils.join(split);
nmsClass = ReflectionManager.getNmsClassIgnoreErrors("Entity" + nmsEntityName);
if (nmsClass == null || Modifier.isAbstract(nmsClass.getModifiers())) {
nmsEntityName = null;
}
}
if (nmsEntityName == null) {
switch(disguiseType) {
case AXOLOTL:
nmsEntityName = "Axolotl";
break;
case GOAT:
nmsEntityName = "Goat";
break;
case GLOW_ITEM_FRAME:
nmsEntityName = "GlowItemFrame";
break;
case GLOW_SQUID:
nmsEntityName = "GlowSquid";
break;
case MARKER:
nmsEntityName = "Marker";
break;
case DONKEY:
nmsEntityName = "HorseDonkey";
break;
case ARROW:
nmsEntityName = "TippedArrow";
break;
case DROPPED_ITEM:
nmsEntityName = "Item";
break;
case FIREBALL:
nmsEntityName = "LargeFireball";
break;
case FIREWORK:
nmsEntityName = "Fireworks";
break;
case GIANT:
nmsEntityName = "GiantZombie";
break;
case HUSK:
nmsEntityName = "ZombieHusk";
break;
case ILLUSIONER:
nmsEntityName = "IllagerIllusioner";
break;
case LEASH_HITCH:
nmsEntityName = "Leash";
break;
case MINECART:
nmsEntityName = "MinecartRideable";
break;
case MINECART_COMMAND:
nmsEntityName = "MinecartCommandBlock";
break;
case MINECART_TNT:
nmsEntityName = "MinecartTNT";
break;
case MULE:
nmsEntityName = "HorseMule";
break;
case PRIMED_TNT:
nmsEntityName = "TNTPrimed";
break;
case PUFFERFISH:
nmsEntityName = "PufferFish";
break;
case SPLASH_POTION:
nmsEntityName = "Potion";
break;
case STRAY:
nmsEntityName = "SkeletonStray";
break;
case TRIDENT:
nmsEntityName = "ThrownTrident";
break;
case WANDERING_TRADER:
nmsEntityName = "VillagerTrader";
break;
case TRADER_LLAMA:
// Interesting capitalization
nmsEntityName = "LLamaTrader";
break;
case ZOMBIFIED_PIGLIN:
nmsEntityName = "PigZombie";
break;
default:
break;
}
}
try {
if (disguiseType == DisguiseType.UNKNOWN || disguiseType.isCustom()) {
DisguiseValues disguiseValues = new DisguiseValues(disguiseType, 0);
disguiseValues.setAdultBox(new FakeBoundingBox(0, 0, 0));
SoundGroup sound = SoundGroup.getGroup(disguiseType.name());
if (sound != null) {
sound.setDamageAndIdleSoundVolume(1f);
}
return;
}
if (nmsEntityName == null) {
DisguiseUtilities.getLogger().warning("Entity name not found! (" + disguiseType.name() + ")");
return;
}
Object nmsEntity = ReflectionManager.createEntityInstance(disguiseType, nmsReflection != null ? disguiseType.getEntityType().getKey().getKey() : nmsEntityName);
if (nmsEntity == null) {
DisguiseUtilities.getLogger().warning("Entity not found! (" + nmsEntityName + ")");
return;
}
disguiseType.setTypeId(ReflectionManager.getEntityTypeId(disguiseType.getEntityType()));
Entity bukkitEntity = ReflectionManager.getBukkitEntity(nmsEntity);
DisguiseValues disguiseValues = new DisguiseValues(disguiseType, bukkitEntity instanceof Damageable ? ((Damageable) bukkitEntity).getMaxHealth() : 0);
WrappedDataWatcher watcher = WrappedDataWatcher.getEntityWatcher(bukkitEntity);
ArrayList<MetaIndex> indexes = MetaIndex.getMetaIndexes(disguiseType.getWatcherClass());
boolean loggedName = false;
for (WrappedWatchableObject watch : watcher.getWatchableObjects()) {
MetaIndex flagType = MetaIndex.getMetaIndex(disguiseType.getWatcherClass(), watch.getIndex());
if (flagType == null) {
DisguiseUtilities.getLogger().severe("MetaIndex not found for " + disguiseType + "! Index: " + watch.getIndex());
DisguiseUtilities.getLogger().severe("Value: " + watch.getRawValue() + " (" + watch.getRawValue().getClass() + ") (" + nmsEntity.getClass() + ") & " + disguiseType.getWatcherClass().getSimpleName());
continue;
}
indexes.remove(flagType);
Object ourValue = ReflectionManager.convertInvalidMeta(flagType.getDefault());
Object nmsValue = ReflectionManager.convertInvalidMeta(watch.getRawValue());
if (ourValue.getClass() != nmsValue.getClass()) {
if (!loggedName) {
DisguiseUtilities.getLogger().severe(StringUtils.repeat("=", 20));
DisguiseUtilities.getLogger().severe("MetaIndex mismatch! Disguise " + disguiseType + ", Entity " + nmsEntityName);
loggedName = true;
}
DisguiseUtilities.getLogger().severe(StringUtils.repeat("-", 20));
DisguiseUtilities.getLogger().severe("Index: " + watch.getIndex() + " | " + flagType.getFlagWatcher().getSimpleName() + " | " + MetaIndex.getName(flagType));
Object flagDefault = flagType.getDefault();
DisguiseUtilities.getLogger().severe("LibsDisguises: " + flagDefault + " (" + flagDefault.getClass() + ")");
DisguiseUtilities.getLogger().severe("LibsDisguises Converted: " + ourValue + " (" + ourValue.getClass() + ")");
DisguiseUtilities.getLogger().severe("Minecraft: " + watch.getRawValue() + " (" + watch.getRawValue().getClass() + ")");
DisguiseUtilities.getLogger().severe("Minecraft Converted: " + nmsValue + " (" + nmsValue.getClass() + ")");
DisguiseUtilities.getLogger().severe(StringUtils.repeat("-", 20));
}
}
for (MetaIndex index : indexes) {
DisguiseUtilities.getLogger().severe(disguiseType + " has MetaIndex remaining! " + index.getFlagWatcher().getSimpleName() + " at index " + index.getIndex());
}
SoundGroup sound = SoundGroup.getGroup(disguiseType.name());
if (sound != null) {
Float soundStrength = ReflectionManager.getSoundModifier(nmsEntity);
if (soundStrength != null) {
sound.setDamageAndIdleSoundVolume(soundStrength);
}
}
// Get the bounding box
disguiseValues.setAdultBox(ReflectionManager.getBoundingBox(bukkitEntity));
if (bukkitEntity instanceof Ageable) {
((Ageable) bukkitEntity).setBaby();
disguiseValues.setBabyBox(ReflectionManager.getBoundingBox(bukkitEntity));
} else if (bukkitEntity instanceof Zombie) {
((Zombie) bukkitEntity).setBaby(true);
disguiseValues.setBabyBox(ReflectionManager.getBoundingBox(bukkitEntity));
} else if (bukkitEntity instanceof ArmorStand) {
((ArmorStand) bukkitEntity).setSmall(true);
disguiseValues.setBabyBox(ReflectionManager.getBoundingBox(bukkitEntity));
}
} catch (SecurityException | IllegalArgumentException | FieldAccessException ex) {
DisguiseUtilities.getLogger().severe("Uh oh! Trouble while making values for the disguise " + disguiseType.name() + "!");
DisguiseUtilities.getLogger().severe("Before reporting this error, " + "please make sure you are using the latest version of LibsDisguises and ProtocolLib.");
DisguiseUtilities.getLogger().severe("Development builds are available at (ProtocolLib) " + "http://ci.dmulloy2.net/job/ProtocolLib/ and (LibsDisguises) https://ci.md-5" + ".net/job/LibsDisguises/");
ex.printStackTrace();
}
}
use of me.libraryaddict.disguise.utilities.sounds.SoundGroup in project LibsDisguises by libraryaddict.
the class PacketListenerSounds method handleNamedSoundEffect.
private void handleNamedSoundEffect(PacketEvent event) {
StructureModifier<Object> mods = event.getPacket().getModifier();
Player observer = event.getPlayer();
SoundType soundType = null;
Entity disguisedEntity = null;
SoundGroup soundGroup = null;
Object soundEffectObj = mods.read(0);
Disguise disguise = null;
int[] soundCords = new int[] { (Integer) mods.read(2), (Integer) mods.read(3), (Integer) mods.read(4) };
for (Set<TargetedDisguise> disguises : DisguiseUtilities.getDisguises().values()) {
for (TargetedDisguise entityDisguise : disguises) {
Entity entity = entityDisguise.getEntity();
if (entity == null || entity.getWorld() != observer.getWorld()) {
continue;
}
if (!entityDisguise.canSee(observer)) {
continue;
}
Location loc = entity.getLocation();
int[] entCords = new int[] { (int) (loc.getX() * 8), (int) (loc.getY() * 8), (int) (loc.getZ() * 8) };
if (soundCords[0] != entCords[0] || soundCords[1] != entCords[1] || soundCords[2] != entCords[2]) {
continue;
}
disguise = entityDisguise;
disguisedEntity = entity;
soundGroup = SoundGroup.getGroup(entity.getType().name());
if (soundGroup == null || soundGroup.getSound(soundEffectObj) == null) {
return;
}
if ((!(entity instanceof LivingEntity)) || ((LivingEntity) entity).getHealth() > 0) {
soundType = soundGroup.getType(soundEffectObj);
} else {
soundType = SoundType.DEATH;
}
}
if (disguise != null) {
break;
}
}
if (disguise == null || !disguise.isSoundsReplaced()) {
return;
}
if (disguisedEntity == observer && !disguise.isSelfDisguiseSoundsReplaced()) {
return;
}
SoundGroup disguiseSound = SoundGroup.getGroup(disguise);
if (disguiseSound == null) {
event.setCancelled(true);
return;
}
Object sound = disguiseSound.getSound(soundType);
if (sound == null) {
event.setCancelled(true);
return;
}
Enum soundCat = ReflectionManager.getSoundCategory(disguise.getType());
float volume = (float) mods.read(5);
float pitch = (float) mods.read(6);
// If the volume is the default, set it to what the real disguise sound group expects
if (volume == soundGroup.getDamageAndIdleSoundVolume()) {
volume = disguiseSound.getDamageAndIdleSoundVolume();
}
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;
} else {
pitch = ((DisguiseUtilities.random.nextFloat() - DisguiseUtilities.random.nextFloat()) * 0.2F) + 1.4F;
}
}
PacketContainer newPacket;
if (sound.getClass().getSimpleName().equals("MinecraftKey")) {
newPacket = new PacketContainer(Server.CUSTOM_SOUND_EFFECT);
StructureModifier<Object> newModifs = newPacket.getModifier();
newModifs.write(2, mods.read(2));
newModifs.write(3, mods.read(3));
newModifs.write(4, mods.read(4));
mods = newModifs;
} else {
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);
}
Aggregations