Fixed Bat disguise

Fixed Painting disguise
Fixed Experience Orb disguise
Fixed some more datawatcher related things
Sounds added back in
Fixed *most* sounds (Some might still not work, please let me know)
Arrows now equal tipped arrows
Code cleanup

NOTE: Yes, this does take a lot of time, there's a lot to do here, and there's so much code to update. Not even mentioning the fact that most packets don't  even work the same anymore (SPAWN NAMED ENTITY and SPAWN ENTITY both do not work the same way anymore)
This commit is contained in:
NavidK0 2016-03-10 00:44:11 -05:00
parent 432571cb09
commit 7dabbb7ce4
15 changed files with 454 additions and 455 deletions

View File

@ -98,7 +98,7 @@ ant.get src: 'http://server.o2gaming.com/downloads/spigot-1.9.jar', dest: file('
dependencies { dependencies {
compile "org.spigotmc:spigot-api:$project.ext.spigotVersion" compile "org.spigotmc:spigot-api:$project.ext.spigotVersion"
compile 'com.comphenix.protocol:ProtocolLib:3.7.0-BETA' compile 'com.comphenix.protocol:ProtocolLib:3.7.0-SNAPSHOT'
compile name: 'spigot-1.9' compile name: 'spigot-1.9'
testCompile group: 'junit', name: 'junit', version: '4.10' testCompile group: 'junit', name: 'junit', version: '4.10'
} }

View File

@ -24,6 +24,7 @@ import org.bukkit.inventory.EntityEquipment;
import org.bukkit.inventory.HorseInventory; import org.bukkit.inventory.HorseInventory;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.Method; import java.lang.reflect.Method;
@ -52,8 +53,10 @@ public class DisguiseAPI {
if (entity instanceof LivingEntity) { if (entity instanceof LivingEntity) {
for (PotionEffect effect : ((LivingEntity) entity).getActivePotionEffects()) { for (PotionEffect effect : ((LivingEntity) entity).getActivePotionEffects()) {
((LivingWatcher) watcher).addPotionEffect(effect.getType()); ((LivingWatcher) watcher).addPotionEffect(effect.getType());
if (effect.getType().getName().equals("INVISIBILITY")) { if (effect.getType() == PotionEffectType.INVISIBILITY) {
watcher.setInvisible(true); watcher.setInvisible(true);
} else if (effect.getType() == PotionEffectType.GLOWING) {
watcher.setGlowing(true);
} }
} }
} }
@ -110,9 +113,7 @@ public class DisguiseAPI {
value = (float) d; value = (float) d;
} }
} else if (toCast == double.class) { } else if (toCast == double.class) {
if (value instanceof Double) { if (!(value instanceof Double)) {
value = value;
} else {
float d = (Float) value; float d = (Float) value;
value = (double) d; value = (double) d;
} }

View File

@ -25,6 +25,7 @@ import me.libraryaddict.disguise.disguisetypes.watchers.MinecartWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.SkeletonWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.SkeletonWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.SlimeWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.SlimeWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.TameableWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.TameableWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.TippedArrowWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.ZombieWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.ZombieWatcher;
import me.libraryaddict.disguise.utilities.DisguiseSound; import me.libraryaddict.disguise.utilities.DisguiseSound;
import me.libraryaddict.disguise.utilities.DisguiseUtilities; import me.libraryaddict.disguise.utilities.DisguiseUtilities;
@ -101,9 +102,11 @@ public class LibsDisguises extends JavaPlugin {
if (disguiseType.getEntityType() == null) { if (disguiseType.getEntityType() == null) {
continue; continue;
} }
Class watcherClass; Class watcherClass = null;
try { try {
switch (disguiseType) { switch (disguiseType) {
case ITEM_FRAME: //Not really supported...
break;
case MINECART_CHEST: case MINECART_CHEST:
case MINECART_COMMAND: case MINECART_COMMAND:
case MINECART_FURNACE: case MINECART_FURNACE:
@ -134,6 +137,9 @@ public class LibsDisguises extends JavaPlugin {
case WITHER_SKELETON: case WITHER_SKELETON:
watcherClass = SkeletonWatcher.class; watcherClass = SkeletonWatcher.class;
break; break;
case ARROW:
watcherClass = TippedArrowWatcher.class;
break;
default: default:
watcherClass = Class.forName("me.libraryaddict.disguise.disguisetypes.watchers." watcherClass = Class.forName("me.libraryaddict.disguise.disguisetypes.watchers."
+ toReadable(disguiseType.name()) + "Watcher"); + toReadable(disguiseType.name()) + "Watcher");
@ -199,6 +205,8 @@ public class LibsDisguises extends JavaPlugin {
case ELDER_GUARDIAN: case ELDER_GUARDIAN:
nmsEntityName = "Guardian"; nmsEntityName = "Guardian";
break; break;
case ARROW:
nmsEntityName = "TippedArrow";
default: default:
break; break;
} }

View File

@ -404,7 +404,7 @@ public abstract class BaseDisguiseCommand implements CommandExecutor {
int miscData = -1; int miscData = -1;
String secondArg = null; String secondArg = null;
if (args.length > 1) { if (args.length > 1) {
// They have defined more arguements! // They have defined more arguments!
// If the first arg is a number // If the first arg is a number
if (args[1].contains(":")) { if (args[1].contains(":")) {
String[] split = args[1].split(":"); String[] split = args[1].split(":");
@ -432,6 +432,7 @@ public abstract class BaseDisguiseCommand implements CommandExecutor {
case SPLASH_POTION: case SPLASH_POTION:
case DROPPED_ITEM: case DROPPED_ITEM:
case FISHING_HOOK: case FISHING_HOOK:
case ARROW:
case TIPPED_ARROW: case TIPPED_ARROW:
case SPECTRAL_ARROW: case SPECTRAL_ARROW:
case SMALL_FIREBALL: case SMALL_FIREBALL:

View File

@ -233,7 +233,7 @@ public abstract class Disguise {
if (isModifyBoundingBox()) { if (isModifyBoundingBox()) {
DisguiseUtilities.doBoundingBox(disguise); DisguiseUtilities.doBoundingBox(disguise);
} }
if (getType() == DisguiseType.BAT && !((BatWatcher) getWatcher()).isFlying()) { if (getType() == DisguiseType.BAT && !((BatWatcher) getWatcher()).isHanging()) {
return; return;
} }
// If the vectorY isn't 0. Cos if it is. Then it doesn't want to send any vectors. // If the vectorY isn't 0. Cos if it is. Then it doesn't want to send any vectors.
@ -306,8 +306,7 @@ public abstract class Disguise {
PacketContainer selfPacket = packet.shallowClone(); PacketContainer selfPacket = packet.shallowClone();
selfPacket.getModifier().write(0, DisguiseAPI.getSelfDisguiseId()); selfPacket.getModifier().write(0, DisguiseAPI.getSelfDisguiseId());
try { try {
ProtocolLibrary.getProtocolManager().sendServerPacket((Player) getEntity(), selfPacket, ProtocolLibrary.getProtocolManager().sendServerPacket((Player) getEntity(), selfPacket, false);
false);
} catch (InvocationTargetException e) { } catch (InvocationTargetException e) {
e.printStackTrace(System.out); e.printStackTrace(System.out);
} }
@ -636,13 +635,13 @@ public abstract class Disguise {
// Since they both share it. With the same classes. Time to check if its from something they extend. // Since they both share it. With the same classes. Time to check if its from something they extend.
// Better make this clear before I compare the values because some default values are different! // Better make this clear before I compare the values because some default values are different!
// Entity is 0 & 1 - But we aint gonna be checking that // Entity is 0 & 1 - But we aint gonna be checking that
// EntityAgeable is 16 // EntityAgeable is 11
// EntityInsentient is 10 & 11 // EntityInsentient is 10
// EntityZombie is 12 & 13 & 14 - But it overrides other values and another check already does this. // EntityLiving is 5 & 6 & 7 & 8 & 9
// EntityLiving is 6 & 7 & 8 & 9
// Lets use switch // Lets use switch
Class baseClass = null; Class baseClass = null;
switch (dataNo) { switch (dataNo) {
case 5:
case 6: case 6:
case 7: case 7:
case 8: case 8:
@ -650,10 +649,9 @@ public abstract class Disguise {
baseClass = ReflectionManager.getNmsClass("EntityLiving"); baseClass = ReflectionManager.getNmsClass("EntityLiving");
break; break;
case 10: case 10:
case 11:
baseClass = ReflectionManager.getNmsClass("EntityInsentient"); baseClass = ReflectionManager.getNmsClass("EntityInsentient");
break; break;
case 16: case 11:
baseClass = ReflectionManager.getNmsClass("EntityAgeable"); baseClass = ReflectionManager.getNmsClass("EntityAgeable");
break; break;
default: default:

View File

@ -14,6 +14,7 @@ public enum DisguiseType {
AREA_EFFECT_CLOUD, AREA_EFFECT_CLOUD,
ARMOR_STAND, ARMOR_STAND,
ARROW,
BAT, BAT,
BLAZE, BLAZE,
BOAT, BOAT,
@ -23,35 +24,35 @@ public enum DisguiseType {
CREEPER, CREEPER,
DONKEY, DONKEY,
DRAGON_FIREBALL, DRAGON_FIREBALL,
DROPPED_ITEM(-1, 1), DROPPED_ITEM(1),
EGG, EGG,
ELDER_GUARDIAN, ELDER_GUARDIAN,
ENDER_CRYSTAL, ENDER_CRYSTAL,
ENDER_DRAGON, ENDER_DRAGON,
ENDER_PEARL, ENDER_PEARL,
ENDER_SIGNAL(15), ENDER_SIGNAL,
ENDERMAN, ENDERMAN,
ENDERMITE, ENDERMITE,
EXPERIENCE_ORB, EXPERIENCE_ORB,
FALLING_BLOCK(12, 1), FALLING_BLOCK(1),
FIREBALL(26, 0), FIREBALL(0),
FIREWORK(22), FIREWORK,
FISHING_HOOK, FISHING_HOOK,
GHAST, GHAST,
GIANT, GIANT,
GUARDIAN, GUARDIAN,
HORSE, HORSE,
IRON_GOLEM, IRON_GOLEM,
ITEM_FRAME(18), ITEM_FRAME,
LEASH_HITCH(8), LEASH_HITCH,
MAGMA_CUBE, MAGMA_CUBE,
MINECART, MINECART,
MINECART_CHEST, MINECART_CHEST(1),
MINECART_COMMAND, MINECART_COMMAND(6),
MINECART_FURNACE, MINECART_FURNACE(2),
MINECART_HOPPER, MINECART_HOPPER(5),
MINECART_MOB_SPAWNER, MINECART_MOB_SPAWNER(4),
MINECART_TNT, MINECART_TNT(5),
MULE, MULE,
MUSHROOM_COW, MUSHROOM_COW,
OCELOT, OCELOT,
@ -59,30 +60,30 @@ public enum DisguiseType {
PIG, PIG,
PIG_ZOMBIE, PIG_ZOMBIE,
PLAYER, PLAYER,
PRIMED_TNT(20), PRIMED_TNT,
RABBIT, RABBIT,
SHEEP, SHEEP,
SHULKER, SHULKER,
SHULKER_BULLET(25), SHULKER_BULLET,
SILVERFISH, SILVERFISH,
SKELETON, SKELETON,
SKELETON_HORSE, SKELETON_HORSE,
SLIME, SLIME,
SMALL_FIREBALL(13, 0), SMALL_FIREBALL(0),
SNOWBALL(11), SNOWBALL,
SNOWMAN, SNOWMAN,
SPECTRAL_ARROW(24), SPECTRAL_ARROW,
SPIDER, SPIDER,
SPLASH_POTION, SPLASH_POTION,
SQUID, SQUID,
TIPPED_ARROW(23), TIPPED_ARROW,
THROWN_EXP_BOTTLE(17), THROWN_EXP_BOTTLE,
UNDEAD_HORSE, UNDEAD_HORSE,
VILLAGER, VILLAGER,
WITCH, WITCH,
WITHER, WITHER,
WITHER_SKELETON, WITHER_SKELETON,
WITHER_SKULL(19), WITHER_SKULL,
WOLF, WOLF,
ZOMBIE, ZOMBIE,
ZOMBIE_VILLAGER, ZOMBIE_VILLAGER,
@ -116,6 +117,8 @@ public enum DisguiseType {
case ELDER_GUARDIAN: case ELDER_GUARDIAN:
toUse = DisguiseType.GUARDIAN; toUse = DisguiseType.GUARDIAN;
break; break;
case ARROW:
toUse = DisguiseType.TIPPED_ARROW;
default: default:
break; break;
} }
@ -196,7 +199,7 @@ public enum DisguiseType {
} }
} }
private int defaultId, entityId; private int defaultData = -1;
private EntityType entityType; private EntityType entityType;
private Class<? extends FlagWatcher> watcherClass; private Class<? extends FlagWatcher> watcherClass;
@ -205,10 +208,7 @@ public enum DisguiseType {
int value = ints[i]; int value = ints[i];
switch (i) { switch (i) {
case 0: case 0:
entityId = value; defaultData = value;
break;
case 1:
defaultId = value;
break; break;
default: default:
break; break;
@ -216,8 +216,8 @@ public enum DisguiseType {
} }
} }
public int getDefaultId() { public int getDefaultData() {
return defaultId; return defaultData;
} }
public Class<? extends Entity> getEntityClass() { public Class<? extends Entity> getEntityClass() {
@ -227,10 +227,6 @@ public enum DisguiseType {
return Entity.class; return Entity.class;
} }
public int getEntityId() {
return entityId;
}
public EntityType getEntityType() { public EntityType getEntityType() {
return entityType; return entityType;
} }

View File

@ -6,7 +6,6 @@ import me.libraryaddict.disguise.disguisetypes.watchers.PaintingWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.SplashPotionWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.SplashPotionWatcher;
import org.bukkit.Art; import org.bukkit.Art;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@ -17,95 +16,53 @@ public class MiscDisguise extends TargetedDisguise {
private int id = -1, data = 0; private int id = -1, data = 0;
public MiscDisguise(DisguiseType disguiseType) { public MiscDisguise(DisguiseType disguiseType) {
this(disguiseType, -1, -1); this(disguiseType, -1, disguiseType.getDefaultData());
}
@Deprecated
public MiscDisguise(DisguiseType disguiseType, boolean replaceSounds) {
this(disguiseType, replaceSounds, -1, -1);
}
@Deprecated
public MiscDisguise(DisguiseType disguiseType, boolean replaceSounds, int addictionalData) {
this(disguiseType, replaceSounds, (disguiseType == DisguiseType.FALLING_BLOCK
|| disguiseType == DisguiseType.DROPPED_ITEM ? addictionalData : -1), (disguiseType == DisguiseType.FALLING_BLOCK
|| disguiseType == DisguiseType.DROPPED_ITEM ? -1 : addictionalData));
}
@Deprecated
public MiscDisguise(DisguiseType disguiseType, boolean replaceSounds, int id, int data) {
this(disguiseType, id, data);
this.setReplaceSounds(replaceSounds);
} }
public MiscDisguise(DisguiseType disguiseType, int id) { public MiscDisguise(DisguiseType disguiseType, int id) {
this(disguiseType, id, -1); this(disguiseType, id, disguiseType.getDefaultData());
} }
public MiscDisguise(DisguiseType disguiseType, int firstParam, int secondParam) { public MiscDisguise(DisguiseType disguiseType, int id, int data) {
if (!disguiseType.isMisc()) { if (!disguiseType.isMisc()) {
throw new InvalidParameterException("Expected a non-living DisguiseType while constructing MiscDisguise. Received " throw new InvalidParameterException("Expected a non-living DisguiseType while constructing MiscDisguise. Received "
+ disguiseType + " instead. Please use " + (disguiseType.isPlayer() ? "PlayerDisguise" : "MobDisguise") + disguiseType + " instead. Please use " + (disguiseType.isPlayer() ? "PlayerDisguise" : "MobDisguise")
+ " instead"); + " instead");
} }
createDisguise(disguiseType); createDisguise(disguiseType);
this.id = getType().getEntityId(); this.id = getType().getTypeId();
this.data = getType().getDefaultId(); this.data = getType().getDefaultData();
switch (disguiseType) { switch (disguiseType) {
// The only disguises which should use a custom data. // The only disguises which should use a custom data.
case PAINTING: case PAINTING:
((PaintingWatcher) getWatcher()).setArt(Art.values()[Math.max(0, firstParam) % Art.values().length]); ((PaintingWatcher) getWatcher()).setArt(Art.values()[Math.max(0, id) % Art.values().length]);
break; break;
case FALLING_BLOCK: case FALLING_BLOCK:
((FallingBlockWatcher) getWatcher()).setBlock(new ItemStack(Math.max(1, firstParam), 1, (short) Math.max(0, ((FallingBlockWatcher) getWatcher()).setBlock(new ItemStack(Math.max(1, id), 1, (short) Math.max(0,
secondParam))); data)));
break; break;
case SPLASH_POTION: case SPLASH_POTION:
((SplashPotionWatcher) getWatcher()).setPotionId(Math.max(0, firstParam)); ((SplashPotionWatcher) getWatcher()).setPotionId(Math.max(0, id));
break; break;
case DROPPED_ITEM: case DROPPED_ITEM:
if (firstParam > 0) { if (id > 0) {
((DroppedItemWatcher) getWatcher()).setItemStack(new ItemStack(firstParam, Math.max(0, secondParam))); ((DroppedItemWatcher) getWatcher()).setItemStack(new ItemStack(id, Math.max(0, data)));
} }
break; break;
case FISHING_HOOK: // Entity ID of whoever is holding fishing rod case FISHING_HOOK: // Entity ID of whoever is holding fishing rod
case ARROW:
case TIPPED_ARROW: // Entity ID of shooter. Used for "Is he on this scoreboard team and do I render it moving through his body?" case TIPPED_ARROW: // Entity ID of shooter. Used for "Is he on this scoreboard team and do I render it moving through his body?"
case SPECTRAL_ARROW: case SPECTRAL_ARROW:
case SMALL_FIREBALL: // Unknown. Uses entity id of shooter. 0 if no shooter case SMALL_FIREBALL: // Unknown. Uses entity id of shooter. 0 if no shooter
case FIREBALL: // Unknown. Uses entity id of shooter. 0 if no shooter case FIREBALL: // Unknown. Uses entity id of shooter. 0 if no shooter
case WITHER_SKULL: // Unknown. Uses entity id of shooter. 0 if no shooter case WITHER_SKULL: // Unknown. Uses entity id of shooter. 0 if no shooter
this.data = firstParam; this.data = id;
break; break;
default: default:
break; break;
} }
} }
@Deprecated
public MiscDisguise(EntityType entityType) {
this(entityType, -1, -1);
}
@Deprecated
public MiscDisguise(EntityType entityType, boolean replaceSounds) {
this(entityType, replaceSounds, -1, -1);
}
@Deprecated
public MiscDisguise(EntityType entityType, boolean replaceSounds, int id, int data) {
this(DisguiseType.getType(entityType), replaceSounds, id, data);
}
@Deprecated
public MiscDisguise(EntityType entityType, int id) {
this(entityType, id, -1);
}
@Deprecated
public MiscDisguise(EntityType disguiseType, int id, int data) {
this(DisguiseType.getType(disguiseType), id, data);
}
@Override @Override
public MiscDisguise addPlayer(Player player) { public MiscDisguise addPlayer(Player player) {
return (MiscDisguise) super.addPlayer(player); return (MiscDisguise) super.addPlayer(player);

View File

@ -80,8 +80,7 @@ public class PlayerDisguise extends TargetedDisguise {
if (getSkin() != null) { if (getSkin() != null) {
gameProfile = ReflectionManager.getGameProfile(null, getName()); gameProfile = ReflectionManager.getGameProfile(null, getName());
} else { } else {
gameProfile = ReflectionManager.getGameProfileWithThisSkin(null, getName(), gameProfile = ReflectionManager.getGameProfileWithThisSkin(null, getName(), DisguiseUtilities.getProfileFromMojang(this));
DisguiseUtilities.getProfileFromMojang(this));
} }
} }
return gameProfile; return gameProfile;

View File

@ -6,15 +6,15 @@ public class BatWatcher extends LivingWatcher {
public BatWatcher(Disguise disguise) { public BatWatcher(Disguise disguise) {
super(disguise); super(disguise);
setFlying(true); setHanging(false);
} }
public boolean isFlying() { public boolean isHanging() {
return (boolean) getValue(11, true); return ((byte)getValue(11, (byte) 1)) == 1;
} }
public void setFlying(boolean flying) { public void setHanging(boolean hanging) {
setValue(11, flying); setValue(11, hanging ? (byte) 1 : (byte) 0);
sendData(11); sendData(11);
} }
} }

View File

@ -9,7 +9,6 @@ public class PaintingWatcher extends FlagWatcher {
private Art painting; private Art painting;
//TODO: Check this
public PaintingWatcher(Disguise disguise) { public PaintingWatcher(Disguise disguise) {
super(disguise); super(disguise);
} }

View File

@ -11,67 +11,67 @@ import java.util.HashSet;
public enum DisguiseSound { public enum DisguiseSound {
ARROW(null, null, null, null, "random.bowhit"), ARROW(null, null, null, null, "random.bowhit"),
BAT("mob.bat.hurt", null, "mob.bat.death", "mob.bat.idle", "damage.fallsmall", "mob.bat.loop", "damage.fallbig", BAT("entity.bat.hurt", null, "entity.bat.death", "entity.bat.idle", "damage.fallsmall", "entity.bat.loop", "damage.fallbig",
"mob.bat.takeoff"), "entity.bat.takeoff"),
BLAZE("mob.blaze.hit", null, "mob.blaze.death", "mob.blaze.breathe", "damage.fallsmall", "damage.fallbig"), BLAZE("entity.blaze.hit", null, "entity.blaze.death", "entity.blaze.breathe", "damage.fallsmall", "damage.fallbig"),
CAVE_SPIDER("mob.spider.say", "mob.spider.step", "mob.spider.death", "mob.spider.say"), CAVE_SPIDER("entity.spider.ambient", "entity.spider.step", "entity.spider.death", "entity.spider.ambient"),
CHICKEN("mob.chicken.hurt", "mob.chicken.step", "mob.chicken.hurt", "mob.chicken.say", "damage.fallsmall", CHICKEN("entity.chicken.hurt", "entity.chicken.step", "entity.chicken.hurt", "entity.chicken.ambient", "damage.fallsmall",
"mob.chicken.plop", "damage.fallbig"), "entity.chicken.plop", "damage.fallbig"),
COW("mob.cow.hurt", "mob.cow.step", "mob.cow.hurt", "mob.cow.say"), COW("entity.cow.hurt", "entity.cow.step", "entity.cow.hurt", "entity.cow.ambient"),
CREEPER("mob.creeper.say", "step.grass", "mob.creeper.death", null), CREEPER("entity.creeper.ambient", "step.grass", "entity.creeper.death", null),
DONKEY("mob.horse.donkey.hit", "step.grass", "mob.horse.donkey.death", "mob.horse.donkey.idle", "mob.horse.gallop", DONKEY("entity.horse.donkey.hit", "step.grass", "entity.horse.donkey.death", "entity.horse.donkey.idle", "entity.horse.gallop",
"mob.horse.leather", "mob.horse.donkey.angry", "mob.horse.wood", "mob.horse.armor", "mob.horse.soft", "entity.horse.leather", "entity.horse.donkey.angry", "entity.horse.wood", "entity.horse.armor", "entity.horse.soft",
"mob.horse.land", "mob.horse.jump", "mob.horse.angry"), "entity.horse.land", "entity.horse.jump", "entity.horse.angry"),
ELDER_GUARDIAN("mob.guardian.elder.hit", null, "mob.guardian.elder.death", "mob.guardian.elder.death"), ELDER_GUARDIAN("entity.guardian.elder.hit", null, "entity.guardian.elder.death", "entity.guardian.elder.death"),
ENDER_DRAGON("mob.enderdragon.hit", null, "mob.enderdragon.end", "mob.enderdragon.growl", "damage.fallsmall", ENDER_DRAGON("entity.enderdragon.hit", null, "entity.enderdragon.end", "entity.enderdragon.growl", "damage.fallsmall",
"mob.enderdragon.wings", "damage.fallbig"), "entity.enderdragon.wings", "damage.fallbig"),
ENDERMAN("mob.endermen.hit", "step.grass", "mob.endermen.death", "mob.endermen.idle", "mob.endermen.scream", ENDERMAN("entity.endermen.hit", "step.grass", "entity.endermen.death", "entity.endermen.idle", "entity.endermen.scream",
"mob.endermen.portal", "mob.endermen.stare"), "entity.endermen.portal", "entity.endermen.stare"),
ENDERMITE("mob.silverfish.hit", "mob.silverfish.step", "mob.silverfish.kill", "mob.silverfish.say"), ENDERMITE("entity.silverfish.hit", "entity.silverfish.step", "entity.silverfish.kill", "entity.silverfish.ambient"),
GHAST("mob.ghast.scream", null, "mob.ghast.death", "mob.ghast.moan", "damage.fallsmall", "mob.ghast.fireball", GHAST("entity.ghast.scream", null, "entity.ghast.death", "entity.ghast.moan", "damage.fallsmall", "entity.ghast.fireball",
"damage.fallbig", "mob.ghast.affectionate_scream", "mob.ghast.charge"), "damage.fallbig", "entity.ghast.affectionate_scream", "entity.ghast.charge"),
GIANT("damage.hit", "step.grass", null, null), GIANT("damage.hit", "step.grass", null, null),
GUARDIAN("mob.guardian.hit", null, "mob.guardian.death", "mob.guardian.death"), GUARDIAN("entity.guardian.hit", null, "entity.guardian.death", "entity.guardian.death"),
HORSE("mob.horse.hit", "step.grass", "mob.horse.death", "mob.horse.idle", "mob.horse.gallop", "mob.horse.leather", HORSE("entity.horse.hit", "step.grass", "entity.horse.death", "entity.horse.idle", "entity.horse.gallop", "entity.horse.leather",
"mob.horse.wood", "mob.horse.armor", "mob.horse.soft", "mob.horse.land", "mob.horse.jump", "mob.horse.angry", "entity.horse.wood", "entity.horse.armor", "entity.horse.soft", "entity.horse.land", "entity.horse.jump", "entity.horse.angry",
"mob.horse.leather"), "entity.horse.leather"),
IRON_GOLEM("mob.irongolem.hit", "mob.irongolem.walk", "mob.irongolem.death", "mob.irongolem.throw"), IRON_GOLEM("entity.irongolem.hit", "entity.irongolem.walk", "entity.irongolem.death", "entity.irongolem.throw"),
MAGMA_CUBE("mob.slime.attack", "mob.slime.big", null, null, "mob.slime.small"), MAGMA_CUBE("entity.slime.attack", "entity.slime.big", null, null, "entity.slime.small"),
MULE("mob.horse.donkey.hit", "step.grass", "mob.horse.donkey.death", "mob.horse.donkey.idle"), MULE("entity.horse.donkey.hit", "step.grass", "entity.horse.donkey.death", "entity.horse.donkey.idle"),
MUSHROOM_COW("mob.cow.hurt", "mob.cow.step", "mob.cow.hurt", "mob.cow.say"), MUSHROOM_COW("entity.cow.hurt", "entity.cow.step", "entity.cow.hurt", "entity.cow.ambient"),
OCELOT("mob.cat.hitt", "step.grass", "mob.cat.hitt", "mob.cat.meow", "mob.cat.purreow", "mob.cat.purr"), OCELOT("entity.cat.hitt", "step.grass", "entity.cat.hitt", "entity.cat.meow", "entity.cat.purreow", "entity.cat.purr"),
PIG("mob.pig.say", "mob.pig.step", "mob.pig.death", "mob.pig.say"), PIG("entity.pig.ambient", "entity.pig.step", "entity.pig.death", "entity.pig.ambient"),
PIG_ZOMBIE("mob.zombiepig.zpighurt", null, "mob.zombiepig.zpigdeath", "mob.zombiepig.zpig", "mob.zombiepig.zpigangry"), PIG_ZOMBIE("entity.zombiepig.zpighurt", null, "entity.zombiepig.zpigdeath", "entity.zombiepig.zpig", "entity.zombiepig.zpigangry"),
PLAYER("game.player.hurt", "step.grass", "game.player.hurt", null), PLAYER("game.player.hurt", "step.grass", "game.player.hurt", null),
RABBIT("mob.rabbit.hurt", "mob.rabbit.hop", "mob.rabbit.death", "mob.rabbit.idle"), RABBIT("entity.rabbit.hurt", "entity.rabbit.hop", "entity.rabbit.death", "entity.rabbit.idle"),
SHEEP("mob.sheep.say", "mob.sheep.step", null, "mob.sheep.say", "mob.sheep.shear"), SHEEP("entity.sheep.ambient", "entity.sheep.step", null, "entity.sheep.ambient", "entity.sheep.shear"),
SHULKER("entity.shulker.hurt", null, "entity.shulker.death", "entity.shulker.ambient", "entity.shulker.open", SHULKER("entity.shulker.hurt", null, "entity.shulker.death", "entity.shulker.ambient", "entity.shulker.open",
"entity.shulker.hurt_closed", "entity.shulker.close", "entity.shulker.teleport", "entity.shulker_bullet.hit", "entity.shulker.hurt_closed", "entity.shulker.close", "entity.shulker.teleport", "entity.shulker_bullet.hit",
"entity.shulker_bullet.hurt"), "entity.shulker_bullet.hurt"),
SILVERFISH("mob.silverfish.hit", "mob.silverfish.step", "mob.silverfish.kill", "mob.silverfish.say"), SILVERFISH("entity.silverfish.hit", "entity.silverfish.step", "entity.silverfish.kill", "entity.silverfish.ambient"),
SKELETON("mob.skeleton.hurt", "mob.skeleton.step", "mob.skeleton.death", "mob.skeleton.say"), SKELETON("entity.skeleton.hurt", "entity.skeleton.step", "entity.skeleton.death", "entity.skeleton.ambient"),
SKELETON_HORSE("mob.horse.skeleton.hit", "step.grass", "mob.horse.skeleton.death", "mob.horse.skeleton.idle", SKELETON_HORSE("entity.horse.skeleton.hit", "step.grass", "entity.horse.skeleton.death", "entity.horse.skeleton.idle",
"mob.horse.gallop", "mob.horse.leather", "mob.horse.wood", "mob.horse.armor", "mob.horse.soft", "mob.horse.land", "entity.horse.gallop", "entity.horse.leather", "entity.horse.wood", "entity.horse.armor", "entity.horse.soft", "entity.horse.land",
"mob.horse.jump", "mob.horse.angry"), "entity.horse.jump", "entity.horse.angry"),
SLIME("mob.slime.attack", "mob.slime.big", null, null, "mob.slime.small"), SLIME("entity.slime.attack", "entity.slime.big", null, null, "entity.slime.small"),
SNOWMAN(), SNOWMAN(),
SPIDER("mob.spider.say", "mob.spider.step", "mob.spider.death", "mob.spider.say"), SPIDER("entity.spider.ambient", "entity.spider.step", "entity.spider.death", "entity.spider.ambient"),
SQUID(), SQUID(),
UNDEAD_HORSE("mob.horse.zombie.hit", "step.grass", "mob.horse.zombie.death", "mob.horse.zombie.idle", "mob.horse.gallop", UNDEAD_HORSE("entity.horse.zombie.hit", "step.grass", "entity.horse.zombie.death", "entity.horse.zombie.idle", "entity.horse.gallop",
"mob.horse.leather", "mob.horse.wood", "mob.horse.armor", "mob.horse.soft", "mob.horse.land", "mob.horse.jump", "entity.horse.leather", "entity.horse.wood", "entity.horse.armor", "entity.horse.soft", "entity.horse.land", "entity.horse.jump",
"mob.horse.angry"), "entity.horse.angry"),
VILLAGER("mob.villager.hit", null, "mob.villager.death", "mob.villager.idle", "mob.villager.haggle", "mob.villager.no", VILLAGER("entity.villager.hit", null, "entity.villager.death", "entity.villager.idle", "entity.villager.haggle", "entity.villager.no",
"mob.villager.yes"), "entity.villager.yes"),
WITCH("mob.witch.hurt", null, "mob.witch.death", "mob.witch.idle"), WITCH("entity.witch.hurt", null, "entity.witch.death", "entity.witch.idle"),
WITHER("mob.wither.hurt", null, "mob.wither.death", "mob.wither.idle", "damage.fallsmall", "mob.wither.spawn", WITHER("entity.wither.hurt", null, "entity.wither.death", "entity.wither.idle", "damage.fallsmall", "entity.wither.spawn",
"damage.fallbig", "mob.wither.shoot"), "damage.fallbig", "entity.wither.shoot"),
WITHER_SKELETON("mob.skeleton.hurt", "mob.skeleton.step", "mob.skeleton.death", "mob.skeleton.say"), WITHER_SKELETON("entity.skeleton.hurt", "entity.skeleton.step", "entity.skeleton.death", "entity.skeleton.ambient"),
WOLF("mob.wolf.hurt", "mob.wolf.step", "mob.wolf.death", "mob.wolf.bark", "mob.wolf.panting", "mob.wolf.whine", WOLF("entity.wolf.hurt", "entity.wolf.step", "entity.wolf.death", "entity.wolf.bark", "entity.wolf.panting", "entity.wolf.whine",
"mob.wolf.howl", "mob.wolf.growl", "mob.wolf.shake"), "entity.wolf.howl", "entity.wolf.growl", "entity.wolf.shake"),
ZOMBIE("mob.zombie.hurt", "mob.zombie.step", "mob.zombie.death", "mob.zombie.say", "mob.zombie.infect", ZOMBIE("entity.zombie.hurt", "entity.zombie.step", "entity.zombie.death", "entity.zombie.ambient", "entity.zombie.infect",
"mob.zombie.woodbreak", "mob.zombie.metal", "mob.zombie.wood"), "entity.zombie.break_wood_door", "entity.zombie.attack_wood_door", "entity.zombie.break_wood_door"),
ZOMBIE_VILLAGER("mob.zombie.hurt", "mob.zombie.step", "mob.zombie.death", "mob.zombie.say", "mob.zombie.infect", ZOMBIE_VILLAGER("entity.zombie.hurt", "entity.zombie.step", "entity.zombie.death", "entity.zombie.ambient", "entity.zombie.infect",
"mob.zombie.woodbreak", "mob.zombie.metal", "mob.zombie.wood"); "entity.zombie.break_wood_door", "entity.zombie.attack_wood_door", "entity.zombie.break_wood_door");
public enum SoundType { public enum SoundType {
CANCEL, DEATH, HURT, IDLE, STEP CANCEL, DEATH, HURT, IDLE, STEP

View File

@ -270,7 +270,6 @@ public class DisguiseUtilities {
} }
public static void doBoundingBox(TargetedDisguise disguise) { public static void doBoundingBox(TargetedDisguise disguise) {
//TODO: Slimes
Entity entity = disguise.getEntity(); Entity entity = disguise.getEntity();
if (entity != null) { if (entity != null) {
if (isDisguiseInUse(disguise)) { if (isDisguiseInUse(disguise)) {
@ -722,10 +721,8 @@ public class DisguiseUtilities {
final Object entityTrackerEntry = ReflectionManager.getEntityTrackerEntry(disguise.getEntity()); final Object entityTrackerEntry = ReflectionManager.getEntityTrackerEntry(disguise.getEntity());
if (entityTrackerEntry != null) { if (entityTrackerEntry != null) {
Set trackedPlayers = (Set) ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers").get(entityTrackerEntry); Set trackedPlayers = (Set) ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers").get(entityTrackerEntry);
Method clear = ReflectionManager.getNmsMethod("EntityTrackerEntry", "clear", final Method clear = ReflectionManager.getNmsMethod("EntityTrackerEntry", "clear", ReflectionManager.getNmsClass("EntityPlayer"));
ReflectionManager.getNmsClass("EntityPlayer")); final Method updatePlayer = ReflectionManager.getNmsMethod("EntityTrackerEntry", "updatePlayer", ReflectionManager.getNmsClass("EntityPlayer"));
final Method updatePlayer = ReflectionManager.getNmsMethod("EntityTrackerEntry", "updatePlayer",
ReflectionManager.getNmsClass("EntityPlayer"));
trackedPlayers = new HashSet(trackedPlayers); //Copy before iterating to prevent ConcurrentModificationException trackedPlayers = new HashSet(trackedPlayers); //Copy before iterating to prevent ConcurrentModificationException
for (final Object p : trackedPlayers) { for (final Object p : trackedPlayers) {
Player player = (Player) ReflectionManager.getBukkitEntity(p); Player player = (Player) ReflectionManager.getBukkitEntity(p);
@ -779,7 +776,6 @@ public class DisguiseUtilities {
ex.printStackTrace(System.out); ex.printStackTrace(System.out);
} }
//Code to stop player pushing in 1.9 //Code to stop player pushing in 1.9
//TODO: Check validity
Scoreboard scoreboard = player.getScoreboard(); Scoreboard scoreboard = player.getScoreboard();
Team t; Team t;
if ((t = scoreboard.getTeam("LDPushing")) != null) { if ((t = scoreboard.getTeam("LDPushing")) != null) {
@ -1023,7 +1019,6 @@ public class DisguiseUtilities {
return; return;
} }
//Code to stop player pushing in 1.9 //Code to stop player pushing in 1.9
//TODO: Check validity
Scoreboard scoreboard = player.getScoreboard(); Scoreboard scoreboard = player.getScoreboard();
Team t; Team t;
if ((t = scoreboard.getTeam("LDPushing")) != null) { if ((t = scoreboard.getTeam("LDPushing")) != null) {
@ -1042,5 +1037,4 @@ public class DisguiseUtilities {
} }
} }
} }
} }

View File

@ -30,6 +30,8 @@ public class DisguiseValues {
case ZOMBIE_VILLAGER: case ZOMBIE_VILLAGER:
type = DisguiseType.ZOMBIE; type = DisguiseType.ZOMBIE;
break; break;
case ARROW:
type = DisguiseType.TIPPED_ARROW;
default: default:
break; break;
} }

View File

@ -24,16 +24,19 @@ import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.DisguiseType; import me.libraryaddict.disguise.disguisetypes.DisguiseType;
import me.libraryaddict.disguise.disguisetypes.FlagWatcher; import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
import me.libraryaddict.disguise.disguisetypes.MiscDisguise; import me.libraryaddict.disguise.disguisetypes.MiscDisguise;
import me.libraryaddict.disguise.disguisetypes.MobDisguise;
import me.libraryaddict.disguise.disguisetypes.PlayerDisguise; import me.libraryaddict.disguise.disguisetypes.PlayerDisguise;
import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.PlayerWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.PlayerWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.SheepWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.SheepWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.SlimeWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.SlimeWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.WolfWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.WolfWatcher;
import me.libraryaddict.disguise.utilities.DisguiseSound.SoundType;
import org.bukkit.Art; import org.bukkit.Art;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.Ageable;
import org.bukkit.entity.Arrow; import org.bukkit.entity.Arrow;
import org.bukkit.entity.Damageable; import org.bukkit.entity.Damageable;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
@ -43,14 +46,18 @@ import org.bukkit.entity.Item;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.entity.Slime; import org.bukkit.entity.Slime;
import org.bukkit.entity.Zombie;
import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.metadata.FixedMetadataValue; import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Random;
import java.util.UUID; import java.util.UUID;
public class PacketsManager { public class PacketsManager {
@ -173,7 +180,6 @@ public class PacketsManager {
} }
if (disguise.getType() == DisguiseType.EXPERIENCE_ORB) { if (disguise.getType() == DisguiseType.EXPERIENCE_ORB) {
//TODO: Fix experience orb
spawnPackets[0] = new PacketContainer(Server.SPAWN_ENTITY_EXPERIENCE_ORB); spawnPackets[0] = new PacketContainer(Server.SPAWN_ENTITY_EXPERIENCE_ORB);
StructureModifier<Object> mods = spawnPackets[0].getModifier(); StructureModifier<Object> mods = spawnPackets[0].getModifier();
mods.write(0, disguisedEntity.getEntityId()); mods.write(0, disguisedEntity.getEntityId());
@ -182,7 +188,6 @@ public class PacketsManager {
mods.write(3, Math.floor(loc.getZ() * 32)); mods.write(3, Math.floor(loc.getZ() * 32));
mods.write(4, 1); mods.write(4, 1);
} else if (disguise.getType() == DisguiseType.PAINTING) { } else if (disguise.getType() == DisguiseType.PAINTING) {
//TODO: Fix painting
spawnPackets[0] = new PacketContainer(Server.SPAWN_ENTITY_PAINTING); spawnPackets[0] = new PacketContainer(Server.SPAWN_ENTITY_PAINTING);
StructureModifier<Object> mods = spawnPackets[0].getModifier(); StructureModifier<Object> mods = spawnPackets[0].getModifier();
mods.write(0, disguisedEntity.getEntityId()); mods.write(0, disguisedEntity.getEntityId());
@ -206,34 +211,27 @@ public class PacketsManager {
spawnPackets[0] = new PacketContainer(Server.NAMED_ENTITY_SPAWN); spawnPackets[0] = new PacketContainer(Server.NAMED_ENTITY_SPAWN);
PlayerDisguise playerDisguise = (PlayerDisguise) disguise; PlayerDisguise playerDisguise = (PlayerDisguise) disguise;
String name = playerDisguise.getSkin() != null ? playerDisguise.getSkin() : playerDisguise.getName(); String name = playerDisguise.getSkin() != null ? playerDisguise.getSkin() : playerDisguise.getName();
int entityId = disguisedEntity.getEntityId();
boolean removeName = false; boolean removeName = false;
if (!DisguiseUtilities.hasGameProfile(name)) { if (!DisguiseUtilities.hasGameProfile(name)) {
removeName = !DisguiseUtilities.getAddedByPlugins().contains(name); removeName = !DisguiseUtilities.getAddedByPlugins().contains(name);
} }
WrappedGameProfile gameProfile = playerDisguise.getGameProfile(); WrappedGameProfile gameProfile = playerDisguise.getGameProfile();
if (removeName) { if (removeName) {
DisguiseUtilities.getAddedByPlugins().remove(name); DisguiseUtilities.getAddedByPlugins().remove(name);
} }
//Write spawn packet in order //Write spawn packet in order
//Id spawnPackets[0].getIntegers().write(0, entityId); //Id
//UUID spawnPackets[0].getSpecificModifier(UUID.class).write(0, gameProfile.getUUID()); //UUID
//x
//y
//z
//pitch
//yaw
spawnPackets[0].getIntegers().write(0, disguisedEntity.getEntityId());
spawnPackets[0].getSpecificModifier(UUID.class).write(0, gameProfile.getUUID());
StructureModifier<Double> doubleMods = spawnPackets[0].getDoubles(); StructureModifier<Double> doubleMods = spawnPackets[0].getDoubles();
doubleMods.write(0, Math.floor(loc.getX() * 32)); doubleMods.write(0, Math.floor(loc.getX() * 32)); //x
doubleMods.write(1, Math.floor(loc.getY() * 32)); doubleMods.write(1, Math.floor(loc.getY() * 32)); //y
doubleMods.write(2, Math.floor(loc.getZ() * 32)); doubleMods.write(2, Math.floor(loc.getZ() * 32)); //z
StructureModifier<Byte> byteMods = spawnPackets[0].getBytes(); StructureModifier<Byte> byteMods = spawnPackets[0].getBytes();
byteMods.write(0, pitch); byteMods.write(0, yaw); //yaw
byteMods.write(1, yaw); byteMods.write(1, pitch); //pitch
spawnPackets[0].getDataWatcherModifier().write(0, createDataWatcher(WrappedDataWatcher.getEntityWatcher(disguisedEntity), disguise.getWatcher())); //watcher, duh
spawnPackets[0].getDataWatcherModifier().write(0, createDataWatcher(WrappedDataWatcher.getEntityWatcher(disguisedEntity), disguise.getWatcher()));
if (DisguiseConfig.isBedPacketsEnabled() && ((PlayerWatcher) disguise.getWatcher()).isSleeping()) { if (DisguiseConfig.isBedPacketsEnabled() && ((PlayerWatcher) disguise.getWatcher()).isSleeping()) {
PacketContainer[] newPackets = new PacketContainer[spawnPackets.length + 1]; PacketContainer[] newPackets = new PacketContainer[spawnPackets.length + 1];
@ -268,42 +266,40 @@ public class PacketsManager {
PacketContainer delayedPacket = spawnPackets[0].shallowClone(); PacketContainer delayedPacket = spawnPackets[0].shallowClone();
delayedPacket.getModifier().write(0, ReflectionManager.getEnumPlayerInfoAction(4)); delayedPacket.getModifier().write(0, ReflectionManager.getEnumPlayerInfoAction(4));
delayedPackets = new PacketContainer[]{delayedPacket}; delayedPackets = new PacketContainer[]{delayedPacket};
} else if (disguise.getType().isMob() || disguise.getType() == DisguiseType.ARMOR_STAND) { } else if (disguise.getType().isMob() || disguise.getType() == DisguiseType.ARMOR_STAND) {
Class<? extends Entity> entityClass = disguise.getType().getEntityClass(); int entityId = disguisedEntity.getEntityId();
int entityId = disguise.getType().getEntityId(); LivingEntity entity = (LivingEntity) disguisedEntity.getWorld().spawnEntity(loc, disguise.getType().getEntityType());
Entity entity = Bukkit.getWorlds().get(0).spawn(disguise.getEntity().getLocation(), entityClass);
entity.setVelocity(disguisedEntity.getVelocity()); entity.setVelocity(disguisedEntity.getVelocity());
if (disguise.getType() == DisguiseType.SLIME || disguise.getType() == DisguiseType.MAGMA_CUBE) { if (disguise.getType() == DisguiseType.SLIME || disguise.getType() == DisguiseType.MAGMA_CUBE) {
((Slime)entity).setSize(((SlimeWatcher)disguise.getWatcher()).getSize()); ((Slime) entity).setSize(((SlimeWatcher) disguise.getWatcher()).getSize());
} }
Object nms = ReflectionManager.getNmsEntity(entity); Object nms = ReflectionManager.getNmsEntity(entity);
PacketContainer packet = ProtocolLibrary.getProtocolManager().createPacketConstructor(Server.SPAWN_ENTITY_LIVING, nms).createPacket(nms); PacketContainer packet = ProtocolLibrary.getProtocolManager().createPacketConstructor(Server.SPAWN_ENTITY_LIVING, nms).createPacket(nms).deepClone();
spawnPackets[0] = packet; spawnPackets[0] = packet;
spawnPackets[0].getIntegers().write(0, entityId); spawnPackets[0].getIntegers().write(0, entityId);
spawnPackets[0].getDataWatcherModifier().write(0, createDataWatcher(WrappedDataWatcher.getEntityWatcher(disguisedEntity), disguise.getWatcher())); spawnPackets[0].getDataWatcherModifier().write(0, createDataWatcher(WrappedDataWatcher.getEntityWatcher(disguisedEntity), disguise.getWatcher()));
entity.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 1, Integer.MAX_VALUE, true, false));
entity.remove(); entity.remove();
//You know, as cheap as this may seem, this is pretty damn effective //You know, as cheap as this may seem, this is pretty damn effective
} else if (disguise.getType().isMisc()) { } else if (disguise.getType().isMisc()) {
//TODO: Fix miscs //TODO: Fix miscs
Class<? extends Entity> entityClass = disguise.getType().getEntityClass(); int id = disguise.getType().getTypeId();
Entity entity = Bukkit.getWorlds().get(0).spawn(disguise.getEntity().getLocation().add(0, 0.5, 0), entityClass);
entity.setVelocity(disguisedEntity.getVelocity());
int entityId = disguise.getType().getEntityId();
int typeId = disguise.getType().getTypeId();
int data = ((MiscDisguise) disguise).getData(); int data = ((MiscDisguise) disguise).getData();
if (disguise.getType() == DisguiseType.FALLING_BLOCK) { if (disguise.getType() == DisguiseType.FALLING_BLOCK) {
data = (((MiscDisguise) disguise).getId() | data << 16); data = (((MiscDisguise) disguise).getId() + data << 12);
} else if (disguise.getType() == DisguiseType.FISHING_HOOK && data == 0) { } else if (disguise.getType() == DisguiseType.FISHING_HOOK && data == 0) {
// If the MiscDisguise data isn't set. Then no entity id was provided, so default to the owners entity id // If the MiscDisguise data isn't set. Then no entity id was provided, so default to the owners entity id
data = disguisedEntity.getEntityId(); data = disguisedEntity.getEntityId();
} else if (disguise.getType() == DisguiseType.ITEM_FRAME) { } else if (disguise.getType() == DisguiseType.ITEM_FRAME) {
data = ((((int) loc.getYaw() % 360) + 720 + 45) / 90) % 4; data = ((((int) loc.getYaw() % 360) + 720 + 45) / 90) % 4;
} }
Object nms = ReflectionManager.getNmsEntity(entity); Object nmsEntity = ReflectionManager.getNmsEntity(disguisedEntity);
spawnPackets[0] = ProtocolLibrary.getProtocolManager().createPacketConstructor(Server.SPAWN_ENTITY, nms, typeId, data) spawnPackets[0] = ProtocolLibrary.getProtocolManager()
.createPacket(nms, typeId, data); .createPacketConstructor(PacketType.Play.Server.SPAWN_ENTITY, nmsEntity, id, data)
spawnPackets[0].getIntegers().write(0, entityId); .createPacket(nmsEntity, id, data);
spawnPackets[0].getModifier().write(2, (int) Math.floor(loc.getY() * 32D));
spawnPackets[0].getModifier().write(7, pitch);
spawnPackets[0].getModifier().write(8, yaw);
if (disguise.getType() == DisguiseType.ITEM_FRAME) { if (disguise.getType() == DisguiseType.ITEM_FRAME) {
if (data % 2 == 0) { if (data % 2 == 0) {
spawnPackets[0].getModifier().write(3, (int) Math.floor((loc.getZ() + (data == 0 ? -1 : 1)) * 32D)); spawnPackets[0].getModifier().write(3, (int) Math.floor((loc.getZ() + (data == 0 ? -1 : 1)) * 32D));
@ -311,7 +307,6 @@ public class PacketsManager {
spawnPackets[0].getModifier().write(1, (int) Math.floor((loc.getX() + (data == 3 ? -1 : 1)) * 32D)); spawnPackets[0].getModifier().write(1, (int) Math.floor((loc.getX() + (data == 3 ? -1 : 1)) * 32D));
} }
} }
entity.remove();
} }
if (spawnPackets[1] == null || disguise.isPlayerDisguise()) { if (spawnPackets[1] == null || disguise.isPlayerDisguise()) {
int entry = spawnPackets[1] == null ? 1 : 0; int entry = spawnPackets[1] == null ? 1 : 0;
@ -501,233 +496,234 @@ public class PacketsManager {
*/ */
public static void init(LibsDisguises plugin) { public static void init(LibsDisguises plugin) {
libsDisguises = plugin; libsDisguises = plugin;
soundsListener = new PacketAdapter(libsDisguises, ListenerPriority.NORMAL, Server.NAMED_SOUND_EFFECT, soundsListener = new PacketAdapter(libsDisguises, ListenerPriority.NORMAL, Server.NAMED_SOUND_EFFECT, Server.ENTITY_STATUS) {
Server.ENTITY_STATUS) {
@Override @Override
public void onPacketSending(PacketEvent event) { public void onPacketSending(PacketEvent event) {
//TODO: Fix this later once ProtocolLib's deepClone for NamedSoundEffect and EntityStatus is fixed if (event.isCancelled()) {
// if (event.isCancelled()) { return;
// return; }
// } event.setPacket(event.getPacket().deepClone());
// event.setPacket(event.getPacket().deepClone()); StructureModifier<Object> mods = event.getPacket().getModifier();
// StructureModifier<Object> mods = event.getPacket().getModifier(); Player observer = event.getPlayer();
// Player observer = event.getPlayer(); if (event.getPacketType() == Server.NAMED_SOUND_EFFECT) {
// if (event.getPacketType() == Server.NAMED_SOUND_EFFECT) { if (event.isAsync()) {
//// if (event.isAsync()) { return;
//// return; }
//// } Object soundEffect = mods.read(0);
//// Object soundEffect = mods.read(0); SoundType soundType = null;
//// SoundType soundType = null; Location soundLoc = new Location(observer.getWorld(), ((Integer) mods.read(2)) / 8D,
//// Location soundLoc = new Location(observer.getWorld(), ((Integer) mods.read(2)) / 8D, ((Integer) mods.read(3)) / 8D, ((Integer) mods.read(4)) / 8D);
//// ((Integer) mods.read(3)) / 8D, ((Integer) mods.read(4)) / 8D); Entity disguisedEntity = null;
//// Entity disguisedEntity = null; DisguiseSound entitySound = null;
//// DisguiseSound entitySound = null; Disguise disguise = null;
//// Disguise disguise = null; Entity[] entities = soundLoc.getChunk().getEntities();
//// Entity[] entities = soundLoc.getChunk().getEntities(); for (Entity entity : entities) {
//// for (Entity entity : entities) { Disguise entityDisguise = DisguiseAPI.getDisguise(observer, entity);
//// Disguise entityDisguise = DisguiseAPI.getDisguise(observer, entity); if (entityDisguise != null) {
//// if (entityDisguise != null) { Location loc = entity.getLocation();
//// Location loc = entity.getLocation(); loc = new Location(observer.getWorld(), ((int) (loc.getX() * 8)) / 8D, ((int) (loc.getY() * 8)) / 8D,
//// loc = new Location(observer.getWorld(), ((int) (loc.getX() * 8)) / 8D, ((int) (loc.getY() * 8)) / 8D, ((int) (loc.getZ() * 8)) / 8D);
//// ((int) (loc.getZ() * 8)) / 8D); if (loc.equals(soundLoc)) {
//// if (loc.equals(soundLoc)) { entitySound = DisguiseSound.getType(entity.getType().name());
//// entitySound = DisguiseSound.getType(entity.getType().name()); if (entitySound != null) {
//// if (entitySound != null) { Object obj = null;
//// Object obj = null; if (entity instanceof LivingEntity) {
//// if (entity instanceof LivingEntity) { try {
//// try { // Use reflection so that this works for either int or double methods
//// // Use reflection so that this works for either int or double methods obj = LivingEntity.class.getMethod("getHealth").invoke(entity);
//// obj = LivingEntity.class.getMethod("getHealth").invoke(entity); if (obj instanceof Double ? (Double) obj == 0 : (Integer) obj == 0) {
//// if (obj instanceof Double ? (Double) obj == 0 : (Integer) obj == 0) { soundType = SoundType.DEATH;
//// soundType = SoundType.DEATH; } else {
//// } else { obj = null;
//// obj = null; }
//// } } catch (Exception e) {
//// } catch (Exception e) { e.printStackTrace();
//// e.printStackTrace(); }
//// } }
//// } if (obj == null) {
//// if (obj == null) { boolean hasInvun = false;
//// boolean hasInvun = false; Object nmsEntity = ReflectionManager.getNmsEntity(entity);
//// Object nmsEntity = ReflectionManager.getNmsEntity(entity); try {
//// try { if (entity instanceof LivingEntity) {
//// if (entity instanceof LivingEntity) { hasInvun = ReflectionManager.getNmsField("Entity", "noDamageTicks").getInt(
//// hasInvun = ReflectionManager.getNmsField("Entity", "noDamageTicks").getInt( nmsEntity) == ReflectionManager.getNmsField("EntityLiving",
//// nmsEntity) == ReflectionManager.getNmsField("EntityLiving", "maxNoDamageTicks").getInt(nmsEntity);
//// "maxNoDamageTicks").getInt(nmsEntity); } else {
//// } else { Class clazz = ReflectionManager.getNmsClass("DamageSource");
//// Class clazz = ReflectionManager.getNmsClass("DamageSource"); hasInvun = (Boolean) ReflectionManager.getNmsMethod("Entity", "isInvulnerable", clazz)
//// hasInvun = (Boolean) ReflectionManager.getNmsMethod("Entity", "isInvulnerable", clazz) .invoke(nmsEntity, ReflectionManager.getNmsField(clazz, "GENERIC"));
//// .invoke(nmsEntity, ReflectionManager.getNmsField(clazz, "GENERIC")); }
//// } } catch (Exception ex) {
//// } catch (Exception ex) { ex.printStackTrace();
//// ex.printStackTrace(); }
//// } soundType = entitySound.getType(ReflectionManager.convertSoundEffectToString(soundEffect), !hasInvun);
//// soundType = entitySound.getType(ReflectionManager.convertSoundEffectToString(soundEffect), !hasInvun); }
//// } if (soundType != null) {
//// if (soundType != null) { disguise = entityDisguise;
//// disguise = entityDisguise; disguisedEntity = entity;
//// disguisedEntity = entity; break;
//// break; }
//// } }
//// } }
//// } }
//// } }
//// } if (disguise != null) {
//// if (disguise != null) { if (disguise.isSelfDisguiseSoundsReplaced() || disguisedEntity != event.getPlayer()) {
//// if (disguise.isSelfDisguiseSoundsReplaced() || disguisedEntity != event.getPlayer()) { if (disguise.isSoundsReplaced()) {
//// if (disguise.isSoundsReplaced()) { String sound = null;
//// String sound = null; DisguiseSound dSound = DisguiseSound.getType(disguise.getType().name());
//// DisguiseSound dSound = DisguiseSound.getType(disguise.getType().name()); if (dSound != null)
//// if (dSound != null) sound = dSound.getSound(soundType);
//// sound = dSound.getSound(soundType);
//// if (sound == null) {
//// if (sound == null) { event.setCancelled(true);
//// event.setCancelled(true); } else {
//// } else { if (sound.equals("step.grass")) {
//// if (sound.equals("step.grass")) { try {
//// try { int typeId = soundLoc.getWorld().getBlockTypeIdAt(soundLoc.getBlockX(),
//// int typeId = soundLoc.getWorld().getBlockTypeIdAt(soundLoc.getBlockX(), soundLoc.getBlockY() - 1, soundLoc.getBlockZ());
//// soundLoc.getBlockY() - 1, soundLoc.getBlockZ()); Object block = ReflectionManager.getNmsMethod("RegistryMaterials", "a", int.class)
//// Object block = ReflectionManager.getNmsMethod("RegistryMaterials", "a", int.class) .invoke(ReflectionManager.getNmsField("Block", "REGISTRY").get(null),
//// .invoke(ReflectionManager.getNmsField("Block", "REGISTRY").get(null), typeId);
//// typeId); if (block != null) {
//// if (block != null) { Object step = ReflectionManager.getNmsField("Block", "stepSound").get(block);
//// Object step = ReflectionManager.getNmsField("Block", "stepSound").get(block); mods.write(0, ReflectionManager.getNmsMethod(step.getClass(), "getStepSound").invoke(step));
//// mods.write(0, ReflectionManager.getNmsMethod(step.getClass(), "getStepSound").invoke(step)); }
//// } } catch (Exception ex) {
//// } catch (Exception ex) { ex.printStackTrace();
//// ex.printStackTrace(); }
//// } // There is no else statement. Because seriously. This should never be null. Unless
//// // There is no else statement. Because seriously. This should never be null. Unless // someone is
//// // someone is // sending fake sounds. In which case. Why cancel it.
//// // sending fake sounds. In which case. Why cancel it. } else {
//// } else { mods.write(0, ReflectionManager.getCraftSoundEffect(sound));
//// mods.write(0, ReflectionManager.getCraftSoundEffect(sound)); // Time to change the pitch and volume
//// // Time to change the pitch and volume if (soundType == SoundType.HURT || soundType == SoundType.DEATH
//// if (soundType == SoundType.HURT || soundType == SoundType.DEATH || soundType == SoundType.IDLE) {
//// || soundType == SoundType.IDLE) { // If the volume is the default
//// // If the volume is the default if (mods.read(5).equals(entitySound.getDamageAndIdleSoundVolume())) {
//// if (mods.read(5).equals(entitySound.getDamageAndIdleSoundVolume())) { mods.write(5, dSound.getDamageAndIdleSoundVolume());
//// mods.write(5, dSound.getDamageAndIdleSoundVolume()); }
//// } // Here I assume its the default pitch as I can't calculate if its real.
//// // Here I assume its the default pitch as I can't calculate if its real. if (disguise instanceof MobDisguise && disguisedEntity instanceof LivingEntity
//// if (disguise instanceof MobDisguise && disguisedEntity instanceof LivingEntity && ((MobDisguise) disguise).doesDisguiseAge()) {
//// && ((MobDisguise) disguise).doesDisguiseAge()) { boolean baby = false;
//// boolean baby = false; if (disguisedEntity instanceof Zombie) {
//// if (disguisedEntity instanceof Zombie) { baby = ((Zombie) disguisedEntity).isBaby();
//// baby = ((Zombie) disguisedEntity).isBaby(); } else if (disguisedEntity instanceof Ageable) {
//// } else if (disguisedEntity instanceof Ageable) { baby = !((Ageable) disguisedEntity).isAdult();
//// baby = !((Ageable) disguisedEntity).isAdult(); }
//// } if (((MobDisguise) disguise).isAdult() == baby) {
//// if (((MobDisguise) disguise).isAdult() == baby) {
//// float pitch = (Integer) mods.read(5);
//// float pitch = (Integer) mods.read(5); if (baby) {
//// if (baby) { // If the pitch is not the expected
//// // If the pitch is not the expected if (pitch > 97 || pitch < 111)
//// if (pitch > 97 || pitch < 111) return;
//// return; pitch = (new Random().nextFloat() - new Random().nextFloat()) * 0.2F + 1.5F;
//// pitch = (new Random().nextFloat() - new Random().nextFloat()) * 0.2F + 1.5F; // Min = 1.5
//// // Min = 1.5 // Cap = 97.5
//// // Cap = 97.5 // Max = 1.7
//// // Max = 1.7 // Cap = 110.5
//// // Cap = 110.5 } else {
//// } else { // If the pitch is not the expected
//// // If the pitch is not the expected if (pitch >= 63 || pitch <= 76)
//// if (pitch >= 63 || pitch <= 76) return;
//// return; pitch = (new Random().nextFloat() - new Random().nextFloat()) * 0.2F + 1.0F;
//// pitch = (new Random().nextFloat() - new Random().nextFloat()) * 0.2F + 1.0F; // Min = 1
//// // Min = 1 // Cap = 63
//// // Cap = 63 // Max = 1.2
//// // Max = 1.2 // Cap = 75.6
//// // Cap = 75.6 }
//// } pitch *= 63;
//// pitch *= 63; if (pitch < 0)
//// if (pitch < 0) pitch = 0;
//// pitch = 0; if (pitch > 255)
//// if (pitch > 255) pitch = 255;
//// pitch = 255; mods.write(6, (int) pitch);
//// mods.write(6, (int) pitch); }
//// } }
//// } }
//// } }
//// } }
//// } }
//// } }
//// } }
//// } } else if (event.getPacketType() == Server.ENTITY_STATUS) {
// } else if (event.getPacketType() == Server.ENTITY_STATUS) { if ((byte) mods.read(1) == 2) {
// if ((byte) mods.read(1) == 2) { // 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 = DisguiseAPI.getDisguise(observer, entity);
// Disguise disguise = DisguiseAPI.getDisguise(observer, entity); if (disguise != null && !disguise.getType().isPlayer()
// if (disguise != null && !disguise.getType().isPlayer() && (disguise.isSelfDisguiseSoundsReplaced() || entity != event.getPlayer())) {
// && (disguise.isSelfDisguiseSoundsReplaced() || entity != event.getPlayer())) { DisguiseSound disSound = DisguiseSound.getType(entity.getType().name());
// DisguiseSound disSound = DisguiseSound.getType(entity.getType().name()); if (disSound == null)
// if (disSound == null) return;
// return; SoundType soundType = null;
// SoundType soundType = null; Object obj = null;
// Object obj = null; if (entity instanceof LivingEntity) {
// if (entity instanceof LivingEntity) { try {
// try { obj = LivingEntity.class.getMethod("getHealth").invoke(entity);
// obj = LivingEntity.class.getMethod("getHealth").invoke(entity); if (obj instanceof Double ? (Double) obj == 0 : (Integer) obj == 0) {
// if (obj instanceof Double ? (Double) obj == 0 : (Integer) obj == 0) { soundType = SoundType.DEATH;
// soundType = SoundType.DEATH; } else {
// } else { obj = null;
// obj = null; }
// } } catch (Exception e) {
// } catch (Exception e) { e.printStackTrace();
// e.printStackTrace(); }
// } }
// } if (obj == null) {
// if (obj == null) { soundType = SoundType.HURT;
// soundType = SoundType.HURT; }
// } if (disSound.getSound(soundType) == null
// if (disSound.getSound(soundType) == null || (disguise.isSelfDisguiseSoundsReplaced() && entity == event.getPlayer())) {
// || (disguise.isSelfDisguiseSoundsReplaced() && entity == event.getPlayer())) { if (disguise.isSelfDisguiseSoundsReplaced() && entity == event.getPlayer()) {
// if (disguise.isSelfDisguiseSoundsReplaced() && entity == event.getPlayer()) { cancelSound = !cancelSound;
// cancelSound = !cancelSound; if (cancelSound)
// if (cancelSound) return;
// return; }
// } 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); if (sound != null) {
// if (sound != null) { Location loc = entity.getLocation();
// Location loc = entity.getLocation(); PacketContainer packet = new PacketContainer(Server.NAMED_SOUND_EFFECT);
// PacketContainer packet = new PacketContainer(Server.NAMED_SOUND_EFFECT); mods = packet.getModifier();
// mods = packet.getModifier(); Object craftSoundEffect = ReflectionManager.getCraftSoundEffect(sound);
// mods.write(0, sound); mods.write(0, craftSoundEffect);
// mods.write(1, (int) (loc.getX() * 8D)); mods.write(1, ReflectionManager.getSoundCategory("master")); //Meh
// mods.write(2, (int) (loc.getY() * 8D)); mods.write(2, (int) (loc.getX() * 8D));
// mods.write(3, (int) (loc.getZ() * 8D)); mods.write(3, (int) (loc.getY() * 8D));
// mods.write(4, disSound.getDamageAndIdleSoundVolume()); mods.write(4, (int) (loc.getZ() * 8D));
// float pitch; mods.write(5, disSound.getDamageAndIdleSoundVolume());
// if (disguise instanceof MobDisguise && !((MobDisguise) disguise).isAdult()) { float pitch;
// pitch = (new Random().nextFloat() - new Random().nextFloat()) * 0.2F + 1.5F; if (disguise instanceof MobDisguise && !((MobDisguise) disguise).isAdult()) {
// } else pitch = (new Random().nextFloat() - new Random().nextFloat()) * 0.2F + 1.5F;
// pitch = (new Random().nextFloat() - new Random().nextFloat()) * 0.2F + 1.0F; } else
// if (disguise.getType() == DisguiseType.BAT) pitch = (new Random().nextFloat() - new Random().nextFloat()) * 0.2F + 1.0F;
// pitch *= 95F; if (disguise.getType() == DisguiseType.BAT)
// pitch *= 63; pitch *= 95F;
// if (pitch < 0) pitch *= 63;
// pitch = 0; if (pitch < 0)
// if (pitch > 255) pitch = 0;
// pitch = 255; if (pitch > 255)
// mods.write(5, (int) pitch); pitch = 255;
// try { mods.write(6, (int) pitch);
// ProtocolLibrary.getProtocolManager().sendServerPacket(observer, packet); try {
// } catch (InvocationTargetException e) { ProtocolLibrary.getProtocolManager().sendServerPacket(observer, packet);
// e.printStackTrace(); } catch (InvocationTargetException e) {
// } e.printStackTrace();
// } }
// } }
// } }
// } }
// } }
// } }
}
} }
}; };
//Self disguise (/vsd) listener
viewDisguisesListener = new PacketAdapter(libsDisguises, ListenerPriority.HIGH, viewDisguisesListener = new PacketAdapter(libsDisguises, ListenerPriority.HIGH,
Server.NAMED_ENTITY_SPAWN, Server.ATTACH_ENTITY, Server.NAMED_ENTITY_SPAWN, Server.ATTACH_ENTITY,
Server.REL_ENTITY_MOVE, Server.ENTITY_MOVE_LOOK, Server.REL_ENTITY_MOVE, Server.ENTITY_MOVE_LOOK,
@ -841,8 +837,7 @@ public class PacketsManager {
&& event.getPlayer().getVehicle() == null) { && event.getPlayer().getVehicle() == null) {
Disguise disguise = DisguiseAPI.getDisguise(event.getPlayer(), event.getPlayer()); Disguise disguise = DisguiseAPI.getDisguise(event.getPlayer(), event.getPlayer());
// If player is disguised, views self disguises and has a inventory modifier // If player is disguised, views self disguises and has a inventory modifier
if (disguise != null && disguise.isSelfDisguiseVisible() if (disguise != null && disguise.isSelfDisguiseVisible() && (disguise.isHidingArmorFromSelf() || disguise.isHidingHeldItemFromSelf())) {
&& (disguise.isHidingArmorFromSelf() || disguise.isHidingHeldItemFromSelf())) {
// If they are in creative and clicked on a slot // If they are in creative and clicked on a slot
if (event.getPacketType() == PacketType.Play.Client.SET_CREATIVE_SLOT) { if (event.getPacketType() == PacketType.Play.Client.SET_CREATIVE_SLOT) {
int slot = event.getPacket().getIntegers().read(0); int slot = event.getPacket().getIntegers().read(0);
@ -926,7 +921,8 @@ public class PacketsManager {
} else if (event.getPacketType() == PacketType.Play.Client.WINDOW_CLICK) { } else if (event.getPacketType() == PacketType.Play.Client.WINDOW_CLICK) {
int slot = event.getPacket().getIntegers().read(1); int slot = event.getPacket().getIntegers().read(1);
org.bukkit.inventory.ItemStack clickedItem; org.bukkit.inventory.ItemStack clickedItem;
if (event.getPacket().getShorts().read(3) == 1) { //TODO: Check this to make sure it is accurate
if (event.getPacket().getShorts().read(0) == 1) {
// Its a shift click // Its a shift click
clickedItem = event.getPacket().getItemModifier().read(0); clickedItem = event.getPacket().getItemModifier().read(0);
if (clickedItem != null && clickedItem.getType() != Material.AIR) { if (clickedItem != null && clickedItem.getType() != Material.AIR) {
@ -1163,6 +1159,7 @@ public class PacketsManager {
if (DisguiseConfig.isEntityStatusPacketsEnabled()) { if (DisguiseConfig.isEntityStatusPacketsEnabled()) {
packetsToListen.add(Server.ENTITY_STATUS); packetsToListen.add(Server.ENTITY_STATUS);
} }
mainListener = new PacketAdapter(libsDisguises, ListenerPriority.HIGH, packetsToListen) { mainListener = new PacketAdapter(libsDisguises, ListenerPriority.HIGH, packetsToListen) {
@Override @Override
public void onPacketSending(PacketEvent event) { public void onPacketSending(PacketEvent event) {
@ -1171,8 +1168,7 @@ public class PacketsManager {
final Player observer = event.getPlayer(); final Player observer = event.getPlayer();
// First get the entity, the one sending this packet // First get the entity, the one sending this packet
StructureModifier<Entity> entityModifer = event.getPacket().getEntityModifier(observer.getWorld()); StructureModifier<Entity> entityModifer = event.getPacket().getEntityModifier(observer.getWorld());
org.bukkit.entity.Entity entity = entityModifer org.bukkit.entity.Entity entity = entityModifer.read((Server.COLLECT == event.getPacketType() ? 1 : 0));
.read((Server.COLLECT == event.getPacketType() ? 1 : 0));
// If the entity is the same as the sender. Don't disguise! // If the entity is the same as the sender. Don't disguise!
// Prevents problems and there is no advantage to be gained. // Prevents problems and there is no advantage to be gained.
if (entity == observer) if (entity == observer)
@ -1315,7 +1311,10 @@ public class PacketsManager {
.getWatcher()).isSleeping())))) { .getWatcher()).isSleeping())))) {
packets = new PacketContainer[0]; packets = new PacketContainer[0];
} }
} else if (sentPacket.getType() == Server.COLLECT) { }
//Else if the disguise is collecting stuff
else if (sentPacket.getType() == Server.COLLECT) {
if (disguise.getType().isMisc()) { if (disguise.getType().isMisc()) {
packets = new PacketContainer[0]; packets = new PacketContainer[0];
} else if (DisguiseConfig.isBedPacketsEnabled() && disguise.getType().isPlayer() } else if (DisguiseConfig.isBedPacketsEnabled() && disguise.getType().isPlayer()
@ -1334,6 +1333,7 @@ public class PacketsManager {
|| sentPacket.getType() == Server.ENTITY_TELEPORT || sentPacket.getType() == Server.ENTITY_TELEPORT
|| sentPacket.getType() == Server.REL_ENTITY_MOVE) { || sentPacket.getType() == Server.REL_ENTITY_MOVE) {
if (disguise.getType() == DisguiseType.RABBIT && (sentPacket.getType() == Server.REL_ENTITY_MOVE || sentPacket.getType() == Server.ENTITY_MOVE_LOOK)) { if (disguise.getType() == DisguiseType.RABBIT && (sentPacket.getType() == Server.REL_ENTITY_MOVE || sentPacket.getType() == Server.ENTITY_MOVE_LOOK)) {
//Rabbit robbing...
if (entity.getMetadata("LibsRabbitHop").isEmpty() if (entity.getMetadata("LibsRabbitHop").isEmpty()
|| System.currentTimeMillis() - entity.getMetadata("LibsRabbitHop").get(0).asLong() < 100 || System.currentTimeMillis() - entity.getMetadata("LibsRabbitHop").get(0).asLong() < 100
|| System.currentTimeMillis() - entity.getMetadata("LibsRabbitHop").get(0).asLong() > 500) { || System.currentTimeMillis() - entity.getMetadata("LibsRabbitHop").get(0).asLong() > 500) {
@ -1349,17 +1349,16 @@ public class PacketsManager {
} }
} }
//Stop wither skulls from looking
if (sentPacket.getType() == Server.ENTITY_LOOK && disguise.getType() == DisguiseType.WITHER_SKULL) { if (sentPacket.getType() == Server.ENTITY_LOOK && disguise.getType() == DisguiseType.WITHER_SKULL) {
packets = new PacketContainer[0]; packets = new PacketContainer[0];
} else if (sentPacket.getType() != Server.REL_ENTITY_MOVE) { } else if (sentPacket.getType() != Server.REL_ENTITY_MOVE) {
packets[0] = sentPacket.shallowClone(); packets[0] = sentPacket.shallowClone();
StructureModifier<Byte> bytes = packets[0].getBytes(); StructureModifier<Byte> bytes = packets[0].getBytes();
byte yawValue = bytes.read(1); byte yawValue = bytes.read(1);
bytes.write(1, getYaw(disguise.getType(), entity.getType(), yawValue)); bytes.write(1, getYaw(disguise.getType(), entity.getType(), yawValue));
byte pitchValue = bytes.read(0); byte pitchValue = bytes.read(0);
bytes.write(0, getPitch(disguise.getType(), DisguiseType.getType(entity.getType()), pitchValue)); bytes.write(0, getPitch(disguise.getType(), DisguiseType.getType(entity.getType()), pitchValue));
if (sentPacket.getType() == Server.ENTITY_TELEPORT && disguise.getType() == DisguiseType.ITEM_FRAME) { if (sentPacket.getType() == Server.ENTITY_TELEPORT && disguise.getType() == DisguiseType.ITEM_FRAME) {
StructureModifier<Double> doubles = packets[0].getDoubles(); StructureModifier<Double> doubles = packets[0].getDoubles();
Location loc = entity.getLocation(); Location loc = entity.getLocation();
@ -1378,7 +1377,10 @@ public class PacketsManager {
} }
} }
} }
} else if (sentPacket.getType() == Server.ENTITY_EQUIPMENT) { }
//Else if the disguise is updating equipment
else if (sentPacket.getType() == Server.ENTITY_EQUIPMENT) {
EquipmentSlot slot = ReflectionManager.createEquipmentSlot(packets[0].getModifier().read(1)); EquipmentSlot slot = ReflectionManager.createEquipmentSlot(packets[0].getModifier().read(1));
org.bukkit.inventory.ItemStack itemStack = disguise.getWatcher().getItemStack(slot); org.bukkit.inventory.ItemStack itemStack = disguise.getWatcher().getItemStack(slot);
if (itemStack != null) { if (itemStack != null) {
@ -1420,15 +1422,24 @@ public class PacketsManager {
// it. // it.
} }
} }
} else if (sentPacket.getType() == Server.BED) { }
//If the entity is going into a bed, stop everything but players from doing this
else if (sentPacket.getType() == Server.BED) {
if (!disguise.getType().isPlayer()) { if (!disguise.getType().isPlayer()) {
packets = new PacketContainer[0]; packets = new PacketContainer[0];
} }
} else if (sentPacket.getType() == Server.ENTITY_STATUS) { }
//If the entity is updating their Facebook status, stop them from showing death
else if (sentPacket.getType() == Server.ENTITY_STATUS) {
if (packets[0].getBytes().read(0) == (byte) 3) { if (packets[0].getBytes().read(0) == (byte) 3) {
packets = new PacketContainer[0]; packets = new PacketContainer[0];
} }
} else if (sentPacket.getType() == Server.ENTITY_HEAD_ROTATION) { }
//If the entity is rotating his head
else if (sentPacket.getType() == Server.ENTITY_HEAD_ROTATION) {
if (disguise.getType().isPlayer() && entity.getType() != EntityType.PLAYER) { if (disguise.getType().isPlayer() && entity.getType() != EntityType.PLAYER) {
Location loc = entity.getLocation(); Location loc = entity.getLocation();
byte pitch = getPitch(disguise.getType(), DisguiseType.getType(entity.getType()), byte pitch = getPitch(disguise.getType(), DisguiseType.getType(entity.getType()),
@ -1444,7 +1455,10 @@ public class PacketsManager {
look.getBytes().write(4, pitch); look.getBytes().write(4, pitch);
packets = new PacketContainer[]{look, rotation}; packets = new PacketContainer[]{look, rotation};
} }
} else { }
//Whatever
else {
packets = null; packets = null;
} }

View File

@ -39,6 +39,7 @@ public class ReflectionManager {
private static final Field pingField; private static final Field pingField;
private static Map<Class<?>, String> primitiveTypes; private static Map<Class<?>, String> primitiveTypes;
private static final Field trackerField; private static final Field trackerField;
public static final Field entityCountField;
/* /*
* This portion of code is originally Copyright (C) 2014-2014 Kane York. * This portion of code is originally Copyright (C) 2014-2014 Kane York.
@ -79,6 +80,8 @@ public class ReflectionManager {
boundingBoxConstructor = getNmsConstructor("AxisAlignedBB", double.class, double.class, double.class, boundingBoxConstructor = getNmsConstructor("AxisAlignedBB", double.class, double.class, double.class,
double.class, double.class, double.class); double.class, double.class, double.class);
setBoundingBoxMethod = getNmsMethod("Entity", "a", getNmsClass("AxisAlignedBB")); setBoundingBoxMethod = getNmsMethod("Entity", "a", getNmsClass("AxisAlignedBB"));
entityCountField = getNmsField("Entity", "entityCount");
entityCountField.setAccessible(true);
} }
public static Object createEntityInstance(String entityName) { public static Object createEntityInstance(String entityName) {
@ -109,20 +112,30 @@ public class ReflectionManager {
return null; return null;
} }
public static Object createMobEffect(int id, int duration, int amplification, boolean ambient, boolean particles) { public static Object getMobEffectList(int id) {
Method nmsMethod = getNmsMethod("MobEffectList", "fromId", Integer.class);
try { try {
return getNmsClass("MobEffect").getDeclaredConstructor(int.class, int.class, int.class, boolean.class, boolean.class) return nmsMethod.invoke(null, id);
.newInstance(id, duration, amplification, ambient, particles); } catch (IllegalAccessException | InvocationTargetException e) {
} catch (Exception e) { e.printStackTrace();
e.printStackTrace(System.out); return null;
} }
return null;
} }
public static Object createMobEffect(PotionEffect effect) { public static Object createMobEffect(PotionEffect effect) {
return createMobEffect(effect.getType().getId(), effect.getDuration(), effect.getAmplifier(), effect.isAmbient(), effect.hasParticles()); return createMobEffect(effect.getType().getId(), effect.getDuration(), effect.getAmplifier(), effect.isAmbient(), effect.hasParticles());
} }
public static Object createMobEffect(int id, int duration, int amplification, boolean ambient, boolean particles) {
try {
return getNmsClass("MobEffect").getDeclaredConstructor(getNmsClass("MobEffectList"), Integer.TYPE, Integer.TYPE, Boolean.TYPE, Boolean.TYPE)
.newInstance(getMobEffectList(id), duration, amplification, ambient, particles);
} catch (Exception e) {
e.printStackTrace(System.out);
}
return null;
}
private static String dir2fqn(String s) { private static String dir2fqn(String s) {
return s.replaceAll("/", "."); return s.replaceAll("/", ".");
} }
@ -283,7 +296,6 @@ public class ReflectionManager {
} }
public static WrappedGameProfile getGameProfileWithThisSkin(UUID uuid, String playerName, WrappedGameProfile profileWithSkin) { public static WrappedGameProfile getGameProfileWithThisSkin(UUID uuid, String playerName, WrappedGameProfile profileWithSkin) {
try { try {
WrappedGameProfile gameProfile = new WrappedGameProfile(uuid != null ? uuid : UUID.randomUUID(), playerName); WrappedGameProfile gameProfile = new WrappedGameProfile(uuid != null ? uuid : UUID.randomUUID(), playerName);
gameProfile.getProperties().putAll(profileWithSkin.getProperties()); gameProfile.getProperties().putAll(profileWithSkin.getProperties());
@ -491,6 +503,24 @@ public class ReflectionManager {
} }
} }
public static Enum getSoundCategory(String category) {
Method method = getNmsMethod("SoundCategory", "a", String.class);
try {
Enum invoke = (Enum) method.invoke(null, category.toLowerCase());
if (invoke == null) {
Class<?> clazz = getNmsClass("SoundCategory");
Enum[] enums = clazz != null ? (Enum[]) clazz.getEnumConstants() : null;
for (Enum anEnum : enums != null ? enums : new Enum[0]) {
if (anEnum.name().equals("MASTER")) return anEnum;
}
}
return null;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
/** /**
* Creates the NMS object EnumItemSlot from an EquipmentSlot. * Creates the NMS object EnumItemSlot from an EquipmentSlot.
* @param slot * @param slot
@ -587,9 +617,8 @@ public class ReflectionManager {
} }
public static Object getCraftSoundEffect(String sound) { public static Object getCraftSoundEffect(String sound) {
Method nmsMethod = getNmsMethod("CraftSound", "getSoundEffect");
try { try {
return nmsMethod.invoke(null, sound); return getCraftMethod("CraftSound", "getSoundEffect", String.class).invoke(null, sound);
} catch (IllegalAccessException | InvocationTargetException e) { } catch (IllegalAccessException | InvocationTargetException e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -625,4 +654,5 @@ public class ReflectionManager {
} }
return null; return null;
} }
} }