Fix join/quit exceptions when wrappers break
Dieser Commit ist enthalten in:
Ursprung
d297e373b4
Commit
502c5960e3
@ -24,9 +24,11 @@ import java.lang.reflect.Modifier;
|
|||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
import com.comphenix.protocol.PacketType;
|
import com.comphenix.protocol.PacketType;
|
||||||
import com.comphenix.protocol.ProtocolLibrary;
|
import com.comphenix.protocol.ProtocolLibrary;
|
||||||
|
import com.comphenix.protocol.ProtocolLogger;
|
||||||
import com.comphenix.protocol.ProtocolManager;
|
import com.comphenix.protocol.ProtocolManager;
|
||||||
import com.comphenix.protocol.injector.BukkitUnwrapper;
|
import com.comphenix.protocol.injector.BukkitUnwrapper;
|
||||||
import com.comphenix.protocol.injector.PacketConstructor;
|
import com.comphenix.protocol.injector.PacketConstructor;
|
||||||
@ -984,41 +986,48 @@ public class BukkitConverters {
|
|||||||
* @return Every converter with a unique generic class.
|
* @return Every converter with a unique generic class.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
// TODO this list needs to be updated
|
|
||||||
public static Map<Class<?>, EquivalentConverter<Object>> getConvertersForGeneric() {
|
public static Map<Class<?>, EquivalentConverter<Object>> getConvertersForGeneric() {
|
||||||
if (genericConverters == null) {
|
if (genericConverters == null) {
|
||||||
// Generics doesn't work, as usual
|
ImmutableMap.Builder<Class<?>, EquivalentConverter<Object>> builder = ImmutableMap.builder();
|
||||||
ImmutableMap.Builder<Class<?>, EquivalentConverter<Object>> builder =
|
addConverter(builder, MinecraftReflection::getDataWatcherClass, BukkitConverters::getDataWatcherConverter);
|
||||||
ImmutableMap.<Class<?>, EquivalentConverter<Object>>builder().
|
addConverter(builder, MinecraftReflection::getItemStackClass, BukkitConverters::getItemStackConverter);
|
||||||
put(MinecraftReflection.getDataWatcherClass(), (EquivalentConverter) getDataWatcherConverter()).
|
addConverter(builder, MinecraftReflection::getNBTBaseClass, BukkitConverters::getNbtConverter);
|
||||||
put(MinecraftReflection.getItemStackClass(), (EquivalentConverter) getItemStackConverter()).
|
addConverter(builder, MinecraftReflection::getNBTCompoundClass, BukkitConverters::getNbtConverter);
|
||||||
put(MinecraftReflection.getNBTBaseClass(), (EquivalentConverter) getNbtConverter()).
|
addConverter(builder, MinecraftReflection::getDataWatcherItemClass, BukkitConverters::getWatchableObjectConverter);
|
||||||
put(MinecraftReflection.getNBTCompoundClass(), (EquivalentConverter) getNbtConverter()).
|
addConverter(builder, MinecraftReflection::getMobEffectClass, BukkitConverters::getPotionEffectConverter);
|
||||||
put(MinecraftReflection.getDataWatcherItemClass(), (EquivalentConverter) getWatchableObjectConverter()).
|
addConverter(builder, MinecraftReflection::getNmsWorldClass, BukkitConverters::getWorldConverter);
|
||||||
put(MinecraftReflection.getMobEffectClass(), (EquivalentConverter) getPotionEffectConverter()).
|
addConverter(builder, MinecraftReflection::getWorldTypeClass, BukkitConverters::getWorldTypeConverter);
|
||||||
put(MinecraftReflection.getNmsWorldClass(), (EquivalentConverter) getWorldConverter());
|
addConverter(builder, MinecraftReflection::getAttributeSnapshotClass, BukkitConverters::getWrappedAttributeConverter);
|
||||||
|
addConverter(builder, MinecraftReflection::getBlockClass, BukkitConverters::getBlockConverter);
|
||||||
if (hasWorldType)
|
addConverter(builder, MinecraftReflection::getGameProfileClass, BukkitConverters::getWrappedGameProfileConverter);
|
||||||
builder.put(MinecraftReflection.getWorldTypeClass(), (EquivalentConverter) getWorldTypeConverter());
|
addConverter(builder, MinecraftReflection::getServerPingClass, BukkitConverters::getWrappedServerPingConverter);
|
||||||
if (hasAttributeSnapshot)
|
addConverter(builder, MinecraftReflection::getStatisticClass, BukkitConverters::getWrappedStatisticConverter);
|
||||||
builder.put(MinecraftReflection.getAttributeSnapshotClass(), (EquivalentConverter) getWrappedAttributeConverter());
|
addConverter(builder, MinecraftReflection::getIBlockDataClass, BukkitConverters::getWrappedBlockDataConverter);
|
||||||
|
|
||||||
// Types added in 1.7.2
|
for (Entry<Class<?>, EquivalentConverter<?>> entry : EnumWrappers.getFromNativeMap().entrySet()) {
|
||||||
if (MinecraftReflection.isUsingNetty()) {
|
addConverter(builder, entry::getKey, entry::getValue);
|
||||||
builder.put(MinecraftReflection.getBlockClass(), (EquivalentConverter) getBlockConverter());
|
|
||||||
builder.put(MinecraftReflection.getGameProfileClass(), (EquivalentConverter) getWrappedGameProfileConverter());
|
|
||||||
builder.put(MinecraftReflection.getIChatBaseComponentClass(), (EquivalentConverter) getWrappedChatComponentConverter());
|
|
||||||
builder.put(MinecraftReflection.getServerPingClass(), (EquivalentConverter) getWrappedServerPingConverter());
|
|
||||||
builder.put(MinecraftReflection.getStatisticClass(), (EquivalentConverter) getWrappedStatisticConverter());
|
|
||||||
|
|
||||||
for (Entry<Class<?>, EquivalentConverter<?>> entry : EnumWrappers.getFromNativeMap().entrySet()) {
|
|
||||||
builder.put((Class) entry.getKey(), (EquivalentConverter) entry.getValue());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
genericConverters = builder.build();
|
genericConverters = builder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
return genericConverters;
|
return genericConverters;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void addConverter(ImmutableMap.Builder<Class<?>, EquivalentConverter<Object>> builder,
|
||||||
|
Supplier<Class<?>> getClass, Supplier<EquivalentConverter> getConverter) {
|
||||||
|
try {
|
||||||
|
Class<?> clazz = getClass.get();
|
||||||
|
if (clazz != null) {
|
||||||
|
EquivalentConverter converter = getConverter.get();
|
||||||
|
if (converter != null) {
|
||||||
|
builder.put(clazz, converter);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ProtocolLogger.debug("Exception registering converter", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve every NMS to/from Bukkit converter as unwrappers.
|
* Retrieve every NMS to/from Bukkit converter as unwrappers.
|
||||||
|
@ -437,8 +437,6 @@ public abstract class EnumWrappers {
|
|||||||
if (nativeClass != null) {
|
if (nativeClass != null) {
|
||||||
FROM_NATIVE.put(nativeClass, converter);
|
FROM_NATIVE.put(nativeClass, converter);
|
||||||
FROM_WRAPPER.put(wrapperClass, converter);
|
FROM_WRAPPER.put(wrapperClass, converter);
|
||||||
} else if (ProtocolLogger.isDebugEnabled()) {
|
|
||||||
// new ClassNotFoundException(wrapperClass.getSimpleName()).printStackTrace();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -452,10 +450,7 @@ public abstract class EnumWrappers {
|
|||||||
try {
|
try {
|
||||||
return FuzzyReflection.fromClass(clazz, true).getFieldListByType(Enum.class).get(index).getType();
|
return FuzzyReflection.fromClass(clazz, true).getFieldListByType(Enum.class).get(index).getType();
|
||||||
} catch (Throwable ex) {
|
} catch (Throwable ex) {
|
||||||
if (ProtocolLogger.isDebugEnabled()) {
|
ProtocolLogger.debug("Exception getting enum from " + clazz + " at index " + index, ex);
|
||||||
// ex.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren