From 16a120036c6f870026330462faa1f65280375e2d Mon Sep 17 00:00:00 2001 From: Steven Smith Date: Sat, 12 Mar 2016 10:48:32 -0800 Subject: [PATCH] Make MagicValues key type more lenient. --- .../java/org/spacehq/mc/protocol/data/MagicValues.java | 8 ++++---- .../ingame/server/world/ServerPlayEffectPacket.java | 9 +-------- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/src/main/java/org/spacehq/mc/protocol/data/MagicValues.java b/src/main/java/org/spacehq/mc/protocol/data/MagicValues.java index 188bc1c8..22eaa801 100644 --- a/src/main/java/org/spacehq/mc/protocol/data/MagicValues.java +++ b/src/main/java/org/spacehq/mc/protocol/data/MagicValues.java @@ -83,7 +83,7 @@ import java.util.Map; import java.util.UUID; public class MagicValues { - private static final Map, List> values = new HashMap, List>(); + private static final Map> values = new HashMap>(); static { register(AttributeType.MAX_HEALTH, "generic.maxHealth"); @@ -814,8 +814,8 @@ public class MagicValues { } @SuppressWarnings({ "unchecked" }) - public static > T key(Class keyType, Object value) { - for(Enum key : values.keySet()) { + public static T key(Class keyType, Object value) { + for(Object key : values.keySet()) { if(keyType.isAssignableFrom(key.getClass())) { for(Object val : values.get(key)) { if(val == value || val.equals(value)) { @@ -835,7 +835,7 @@ public class MagicValues { } @SuppressWarnings("unchecked") - public static T value(Class valueType, Enum key) { + public static T value(Class valueType, Object key) { if(values.containsKey(key)) { for(Object val : values.get(key)) { if(valueType.isAssignableFrom(val.getClass())) { diff --git a/src/main/java/org/spacehq/mc/protocol/packet/ingame/server/world/ServerPlayEffectPacket.java b/src/main/java/org/spacehq/mc/protocol/packet/ingame/server/world/ServerPlayEffectPacket.java index ebb64e76..4ac24ce2 100644 --- a/src/main/java/org/spacehq/mc/protocol/packet/ingame/server/world/ServerPlayEffectPacket.java +++ b/src/main/java/org/spacehq/mc/protocol/packet/ingame/server/world/ServerPlayEffectPacket.java @@ -79,14 +79,7 @@ public class ServerPlayEffectPacket implements Packet { @Override public void write(NetOutput out) throws IOException { - int id = 0; - if(this.effect instanceof ParticleEffect) { - id = MagicValues.value(Integer.class, (ParticleEffect) this.effect); - } else if(this.effect instanceof SoundEffect) { - id = MagicValues.value(Integer.class, (SoundEffect) this.effect); - } - - out.writeInt(id); + out.writeInt(MagicValues.value(Integer.class, this.effect)); NetUtil.writePosition(out, this.position); int value = 0; if(this.data instanceof RecordEffectData) {