Cleaned up code. Fixed error for sounds handling

This commit is contained in:
libraryaddict 2013-12-08 07:51:37 +13:00
parent 1434bdc49e
commit cdc02b4090
4 changed files with 24 additions and 20 deletions

View File

@ -282,15 +282,15 @@ public class FlagWatcher {
setItemInHand(itemstack);
}
public void setItemInHand(org.bukkit.inventory.ItemStack itemstack) {
setItemStack(SlotType.HELD_ITEM, itemstack);
}
public void setInvisible(boolean setInvis) {
setFlag(0, 5, setInvis);
sendData(0);
}
public void setItemInHand(org.bukkit.inventory.ItemStack itemstack) {
setItemStack(SlotType.HELD_ITEM, itemstack);
}
public void setItemStack(int slot, org.bukkit.inventory.ItemStack itemStack) {
// Itemstack which is null means that its not replacing the disguises itemstack.
if (itemStack == null) {

View File

@ -226,6 +226,7 @@ public class DisguiseUtilities {
if (player.equals(((Player) ReflectionManager.getBukkitEntity(p)).getName())) {
clear.invoke(entityTrackerEntry, p);
updatePlayer.invoke(entityTrackerEntry, p);
break;
}
}
}
@ -373,9 +374,9 @@ public class DisguiseUtilities {
Vector velocity = player.getVelocity();
manager.sendServerPacket(
player,
manager.createPacketConstructor(PacketType.Play.Server.ENTITY_VELOCITY, player.getEntityId(), velocity.getX(),
velocity.getY(), velocity.getZ()).createPacket(player.getEntityId(), velocity.getX(),
velocity.getY(), velocity.getZ()));
manager.createPacketConstructor(PacketType.Play.Server.ENTITY_VELOCITY, player.getEntityId(),
velocity.getX(), velocity.getY(), velocity.getZ()).createPacket(player.getEntityId(),
velocity.getX(), velocity.getY(), velocity.getZ()));
}
// Why the hell would he even need this. Meh.
@ -399,9 +400,10 @@ public class DisguiseUtilities {
}
if (item != null && item.getType() != Material.AIR) {
manager.sendServerPacket(player,
manager.createPacketConstructor(PacketType.Play.Server.ENTITY_EQUIPMENT, player.getEntityId(), i, item)
.createPacket(player.getEntityId(), i, item));
manager.sendServerPacket(
player,
manager.createPacketConstructor(PacketType.Play.Server.ENTITY_EQUIPMENT, player.getEntityId(), i,
item).createPacket(player.getEntityId(), i, item));
}
}
Location loc = player.getLocation();
@ -409,9 +411,8 @@ public class DisguiseUtilities {
if (player.isSleeping()) {
manager.sendServerPacket(
player,
manager.createPacketConstructor(PacketType.Play.Server.BED, player, 0, loc.getBlockX(),
loc.getBlockY(), loc.getBlockZ()).createPacket(player, 0, loc.getBlockX(), loc.getBlockY(),
loc.getBlockZ()));
manager.createPacketConstructor(PacketType.Play.Server.BED, player, 0, loc.getBlockX(), loc.getBlockY(),
loc.getBlockZ()).createPacket(player, 0, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()));
}
// Resend any active potion effects

View File

@ -2,6 +2,7 @@ package me.libraryaddict.disguise.utilities;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Random;
@ -539,7 +540,9 @@ public class PacketsManager {
Class blockClass = ReflectionManager.getNmsClass("Block");
Object block;
if (ReflectionManager.isAfter17()) {
block = blockClass.getMethod("REGISTRY", int.class).invoke(null, typeId);
block = ReflectionManager.getNmsClass("RegistryMaterials")
.getMethod("a", int.class)
.invoke(blockClass.getField("REGISTRY").get(null), typeId);
} else {
block = ((Object[]) blockClass.getField("byId").get(null))[typeId];
}

View File

@ -12,10 +12,10 @@ import org.bukkit.entity.Entity;
import org.bukkit.inventory.ItemStack;
public class ReflectionManager {
private static boolean after17 = true;
private static String bukkitVersion = Bukkit.getServer().getClass().getName().split("\\.")[3];
private static Class itemClass;
private static Method soundMethod;
private static boolean after17 = true;
static {
for (Method method : getNmsClass("EntityLiving").getDeclaredMethods()) {
try {
@ -53,11 +53,7 @@ public class ReflectionManager {
}
}
}public static boolean isAfter17() {
return after17;
}
public static Object createEntityInstance(String entityName) {
}public static Object createEntityInstance(String entityName) {
try {
Class entityClass = getNmsClass("Entity" + entityName);
Object entityObject;
@ -194,4 +190,8 @@ public class ReflectionManager {
return null;
}
public static boolean isAfter17() {
return after17;
}
}