Fix reflection for 1.21.7/8 (round 5)
This commit is contained in:
@@ -179,9 +179,7 @@ public record PlayerDataWrapper(CompoundTag data) {
|
|||||||
|
|
||||||
|
|
||||||
private int getHeldItemSlot() {
|
private int getHeldItemSlot() {
|
||||||
if (!data.contains("SelectedItemSlot"))
|
return data.getInt("SelectedItemSlot").orElse(0);
|
||||||
return 0;
|
|
||||||
return data.getInt("SelectedItemSlot");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setHeldItemSlot(int slot) {
|
private void setHeldItemSlot(int slot) {
|
||||||
@@ -194,9 +192,7 @@ public record PlayerDataWrapper(CompoundTag data) {
|
|||||||
* @return the value of Score.
|
* @return the value of Score.
|
||||||
*/
|
*/
|
||||||
public int getScore() {
|
public int getScore() {
|
||||||
if (!data.contains("Score"))
|
return data.getInt("Score").orElse(0);
|
||||||
return 0;
|
|
||||||
return data.getInt("Score");
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -214,9 +210,7 @@ public record PlayerDataWrapper(CompoundTag data) {
|
|||||||
* @return the value of XpTotal.
|
* @return the value of XpTotal.
|
||||||
*/
|
*/
|
||||||
public int getTotalExperience() {
|
public int getTotalExperience() {
|
||||||
if (!data.contains("XpTotal"))
|
return data.getInt("XpTotal").orElse(0);
|
||||||
return 0;
|
|
||||||
return data.getInt("XpTotal");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -7,8 +7,8 @@ import fr.pandacube.lib.reflect.ReflectMethod;
|
|||||||
import fr.pandacube.lib.reflect.wrapper.ReflectWrapper;
|
import fr.pandacube.lib.reflect.wrapper.ReflectWrapper;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import static fr.pandacube.lib.util.ThrowableUtil.wrapEx;
|
import static fr.pandacube.lib.util.ThrowableUtil.wrapEx;
|
||||||
import static fr.pandacube.lib.util.ThrowableUtil.wrapReflectEx;
|
import static fr.pandacube.lib.util.ThrowableUtil.wrapReflectEx;
|
||||||
@@ -29,7 +29,6 @@ public class CompoundTag extends ReflectWrapper implements Tag {
|
|||||||
private static final ReflectMethod<?> putShort = wrapEx(() -> REFLECT.method("putShort", String.class, short.class));
|
private static final ReflectMethod<?> putShort = wrapEx(() -> REFLECT.method("putShort", String.class, short.class));
|
||||||
private static final ReflectMethod<?> put = wrapEx(() -> REFLECT.method("put", String.class, Tag.REFLECT.get()));
|
private static final ReflectMethod<?> put = wrapEx(() -> REFLECT.method("put", String.class, Tag.REFLECT.get()));
|
||||||
|
|
||||||
private static final ReflectMethod<?> getTagType = wrapEx(() -> REFLECT.method("getTagType", String.class));
|
|
||||||
private static final ReflectMethod<?> getByte = wrapEx(() -> REFLECT.method("getByte", String.class));
|
private static final ReflectMethod<?> getByte = wrapEx(() -> REFLECT.method("getByte", String.class));
|
||||||
private static final ReflectMethod<?> getShort = wrapEx(() -> REFLECT.method("getShort", String.class));
|
private static final ReflectMethod<?> getShort = wrapEx(() -> REFLECT.method("getShort", String.class));
|
||||||
private static final ReflectMethod<?> getInt = wrapEx(() -> REFLECT.method("getInt", String.class));
|
private static final ReflectMethod<?> getInt = wrapEx(() -> REFLECT.method("getInt", String.class));
|
||||||
@@ -45,11 +44,10 @@ public class CompoundTag extends ReflectWrapper implements Tag {
|
|||||||
private static final ReflectMethod<?> getList = wrapEx(() -> REFLECT.method("getList", String.class, int.class));
|
private static final ReflectMethod<?> getList = wrapEx(() -> REFLECT.method("getList", String.class, int.class));
|
||||||
|
|
||||||
private static final ReflectMethod<?> get = wrapEx(() -> REFLECT.method("get", String.class));
|
private static final ReflectMethod<?> get = wrapEx(() -> REFLECT.method("get", String.class));
|
||||||
private static final ReflectMethod<?> getAllKeys = wrapEx(() -> REFLECT.method("getAllKeys"));
|
private static final ReflectMethod<?> keySet = wrapEx(() -> REFLECT.method("keySet"));
|
||||||
private static final ReflectMethod<?> entrySet = wrapEx(() -> REFLECT.method("entrySet"));
|
private static final ReflectMethod<?> entrySet = wrapEx(() -> REFLECT.method("entrySet"));
|
||||||
private static final ReflectMethod<?> size = wrapEx(() -> REFLECT.method("size"));
|
private static final ReflectMethod<?> size = wrapEx(() -> REFLECT.method("size"));
|
||||||
private static final ReflectMethod<?> contains = wrapEx(() -> REFLECT.method("contains", String.class));
|
private static final ReflectMethod<?> contains = wrapEx(() -> REFLECT.method("contains", String.class));
|
||||||
private static final ReflectMethod<?> containsStringInt = wrapEx(() -> REFLECT.method("contains", String.class, int.class));
|
|
||||||
|
|
||||||
public CompoundTag() {
|
public CompoundTag() {
|
||||||
this(wrapReflectEx(() -> CONSTRUCTOR.instantiate()));
|
this(wrapReflectEx(() -> CONSTRUCTOR.instantiate()));
|
||||||
@@ -95,54 +93,64 @@ public class CompoundTag extends ReflectWrapper implements Tag {
|
|||||||
public void put(String key, Tag value) {
|
public void put(String key, Tag value) {
|
||||||
wrapReflectEx(() -> put.invoke(__getRuntimeInstance(), key, unwrap(value)));
|
wrapReflectEx(() -> put.invoke(__getRuntimeInstance(), key, unwrap(value)));
|
||||||
}
|
}
|
||||||
public byte getTagType(String key) {
|
@SuppressWarnings("unchecked")
|
||||||
return (byte) wrapReflectEx(() -> getTagType.invoke(__getRuntimeInstance(), key));
|
public Optional<Byte> getByte(String key) {
|
||||||
|
return (Optional<Byte>) wrapReflectEx(() -> getByte.invoke(__getRuntimeInstance(), key));
|
||||||
}
|
}
|
||||||
public byte getByte(String key) {
|
@SuppressWarnings("unchecked")
|
||||||
return (byte) wrapReflectEx(() -> getByte.invoke(__getRuntimeInstance(), key));
|
public Optional<Short> getShort(String key) {
|
||||||
|
return (Optional<Short>) wrapReflectEx(() -> getShort.invoke(__getRuntimeInstance(), key));
|
||||||
}
|
}
|
||||||
public short getShort(String key) {
|
@SuppressWarnings("unchecked")
|
||||||
return (short) wrapReflectEx(() -> getShort.invoke(__getRuntimeInstance(), key));
|
public Optional<Integer> getInt(String key) {
|
||||||
|
return (Optional<Integer>) wrapReflectEx(() -> getInt.invoke(__getRuntimeInstance(), key));
|
||||||
}
|
}
|
||||||
public int getInt(String key) {
|
@SuppressWarnings("unchecked")
|
||||||
return (int) wrapReflectEx(() -> getInt.invoke(__getRuntimeInstance(), key));
|
public Optional<Long> getLong(String key) {
|
||||||
|
return (Optional<Long>) wrapReflectEx(() -> getLong.invoke(__getRuntimeInstance(), key));
|
||||||
}
|
}
|
||||||
public long getLong(String key) {
|
@SuppressWarnings("unchecked")
|
||||||
return (long) wrapReflectEx(() -> getLong.invoke(__getRuntimeInstance(), key));
|
public Optional<Float> getFloat(String key) {
|
||||||
|
return (Optional<Float>) wrapReflectEx(() -> getFloat.invoke(__getRuntimeInstance(), key));
|
||||||
}
|
}
|
||||||
public float getFloat(String key) {
|
@SuppressWarnings("unchecked")
|
||||||
return (float) wrapReflectEx(() -> getFloat.invoke(__getRuntimeInstance(), key));
|
public Optional<Double> getDouble(String key) {
|
||||||
|
return (Optional<Double>) wrapReflectEx(() -> getDouble.invoke(__getRuntimeInstance(), key));
|
||||||
}
|
}
|
||||||
public double getDouble(String key) {
|
@SuppressWarnings("unchecked")
|
||||||
return (double) wrapReflectEx(() -> getDouble.invoke(__getRuntimeInstance(), key));
|
public Optional<String> getString(String key) {
|
||||||
|
return (Optional<String>) wrapReflectEx(() -> getString.invoke(__getRuntimeInstance(), key));
|
||||||
}
|
}
|
||||||
public String getString(String key) {
|
@SuppressWarnings("unchecked")
|
||||||
return (String) wrapReflectEx(() -> getString.invoke(__getRuntimeInstance(), key));
|
public Optional<byte[]> getByteArray(String key) {
|
||||||
|
return (Optional<byte[]>) wrapReflectEx(() -> getByteArray.invoke(__getRuntimeInstance(), key));
|
||||||
}
|
}
|
||||||
public byte[] getByteArray(String key) {
|
@SuppressWarnings("unchecked")
|
||||||
return (byte[]) wrapReflectEx(() -> getByteArray.invoke(__getRuntimeInstance(), key));
|
public Optional<int[]> getIntArray(String key) {
|
||||||
|
return (Optional<int[]>) wrapReflectEx(() -> getIntArray.invoke(__getRuntimeInstance(), key));
|
||||||
}
|
}
|
||||||
public int[] getIntArray(String key) {
|
@SuppressWarnings("unchecked")
|
||||||
return (int[]) wrapReflectEx(() -> getIntArray.invoke(__getRuntimeInstance(), key));
|
public Optional<long[]> getLongArray(String key) {
|
||||||
|
return (Optional<long[]>) wrapReflectEx(() -> getLongArray.invoke(__getRuntimeInstance(), key));
|
||||||
}
|
}
|
||||||
public long[] getLongArray(String key) {
|
public Optional<CompoundTag> getCompound(String key) {
|
||||||
return (long[]) wrapReflectEx(() -> getLongArray.invoke(__getRuntimeInstance(), key));
|
return ((Optional<?>) wrapReflectEx(() -> getCompound.invoke(__getRuntimeInstance(), key)))
|
||||||
|
.map(u -> wrap(u, CompoundTag.class));
|
||||||
}
|
}
|
||||||
public CompoundTag getCompound(String key) {
|
@SuppressWarnings("unchecked")
|
||||||
return wrap(wrapReflectEx(() -> getCompound.invoke(__getRuntimeInstance(), key)), CompoundTag.class);
|
public Optional<Boolean> getBoolean(String key) {
|
||||||
|
return (Optional<Boolean>) wrapReflectEx(() -> getBoolean.invoke(__getRuntimeInstance(), key));
|
||||||
}
|
}
|
||||||
public boolean getBoolean(String key) {
|
public Optional<ListTag> getList(String key, int type) {
|
||||||
return (boolean) wrapReflectEx(() -> getBoolean.invoke(__getRuntimeInstance(), key));
|
return ((Optional<?>) wrapReflectEx(() -> getList.invoke(__getRuntimeInstance(), key, type)))
|
||||||
}
|
.map(u -> wrap(u, ListTag.class));
|
||||||
public ListTag getList(String key, int type) {
|
|
||||||
return wrap(wrapReflectEx(() -> getList.invoke(__getRuntimeInstance(), key, type)), ListTag.class);
|
|
||||||
}
|
}
|
||||||
public Tag get(String key) {
|
public Tag get(String key) {
|
||||||
return wrap(wrapReflectEx(() -> get.invoke(__getRuntimeInstance(), key)), Tag.class);
|
return wrap(wrapReflectEx(() -> get.invoke(__getRuntimeInstance(), key)), Tag.class);
|
||||||
}
|
}
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public Set<String> getAllKeys() {
|
public Set<String> keySet() {
|
||||||
return (Set<String>) wrapReflectEx(() -> getAllKeys.invoke(__getRuntimeInstance()));
|
return (Set<String>) wrapReflectEx(() -> keySet.invoke(__getRuntimeInstance()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -159,8 +167,5 @@ public class CompoundTag extends ReflectWrapper implements Tag {
|
|||||||
public boolean contains(String key) {
|
public boolean contains(String key) {
|
||||||
return (boolean) wrapReflectEx(() -> contains.invoke(__getRuntimeInstance(), key));
|
return (boolean) wrapReflectEx(() -> contains.invoke(__getRuntimeInstance(), key));
|
||||||
}
|
}
|
||||||
public boolean contains(String key, int type) {
|
|
||||||
return (boolean) wrapReflectEx(() -> containsStringInt.invoke(__getRuntimeInstance(), key, type));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user