From 8846b28469e6f6864cb4477cc5938727f6b74be1 Mon Sep 17 00:00:00 2001 From: Dan Mulloy Date: Sun, 25 Jan 2015 12:42:30 -0500 Subject: [PATCH] Add support for Particle modification --- .../protocol/events/PacketContainer.java | 13 ++- .../protocol/wrappers/EnumWrappers.java | 86 +++++++++++++++++++ 2 files changed, 98 insertions(+), 1 deletion(-) diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/events/PacketContainer.java b/ProtocolLib/src/main/java/com/comphenix/protocol/events/PacketContainer.java index 6f6f553b..609d00d9 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/events/PacketContainer.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/events/PacketContainer.java @@ -78,6 +78,7 @@ import com.comphenix.protocol.wrappers.EnumWrappers.CombatEventType; import com.comphenix.protocol.wrappers.EnumWrappers.Difficulty; import com.comphenix.protocol.wrappers.EnumWrappers.EntityUseAction; import com.comphenix.protocol.wrappers.EnumWrappers.NativeGameMode; +import com.comphenix.protocol.wrappers.EnumWrappers.Particle; import com.comphenix.protocol.wrappers.EnumWrappers.PlayerAction; import com.comphenix.protocol.wrappers.EnumWrappers.PlayerDigType; import com.comphenix.protocol.wrappers.EnumWrappers.PlayerInfoAction; @@ -739,7 +740,7 @@ public class PacketContainer implements Serializable { } /** - * Retrieve a read/write structure for the PlayerInfo enum in 1.8 + * Retrieve a read/write structure for the PlayerInfo enum in 1.8. * @return A modifier for PlayerInfoAction enum fields. */ public StructureModifier getPlayerInfoAction() { @@ -808,6 +809,16 @@ public class PacketContainer implements Serializable { EnumWrappers.getScoreboardActionClass(), EnumWrappers.getUpdateScoreActionConverter()); } + /** + * Retrieve a read/write structure for the Particle enum in 1.8. + * @return A modifier for Particle enum fields. + */ + public StructureModifier getParticles() { + // Convert to and from the wrapper + return structureModifier.withType( + EnumWrappers.getParticleClass(), EnumWrappers.getParticleConverter()); + } + /** * Retrieves the ID of this packet. *

diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/wrappers/EnumWrappers.java b/ProtocolLib/src/main/java/com/comphenix/protocol/wrappers/EnumWrappers.java index 125bdab0..3beae065 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/wrappers/EnumWrappers.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/wrappers/EnumWrappers.java @@ -1,5 +1,6 @@ package com.comphenix.protocol.wrappers; +import java.util.HashMap; import java.util.Map; import org.bukkit.GameMode; @@ -122,6 +123,79 @@ public abstract class EnumWrappers { REMOVE; } + public enum Particle { + EXPLOSION_NORMAL(0, true), + EXPLOSION_LARGE(1, true), + EXPLOSION_HUGE(2, true), + FIREWORKS_SPARK(3, false), + WATER_BUBBLE(4, false), + WATER_SPLASH(5, false), + WATER_WAKE(6, false), + SUSPENDED(7, false), + SUSPENDED_DEPTH(8, false), + CRIT(9, false), + CRIT_MAGIC(10, false), + SMOKE_NORMAL(11, false), + SMOKE_LARGE(12, false), + SPELL(13, false), + SPELL_INSTANT(14, false), + SPELL_MOB(15, false), + SPELL_MOB_AMBIENT(16, false), + SPELL_WITCH(17, false), + DRIP_WATER(18, false), + DRIP_LAVA(19, false), + VILLAGER_ANGRY(20, false), + VILLAGER_HAPPY(21, false), + TOWN_AURA(22, false), + NOTE(23, false), + PORTAL(24, false), + ENCHANTMENT_TABLE(25, false), + FLAME(26, false), + LAVA(27, false), + FOOTSTEP(28, false), + CLOUD(29, false), + REDSTONE(30, false), + SNOWBALL(31, false), + SNOW_SHOVEL(32, false), + SLIME(33, false), + HEART(34, false), + BARRIER(35, false), + ITEM_CRACK(36, false), + BLOCK_CRACK(37, false), + BLOCK_DUST(38, false), + WATER_DROP(39, false), + ITEM_TAKE(40, false), + MOB_APPEARANCE(41, true); + + private static final Map BY_ID; + static { + BY_ID = new HashMap(); + for (Particle particle : values()) { + BY_ID.put(particle.getId(), particle); + } + } + + private final int id; + private final boolean longDistance; + + private Particle(int id, boolean longDistance) { + this.id = id; + this.longDistance = longDistance; + } + + public int getId() { + return id; + } + + public boolean isLongDistance() { + return longDistance; + } + + public static Particle getById(int id) { + return BY_ID.get(id); + } + } + private static Class PROTOCOL_CLASS = null; private static Class CLIENT_COMMAND_CLASS = null; private static Class CHAT_VISIBILITY_CLASS = null; @@ -136,6 +210,7 @@ public abstract class EnumWrappers { private static Class PLAYER_DIG_TYPE_CLASS = null; private static Class PLAYER_ACTION_CLASS = null; private static Class SCOREBOARD_ACTION_CLASS = null; + private static Class PARTICLE_CLASS = null; private static boolean INITIALIZED = false; private static Map, EquivalentConverter> FROM_NATIVE = Maps.newHashMap(); @@ -165,6 +240,7 @@ public abstract class EnumWrappers { PLAYER_DIG_TYPE_CLASS = getEnum(PacketType.Play.Client.BLOCK_DIG.getPacketClass(), 0); PLAYER_ACTION_CLASS = getEnum(PacketType.Play.Client.ENTITY_ACTION.getPacketClass(), 0); SCOREBOARD_ACTION_CLASS = getEnum(PacketType.Play.Server.SCOREBOARD_SCORE.getPacketClass(), 0); + PARTICLE_CLASS = getEnum(PacketType.Play.Server.WORLD_PARTICLES.getPacketClass(), 0); associate(PROTOCOL_CLASS, Protocol.class, getClientCommandConverter()); associate(CLIENT_COMMAND_CLASS, ClientCommand.class, getClientCommandConverter()); @@ -180,6 +256,7 @@ public abstract class EnumWrappers { associate(PLAYER_DIG_TYPE_CLASS, PlayerDigType.class, getPlayerDiggingActionConverter()); associate(PLAYER_ACTION_CLASS, PlayerAction.class, getEntityActionConverter()); associate(SCOREBOARD_ACTION_CLASS, ScoreboardAction.class, getUpdateScoreActionConverter()); + associate(PARTICLE_CLASS, Particle.class, getParticleConverter()); INITIALIZED = true; } @@ -277,6 +354,11 @@ public abstract class EnumWrappers { return SCOREBOARD_ACTION_CLASS; } + public static Class getParticleClass() { + initialize(); + return PARTICLE_CLASS; + } + // Get the converters public static EquivalentConverter getProtocolConverter() { return new EnumConverter(Protocol.class); @@ -334,6 +416,10 @@ public abstract class EnumWrappers { return new EnumConverter(ScoreboardAction.class); } + public static EquivalentConverter getParticleConverter() { + return new EnumConverter(Particle.class); + } + // The common enum converter @SuppressWarnings({ "rawtypes", "unchecked" }) private static class EnumConverter> implements EquivalentConverter {