diff --git a/.gitignore b/.gitignore index 5ac01408..e07b945b 100644 --- a/.gitignore +++ b/.gitignore @@ -16,6 +16,10 @@ local.properties .settings/ .loadpath target/ +build +lib +dist + # External tool builders .externalToolBuilders/ @@ -214,3 +218,4 @@ pip-log.txt #Mr Developer .mr.developer.cfg +/.nb-gradle/private/ \ No newline at end of file diff --git a/.gradle/2.2.1/taskArtifacts/cache.properties b/.gradle/2.2.1/taskArtifacts/cache.properties new file mode 100644 index 00000000..6dc41ef8 --- /dev/null +++ b/.gradle/2.2.1/taskArtifacts/cache.properties @@ -0,0 +1 @@ +#Thu Feb 26 11:28:25 EST 2015 diff --git a/.gradle/2.2.1/taskArtifacts/cache.properties.lock b/.gradle/2.2.1/taskArtifacts/cache.properties.lock new file mode 100644 index 00000000..9a517eb0 Binary files /dev/null and b/.gradle/2.2.1/taskArtifacts/cache.properties.lock differ diff --git a/.gradle/2.2.1/taskArtifacts/fileHashes.bin b/.gradle/2.2.1/taskArtifacts/fileHashes.bin new file mode 100644 index 00000000..7be4435d Binary files /dev/null and b/.gradle/2.2.1/taskArtifacts/fileHashes.bin differ diff --git a/.gradle/2.2.1/taskArtifacts/fileSnapshots.bin b/.gradle/2.2.1/taskArtifacts/fileSnapshots.bin new file mode 100644 index 00000000..6ec0eca1 Binary files /dev/null and b/.gradle/2.2.1/taskArtifacts/fileSnapshots.bin differ diff --git a/.gradle/2.2.1/taskArtifacts/outputFileStates.bin b/.gradle/2.2.1/taskArtifacts/outputFileStates.bin new file mode 100644 index 00000000..fd04df11 Binary files /dev/null and b/.gradle/2.2.1/taskArtifacts/outputFileStates.bin differ diff --git a/.gradle/2.2.1/taskArtifacts/taskArtifacts.bin b/.gradle/2.2.1/taskArtifacts/taskArtifacts.bin new file mode 100644 index 00000000..96726ea8 Binary files /dev/null and b/.gradle/2.2.1/taskArtifacts/taskArtifacts.bin differ diff --git a/build.gradle b/build.gradle new file mode 100644 index 00000000..0caa3150 --- /dev/null +++ b/build.gradle @@ -0,0 +1,57 @@ +apply plugin: 'java' + +sourceCompatibility = '1.8' +ext.spigotVersion = '1.8.3-R0.1-SNAPSHOT' + +[compileJava, compileTestJava]*.options*.encoding = 'UTF-8' + +repositories { + + mavenCentral() + + maven { + name 'Spigot' + url 'https://hub.spigotmc.org/nexus/content/groups/public/' + } + + maven { + name 'Vault-Repo' + url 'http://nexus.theyeticave.net/content/repositories/pub_releases' + } + + maven { + name 'shadowvolt-repo' + url 'http://ci.shadowvolt.com/plugin/repository/everything' + } +} + +tasks.build.doLast { + File export = file('build/libs/LibsDisguises.jar') + File dest = file('dist') + dest.mkdir() + dest.listFiles().each { + it.delete() + } + export.renameTo(new File(dest, "LibsDisguises.jar")) + file('build').delete() + println "Copied LibsDisguises.jar into /dist" + println "LibsDisguises is finished compiling, have a nice day!" +} + +file('libs').mkdirs() + +//Retrieves spigot-1.8.jar server file from link +ant.get src: 'https://www.dropbox.com/s/k7simfgpdun3f8q/spigot-1.8.jar?dl=1', dest: file('libs'), verbose: false, skipexisting: true + +jar { + baseName "LibsDisguises" +} + +dependencies { + compile files( + 'libs/spigot-1.8.jar' + ) + compile 'org.bukkit:bukkit:' + project.ext.spigotVersion + compile 'com.comphenix.protocol:ProtocolLib:3.6.3-SNAPSHOT' + testCompile group: 'junit', name: 'junit', version: '4.10' +} diff --git a/libs/spigot-1.8.jar b/libs/spigot-1.8.jar new file mode 100644 index 00000000..e80458bb Binary files /dev/null and b/libs/spigot-1.8.jar differ diff --git a/pom.xml b/pom.xml deleted file mode 100644 index 4c7131ab..00000000 --- a/pom.xml +++ /dev/null @@ -1,107 +0,0 @@ - - 4.0.0 - LibsDisguises - LibsDisguises - 8.2.6-SNAPSHOT - - - src - test - clean package - target - LibsDisguises - - - maven-compiler-plugin - 2.3.2 - - 1.6 - 1.6 - - - - org.apache.maven.plugins - maven-shade-plugin - 1.5 - - - package - - shade - - - - - com.fasterxml.uuid:java-uuid-generator - - - - - - - - - - . - true - ${project.basedir} - - plugin.yml - config.yml - README.md - - - - - - UTF-8 - - - - - md_5-repo - http://repo.md-5.net/content/groups/public/ - - - shadowvolt-repo - Shadowvolt Maven Repository - http://ci.shadowvolt.com/plugin/repository/everything/ - - - - - - com.comphenix.protocol - ProtocolLib - 3.6.3-SNAPSHOT - - - org.spigotmc - spigot-api - 1.7.8-R0.1-SNAPSHOT - - - junit - junit - 4.11 - test - - - org.spigotmc - spigot - 1.7.10-R0.1-SNAPSHOT - - - - - - md_5-releases - http://repo.md-5.net/content/repositories/releases/ - - - md_5-snapshots - http://repo.md-5.net/content/repositories/snapshots/ - - - \ No newline at end of file diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 00000000..f0b731cb --- /dev/null +++ b/settings.gradle @@ -0,0 +1 @@ +rootProject.name = 'LibsDisguises' diff --git a/src/me/libraryaddict/disguise/DisguiseAPI.java b/src/main/java/me/libraryaddict/disguise/DisguiseAPI.java similarity index 100% rename from src/me/libraryaddict/disguise/DisguiseAPI.java rename to src/main/java/me/libraryaddict/disguise/DisguiseAPI.java diff --git a/src/me/libraryaddict/disguise/DisguiseConfig.java b/src/main/java/me/libraryaddict/disguise/DisguiseConfig.java similarity index 100% rename from src/me/libraryaddict/disguise/DisguiseConfig.java rename to src/main/java/me/libraryaddict/disguise/DisguiseConfig.java diff --git a/src/me/libraryaddict/disguise/DisguiseListener.java b/src/main/java/me/libraryaddict/disguise/DisguiseListener.java similarity index 100% rename from src/me/libraryaddict/disguise/DisguiseListener.java rename to src/main/java/me/libraryaddict/disguise/DisguiseListener.java diff --git a/src/me/libraryaddict/disguise/LibsDisguises.java b/src/main/java/me/libraryaddict/disguise/LibsDisguises.java similarity index 90% rename from src/me/libraryaddict/disguise/LibsDisguises.java rename to src/main/java/me/libraryaddict/disguise/LibsDisguises.java index b349c27b..35adfd10 100644 --- a/src/me/libraryaddict/disguise/LibsDisguises.java +++ b/src/main/java/me/libraryaddict/disguise/LibsDisguises.java @@ -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; } diff --git a/src/me/libraryaddict/disguise/commands/DisguiseCloneCommand.java b/src/main/java/me/libraryaddict/disguise/commands/DisguiseCloneCommand.java similarity index 100% rename from src/me/libraryaddict/disguise/commands/DisguiseCloneCommand.java rename to src/main/java/me/libraryaddict/disguise/commands/DisguiseCloneCommand.java diff --git a/src/me/libraryaddict/disguise/commands/DisguiseCommand.java b/src/main/java/me/libraryaddict/disguise/commands/DisguiseCommand.java similarity index 100% rename from src/me/libraryaddict/disguise/commands/DisguiseCommand.java rename to src/main/java/me/libraryaddict/disguise/commands/DisguiseCommand.java diff --git a/src/me/libraryaddict/disguise/commands/DisguiseEntityCommand.java b/src/main/java/me/libraryaddict/disguise/commands/DisguiseEntityCommand.java similarity index 100% rename from src/me/libraryaddict/disguise/commands/DisguiseEntityCommand.java rename to src/main/java/me/libraryaddict/disguise/commands/DisguiseEntityCommand.java diff --git a/src/me/libraryaddict/disguise/commands/DisguiseHelpCommand.java b/src/main/java/me/libraryaddict/disguise/commands/DisguiseHelpCommand.java similarity index 100% rename from src/me/libraryaddict/disguise/commands/DisguiseHelpCommand.java rename to src/main/java/me/libraryaddict/disguise/commands/DisguiseHelpCommand.java diff --git a/src/me/libraryaddict/disguise/commands/DisguisePlayerCommand.java b/src/main/java/me/libraryaddict/disguise/commands/DisguisePlayerCommand.java similarity index 100% rename from src/me/libraryaddict/disguise/commands/DisguisePlayerCommand.java rename to src/main/java/me/libraryaddict/disguise/commands/DisguisePlayerCommand.java diff --git a/src/me/libraryaddict/disguise/commands/DisguiseRadiusCommand.java b/src/main/java/me/libraryaddict/disguise/commands/DisguiseRadiusCommand.java similarity index 100% rename from src/me/libraryaddict/disguise/commands/DisguiseRadiusCommand.java rename to src/main/java/me/libraryaddict/disguise/commands/DisguiseRadiusCommand.java diff --git a/src/me/libraryaddict/disguise/commands/LibsDisguisesCommand.java b/src/main/java/me/libraryaddict/disguise/commands/LibsDisguisesCommand.java similarity index 100% rename from src/me/libraryaddict/disguise/commands/LibsDisguisesCommand.java rename to src/main/java/me/libraryaddict/disguise/commands/LibsDisguisesCommand.java diff --git a/src/me/libraryaddict/disguise/commands/UndisguiseCommand.java b/src/main/java/me/libraryaddict/disguise/commands/UndisguiseCommand.java similarity index 100% rename from src/me/libraryaddict/disguise/commands/UndisguiseCommand.java rename to src/main/java/me/libraryaddict/disguise/commands/UndisguiseCommand.java diff --git a/src/me/libraryaddict/disguise/commands/UndisguiseEntityCommand.java b/src/main/java/me/libraryaddict/disguise/commands/UndisguiseEntityCommand.java similarity index 100% rename from src/me/libraryaddict/disguise/commands/UndisguiseEntityCommand.java rename to src/main/java/me/libraryaddict/disguise/commands/UndisguiseEntityCommand.java diff --git a/src/me/libraryaddict/disguise/commands/UndisguisePlayerCommand.java b/src/main/java/me/libraryaddict/disguise/commands/UndisguisePlayerCommand.java similarity index 100% rename from src/me/libraryaddict/disguise/commands/UndisguisePlayerCommand.java rename to src/main/java/me/libraryaddict/disguise/commands/UndisguisePlayerCommand.java diff --git a/src/me/libraryaddict/disguise/commands/UndisguiseRadiusCommand.java b/src/main/java/me/libraryaddict/disguise/commands/UndisguiseRadiusCommand.java similarity index 100% rename from src/me/libraryaddict/disguise/commands/UndisguiseRadiusCommand.java rename to src/main/java/me/libraryaddict/disguise/commands/UndisguiseRadiusCommand.java diff --git a/src/me/libraryaddict/disguise/disguisetypes/AnimalColor.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/AnimalColor.java similarity index 100% rename from src/me/libraryaddict/disguise/disguisetypes/AnimalColor.java rename to src/main/java/me/libraryaddict/disguise/disguisetypes/AnimalColor.java diff --git a/src/me/libraryaddict/disguise/disguisetypes/Disguise.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/Disguise.java similarity index 99% rename from src/me/libraryaddict/disguise/disguisetypes/Disguise.java rename to src/main/java/me/libraryaddict/disguise/disguisetypes/Disguise.java index 290811bb..6a492c6e 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/Disguise.java +++ b/src/main/java/me/libraryaddict/disguise/disguisetypes/Disguise.java @@ -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) { diff --git a/src/me/libraryaddict/disguise/disguisetypes/DisguiseType.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/DisguiseType.java similarity index 85% rename from src/me/libraryaddict/disguise/disguisetypes/DisguiseType.java rename to src/main/java/me/libraryaddict/disguise/disguisetypes/DisguiseType.java index 664792bd..b811f723 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/DisguiseType.java +++ b/src/main/java/me/libraryaddict/disguise/disguisetypes/DisguiseType.java @@ -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 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 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() { diff --git a/src/me/libraryaddict/disguise/disguisetypes/FlagWatcher.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/FlagWatcher.java similarity index 98% rename from src/me/libraryaddict/disguise/disguisetypes/FlagWatcher.java rename to src/main/java/me/libraryaddict/disguise/disguisetypes/FlagWatcher.java index 2d542a20..a16a4348 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/FlagWatcher.java +++ b/src/main/java/me/libraryaddict/disguise/disguisetypes/FlagWatcher.java @@ -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) { diff --git a/src/me/libraryaddict/disguise/disguisetypes/MiscDisguise.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/MiscDisguise.java similarity index 100% rename from src/me/libraryaddict/disguise/disguisetypes/MiscDisguise.java rename to src/main/java/me/libraryaddict/disguise/disguisetypes/MiscDisguise.java diff --git a/src/me/libraryaddict/disguise/disguisetypes/MobDisguise.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/MobDisguise.java similarity index 100% rename from src/me/libraryaddict/disguise/disguisetypes/MobDisguise.java rename to src/main/java/me/libraryaddict/disguise/disguisetypes/MobDisguise.java diff --git a/src/me/libraryaddict/disguise/disguisetypes/PlayerDisguise.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/PlayerDisguise.java similarity index 85% rename from src/me/libraryaddict/disguise/disguisetypes/PlayerDisguise.java rename to src/main/java/me/libraryaddict/disguise/disguisetypes/PlayerDisguise.java index 0746a3bb..08dd21a0 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/PlayerDisguise.java +++ b/src/main/java/me/libraryaddict/disguise/disguisetypes/PlayerDisguise.java @@ -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; diff --git a/src/me/libraryaddict/disguise/disguisetypes/RabbitType.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/RabbitType.java similarity index 100% rename from src/me/libraryaddict/disguise/disguisetypes/RabbitType.java rename to src/main/java/me/libraryaddict/disguise/disguisetypes/RabbitType.java diff --git a/src/me/libraryaddict/disguise/disguisetypes/TargetedDisguise.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/TargetedDisguise.java similarity index 100% rename from src/me/libraryaddict/disguise/disguisetypes/TargetedDisguise.java rename to src/main/java/me/libraryaddict/disguise/disguisetypes/TargetedDisguise.java diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/AgeableWatcher.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/AgeableWatcher.java similarity index 82% rename from src/me/libraryaddict/disguise/disguisetypes/watchers/AgeableWatcher.java rename to src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/AgeableWatcher.java index fcc24855..b164717e 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/AgeableWatcher.java +++ b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/AgeableWatcher.java @@ -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); } diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/ArmorStandWatcher.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/ArmorStandWatcher.java similarity index 100% rename from src/me/libraryaddict/disguise/disguisetypes/watchers/ArmorStandWatcher.java rename to src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/ArmorStandWatcher.java diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/ArrowWatcher.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/ArrowWatcher.java similarity index 100% rename from src/me/libraryaddict/disguise/disguisetypes/watchers/ArrowWatcher.java rename to src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/ArrowWatcher.java diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/BatWatcher.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/BatWatcher.java similarity index 100% rename from src/me/libraryaddict/disguise/disguisetypes/watchers/BatWatcher.java rename to src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/BatWatcher.java diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/BlazeWatcher.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/BlazeWatcher.java similarity index 100% rename from src/me/libraryaddict/disguise/disguisetypes/watchers/BlazeWatcher.java rename to src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/BlazeWatcher.java diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/BoatWatcher.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/BoatWatcher.java similarity index 100% rename from src/me/libraryaddict/disguise/disguisetypes/watchers/BoatWatcher.java rename to src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/BoatWatcher.java diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/CreeperWatcher.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/CreeperWatcher.java similarity index 100% rename from src/me/libraryaddict/disguise/disguisetypes/watchers/CreeperWatcher.java rename to src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/CreeperWatcher.java diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/DroppedItemWatcher.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/DroppedItemWatcher.java similarity index 100% rename from src/me/libraryaddict/disguise/disguisetypes/watchers/DroppedItemWatcher.java rename to src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/DroppedItemWatcher.java diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/EndermanWatcher.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/EndermanWatcher.java similarity index 94% rename from src/me/libraryaddict/disguise/disguisetypes/watchers/EndermanWatcher.java rename to src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/EndermanWatcher.java index 14323bb1..23912f5a 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/EndermanWatcher.java +++ b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/EndermanWatcher.java @@ -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)); } diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/FallingBlockWatcher.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/FallingBlockWatcher.java similarity index 100% rename from src/me/libraryaddict/disguise/disguisetypes/watchers/FallingBlockWatcher.java rename to src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/FallingBlockWatcher.java diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/GhastWatcher.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/GhastWatcher.java similarity index 100% rename from src/me/libraryaddict/disguise/disguisetypes/watchers/GhastWatcher.java rename to src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/GhastWatcher.java diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/GuardianWatcher.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/GuardianWatcher.java similarity index 100% rename from src/me/libraryaddict/disguise/disguisetypes/watchers/GuardianWatcher.java rename to src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/GuardianWatcher.java diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/HorseWatcher.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/HorseWatcher.java similarity index 100% rename from src/me/libraryaddict/disguise/disguisetypes/watchers/HorseWatcher.java rename to src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/HorseWatcher.java diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/ItemFrameWatcher.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/ItemFrameWatcher.java similarity index 78% rename from src/me/libraryaddict/disguise/disguisetypes/watchers/ItemFrameWatcher.java rename to src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/ItemFrameWatcher.java index 5893f269..e50d6cb4 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/ItemFrameWatcher.java +++ b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/ItemFrameWatcher.java @@ -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); } } diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/LivingWatcher.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/LivingWatcher.java similarity index 100% rename from src/me/libraryaddict/disguise/disguisetypes/watchers/LivingWatcher.java rename to src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/LivingWatcher.java diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/MinecartWatcher.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/MinecartWatcher.java similarity index 100% rename from src/me/libraryaddict/disguise/disguisetypes/watchers/MinecartWatcher.java rename to src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/MinecartWatcher.java diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/OcelotWatcher.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/OcelotWatcher.java similarity index 100% rename from src/me/libraryaddict/disguise/disguisetypes/watchers/OcelotWatcher.java rename to src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/OcelotWatcher.java diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/PaintingWatcher.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/PaintingWatcher.java similarity index 100% rename from src/me/libraryaddict/disguise/disguisetypes/watchers/PaintingWatcher.java rename to src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/PaintingWatcher.java diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/PigWatcher.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/PigWatcher.java similarity index 100% rename from src/me/libraryaddict/disguise/disguisetypes/watchers/PigWatcher.java rename to src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/PigWatcher.java diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/PlayerWatcher.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/PlayerWatcher.java similarity index 98% rename from src/me/libraryaddict/disguise/disguisetypes/watchers/PlayerWatcher.java rename to src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/PlayerWatcher.java index c17adb50..6cd3206e 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/PlayerWatcher.java +++ b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/PlayerWatcher.java @@ -110,7 +110,7 @@ public class PlayerWatcher extends LivingWatcher { PacketContainer packet = new PacketContainer(PacketType.Play.Server.ANIMATION); StructureModifier 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); diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/RabbitWatcher.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/RabbitWatcher.java similarity index 100% rename from src/me/libraryaddict/disguise/disguisetypes/watchers/RabbitWatcher.java rename to src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/RabbitWatcher.java diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/SheepWatcher.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/SheepWatcher.java similarity index 100% rename from src/me/libraryaddict/disguise/disguisetypes/watchers/SheepWatcher.java rename to src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/SheepWatcher.java diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/SlimeWatcher.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/SlimeWatcher.java similarity index 100% rename from src/me/libraryaddict/disguise/disguisetypes/watchers/SlimeWatcher.java rename to src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/SlimeWatcher.java diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/SplashPotionWatcher.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/SplashPotionWatcher.java similarity index 100% rename from src/me/libraryaddict/disguise/disguisetypes/watchers/SplashPotionWatcher.java rename to src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/SplashPotionWatcher.java diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/TameableWatcher.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/TameableWatcher.java similarity index 100% rename from src/me/libraryaddict/disguise/disguisetypes/watchers/TameableWatcher.java rename to src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/TameableWatcher.java diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/VillagerWatcher.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/VillagerWatcher.java similarity index 100% rename from src/me/libraryaddict/disguise/disguisetypes/watchers/VillagerWatcher.java rename to src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/VillagerWatcher.java diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/WitherSkullWatcher.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/WitherSkullWatcher.java similarity index 100% rename from src/me/libraryaddict/disguise/disguisetypes/watchers/WitherSkullWatcher.java rename to src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/WitherSkullWatcher.java diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/WitherWatcher.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/WitherWatcher.java similarity index 100% rename from src/me/libraryaddict/disguise/disguisetypes/watchers/WitherWatcher.java rename to src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/WitherWatcher.java diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/WolfWatcher.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/WolfWatcher.java similarity index 100% rename from src/me/libraryaddict/disguise/disguisetypes/watchers/WolfWatcher.java rename to src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/WolfWatcher.java diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/ZombieWatcher.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/ZombieWatcher.java similarity index 100% rename from src/me/libraryaddict/disguise/disguisetypes/watchers/ZombieWatcher.java rename to src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/ZombieWatcher.java diff --git a/src/me/libraryaddict/disguise/events/DisguiseEvent.java b/src/main/java/me/libraryaddict/disguise/events/DisguiseEvent.java similarity index 100% rename from src/me/libraryaddict/disguise/events/DisguiseEvent.java rename to src/main/java/me/libraryaddict/disguise/events/DisguiseEvent.java diff --git a/src/me/libraryaddict/disguise/events/UndisguiseEvent.java b/src/main/java/me/libraryaddict/disguise/events/UndisguiseEvent.java similarity index 100% rename from src/me/libraryaddict/disguise/events/UndisguiseEvent.java rename to src/main/java/me/libraryaddict/disguise/events/UndisguiseEvent.java diff --git a/src/me/libraryaddict/disguise/utilities/BaseDisguiseCommand.java b/src/main/java/me/libraryaddict/disguise/utilities/BaseDisguiseCommand.java similarity index 99% rename from src/me/libraryaddict/disguise/utilities/BaseDisguiseCommand.java rename to src/main/java/me/libraryaddict/disguise/utilities/BaseDisguiseCommand.java index 9bd47717..0b65d65b 100644 --- a/src/me/libraryaddict/disguise/utilities/BaseDisguiseCommand.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/BaseDisguiseCommand.java @@ -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)) { diff --git a/src/me/libraryaddict/disguise/utilities/ClassGetter.java b/src/main/java/me/libraryaddict/disguise/utilities/ClassGetter.java similarity index 100% rename from src/me/libraryaddict/disguise/utilities/ClassGetter.java rename to src/main/java/me/libraryaddict/disguise/utilities/ClassGetter.java diff --git a/src/me/libraryaddict/disguise/utilities/DisguiseSound.java b/src/main/java/me/libraryaddict/disguise/utilities/DisguiseSound.java similarity index 98% rename from src/me/libraryaddict/disguise/utilities/DisguiseSound.java rename to src/main/java/me/libraryaddict/disguise/utilities/DisguiseSound.java index 801cbd82..58441500 100644 --- a/src/me/libraryaddict/disguise/utilities/DisguiseSound.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/DisguiseSound.java @@ -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"), diff --git a/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java b/src/main/java/me/libraryaddict/disguise/utilities/DisguiseUtilities.java similarity index 88% rename from src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java rename to src/main/java/me/libraryaddict/disguise/utilities/DisguiseUtilities.java index df8eb691..e9982bc3 100644 --- a/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/DisguiseUtilities.java @@ -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 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 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 rebuildForVersion(Player player, FlagWatcher watcher, List list) { - if (!LibVersion.is1_8()) + if (true) // Use for future protocol compatibility return list; ArrayList rebuiltList = new ArrayList(); ArrayList backups = new ArrayList(); - // 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 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(); diff --git a/src/me/libraryaddict/disguise/utilities/DisguiseValues.java b/src/main/java/me/libraryaddict/disguise/utilities/DisguiseValues.java similarity index 100% rename from src/me/libraryaddict/disguise/utilities/DisguiseValues.java rename to src/main/java/me/libraryaddict/disguise/utilities/DisguiseValues.java diff --git a/src/me/libraryaddict/disguise/utilities/FakeBoundingBox.java b/src/main/java/me/libraryaddict/disguise/utilities/FakeBoundingBox.java similarity index 100% rename from src/me/libraryaddict/disguise/utilities/FakeBoundingBox.java rename to src/main/java/me/libraryaddict/disguise/utilities/FakeBoundingBox.java diff --git a/src/me/libraryaddict/disguise/utilities/LibsProfileLookup.java b/src/main/java/me/libraryaddict/disguise/utilities/LibsProfileLookup.java similarity index 100% rename from src/me/libraryaddict/disguise/utilities/LibsProfileLookup.java rename to src/main/java/me/libraryaddict/disguise/utilities/LibsProfileLookup.java diff --git a/src/me/libraryaddict/disguise/utilities/LibsProfileLookupCaller.java b/src/main/java/me/libraryaddict/disguise/utilities/LibsProfileLookupCaller.java similarity index 81% rename from src/me/libraryaddict/disguise/utilities/LibsProfileLookupCaller.java rename to src/main/java/me/libraryaddict/disguise/utilities/LibsProfileLookupCaller.java index 5b46e681..49c9213f 100644 --- a/src/me/libraryaddict/disguise/utilities/LibsProfileLookupCaller.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/LibsProfileLookupCaller.java @@ -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; diff --git a/src/me/libraryaddict/disguise/utilities/PacketsManager.java b/src/main/java/me/libraryaddict/disguise/utilities/PacketsManager.java similarity index 97% rename from src/me/libraryaddict/disguise/utilities/PacketsManager.java rename to src/main/java/me/libraryaddict/disguise/utilities/PacketsManager.java index d64ca7ea..0a8bb056 100644 --- a/src/me/libraryaddict/disguise/utilities/PacketsManager.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/PacketsManager.java @@ -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 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 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 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 intMods = spawnPackets[0].getIntegers(); intMods.write(0, disguisedEntity.getEntityId()); @@ -266,22 +264,23 @@ public class PacketsManager { } } - if (LibVersion.is1_8()) { - ArrayList newPackets = new ArrayList(); - 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 newPackets = new ArrayList(); + 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 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 }; } } diff --git a/src/me/libraryaddict/disguise/utilities/ReflectionManager.java b/src/main/java/me/libraryaddict/disguise/utilities/ReflectionManager.java similarity index 79% rename from src/me/libraryaddict/disguise/utilities/ReflectionManager.java rename to src/main/java/me/libraryaddict/disguise/utilities/ReflectionManager.java index 16c37256..fb6b1897 100644 --- a/src/me/libraryaddict/disguise/utilities/ReflectionManager.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/ReflectionManager.java @@ -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>> ForgeMethodMappings; private static final Method ihmGet; - private static HashMap is1_8 = new HashMap(); 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(); } } + } diff --git a/src/me/libraryaddict/disguise/utilities/UpdateChecker.java b/src/main/java/me/libraryaddict/disguise/utilities/UpdateChecker.java similarity index 100% rename from src/me/libraryaddict/disguise/utilities/UpdateChecker.java rename to src/main/java/me/libraryaddict/disguise/utilities/UpdateChecker.java diff --git a/config.yml b/src/main/resources/config.yml similarity index 100% rename from config.yml rename to src/main/resources/config.yml diff --git a/plugin.yml b/src/main/resources/plugin.yml similarity index 98% rename from plugin.yml rename to src/main/resources/plugin.yml index 6dc23013..9efc1c55 100644 --- a/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,7 +1,8 @@ name: LibsDisguises main: me.libraryaddict.disguise.LibsDisguises -version: ${project.version} +version: 8.3 Unofficial author: libraryaddict +authors: [Byteflux, Navid K.] depend: [ProtocolLib] commands: libsdisguises: diff --git a/src/me/libraryaddict/disguise/disguisetypes/FutureDisguiseType.java b/src/me/libraryaddict/disguise/disguisetypes/FutureDisguiseType.java deleted file mode 100644 index 1bf57b83..00000000 --- a/src/me/libraryaddict/disguise/disguisetypes/FutureDisguiseType.java +++ /dev/null @@ -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 entityClass; - private int entityId; - private float maxHealth; - - private FutureDisguiseType(Class 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 getEntityClass() { - return entityClass; - } - - public int getEntityId() { - return entityId; - } - - public float getMaxHealth() { - return maxHealth; - } - - public boolean isAlive() { - return this != ARMOR_STAND; - } - -}