Skip to content

Commit c77a700

Browse files
committed
Add wrapper for ItemSlot
Closes #183
1 parent 10ded26 commit c77a700

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

modules/API/src/main/java/com/comphenix/protocol/events/PacketContainer.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
import com.comphenix.protocol.wrappers.EnumWrappers.CombatEventType;
8181
import com.comphenix.protocol.wrappers.EnumWrappers.Difficulty;
8282
import com.comphenix.protocol.wrappers.EnumWrappers.EntityUseAction;
83+
import com.comphenix.protocol.wrappers.EnumWrappers.ItemSlot;
8384
import com.comphenix.protocol.wrappers.EnumWrappers.NativeGameMode;
8485
import com.comphenix.protocol.wrappers.EnumWrappers.Particle;
8586
import com.comphenix.protocol.wrappers.EnumWrappers.PlayerAction;
@@ -866,6 +867,15 @@ public StructureModifier<SoundCategory> getSoundCategories() {
866867
EnumWrappers.getSoundCategoryClass(), EnumWrappers.getSoundCategoryConverter());
867868
}
868869

870+
/**
871+
* Retrive a read/write structure for the ItemSlot enum in 1.9.
872+
* @return A modifier for ItemSlot enum fields.
873+
*/
874+
public StructureModifier<ItemSlot> getItemSlots() {
875+
return structureModifier.<ItemSlot>withType(
876+
EnumWrappers.getItemSlotClass(), EnumWrappers.getItemSlotConverter());
877+
}
878+
869879
/**
870880
* Retrieves the ID of this packet.
871881
* <p>

modules/API/src/main/java/com/comphenix/protocol/wrappers/EnumWrappers.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,15 @@ public static SoundCategory getByKey(String key) {
306306
}
307307
}
308308

309+
public enum ItemSlot {
310+
MAINHAND,
311+
OFFHAND,
312+
FEET,
313+
LEGS,
314+
CHEST,
315+
HEAD;
316+
}
317+
309318
private static Class<?> PROTOCOL_CLASS = null;
310319
private static Class<?> CLIENT_COMMAND_CLASS = null;
311320
private static Class<?> CHAT_VISIBILITY_CLASS = null;
@@ -322,6 +331,7 @@ public static SoundCategory getByKey(String key) {
322331
private static Class<?> SCOREBOARD_ACTION_CLASS = null;
323332
private static Class<?> PARTICLE_CLASS = null;
324333
private static Class<?> SOUND_CATEGORY_CLASS = null;
334+
private static Class<?> ITEM_SLOT_CLASS = null;
325335

326336
private static boolean INITIALIZED = false;
327337
private static Map<Class<?>, EquivalentConverter<?>> FROM_NATIVE = Maps.newHashMap();
@@ -355,6 +365,7 @@ private static void initialize() {
355365
SCOREBOARD_ACTION_CLASS = getEnum(PacketType.Play.Server.SCOREBOARD_SCORE.getPacketClass(), 0);
356366
PARTICLE_CLASS = getEnum(PacketType.Play.Server.WORLD_PARTICLES.getPacketClass(), 0);
357367
SOUND_CATEGORY_CLASS = getEnum(PacketType.Play.Server.CUSTOM_SOUND_EFFECT.getPacketClass(), 0);
368+
ITEM_SLOT_CLASS = getEnum(PacketType.Play.Server.ENTITY_EQUIPMENT.getPacketClass(), 0);
358369

359370
associate(PROTOCOL_CLASS, Protocol.class, getClientCommandConverter());
360371
associate(CLIENT_COMMAND_CLASS, ClientCommand.class, getClientCommandConverter());
@@ -372,6 +383,7 @@ private static void initialize() {
372383
associate(SCOREBOARD_ACTION_CLASS, ScoreboardAction.class, getUpdateScoreActionConverter());
373384
associate(PARTICLE_CLASS, Particle.class, getParticleConverter());
374385
associate(SOUND_CATEGORY_CLASS, SoundCategory.class, getSoundCategoryConverter());
386+
associate(ITEM_SLOT_CLASS, ItemSlot.class, getItemSlotConverter());
375387
INITIALIZED = true;
376388
}
377389

@@ -485,6 +497,11 @@ public static Class<?> getSoundCategoryClass() {
485497
return SOUND_CATEGORY_CLASS;
486498
}
487499

500+
public static Class<?> getItemSlotClass() {
501+
initialize();
502+
return ITEM_SLOT_CLASS;
503+
}
504+
488505
// Get the converters
489506
public static EquivalentConverter<Protocol> getProtocolConverter() {
490507
return new EnumConverter<Protocol>(Protocol.class);
@@ -550,6 +567,10 @@ public static EquivalentConverter<SoundCategory> getSoundCategoryConverter() {
550567
return new EnumConverter<SoundCategory>(SoundCategory.class);
551568
}
552569

570+
public static EquivalentConverter<ItemSlot> getItemSlotConverter() {
571+
return new EnumConverter<ItemSlot>(ItemSlot.class);
572+
}
573+
553574
/**
554575
* Retrieve a generic enum converter for use with StructureModifiers.
555576
* @param enumClass - Enum class

0 commit comments

Comments
 (0)