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?
# Best used when viewing yourself in 3rd person
ViewDisguises: false 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,6 +278,7 @@ 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 (hearSelfDisguise || entity != event.getPlayer()) {
if (disguise != null) { if (disguise != null) {
DisguiseSound disSound = DisguiseSound.getType(entity.getType().name()); DisguiseSound disSound = DisguiseSound.getType(entity.getType().name());
if (disSound == null) if (disSound == null)
@ -277,7 +289,8 @@ public class DisguiseAPI {
} else { } else {
soundType = SoundType.HURT; 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()); disSound = DisguiseSound.getType(disguise.getType().name());
if (disSound != null) { if (disSound != null) {
String sound = disSound.getSound(soundType); String sound = disSound.getSound(soundType);
@ -315,6 +328,7 @@ public class DisguiseAPI {
} }
} }
} }
}
}; };
viewDisguisesListener = new PacketAdapter(libsDisguises, ConnectionSide.SERVER_SIDE, ListenerPriority.HIGHEST, viewDisguisesListener = new PacketAdapter(libsDisguises, ConnectionSide.SERVER_SIDE, ListenerPriority.HIGHEST,
Packets.Server.NAMED_ENTITY_SPAWN, Packets.Server.ATTACH_ENTITY, Packets.Server.REL_ENTITY_MOVE, Packets.Server.NAMED_ENTITY_SPAWN, Packets.Server.ATTACH_ENTITY, Packets.Server.REL_ENTITY_MOVE,
@ -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());