Added new entities to DisguiseType

Changed entity Ids to reflect new entity Ids in Spigot 1.9
Cleaned up code
This commit is contained in:
NavidK0 2016-02-19 15:29:53 -05:00
parent 9847ff035a
commit 50623a9be2
27 changed files with 121 additions and 161 deletions

View File

@ -9,7 +9,7 @@ println 'Compiling LibsDisguises via Gradle ver. ' + gradle.gradleVersion
sourceCompatibility = '1.7'
ext.spigotVersion = '1.8.8-R0.1-SNAPSHOT'
ext.disguisesVersion = '8.6.8'
ext.disguisesVersion = '9.0.0'
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'

View File

@ -63,7 +63,7 @@ public abstract class Disguise {
/**
* Seems I do this method so I can make cleaner constructors on disguises..
*
* @param newType
* @param newType The disguise
*/
protected void createDisguise(DisguiseType newType) {
if (getWatcher() != null) {
@ -73,7 +73,7 @@ public abstract class Disguise {
throw new RuntimeException(
"DisguiseType "
+ newType
+ " was used in a futile attempt to construct a disguise, but this version of craftbukkit does not have that entity");
+ " was used in a futile attempt to construct a disguise, but this version of Spigot does not have that entity");
}
// Set the disguise type
disguiseType = newType;
@ -103,7 +103,7 @@ public abstract class Disguise {
else if (getType() == DisguiseType.ZOMBIE_VILLAGER) {
getWatcher().setValue(13, (byte) 1);
} else if (getType() == DisguiseType.ELDER_GUARDIAN) {
getWatcher().setValue(16, 0 | 4);
getWatcher().setValue(16, 4);
} // Else if its a horse. Set the horse watcher type
else if (getWatcher() instanceof HorseWatcher) {
try {
@ -325,7 +325,7 @@ public abstract class Disguise {
/**
* Get the disguised entity
*
* @return
* @return entity
*/
public Entity getEntity() {
return entity;
@ -334,7 +334,7 @@ public abstract class Disguise {
/**
* Get the disguise type
*
* @return
* @return disguiseType
*/
public DisguiseType getType() {
return disguiseType;
@ -343,7 +343,7 @@ public abstract class Disguise {
/**
* Get the flag watcher
*
* @return
* @return flagWatcher
*/
public FlagWatcher getWatcher() {
return watcher;
@ -352,7 +352,7 @@ public abstract class Disguise {
/**
* In use doesn't mean that this disguise is active. It means that Lib's Disguises still stores a reference to the disguise. getEntity() can still return null if this disguise is active after despawn, logout, etc.
*
* @return
* @return isDisguiseInUse
*/
public boolean isDisguiseInUse() {
return disguiseInUse;
@ -396,16 +396,9 @@ public abstract class Disguise {
/**
* Internal use
*
* @return
*/
public boolean isRemoveDisguiseOnDeath() {
if (getEntity() == null) {
return true;
}
return getEntity() instanceof Player
? (!((Player) getEntity()).isOnline() ? !isKeepDisguiseOnPlayerLogout() : !isKeepDisguiseOnPlayerDeath())
: (!isKeepDisguiseOnEntityDespawn() || getEntity().isDead());
return getEntity() == null || (getEntity() instanceof Player ? (!((Player) getEntity()).isOnline() ? !isKeepDisguiseOnPlayerLogout() : !isKeepDisguiseOnPlayerDeath()) : (!isKeepDisguiseOnEntityDespawn() || getEntity().isDead()));
}
public boolean isSelfDisguiseSoundsReplaced() {
@ -415,7 +408,7 @@ public abstract class Disguise {
/**
* Can the disguised view himself as the disguise
*
* @return
* @return viewSelfDisguise
*/
public boolean isSelfDisguiseVisible() {
return viewSelfDisguise;
@ -441,7 +434,7 @@ public abstract class Disguise {
/**
* Removes the disguise and undisguises the entity if its using this disguise.
*
* @return
* @return removeDiguise
*/
public boolean removeDisguise() {
if (disguiseInUse) {
@ -505,7 +498,7 @@ public abstract class Disguise {
* Set the entity of the disguise. Only used for internal things.
*
* @param entity
* @return
* @return disguise
*/
public Disguise setEntity(Entity entity) {
if (this.getEntity() != null) {

View File

@ -12,6 +12,7 @@ import java.lang.reflect.Method;
public enum DisguiseType {
AREA_EFFECT_CLOUD, //Disguising as this would be something else.
ARMOR_STAND(78),
ARROW(60),
BAT,
@ -22,8 +23,9 @@ public enum DisguiseType {
COW,
CREEPER,
DONKEY,
DROPPED_ITEM(2, 1),
EGG(62),
DRAGON_FIREBALL(26),
DROPPED_ITEM(-1, 1),
EGG,
ELDER_GUARDIAN,
ENDER_CRYSTAL(51),
ENDER_DRAGON,
@ -35,7 +37,7 @@ public enum DisguiseType {
FALLING_BLOCK(70, 1),
FIREBALL(63, 0),
FIREWORK(76),
FISHING_HOOK(90),
FISHING_HOOK,
GHAST,
GIANT,
GUARDIAN,
@ -43,6 +45,7 @@ public enum DisguiseType {
IRON_GOLEM,
ITEM_FRAME(71),
LEASH_HITCH(77),
LIGHTING,
MAGMA_CUBE,
MINECART(10, 0),
MINECART_CHEST(10, 1),
@ -61,6 +64,8 @@ public enum DisguiseType {
PRIMED_TNT(50),
RABBIT,
SHEEP,
SHULKER,
SHULKER_BULLET(25),
SILVERFISH,
SKELETON,
SKELETON_HORSE,
@ -68,12 +73,15 @@ public enum DisguiseType {
SMALL_FIREBALL(64, 0),
SNOWBALL(61),
SNOWMAN,
SPECTRAL_ARROW(24),
SPIDER,
SPLASH_POTION(73),
SPLASH_POTION(-1),
SQUID,
TIPPED_ARROW(23),
THROWN_EXP_BOTTLE(75),
UNDEAD_HORSE,
VILLAGER,
WEATHER,
WITCH,
WITHER,
WITHER_SKELETON,
@ -116,7 +124,7 @@ public enum DisguiseType {
}
type.setEntityType(EntityType.valueOf(toUse.name()));
} catch (Throwable ex) {
// This version of craftbukkit doesn't have the disguise.
// This version of Spigot doesn't have the disguise.
}
}
try {

View File

@ -75,7 +75,7 @@ public class FlagWatcher {
}
cloned.entityValues = (HashMap<Integer, Object>) entityValues.clone();
cloned.items = items.clone();
cloned.modifiedEntityAnimations = (HashSet) modifiedEntityAnimations.clone();
cloned.modifiedEntityAnimations = (HashSet<Integer>) modifiedEntityAnimations.clone();
cloned.addEntityAnimations = addEntityAnimations;
return cloned;
}
@ -106,7 +106,7 @@ public class FlagWatcher {
}
if (value != null) {
if (isEntityAnimationsAdded() && dataType == 0) {
value = this.addEntityAnimations((Byte) value, (Byte) watch.getValue());
value = this.addEntityAnimations((byte) value, (byte) watch.getValue());
}
boolean isDirty = watch.getDirtyState();
watch = new WrappedWatchableObject(dataType, value);
@ -173,7 +173,7 @@ public class FlagWatcher {
}
private boolean getFlag(int byteValue) {
return ((Byte) getValue(0, (byte) 0) & 1 << byteValue) != 0;
return ((byte) getValue(0, (byte) 0) & 1 << byteValue) != 0;
}
public ItemStack getItemInHand() {
@ -264,7 +264,7 @@ public class FlagWatcher {
}
Object value = entityValues.get(data);
if (isEntityAnimationsAdded() && DisguiseConfig.isMetadataPacketsEnabled() && data == 0) {
value = addEntityAnimations((Byte) value, WrappedDataWatcher.getEntityWatcher(disguise.getEntity()).getByte(0));
value = addEntityAnimations((byte) value, WrappedDataWatcher.getEntityWatcher(disguise.getEntity()).getByte(0));
}
list.add(new WrappedWatchableObject(data, value));
}
@ -317,7 +317,7 @@ public class FlagWatcher {
private void setFlag(int byteValue, boolean flag) {
modifiedEntityAnimations.add(byteValue);
byte b0 = (Byte) getValue(0, (byte) 0);
byte b0 = (byte) getValue(0, (byte) 0);
if (flag) {
setValue(0, (byte) (b0 | 1 << byteValue));
} else {

View File

@ -17,7 +17,7 @@ public class AgeableWatcher extends LivingWatcher {
}
public boolean isBaby() {
return ((Byte) getValue(12, (byte) 0)).intValue() < 0;
return ((byte) getValue(12, (byte) 0)) < 0;
}
public void setAdult() {

View File

@ -9,7 +9,7 @@ public class ArmorStandWatcher extends LivingWatcher {
}
private boolean get10(int value) {
return ((Byte) getValue(10, 0) & value) != 0;
return ((byte) getValue(10, 0) & value) != 0;
}
public boolean isNoBasePlate() {
@ -29,7 +29,7 @@ public class ArmorStandWatcher extends LivingWatcher {
}
private void set10(int value, boolean isTrue) {
byte b1 = (Byte) getValue(10, (byte) 0);
byte b1 = (byte) getValue(10, (byte) 0);
if (isTrue) {
b1 = (byte) (b1 | value);
} else {

View File

@ -10,7 +10,7 @@ public class ArrowWatcher extends FlagWatcher {
}
public boolean isCritical() {
return (Byte) getValue(16, (byte) 0) == 1;
return (byte) getValue(16, (byte) 0) == 1;
}
public void setCritical(boolean critical) {

View File

@ -10,7 +10,7 @@ public class BatWatcher extends LivingWatcher {
}
public boolean isFlying() {
return (Byte) getValue(16, (byte) 1) == 0;
return (byte) getValue(16, (byte) 1) == 0;
}
public void setFlying(boolean flying) {

View File

@ -9,7 +9,7 @@ public class BlazeWatcher extends LivingWatcher {
}
public boolean isBlazing() {
return (Byte) getValue(16, (byte) 0) == 1;
return (byte) getValue(16, (byte) 0) == 1;
}
public void setBlazing(boolean isBlazing) {

View File

@ -9,11 +9,11 @@ public class CreeperWatcher extends LivingWatcher {
}
public boolean isIgnited() {
return (Byte) getValue(18, (byte) 0) == 1;
return (byte) getValue(18, (byte) 0) == 1;
}
public boolean isPowered() {
return (Byte) getValue(17, (byte) 0) == 1;
return (byte) getValue(17, (byte) 0) == 1;
}
public void setIgnited(boolean ignited) {

View File

@ -1,8 +1,7 @@
package me.libraryaddict.disguise.disguisetypes.watchers;
import org.bukkit.inventory.ItemStack;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import org.bukkit.inventory.ItemStack;
public class EndermanWatcher extends LivingWatcher {
@ -12,11 +11,11 @@ public class EndermanWatcher extends LivingWatcher {
@Override
public ItemStack getItemInHand() {
return new ItemStack((Byte) getValue(16, (byte) 0), 1, ((Byte) getValue(17, (byte) 0)));
return new ItemStack((byte) getValue(16, (byte) 0), 1, ((byte) getValue(17, (byte) 0)));
}
public boolean isAggressive() {
return (Byte) getValue(18, (byte) 0) == 1;
return (byte) getValue(18, (byte) 0) == 1;
}
@Deprecated

View File

@ -9,7 +9,7 @@ public class GhastWatcher extends LivingWatcher {
}
public boolean isAggressive() {
return (Byte) getValue(16, (byte) 0) == 1;
return (byte) getValue(16, (byte) 0) == 1;
}
public void setAggressive(boolean isAggressive) {

View File

@ -1,26 +1,24 @@
package me.libraryaddict.disguise.disguisetypes.watchers;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import me.libraryaddict.disguise.DisguiseAPI;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.ReflectionManager;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffectType;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.wrappers.WrappedAttribute;
import com.comphenix.protocol.wrappers.WrappedAttribute.Builder;
import me.libraryaddict.disguise.DisguiseAPI;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.ReflectionManager;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffectType;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
public class LivingWatcher extends FlagWatcher {
@ -80,7 +78,7 @@ public class LivingWatcher extends FlagWatcher {
}
public boolean getPotionParticlesRemoved() {
return (Byte) getValue(8, (byte) 0) == 1;
return (byte) getValue(8, (byte) 0) == 1;
}
private int getPotions() {
@ -99,7 +97,7 @@ public class LivingWatcher extends FlagWatcher {
int n = (Integer) potionNo.invoke(list[localMobEffect]);
f1 += (n >> 16 & 0xFF) / 255.0F;
f2 += (n >> 8 & 0xFF) / 255.0F;
f3 += (n >> 0 & 0xFF) / 255.0F;
f3 += (n & 0xFF) / 255.0F;
f4 += 1.0F;
}
} catch (Exception ex) {

View File

@ -30,7 +30,7 @@ public class MinecartWatcher extends FlagWatcher {
}
public boolean getViewBlockInCart() {
return ((Byte) getValue(22, (byte) 0)) == (byte) 1;
return ((byte) getValue(22, (byte) 0)) == (byte) 1;
}
public void setBlockInCart(ItemStack item) {

View File

@ -1,7 +1,6 @@
package me.libraryaddict.disguise.disguisetypes.watchers;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import org.bukkit.entity.Ocelot;
import org.bukkit.entity.Ocelot.Type;
@ -12,7 +11,7 @@ public class OcelotWatcher extends TameableWatcher {
}
public Type getType() {
return Ocelot.Type.getType((Byte) getValue(18, (byte) 0));
return Ocelot.Type.getType((byte) getValue(18, (byte) 0));
}
public void setType(Type newType) {

View File

@ -9,7 +9,7 @@ public class PigWatcher extends AgeableWatcher {
}
public boolean isSaddled() {
return (Byte) getValue(16, (byte) 0) == 1;
return (byte) getValue(16, (byte) 0) == 1;
}
public void setSaddled(boolean isSaddled) {

View File

@ -1,19 +1,16 @@
package me.libraryaddict.disguise.disguisetypes.watchers;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Player;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.reflect.StructureModifier;
import me.libraryaddict.disguise.DisguiseAPI;
import me.libraryaddict.disguise.DisguiseConfig;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.PlayerDisguise;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.ReflectionManager.LibVersion;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Player;
public class PlayerWatcher extends LivingWatcher {
@ -32,7 +29,7 @@ public class PlayerWatcher extends LivingWatcher {
}
public int getArrowsSticking() {
return (Byte) getValue(9, (byte) 0);
return (byte) getValue(9, (byte) 0);
}
public BlockFace getSleepingDirection() {
@ -48,7 +45,7 @@ public class PlayerWatcher extends LivingWatcher {
}
private boolean getValue16(int i) {
return ((Byte) getValue(16, (byte) 0) & 1 << i) != 0;
return ((byte) getValue(16, (byte) 0) & 1 << i) != 0;
}
public boolean isHideCape() {
@ -129,11 +126,11 @@ public class PlayerWatcher extends LivingWatcher {
}
private void setValue16(int i, boolean flag) {
byte b0 = (Byte) getValue(16, (byte) 0);
byte b0 = (byte) getValue(16, (byte) 0);
if (flag) {
setValue(16, (byte) (b0 | 1 << i));
} else {
setValue(16, (byte) (b0 & (1 << i ^ 0xFFFFFFFF)));
setValue(16, (byte) (b0 & (~1 << i)));
}
}

View File

@ -11,21 +11,21 @@ public class SheepWatcher extends AgeableWatcher {
}
public AnimalColor getColor() {
return AnimalColor.getColor((Byte) getValue(16, (byte) 0) & 15);
return AnimalColor.getColor((byte) getValue(16, (byte) 0) & 15);
}
public boolean isSheared() {
return ((Byte) getValue(16, (byte) 0) & 16) != 0;
return ((byte) getValue(16, (byte) 0) & 16) != 0;
}
public void setColor(AnimalColor color) {
byte b0 = (Byte) getValue(16, (byte) 0);
byte b0 = (byte) getValue(16, (byte) 0);
setValue(16, (byte) (b0 & 240 | color.getId() & 15));
sendData(16);
}
public void setSheared(boolean flag) {
byte b0 = (Byte) getValue(16, (byte) 0);
byte b0 = (byte) getValue(16, (byte) 0);
if (flag) {
setValue(16, (byte) (b0 | 16));
} else {

View File

@ -1,9 +1,9 @@
package me.libraryaddict.disguise.disguisetypes.watchers;
import java.util.Random;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import java.util.Random;
public class SlimeWatcher extends LivingWatcher {
public SlimeWatcher(Disguise disguise) {
@ -12,7 +12,7 @@ public class SlimeWatcher extends LivingWatcher {
}
public int getSize() {
return (Byte) getValue(16, (byte) 1);
return (byte) getValue(16, (byte) 1);
}
public void setSize(int size) {

View File

@ -26,11 +26,11 @@ public class TameableWatcher extends AgeableWatcher {
}
protected boolean isTrue(int no) {
return ((Byte) getValue(16, (byte) 0) & no) != 0;
return ((byte) getValue(16, (byte) 0) & no) != 0;
}
protected void setFlag(int no, boolean flag) {
byte b0 = (Byte) getValue(16, (byte) 0);
byte b0 = (byte) getValue(16, (byte) 0);
if (flag) {
setValue(16, (byte) (b0 | no));
} else {

View File

@ -10,7 +10,7 @@ public class WitherSkullWatcher extends FlagWatcher {
}
public boolean isBlue() {
return (Byte) getValue(10, (byte) 0) == 1;
return (byte) getValue(10, (byte) 0) == 1;
}
public void setBlue(boolean blue) {

View File

@ -10,7 +10,7 @@ public class WolfWatcher extends TameableWatcher {
}
public AnimalColor getCollarColor() {
return AnimalColor.getColor((Byte) getValue(20, (byte) 14));
return AnimalColor.getColor((byte) getValue(20, (byte) 14));
}
public boolean isAngry() {

View File

@ -13,15 +13,15 @@ public class ZombieWatcher extends LivingWatcher {
}
public boolean isBaby() {
return (Byte) getValue(12, (byte) 0) == 1;
return (byte) getValue(12, (byte) 0) == 1;
}
public boolean isShaking() {
return (Byte) getValue(14, (byte) 0) == 1;
return (byte) getValue(14, (byte) 0) == 1;
}
public boolean isVillager() {
return (Byte) getValue(13, (byte) 0) == 1;
return (byte) getValue(13, (byte) 0) == 1;
}
public void setAdult() {

View File

@ -33,6 +33,7 @@ import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.scheduler.BukkitTask;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.File;
@ -46,7 +47,6 @@ import java.net.URLConnection;
import java.net.URLEncoder;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.Set;
import java.util.UUID;
@ -275,7 +275,7 @@ public class Metrics {
* @return the File object for the config file
*/
public File getConfigFile() {
// I believe the easiest way to get the base folder (e.g craftbukkit set via -P) for plugins to use
// I believe the easiest way to get the base folder (e.g Spigot set via -P) for plugins to use
// is to abuse the plugin object we already have
// plugin.getDataFolder() => base/plugins/PluginA/
// pluginsFolder => base/plugins/
@ -334,9 +334,7 @@ public class Metrics {
json.append(':');
json.append('{');
boolean firstGraph = true;
final Iterator<Graph> iter = graphs.iterator();
while (iter.hasNext()) {
Graph graph = iter.next();
for (Graph graph : graphs) {
StringBuilder graphJson = new StringBuilder();
graphJson.append('{');
for (Plotter plotter : graph.getPlotters()) {
@ -402,9 +400,7 @@ public class Metrics {
// Is this the first update this hour?
if (response.equals("1") || response.contains("This is your first update this hour")) {
synchronized (graphs) {
final Iterator<Graph> iter = graphs.iterator();
while (iter.hasNext()) {
final Graph graph = iter.next();
for (Graph graph : graphs) {
for (Plotter plotter : graph.getPlotters()) {
plotter.reset();
}
@ -418,7 +414,7 @@ public class Metrics {
* GZip compress a string of bytes
*
* @param input
* @return
* @return byte[]
*/
public static byte[] gzip(String input) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
@ -487,7 +483,7 @@ public class Metrics {
* Escape a string to create a valid JSON string
*
* @param text
* @return
* @return String
*/
private static String escapeJSON(String text) {
StringBuilder builder = new StringBuilder();
@ -515,7 +511,7 @@ public class Metrics {
default:
if (chr < ' ') {
String t = "000" + Integer.toHexString(chr);
builder.append("\\u" + t.substring(t.length() - 4));
builder.append("\\u").append(t.substring(t.length() - 4));
} else {
builder.append(chr);
}

View File

@ -119,7 +119,7 @@ public class PacketsManager {
if (disguise.getEntity() == null)
disguise.setEntity(disguisedEntity);
Object nmsEntity = ReflectionManager.getNmsEntity(disguisedEntity);
ArrayList<PacketContainer> packets = new ArrayList<PacketContainer>();
ArrayList<PacketContainer> packets = new ArrayList<>();
// This sends the armor packets so that the player isn't naked.
// Please note it only sends the packets that wouldn't be sent normally
if (DisguiseConfig.isEquipmentPacketsEnabled()) {
@ -151,7 +151,7 @@ public class PacketsManager {
if (DisguiseConfig.isMiscDisguisesForLivingEnabled()) {
if (disguise.getWatcher() instanceof LivingWatcher) {
PacketContainer packet = new PacketContainer(PacketType.Play.Server.UPDATE_ATTRIBUTES);
List<WrappedAttribute> attributes = new ArrayList<WrappedAttribute>();
List<WrappedAttribute> attributes = new ArrayList<>();
Builder builder = WrappedAttribute.newBuilder().attributeKey("generic.maxHealth");
if (((LivingWatcher) disguise.getWatcher()).isMaxHealthSet()) {
builder.baseValue(((LivingWatcher) disguise.getWatcher()).getMaxHealth());
@ -257,16 +257,14 @@ public class PacketsManager {
PacketContainer[] bedPackets = DisguiseUtilities.getBedPackets(player,
loc.clone().subtract(0, PacketsManager.getYModifier(disguisedEntity, disguise), 0), player.getLocation(),
((PlayerDisguise) disguise));
for (int i = 0; i < 2; i++) {
spawnPackets[i + 1] = bedPackets[i];
}
System.arraycopy(bedPackets, 0, spawnPackets, 1, 2);
}
ArrayList<PacketContainer> newPackets = new ArrayList<PacketContainer>();
ArrayList<PacketContainer> 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]);
for (PacketContainer spawnPacket : spawnPackets) {
if (spawnPacket != null) { // Get rid of empty packet '1' if it exists.
newPackets.add(spawnPacket);
}
}
spawnPackets = newPackets.toArray(new PacketContainer[newPackets.size()]);
@ -547,8 +545,7 @@ public class PacketsManager {
DisguiseSound entitySound = null;
Disguise disguise = null;
Entity[] entities = soundLoc.getChunk().getEntities();
for (int i = 0; i < entities.length; i++) {
Entity entity = entities[i];
for (Entity entity : entities) {
Disguise entityDisguise = DisguiseAPI.getDisguise(observer, entity);
if (entityDisguise != null) {
Location loc = entity.getLocation();
@ -618,8 +615,7 @@ public class PacketsManager {
typeId);
if (block != null) {
Object step = ReflectionManager.getNmsField("Block", "stepSound").get(block);
mods.write(0, ReflectionManager.getNmsMethod(step.getClass(), "getStepSound")
.invoke(step));
mods.write(0, ReflectionManager.getNmsMethod(step.getClass(), "getStepSound").invoke(step));
}
} catch (Exception ex) {
ex.printStackTrace();
@ -682,7 +678,7 @@ public class PacketsManager {
}
}
} else if (event.getPacketType() == PacketType.Play.Server.ENTITY_STATUS) {
if ((Byte) mods.read(1) == 2) {
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);
@ -805,7 +801,7 @@ public class PacketsManager {
event.setPacket(event.getPacket().deepClone());
for (WrappedWatchableObject watch : event.getPacket().getWatchableCollectionModifier().read(0)) {
if (watch.getIndex() == 0) {
byte b = (Byte) watch.getValue();
byte b = (byte) watch.getValue();
byte a = (byte) (b | 1 << 5);
if ((b & 1 << 3) != 0)
a = (byte) (a | 1 << 3);
@ -817,7 +813,7 @@ public class PacketsManager {
PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_METADATA);
StructureModifier<Object> mods = packet.getModifier();
mods.write(0, observer.getEntityId());
List<WrappedWatchableObject> watchableList = new ArrayList<WrappedWatchableObject>();
List<WrappedWatchableObject> watchableList = new ArrayList<>();
byte b = (byte) 1 << 5;
if (observer.isSprinting())
b = (byte) (b | 1 << 3);
@ -1144,7 +1140,7 @@ public class PacketsManager {
if (mainListener != null) {
ProtocolLibrary.getProtocolManager().removePacketListener(mainListener);
}
List<PacketType> packetsToListen = new ArrayList<PacketType>();
List<PacketType> packetsToListen = new ArrayList<>();
// Add spawn packets
{
packetsToListen.add(PacketType.Play.Server.NAMED_ENTITY_SPAWN);
@ -1276,7 +1272,7 @@ public class PacketsManager {
if (disguise.isMiscDisguise()) {
packets = new PacketContainer[0];
} else {
List<WrappedAttribute> attributes = new ArrayList<WrappedAttribute>();
List<WrappedAttribute> attributes = new ArrayList<>();
for (WrappedAttribute attribute : sentPacket.getAttributeCollectionModifier().read(0)) {
if (attribute.getAttributeKey().equals("generic.maxHealth")) {
packets[0] = new PacketContainer(PacketType.Play.Server.UPDATE_ATTRIBUTES);
@ -1340,9 +1336,7 @@ public class PacketsManager {
.getWatcher()).isSleeping())))) {
packets = new PacketContainer[0];
}
}
else if (sentPacket.getType() == PacketType.Play.Server.COLLECT) {
} else if (sentPacket.getType() == PacketType.Play.Server.COLLECT) {
if (disguise.getType().isMisc()) {
packets = new PacketContainer[0];
} else if (DisguiseConfig.isBedPacketsEnabled() && disguise.getType().isPlayer()
@ -1408,9 +1402,7 @@ public class PacketsManager {
}
}
}
}
else if (sentPacket.getType() == PacketType.Play.Server.ENTITY_EQUIPMENT) {
} else if (sentPacket.getType() == PacketType.Play.Server.ENTITY_EQUIPMENT) {
int slot = (Integer) packets[0].getModifier().read(1) - 1;
if (slot < 0)
slot = 4;
@ -1424,7 +1416,7 @@ public class PacketsManager {
ItemStack heldItem = packets[0].getItemModifier().read(0);
if (heldItem != null && heldItem.getType() != Material.AIR) {
// Convert the datawatcher
List<WrappedWatchableObject> list = new ArrayList<WrappedWatchableObject>();
List<WrappedWatchableObject> list = new ArrayList<>();
if (DisguiseConfig.isMetadataPacketsEnabled()) {
list.add(new WrappedWatchableObject(0, WrappedDataWatcher.getEntityWatcher(entity).getByte(0)));
list = disguise.getWatcher().convert(list);
@ -1444,7 +1436,7 @@ public class PacketsManager {
PacketContainer packetUnblock = packetBlock.deepClone();
// Make a packet to send the 'unblock'
for (WrappedWatchableObject watcher : packetUnblock.getWatchableCollectionModifier().read(0)) {
watcher.setValue((byte) ((Byte) watcher.getValue() & ~(1 << 4)));
watcher.setValue((byte) ((byte) watcher.getValue() & ~(1 << 4)));
}
// Send the unblock before the itemstack change so that the 2nd metadata packet works. Why? Scheduler
// delay.
@ -1453,21 +1445,15 @@ public class PacketsManager {
// it.
}
}
}
else if (sentPacket.getType() == PacketType.Play.Server.BED) {
} else if (sentPacket.getType() == PacketType.Play.Server.BED) {
if (!disguise.getType().isPlayer()) {
packets = new PacketContainer[0];
}
}
else if (sentPacket.getType() == PacketType.Play.Server.ENTITY_STATUS) {
} else if (sentPacket.getType() == PacketType.Play.Server.ENTITY_STATUS) {
if (packets[0].getBytes().read(0) == (byte) 3) {
packets = new PacketContainer[0];
}
}
else if (sentPacket.getType() == PacketType.Play.Server.ENTITY_HEAD_ROTATION) {
} else if (sentPacket.getType() == PacketType.Play.Server.ENTITY_HEAD_ROTATION) {
if (disguise.getType().isPlayer() && entity.getType() != EntityType.PLAYER) {
Location loc = entity.getLocation();
byte pitch = getPitch(disguise.getType(), DisguiseType.getType(entity.getType()),
@ -1483,9 +1469,7 @@ public class PacketsManager {
look.getBytes().write(4, pitch);
packets = new PacketContainer[]{look, rotation};
}
}
else {
} else {
packets = null;
}

View File

@ -28,21 +28,6 @@ import java.util.regex.Pattern;
public class ReflectionManager {
public enum LibVersion {
V1_8;
private static LibVersion currentVersion;
static {
//String mcVersion = Bukkit.getVersion().split("MC: ")[1].replace(")", "");
currentVersion = V1_8;
}
public static LibVersion getGameVersion() {
return currentVersion;
}
}
private static final String bukkitVersion = Bukkit.getServer().getClass().getName().split("\\.")[3];
private static final Class<?> craftItemClass;
private static Method damageAndIdleSoundMethod;
@ -551,7 +536,7 @@ public class ReflectionManager {
try {
damageAndIdleSoundMethod.setAccessible(true);
return (Float) damageAndIdleSoundMethod.invoke(entity);
} catch (Exception ex) {
} catch (Exception ignored) {
}
return null;
}
@ -610,6 +595,7 @@ public class ReflectionManager {
public static void setAllowSleep(Player player) {
try {
//TODO: Fix this!
/**
* Object nmsEntity = getNmsEntity(player); Object connection = getNmsField(nmsEntity.getClass(), "playerConnection").get(nmsEntity); Field check = getNmsField(connection.getClass(), "checkMovement"); check.setBoolean(connection, true); *
*/

View File

@ -1,6 +1,6 @@
name: LibsDisguises
main: me.libraryaddict.disguise.LibsDisguises
version: 8.6.8
version: 9.0.0
author: libraryaddict
authors: [Byteflux, Navid K.]
softdepend: [ProtocolLib]