From f15966a0f27876939e1a01d3ddace834c9b4c0cc Mon Sep 17 00:00:00 2001 From: Andrew Date: Wed, 31 Jul 2013 17:46:24 +1200 Subject: [PATCH] More config options. Added hearing yourself disguised option --- config.yml | 12 ++- .../libraryaddict/disguise/DisguiseAPI.java | 100 +++++++++++------- .../libraryaddict/disguise/LibsDisguises.java | 21 ++-- 3 files changed, 84 insertions(+), 49 deletions(-) diff --git a/config.yml b/config.yml index 43539f97..8ac2946d 100644 --- a/config.yml +++ b/config.yml @@ -7,4 +7,14 @@ DisguiseRadiusMax: 50 # Whats the max size allowed for command undisguiseradius UndisguiseRadiusMax: 50 # Shall the players view their disguises? -ViewDisguises: false \ No newline at end of file +# Best used when viewing yourself in 3rd person +ViewDisguises: false +# Shall I disguise the sounds? +# This turns your damage sound into a MOOOO +DisguiseSounds: true +# Shall the disguised hear their disguise sounds or their damage sounds. +# I disable this as it can be a little confusing when not used with self disguises +HearSelfDisguise: false +# Shall I send the velocity packets? I REALLY recommend you don't disable. +# This is the only thing allowing the mobs to fly without glitching out. +SendVelocity: true \ No newline at end of file diff --git a/src/me/libraryaddict/disguise/DisguiseAPI.java b/src/me/libraryaddict/disguise/DisguiseAPI.java index 4c2ad8cb..2fd55a7a 100644 --- a/src/me/libraryaddict/disguise/DisguiseAPI.java +++ b/src/me/libraryaddict/disguise/DisguiseAPI.java @@ -68,6 +68,7 @@ public class DisguiseAPI { private static boolean soundsEnabled; private static HashMap selfDisguisesIds = new HashMap(); private static boolean viewDisguises; + private static boolean hearSelfDisguise; private static PacketListener viewDisguisesListener; private synchronized static Disguise access(Entity entity, Disguise... args) { @@ -129,6 +130,16 @@ public class DisguiseAPI { } } + public static void setHearSelfDisguise(boolean replaceSound) { + if (hearSelfDisguise != replaceSound) { + hearSelfDisguise = replaceSound; + } + } + + public static boolean canHearSelfDisguise() { + return hearSelfDisguise; + } + private static Disguise get(Entity obj) { return access(obj); } @@ -197,7 +208,7 @@ public class DisguiseAPI { } } } - if (disguisedEntity != null) { + if (disguisedEntity != null && (hearSelfDisguise || disguisedEntity != event.getPlayer())) { Disguise disguise = DisguiseAPI.getDisguise(disguisedEntity); if (disguise.replaceSounds()) { String sound = null; @@ -267,46 +278,49 @@ public class DisguiseAPI { // It made a damage animation Entity entity = event.getPacket().getEntityModifier(observer.getWorld()).read(0); Disguise disguise = getDisguise(entity); - if (disguise != null) { - DisguiseSound disSound = DisguiseSound.getType(entity.getType().name()); - if (disSound == null) - return; - SoundType soundType = null; - if (entity instanceof LivingEntity && ((LivingEntity) entity).getHealth() == 0) { - soundType = SoundType.DEATH; - } else { - soundType = SoundType.HURT; - } - if (disSound.getSound(soundType) == null) { - disSound = DisguiseSound.getType(disguise.getType().name()); - if (disSound != null) { - String sound = disSound.getSound(soundType); - if (sound != null) { - Location loc = entity.getLocation(); - PacketContainer packet = new PacketContainer(Packets.Server.NAMED_SOUND_EFFECT); - mods = packet.getModifier(); - mods.write(0, sound); - mods.write(1, (int) (loc.getX() * 8D)); - mods.write(2, (int) (loc.getY() * 8D)); - mods.write(3, (int) (loc.getZ() * 8D)); - mods.write(4, disSound.getDamageSoundVolume()); - float pitch; - if (disguise instanceof MobDisguise && !((MobDisguise) disguise).isAdult()) { - pitch = (new Random().nextFloat() - new Random().nextFloat()) * 0.2F + 1.5F; - } else - pitch = (new Random().nextFloat() - new Random().nextFloat()) * 0.2F + 1.0F; - if (disguise.getType() == DisguiseType.BAT) - pitch *= 95F; - pitch *= 63; - if (pitch < 0) - pitch = 0; - if (pitch > 255) - pitch = 255; - mods.write(5, (int) pitch); - try { - ProtocolLibrary.getProtocolManager().sendServerPacket(observer, packet); - } catch (InvocationTargetException e) { - e.printStackTrace(); + if (hearSelfDisguise || entity != event.getPlayer()) { + if (disguise != null) { + DisguiseSound disSound = DisguiseSound.getType(entity.getType().name()); + if (disSound == null) + return; + SoundType soundType = null; + if (entity instanceof LivingEntity && ((LivingEntity) entity).getHealth() == 0) { + soundType = SoundType.DEATH; + } else { + soundType = SoundType.HURT; + } + if (disSound.getSound(soundType) == null + || (hearSelfDisguise && entity == event.getPlayer() && (soundType == SoundType.HURT || soundType == SoundType.DEATH))) { + disSound = DisguiseSound.getType(disguise.getType().name()); + if (disSound != null) { + String sound = disSound.getSound(soundType); + if (sound != null) { + Location loc = entity.getLocation(); + PacketContainer packet = new PacketContainer(Packets.Server.NAMED_SOUND_EFFECT); + mods = packet.getModifier(); + mods.write(0, sound); + mods.write(1, (int) (loc.getX() * 8D)); + mods.write(2, (int) (loc.getY() * 8D)); + mods.write(3, (int) (loc.getZ() * 8D)); + mods.write(4, disSound.getDamageSoundVolume()); + float pitch; + if (disguise instanceof MobDisguise && !((MobDisguise) disguise).isAdult()) { + pitch = (new Random().nextFloat() - new Random().nextFloat()) * 0.2F + 1.5F; + } else + pitch = (new Random().nextFloat() - new Random().nextFloat()) * 0.2F + 1.0F; + if (disguise.getType() == DisguiseType.BAT) + pitch *= 95F; + pitch *= 63; + if (pitch < 0) + pitch = 0; + if (pitch > 255) + pitch = 255; + mods.write(5, (int) pitch); + try { + ProtocolLibrary.getProtocolManager().sendServerPacket(observer, packet); + } catch (InvocationTargetException e) { + e.printStackTrace(); + } } } } @@ -382,6 +396,10 @@ public class DisguiseAPI { } event.setCancelled(true); break; + case Packets.Server.ENTITY_STATUS: + if (hearSelfDisguise && (Byte) event.getPacket().getModifier().read(1) == 2) + event.setCancelled(true); + break; default: break; } diff --git a/src/me/libraryaddict/disguise/LibsDisguises.java b/src/me/libraryaddict/disguise/LibsDisguises.java index dc667067..e4533889 100644 --- a/src/me/libraryaddict/disguise/LibsDisguises.java +++ b/src/me/libraryaddict/disguise/LibsDisguises.java @@ -442,10 +442,22 @@ public class LibsDisguises extends JavaPlugin { getPluginLoader().disablePlugin(this); return; } + saveDefaultConfig(); + if (!getConfig().contains("DisguiseRadiusMax")) + getConfig().set("DisguiseRadiusMax", getConfig().getInt("DisguiseRadiusMax")); + if (!getConfig().contains("UndisguiseRadiusMax")) + getConfig().set("UndisguiseRadiusMax", getConfig().getInt("UndisguiseRadiusMax")); + if (!getConfig().contains("DisguiseSounds")) + getConfig().set("DisguiseSounds", getConfig().getBoolean("DisguiseSounds")); + if (!getConfig().contains("HearSelfDisguise")) + getConfig().set("HearSelfDisguise", getConfig().getBoolean("HearSelfDisguise")); + if (!getConfig().contains("SendVelocity")) + getConfig().set("SendVelocity", getConfig().getBoolean("SendVelocity")); DisguiseAPI.init(this); - DisguiseAPI.enableSounds(true); - DisguiseAPI.setVelocitySent(true); + DisguiseAPI.enableSounds(getConfig().getBoolean("DisguiseSounds")); + DisguiseAPI.setVelocitySent(getConfig().getBoolean("SendVelocity")); DisguiseAPI.setViewDisguises(getConfig().getBoolean("ViewDisguises")); + DisguiseAPI.setHearSelfDisguise(getConfig().getBoolean("HearSelfDisguise")); try { // Here I use reflection to set the plugin for Disguise.. // Kinda stupid but I don't want open API calls. @@ -456,11 +468,6 @@ public class LibsDisguises extends JavaPlugin { ex.printStackTrace(); } addPacketListeners(); - saveDefaultConfig(); - if (!getConfig().contains("DisguiseRadiusMax")) - getConfig().set("DisguiseRadiusMax", getConfig().getInt("DisguiseRadiusMax")); - if (!getConfig().contains("UndisguiseRadiusMax")) - getConfig().set("UndisguiseRadiusMax", getConfig().getInt("UndisguiseRadiusMax")); DisguiseListener listener = new DisguiseListener(this); Bukkit.getPluginManager().registerEvents(listener, this); getCommand("disguise").setExecutor(new DisguiseCommand());