Пример #1
0
 static {
   final String[] parts = Bukkit.class.getName().split(".");
   if (parts.length == 4) {
     InventoryUtil.version = "";
   } else {
     InventoryUtil.version = "." + parts[4];
   }
   Field tiinv = null;
   Field ttitle = null;
   Field thandle = null;
   Field tcontainerCounter = null;
   Constructor<?> topenWindowPacket = null;
   Field tplayerConnection = null;
   Method tsendPacket;
   try {
     tiinv =
         getVersionedClass("org.bukkit.craftbukkit.inventory.CraftInventory")
             .getDeclaredField("inventory");
     tiinv.setAccessible(true);
     ttitle =
         getVersionedClass(
                 "org.bukkit.craftbukkit.inventory.CraftInventoryCustom$MinecraftInventory")
             .getDeclaredField("title");
     ttitle.setAccessible(true);
     thandle =
         getVersionedClass("org.bukkit.craftbukkit.entity.CraftEntity").getDeclaredField("handle");
     thandle.setAccessible(true);
     tcontainerCounter =
         getVersionedClass("net.minecraft.server.EntityPlayer")
             .getDeclaredField("containerCounter");
     tcontainerCounter.setAccessible(true);
     thandle =
         getVersionedClass("org.bukkit.craftbukkit.entity.CraftEntity").getDeclaredField("handle");
     thandle.setAccessible(true);
     topenWindowPacket =
         getVersionedClass("net.minecraft.server.PacketPlayOutOpenWindow")
             .getDeclaredConstructor(
                 Integer.TYPE, Integer.TYPE, String.class, Integer.TYPE, Boolean.TYPE);
     topenWindowPacket.setAccessible(true);
     tplayerConnection =
         getVersionedClass("net.minecraft.server.EntityPlayer")
             .getDeclaredField("playerConnection");
     tplayerConnection.setAccessible(true);
     tsendPacket =
         getVersionedClass("net.minecraft.server.PlayerConnection")
             .getDeclaredMethod(
                 "sendPacket", topenWindowPacket.getDeclaringClass().getSuperclass());
     tsendPacket.setAccessible(true);
   } catch (Exception ex) {
     throw new ExceptionInInitializerError(ex);
   }
   iinvField = tiinv;
   titleField = ttitle;
   handleField = thandle;
   containerCounterField = tcontainerCounter;
   openWindowPacketConstructor = topenWindowPacket;
   playerConnectionField = tplayerConnection;
   sendPacket = tsendPacket;
 }
Пример #2
0
 private static void setField(final String field, final Object value)
     throws NoSuchFieldException, IllegalAccessException {
   final Field f = ParticleUtils.packet.getClass().getDeclaredField(field);
   f.setAccessible(true);
   f.set(ParticleUtils.packet, value);
 }