More config options. Added hearing yourself disguised option

This commit is contained in:
Andrew 2013-07-31 17:46:24 +12:00
parent d12e58899e
commit f15966a0f2
3 changed files with 84 additions and 49 deletions

View file

@ -7,4 +7,14 @@ DisguiseRadiusMax: 50
# Whats the max size allowed for command undisguiseradius
UndisguiseRadiusMax: 50
# Shall the players view their disguises?
ViewDisguises: false
# 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

View file

@ -68,6 +68,7 @@ public class DisguiseAPI {
private static boolean soundsEnabled;
private static HashMap<Integer, Integer> selfDisguisesIds = new HashMap<Integer, Integer>();
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;
}

View file

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