- Changed entire project to gradle

- Updated for 1.8.3
- No more errors, woo
This commit is contained in:
NavidK0
2015-03-09 20:28:41 -04:00
parent 14757a035b
commit 573f4cdc88
81 changed files with 299 additions and 645 deletions

View File

@@ -15,7 +15,6 @@ import me.libraryaddict.disguise.commands.*;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
import me.libraryaddict.disguise.disguisetypes.FutureDisguiseType;
import me.libraryaddict.disguise.disguisetypes.watchers.AgeableWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.GuardianWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.HorseWatcher;
@@ -26,11 +25,9 @@ import me.libraryaddict.disguise.disguisetypes.watchers.TameableWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.ZombieWatcher;
import me.libraryaddict.disguise.utilities.DisguiseSound;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.FakeBoundingBox;
import me.libraryaddict.disguise.utilities.PacketsManager;
import me.libraryaddict.disguise.utilities.ReflectionManager;
import me.libraryaddict.disguise.utilities.DisguiseValues;
import me.libraryaddict.disguise.utilities.ReflectionManager.LibVersion;
import org.bukkit.Bukkit;
import org.bukkit.entity.Ageable;
@@ -154,7 +151,7 @@ public class LibsDisguises extends JavaPlugin {
*/
private void registerValues() {
for (DisguiseType disguiseType : DisguiseType.values()) {
if (disguiseType.getEntityType() == null && !(disguiseType.is1_8() && LibVersion.is1_8())) {
if (disguiseType.getEntityType() == null) {
continue;
}
Class watcherClass = null;
@@ -209,25 +206,6 @@ public class LibsDisguises extends JavaPlugin {
if (DisguiseValues.getDisguiseValues(disguiseType) != null) {
continue;
}
if (disguiseType.is1_8()) {
int entitySize = 0;
FutureDisguiseType futureType = disguiseType.getFutureType();
DisguiseValues disguiseValues = new DisguiseValues(disguiseType, null, entitySize, futureType.getMaxHealth());
Object[] objs = disguiseType.getFutureType().getDataWatcher();
for (int i = 0; i < objs.length; i += 2) {
disguiseValues.setMetaValue((Integer) objs[i], objs[i + 1]);
}
// Get the bounding box
float[] box = futureType.getBoundingBox();
disguiseValues.setAdultBox(new FakeBoundingBox(box[0], box[1], box[2]));
/* if (disguiseType == DisguiseType.RABBIT) {
((Ageable) bukkitEntity).setBaby();
disguiseValues.setBabyBox(ReflectionManager.getBoundingBox(bukkitEntity));
}
disguiseValues.setEntitySize(ReflectionManager.getSize(bukkitEntity));*/
continue;
}
String nmsEntityName = toReadable(disguiseType.name());
switch (disguiseType) {
case WITHER_SKELETON:
@@ -264,6 +242,9 @@ public class LibsDisguises extends JavaPlugin {
case LEASH_HITCH:
nmsEntityName = "Leash";
break;
case ELDER_GUARDIAN:
nmsEntityName = "Guardian";
break;
default:
break;
}

View File

@@ -64,7 +64,7 @@ public abstract class Disguise {
protected void createDisguise(DisguiseType newType) {
if (getWatcher() != null)
return;
if (!(LibVersion.is1_8() && newType.is1_8()) && newType.getEntityType() == null) {
if (newType.getEntityType() == null) {
throw new RuntimeException(
"DisguiseType "
+ newType
@@ -101,7 +101,7 @@ public abstract class Disguise {
}
else if (getType() == DisguiseType.ELDER_GUARDIAN) {
getWatcher().setValue(14, 0 | 4);
getWatcher().setValue(16, 0 | 4);
}
// Else if its a horse. Set the horse watcher type
else if (getWatcher() instanceof HorseWatcher) {

View File

@@ -2,17 +2,16 @@ package me.libraryaddict.disguise.disguisetypes;
import java.lang.reflect.Method;
import me.libraryaddict.disguise.utilities.ReflectionManager.LibVersion;
import org.apache.commons.lang.StringUtils;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Guardian;
import org.bukkit.entity.Horse;
import org.bukkit.entity.Skeleton;
import org.bukkit.entity.Zombie;
public enum DisguiseType {
ARMOR_STAND(FutureDisguiseType.ARMOR_STAND),
ARMOR_STAND(78),
ARROW(60),
@@ -36,7 +35,7 @@ public enum DisguiseType {
EGG(62),
ELDER_GUARDIAN(FutureDisguiseType.ELDER_GUARDIAN),
ELDER_GUARDIAN,
ENDER_CRYSTAL(51),
@@ -48,7 +47,7 @@ public enum DisguiseType {
ENDERMAN,
ENDERMITE(FutureDisguiseType.ENDERMITE),
ENDERMITE,
EXPERIENCE_ORB,
@@ -64,7 +63,7 @@ public enum DisguiseType {
GIANT,
GUARDIAN(FutureDisguiseType.GUARDIAN),
GUARDIAN,
HORSE,
@@ -106,7 +105,7 @@ public enum DisguiseType {
PRIMED_TNT(50),
RABBIT(FutureDisguiseType.RABBIT),
RABBIT,
SHEEP,
@@ -150,7 +149,7 @@ public enum DisguiseType {
ZOMBIE_VILLAGER;
private static Method isVillager, getVariant, getSkeletonType;
private static Method isVillager, getVariant, getSkeletonType, isElder;
static {
// We set the entity type in this so that we can safely ignore disguisetypes which don't exist in older versions of MC.
@@ -175,6 +174,9 @@ public enum DisguiseType {
case WITHER_SKELETON:
toUse = DisguiseType.SKELETON;
break;
case ELDER_GUARDIAN:
toUse = DisguiseType.GUARDIAN;
break;
default:
break;
}
@@ -196,6 +198,10 @@ public enum DisguiseType {
getSkeletonType = Skeleton.class.getMethod("getSkeletonType");
} catch (Throwable ignored) {
}
try {
isElder = Guardian.class.getMethod("isElder");
} catch (Throwable ignored) {
}
}
public static DisguiseType getType(Entity entity) {
@@ -228,6 +234,15 @@ public enum DisguiseType {
ex.printStackTrace();
}
break;
case GUARDIAN:
try {
if ((Boolean) isElder.invoke(entity)) {
disguiseType = DisguiseType.ELDER_GUARDIAN;
}
} catch (Exception ex) {
ex.printStackTrace();
}
break;
default:
break;
}
@@ -244,10 +259,9 @@ public enum DisguiseType {
private int defaultId, entityId;
private EntityType entityType;
private FutureDisguiseType futureType;
private Class<? extends FlagWatcher> watcherClass;
private DisguiseType(FutureDisguiseType disguiseType, int... ints) {
private DisguiseType(int... ints) {
for (int i = 0; i < ints.length; i++) {
int value = ints[i];
switch (i) {
@@ -261,13 +275,6 @@ public enum DisguiseType {
break;
}
}
if (LibVersion.is1_8()) {
futureType = disguiseType;
}
}
private DisguiseType(int... ints) {
this(null, ints);
}
public int getDefaultId() {
@@ -275,9 +282,6 @@ public enum DisguiseType {
}
public Class<? extends Entity> getEntityClass() {
if (futureType != null) {
return futureType.getEntityClass();
}
if (entityType != null) {
return getEntityType().getEntityClass();
}
@@ -292,28 +296,20 @@ public enum DisguiseType {
return entityType;
}
public FutureDisguiseType getFutureType() {
return futureType;
}
public int getTypeId() {
return is1_8() ? futureType.getEntityId() : (int) getEntityType().getTypeId();
return (int) getEntityType().getTypeId();
}
public Class getWatcherClass() {
return watcherClass;
}
public boolean is1_8() {
return futureType != null;
}
public boolean isMisc() {
return is1_8() ? !futureType.isAlive() : getEntityType() != null && !getEntityType().isAlive();
return getEntityType() != null && !getEntityType().isAlive();
}
public boolean isMob() {
return is1_8() ? futureType.isAlive() : getEntityType() != null && getEntityType().isAlive() && !isPlayer();
return getEntityType() != null && getEntityType().isAlive() && !isPlayer();
}
public boolean isPlayer() {

View File

@@ -158,7 +158,7 @@ public class FlagWatcher {
}
public String getCustomName() {
return (String) getValue(10, null);
return (String) getValue(2, null);
}
protected TargetedDisguise getDisguise() {
@@ -207,7 +207,7 @@ public class FlagWatcher {
}
public boolean isCustomNameVisible() {
return (Byte) getValue(11, (byte) 0) == 1;
return (Byte) getValue(3, (byte) 0) == 1;
}
public boolean isEntityAnimationsAdded() {
@@ -296,13 +296,13 @@ public class FlagWatcher {
if (name != null && name.length() > 64) {
name = name.substring(0, 64);
}
setValue(10, name);
sendData(10);
setValue(2, name);
sendData(2);
}
public void setCustomNameVisible(boolean display) {
setValue(11, (byte) (display ? 1 : 0));
sendData(11);
setValue(3, (byte) (display ? 1 : 0));
sendData(3);
}
private void setFlag(int byteValue, boolean flag) {

View File

@@ -153,32 +153,30 @@ public class PlayerDisguise extends TargetedDisguise {
}
public PlayerDisguise setSkin(String skinToUse) {
if (LibVersion.is1_7_6()) {
this.skinToUse = skinToUse;
if (skinToUse == null) {
this.currentLookup = null;
this.gameProfile = null;
} else {
if (skinToUse.length() > 16) {
this.skinToUse = skinToUse.substring(0, 16);
}
currentLookup = new LibsProfileLookup() {
this.skinToUse = skinToUse;
if (skinToUse == null) {
this.currentLookup = null;
this.gameProfile = null;
} else {
if (skinToUse.length() > 16) {
this.skinToUse = skinToUse.substring(0, 16);
}
currentLookup = new LibsProfileLookup() {
@Override
public void onLookup(WrappedGameProfile gameProfile) {
if (currentLookup == this && gameProfile != null) {
setSkin(gameProfile);
if (!gameProfile.getProperties().isEmpty() && DisguiseUtilities.isDisguiseInUse(PlayerDisguise.this)) {
DisguiseUtilities.refreshTrackers(PlayerDisguise.this);
}
currentLookup = null;
@Override
public void onLookup(WrappedGameProfile gameProfile) {
if (currentLookup == this && gameProfile != null) {
setSkin(gameProfile);
if (!gameProfile.getProperties().isEmpty() && DisguiseUtilities.isDisguiseInUse(PlayerDisguise.this)) {
DisguiseUtilities.refreshTrackers(PlayerDisguise.this);
}
currentLookup = null;
}
};
WrappedGameProfile gameProfile = DisguiseUtilities.getProfileFromMojang(this.skinToUse, currentLookup);
if (gameProfile != null) {
setSkin(gameProfile);
}
};
WrappedGameProfile gameProfile = DisguiseUtilities.getProfileFromMojang(this.skinToUse, currentLookup);
if (gameProfile != null) {
setSkin(gameProfile);
}
}
return this;

View File

@@ -17,7 +17,7 @@ public class AgeableWatcher extends LivingWatcher {
}
public boolean isBaby() {
return (Integer) getValue(12, 0) < 0;
return ((Byte) getValue(12, (byte) 0)).intValue() < 0;
}
public void setAdult() {
@@ -25,7 +25,7 @@ public class AgeableWatcher extends LivingWatcher {
}
public void setAge(int newAge) {
setValue(12, newAge);
setValue(12, (byte) newAge);
sendData(12);
}
@@ -34,7 +34,7 @@ public class AgeableWatcher extends LivingWatcher {
}
public void setBaby(boolean isBaby) {
setValue(12, isBaby ? -24000 : 0);
setValue(12, (byte) (isBaby ? -1 : 0));
sendData(12);
}

View File

@@ -36,7 +36,7 @@ public class EndermanWatcher extends LivingWatcher {
@Override
public void setItemInHand(ItemStack itemstack) {
setValue(16, (byte) (itemstack.getTypeId() & 255));
setValue(16, (short) (itemstack.getTypeId() & 255));
setValue(17, (byte) (itemstack.getDurability() & 255));
}

View File

@@ -13,11 +13,11 @@ public class ItemFrameWatcher extends FlagWatcher {
public ItemStack getItem() {
if (getValue(2, null) == null)
return new ItemStack(0);
return (ItemStack) getValue(2, null);
return (ItemStack) getValue(8, null);
}
public int getRotation() {
return (Integer) getValue(3, 0);
return (Integer) getValue(9, 0);
}
public void setItem(ItemStack newItem) {
@@ -25,13 +25,13 @@ public class ItemFrameWatcher extends FlagWatcher {
newItem = new ItemStack(0);
newItem = newItem.clone();
newItem.setAmount(1);
setValue(2, newItem);
sendData(2);
setValue(8, newItem);
sendData(8);
}
public void setRotation(int rotation) {
setValue(3, (byte) (rotation % 4));
sendData(3);
setValue(9, (byte) (rotation % 4));
sendData(9);
}
}

View File

@@ -110,7 +110,7 @@ public class PlayerWatcher extends LivingWatcher {
PacketContainer packet = new PacketContainer(PacketType.Play.Server.ANIMATION);
StructureModifier<Integer> mods = packet.getIntegers();
mods.write(0, getDisguise().getEntity().getEntityId());
mods.write(1, LibVersion.is1_7() ? 3 : 2);
mods.write(1, 3);
for (Player player : DisguiseUtilities.getPerverts(getDisguise())) {
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet);

View File

@@ -339,7 +339,7 @@ public abstract class BaseDisguiseCommand implements CommandExecutor {
throw new DisguiseParseException(ChatColor.RED + "Error! The disguise " + ChatColor.GREEN + args[0]
+ ChatColor.RED + " doesn't exist!");
}
if (!(LibVersion.is1_8() && disguiseType.is1_8()) && disguiseType.getEntityType() == null) {
if (disguiseType.getEntityType() == null) {
throw new DisguiseParseException(ChatColor.RED + "Error! This version of minecraft does not have that disguise!");
}
if (!map.containsKey(disguiseType)) {

View File

@@ -66,8 +66,7 @@ public enum DisguiseSound {
PIG_ZOMBIE("mob.zombiepig.zpighurt", null, "mob.zombiepig.zpigdeath", "mob.zombiepig.zpig", "mob.zombiepig.zpigangry"),
PLAYER(LibVersion.is1_7() ? "game.player.hurt" : "damage.hit", "step.grass", LibVersion.is1_7() ? "game.player.hurt"
: "damage.hit", null),
PLAYER("game.player.hurt", "step.grass", "game.player.hurt", null),
RABBIT("mob.rabbit.hurt", "mob.rabbit.hop", "mob.rabbit.death", "mob.rabbit.idle"),

View File

@@ -23,13 +23,9 @@ import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
import me.libraryaddict.disguise.disguisetypes.PlayerDisguise;
import me.libraryaddict.disguise.disguisetypes.TargetedDisguise;
import me.libraryaddict.disguise.disguisetypes.watchers.AgeableWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.EndermanWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.ItemFrameWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.MinecartWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.PlayerWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.ZombieWatcher;
import me.libraryaddict.disguise.disguisetypes.TargetedDisguise.TargetType;
import me.libraryaddict.disguise.utilities.ReflectionManager.LibVersion;
import org.bukkit.Bukkit;
import org.bukkit.Location;
@@ -41,6 +37,7 @@ import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Zombie;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.util.Vector;
@@ -97,30 +94,15 @@ public class DisguiseUtilities {
block = ((Object[]) ReflectionManager.getNmsField(ReflectionManager.getNmsClass("Block"), "byId").get(null))[Material.BED_BLOCK
.getId()];
}
if (LibVersion.is1_8()) {
Method fromLegacyData = block.getClass().getMethod("fromLegacyData", int.class);
Method setType = chunkSection.getClass().getMethod("setType", int.class, int.class, int.class,
ReflectionManager.getNmsClass("IBlockData"));
Method setSky = chunkSection.getClass().getMethod("a", int.class, int.class, int.class, int.class);
Method setEmitted = chunkSection.getClass().getMethod("b", int.class, int.class, int.class, int.class);
for (BlockFace face : new BlockFace[] { BlockFace.EAST, BlockFace.WEST, BlockFace.NORTH, BlockFace.SOUTH }) {
setType.invoke(chunkSection, 1 + face.getModX(), 0, 1 + face.getModZ(), fromLegacyData.invoke(block, face.ordinal()));
setSky.invoke(chunkSection, 1 + face.getModX(), 0, 1 + face.getModZ(), 0);
setEmitted.invoke(chunkSection, 1 + face.getModX(), 0, 1 + face.getModZ(), 0);
}
} else {
Method setId = chunkSection.getClass().getMethod("setTypeId", int.class, int.class, int.class,
ReflectionManager.getNmsClass("Block"));
Method setData = chunkSection.getClass().getMethod("setData", int.class, int.class, int.class, int.class);
Method setSky = chunkSection.getClass().getMethod("setSkyLight", int.class, int.class, int.class, int.class);
Method setEmitted = chunkSection.getClass().getMethod("setEmittedLight", int.class, int.class, int.class, int.class);
for (BlockFace face : new BlockFace[] { BlockFace.EAST, BlockFace.WEST, BlockFace.NORTH, BlockFace.SOUTH }) {
setId.invoke(chunkSection, 1 + face.getModX(), 0, 1 + face.getModZ(), block);
setData.invoke(chunkSection, 1 + face.getModX(), 0, 1 + face.getModZ(), face.ordinal());
setSky.invoke(chunkSection, 1 + face.getModX(), 0, 1 + face.getModZ(), 0);
setEmitted.invoke(chunkSection, 1 + face.getModX(), 0, 1 + face.getModZ(), 0);
}
Method fromLegacyData = block.getClass().getMethod("fromLegacyData", int.class);
Method setType = chunkSection.getClass().getMethod("setType", int.class, int.class, int.class,
ReflectionManager.getNmsClass("IBlockData"));
Method setSky = chunkSection.getClass().getMethod("a", int.class, int.class, int.class, int.class);
Method setEmitted = chunkSection.getClass().getMethod("b", int.class, int.class, int.class, int.class);
for (BlockFace face : new BlockFace[] { BlockFace.EAST, BlockFace.WEST, BlockFace.NORTH, BlockFace.SOUTH }) {
setType.invoke(chunkSection, 1 + face.getModX(), 0, 1 + face.getModZ(), fromLegacyData.invoke(block, face.ordinal()));
setSky.invoke(chunkSection, 1 + face.getModX(), 0, 1 + face.getModZ(), 0);
setEmitted.invoke(chunkSection, 1 + face.getModX(), 0, 1 + face.getModZ(), 0);
}
Object[] array = (Object[]) Array.newInstance(chunkSection.getClass(), 16);
@@ -341,7 +323,7 @@ public class DisguiseUtilities {
try {
packets[i] = ProtocolLibrary.getProtocolManager()
.createPacketConstructor(PacketType.Play.Server.MAP_CHUNK, bedChunk, true, 0, 40)
.createPacket(bedChunk, true, 0, LibVersion.is1_8() ? 48 : 0);
.createPacket(bedChunk, true, 0, 48);
} catch (IllegalArgumentException ex) {
packets[i] = ProtocolLibrary.getProtocolManager()
.createPacketConstructor(PacketType.Play.Server.MAP_CHUNK, bedChunk, true, 0)
@@ -350,15 +332,9 @@ public class DisguiseUtilities {
i++;
// Make load packets
if (oldLoc == null || i > 1) {
try {
packets[i] = ProtocolLibrary.getProtocolManager()
.createPacketConstructor(PacketType.Play.Server.MAP_CHUNK_BULK, Arrays.asList(bedChunk), 40)
.createPacket(Arrays.asList(bedChunk), LibVersion.is1_8() ? 48 : 0);
} catch (IllegalArgumentException ex) {
packets[i] = ProtocolLibrary.getProtocolManager()
.createPacketConstructor(PacketType.Play.Server.MAP_CHUNK_BULK, List.class)
.createPacket(Arrays.asList(bedChunk));
}
packets[i] = ProtocolLibrary.getProtocolManager()
.createPacketConstructor(PacketType.Play.Server.MAP_CHUNK_BULK, Arrays.asList(bedChunk))
.createPacket(Arrays.asList(bedChunk));
i++;
}
}
@@ -370,19 +346,13 @@ public class DisguiseUtilities {
PacketContainer setBed = new PacketContainer(PacketType.Play.Server.BED);
StructureModifier<Integer> bedInts = setBed.getIntegers();
bedInts.write(0, entity.getEntityId());
if (LibVersion.is1_8()) {
PlayerWatcher watcher = disguise.getWatcher();
int chunkX = (int) Math.floor(playerLocation.getX() / 16D) - 17, chunkZ = (int) Math
.floor(playerLocation.getZ() / 16D) - 17;
chunkX -= chunkX % 8;
chunkZ -= chunkZ % 8;
bedInts.write(1, (chunkX * 16) + 1 + watcher.getSleepingDirection().getModX());
bedInts.write(3, (chunkZ * 16) + 1 + watcher.getSleepingDirection().getModZ());
} else {
bedInts.write(1, loc.getBlockX());
bedInts.write(2, loc.getBlockY());
bedInts.write(3, loc.getBlockZ());
}
PlayerWatcher watcher = disguise.getWatcher();
int chunkX = (int) Math.floor(playerLocation.getX() / 16D) - 17, chunkZ = (int) Math
.floor(playerLocation.getZ() / 16D) - 17;
chunkX -= chunkX % 8;
chunkZ -= chunkZ % 8;
bedInts.write(1, (chunkX * 16) + 1 + watcher.getSleepingDirection().getModX());
bedInts.write(3, (chunkZ * 16) + 1 + watcher.getSleepingDirection().getModZ());
PacketContainer teleport = new PacketContainer(PacketType.Play.Server.ENTITY_TELEPORT);
StructureModifier<Integer> ints = teleport.getIntegers();
ints.write(0, entity.getEntityId());
@@ -495,8 +465,8 @@ public class DisguiseUtilities {
}
if (DisguiseAPI.isDisguiseInUse(disguise)
&& (!gameProfile.getName().equals(
disguise.getSkin() != null && LibVersion.is1_7_6() ? disguise.getSkin() : disguise.getName()) || (LibVersion
.is1_7_6() && !gameProfile.getProperties().isEmpty()))) {
disguise.getSkin() != null ? disguise.getSkin() : disguise.getName())
|| !gameProfile.getProperties().isEmpty())) {
disguise.setGameProfile(gameProfile);
DisguiseUtilities.refreshTrackers(disguise);
}
@@ -523,7 +493,7 @@ public class DisguiseUtilities {
Player player = Bukkit.getPlayerExact(playerName);
if (player != null) {
WrappedGameProfile gameProfile = ReflectionManager.getGameProfile(player);
if (!LibVersion.is1_7_6() || !gameProfile.getProperties().isEmpty()) {
if (!gameProfile.getProperties().isEmpty()) {
gameProfiles.put(playerName, gameProfile);
return gameProfile;
}
@@ -536,7 +506,7 @@ public class DisguiseUtilities {
final WrappedGameProfile gameProfile = lookupGameProfile(origName);
Bukkit.getScheduler().runTask(libsDisguises, new Runnable() {
public void run() {
if (!LibVersion.is1_7_6() || !gameProfile.getProperties().isEmpty()) {
if (!gameProfile.getProperties().isEmpty()) {
if (gameProfiles.containsKey(playerName) && gameProfiles.get(playerName) == null) {
gameProfiles.put(playerName, gameProfile);
}
@@ -613,54 +583,17 @@ public class DisguiseUtilities {
*/
public static List<WrappedWatchableObject> rebuildForVersion(Player player, FlagWatcher watcher,
List<WrappedWatchableObject> list) {
if (!LibVersion.is1_8())
if (true) // Use for future protocol compatibility
return list;
ArrayList<WrappedWatchableObject> rebuiltList = new ArrayList<WrappedWatchableObject>();
ArrayList<WrappedWatchableObject> backups = new ArrayList<WrappedWatchableObject>();
// TODO Player and Minecart
for (WrappedWatchableObject obj : list) {
if (obj.getValue().getClass().getName().startsWith("org.")) {
backups.add(obj);
continue;
}
switch (obj.getIndex()) {
case 2:
case 3:
if (watcher instanceof ItemFrameWatcher) {
rebuiltList.add(new WrappedWatchableObject(obj.getIndex() + 6, obj.getValue()));
} else {
backups.add(obj);
}
break;
case 10:
case 11:
rebuiltList.add(new WrappedWatchableObject(obj.getIndex() - 8, obj.getValue()));
break;
case 12:
if (watcher instanceof AgeableWatcher) {
int i = (Integer) obj.getValue();
rebuiltList.add(new WrappedWatchableObject(obj.getIndex(), (byte) (i < 0 ? -1 : (i >= 6000 ? 1 : 0))));
} else {
backups.add(obj);
}
break;
case 16:
if (watcher instanceof EndermanWatcher) {
rebuiltList.add(new WrappedWatchableObject(obj.getIndex(), ((Byte) obj.getValue()).shortValue()));
} else {
backups.add(obj);
}
break;
case 20:
if (watcher instanceof MinecartWatcher) {
// TODO
backups.add(obj);
} else {
backups.add(obj);
}
default:
backups.add(obj);
break;
// TODO: Future version support
}
}
Iterator<WrappedWatchableObject> itel = backups.iterator();
@@ -687,6 +620,8 @@ public class DisguiseUtilities {
if (disguise.isDisguiseInUse() && disguise.getEntity() instanceof Player
&& ((Player) disguise.getEntity()).getName().equalsIgnoreCase(player)) {
removeSelfDisguise((Player) disguise.getEntity());
if (disguise.isSelfDisguiseVisible())
selfDisguised.add(disguise.getEntity().getUniqueId());
ProtocolLibrary.getProtocolManager().sendServerPacket((Player) disguise.getEntity(), destroyPacket);
Bukkit.getScheduler().scheduleSyncDelayedTask(libsDisguises, new Runnable() {
public void run() {
@@ -697,7 +632,6 @@ public class DisguiseUtilities {
}
}
}, 2);
DisguiseUtilities.sendSelfDisguise((Player) disguise.getEntity(), disguise);
} else {
final Object entityTrackerEntry = ReflectionManager.getEntityTrackerEntry(disguise.getEntity());
if (entityTrackerEntry != null) {
@@ -781,6 +715,7 @@ public class DisguiseUtilities {
try {
if (selfDisguised.contains(disguise.getEntity().getUniqueId()) && disguise.isDisguiseInUse()) {
removeSelfDisguise((Player) disguise.getEntity());
selfDisguised.add(disguise.getEntity().getUniqueId());
ProtocolLibrary.getProtocolManager().sendServerPacket((Player) disguise.getEntity(), destroyPacket);
Bukkit.getScheduler().scheduleSyncDelayedTask(libsDisguises, new Runnable() {
public void run() {
@@ -850,8 +785,7 @@ public class DisguiseUtilities {
public static void removeSelfDisguise(Player player) {
if (selfDisguised.contains(player.getUniqueId())) {
// Send a packet to destroy the fake entity
PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_DESTROY);
packet.getModifier().write(0, new int[] { DisguiseAPI.getSelfDisguiseId() });
PacketContainer packet = getDestroyPacket(DisguiseAPI.getSelfDisguiseId());
try {
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet);
} catch (Exception ex) {
@@ -979,10 +913,11 @@ public class DisguiseUtilities {
}
// Resend any active potion effects
for (Object potionEffect : player.getActivePotionEffects()) {
for (PotionEffect potionEffect : player.getActivePotionEffects()) {
Object mobEffect = ReflectionManager.createMobEffect(potionEffect);
sendSelfPacket(player,
manager.createPacketConstructor(PacketType.Play.Server.ENTITY_EFFECT, player.getEntityId(), potionEffect)
.createPacket(player.getEntityId(), potionEffect));
manager.createPacketConstructor(PacketType.Play.Server.ENTITY_EFFECT, player.getEntityId(), mobEffect)
.createPacket(player.getEntityId(), mobEffect));
}
} catch (Exception ex) {
ex.printStackTrace();

View File

@@ -2,8 +2,8 @@ package me.libraryaddict.disguise.utilities;
import com.comphenix.protocol.wrappers.WrappedGameProfile;
import net.minecraft.util.com.mojang.authlib.GameProfile;
import net.minecraft.util.com.mojang.authlib.ProfileLookupCallback;
import com.mojang.authlib.GameProfile;
import com.mojang.authlib.ProfileLookupCallback;
public class LibsProfileLookupCaller implements ProfileLookupCallback {
private WrappedGameProfile gameProfile;

View File

@@ -5,6 +5,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Random;
import java.util.UUID;
import me.libraryaddict.disguise.DisguiseAPI;
import me.libraryaddict.disguise.DisguiseConfig;
@@ -21,7 +22,6 @@ import me.libraryaddict.disguise.disguisetypes.watchers.PlayerWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.SheepWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.WolfWatcher;
import me.libraryaddict.disguise.utilities.DisguiseSound.SoundType;
import me.libraryaddict.disguise.utilities.ReflectionManager.LibVersion;
import org.bukkit.Art;
import org.bukkit.Bukkit;
@@ -84,7 +84,7 @@ public class PacketsManager {
try {
Player observer = event.getPlayer();
StructureModifier<Entity> entityModifer = event.getPacket().getEntityModifier(observer.getWorld());
Entity entity = entityModifer.read(LibVersion.is1_7() ? 0 : 1);
Entity entity = entityModifer.read(0);
if (entity instanceof ExperienceOrb || entity instanceof Item || entity instanceof Arrow
|| entity == observer) {
event.setCancelled(true);
@@ -196,12 +196,10 @@ public class PacketsManager {
spawnPackets[0] = new PacketContainer(PacketType.Play.Server.SPAWN_ENTITY_PAINTING);
StructureModifier<Object> mods = spawnPackets[0].getModifier();
mods.write(0, disguisedEntity.getEntityId());
mods.write(1, loc.getBlockX());
mods.write(2, loc.getBlockY());
mods.write(3, loc.getBlockZ());
mods.write(4, ((int) loc.getYaw()) % 4);
mods.write(1, ReflectionManager.getBlockPosition(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()));
mods.write(2, ReflectionManager.getEnumDirection(((int) loc.getYaw()) % 4));
int id = ((MiscDisguise) disguise).getData();
mods.write(5, ReflectionManager.getEnumArt(Art.values()[id]));
mods.write(3, ReflectionManager.getEnumArt(Art.values()[id]));
// Make the teleport packet to make it visible..
spawnPackets[1] = new PacketContainer(PacketType.Play.Server.ENTITY_TELEPORT);
@@ -217,7 +215,7 @@ public class PacketsManager {
spawnPackets[0] = new PacketContainer(PacketType.Play.Server.NAMED_ENTITY_SPAWN);
StructureModifier<String> stringMods = spawnPackets[0].getStrings();
WrappedGameProfile gameProfile = null; // TODO Will this throw a error for older MC's? Namely pre-1.7
WrappedGameProfile gameProfile;
if (stringMods.size() > 0) {
for (int i = 0; i < stringMods.size(); i++) {
stringMods.write(i, ((PlayerDisguise) disguise).getName());
@@ -233,7 +231,7 @@ public class PacketsManager {
if (removeName) {
DisguiseUtilities.getAddedByPlugins().remove(name);
}
spawnPackets[0].getGameProfiles().write(0, gameProfile);
spawnPackets[0].getSpecificModifier(UUID.class).write(0, gameProfile.getUUID());
}
StructureModifier<Integer> intMods = spawnPackets[0].getIntegers();
intMods.write(0, disguisedEntity.getEntityId());
@@ -266,22 +264,23 @@ public class PacketsManager {
}
}
if (LibVersion.is1_8()) {
ArrayList<PacketContainer> newPackets = new ArrayList<PacketContainer>();
newPackets.add(null);
for (int i = 0; i < spawnPackets.length; i++) {
if (spawnPackets[i] != null) { // Get rid of empty packet '1' if it exists.
newPackets.add(spawnPackets[i]);
}
ArrayList<PacketContainer> newPackets = new ArrayList<PacketContainer>();
newPackets.add(null);
for (int i = 0; i < spawnPackets.length; i++) {
if (spawnPackets[i] != null) { // Get rid of empty packet '1' if it exists.
newPackets.add(spawnPackets[i]);
}
spawnPackets = newPackets.toArray(new PacketContainer[newPackets.size()]);
spawnPackets[0] = new PacketContainer(PacketType.Play.Server.PLAYER_INFO);
spawnPackets[0].getGameProfiles().write(0, gameProfile);
spawnPackets[0].getModifier().write(4, gameProfile.getName());
PacketContainer delayedPacket = spawnPackets[0].shallowClone();
delayedPacket.getModifier().write(0, 4);
delayedPackets = new PacketContainer[] { delayedPacket };
}
spawnPackets = newPackets.toArray(new PacketContainer[newPackets.size()]);
spawnPackets[0] = new PacketContainer(PacketType.Play.Server.PLAYER_INFO);
spawnPackets[0].getModifier().write(0, ReflectionManager.getEnumPlayerInfoAction(0));
List playerList = new ArrayList();
PlayerDisguise playerDisguise = (PlayerDisguise) disguise;
playerList.add(ReflectionManager.getPlayerInfoData(spawnPackets[0].getHandle(), playerDisguise.getGameProfile()));
spawnPackets[0].getModifier().write(1, playerList);
PacketContainer delayedPacket = spawnPackets[0].shallowClone();
delayedPacket.getModifier().write(0, ReflectionManager.getEnumPlayerInfoAction(4));
delayedPackets = new PacketContainer[] { delayedPacket };
} else if (disguise.getType().isMob() || disguise.getType() == DisguiseType.ARMOR_STAND) {
@@ -615,14 +614,9 @@ public class PacketsManager {
try {
int typeId = soundLoc.getWorld().getBlockTypeIdAt(soundLoc.getBlockX(),
soundLoc.getBlockY() - 1, soundLoc.getBlockZ());
Object block;
if (LibVersion.is1_7()) {
block = ReflectionManager.getNmsMethod("RegistryMaterials", "a", int.class)
.invoke(ReflectionManager.getNmsField("Block", "REGISTRY").get(null),
typeId);
} else {
block = ((Object[]) ReflectionManager.getNmsField("Block", "byId").get(null))[typeId];
}
Object block = ReflectionManager.getNmsMethod("RegistryMaterials", "a", int.class)
.invoke(ReflectionManager.getNmsField("Block", "REGISTRY").get(null),
typeId);
if (block != null) {
Object step = ReflectionManager.getNmsField("Block", "stepSound").get(block);
mods.write(0, ReflectionManager.getNmsMethod(step.getClass(), "getStepSound")
@@ -689,7 +683,7 @@ public class PacketsManager {
}
}
} else if (event.getPacketType() == PacketType.Play.Server.ENTITY_STATUS) {
if ((Byte) mods.read(1) == (LibVersion.is1_7() ? 2 : 1)) {
if ((Byte) mods.read(1) == 2) {
// It made a damage animation
Entity entity = event.getPacket().getEntityModifier(observer.getWorld()).read(0);
Disguise disguise = DisguiseAPI.getDisguise(observer, entity);
@@ -836,7 +830,7 @@ public class PacketsManager {
e.printStackTrace();
}
} else if (event.getPacketType() == PacketType.Play.Server.ANIMATION) {
if (event.getPacket().getIntegers().read(1) != (LibVersion.is1_7() ? 2 : 3)) {
if (event.getPacket().getIntegers().read(1) != 2) {
event.setCancelled(true);
}
} else if (event.getPacketType() == PacketType.Play.Server.ATTACH_ENTITY
@@ -853,7 +847,7 @@ public class PacketsManager {
} else if (event.getPacketType() == PacketType.Play.Server.ENTITY_STATUS) {
Disguise disguise = DisguiseAPI.getDisguise(event.getPlayer(), event.getPlayer());
if (disguise.isSelfDisguiseSoundsReplaced() && !disguise.getType().isPlayer()
&& event.getPacket().getBytes().read(0) == (LibVersion.is1_7() ? 2 : 1)) {
&& event.getPacket().getBytes().read(0) == 2) {
event.setCancelled(true);
}
}
@@ -1342,7 +1336,7 @@ public class PacketsManager {
// Else if the disguise is attempting to send players a forbidden packet
else if (sentPacket.getType() == PacketType.Play.Server.ANIMATION) {
if (disguise.getType().isMisc()
|| (packets[0].getIntegers().read(1) == (LibVersion.is1_7() ? 2 : 3) && (!disguise.getType()
|| (packets[0].getIntegers().read(1) == 2 && (!disguise.getType()
.isPlayer() || (DisguiseConfig.isBedPacketsEnabled() && ((PlayerWatcher) disguise
.getWatcher()).isSleeping())))) {
packets = new PacketContainer[0];
@@ -1357,7 +1351,7 @@ public class PacketsManager {
PacketContainer newPacket = new PacketContainer(PacketType.Play.Server.ANIMATION);
StructureModifier<Integer> mods = newPacket.getIntegers();
mods.write(0, disguise.getEntity().getEntityId());
mods.write(1, LibVersion.is1_7() ? 3 : 2);
mods.write(1, 3);
packets = new PacketContainer[] { newPacket, sentPacket };
}
}

View File

@@ -4,6 +4,7 @@ import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
@@ -25,58 +26,29 @@ import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import com.comphenix.protocol.wrappers.WrappedGameProfile;
import org.bukkit.potion.PotionEffect;
public class ReflectionManager {
public enum LibVersion {
V1_6, V1_7, V1_7_10, V1_7_6, V1_8;
V1_8;
private static LibVersion currentVersion;
static {
String mcVersion = Bukkit.getVersion().split("MC: ")[1].replace(")", "");
if (mcVersion.startsWith("1.")) {
if (mcVersion.compareTo("1.7") < 0) {
currentVersion = LibVersion.V1_6;
} else if (mcVersion.startsWith("1.7")) {
if (mcVersion.equals("1.7.10")) {
currentVersion = LibVersion.V1_7_10;
} else {
currentVersion = mcVersion.compareTo("1.7.6") < 0 ? LibVersion.V1_7 : LibVersion.V1_7_6;
}
} else {
currentVersion = V1_8;
}
}
//String mcVersion = Bukkit.getVersion().split("MC: ")[1].replace(")", "");
currentVersion = V1_8;
}
public static LibVersion getGameVersion() {
return currentVersion;
}
public static boolean is1_6() {
return getGameVersion() == V1_6;
}
public static boolean is1_7() {
return getGameVersion() == V1_7 || is1_7_6();
}
public static boolean is1_7_10() {
return getGameVersion() == V1_7_10 || is1_8();
}
public static boolean is1_7_6() {
return getGameVersion() == V1_7_6 || is1_7_10();
}
public static boolean is1_8() {
return getGameVersion() == V1_8;
}
}
private static final String bukkitVersion = Bukkit.getServer().getClass().getName().split("\\.")[3];
private static final Class<?> craftItemClass;
private static Method damageAndIdleSoundMethod;
private static final Field entitiesField;
private static final Constructor<?> boundingBoxConstructor;
private static final Method setBoundingBoxMethod;
/**
* Map of mc-dev simple class name to fully qualified Forge class name.
*/
@@ -92,7 +64,6 @@ public class ReflectionManager {
*/
private static Map<String, Map<String, Map<String, String>>> ForgeMethodMappings;
private static final Method ihmGet;
private static HashMap<String, Boolean> is1_8 = new HashMap<String, Boolean>();
private static final boolean isForge = Bukkit.getServer().getName().contains("Cauldron")
|| Bukkit.getServer().getName().contains("MCPC-Plus");
private static final Field pingField;
@@ -224,6 +195,9 @@ public class ReflectionManager {
trackerField = getNmsField("WorldServer", "tracker");
entitiesField = getNmsField("EntityTracker", "trackedEntities");
ihmGet = getNmsMethod("IntHashMap", "get", int.class);
boundingBoxConstructor = getNmsConstructor("AxisAlignedBB",double.class, double.class, double.class,
double.class, double.class, double.class);
setBoundingBoxMethod = getNmsMethod("Entity", "a", getNmsClass("AxisAlignedBB"));
}
public static Object createEntityInstance(String entityName) {
@@ -235,19 +209,13 @@ public class ReflectionManager {
Object minecraftServer = getNmsMethod("MinecraftServer", "getServer").invoke(null);
Object playerinteractmanager = getNmsClass("PlayerInteractManager").getConstructor(getNmsClass("World"))
.newInstance(world);
if (LibVersion.is1_7()) {
WrappedGameProfile gameProfile = getGameProfile(null, "LibsDisguises");
entityObject = entityClass.getConstructor(getNmsClass("MinecraftServer"), getNmsClass("WorldServer"),
gameProfile.getHandleType(), playerinteractmanager.getClass()).newInstance(minecraftServer, world,
gameProfile.getHandle(), playerinteractmanager);
} else {
entityObject = entityClass.getConstructor(getNmsClass("MinecraftServer"), getNmsClass("World"), String.class,
playerinteractmanager.getClass()).newInstance(minecraftServer, world, "LibsDisguises",
playerinteractmanager);
}
} else if (LibVersion.is1_8() && entityName.equals("EnderPearl")) {
WrappedGameProfile gameProfile = getGameProfile(null, "LibsDisguises");
entityObject = entityClass.getConstructor(getNmsClass("MinecraftServer"), getNmsClass("WorldServer"),
gameProfile.getHandleType(), playerinteractmanager.getClass()).newInstance(minecraftServer, world,
gameProfile.getHandle(), playerinteractmanager);
} else if (entityName.equals("EnderPearl")) {
entityObject = entityClass.getConstructor(getNmsClass("World"), getNmsClass("EntityLiving"))
.newInstance(world, createEntityInstance("Sheep"));
.newInstance(world, createEntityInstance("Cow"));
} else {
entityObject = entityClass.getConstructor(getNmsClass("World")).newInstance(world);
}
@@ -258,18 +226,27 @@ public class ReflectionManager {
return null;
}
public static Object createMobEffect(int id, int duration, int amplification, boolean ambient, boolean particles) {
try {
return getNmsClass("MobEffect").getConstructor(int.class, int.class, int.class, boolean.class, boolean.class)
.newInstance(id, duration, amplification, ambient, particles);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public static Object createMobEffect(PotionEffect effect) {
return createMobEffect(effect.getType().getId(), effect.getDuration(), effect.getAmplifier(), effect.isAmbient(), effect.hasParticles());
}
private static String dir2fqn(String s) {
return s.replaceAll("/", ".");
}
public static FakeBoundingBox getBoundingBox(Entity entity) {
try {
Object boundingBox;
if (LibVersion.is1_8()) {
boundingBox = getNmsMethod("Entity", "getBoundingBox").invoke(getNmsEntity(entity));
} else {
boundingBox = getNmsField("Entity", "boundingBox").get(getNmsEntity(entity));
}
Object boundingBox = getNmsMethod("Entity", "getBoundingBox").invoke(getNmsEntity(entity));
double x = 0, y = 0, z = 0;
int stage = 0;
for (Field field : boundingBox.getClass().getFields()) {
@@ -368,13 +345,51 @@ public class ReflectionManager {
return null;
}
public static WrappedGameProfile getGameProfile(Player player) {
if (LibVersion.is1_7() || LibVersion.is1_8()) {
return WrappedGameProfile.fromPlayer(player);
public static Object getBlockPosition(int x, int y, int z) {
try {
return getNmsClass("BlockPosition").getConstructor(int.class, int.class, int.class).newInstance(x, y, z);
} catch (Exception ex) {
ex.printStackTrace();
}
return null;
}
public static Enum getEnumDirection(int direction) {
try {
return (Enum) getNmsMethod("EnumDirection", "fromType2", int.class).invoke(null, direction);
} catch (Exception ex) {
ex.printStackTrace();
}
return null;
}
public static Enum getEnumPlayerInfoAction(int action) {
try {
return (Enum) getNmsClass("PacketPlayOutPlayerInfo$EnumPlayerInfoAction").getEnumConstants()[action];
} catch (Exception ex) {
ex.printStackTrace();
}
return null;
}
public static Object getPlayerInfoData(Object playerInfoPacket, WrappedGameProfile gameProfile) {
try {
Object playerListName = getNmsClass("ChatComponentText").getConstructor(String.class)
.newInstance(gameProfile.getName());
return getNmsClass("PacketPlayOutPlayerInfo$PlayerInfoData").getConstructor(getNmsClass("PacketPlayOutPlayerInfo"),
gameProfile.getHandleType(), int.class, getNmsClass("WorldSettings$EnumGamemode"), getNmsClass("IChatBaseComponent"))
.newInstance(playerInfoPacket, gameProfile.getHandle(), 0,
getNmsClass("WorldSettings$EnumGamemode").getEnumConstants()[1], playerListName);
} catch (Exception ex) {
ex.printStackTrace();
}
return null;
}
public static WrappedGameProfile getGameProfile(Player player) {
return WrappedGameProfile.fromPlayer(player);
}
public static WrappedGameProfile getGameProfile(UUID uuid, String playerName) {
try {
return new WrappedGameProfile(uuid != null ? uuid : UUID.randomUUID(), playerName);
@@ -387,9 +402,7 @@ public class ReflectionManager {
public static WrappedGameProfile getGameProfileWithThisSkin(UUID uuid, String playerName, WrappedGameProfile profileWithSkin) {
try {
WrappedGameProfile gameProfile = new WrappedGameProfile(uuid != null ? uuid : UUID.randomUUID(), playerName);
if (LibVersion.is1_7_6()) {
gameProfile.getProperties().putAll(profileWithSkin.getProperties());
}
gameProfile.getProperties().putAll(profileWithSkin.getProperties());
return gameProfile;
} catch (Exception ex) {
ex.printStackTrace();
@@ -418,6 +431,19 @@ public class ReflectionManager {
return null;
}
public static Constructor getNmsConstructor(Class clazz, Class<?>... parameters) {
try {
return clazz.getConstructor(parameters);
} catch (NoSuchMethodException e) {
e.printStackTrace();
}
return null;
}
public static Constructor getNmsConstructor(String className, Class<?>... parameters) {
return getNmsConstructor(getNmsClass(className), parameters);
}
public static Object getNmsEntity(Entity entity) {
try {
return getCraftClass("entity.CraftEntity").getMethod("getHandle").invoke(entity);
@@ -496,12 +522,7 @@ public class ReflectionManager {
try {
float length = getNmsField("Entity", "length").getFloat(getNmsEntity(entity));
float width = getNmsField("Entity", "width").getFloat(getNmsEntity(entity));
float height;
if (LibVersion.is1_8()) {
height = (Float) getNmsMethod("Entity", "getHeadHeight").invoke(getNmsEntity(entity));
} else {
height = getNmsField("Entity", "height").getFloat(getNmsEntity(entity));
}
float height = (Float) getNmsMethod("Entity", "getHeadHeight").invoke(getNmsEntity(entity));
return new float[] { length, width, height };
} catch (Exception ex) {
ex.printStackTrace();
@@ -550,12 +571,12 @@ public class ReflectionManager {
for (Method method : getNmsClass("MinecraftServer").getMethods()) {
if (method.getReturnType().getSimpleName().equals("GameProfileRepository")) {
Object profileRepo = method.invoke(minecraftServer);
Object agent = Class.forName("net.minecraft.util.com.mojang.authlib.Agent").getField("MINECRAFT").get(null);
Object agent = Class.forName("com.mojang.authlib.Agent").getField("MINECRAFT").get(null);
LibsProfileLookupCaller callback = new LibsProfileLookupCaller();
profileRepo
.getClass()
.getMethod("findProfilesByNames", String[].class, agent.getClass(),
Class.forName("net.minecraft.util.com.mojang.authlib.ProfileLookupCallback"))
Class.forName("com.mojang.authlib.ProfileLookupCallback"))
.invoke(profileRepo, new String[] { playername }, agent, callback);
if (callback.getGameProfile() != null) {
return callback.getGameProfile();
@@ -569,26 +590,6 @@ public class ReflectionManager {
return null;
}
public static boolean is1_8(Player player) {
if (LibVersion.is1_8()) {
if (is1_8.containsKey(player.getName())) {
return is1_8.get(player.getName());
}
try {
Object nmsEntity = getNmsEntity(player);
Object connection = getNmsField(nmsEntity.getClass(), "playerConnection").get(nmsEntity);
Field networkManager = getNmsField(connection.getClass(), "networkManager");
Method getVersion = getNmsMethod(networkManager.getType(), "getVersion");
boolean is18 = (Integer) getVersion.invoke(networkManager.get(connection)) >= 28;
is1_8.put(player.getName(), is18);
return is18;
} catch (Exception ex) {
ex.printStackTrace();
}
}
return false;
}
public static boolean isForge() {
return isForge;
}
@@ -604,7 +605,7 @@ public class ReflectionManager {
}
public static void removePlayer(Player player) {
is1_8.remove(player.getName());
}
public static void setAllowSleep(Player player) {
@@ -620,43 +621,13 @@ public class ReflectionManager {
public static void setBoundingBox(Entity entity, FakeBoundingBox newBox) {
try {
Object boundingBox;
if (LibVersion.is1_8()) {
boundingBox = getNmsMethod("Entity", "getBoundingBox").invoke(getNmsEntity(entity));
} else {
boundingBox = getNmsField("Entity", "boundingBox").get(getNmsEntity(entity));
}
int stage = 0;
Location loc = entity.getLocation();
for (Field field : boundingBox.getClass().getFields()) {
if (field.getType().getSimpleName().equals("double")) {
stage++;
switch (stage) {
case 1:
field.setDouble(boundingBox, loc.getX() - newBox.getX());
break;
case 2:
// field.setDouble(boundingBox, loc.getY() - newBox.getY());
break;
case 3:
field.setDouble(boundingBox, loc.getZ() - newBox.getZ());
break;
case 4:
field.setDouble(boundingBox, loc.getX() + newBox.getX());
break;
case 5:
field.setDouble(boundingBox, loc.getY() + newBox.getY());
break;
case 6:
field.setDouble(boundingBox, loc.getZ() + newBox.getZ());
break;
default:
throw new Exception("Error while setting the bounding box, more doubles than I thought??");
}
}
}
Object boundingBox = boundingBoxConstructor.newInstance(loc.getX() - newBox.getX(), loc.getY() - newBox.getY(),
loc.getZ() - newBox.getZ(), loc.getX() + newBox.getX(), loc.getY() + newBox.getY(), loc.getZ() + newBox.getZ());
setBoundingBoxMethod.invoke(getNmsEntity(entity), boundingBox);
} catch (Exception ex) {
ex.printStackTrace();
}
}
}

View File

@@ -0,0 +1,124 @@
# Shall I notify people of a LibsDisguises update?
NotifyUpdate: true
# Whats the permission to get the notification?
Permission: 'libsdisguises.update'
# Whats the max size allowed for command disguiseradius
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
ViewSelfDisguises: 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
# For self disguises, they need to have the armor and the held item removed
# Else they see floating armor, floating held items.
# This turns the items invisible in the disguised players inventory. It does not actually remove them!
RemoveArmor: true
RemoveHeldItem: false
# If you set a disguise to burning, it will no longer be able to be shown as sneaking or invisible.
# Set this to true if you want the disguise to get the animations of the disguised entity. Such as invisible, on fire, sprinting, sneaking, blocking
# This is only valid if you set a animation on the disguise itself. Because the entitys animations are applied otherwise.
AddEntityAnimations: true
# When a sheep or wolf is right clicked with dye. The client automatically assumes it was successful and displays the sheeps wool or the wolfs collar as dyed.
# This is a option that either prevents that happening, or it changes their color officially in the plugin so that everyone sees it changed.
# Its currently set to false which means that the color is not changed and will refresh itself to the player.
# Please note that this will not remove the dye from their hands. This also does not check if the disguised entity is actually a sheep/wolf and wants a say in its color.
DyeableSheep: false
DyeableWolf: false
# This is only called into action when the disguise is constructed using the commands.
# And when the disguise supports that. This will not be used at all for plugins constructing the disguises for instance.
# Such as prophunt. Its also false because its kind of a retarded feature.
# This is pretty simple. It shows the players displayname (Name as it appears in chat) above their head.
# This also overrides any custom name they have set in their disguise options.
ShowNamesAboveDisguises: false
# This supports the above option.
# If this is true, then the name shown above the head appears regardless of if you are looking at the disguise directly or not.
NameAboveHeadAlwaysVisible: true
# This modifys the bounding box, This is stuff like can a arrow hit them.
# If you turn this to true, arrows will act like they hit the disguise in the right place!
# So someone disguised as a enderdragon will easily get shot down by arrows!
# This WILL conflict with NoCheatPlus. Other plugins may also get problems.
# This shouldn't really be enabled for players as it also interferes with their movement because the server thinks the player is larger than he really is.
# That makes the player unable to approach this building because the server thinks he is trying to glitch inside blocks.
ModifyBoundingBox: false
# This prevents disguised players from being targeted by monsters.
# This doesn't prevent their targeting you if already targeting when disguised
# They will just ignore you unless provoked.
MonstersIgnoreDisguises: false
# Sigh. People are going to want this.
# So lets make your disguise blown if you are attacked..
# Works only for disguised players when attacked by a entity (arrow, monster. etc)
# This will blow all disguises he has on him
BlowDisguises: false
BlownDisguiseMessage: '&cYour disguise was blown!'
# A option to choose how many seconds a DisguiseEntity command is valid for people to right click a entity to disguise it before expiring
DisguiseEntityExpire: 10
# Another option to choose the same thing for DisguiseClone command
DisguiseCloneExpire: 10
# Max disguises to store at a time with the DisguiseClone command
DisguiseCloneSize: 3
# This I don't really recommend turning on as it can make a memory leak..
# These disguises, as normal will not persist after a server restart.
# There is also no EntityDeath option as entities do not revive after death.
KeepDisguises:
EntityDespawn: false
PlayerDeath: false
PlayerLogout: false
# This controls if a entitys max health is determined by the entity, or by the disguise.
# Wither is 200, a player is 20. With this enabled, a player disguised as a wither will have the boss bar health accurate to the players health.
# Else it will be 1/20 of the boss bar when he is full health.
# Setting this in LivingWatcher overrides both values.
MaxHealthDeterminedByEntity: true
# This here is a option to turn off misc disguises.
# This means you can not have a living entity disguise as a non-living entity.
# This disables the Attributes packet, Non-living entities can still disguise as other non-living
# This means that the above option will not work as it uses the attribute packet.
MiscDisguisesForLiving: true
# Turn this to true to have players undisguised when switching worlds
UndisguiseOnWorldChange: false
# This will help performance, especially with CPU
# Due to safety reasons, self disguises can never have their packets disabled.
PacketsEnabled:
# This disables the animation packet. If a disguised entity sends a animation packet and they are using a non-living disguise. People will crash.
# Disabling this also means that if a player disguised as a non-player leaves a bug. People will crash
Animation: true
# Disabling this means that you can't use the setSleeping option on a player disguise. Also you will crash anyone watching when you try to sleep in a bed if disguised as a non-player
# This also sends a chunk packet at key positions else it doesn't work for 1.8. Lazyness means it does it for older versions too currently.
Bed: true
# This disguises the collect packet. If a living entity disguised as a non-living entity picks up a item. People will crash. This fixes it
# This also fixes people crashing if a item disguised as a sleeping player is picked up - Only true if Bed is enabled as well
Collect: true
# This disables a fix for when a disguised entity wearing armor dies, if the disguise can wear armor. It drops unpickupable items to anyone watching.
EntityStatus: true
# Entity equipment is the packets that are sent to ensure that a disguise has or doesn't have armor, and their held item.
# Disabling this means that any disguises which can wear armor or hold items will show the armor/held item that the disguised is wearing.
Equipment: true
# This doesn't actually disable the packet. It would introduce problems. Instead it does the next best thing and caches the data.
# This means that entity metadata will not change, and will only be sent in the spawn packet.
# This is good if performance is extremely in need.
# This is bad to disable unless you are ONLY going to use the disguises for decorations.
# To be honest. This is basically "Disable entity animations". That option is called 'AddEntityAnimations' in the config but unlike that, this is always in effect.
# Animations set by use of the api or through the disguise command are still in effect.
Metadata: true
# Movement packets are the biggest cpu hit. These are majorly used to ensure that the disguises facing direction isn't bugged up.
# If you are using the Item_Frame disguise, when a packet is sent (Roughly every 2min) the disguise will bug up until they move.
Movement: true
# Disable this if you don't mind crashing everytime you see someone riding something disguised as a non-living entity
Riding: true
# When disguised as a wither skull, it sends a look packet every tick so that the wither skull is facing the right way.
WitherSkull: true

View File

@@ -0,0 +1,79 @@
name: LibsDisguises
main: me.libraryaddict.disguise.LibsDisguises
version: 8.3 Unofficial
author: libraryaddict
authors: [Byteflux, Navid K.]
depend: [ProtocolLib]
commands:
libsdisguises:
permission: libsdisguises.seecmd.libsdisguises
disguise:
aliases: [d, dis]
permission: libsdisguises.seecmd.disguise
disguiseentity:
aliases: [dentity, disentity]
permission: libsdisguises.seecmd.disguiseentity
disguisehelp:
aliases: [dhelp, dishelp]
permission: libsdisguises.seecmd.disguisehelp
disguiseplayer:
aliases: [dplayer, displayer]
permission: libsdisguises.seecmd.disguiseplayer
disguiseradius:
aliases: [disradius, dradius]
permission: libsdisguises.seecmd.disguiseradius
undisguise:
aliases: [u, und, undis]
permission: libsdisguises.seecmd.undisguise
undisguiseentity:
aliases: [undisentity, undentity]
permission: libsdisguises.seecmd.undisguiseentity
undisguiseplayer:
aliases: [undisplayer, undplayer]
permission: libsdisguises.seecmd.undisguiseplayer
undisguiseradius:
aliases: [undisradius, undradius]
permission: libsdisguises.seecmd.undisguiseradius
disguiseclone:
aliases: [disguisec, disc, disclone, dclone, clonedisguise, clonedis, cdisguise, cdis]
permission: libsdisguises.seecmd.disguiseclone
permissions:
libsdisguises.seecmd:
description: See all commands in tab-completion
default: true
children:
libsdisguises.seecmd.libsdisguises: true
libsdisguises.seecmd.disguise: true
libsdisguises.seecmd.disguiseentity: true
libsdisguises.seecmd.disguisehelp: true
libsdisguises.seecmd.disguiseplayer: true
libsdisguises.seecmd.disguiseradius: true
libsdisguises.seecmd.undisguise: true
libsdisguises.seecmd.undisguiseentity: true
libsdisguises.seecmd.undisguiseplayer: true
libsdisguises.seecmd.undisguiseradius: true
libsdisguises.seecmd.disguiseclone: true
libsdisguises.seecmd.libsdisguises:
description: See the /libsdisguises command in tab-completion
libsdisguises.seecmd.disguise:
description: See the /disguise command in tab-completion
libsdisguises.seecmd.disguiseentity:
description: See the /disguiseentity command in tab-completion
libsdisguises.seecmd.disguisehelp:
description: See the /disguisehelp command in tab-completion
libsdisguises.seecmd.disguiseplayer:
description: See the /disguiseplayer command in tab-completion
libsdisguises.seecmd.disguiseradius:
description: See the /disguiseradius command in tab-completion
libsdisguises.seecmd.undisguise:
description: See the /undisguise command in tab-completion
libsdisguises.seecmd.undisguiseentity:
description: See the /undisguiseentity command in tab-completion
libsdisguises.seecmd.undisguiseplayer:
description: See the /undisguiseplayer command in tab-completion
libsdisguises.seecmd.undisguiseradius:
description: See the /undisguiseradius command in tab-completion
libsdisguises.seecmd.disguiseclone:
description: See the /disguiseclone command in tab-completion

View File

@@ -1,178 +0,0 @@
package me.libraryaddict.disguise.disguisetypes;
import org.bukkit.entity.Animals;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Monster;
public enum FutureDisguiseType {
ARMOR_STAND(Entity.class, 30, 2, new float[] { 0F, 0F, 0F }, new Object[] {
1, (short) 300,
2, "",
3, (byte) 0,
4, (byte) 0,
6, 1F,
7, 0,
8, (byte) 0,
9, (byte) 0,
10, (byte) 0,
// 11,
// 12,
// 13,
// 14,
// 15,
// 16
}),
ELDER_GUARDIAN(Monster.class, 68, 80, new float[] { 0F, 0F, 0F }, new Object[] {
1, (short) 300,
2, "",
3, (byte) 0,
4, (byte) 0,
6, 1F,
7, 0,
8, (byte) 0,
9, (byte) 0,
15, (byte) 0,
16, 0 | 4,
17, 0
}),
ENDERMITE(Monster.class, 67, 8, new float[] { 0F, 0F, 0F }, new Object[] {
0, (byte) 0,
1, (short) 300,
2, "",
3, (byte) 0,
4, (byte) 0,
6, 1F,
7, 0,
8, (byte) 0,
9, (byte) 0,
15, (byte) 0
}),
GUARDIAN(Monster.class, 68, 30, new float[] { 0F, 0F, 0F }, new Object[] {
1, (short) 300,
2, "",
3, (byte) 0,
4, (byte) 0,
6, 1F,
7, 0,
8, (byte) 0,
9, (byte) 0,
15, (byte) 0,
16, 0,
17, 0
}),
RABBIT(Animals.class, 101, 10, new float[] { 0F, 0F, 0F }, new Object[] { 1, (short) 300,
2, "",
3, (byte) 0,
4, (byte) 0,
6, 1F,
7, 0,
8, (byte) 0,
9, (byte) 0,
12, 0,
15, (byte) 0,
18, (byte) 0
});
private float[] boundingBox;
private Object[] dataWatcher;
private Class<? extends Entity> entityClass;
private int entityId;
private float maxHealth;
private FutureDisguiseType(Class<? extends Entity> entityClass, int entityId, float maxHealth, float[] boundingBox,
Object[] watcherValues) {
this.entityClass = entityClass;
this.dataWatcher = watcherValues;
this.boundingBox = boundingBox;
if (watcherValues.length % 2 != 0) {
System.out.print("Error! " + name() + " has odd number of params!");
}
this.entityId = entityId;
}
public float[] getBoundingBox() {
return boundingBox;
}
public Object[] getDataWatcher() {
return dataWatcher;
}
public Class<? extends Entity> getEntityClass() {
return entityClass;
}
public int getEntityId() {
return entityId;
}
public float getMaxHealth() {
return maxHealth;
}
public boolean isAlive() {
return this != ARMOR_STAND;
}
}