From 9b88847c2862c134e47a7d9661b1a87b5712a103 Mon Sep 17 00:00:00 2001 From: Dan Mulloy Date: Fri, 28 Nov 2014 22:08:46 -0500 Subject: [PATCH] Actually update to 1.8 --- .../com/comphenix/protocol/PacketType.java | 23 +++-- .../injector/netty/NettyProtocolRegistry.java | 87 +++++++++++-------- .../protocol/reflect/StructureModifier.java | 51 +++++------ .../reflect/cloning/BukkitCloner.java | 17 ++-- .../reflect/instances/DefaultInstances.java | 28 +++--- .../comphenix/protocol/utility/Constants.java | 14 +++ .../protocol/utility/MinecraftReflection.java | 81 +++-------------- .../protocol/BukkitInitialization.java | 3 +- 8 files changed, 137 insertions(+), 167 deletions(-) create mode 100644 ProtocolLib/src/main/java/com/comphenix/protocol/utility/Constants.java diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/PacketType.java b/ProtocolLib/src/main/java/com/comphenix/protocol/PacketType.java index 2316e2f8..5c8c3ec2 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/PacketType.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/PacketType.java @@ -10,7 +10,6 @@ import java.util.concurrent.Future; import org.bukkit.Bukkit; -import com.comphenix.protocol.annotations.Spigot; import com.comphenix.protocol.events.ConnectionSide; import com.comphenix.protocol.injector.packet.PacketRegistry; import com.comphenix.protocol.reflect.ObjectEnum; @@ -179,13 +178,16 @@ public class PacketType implements Serializable, Comparable { public static final PacketType SCOREBOARD_TEAM = new PacketType(PROTOCOL, SENDER, 0x3E, 209); public static final PacketType CUSTOM_PAYLOAD = new PacketType(PROTOCOL, SENDER, 0x3F, 250); public static final PacketType KICK_DISCONNECT = new PacketType(PROTOCOL, SENDER, 0x40, 255); - - @Spigot(minimumBuild = 1628) - public static final PacketType TITLE = new PacketType(PROTOCOL, SENDER, 0x45, -1); - @Spigot(minimumBuild = 1628) - public static final PacketType TAB_HEADER = new PacketType(PROTOCOL, SENDER, 0x47, -1); - @Spigot(minimumBuild = 1628) + public static final PacketType SERVER_DIFFICULTY = new PacketType(PROTOCOL, SENDER, 0x41, -1); + public static final PacketType COMBAT_EVENT = new PacketType(PROTOCOL, SENDER, 0x42, -1); + public static final PacketType CAMERA = new PacketType(PROTOCOL, SENDER, 0x43, -1); + public static final PacketType WORLD_BORDER = new PacketType(PROTOCOL, SENDER, 0x44, -1); + public static final PacketType TITLE = new PacketType(PROTOCOL, SENDER, 0x45, -1); + public static final PacketType SET_COMPRESSION = new PacketType(PROTOCOL, SENDER, 0x46, -1); + public static final PacketType PLAYER_LIST_HEADER_FOOTER = + new PacketType(PROTOCOL, SENDER, 0x47, -1); public static final PacketType RESOURCE_PACK_SEND = new PacketType(PROTOCOL, SENDER, 0x48, -1); + public static final PacketType UPDATE_ENTITY_NBT = new PacketType(PROTOCOL, SENDER, 0x49, -1); // The instance must private final static Server INSTANCE = new Server(); @@ -232,8 +234,7 @@ public class PacketType implements Serializable, Comparable { public static final PacketType SETTINGS = new PacketType(PROTOCOL, SENDER, 0x15, 204); public static final PacketType CLIENT_COMMAND = new PacketType(PROTOCOL, SENDER, 0x16, 205); public static final PacketType CUSTOM_PAYLOAD = new PacketType(PROTOCOL, SENDER, 0x17, 250); - - @Spigot(minimumBuild = 1628) + public static final PacketType SPECTATE = new PacketType(PROTOCOL, SENDER, 0x18, -1); public static final PacketType RESOURCE_PACK_STATUS = new PacketType(PROTOCOL, SENDER, 0x19, -1); private final static Client INSTANCE = new Client(); @@ -332,9 +333,7 @@ public class PacketType implements Serializable, Comparable { public static final PacketType ENCRYPTION_BEGIN = new PacketType(PROTOCOL, SENDER, 0x01, 253); @SuppressWarnings("deprecation") public static final PacketType SUCCESS = new PacketType(PROTOCOL, SENDER, 0x02, Packets.Server.LOGIN_SUCCESS); - - @Spigot(minimumBuild = 1628) - public static final PacketType LOGIN_COMPRESSION = new PacketType(PROTOCOL, SENDER, 0x03, -1); + public static final PacketType SET_COMPRESSION = new PacketType(PROTOCOL, SENDER, 0x03, -1); private final static Server INSTANCE = new Server(); diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/netty/NettyProtocolRegistry.java b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/netty/NettyProtocolRegistry.java index d4b96672..4b5f10f6 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/netty/NettyProtocolRegistry.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/netty/NettyProtocolRegistry.java @@ -14,8 +14,8 @@ import com.comphenix.protocol.reflect.StructureModifier; import com.comphenix.protocol.utility.MinecraftReflection; import com.google.common.collect.BiMap; import com.google.common.collect.HashBiMap; -import com.google.common.collect.Iterables; import com.google.common.collect.Lists; +import com.google.common.collect.Maps; import com.google.common.collect.Sets; /** @@ -107,42 +107,57 @@ public class NettyProtocolRegistry { * Load the packet lookup tables in each protocol. */ private synchronized void initialize() { - final Object[] protocols = enumProtocol.getEnumConstants(); - List>> serverMaps = Lists.newArrayList(); - List>> clientMaps = Lists.newArrayList(); - StructureModifier modifier = null; - - // Result + Object[] protocols = enumProtocol.getEnumConstants(); + + // ID to Packet class maps + Map>> serverMaps = Maps.newLinkedHashMap(); + Map>> clientMaps = Maps.newLinkedHashMap(); + Register result = new Register(); - + StructureModifier modifier = null; + + // Iterate through the protocols for (Object protocol : protocols) { if (modifier == null) modifier = new StructureModifier(protocol.getClass().getSuperclass(), false); - StructureModifier>> maps = modifier.withTarget(protocol).withType(Map.class); - - serverMaps.add(maps.read(0)); - clientMaps.add(maps.read(1)); + StructureModifier>>> maps = modifier.withTarget(protocol).withType(Map.class); + for (Entry>> entry : maps.read(0).entrySet()) { + String direction = entry.getKey().toString(); + if (direction.contains("CLIENTBOUND")) { // Sent by Server + serverMaps.put(protocol, entry.getValue()); + } else if (direction.contains("SERVERBOUND")) { // Sent by Client + clientMaps.put(protocol, entry.getValue()); + } + } } + // Maps we have to occationally check have changed - for (Map> map : Iterables.concat(serverMaps, clientMaps)) { + for (Map> map : serverMaps.values()) { + result.containers.add(new MapContainer(map)); + } + + for (Map> map : clientMaps.values()) { result.containers.add(new MapContainer(map)); } - // Heuristic - there are more server packets than client packets - if (sum(clientMaps) > sum(serverMaps)) { - // Swap if this is violated - List>> temp = serverMaps; - serverMaps = clientMaps; - clientMaps = temp; - } - +// // Heuristic - there are more server packets than client packets +// if (sum(clientMaps) > sum(serverMaps)) { +// // Swap if this is violated +// List>> temp = serverMaps; +// serverMaps = clientMaps; +// clientMaps = temp; +// } + for (int i = 0; i < protocols.length; i++) { - Enum enumProtocol = (Enum) protocols[i]; + Object protocol = protocols[i]; + Enum enumProtocol = (Enum) protocol; Protocol equivalent = Protocol.fromVanilla(enumProtocol); // Associate known types - associatePackets(result, serverMaps.get(i), equivalent, Sender.SERVER); - associatePackets(result, clientMaps.get(i), equivalent, Sender.CLIENT); + if (serverMaps.containsKey(protocol)) + associatePackets(result, serverMaps.get(protocol), equivalent, Sender.SERVER); + if (clientMaps.containsKey(protocol)) + associatePackets(result, clientMaps.get(protocol), equivalent, Sender.CLIENT); } // Exchange (thread safe, as we have only one writer) this.register = result; @@ -160,16 +175,16 @@ public class NettyProtocolRegistry { } } - /** - * Retrieve the number of mapping in all the maps. - * @param maps - iterable of maps. - * @return The sum of all the entries. - */ - private int sum(Iterable>> maps) { - int count = 0; - - for (Map> map : maps) - count += map.size(); - return count; - } +// /** +// * Retrieve the number of mapping in all the maps. +// * @param maps - iterable of maps. +// * @return The sum of all the entries. +// */ +// private int sum(Iterable>> maps) { +// int count = 0; +// +// for (Map> map : maps) +// count += map.size(); +// return count; +// } } diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/reflect/StructureModifier.java b/ProtocolLib/src/main/java/com/comphenix/protocol/reflect/StructureModifier.java index 77319aa8..0f2ff8f5 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/reflect/StructureModifier.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/reflect/StructureModifier.java @@ -2,16 +2,16 @@ * ProtocolLib - Bukkit server library that allows access to the Minecraft protocol. * Copyright (C) 2012 Kristian S. Stangeland * - * This program is free software; you can redistribute it and/or modify it under the terms of the - * GNU General Public License as published by the Free Software Foundation; either version 2 of + * This program is free software; you can redistribute it and/or modify it under the terms of the + * GNU General Public License as published by the Free Software Foundation; either version 2 of * the License, or (at your option) any later version. * - * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along with this program; - * if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + * You should have received a copy of the GNU General Public License along with this program; + * if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA * 02111-1307 USA */ @@ -119,7 +119,7 @@ public class StructureModifier { List fields = getFields(targetType, superclassExclude); Map defaults = requireDefault ? generateDefaultFields(fields) : new HashMap(); - initialize(targetType, Object.class, fields, defaults, null, + initialize(targetType, Object.class, fields, defaults, null, new ConcurrentHashMap(), useStructureCompiler); } @@ -135,8 +135,8 @@ public class StructureModifier { * @param other - information to set. */ protected void initialize(StructureModifier other) { - initialize(other.targetType, other.fieldType, other.data, - other.defaultFields, other.converter, other.subtypeCache, + initialize(other.targetType, other.fieldType, other.data, + other.defaultFields, other.converter, other.subtypeCache, other.useStructureCompiler); } @@ -149,7 +149,7 @@ public class StructureModifier { * @param converter - converts between the common field type and the actual type the consumer expects. * @param subTypeCache - a structure modifier cache. */ - protected void initialize(Class targetType, Class fieldType, + protected void initialize(Class targetType, Class fieldType, List data, Map defaultFields, EquivalentConverter converter, Map subTypeCache) { initialize(targetType, fieldType, data, defaultFields, converter, subTypeCache, true); @@ -165,7 +165,7 @@ public class StructureModifier { * @param subTypeCache - a structure modifier cache. * @param useStructureCompiler - whether or not to automatically compile this structure modifier. */ - protected void initialize(Class targetType, Class fieldType, + protected void initialize(Class targetType, Class fieldType, List data, Map defaultFields, EquivalentConverter converter, Map subTypeCache, boolean useStructureCompiler) { @@ -187,21 +187,22 @@ public class StructureModifier { */ @SuppressWarnings("unchecked") public TField read(int fieldIndex) throws FieldAccessException { - if (fieldIndex < 0 || fieldIndex >= data.size()) - throw new FieldAccessException("Field index must be within 0 - count", - new IndexOutOfBoundsException("Out of bounds")); + if (fieldIndex < 0) + throw new FieldAccessException(String.format("Field index (%s) cannot be negative.", fieldIndex)); + if (fieldIndex >= data.size()) + throw new FieldAccessException(String.format("Field index out of bounds. (Index: %s, Size: %s)", fieldIndex, data.size())); if (target == null) - throw new IllegalStateException("Cannot read from a NULL target."); - + throw new IllegalStateException("Cannot read from a null target"); + try { Object result = FieldUtils.readField(data.get(fieldIndex), target, true); - + // Use the converter, if we have it if (needConversion()) return converter.getSpecific(result); else return (TField) result; - + } catch (IllegalAccessException e) { throw new FieldAccessException("Cannot read field due to a security limitation.", e); } @@ -282,7 +283,7 @@ public class StructureModifier { */ public StructureModifier write(int fieldIndex, TField value) throws FieldAccessException { if (fieldIndex < 0 || fieldIndex >= data.size()) - throw new FieldAccessException("Field index must be within 0 - count", + throw new FieldAccessException("Field index must be within 0 - count", new IndexOutOfBoundsException("Out of bounds")); if (target == null) throw new IllegalStateException("Cannot write to a NULL target."); @@ -364,7 +365,7 @@ public class StructureModifier { // Write a default instance to every field for (Field field : defaultFields.keySet()) { try { - FieldUtils.writeField(field, target, + FieldUtils.writeField(field, target, generator.getDefault(field.getType()), true); } catch (IllegalAccessException e) { throw new FieldAccessException("Cannot write to field due to a security limitation.", e); @@ -410,7 +411,7 @@ public class StructureModifier { subtypeCache.put(fieldType, result); // Automatically compile the structure modifier - if (useStructureCompiler && BackgroundCompiler.getInstance() != null) + if (useStructureCompiler && BackgroundCompiler.getInstance() != null) BackgroundCompiler.getInstance().scheduleCompilation(subtypeCache, fieldType); } } @@ -479,12 +480,12 @@ public class StructureModifier { * @return A new structure modifier. */ protected StructureModifier withFieldType( - Class fieldType, List filtered, + Class fieldType, List filtered, Map defaults, EquivalentConverter converter) { StructureModifier result = new StructureModifier(); - result.initialize(targetType, fieldType, filtered, defaults, - converter, new ConcurrentHashMap(), + result.initialize(targetType, fieldType, filtered, defaults, + converter, new ConcurrentHashMap(), useStructureCompiler); return result; } @@ -596,7 +597,7 @@ public class StructureModifier { int mod = field.getModifiers(); // Ignore static and "abstract packet" fields - if (!Modifier.isStatic(mod) && + if (!Modifier.isStatic(mod) && (superclassExclude == null || !field.getDeclaringClass().equals(superclassExclude) )) { diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/reflect/cloning/BukkitCloner.java b/ProtocolLib/src/main/java/com/comphenix/protocol/reflect/cloning/BukkitCloner.java index 4ccac36d..cf4c8f16 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/reflect/cloning/BukkitCloner.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/reflect/cloning/BukkitCloner.java @@ -2,16 +2,16 @@ * ProtocolLib - Bukkit server library that allows access to the Minecraft protocol. * Copyright (C) 2012 Kristian S. Stangeland * - * This program is free software; you can redistribute it and/or modify it under the terms of the - * GNU General Public License as published by the Free Software Foundation; either version 2 of + * This program is free software; you can redistribute it and/or modify it under the terms of the + * GNU General Public License as published by the Free Software Foundation; either version 2 of * the License, or (at your option) any later version. * - * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along with this program; - * if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + * You should have received a copy of the GNU General Public License along with this program; + * if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA * 02111-1307 USA */ @@ -40,7 +40,8 @@ public class BukkitCloner implements Cloner { List> classes = Lists.newArrayList(); classes.add(MinecraftReflection.getItemStackClass()); - classes.add(MinecraftReflection.getChunkPositionClass()); + // TODO: Chunk position does not exist + // classes.add(MinecraftReflection.getChunkPositionClass()); classes.add(MinecraftReflection.getDataWatcherClass()); if (MinecraftReflection.isUsingNetty()) { @@ -72,7 +73,7 @@ public class BukkitCloner implements Cloner { if (source == null) throw new IllegalArgumentException("source cannot be NULL."); - // Convert to a wrapper + // Convert to a wrapper switch (findMatchingClass(source.getClass())) { case 0: return MinecraftReflection.getMinecraftItemStack(MinecraftReflection.getBukkitItemStack(source).clone()); diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/reflect/instances/DefaultInstances.java b/ProtocolLib/src/main/java/com/comphenix/protocol/reflect/instances/DefaultInstances.java index 442cfc03..55f9afde 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/reflect/instances/DefaultInstances.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/reflect/instances/DefaultInstances.java @@ -2,16 +2,16 @@ * ProtocolLib - Bukkit server library that allows access to the Minecraft protocol. * Copyright (C) 2012 Kristian S. Stangeland * - * This program is free software; you can redistribute it and/or modify it under the terms of the - * GNU General Public License as published by the Free Software Foundation; either version 2 of + * This program is free software; you can redistribute it and/or modify it under the terms of the + * GNU General Public License as published by the Free Software Foundation; either version 2 of * the License, or (at your option) any later version. * - * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along with this program; - * if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + * You should have received a copy of the GNU General Public License along with this program; + * if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA * 02111-1307 USA */ @@ -125,7 +125,7 @@ public class DefaultInstances implements InstanceProvider { } /** - * Retrieve the the maximum height of the hierachy of creates types. + * Retrieve the the maximum height of the hierachy of creates types. * @return Maximum height. */ public int getMaximumRecursion() { @@ -220,7 +220,7 @@ public class DefaultInstances implements InstanceProvider { if (getDefaultInternal(type, providers, recursionLevel) == null) { return true; } - } + } return false; } @@ -249,7 +249,6 @@ public class DefaultInstances implements InstanceProvider { @SuppressWarnings("unchecked") private T getDefaultInternal(Class type, List providers, int recursionLevel) { - // The instance providiers should protect themselves against recursion try { for (InstanceProvider generator : providers) { @@ -276,12 +275,13 @@ public class DefaultInstances implements InstanceProvider { Object[] params = new Object[parameterCount]; Class[] types = minimum.getParameterTypes(); - // Fill out + // Fill out for (int i = 0; i < parameterCount; i++) { params[i] = getDefaultInternal(types[i], providers, recursionLevel + 1); // Did we break the non-null contract? if (params[i] == null && nonNull) { + System.out.println("Nonnull contract broken."); return null; } } @@ -316,7 +316,7 @@ public class DefaultInstances implements InstanceProvider { } /** - * Used by the default instance provider to create a class from a given constructor. + * Used by the default instance provider to create a class from a given constructor. * The default method uses reflection. * @param type - the type to create. * @param constructor - the constructor to use. @@ -326,10 +326,10 @@ public class DefaultInstances implements InstanceProvider { */ protected T createInstance(Class type, Constructor constructor, Class[] types, Object[] params) { try { - return (T) constructor.newInstance(params); + return constructor.newInstance(params); } catch (Exception e) { - //e.printStackTrace(); - // Cannot create it + // System.out.println("Failed to create instance " + constructor); + // e.printStackTrace(); return null; } } diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/utility/Constants.java b/ProtocolLib/src/main/java/com/comphenix/protocol/utility/Constants.java new file mode 100644 index 00000000..2e095c6b --- /dev/null +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/utility/Constants.java @@ -0,0 +1,14 @@ +/** + * (c) 2014 dmulloy2 + */ +package com.comphenix.protocol.utility; + +/** + * @author dmulloy2 + */ + +public final class Constants { + public static final String PACKAGE_VERSION = "v1_8_R1"; + public static final String NMS = "net.minecraft.server." + PACKAGE_VERSION; + public static final String OBC = "org.bukkit.craftbukkit." + PACKAGE_VERSION; +} \ No newline at end of file diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/utility/MinecraftReflection.java b/ProtocolLib/src/main/java/com/comphenix/protocol/utility/MinecraftReflection.java index ba0987b7..95d200f9 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/utility/MinecraftReflection.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/utility/MinecraftReflection.java @@ -113,11 +113,6 @@ public class MinecraftReflection { */ private static String MINECRAFT_PREFIX_PACKAGE = "net.minecraft.server"; - /** - * The package with all the library classes. - */ - private static String MINECRAFT_LIBRARY_PACKAGE = "net.minecraft.util"; - /** * Represents a regular expression that will match the version string in a package: * org.bukkit.craftbukkit.v1_6_R2 -> v1_6_R2 @@ -228,9 +223,6 @@ public class MinecraftReflection { // Libigot patch handleLibigot(); - // Minecraft library package - handleLibraryPackage(); - // Next, do the same for CraftEntity.getHandle() in order to get the correct Minecraft package Class craftEntity = getCraftEntityClass(); Method getHandle = craftEntity.getMethod("getHandle"); @@ -277,29 +269,6 @@ public class MinecraftReflection { } } - /** - * Retrieve the Minecraft library package string. - * @return The library package. - */ - private static String getMinecraftLibraryPackage() { - getMinecraftPackage(); - return MINECRAFT_LIBRARY_PACKAGE; - } - - private static void handleLibraryPackage() { - try { - MINECRAFT_LIBRARY_PACKAGE = "net.minecraft.util"; - // Try loading Google GSON - getClassSource().loadClass(CachedPackage.combine(MINECRAFT_LIBRARY_PACKAGE, "com.google.gson.Gson")); - - } catch (Exception e) { - // Assume it's MCPC - MINECRAFT_LIBRARY_PACKAGE = ""; - ProtocolLibrary.getErrorReporter().reportWarning(MinecraftReflection.class, - Report.newBuilder(REPORT_NON_CRAFTBUKKIT_LIBRARY_PACKAGE)); - } - } - /** * Retrieve the package version of the underlying CraftBukkit server. * @return The package version, or NULL if not applicable (before 1.4.6). @@ -1208,18 +1177,17 @@ public class MinecraftReflection { Class normalChunkGenerator = getCraftBukkitClass("generator.NormalChunkGenerator"); // ChunkPosition a(net.minecraft.server.World world, String string, int i, int i1, int i2) { - FuzzyMethodContract selected = FuzzyMethodContract.newBuilder(). - banModifier(Modifier.STATIC). - parameterMatches(getMinecraftObjectMatcher(), 0). - parameterExactType(String.class, 1). - parameterExactType(int.class, 2). - parameterExactType(int.class, 3). - parameterExactType(int.class, 4). - build(); + FuzzyMethodContract selected = FuzzyMethodContract.newBuilder() + .banModifier(Modifier.STATIC) + .parameterMatches(getMinecraftObjectMatcher(), 0) + .parameterExactType(String.class, 1) + .parameterExactType(int.class, 2) + .parameterExactType(int.class, 3) + .parameterExactType(int.class, 4) + .build(); return setMinecraftClass("ChunkPosition", - FuzzyReflection.fromClass(normalChunkGenerator). - getMethod(selected).getReturnType()); + FuzzyReflection.fromClass(normalChunkGenerator).getMethod(selected).getReturnType()); } } @@ -1682,13 +1650,7 @@ public class MinecraftReflection { * @return The GSON class. */ public static Class getMinecraftGsonClass() { - try { - return getMinecraftLibraryClass("com.google.gson.Gson"); - } catch (RuntimeException e) { - Class match = FuzzyReflection.fromClass(PacketType.Status.Server.OUT_SERVER_INFO.getPacketClass()). - getFieldByType(".*\\.google\\.gson\\.Gson").getType(); - return setMinecraftLibraryClass("com.google.gson.Gson", match); - } + return getClass("org.bukkit.craftbukkit.libs.com.google.gson.Gson"); } /** @@ -1907,29 +1869,6 @@ public class MinecraftReflection { return getClass(getMinecraftPackage() + "." + className); } - /** - * Retrieve the class object of a specific Minecraft library class. - * @param className - the specific library Minecraft class. - * @return Class object. - * @throws RuntimeException If we are unable to find the given class. - */ - public static Class getMinecraftLibraryClass(String className) { - return getClass(getMinecraftLibraryPackage() + "." + className); - } - - /** - * Set the class object for the specific library class. - * @param className - name of the Minecraft library class. - * @param clazz - the new class object. - * @return The provided clazz object. - */ - private static Class setMinecraftLibraryClass(String className, Class clazz) { - if (libraryPackage == null) - libraryPackage = new CachedPackage(getMinecraftLibraryPackage(), getClassSource()); - libraryPackage.setPackageClass(className, clazz); - return clazz; - } - /** * Set the class object for the specific Minecraft class. * @param className - name of the Minecraft class. diff --git a/ProtocolLib/src/test/java/com/comphenix/protocol/BukkitInitialization.java b/ProtocolLib/src/test/java/com/comphenix/protocol/BukkitInitialization.java index e653daef..4a8aeae8 100644 --- a/ProtocolLib/src/test/java/com/comphenix/protocol/BukkitInitialization.java +++ b/ProtocolLib/src/test/java/com/comphenix/protocol/BukkitInitialization.java @@ -15,6 +15,7 @@ import org.bukkit.inventory.ItemFactory; import org.bukkit.inventory.meta.ItemMeta; import com.comphenix.protocol.reflect.FieldUtils; +import com.comphenix.protocol.utility.Constants; import com.comphenix.protocol.utility.MinecraftReflection; // Will have to be updated for every version though @@ -68,6 +69,6 @@ public class BukkitInitialization { */ public static void initializePackage() { // Initialize reflection - MinecraftReflection.setMinecraftPackage("net.minecraft.server.v1_7_R4", "org.bukkit.craftbukkit.v1_7_R4"); + MinecraftReflection.setMinecraftPackage(Constants.NMS, Constants.OBC); } }