Add support for ResourcePackStatus
Dieser Commit ist enthalten in:
Ursprung
d7087c2da5
Commit
1c8e3b5ee3
@ -76,6 +76,7 @@ import com.comphenix.protocol.wrappers.EnumWrappers.ClientCommand;
|
|||||||
import com.comphenix.protocol.wrappers.EnumWrappers.Difficulty;
|
import com.comphenix.protocol.wrappers.EnumWrappers.Difficulty;
|
||||||
import com.comphenix.protocol.wrappers.EnumWrappers.EntityUseAction;
|
import com.comphenix.protocol.wrappers.EnumWrappers.EntityUseAction;
|
||||||
import com.comphenix.protocol.wrappers.EnumWrappers.NativeGameMode;
|
import com.comphenix.protocol.wrappers.EnumWrappers.NativeGameMode;
|
||||||
|
import com.comphenix.protocol.wrappers.EnumWrappers.ResourcePackStatus;
|
||||||
import com.comphenix.protocol.wrappers.WrappedAttribute;
|
import com.comphenix.protocol.wrappers.WrappedAttribute;
|
||||||
import com.comphenix.protocol.wrappers.WrappedChatComponent;
|
import com.comphenix.protocol.wrappers.WrappedChatComponent;
|
||||||
import com.comphenix.protocol.wrappers.WrappedDataWatcher;
|
import com.comphenix.protocol.wrappers.WrappedDataWatcher;
|
||||||
@ -689,7 +690,17 @@ public class PacketContainer implements Serializable {
|
|||||||
return structureModifier.<NativeGameMode>withType(
|
return structureModifier.<NativeGameMode>withType(
|
||||||
EnumWrappers.getGameModeClass(), EnumWrappers.getGameModeConverter());
|
EnumWrappers.getGameModeClass(), EnumWrappers.getGameModeConverter());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve a read/write structure for the ResourcePackStatus enum in 1.8.
|
||||||
|
* @return A modifier for ResourcePackStatus enum fields.
|
||||||
|
*/
|
||||||
|
public StructureModifier<ResourcePackStatus> getResourcePackStatus() {
|
||||||
|
// Convert to and from the wrapper
|
||||||
|
return structureModifier.<ResourcePackStatus>withType(
|
||||||
|
EnumWrappers.getResourcePackStatusClass(), EnumWrappers.getResourcePackStatusConverter());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves the ID of this packet.
|
* Retrieves the ID of this packet.
|
||||||
* <p>
|
* <p>
|
||||||
|
@ -21,26 +21,26 @@ public abstract class EnumWrappers {
|
|||||||
REQUEST_STATS,
|
REQUEST_STATS,
|
||||||
OPEN_INVENTORY_ACHIEVEMENT;
|
OPEN_INVENTORY_ACHIEVEMENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum ChatVisibility {
|
public enum ChatVisibility {
|
||||||
FULL,
|
FULL,
|
||||||
SYSTEM,
|
SYSTEM,
|
||||||
HIDDEN;
|
HIDDEN;
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum Difficulty {
|
public enum Difficulty {
|
||||||
PEACEFUL,
|
PEACEFUL,
|
||||||
EASY,
|
EASY,
|
||||||
NORMAL,
|
NORMAL,
|
||||||
HARD;
|
HARD;
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum EntityUseAction {
|
public enum EntityUseAction {
|
||||||
INTERACT,
|
INTERACT,
|
||||||
ATTACK,
|
ATTACK,
|
||||||
INTERACT_AT;
|
INTERACT_AT;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a native game mode in Minecraft.
|
* Represents a native game mode in Minecraft.
|
||||||
* <p>
|
* <p>
|
||||||
@ -60,43 +60,58 @@ public abstract class EnumWrappers {
|
|||||||
NONE;
|
NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public enum ResourcePackStatus {
|
||||||
|
SUCCESSFULLY_LOADED,
|
||||||
|
DECLINED,
|
||||||
|
FAILED_DOWNLOAD,
|
||||||
|
ACCEPTED;
|
||||||
|
}
|
||||||
|
|
||||||
private static Class<?> PROTOCOL_CLASS = null;
|
private static Class<?> PROTOCOL_CLASS = null;
|
||||||
private static Class<?> CLIENT_COMMAND_CLASS = null;
|
private static Class<?> CLIENT_COMMAND_CLASS = null;
|
||||||
private static Class<?> CHAT_VISIBILITY_CLASS = null;
|
private static Class<?> CHAT_VISIBILITY_CLASS = null;
|
||||||
private static Class<?> DIFFICULTY_CLASS = null;
|
private static Class<?> DIFFICULTY_CLASS = null;
|
||||||
private static Class<?> ENTITY_USE_ACTION_CLASS = null;
|
private static Class<?> ENTITY_USE_ACTION_CLASS = null;
|
||||||
private static Class<?> GAMEMODE_CLASS = null;
|
private static Class<?> GAMEMODE_CLASS = null;
|
||||||
|
private static Class<?> RESOURCE_PACK_STATUS_CLASS = null;
|
||||||
|
|
||||||
|
private static boolean INITIALIZED = false;
|
||||||
private static Map<Class<?>, EquivalentConverter<?>> FROM_NATIVE = Maps.newHashMap();
|
private static Map<Class<?>, EquivalentConverter<?>> FROM_NATIVE = Maps.newHashMap();
|
||||||
private static Map<Class<?>, EquivalentConverter<?>> FROM_WRAPPER = Maps.newHashMap();
|
private static Map<Class<?>, EquivalentConverter<?>> FROM_WRAPPER = Maps.newHashMap();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize the wrappers, if we haven't already.
|
* Initialize the wrappers, if we haven't already.
|
||||||
*/
|
*/
|
||||||
private static void initialize() {
|
private static void initialize() {
|
||||||
if (!MinecraftReflection.isUsingNetty())
|
if (!MinecraftReflection.isUsingNetty())
|
||||||
throw new IllegalArgumentException("Not supported on 1.6.4 and earlier.");
|
throw new IllegalArgumentException("Not supported on 1.6.4 and earlier.");
|
||||||
|
|
||||||
|
if (INITIALIZED)
|
||||||
|
return;
|
||||||
|
|
||||||
PROTOCOL_CLASS = getEnum(PacketType.Handshake.Client.SET_PROTOCOL.getPacketClass(), 0);
|
PROTOCOL_CLASS = getEnum(PacketType.Handshake.Client.SET_PROTOCOL.getPacketClass(), 0);
|
||||||
CLIENT_COMMAND_CLASS = getEnum(PacketType.Play.Client.CLIENT_COMMAND.getPacketClass(), 0);
|
CLIENT_COMMAND_CLASS = getEnum(PacketType.Play.Client.CLIENT_COMMAND.getPacketClass(), 0);
|
||||||
CHAT_VISIBILITY_CLASS = getEnum(PacketType.Play.Client.SETTINGS.getPacketClass(), 0);
|
CHAT_VISIBILITY_CLASS = getEnum(PacketType.Play.Client.SETTINGS.getPacketClass(), 0);
|
||||||
DIFFICULTY_CLASS = getEnum(PacketType.Play.Server.LOGIN.getPacketClass(), 1);
|
DIFFICULTY_CLASS = getEnum(PacketType.Play.Server.LOGIN.getPacketClass(), 1);
|
||||||
ENTITY_USE_ACTION_CLASS = getEnum(PacketType.Play.Client.USE_ENTITY.getPacketClass(), 0);
|
ENTITY_USE_ACTION_CLASS = getEnum(PacketType.Play.Client.USE_ENTITY.getPacketClass(), 0);
|
||||||
GAMEMODE_CLASS = getEnum(PacketType.Play.Server.LOGIN.getPacketClass(), 0);
|
GAMEMODE_CLASS = getEnum(PacketType.Play.Server.LOGIN.getPacketClass(), 0);
|
||||||
|
RESOURCE_PACK_STATUS_CLASS = getEnum(PacketType.Play.Client.RESOURCE_PACK_STATUS.getPacketClass(), 0);
|
||||||
|
|
||||||
associate(PROTOCOL_CLASS, Protocol.class, getClientCommandConverter());
|
associate(PROTOCOL_CLASS, Protocol.class, getClientCommandConverter());
|
||||||
associate(CLIENT_COMMAND_CLASS, ClientCommand.class, getClientCommandConverter());
|
associate(CLIENT_COMMAND_CLASS, ClientCommand.class, getClientCommandConverter());
|
||||||
associate(CHAT_VISIBILITY_CLASS, ChatVisibility.class, getChatVisibilityConverter());
|
associate(CHAT_VISIBILITY_CLASS, ChatVisibility.class, getChatVisibilityConverter());
|
||||||
associate(DIFFICULTY_CLASS, Difficulty.class, getDifficultyConverter());
|
associate(DIFFICULTY_CLASS, Difficulty.class, getDifficultyConverter());
|
||||||
associate(ENTITY_USE_ACTION_CLASS, EntityUseAction.class, getEntityUseActionConverter());
|
associate(ENTITY_USE_ACTION_CLASS, EntityUseAction.class, getEntityUseActionConverter());
|
||||||
associate(GAMEMODE_CLASS, NativeGameMode.class, getGameModeConverter());
|
associate(GAMEMODE_CLASS, NativeGameMode.class, getGameModeConverter());
|
||||||
|
associate(RESOURCE_PACK_STATUS_CLASS, ResourcePackStatus.class, getResourcePackStatusConverter());
|
||||||
|
INITIALIZED = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void associate(Class<?> nativeClass, Class<?> wrapperClass, EquivalentConverter<?> converter) {
|
private static void associate(Class<?> nativeClass, Class<?> wrapperClass, EquivalentConverter<?> converter) {
|
||||||
FROM_NATIVE.put(nativeClass, converter);
|
FROM_NATIVE.put(nativeClass, converter);
|
||||||
FROM_WRAPPER.put(wrapperClass, converter);
|
FROM_WRAPPER.put(wrapperClass, converter);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the enum field with the given declaration index (in relation to the other enums).
|
* Retrieve the enum field with the given declaration index (in relation to the other enums).
|
||||||
* @param clazz - the declaration class.
|
* @param clazz - the declaration class.
|
||||||
@ -106,66 +121,85 @@ public abstract class EnumWrappers {
|
|||||||
private static Class<?> getEnum(Class<?> clazz, int index) {
|
private static Class<?> getEnum(Class<?> clazz, int index) {
|
||||||
return FuzzyReflection.fromClass(clazz, true).getFieldListByType(Enum.class).get(index).getType();
|
return FuzzyReflection.fromClass(clazz, true).getFieldListByType(Enum.class).get(index).getType();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Map<Class<?>, EquivalentConverter<?>> getFromNativeMap() {
|
public static Map<Class<?>, EquivalentConverter<?>> getFromNativeMap() {
|
||||||
return FROM_NATIVE;
|
return FROM_NATIVE;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Map<Class<?>, EquivalentConverter<?>> getFromWrapperMap() {
|
public static Map<Class<?>, EquivalentConverter<?>> getFromWrapperMap() {
|
||||||
return FROM_WRAPPER;
|
return FROM_WRAPPER;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the native enum classes
|
// Get the native enum classes
|
||||||
public static Class<?> getProtocolClass() {
|
public static Class<?> getProtocolClass() {
|
||||||
initialize();
|
initialize();
|
||||||
return PROTOCOL_CLASS;
|
return PROTOCOL_CLASS;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Class<?> getClientCommandClass() {
|
public static Class<?> getClientCommandClass() {
|
||||||
initialize();
|
initialize();
|
||||||
return CLIENT_COMMAND_CLASS;
|
return CLIENT_COMMAND_CLASS;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Class<?> getChatVisibilityClass() {
|
public static Class<?> getChatVisibilityClass() {
|
||||||
initialize();
|
initialize();
|
||||||
return CHAT_VISIBILITY_CLASS;
|
return CHAT_VISIBILITY_CLASS;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Class<?> getDifficultyClass() {
|
public static Class<?> getDifficultyClass() {
|
||||||
initialize();
|
initialize();
|
||||||
return DIFFICULTY_CLASS;
|
return DIFFICULTY_CLASS;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Class<?> getEntityUseActionClass() {
|
public static Class<?> getEntityUseActionClass() {
|
||||||
initialize();
|
initialize();
|
||||||
return ENTITY_USE_ACTION_CLASS;
|
return ENTITY_USE_ACTION_CLASS;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Class<?> getGameModeClass() {
|
public static Class<?> getGameModeClass() {
|
||||||
initialize();
|
initialize();
|
||||||
return GAMEMODE_CLASS;
|
return GAMEMODE_CLASS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Class<?> getResourcePackStatusClass() {
|
||||||
|
initialize();
|
||||||
|
return RESOURCE_PACK_STATUS_CLASS;
|
||||||
|
}
|
||||||
|
|
||||||
// Get the converters
|
// Get the converters
|
||||||
public static EquivalentConverter<Protocol> getProtocolConverter() {
|
public static EquivalentConverter<Protocol> getProtocolConverter() {
|
||||||
return new EnumConverter<Protocol>(Protocol.class);
|
return new EnumConverter<Protocol>(Protocol.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static EquivalentConverter<ClientCommand> getClientCommandConverter() {
|
public static EquivalentConverter<ClientCommand> getClientCommandConverter() {
|
||||||
return new EnumConverter<ClientCommand>(ClientCommand.class);
|
return new EnumConverter<ClientCommand>(ClientCommand.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static EquivalentConverter<ChatVisibility> getChatVisibilityConverter() {
|
public static EquivalentConverter<ChatVisibility> getChatVisibilityConverter() {
|
||||||
return new EnumConverter<ChatVisibility>(ChatVisibility.class);
|
return new EnumConverter<ChatVisibility>(ChatVisibility.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static EquivalentConverter<Difficulty> getDifficultyConverter() {
|
public static EquivalentConverter<Difficulty> getDifficultyConverter() {
|
||||||
return new EnumConverter<Difficulty>(Difficulty.class);
|
return new EnumConverter<Difficulty>(Difficulty.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static EquivalentConverter<EntityUseAction> getEntityUseActionConverter() {
|
public static EquivalentConverter<EntityUseAction> getEntityUseActionConverter() {
|
||||||
return new EnumConverter<EntityUseAction>(EntityUseAction.class);
|
return new EnumConverter<EntityUseAction>(EntityUseAction.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static EquivalentConverter<NativeGameMode> getGameModeConverter() {
|
public static EquivalentConverter<NativeGameMode> getGameModeConverter() {
|
||||||
return new EnumConverter<NativeGameMode>(NativeGameMode.class);
|
return new EnumConverter<NativeGameMode>(NativeGameMode.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static EquivalentConverter<ResourcePackStatus> getResourcePackStatusConverter() {
|
||||||
|
return new EnumConverter<ResourcePackStatus>(ResourcePackStatus.class);
|
||||||
|
}
|
||||||
|
|
||||||
// The common enum converter
|
// The common enum converter
|
||||||
@SuppressWarnings({"rawtypes", "unchecked"})
|
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||||
private static class EnumConverter<T extends Enum<T>> implements EquivalentConverter<T> {
|
private static class EnumConverter<T extends Enum<T>> implements EquivalentConverter<T> {
|
||||||
private Class<T> specificType;
|
private Class<T> specificType;
|
||||||
|
|
||||||
public EnumConverter(Class<T> specificType) {
|
public EnumConverter(Class<T> specificType) {
|
||||||
this.specificType = specificType;
|
this.specificType = specificType;
|
||||||
}
|
}
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren