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 # Whats the max size allowed for command undisguiseradius
UndisguiseRadiusMax: 50 UndisguiseRadiusMax: 50
# Shall the players view their disguises? # 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 boolean soundsEnabled;
private static HashMap<Integer, Integer> selfDisguisesIds = new HashMap<Integer, Integer>(); private static HashMap<Integer, Integer> selfDisguisesIds = new HashMap<Integer, Integer>();
private static boolean viewDisguises; private static boolean viewDisguises;
private static boolean hearSelfDisguise;
private static PacketListener viewDisguisesListener; private static PacketListener viewDisguisesListener;
private synchronized static Disguise access(Entity entity, Disguise... args) { 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) { private static Disguise get(Entity obj) {
return access(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); Disguise disguise = DisguiseAPI.getDisguise(disguisedEntity);
if (disguise.replaceSounds()) { if (disguise.replaceSounds()) {
String sound = null; String sound = null;
@ -267,46 +278,49 @@ public class DisguiseAPI {
// It made a damage animation // It made a damage animation
Entity entity = event.getPacket().getEntityModifier(observer.getWorld()).read(0); Entity entity = event.getPacket().getEntityModifier(observer.getWorld()).read(0);
Disguise disguise = getDisguise(entity); Disguise disguise = getDisguise(entity);
if (disguise != null) { if (hearSelfDisguise || entity != event.getPlayer()) {
DisguiseSound disSound = DisguiseSound.getType(entity.getType().name()); if (disguise != null) {
if (disSound == null) DisguiseSound disSound = DisguiseSound.getType(entity.getType().name());
return; if (disSound == null)
SoundType soundType = null; return;
if (entity instanceof LivingEntity && ((LivingEntity) entity).getHealth() == 0) { SoundType soundType = null;
soundType = SoundType.DEATH; if (entity instanceof LivingEntity && ((LivingEntity) entity).getHealth() == 0) {
} else { soundType = SoundType.DEATH;
soundType = SoundType.HURT; } else {
} soundType = SoundType.HURT;
if (disSound.getSound(soundType) == null) { }
disSound = DisguiseSound.getType(disguise.getType().name()); if (disSound.getSound(soundType) == null
if (disSound != null) { || (hearSelfDisguise && entity == event.getPlayer() && (soundType == SoundType.HURT || soundType == SoundType.DEATH))) {
String sound = disSound.getSound(soundType); disSound = DisguiseSound.getType(disguise.getType().name());
if (sound != null) { if (disSound != null) {
Location loc = entity.getLocation(); String sound = disSound.getSound(soundType);
PacketContainer packet = new PacketContainer(Packets.Server.NAMED_SOUND_EFFECT); if (sound != null) {
mods = packet.getModifier(); Location loc = entity.getLocation();
mods.write(0, sound); PacketContainer packet = new PacketContainer(Packets.Server.NAMED_SOUND_EFFECT);
mods.write(1, (int) (loc.getX() * 8D)); mods = packet.getModifier();
mods.write(2, (int) (loc.getY() * 8D)); mods.write(0, sound);
mods.write(3, (int) (loc.getZ() * 8D)); mods.write(1, (int) (loc.getX() * 8D));
mods.write(4, disSound.getDamageSoundVolume()); mods.write(2, (int) (loc.getY() * 8D));
float pitch; mods.write(3, (int) (loc.getZ() * 8D));
if (disguise instanceof MobDisguise && !((MobDisguise) disguise).isAdult()) { mods.write(4, disSound.getDamageSoundVolume());
pitch = (new Random().nextFloat() - new Random().nextFloat()) * 0.2F + 1.5F; float pitch;
} else if (disguise instanceof MobDisguise && !((MobDisguise) disguise).isAdult()) {
pitch = (new Random().nextFloat() - new Random().nextFloat()) * 0.2F + 1.0F; pitch = (new Random().nextFloat() - new Random().nextFloat()) * 0.2F + 1.5F;
if (disguise.getType() == DisguiseType.BAT) } else
pitch *= 95F; pitch = (new Random().nextFloat() - new Random().nextFloat()) * 0.2F + 1.0F;
pitch *= 63; if (disguise.getType() == DisguiseType.BAT)
if (pitch < 0) pitch *= 95F;
pitch = 0; pitch *= 63;
if (pitch > 255) if (pitch < 0)
pitch = 255; pitch = 0;
mods.write(5, (int) pitch); if (pitch > 255)
try { pitch = 255;
ProtocolLibrary.getProtocolManager().sendServerPacket(observer, packet); mods.write(5, (int) pitch);
} catch (InvocationTargetException e) { try {
e.printStackTrace(); ProtocolLibrary.getProtocolManager().sendServerPacket(observer, packet);
} catch (InvocationTargetException e) {
e.printStackTrace();
}
} }
} }
} }
@ -382,6 +396,10 @@ public class DisguiseAPI {
} }
event.setCancelled(true); event.setCancelled(true);
break; break;
case Packets.Server.ENTITY_STATUS:
if (hearSelfDisguise && (Byte) event.getPacket().getModifier().read(1) == 2)
event.setCancelled(true);
break;
default: default:
break; break;
} }

View File

@ -442,10 +442,22 @@ public class LibsDisguises extends JavaPlugin {
getPluginLoader().disablePlugin(this); getPluginLoader().disablePlugin(this);
return; 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.init(this);
DisguiseAPI.enableSounds(true); DisguiseAPI.enableSounds(getConfig().getBoolean("DisguiseSounds"));
DisguiseAPI.setVelocitySent(true); DisguiseAPI.setVelocitySent(getConfig().getBoolean("SendVelocity"));
DisguiseAPI.setViewDisguises(getConfig().getBoolean("ViewDisguises")); DisguiseAPI.setViewDisguises(getConfig().getBoolean("ViewDisguises"));
DisguiseAPI.setHearSelfDisguise(getConfig().getBoolean("HearSelfDisguise"));
try { try {
// Here I use reflection to set the plugin for Disguise.. // Here I use reflection to set the plugin for Disguise..
// Kinda stupid but I don't want open API calls. // Kinda stupid but I don't want open API calls.
@ -456,11 +468,6 @@ public class LibsDisguises extends JavaPlugin {
ex.printStackTrace(); ex.printStackTrace();
} }
addPacketListeners(); 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); DisguiseListener listener = new DisguiseListener(this);
Bukkit.getPluginManager().registerEvents(listener, this); Bukkit.getPluginManager().registerEvents(listener, this);
getCommand("disguise").setExecutor(new DisguiseCommand()); getCommand("disguise").setExecutor(new DisguiseCommand());