Archiviert
13
0

Add more EnumWrappers (PlayerDiggingAction, EntityAction, UpdateScoreAction)

Dieser Commit ist enthalten in:
Zeruska 2014-12-03 21:56:23 +01:00
Ursprung dabbe3fca9
Commit d6b94e658a
2 geänderte Dateien mit 93 neuen und 0 gelöschten Zeilen

Datei anzeigen

@ -75,11 +75,14 @@ import com.comphenix.protocol.wrappers.EnumWrappers.ChatVisibility;
import com.comphenix.protocol.wrappers.EnumWrappers.ClientCommand;
import com.comphenix.protocol.wrappers.EnumWrappers.CombatEventType;
import com.comphenix.protocol.wrappers.EnumWrappers.Difficulty;
import com.comphenix.protocol.wrappers.EnumWrappers.EntityAction;
import com.comphenix.protocol.wrappers.EnumWrappers.EntityUseAction;
import com.comphenix.protocol.wrappers.EnumWrappers.NativeGameMode;
import com.comphenix.protocol.wrappers.EnumWrappers.PlayerDiggingAction;
import com.comphenix.protocol.wrappers.EnumWrappers.PlayerInfoAction;
import com.comphenix.protocol.wrappers.EnumWrappers.ResourcePackStatus;
import com.comphenix.protocol.wrappers.EnumWrappers.TitleAction;
import com.comphenix.protocol.wrappers.EnumWrappers.UpdateScoreAction;
import com.comphenix.protocol.wrappers.EnumWrappers.WorldBorderAction;
import com.comphenix.protocol.wrappers.WrappedAttribute;
import com.comphenix.protocol.wrappers.WrappedChatComponent;
@ -745,6 +748,36 @@ public class PacketContainer implements Serializable {
EnumWrappers.getCombatEventTypeClass(), EnumWrappers.getCombatEventTypeConverter());
}
/**
* Retrieve a read/write structure for the PlayerDiggingAction enum in 1.8.
* @return A modifier for PlayerDiggingAction enum fields.
*/
public StructureModifier<PlayerDiggingAction> getPlayerDiggingActions() {
// Convert to and from the wrapper
return structureModifier.<PlayerDiggingAction>withType(
EnumWrappers.getPlayerDiggingActionClass(), EnumWrappers.getPlayerDiggingActionConverter());
}
/**
* Retrieve a read/write structure for the EntityAction enum in 1.8.
* @return A modifier for EntityAction enum fields.
*/
public StructureModifier<EntityAction> getEntityActions() {
// Convert to and from the wrapper
return structureModifier.<EntityAction>withType(
EnumWrappers.getEntityActionClass(), EnumWrappers.getEntityActionConverter());
}
/**
* Retrieve a read/write structure for the UpdateScoreAction enum in 1.8.
* @return A modifier for UpdateScoreAction enum fields.
*/
public StructureModifier<UpdateScoreAction> getUpdateScoreActions() {
// Convert to and from the wrapper
return structureModifier.<UpdateScoreAction>withType(
EnumWrappers.getUpdateScoreActionClass(), EnumWrappers.getUpdateScoreActionConverter());
}
/**
* Retrieves the ID of this packet.
* <p>

Datei anzeigen

@ -98,6 +98,30 @@ public abstract class EnumWrappers {
ENTITY_DIED;
}
public enum PlayerDiggingAction {
START_DESTROY_BLOCK,
ABORT_DESTROY_BLOCK,
STOP_DESTROY_BLOCK,
DROP_ALL_ITEMS,
DROP_ITEM,
RELEASE_USE_ITEM;
}
public enum EntityAction {
START_SNEAKING,
STOP_SNEAKING,
STOP_SLEEPING,
START_SPRINTING,
STOP_SPRINTING,
RIDING_JUMP,
OPEN_INVENTORY;
}
public enum UpdateScoreAction {
CHANGE,
REMOVE;
}
private static Class<?> PROTOCOL_CLASS = null;
private static Class<?> CLIENT_COMMAND_CLASS = null;
private static Class<?> CHAT_VISIBILITY_CLASS = null;
@ -109,6 +133,9 @@ public abstract class EnumWrappers {
private static Class<?> TITLE_ACTION_CLASS = null;
private static Class<?> WORLD_BORDER_ACTION_CLASS = null;
private static Class<?> COMBAT_EVENT_TYPE_CLASS = null;
private static Class<?> PLAYER_DIGGING_ACTION_CLASS = null;
private static Class<?> ENTITY_ACTION_CLASS = null;
private static Class<?> UPDATE_SCORE_ACTION_CLASS = null;
private static boolean INITIALIZED = false;
private static Map<Class<?>, EquivalentConverter<?>> FROM_NATIVE = Maps.newHashMap();
@ -135,6 +162,9 @@ public abstract class EnumWrappers {
TITLE_ACTION_CLASS = getEnum(PacketType.Play.Server.TITLE.getPacketClass(), 0);
WORLD_BORDER_ACTION_CLASS = getEnum(PacketType.Play.Server.WORLD_BORDER.getPacketClass(), 0);
COMBAT_EVENT_TYPE_CLASS = getEnum(PacketType.Play.Server.COMBAT_EVENT.getPacketClass(), 0);
PLAYER_DIGGING_ACTION_CLASS = getEnum(PacketType.Play.Client.BLOCK_DIG.getPacketClass(), 0);
ENTITY_ACTION_CLASS = getEnum(PacketType.Play.Client.ENTITY_ACTION.getPacketClass(), 0);
UPDATE_SCORE_ACTION_CLASS = getEnum(PacketType.Play.Server.SCOREBOARD_SCORE.getPacketClass(), 0);
associate(PROTOCOL_CLASS, Protocol.class, getClientCommandConverter());
associate(CLIENT_COMMAND_CLASS, ClientCommand.class, getClientCommandConverter());
@ -147,6 +177,9 @@ public abstract class EnumWrappers {
associate(TITLE_ACTION_CLASS, TitleAction.class, getTitleActionConverter());
associate(WORLD_BORDER_ACTION_CLASS, WorldBorderAction.class, getWorldBorderActionConverter());
associate(COMBAT_EVENT_TYPE_CLASS, CombatEventType.class, getCombatEventTypeConverter());
associate(PLAYER_DIGGING_ACTION_CLASS, PlayerDiggingAction.class, getPlayerDiggingActionConverter());
associate(ENTITY_ACTION_CLASS, EntityAction.class, getEntityActionConverter());
associate(UPDATE_SCORE_ACTION_CLASS, UpdateScoreAction.class, getUpdateScoreActionConverter());
INITIALIZED = true;
}
@ -229,6 +262,21 @@ public abstract class EnumWrappers {
return COMBAT_EVENT_TYPE_CLASS;
}
public static Class<?> getPlayerDiggingActionClass() {
initialize();
return PLAYER_DIGGING_ACTION_CLASS;
}
public static Class<?> getEntityActionClass() {
initialize();
return ENTITY_ACTION_CLASS;
}
public static Class<?> getUpdateScoreActionClass() {
initialize();
return UPDATE_SCORE_ACTION_CLASS;
}
// Get the converters
public static EquivalentConverter<Protocol> getProtocolConverter() {
return new EnumConverter<Protocol>(Protocol.class);
@ -274,6 +322,18 @@ public abstract class EnumWrappers {
return new EnumConverter<CombatEventType>(CombatEventType.class);
}
public static EquivalentConverter<PlayerDiggingAction> getPlayerDiggingActionConverter() {
return new EnumConverter<PlayerDiggingAction>(PlayerDiggingAction.class);
}
public static EquivalentConverter<EntityAction> getEntityActionConverter() {
return new EnumConverter<EntityAction>(EntityAction.class);
}
public static EquivalentConverter<UpdateScoreAction> getUpdateScoreActionConverter() {
return new EnumConverter<UpdateScoreAction>(UpdateScoreAction.class);
}
// The common enum converter
@SuppressWarnings({ "rawtypes", "unchecked" })
private static class EnumConverter<T extends Enum<T>> implements EquivalentConverter<T> {