Archiviert
13
0

Actually update to 1.8

Dieser Commit ist enthalten in:
Dan Mulloy 2014-11-28 22:08:46 -05:00
Ursprung 075ef28b5e
Commit 9b88847c28
8 geänderte Dateien mit 137 neuen und 167 gelöschten Zeilen

Datei anzeigen

@ -10,7 +10,6 @@ import java.util.concurrent.Future;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import com.comphenix.protocol.annotations.Spigot;
import com.comphenix.protocol.events.ConnectionSide; import com.comphenix.protocol.events.ConnectionSide;
import com.comphenix.protocol.injector.packet.PacketRegistry; import com.comphenix.protocol.injector.packet.PacketRegistry;
import com.comphenix.protocol.reflect.ObjectEnum; import com.comphenix.protocol.reflect.ObjectEnum;
@ -179,13 +178,16 @@ public class PacketType implements Serializable, Comparable<PacketType> {
public static final PacketType SCOREBOARD_TEAM = new PacketType(PROTOCOL, SENDER, 0x3E, 209); 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 CUSTOM_PAYLOAD = new PacketType(PROTOCOL, SENDER, 0x3F, 250);
public static final PacketType KICK_DISCONNECT = new PacketType(PROTOCOL, SENDER, 0x40, 255); public static final PacketType KICK_DISCONNECT = new PacketType(PROTOCOL, SENDER, 0x40, 255);
public static final PacketType SERVER_DIFFICULTY = new PacketType(PROTOCOL, SENDER, 0x41, -1);
@Spigot(minimumBuild = 1628) 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 TITLE = new PacketType(PROTOCOL, SENDER, 0x45, -1);
@Spigot(minimumBuild = 1628) public static final PacketType SET_COMPRESSION = new PacketType(PROTOCOL, SENDER, 0x46, -1);
public static final PacketType TAB_HEADER = new PacketType(PROTOCOL, SENDER, 0x47, -1); public static final PacketType PLAYER_LIST_HEADER_FOOTER =
@Spigot(minimumBuild = 1628) new PacketType(PROTOCOL, SENDER, 0x47, -1);
public static final PacketType RESOURCE_PACK_SEND = new PacketType(PROTOCOL, SENDER, 0x48, -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 // The instance must
private final static Server INSTANCE = new Server(); private final static Server INSTANCE = new Server();
@ -232,8 +234,7 @@ public class PacketType implements Serializable, Comparable<PacketType> {
public static final PacketType SETTINGS = new PacketType(PROTOCOL, SENDER, 0x15, 204); 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 CLIENT_COMMAND = new PacketType(PROTOCOL, SENDER, 0x16, 205);
public static final PacketType CUSTOM_PAYLOAD = new PacketType(PROTOCOL, SENDER, 0x17, 250); public static final PacketType CUSTOM_PAYLOAD = new PacketType(PROTOCOL, SENDER, 0x17, 250);
public static final PacketType SPECTATE = new PacketType(PROTOCOL, SENDER, 0x18, -1);
@Spigot(minimumBuild = 1628)
public static final PacketType RESOURCE_PACK_STATUS = new PacketType(PROTOCOL, SENDER, 0x19, -1); public static final PacketType RESOURCE_PACK_STATUS = new PacketType(PROTOCOL, SENDER, 0x19, -1);
private final static Client INSTANCE = new Client(); private final static Client INSTANCE = new Client();
@ -332,9 +333,7 @@ public class PacketType implements Serializable, Comparable<PacketType> {
public static final PacketType ENCRYPTION_BEGIN = new PacketType(PROTOCOL, SENDER, 0x01, 253); public static final PacketType ENCRYPTION_BEGIN = new PacketType(PROTOCOL, SENDER, 0x01, 253);
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public static final PacketType SUCCESS = new PacketType(PROTOCOL, SENDER, 0x02, Packets.Server.LOGIN_SUCCESS); public static final PacketType SUCCESS = new PacketType(PROTOCOL, SENDER, 0x02, Packets.Server.LOGIN_SUCCESS);
public static final PacketType SET_COMPRESSION = new PacketType(PROTOCOL, SENDER, 0x03, -1);
@Spigot(minimumBuild = 1628)
public static final PacketType LOGIN_COMPRESSION = new PacketType(PROTOCOL, SENDER, 0x03, -1);
private final static Server INSTANCE = new Server(); private final static Server INSTANCE = new Server();

Datei anzeigen

@ -14,8 +14,8 @@ import com.comphenix.protocol.reflect.StructureModifier;
import com.comphenix.protocol.utility.MinecraftReflection; import com.comphenix.protocol.utility.MinecraftReflection;
import com.google.common.collect.BiMap; import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap; import com.google.common.collect.HashBiMap;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
/** /**
@ -107,42 +107,57 @@ public class NettyProtocolRegistry {
* Load the packet lookup tables in each protocol. * Load the packet lookup tables in each protocol.
*/ */
private synchronized void initialize() { private synchronized void initialize() {
final Object[] protocols = enumProtocol.getEnumConstants(); Object[] protocols = enumProtocol.getEnumConstants();
List<Map<Integer, Class<?>>> serverMaps = Lists.newArrayList();
List<Map<Integer, Class<?>>> clientMaps = Lists.newArrayList(); // ID to Packet class maps
Map<Object, Map<Integer, Class<?>>> serverMaps = Maps.newLinkedHashMap();
Map<Object, Map<Integer, Class<?>>> clientMaps = Maps.newLinkedHashMap();
Register result = new Register();
StructureModifier<Object> modifier = null; StructureModifier<Object> modifier = null;
// Result // Iterate through the protocols
Register result = new Register();
for (Object protocol : protocols) { for (Object protocol : protocols) {
if (modifier == null) if (modifier == null)
modifier = new StructureModifier<Object>(protocol.getClass().getSuperclass(), false); modifier = new StructureModifier<Object>(protocol.getClass().getSuperclass(), false);
StructureModifier<Map<Integer, Class<?>>> maps = modifier.withTarget(protocol).withType(Map.class); StructureModifier<Map<Object, Map<Integer, Class<?>>>> maps = modifier.withTarget(protocol).withType(Map.class);
for (Entry<Object, Map<Integer, Class<?>>> entry : maps.read(0).entrySet()) {
serverMaps.add(maps.read(0)); String direction = entry.getKey().toString();
clientMaps.add(maps.read(1)); 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 // Maps we have to occationally check have changed
for (Map<Integer, Class<?>> map : Iterables.concat(serverMaps, clientMaps)) { for (Map<Integer, Class<?>> map : serverMaps.values()) {
result.containers.add(new MapContainer(map)); result.containers.add(new MapContainer(map));
} }
// Heuristic - there are more server packets than client packets for (Map<Integer, Class<?>> map : clientMaps.values()) {
if (sum(clientMaps) > sum(serverMaps)) { result.containers.add(new MapContainer(map));
// Swap if this is violated
List<Map<Integer, Class<?>>> 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<Map<Integer, Class<?>>> temp = serverMaps;
// serverMaps = clientMaps;
// clientMaps = temp;
// }
for (int i = 0; i < protocols.length; i++) { 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); Protocol equivalent = Protocol.fromVanilla(enumProtocol);
// Associate known types // Associate known types
associatePackets(result, serverMaps.get(i), equivalent, Sender.SERVER); if (serverMaps.containsKey(protocol))
associatePackets(result, clientMaps.get(i), equivalent, Sender.CLIENT); 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) // Exchange (thread safe, as we have only one writer)
this.register = result; this.register = result;
@ -160,16 +175,16 @@ public class NettyProtocolRegistry {
} }
} }
/** // /**
* Retrieve the number of mapping in all the maps. // * Retrieve the number of mapping in all the maps.
* @param maps - iterable of maps. // * @param maps - iterable of maps.
* @return The sum of all the entries. // * @return The sum of all the entries.
*/ // */
private int sum(Iterable<? extends Map<Integer, Class<?>>> maps) { // private int sum(Iterable<? extends Map<Integer, Class<?>>> maps) {
int count = 0; // int count = 0;
//
for (Map<Integer, Class<?>> map : maps) // for (Map<Integer, Class<?>> map : maps)
count += map.size(); // count += map.size();
return count; // return count;
} // }
} }

Datei anzeigen

@ -187,11 +187,12 @@ public class StructureModifier<TField> {
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public TField read(int fieldIndex) throws FieldAccessException { public TField read(int fieldIndex) throws FieldAccessException {
if (fieldIndex < 0 || fieldIndex >= data.size()) if (fieldIndex < 0)
throw new FieldAccessException("Field index must be within 0 - count", throw new FieldAccessException(String.format("Field index (%s) cannot be negative.", fieldIndex));
new IndexOutOfBoundsException("Out of bounds")); if (fieldIndex >= data.size())
throw new FieldAccessException(String.format("Field index out of bounds. (Index: %s, Size: %s)", fieldIndex, data.size()));
if (target == null) if (target == null)
throw new IllegalStateException("Cannot read from a NULL target."); throw new IllegalStateException("Cannot read from a null target");
try { try {
Object result = FieldUtils.readField(data.get(fieldIndex), target, true); Object result = FieldUtils.readField(data.get(fieldIndex), target, true);

Datei anzeigen

@ -40,7 +40,8 @@ public class BukkitCloner implements Cloner {
List<Class<?>> classes = Lists.newArrayList(); List<Class<?>> classes = Lists.newArrayList();
classes.add(MinecraftReflection.getItemStackClass()); classes.add(MinecraftReflection.getItemStackClass());
classes.add(MinecraftReflection.getChunkPositionClass()); // TODO: Chunk position does not exist
// classes.add(MinecraftReflection.getChunkPositionClass());
classes.add(MinecraftReflection.getDataWatcherClass()); classes.add(MinecraftReflection.getDataWatcherClass());
if (MinecraftReflection.isUsingNetty()) { if (MinecraftReflection.isUsingNetty()) {

Datei anzeigen

@ -249,7 +249,6 @@ public class DefaultInstances implements InstanceProvider {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private <T> T getDefaultInternal(Class<T> type, List<InstanceProvider> providers, int recursionLevel) { private <T> T getDefaultInternal(Class<T> type, List<InstanceProvider> providers, int recursionLevel) {
// The instance providiers should protect themselves against recursion // The instance providiers should protect themselves against recursion
try { try {
for (InstanceProvider generator : providers) { for (InstanceProvider generator : providers) {
@ -282,6 +281,7 @@ public class DefaultInstances implements InstanceProvider {
// Did we break the non-null contract? // Did we break the non-null contract?
if (params[i] == null && nonNull) { if (params[i] == null && nonNull) {
System.out.println("Nonnull contract broken.");
return null; return null;
} }
} }
@ -326,10 +326,10 @@ public class DefaultInstances implements InstanceProvider {
*/ */
protected <T> T createInstance(Class<T> type, Constructor<T> constructor, Class<?>[] types, Object[] params) { protected <T> T createInstance(Class<T> type, Constructor<T> constructor, Class<?>[] types, Object[] params) {
try { try {
return (T) constructor.newInstance(params); return constructor.newInstance(params);
} catch (Exception e) { } catch (Exception e) {
// System.out.println("Failed to create instance " + constructor);
// e.printStackTrace(); // e.printStackTrace();
// Cannot create it
return null; return null;
} }
} }

Datei anzeigen

@ -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;
}

Datei anzeigen

@ -113,11 +113,6 @@ public class MinecraftReflection {
*/ */
private static String MINECRAFT_PREFIX_PACKAGE = "net.minecraft.server"; 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: * Represents a regular expression that will match the version string in a package:
* org.bukkit.craftbukkit.v1_6_R2 -> v1_6_R2 * org.bukkit.craftbukkit.v1_6_R2 -> v1_6_R2
@ -228,9 +223,6 @@ public class MinecraftReflection {
// Libigot patch // Libigot patch
handleLibigot(); handleLibigot();
// Minecraft library package
handleLibraryPackage();
// Next, do the same for CraftEntity.getHandle() in order to get the correct Minecraft package // Next, do the same for CraftEntity.getHandle() in order to get the correct Minecraft package
Class<?> craftEntity = getCraftEntityClass(); Class<?> craftEntity = getCraftEntityClass();
Method getHandle = craftEntity.getMethod("getHandle"); 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. * Retrieve the package version of the underlying CraftBukkit server.
* @return The package version, or NULL if not applicable (before 1.4.6). * @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"); Class<?> normalChunkGenerator = getCraftBukkitClass("generator.NormalChunkGenerator");
// ChunkPosition a(net.minecraft.server.World world, String string, int i, int i1, int i2) { // ChunkPosition a(net.minecraft.server.World world, String string, int i, int i1, int i2) {
FuzzyMethodContract selected = FuzzyMethodContract.newBuilder(). FuzzyMethodContract selected = FuzzyMethodContract.newBuilder()
banModifier(Modifier.STATIC). .banModifier(Modifier.STATIC)
parameterMatches(getMinecraftObjectMatcher(), 0). .parameterMatches(getMinecraftObjectMatcher(), 0)
parameterExactType(String.class, 1). .parameterExactType(String.class, 1)
parameterExactType(int.class, 2). .parameterExactType(int.class, 2)
parameterExactType(int.class, 3). .parameterExactType(int.class, 3)
parameterExactType(int.class, 4). .parameterExactType(int.class, 4)
build(); .build();
return setMinecraftClass("ChunkPosition", return setMinecraftClass("ChunkPosition",
FuzzyReflection.fromClass(normalChunkGenerator). FuzzyReflection.fromClass(normalChunkGenerator).getMethod(selected).getReturnType());
getMethod(selected).getReturnType());
} }
} }
@ -1682,13 +1650,7 @@ public class MinecraftReflection {
* @return The GSON class. * @return The GSON class.
*/ */
public static Class<?> getMinecraftGsonClass() { public static Class<?> getMinecraftGsonClass() {
try { return getClass("org.bukkit.craftbukkit.libs.com.google.gson.Gson");
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);
}
} }
/** /**
@ -1907,29 +1869,6 @@ public class MinecraftReflection {
return getClass(getMinecraftPackage() + "." + className); 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. * Set the class object for the specific Minecraft class.
* @param className - name of the Minecraft class. * @param className - name of the Minecraft class.

Datei anzeigen

@ -15,6 +15,7 @@ import org.bukkit.inventory.ItemFactory;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
import com.comphenix.protocol.reflect.FieldUtils; import com.comphenix.protocol.reflect.FieldUtils;
import com.comphenix.protocol.utility.Constants;
import com.comphenix.protocol.utility.MinecraftReflection; import com.comphenix.protocol.utility.MinecraftReflection;
// Will have to be updated for every version though // Will have to be updated for every version though
@ -68,6 +69,6 @@ public class BukkitInitialization {
*/ */
public static void initializePackage() { public static void initializePackage() {
// Initialize reflection // Initialize reflection
MinecraftReflection.setMinecraftPackage("net.minecraft.server.v1_7_R4", "org.bukkit.craftbukkit.v1_7_R4"); MinecraftReflection.setMinecraftPackage(Constants.NMS, Constants.OBC);
} }
} }