mirror of
https://github.com/GeyserMC/MCProtocolLib.git
synced 2024-12-12 08:41:00 -05:00
Make MagicValues key type more lenient.
This commit is contained in:
parent
7dd6887fed
commit
16a120036c
2 changed files with 5 additions and 12 deletions
|
@ -83,7 +83,7 @@ import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class MagicValues {
|
public class MagicValues {
|
||||||
private static final Map<Enum<?>, List<Object>> values = new HashMap<Enum<?>, List<Object>>();
|
private static final Map<Object, List<Object>> values = new HashMap<Object, List<Object>>();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
register(AttributeType.MAX_HEALTH, "generic.maxHealth");
|
register(AttributeType.MAX_HEALTH, "generic.maxHealth");
|
||||||
|
@ -814,8 +814,8 @@ public class MagicValues {
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings({ "unchecked" })
|
@SuppressWarnings({ "unchecked" })
|
||||||
public static <T extends Enum<?>> T key(Class<T> keyType, Object value) {
|
public static <T> T key(Class<T> keyType, Object value) {
|
||||||
for(Enum<?> key : values.keySet()) {
|
for(Object key : values.keySet()) {
|
||||||
if(keyType.isAssignableFrom(key.getClass())) {
|
if(keyType.isAssignableFrom(key.getClass())) {
|
||||||
for(Object val : values.get(key)) {
|
for(Object val : values.get(key)) {
|
||||||
if(val == value || val.equals(value)) {
|
if(val == value || val.equals(value)) {
|
||||||
|
@ -835,7 +835,7 @@ public class MagicValues {
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public static <T> T value(Class<T> valueType, Enum<?> key) {
|
public static <T> T value(Class<T> valueType, Object key) {
|
||||||
if(values.containsKey(key)) {
|
if(values.containsKey(key)) {
|
||||||
for(Object val : values.get(key)) {
|
for(Object val : values.get(key)) {
|
||||||
if(valueType.isAssignableFrom(val.getClass())) {
|
if(valueType.isAssignableFrom(val.getClass())) {
|
||||||
|
|
|
@ -79,14 +79,7 @@ public class ServerPlayEffectPacket implements Packet {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(NetOutput out) throws IOException {
|
public void write(NetOutput out) throws IOException {
|
||||||
int id = 0;
|
out.writeInt(MagicValues.value(Integer.class, this.effect));
|
||||||
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);
|
|
||||||
NetUtil.writePosition(out, this.position);
|
NetUtil.writePosition(out, this.position);
|
||||||
int value = 0;
|
int value = 0;
|
||||||
if(this.data instanceof RecordEffectData) {
|
if(this.data instanceof RecordEffectData) {
|
||||||
|
|
Loading…
Reference in a new issue