Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-10-05 01:31:05 +02:00
Nicer getters in Pair and Triple
Dieser Commit ist enthalten in:
Ursprung
68e4146f3b
Commit
32a84f24ef
@ -64,7 +64,7 @@ public interface ViaAPI<T> {
|
|||||||
* @return API version incremented with meaningful API changes
|
* @return API version incremented with meaningful API changes
|
||||||
*/
|
*/
|
||||||
default int apiVersion() {
|
default int apiVersion() {
|
||||||
return 6;
|
return 7;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -35,14 +35,28 @@ public class Pair<X, Y> {
|
|||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public @Nullable X key() {
|
||||||
|
return key;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @Nullable Y value() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated/*(forRemoval = true)*/
|
||||||
public @Nullable X getKey() {
|
public @Nullable X getKey() {
|
||||||
return key;
|
return key;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated/*(forRemoval = true)*/
|
||||||
public @Nullable Y getValue() {
|
public @Nullable Y getValue() {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated don't count on this continuing to be mutable
|
||||||
|
*/
|
||||||
|
@Deprecated/*(forRemoval = true)*/
|
||||||
public void setValue(@Nullable Y value) {
|
public void setValue(@Nullable Y value) {
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
@ -37,14 +37,29 @@ public class Triple<A, B, C> {
|
|||||||
this.third = third;
|
this.third = third;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public @Nullable A first() {
|
||||||
|
return first;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @Nullable B second() {
|
||||||
|
return second;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @Nullable C third() {
|
||||||
|
return third;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated/*(forRemoval = true)*/
|
||||||
public @Nullable A getFirst() {
|
public @Nullable A getFirst() {
|
||||||
return first;
|
return first;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated/*(forRemoval = true)*/
|
||||||
public @Nullable B getSecond() {
|
public @Nullable B getSecond() {
|
||||||
return second;
|
return second;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated/*(forRemoval = true)*/
|
||||||
public @Nullable C getThird() {
|
public @Nullable C getThird() {
|
||||||
return third;
|
return third;
|
||||||
}
|
}
|
||||||
|
@ -179,9 +179,9 @@ public class BukkitViaInjector implements ViaInjector {
|
|||||||
|
|
||||||
for (Pair<Field, Object> pair : injectedLists) {
|
for (Pair<Field, Object> pair : injectedLists) {
|
||||||
try {
|
try {
|
||||||
Object o = pair.getKey().get(pair.getValue());
|
Object o = pair.key().get(pair.value());
|
||||||
if (o instanceof ListWrapper) {
|
if (o instanceof ListWrapper) {
|
||||||
pair.getKey().set(pair.getValue(), ((ListWrapper) o).getOriginalList());
|
pair.key().set(pair.value(), ((ListWrapper) o).getOriginalList());
|
||||||
}
|
}
|
||||||
} catch (IllegalAccessException e) {
|
} catch (IllegalAccessException e) {
|
||||||
Via.getPlatform().getLogger().severe("Failed to remove injection, reload won't work with connections, please reboot!");
|
Via.getPlatform().getLogger().severe("Failed to remove injection, reload won't work with connections, please reboot!");
|
||||||
@ -354,12 +354,12 @@ public class BukkitViaInjector implements ViaInjector {
|
|||||||
JsonObject currentLists = new JsonObject();
|
JsonObject currentLists = new JsonObject();
|
||||||
try {
|
try {
|
||||||
for (Pair<Field, Object> pair : injectedLists) {
|
for (Pair<Field, Object> pair : injectedLists) {
|
||||||
Object list = pair.getKey().get(pair.getValue());
|
Object list = pair.key().get(pair.value());
|
||||||
// Note down the current value (could be overridden by another plugin)
|
// Note down the current value (could be overridden by another plugin)
|
||||||
currentLists.addProperty(pair.getKey().getName(), list.getClass().getName());
|
currentLists.addProperty(pair.key().getName(), list.getClass().getName());
|
||||||
// Also if it's not overridden we can display what's inside our list (possibly another plugin)
|
// Also if it's not overridden we can display what's inside our list (possibly another plugin)
|
||||||
if (list instanceof ListWrapper) {
|
if (list instanceof ListWrapper) {
|
||||||
wrappedLists.addProperty(pair.getKey().getName(), ((ListWrapper) list).getOriginalList().getClass().getName());
|
wrappedLists.addProperty(pair.key().getName(), ((ListWrapper) list).getOriginalList().getClass().getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
data.add("wrappedLists", wrappedLists);
|
data.add("wrappedLists", wrappedLists);
|
||||||
|
@ -340,8 +340,8 @@ public class ProtocolManagerImpl implements ProtocolManager {
|
|||||||
@Override
|
@Override
|
||||||
public Protocol getBaseProtocol(int serverVersion) {
|
public Protocol getBaseProtocol(int serverVersion) {
|
||||||
for (Pair<Range<Integer>, Protocol> rangeProtocol : Lists.reverse(baseProtocols)) {
|
for (Pair<Range<Integer>, Protocol> rangeProtocol : Lists.reverse(baseProtocols)) {
|
||||||
if (rangeProtocol.getKey().contains(serverVersion)) {
|
if (rangeProtocol.key().contains(serverVersion)) {
|
||||||
return rangeProtocol.getValue();
|
return rangeProtocol.value();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw new IllegalStateException("No Base Protocol for " + serverVersion);
|
throw new IllegalStateException("No Base Protocol for " + serverVersion);
|
||||||
|
@ -72,9 +72,9 @@ public class PacketWrapperImpl implements PacketWrapper {
|
|||||||
public <T> T get(Type<T> type, int index) throws Exception {
|
public <T> T get(Type<T> type, int index) throws Exception {
|
||||||
int currentIndex = 0;
|
int currentIndex = 0;
|
||||||
for (Pair<Type, Object> packetValue : packetValues) {
|
for (Pair<Type, Object> packetValue : packetValues) {
|
||||||
if (packetValue.getKey() != type) continue;
|
if (packetValue.key() != type) continue;
|
||||||
if (currentIndex == index) {
|
if (currentIndex == index) {
|
||||||
return (T) packetValue.getValue();
|
return (T) packetValue.value();
|
||||||
}
|
}
|
||||||
currentIndex++;
|
currentIndex++;
|
||||||
}
|
}
|
||||||
@ -87,7 +87,7 @@ public class PacketWrapperImpl implements PacketWrapper {
|
|||||||
public boolean is(Type type, int index) {
|
public boolean is(Type type, int index) {
|
||||||
int currentIndex = 0;
|
int currentIndex = 0;
|
||||||
for (Pair<Type, Object> packetValue : packetValues) {
|
for (Pair<Type, Object> packetValue : packetValues) {
|
||||||
if (packetValue.getKey() != type) continue;
|
if (packetValue.key() != type) continue;
|
||||||
if (currentIndex == index) {
|
if (currentIndex == index) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -100,7 +100,7 @@ public class PacketWrapperImpl implements PacketWrapper {
|
|||||||
public boolean isReadable(Type type, int index) {
|
public boolean isReadable(Type type, int index) {
|
||||||
int currentIndex = 0;
|
int currentIndex = 0;
|
||||||
for (Pair<Type, Object> packetValue : readableObjects) {
|
for (Pair<Type, Object> packetValue : readableObjects) {
|
||||||
if (packetValue.getKey().getBaseClass() != type.getBaseClass()) continue;
|
if (packetValue.key().getBaseClass() != type.getBaseClass()) continue;
|
||||||
if (currentIndex == index) {
|
if (currentIndex == index) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -114,7 +114,7 @@ public class PacketWrapperImpl implements PacketWrapper {
|
|||||||
public <T> void set(Type<T> type, int index, T value) throws Exception {
|
public <T> void set(Type<T> type, int index, T value) throws Exception {
|
||||||
int currentIndex = 0;
|
int currentIndex = 0;
|
||||||
for (Pair<Type, Object> packetValue : packetValues) {
|
for (Pair<Type, Object> packetValue : packetValues) {
|
||||||
if (packetValue.getKey() != type) continue;
|
if (packetValue.key() != type) continue;
|
||||||
if (currentIndex == index) {
|
if (currentIndex == index) {
|
||||||
packetValue.setValue(attemptTransform(type, value));
|
packetValue.setValue(attemptTransform(type, value));
|
||||||
return;
|
return;
|
||||||
@ -139,15 +139,15 @@ public class PacketWrapperImpl implements PacketWrapper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Pair<Type, Object> read = readableObjects.poll();
|
Pair<Type, Object> read = readableObjects.poll();
|
||||||
Type rtype = read.getKey();
|
Type rtype = read.key();
|
||||||
if (rtype == type
|
if (rtype == type
|
||||||
|| (type.getBaseClass() == rtype.getBaseClass()
|
|| (type.getBaseClass() == rtype.getBaseClass()
|
||||||
&& type.getOutputClass() == rtype.getOutputClass())) {
|
&& type.getOutputClass() == rtype.getOutputClass())) {
|
||||||
return (T) read.getValue();
|
return (T) read.value();
|
||||||
} else if (rtype == Type.NOTHING) {
|
} else if (rtype == Type.NOTHING) {
|
||||||
return read(type); // retry
|
return read(type); // retry
|
||||||
} else {
|
} else {
|
||||||
Exception e = new IOException("Unable to read type " + type.getTypeName() + ", found " + read.getKey().getTypeName());
|
Exception e = new IOException("Unable to read type " + type.getTypeName() + ", found " + read.key().getTypeName());
|
||||||
throw new InformativeException(e).set("Type", type.getTypeName()).set("Packet ID", getId()).set("Packet Type", packetType).set("Data", packetValues);
|
throw new InformativeException(e).set("Type", type.getTypeName()).set("Packet ID", getId()).set("Packet Type", packetType).set("Data", packetValues);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -207,9 +207,9 @@ public class PacketWrapperImpl implements PacketWrapper {
|
|||||||
int index = 0;
|
int index = 0;
|
||||||
for (Pair<Type, Object> packetValue : packetValues) {
|
for (Pair<Type, Object> packetValue : packetValues) {
|
||||||
try {
|
try {
|
||||||
packetValue.getKey().write(buffer, packetValue.getValue());
|
packetValue.key().write(buffer, packetValue.value());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new InformativeException(e).set("Index", index).set("Type", packetValue.getKey().getTypeName()).set("Packet ID", getId()).set("Packet Type", packetType).set("Data", packetValues);
|
throw new InformativeException(e).set("Index", index).set("Type", packetValue.key().getTypeName()).set("Packet ID", getId()).set("Packet Type", packetType).set("Data", packetValues);
|
||||||
}
|
}
|
||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
|
@ -299,8 +299,8 @@ public class Protocol1_11To1_10 extends AbstractProtocol<ClientboundPackets1_9_3
|
|||||||
Via.getPlatform().getLogger().warning("Received unknown 1.11 -> 1.10.2 potion data (" + data + ")");
|
Via.getPlatform().getLogger().warning("Received unknown 1.11 -> 1.10.2 potion data (" + data + ")");
|
||||||
data = 0;
|
data = 0;
|
||||||
} else {
|
} else {
|
||||||
data = newData.getKey();
|
data = newData.key();
|
||||||
isInstant = newData.getValue();
|
isInstant = newData.value();
|
||||||
}
|
}
|
||||||
if (isInstant) {
|
if (isInstant) {
|
||||||
packetWrapper.set(Type.INT, 0, 2007);
|
packetWrapper.set(Type.INT, 0, 2007);
|
||||||
|
@ -63,8 +63,8 @@ public class BlockConnectionStorage implements StorableObject {
|
|||||||
long pair = getChunkSectionIndex(x, y, z);
|
long pair = getChunkSectionIndex(x, y, z);
|
||||||
Pair<byte[], NibbleArray> map = getChunkSection(pair, (blockState & 0xF) != 0);
|
Pair<byte[], NibbleArray> map = getChunkSection(pair, (blockState & 0xF) != 0);
|
||||||
int blockIndex = encodeBlockPos(x, y, z);
|
int blockIndex = encodeBlockPos(x, y, z);
|
||||||
map.getKey()[blockIndex] = (byte) (blockState >> 4);
|
map.key()[blockIndex] = (byte) (blockState >> 4);
|
||||||
NibbleArray nibbleArray = map.getValue();
|
NibbleArray nibbleArray = map.value();
|
||||||
if (nibbleArray != null) {
|
if (nibbleArray != null) {
|
||||||
nibbleArray.set(blockIndex, blockState);
|
nibbleArray.set(blockIndex, blockState);
|
||||||
}
|
}
|
||||||
@ -75,9 +75,9 @@ public class BlockConnectionStorage implements StorableObject {
|
|||||||
Pair<byte[], NibbleArray> map = blockStorage.get(pair);
|
Pair<byte[], NibbleArray> map = blockStorage.get(pair);
|
||||||
if (map == null) return 0;
|
if (map == null) return 0;
|
||||||
short blockPosition = encodeBlockPos(x, y, z);
|
short blockPosition = encodeBlockPos(x, y, z);
|
||||||
NibbleArray nibbleArray = map.getValue();
|
NibbleArray nibbleArray = map.value();
|
||||||
return WorldPackets.toNewId(
|
return WorldPackets.toNewId(
|
||||||
((map.getKey()[blockPosition] & 0xFF) << 4)
|
((map.key()[blockPosition] & 0xFF) << 4)
|
||||||
| (nibbleArray == null ? 0 : nibbleArray.get(blockPosition))
|
| (nibbleArray == null ? 0 : nibbleArray.get(blockPosition))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -87,7 +87,7 @@ public class BlockConnectionStorage implements StorableObject {
|
|||||||
Pair<byte[], NibbleArray> map = blockStorage.get(pair);
|
Pair<byte[], NibbleArray> map = blockStorage.get(pair);
|
||||||
if (map == null) return;
|
if (map == null) return;
|
||||||
int blockIndex = encodeBlockPos(x, y, z);
|
int blockIndex = encodeBlockPos(x, y, z);
|
||||||
NibbleArray nibbleArray = map.getValue();
|
NibbleArray nibbleArray = map.value();
|
||||||
if (nibbleArray != null) {
|
if (nibbleArray != null) {
|
||||||
nibbleArray.set(blockIndex, 0);
|
nibbleArray.set(blockIndex, 0);
|
||||||
boolean allZero = true;
|
boolean allZero = true;
|
||||||
@ -99,8 +99,8 @@ public class BlockConnectionStorage implements StorableObject {
|
|||||||
}
|
}
|
||||||
if (allZero) map.setValue(null);
|
if (allZero) map.setValue(null);
|
||||||
}
|
}
|
||||||
map.getKey()[blockIndex] = 0;
|
map.key()[blockIndex] = 0;
|
||||||
for (short entry : map.getKey()) {
|
for (short entry : map.key()) {
|
||||||
if (entry != 0) return;
|
if (entry != 0) return;
|
||||||
}
|
}
|
||||||
blockStorage.remove(pair);
|
blockStorage.remove(pair);
|
||||||
@ -122,7 +122,7 @@ public class BlockConnectionStorage implements StorableObject {
|
|||||||
map = new Pair<>(new byte[4096], null);
|
map = new Pair<>(new byte[4096], null);
|
||||||
blockStorage.put(index, map);
|
blockStorage.put(index, map);
|
||||||
}
|
}
|
||||||
if (map.getValue() == null && requireNibbleArray) {
|
if (map.value() == null && requireNibbleArray) {
|
||||||
map.setValue(new NibbleArray(4096));
|
map.setValue(new NibbleArray(4096));
|
||||||
}
|
}
|
||||||
return map;
|
return map;
|
||||||
|
@ -325,12 +325,12 @@ public class EntityPackets {
|
|||||||
wrapper.write(Type.INT, properties.size());
|
wrapper.write(Type.INT, properties.size());
|
||||||
for (Map.Entry<String, Pair<Double, List<Triple<UUID, Double, Byte>>>> entry : properties.entrySet()) {
|
for (Map.Entry<String, Pair<Double, List<Triple<UUID, Double, Byte>>>> entry : properties.entrySet()) {
|
||||||
wrapper.write(Type.STRING, entry.getKey()); // Key
|
wrapper.write(Type.STRING, entry.getKey()); // Key
|
||||||
wrapper.write(Type.DOUBLE, entry.getValue().getKey()); // Value
|
wrapper.write(Type.DOUBLE, entry.getValue().key()); // Value
|
||||||
wrapper.write(Type.VAR_INT, entry.getValue().getValue().size());
|
wrapper.write(Type.VAR_INT, entry.getValue().value().size());
|
||||||
for (Triple<UUID, Double, Byte> modifier : entry.getValue().getValue()) {
|
for (Triple<UUID, Double, Byte> modifier : entry.getValue().value()) {
|
||||||
wrapper.write(Type.UUID, modifier.getFirst());
|
wrapper.write(Type.UUID, modifier.first());
|
||||||
wrapper.write(Type.DOUBLE, modifier.getSecond()); // Amount
|
wrapper.write(Type.DOUBLE, modifier.second()); // Amount
|
||||||
wrapper.write(Type.BYTE, modifier.getThird()); // Operation
|
wrapper.write(Type.BYTE, modifier.third()); // Operation
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -162,9 +162,9 @@ public class SpongeViaInjector implements ViaInjector {
|
|||||||
|
|
||||||
for (Pair<Field, Object> pair : injectedLists) {
|
for (Pair<Field, Object> pair : injectedLists) {
|
||||||
try {
|
try {
|
||||||
Object o = pair.getKey().get(pair.getValue());
|
Object o = pair.key().get(pair.value());
|
||||||
if (o instanceof ListWrapper) {
|
if (o instanceof ListWrapper) {
|
||||||
pair.getKey().set(pair.getValue(), ((ListWrapper) o).getOriginalList());
|
pair.key().set(pair.value(), ((ListWrapper) o).getOriginalList());
|
||||||
}
|
}
|
||||||
} catch (IllegalAccessException e) {
|
} catch (IllegalAccessException e) {
|
||||||
Via.getPlatform().getLogger().severe("Failed to remove injection, reload won't work with connections, please reboot!");
|
Via.getPlatform().getLogger().severe("Failed to remove injection, reload won't work with connections, please reboot!");
|
||||||
@ -257,12 +257,12 @@ public class SpongeViaInjector implements ViaInjector {
|
|||||||
JsonObject currentLists = new JsonObject();
|
JsonObject currentLists = new JsonObject();
|
||||||
try {
|
try {
|
||||||
for (Pair<Field, Object> pair : injectedLists) {
|
for (Pair<Field, Object> pair : injectedLists) {
|
||||||
Object list = pair.getKey().get(pair.getValue());
|
Object list = pair.key().get(pair.value());
|
||||||
// Note down the current value (could be overridden by another plugin)
|
// Note down the current value (could be overridden by another plugin)
|
||||||
currentLists.addProperty(pair.getKey().getName(), list.getClass().getName());
|
currentLists.addProperty(pair.key().getName(), list.getClass().getName());
|
||||||
// Also if it's not overridden we can display what's inside our list (possibly another plugin)
|
// Also if it's not overridden we can display what's inside our list (possibly another plugin)
|
||||||
if (list instanceof ListWrapper) {
|
if (list instanceof ListWrapper) {
|
||||||
wrappedLists.addProperty(pair.getKey().getName(), ((ListWrapper) list).getOriginalList().getClass().getName());
|
wrappedLists.addProperty(pair.key().getName(), ((ListWrapper) list).getOriginalList().getClass().getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
data.add("wrappedLists", wrappedLists);
|
data.add("wrappedLists", wrappedLists);
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren