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); setItemInHand(itemstack);
} }
public void setItemInHand(org.bukkit.inventory.ItemStack itemstack) {
setItemStack(SlotType.HELD_ITEM, itemstack);
}
public void setInvisible(boolean setInvis) { public void setInvisible(boolean setInvis) {
setFlag(0, 5, setInvis); setFlag(0, 5, setInvis);
sendData(0); 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) { public void setItemStack(int slot, org.bukkit.inventory.ItemStack itemStack) {
// Itemstack which is null means that its not replacing the disguises itemstack. // Itemstack which is null means that its not replacing the disguises itemstack.
if (itemStack == null) { if (itemStack == null) {

View File

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

View File

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

View File

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