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?
# 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,6 +278,7 @@ public class DisguiseAPI {
// It made a damage animation
Entity entity = event.getPacket().getEntityModifier(observer.getWorld()).read(0);
Disguise disguise = getDisguise(entity);
if (hearSelfDisguise || entity != event.getPlayer()) {
if (disguise != null) {
DisguiseSound disSound = DisguiseSound.getType(entity.getType().name());
if (disSound == null)
@ -277,7 +289,8 @@ public class DisguiseAPI {
} else {
soundType = SoundType.HURT;
}
if (disSound.getSound(soundType) == null) {
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);
@ -315,6 +328,7 @@ public class DisguiseAPI {
}
}
}
}
};
viewDisguisesListener = new PacketAdapter(libsDisguises, ConnectionSide.SERVER_SIDE, ListenerPriority.HIGHEST,
Packets.Server.NAMED_ENTITY_SPAWN, Packets.Server.ATTACH_ENTITY, Packets.Server.REL_ENTITY_MOVE,
@ -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());