Removed isExp() and now supports playing sounds. ALso no crashing for entitys
This commit is contained in:
parent
1739c96e38
commit
2ff2acb3a1
@ -12,6 +12,7 @@ import org.bukkit.entity.Player;
|
||||
public class DisguiseAPI {
|
||||
|
||||
private static ConcurrentHashMap<String, Disguise> disguises = new ConcurrentHashMap<String, Disguise>();
|
||||
private static boolean playSounds = true;
|
||||
|
||||
/**
|
||||
* @param Player
|
||||
@ -79,6 +80,20 @@ public class DisguiseAPI {
|
||||
return disguises.containsKey(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Does sounds play when the disguiser is hurt
|
||||
*/
|
||||
public static boolean playSounds() {
|
||||
return playSounds;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Boolean - Set if sounds play when the disguiser is hurt
|
||||
*/
|
||||
public static void setPlaySounds(boolean sounds) {
|
||||
playSounds = sounds;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Disguiser
|
||||
* - Undisguises him
|
||||
|
@ -53,7 +53,7 @@ public class Disguise {
|
||||
spawnPacket = new Packet20NamedEntitySpawn(entityHuman);
|
||||
((Packet20NamedEntitySpawn) spawnPacket).b = ((PlayerDisguise) this).getName();
|
||||
|
||||
} else if (getType().isExp()) {
|
||||
} else if (getType() == DisguiseType.EXPERIENCE_ORB) {
|
||||
|
||||
Entity entity = getEntity(((CraftPlayer) p).getHandle().world, p.getLocation(), p.getEntityId());
|
||||
spawnPacket = new Packet26AddExpOrb((EntityExperienceOrb) entity);
|
||||
|
@ -4,7 +4,7 @@ public enum DisguiseType {
|
||||
ARROW(EntityType.MISC, 60), BAT(EntityType.MOB), BLAZE(EntityType.MOB), BOAT(EntityType.MISC, 1), CAVE_SPIDER(EntityType.MOB), CHICKEN(
|
||||
EntityType.MOB), COW(EntityType.MOB), CREEPER(EntityType.MOB), EGG(EntityType.MISC, 62), ENDER_CRYSTAL(
|
||||
EntityType.MISC, 51), ENDER_DRAGON(EntityType.MOB), ENDER_PEARL(EntityType.MISC, 65), ENDER_SIGNAL(EntityType.MISC,
|
||||
72), ENDERMAN(EntityType.MOB), EXPERIENCE_ORB(EntityType.EXP), FALLING_BLOCK(EntityType.MISC, 70, 1), FIREWORKS(
|
||||
72), ENDERMAN(EntityType.MOB), EXPERIENCE_ORB(EntityType.MISC), FALLING_BLOCK(EntityType.MISC, 70, 1), FIREWORKS(
|
||||
EntityType.MISC, 76), FISHING_HOOK(EntityType.MISC, 90), GHAST(EntityType.MOB), GIANT_ZOMBIE(EntityType.MOB), IRON_GOLEM(
|
||||
EntityType.MOB), ITEM(EntityType.MISC, 2, 1), ITEM_FRAME(EntityType.MISC, 71), LARGE_FIREBALL(EntityType.MISC, 63, 0), MAGMA_CUBE(
|
||||
EntityType.MOB), MINECART_CHEST(EntityType.MISC, 10, 1), MINECART_FURNACE(EntityType.MISC, 10, 2), MINECART_HOPPER(
|
||||
@ -18,7 +18,7 @@ public enum DisguiseType {
|
||||
EntityType.MOB);
|
||||
|
||||
public static enum EntityType {
|
||||
EXP, MISC, MOB, PLAYER;
|
||||
MISC, MOB, PLAYER;
|
||||
}
|
||||
|
||||
public static DisguiseType getType(org.bukkit.entity.EntityType entityType) {
|
||||
@ -64,10 +64,6 @@ public enum DisguiseType {
|
||||
return entityId;
|
||||
}
|
||||
|
||||
public boolean isExp() {
|
||||
return entityType == EntityType.EXP;
|
||||
}
|
||||
|
||||
public boolean isMisc() {
|
||||
return entityType == EntityType.MISC;
|
||||
}
|
||||
|
@ -9,6 +9,10 @@ public class ZombieWatcher extends FlagWatcher {
|
||||
setValue(13, (byte) 0);
|
||||
}
|
||||
|
||||
public boolean isVillager() {
|
||||
return (Byte) getValue(13) == 1;
|
||||
}
|
||||
|
||||
public void setVillager(boolean villager) {
|
||||
if (isVillager() != villager) {
|
||||
setValue(13, (byte) (villager ? 1 : 0));
|
||||
@ -16,8 +20,4 @@ public class ZombieWatcher extends FlagWatcher {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isVillager() {
|
||||
return (Byte) getValue(13) == 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,11 +1,17 @@
|
||||
package me.libraryaddict.disguise;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import me.libraryaddict.disguise.DisguiseTypes.Disguise;
|
||||
import me.libraryaddict.disguise.DisguiseTypes.DisguiseType;
|
||||
import me.libraryaddict.disguise.DisguiseTypes.PlayerDisguise;
|
||||
import net.minecraft.server.v1_5_R3.WatchableObject;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.craftbukkit.v1_5_R3.CraftSound;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
@ -23,31 +29,102 @@ public class LibsDisguises extends JavaPlugin {
|
||||
getCommand("disguise").setExecutor(new DisguiseCommand());
|
||||
ProtocolLibrary.getProtocolManager().addPacketListener(
|
||||
new PacketAdapter(this, ConnectionSide.SERVER_SIDE, ListenerPriority.NORMAL, Packets.Server.NAMED_ENTITY_SPAWN,
|
||||
Packets.Server.ENTITY_METADATA) {
|
||||
Packets.Server.ENTITY_METADATA, Packets.Server.NAMED_SOUND_EFFECT, Packets.Server.ARM_ANIMATION) {
|
||||
@Override
|
||||
public void onPacketSending(PacketEvent event) {
|
||||
StructureModifier<Object> mods = event.getPacket().getModifier();
|
||||
try {
|
||||
Player observer = event.getPlayer();
|
||||
org.bukkit.entity.Entity entity = event.getPacket().getEntityModifier(observer.getWorld()).read(0);
|
||||
if (entity instanceof Player) {
|
||||
Player watched = (Player) entity;
|
||||
if (DisguiseAPI.isDisguised(watched.getName())) {
|
||||
Disguise disguise = DisguiseAPI.getDisguise(watched);
|
||||
if (event.getPacketID() == Packets.Server.NAMED_ENTITY_SPAWN) {
|
||||
if (disguise.getType().isPlayer()) {
|
||||
String name = (String) mods.read(1);
|
||||
if (!name.equals(((PlayerDisguise) disguise).getName())) {
|
||||
if (event.getPacketID() == Packets.Server.NAMED_SOUND_EFFECT) {
|
||||
if (!DisguiseAPI.playSounds())
|
||||
return;
|
||||
String soundName = (String) mods.read(0);
|
||||
if (soundName.startsWith("step.") || soundName.equals("damage.hit")) {
|
||||
Disguise dis = null;
|
||||
Location soundLoc = new Location(observer.getWorld(), (Integer) mods.read(1), (Integer) mods
|
||||
.read(2), (Integer) mods.read(3));
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
if (DisguiseAPI.isDisguised(player)) {
|
||||
Location loc = player.getLocation();
|
||||
Location dLoc = new Location(observer.getWorld(), (int) (loc.getX() * 8), (int) (loc
|
||||
.getY() * 8), (int) (loc.getZ() * 8));
|
||||
if (dLoc.equals(soundLoc)) {
|
||||
dis = DisguiseAPI.getDisguise(player);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (dis != null) {
|
||||
if (dis.getType().isPlayer())
|
||||
return;
|
||||
if (dis.getType().isMisc()) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
String sound = null;
|
||||
try {
|
||||
Field field = CraftSound.class.getDeclaredField("sounds");
|
||||
field.setAccessible(true);
|
||||
List<String> sounds = Arrays.asList((String[]) field.get(null));
|
||||
String mobName = dis.getType().name().toLowerCase().replace("_", "");
|
||||
if (dis.getType() == DisguiseType.WITHER_SKELETON)
|
||||
mobName = "skeleton";
|
||||
else if (dis.getType() == DisguiseType.OCELOT)
|
||||
mobName = "cat";
|
||||
if (soundName.startsWith("step.")) {
|
||||
if (sounds.contains("mob." + mobName + ".walk"))
|
||||
sound = "mob." + mobName + ".walk";
|
||||
else if (sounds.contains("mob." + mobName + ".step"))
|
||||
sound = "mob." + mobName + ".step";
|
||||
} else if (soundName.equals("damage.hit")) {
|
||||
if (sounds.contains("mob." + mobName + ".hit"))
|
||||
sound = "mob." + mobName + ".hit";
|
||||
else if (sounds.contains("mob." + mobName + ".hitt"))
|
||||
sound = "mob." + mobName + ".hitt";
|
||||
else if (sounds.contains("mob." + mobName + ".hurt"))
|
||||
sound = "mob." + mobName + ".hurt";
|
||||
else if (sounds.contains("mob." + mobName + ".say"))
|
||||
sound = "mob." + mobName + ".say";
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
System.out.print(sound);
|
||||
if (sound != null) {
|
||||
mods.write(0, sound);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
org.bukkit.entity.Entity entity = event.getPacket().getEntityModifier(observer.getWorld())
|
||||
.read(0);
|
||||
if (entity instanceof Player) {
|
||||
Player watched = (Player) entity;
|
||||
if (DisguiseAPI.isDisguised(watched.getName())) {
|
||||
Disguise disguise = DisguiseAPI.getDisguise(watched);
|
||||
if (event.getPacketID() == Packets.Server.ENTITY_METADATA
|
||||
&& !disguise.getType().isPlayer()) {
|
||||
if (disguise.hasWatcher()) {
|
||||
mods.write(1, disguise.getWatcher().convert((List<WatchableObject>) mods.read(1)));
|
||||
}
|
||||
} else if (event.getPacketID() == Packets.Server.NAMED_ENTITY_SPAWN) {
|
||||
if (disguise.getType().isPlayer()) {
|
||||
String name = (String) mods.read(1);
|
||||
if (!name.equals(((PlayerDisguise) disguise).getName())) {
|
||||
event.setCancelled(true);
|
||||
DisguiseAPI.disguiseToPlayer(watched, observer, disguise);
|
||||
}
|
||||
} else {
|
||||
event.setCancelled(true);
|
||||
DisguiseAPI.disguiseToPlayer(watched, observer, disguise);
|
||||
}
|
||||
} else {
|
||||
event.setCancelled(true);
|
||||
DisguiseAPI.disguiseToPlayer(watched, observer, disguise);
|
||||
}
|
||||
} else if (!disguise.getType().isPlayer()) {
|
||||
if (disguise.hasWatcher()) {
|
||||
mods.write(1, disguise.getWatcher().convert((List<WatchableObject>) mods.read(1)));
|
||||
// Set the sounds and cancel bad packets.
|
||||
if (disguise.getType().isMisc()) {
|
||||
if (event.getPacketID() == Packets.Server.ARM_ANIMATION) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user