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 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 TITLE = new PacketType(PROTOCOL, SENDER, 0x45, -1);
|
public static final PacketType CAMERA = new PacketType(PROTOCOL, SENDER, 0x43, -1);
|
||||||
@Spigot(minimumBuild = 1628)
|
public static final PacketType WORLD_BORDER = new PacketType(PROTOCOL, SENDER, 0x44, -1);
|
||||||
public static final PacketType TAB_HEADER = new PacketType(PROTOCOL, SENDER, 0x47, -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 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 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();
|
||||||
|
|
||||||
|
@ -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
|
||||||
StructureModifier<Object> modifier = null;
|
Map<Object, Map<Integer, Class<?>>> serverMaps = Maps.newLinkedHashMap();
|
||||||
|
Map<Object, Map<Integer, Class<?>>> clientMaps = Maps.newLinkedHashMap();
|
||||||
// Result
|
|
||||||
Register result = new Register();
|
Register result = new Register();
|
||||||
|
StructureModifier<Object> modifier = null;
|
||||||
|
|
||||||
|
// Iterate through the protocols
|
||||||
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));
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Map<Integer, Class<?>> map : clientMaps.values()) {
|
||||||
result.containers.add(new MapContainer(map));
|
result.containers.add(new MapContainer(map));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Heuristic - there are more server packets than client packets
|
// // Heuristic - there are more server packets than client packets
|
||||||
if (sum(clientMaps) > sum(serverMaps)) {
|
// if (sum(clientMaps) > sum(serverMaps)) {
|
||||||
// Swap if this is violated
|
// // Swap if this is violated
|
||||||
List<Map<Integer, Class<?>>> temp = serverMaps;
|
// List<Map<Integer, Class<?>>> temp = serverMaps;
|
||||||
serverMaps = clientMaps;
|
// serverMaps = clientMaps;
|
||||||
clientMaps = temp;
|
// 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;
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
@ -2,16 +2,16 @@
|
|||||||
* ProtocolLib - Bukkit server library that allows access to the Minecraft protocol.
|
* ProtocolLib - Bukkit server library that allows access to the Minecraft protocol.
|
||||||
* Copyright (C) 2012 Kristian S. Stangeland
|
* Copyright (C) 2012 Kristian S. Stangeland
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify it under the terms of the
|
* 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
|
* GNU General Public License as published by the Free Software Foundation; either version 2 of
|
||||||
* the License, or (at your option) any later version.
|
* 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;
|
* 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.
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
* See the GNU General Public License for more details.
|
* 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;
|
* 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
|
* if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||||
* 02111-1307 USA
|
* 02111-1307 USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -119,7 +119,7 @@ public class StructureModifier<TField> {
|
|||||||
List<Field> fields = getFields(targetType, superclassExclude);
|
List<Field> fields = getFields(targetType, superclassExclude);
|
||||||
Map<Field, Integer> defaults = requireDefault ? generateDefaultFields(fields) : new HashMap<Field, Integer>();
|
Map<Field, Integer> defaults = requireDefault ? generateDefaultFields(fields) : new HashMap<Field, Integer>();
|
||||||
|
|
||||||
initialize(targetType, Object.class, fields, defaults, null,
|
initialize(targetType, Object.class, fields, defaults, null,
|
||||||
new ConcurrentHashMap<Class, StructureModifier>(), useStructureCompiler);
|
new ConcurrentHashMap<Class, StructureModifier>(), useStructureCompiler);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -135,8 +135,8 @@ public class StructureModifier<TField> {
|
|||||||
* @param other - information to set.
|
* @param other - information to set.
|
||||||
*/
|
*/
|
||||||
protected void initialize(StructureModifier<TField> other) {
|
protected void initialize(StructureModifier<TField> other) {
|
||||||
initialize(other.targetType, other.fieldType, other.data,
|
initialize(other.targetType, other.fieldType, other.data,
|
||||||
other.defaultFields, other.converter, other.subtypeCache,
|
other.defaultFields, other.converter, other.subtypeCache,
|
||||||
other.useStructureCompiler);
|
other.useStructureCompiler);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -149,7 +149,7 @@ public class StructureModifier<TField> {
|
|||||||
* @param converter - converts between the common field type and the actual type the consumer expects.
|
* @param converter - converts between the common field type and the actual type the consumer expects.
|
||||||
* @param subTypeCache - a structure modifier cache.
|
* @param subTypeCache - a structure modifier cache.
|
||||||
*/
|
*/
|
||||||
protected void initialize(Class targetType, Class fieldType,
|
protected void initialize(Class targetType, Class fieldType,
|
||||||
List<Field> data, Map<Field, Integer> defaultFields,
|
List<Field> data, Map<Field, Integer> defaultFields,
|
||||||
EquivalentConverter<TField> converter, Map<Class, StructureModifier> subTypeCache) {
|
EquivalentConverter<TField> converter, Map<Class, StructureModifier> subTypeCache) {
|
||||||
initialize(targetType, fieldType, data, defaultFields, converter, subTypeCache, true);
|
initialize(targetType, fieldType, data, defaultFields, converter, subTypeCache, true);
|
||||||
@ -165,7 +165,7 @@ public class StructureModifier<TField> {
|
|||||||
* @param subTypeCache - a structure modifier cache.
|
* @param subTypeCache - a structure modifier cache.
|
||||||
* @param useStructureCompiler - whether or not to automatically compile this structure modifier.
|
* @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<Field> data, Map<Field, Integer> defaultFields,
|
List<Field> data, Map<Field, Integer> defaultFields,
|
||||||
EquivalentConverter<TField> converter, Map<Class, StructureModifier> subTypeCache,
|
EquivalentConverter<TField> converter, Map<Class, StructureModifier> subTypeCache,
|
||||||
boolean useStructureCompiler) {
|
boolean useStructureCompiler) {
|
||||||
@ -187,21 +187,22 @@ 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);
|
||||||
|
|
||||||
// Use the converter, if we have it
|
// Use the converter, if we have it
|
||||||
if (needConversion())
|
if (needConversion())
|
||||||
return converter.getSpecific(result);
|
return converter.getSpecific(result);
|
||||||
else
|
else
|
||||||
return (TField) result;
|
return (TField) result;
|
||||||
|
|
||||||
} catch (IllegalAccessException e) {
|
} catch (IllegalAccessException e) {
|
||||||
throw new FieldAccessException("Cannot read field due to a security limitation.", e);
|
throw new FieldAccessException("Cannot read field due to a security limitation.", e);
|
||||||
}
|
}
|
||||||
@ -282,7 +283,7 @@ public class StructureModifier<TField> {
|
|||||||
*/
|
*/
|
||||||
public StructureModifier<TField> write(int fieldIndex, TField value) throws FieldAccessException {
|
public StructureModifier<TField> write(int fieldIndex, TField value) throws FieldAccessException {
|
||||||
if (fieldIndex < 0 || fieldIndex >= data.size())
|
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"));
|
new IndexOutOfBoundsException("Out of bounds"));
|
||||||
if (target == null)
|
if (target == null)
|
||||||
throw new IllegalStateException("Cannot write to a NULL target.");
|
throw new IllegalStateException("Cannot write to a NULL target.");
|
||||||
@ -364,7 +365,7 @@ public class StructureModifier<TField> {
|
|||||||
// Write a default instance to every field
|
// Write a default instance to every field
|
||||||
for (Field field : defaultFields.keySet()) {
|
for (Field field : defaultFields.keySet()) {
|
||||||
try {
|
try {
|
||||||
FieldUtils.writeField(field, target,
|
FieldUtils.writeField(field, target,
|
||||||
generator.getDefault(field.getType()), true);
|
generator.getDefault(field.getType()), true);
|
||||||
} catch (IllegalAccessException e) {
|
} catch (IllegalAccessException e) {
|
||||||
throw new FieldAccessException("Cannot write to field due to a security limitation.", e);
|
throw new FieldAccessException("Cannot write to field due to a security limitation.", e);
|
||||||
@ -410,7 +411,7 @@ public class StructureModifier<TField> {
|
|||||||
subtypeCache.put(fieldType, result);
|
subtypeCache.put(fieldType, result);
|
||||||
|
|
||||||
// Automatically compile the structure modifier
|
// Automatically compile the structure modifier
|
||||||
if (useStructureCompiler && BackgroundCompiler.getInstance() != null)
|
if (useStructureCompiler && BackgroundCompiler.getInstance() != null)
|
||||||
BackgroundCompiler.getInstance().scheduleCompilation(subtypeCache, fieldType);
|
BackgroundCompiler.getInstance().scheduleCompilation(subtypeCache, fieldType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -479,12 +480,12 @@ public class StructureModifier<TField> {
|
|||||||
* @return A new structure modifier.
|
* @return A new structure modifier.
|
||||||
*/
|
*/
|
||||||
protected <T> StructureModifier<T> withFieldType(
|
protected <T> StructureModifier<T> withFieldType(
|
||||||
Class fieldType, List<Field> filtered,
|
Class fieldType, List<Field> filtered,
|
||||||
Map<Field, Integer> defaults, EquivalentConverter<T> converter) {
|
Map<Field, Integer> defaults, EquivalentConverter<T> converter) {
|
||||||
|
|
||||||
StructureModifier<T> result = new StructureModifier<T>();
|
StructureModifier<T> result = new StructureModifier<T>();
|
||||||
result.initialize(targetType, fieldType, filtered, defaults,
|
result.initialize(targetType, fieldType, filtered, defaults,
|
||||||
converter, new ConcurrentHashMap<Class, StructureModifier>(),
|
converter, new ConcurrentHashMap<Class, StructureModifier>(),
|
||||||
useStructureCompiler);
|
useStructureCompiler);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -596,7 +597,7 @@ public class StructureModifier<TField> {
|
|||||||
int mod = field.getModifiers();
|
int mod = field.getModifiers();
|
||||||
|
|
||||||
// Ignore static and "abstract packet" fields
|
// Ignore static and "abstract packet" fields
|
||||||
if (!Modifier.isStatic(mod) &&
|
if (!Modifier.isStatic(mod) &&
|
||||||
(superclassExclude == null || !field.getDeclaringClass().equals(superclassExclude)
|
(superclassExclude == null || !field.getDeclaringClass().equals(superclassExclude)
|
||||||
)) {
|
)) {
|
||||||
|
|
||||||
|
@ -2,16 +2,16 @@
|
|||||||
* ProtocolLib - Bukkit server library that allows access to the Minecraft protocol.
|
* ProtocolLib - Bukkit server library that allows access to the Minecraft protocol.
|
||||||
* Copyright (C) 2012 Kristian S. Stangeland
|
* Copyright (C) 2012 Kristian S. Stangeland
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify it under the terms of the
|
* 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
|
* GNU General Public License as published by the Free Software Foundation; either version 2 of
|
||||||
* the License, or (at your option) any later version.
|
* 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;
|
* 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.
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
* See the GNU General Public License for more details.
|
* 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;
|
* 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
|
* if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||||
* 02111-1307 USA
|
* 02111-1307 USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -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()) {
|
||||||
@ -72,7 +73,7 @@ public class BukkitCloner implements Cloner {
|
|||||||
if (source == null)
|
if (source == null)
|
||||||
throw new IllegalArgumentException("source cannot be NULL.");
|
throw new IllegalArgumentException("source cannot be NULL.");
|
||||||
|
|
||||||
// Convert to a wrapper
|
// Convert to a wrapper
|
||||||
switch (findMatchingClass(source.getClass())) {
|
switch (findMatchingClass(source.getClass())) {
|
||||||
case 0:
|
case 0:
|
||||||
return MinecraftReflection.getMinecraftItemStack(MinecraftReflection.getBukkitItemStack(source).clone());
|
return MinecraftReflection.getMinecraftItemStack(MinecraftReflection.getBukkitItemStack(source).clone());
|
||||||
|
@ -2,16 +2,16 @@
|
|||||||
* ProtocolLib - Bukkit server library that allows access to the Minecraft protocol.
|
* ProtocolLib - Bukkit server library that allows access to the Minecraft protocol.
|
||||||
* Copyright (C) 2012 Kristian S. Stangeland
|
* Copyright (C) 2012 Kristian S. Stangeland
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify it under the terms of the
|
* 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
|
* GNU General Public License as published by the Free Software Foundation; either version 2 of
|
||||||
* the License, or (at your option) any later version.
|
* 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;
|
* 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.
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
* See the GNU General Public License for more details.
|
* 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;
|
* 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
|
* if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||||
* 02111-1307 USA
|
* 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.
|
* @return Maximum height.
|
||||||
*/
|
*/
|
||||||
public int getMaximumRecursion() {
|
public int getMaximumRecursion() {
|
||||||
@ -220,7 +220,7 @@ public class DefaultInstances implements InstanceProvider {
|
|||||||
if (getDefaultInternal(type, providers, recursionLevel) == null) {
|
if (getDefaultInternal(type, providers, recursionLevel) == null) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -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) {
|
||||||
@ -276,12 +275,13 @@ public class DefaultInstances implements InstanceProvider {
|
|||||||
Object[] params = new Object[parameterCount];
|
Object[] params = new Object[parameterCount];
|
||||||
Class<?>[] types = minimum.getParameterTypes();
|
Class<?>[] types = minimum.getParameterTypes();
|
||||||
|
|
||||||
// Fill out
|
// Fill out
|
||||||
for (int i = 0; i < parameterCount; i++) {
|
for (int i = 0; i < parameterCount; i++) {
|
||||||
params[i] = getDefaultInternal(types[i], providers, recursionLevel + 1);
|
params[i] = getDefaultInternal(types[i], providers, recursionLevel + 1);
|
||||||
|
|
||||||
// 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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -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.
|
* The default method uses reflection.
|
||||||
* @param type - the type to create.
|
* @param type - the type to create.
|
||||||
* @param constructor - the constructor to use.
|
* @param constructor - the constructor to use.
|
||||||
@ -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) {
|
||||||
//e.printStackTrace();
|
// System.out.println("Failed to create instance " + constructor);
|
||||||
// Cannot create it
|
// e.printStackTrace();
|
||||||
return null;
|
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";
|
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.
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren