Actually update to 1.8
Dieser Commit ist enthalten in:
Ursprung
075ef28b5e
Commit
9b88847c28
@ -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<PacketType> {
|
||||
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 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);
|
||||
@Spigot(minimumBuild = 1628)
|
||||
public static final PacketType TAB_HEADER = new PacketType(PROTOCOL, SENDER, 0x47, -1);
|
||||
@Spigot(minimumBuild = 1628)
|
||||
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<PacketType> {
|
||||
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<PacketType> {
|
||||
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();
|
||||
|
||||
|
@ -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<Map<Integer, Class<?>>> serverMaps = Lists.newArrayList();
|
||||
List<Map<Integer, Class<?>>> clientMaps = Lists.newArrayList();
|
||||
Object[] protocols = enumProtocol.getEnumConstants();
|
||||
|
||||
// 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;
|
||||
|
||||
// Result
|
||||
Register result = new Register();
|
||||
|
||||
// Iterate through the protocols
|
||||
for (Object protocol : protocols) {
|
||||
if (modifier == null)
|
||||
modifier = new StructureModifier<Object>(protocol.getClass().getSuperclass(), false);
|
||||
StructureModifier<Map<Integer, Class<?>>> maps = modifier.withTarget(protocol).withType(Map.class);
|
||||
|
||||
serverMaps.add(maps.read(0));
|
||||
clientMaps.add(maps.read(1));
|
||||
StructureModifier<Map<Object, Map<Integer, Class<?>>>> maps = modifier.withTarget(protocol).withType(Map.class);
|
||||
for (Entry<Object, Map<Integer, Class<?>>> 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<Integer, Class<?>> map : Iterables.concat(serverMaps, clientMaps)) {
|
||||
for (Map<Integer, Class<?>> map : serverMaps.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<Map<Integer, Class<?>>> temp = serverMaps;
|
||||
serverMaps = clientMaps;
|
||||
clientMaps = temp;
|
||||
for (Map<Integer, Class<?>> 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<Map<Integer, Class<?>>> 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<? extends Map<Integer, Class<?>>> maps) {
|
||||
int count = 0;
|
||||
|
||||
for (Map<Integer, Class<?>> 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<? extends Map<Integer, Class<?>>> maps) {
|
||||
// int count = 0;
|
||||
//
|
||||
// for (Map<Integer, Class<?>> map : maps)
|
||||
// count += map.size();
|
||||
// return count;
|
||||
// }
|
||||
}
|
||||
|
@ -187,11 +187,12 @@ public class StructureModifier<TField> {
|
||||
*/
|
||||
@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);
|
||||
|
@ -40,7 +40,8 @@ public class BukkitCloner implements Cloner {
|
||||
List<Class<?>> 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()) {
|
||||
|
@ -249,7 +249,6 @@ public class DefaultInstances implements InstanceProvider {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private <T> T getDefaultInternal(Class<T> type, List<InstanceProvider> providers, int recursionLevel) {
|
||||
|
||||
// The instance providiers should protect themselves against recursion
|
||||
try {
|
||||
for (InstanceProvider generator : providers) {
|
||||
@ -282,6 +281,7 @@ public class DefaultInstances implements InstanceProvider {
|
||||
|
||||
// Did we break the non-null contract?
|
||||
if (params[i] == null && nonNull) {
|
||||
System.out.println("Nonnull contract broken.");
|
||||
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) {
|
||||
try {
|
||||
return (T) constructor.newInstance(params);
|
||||
return constructor.newInstance(params);
|
||||
} catch (Exception e) {
|
||||
// System.out.println("Failed to create instance " + constructor);
|
||||
// e.printStackTrace();
|
||||
// Cannot create it
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
@ -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.
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren