Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-09-08 22:02:50 +02:00
Produce less overhead in packet handler registering
Instead of creating a void type reader for every single PacketHandler registered, this just directly uses the consumer-like PacketHandler. The distinction between ValueCreator and the normal PacketHandler was unnecessary given you could also just read something in a ValueCreator instance, effectively just being a consumer of a PacketWrapper instance.
Dieser Commit ist enthalten in:
Ursprung
a8b3444ff5
Commit
7b1f9c199a
@ -25,7 +25,7 @@ package com.viaversion.viaversion.api.protocol.packet;
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.protocol.Protocol;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.ValueCreator;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.exception.InformativeException;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
@ -241,13 +241,13 @@ public interface PacketWrapper {
|
||||
/**
|
||||
* Creates a new packet with values.
|
||||
*
|
||||
* @param packetType packet type of the new packet
|
||||
* @param valueCreator ValueCreator to write to the packet
|
||||
* @param packetType packet type of the new packet
|
||||
* @param handler handler to write to the packet
|
||||
* @return newly created packet wrapper
|
||||
* @throws Exception if it failed to write the values from the ValueCreator.
|
||||
* @throws Exception if it failed to write the values from the ValueCreator
|
||||
*/
|
||||
default PacketWrapper create(PacketType packetType, ValueCreator valueCreator) throws Exception {
|
||||
return create(packetType.getId(), valueCreator);
|
||||
default PacketWrapper create(PacketType packetType, PacketHandler handler) throws Exception {
|
||||
return create(packetType.getId(), handler);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -261,12 +261,12 @@ public interface PacketWrapper {
|
||||
/**
|
||||
* Creates a new packet with values.
|
||||
*
|
||||
* @param packetId id of the packet
|
||||
* @param valueCreator ValueCreator to write to the packet.
|
||||
* @param packetId id of the packet
|
||||
* @param handler handler to write to the packet
|
||||
* @return newly created packet wrapper
|
||||
* @throws Exception if it failed to write the values from the ValueCreator.
|
||||
* @throws Exception if it failed to write the values from the ValueCreator
|
||||
*/
|
||||
PacketWrapper create(int packetId, ValueCreator valueCreator) throws Exception;
|
||||
PacketWrapper create(int packetId, PacketHandler handler) throws Exception;
|
||||
|
||||
/**
|
||||
* Applies a pipeline from an index to the wrapper.
|
||||
|
@ -23,25 +23,15 @@
|
||||
package com.viaversion.viaversion.api.protocol.remapper;
|
||||
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
import com.viaversion.viaversion.exception.InformativeException;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface PacketHandler extends ValueWriter {
|
||||
public interface PacketHandler {
|
||||
|
||||
/**
|
||||
* Handle a packet
|
||||
* Handles a packet.
|
||||
*
|
||||
* @param wrapper The associated wrapper
|
||||
* @throws Exception Throws exception if it failed to handle the packet
|
||||
* @param wrapper packet wrapper
|
||||
* @throws Exception if an error occurs during the packet handling
|
||||
*/
|
||||
void handle(PacketWrapper wrapper) throws Exception;
|
||||
|
||||
@Override
|
||||
default void write(PacketWrapper writer, Object inputValue) throws Exception {
|
||||
try {
|
||||
handle(writer);
|
||||
} catch (InformativeException e) {
|
||||
e.addSource(this.getClass());
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -26,23 +26,22 @@ import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.exception.CancelException;
|
||||
import com.viaversion.viaversion.exception.InformativeException;
|
||||
import com.viaversion.viaversion.util.Pair;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
|
||||
public abstract class PacketRemapper {
|
||||
private final List<Pair<ValueReader, ValueWriter>> valueRemappers = new ArrayList<>();
|
||||
private final List<PacketHandler> valueRemappers = new ArrayList<>();
|
||||
|
||||
protected PacketRemapper() {
|
||||
registerMap();
|
||||
}
|
||||
|
||||
/**
|
||||
* Map a type to the same type.
|
||||
* Reads and writes the given type.
|
||||
*
|
||||
* @param type Type to map
|
||||
* @param type type to map
|
||||
*/
|
||||
public void map(Type type) {
|
||||
TypeRemapper remapper = new TypeRemapper(type);
|
||||
@ -50,23 +49,23 @@ public abstract class PacketRemapper {
|
||||
}
|
||||
|
||||
/**
|
||||
* Map a type from an old type to a new type
|
||||
* Reads the first given type and writes the second given type.
|
||||
*
|
||||
* @param oldType The old type
|
||||
* @param newType The new type
|
||||
* @param oldType old type
|
||||
* @param newType new type
|
||||
*/
|
||||
public void map(Type oldType, Type newType) {
|
||||
map(new TypeRemapper(oldType), new TypeRemapper(newType));
|
||||
}
|
||||
|
||||
/**
|
||||
* Map a type from an old type to a transformed new type.
|
||||
* Maps a type from an old type to a transformed new type.
|
||||
*
|
||||
* @param oldType The old type
|
||||
* @param <T1> The old return type.
|
||||
* @param newType The new type
|
||||
* @param <T2> The new return type.
|
||||
* @param transformer The transformer to use to produce the new type.
|
||||
* @param <T1> old value type
|
||||
* @param <T2> new value type
|
||||
* @param oldType old type
|
||||
* @param newType new type
|
||||
* @param transformer transformer to produce the new type
|
||||
*/
|
||||
public <T1, T2> void map(Type<T1> oldType, Type<T2> newType, Function<T1, T2> transformer) {
|
||||
map(new TypeRemapper<>(oldType), new ValueTransformer<T1, T2>(newType) {
|
||||
@ -78,11 +77,11 @@ public abstract class PacketRemapper {
|
||||
}
|
||||
|
||||
/**
|
||||
* Map a type from an old type to a transformed new type.
|
||||
* Maps a type from an old type to a transformed new type based on their input type.
|
||||
*
|
||||
* @param <T1> The old return type.
|
||||
* @param transformer The transformer to use to produce the new type.
|
||||
* @param <T2> The new return type.
|
||||
* @param <T1> old value type
|
||||
* @param <T2> new value type
|
||||
* @param transformer transformer to produce the new type
|
||||
*/
|
||||
public <T1, T2> void map(ValueTransformer<T1, T2> transformer) {
|
||||
if (transformer.getInputType() == null) {
|
||||
@ -92,73 +91,79 @@ public abstract class PacketRemapper {
|
||||
}
|
||||
|
||||
/**
|
||||
* Map a type from an old type to a transformed new type.
|
||||
* Maps a type from an old type to a transformed new type.
|
||||
*
|
||||
* @param oldType The old type
|
||||
* @param <T1> The old return type.
|
||||
* @param transformer The transformer to use to produce the new type.
|
||||
* @param <T2> The new return type.
|
||||
* @param <T1> old value type
|
||||
* @param <T2> new value type
|
||||
* @param oldType old type
|
||||
* @param transformer transformer to produce the new type
|
||||
*/
|
||||
public <T1, T2> void map(Type<T1> oldType, ValueTransformer<T1, T2> transformer) {
|
||||
map(new TypeRemapper(oldType), transformer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Map a type using a basic ValueReader to a ValueWriter
|
||||
* Maps a type using a basic ValueReader to a ValueWriter.
|
||||
*
|
||||
* @param inputReader The reader to read with.
|
||||
* @param outputWriter The writer to write with
|
||||
* @param <T> The return type
|
||||
* @param inputReader reader to read with
|
||||
* @param outputWriter writer to write with
|
||||
* @param <T> read/write type
|
||||
*/
|
||||
public <T> void map(ValueReader<T> inputReader, ValueWriter<T> outputWriter) {
|
||||
valueRemappers.add(new Pair<>(inputReader, outputWriter));
|
||||
valueRemappers.add(new ReadWriteValueHandler(inputReader, outputWriter));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a value
|
||||
* Adds a packet handler.
|
||||
*
|
||||
* @param creator The creator to used to make the value(s).
|
||||
*/
|
||||
public void create(ValueCreator creator) {
|
||||
map(new TypeRemapper(Type.NOTHING), creator);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a handler
|
||||
*
|
||||
* @param handler The handler to use to handle the current packet.
|
||||
* @param handler packet handler
|
||||
*/
|
||||
public void handler(PacketHandler handler) {
|
||||
map(new TypeRemapper(Type.NOTHING), handler);
|
||||
valueRemappers.add(handler);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the mappings for this packet
|
||||
* Writes a value.
|
||||
*
|
||||
* @param type type to write
|
||||
* @param value value to write
|
||||
*/
|
||||
public <T> void create(Type<T> type, T value) {
|
||||
valueRemappers.add(wrapper -> wrapper.write(type, value));
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads (and thus removes) the given type.
|
||||
*
|
||||
* @param type type to read
|
||||
*/
|
||||
public void read(Type type) {
|
||||
valueRemappers.add(wrapper -> wrapper.read(type));
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers the handlers for this packet.
|
||||
*/
|
||||
public abstract void registerMap();
|
||||
|
||||
/**
|
||||
* Remap a packet wrapper
|
||||
* Processes a packet wrapper.
|
||||
*
|
||||
* @param packetWrapper The wrapper to remap
|
||||
* @throws InformativeException if it fails to write / read to the packet
|
||||
* @param packetWrapper packet wrapper to remap
|
||||
* @throws InformativeException if packet reading or writing fails
|
||||
* @throws CancelException if the packet should be cancelled
|
||||
*/
|
||||
public void remap(PacketWrapper packetWrapper) throws Exception {
|
||||
try {
|
||||
// Read all the current values
|
||||
for (Pair<ValueReader, ValueWriter> valueRemapper : valueRemappers) {
|
||||
Object object = valueRemapper.getKey().read(packetWrapper);
|
||||
// Convert object to write type :O!!!
|
||||
valueRemapper.getValue().write(packetWrapper, object);
|
||||
for (PacketHandler handler : valueRemappers) {
|
||||
handler.handle(packetWrapper);
|
||||
}
|
||||
// If we had handlers we'd put them here
|
||||
} catch (InformativeException e) {
|
||||
e.addSource(this.getClass());
|
||||
throw e;
|
||||
} catch (CancelException e) {
|
||||
// Pass through CancelExceptions
|
||||
throw e;
|
||||
} catch (InformativeException e) {
|
||||
e.addSource(this.getClass());
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
// Wrap other exceptions during packet handling
|
||||
InformativeException ex = new InformativeException(e);
|
||||
|
@ -23,25 +23,18 @@
|
||||
package com.viaversion.viaversion.api.protocol.remapper;
|
||||
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
import com.viaversion.viaversion.exception.InformativeException;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface ValueCreator extends ValueWriter {
|
||||
/**
|
||||
* Write new values to a Packet.
|
||||
*
|
||||
* @param wrapper The packet to write to
|
||||
* @throws Exception Throws exception if it fails to write.
|
||||
*/
|
||||
void write(PacketWrapper wrapper) throws Exception;
|
||||
public final class ReadWriteValueHandler implements PacketHandler {
|
||||
private final ValueReader reader;
|
||||
private final ValueWriter writer;
|
||||
|
||||
public ReadWriteValueHandler(ValueReader reader, ValueWriter writer) {
|
||||
this.reader = reader;
|
||||
this.writer = writer;
|
||||
}
|
||||
|
||||
@Override
|
||||
default void write(PacketWrapper writer, Object inputValue) throws Exception {
|
||||
try {
|
||||
write(writer);
|
||||
} catch (InformativeException e) {
|
||||
e.addSource(this.getClass());
|
||||
throw e;
|
||||
}
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
writer.write(wrapper, reader.read(wrapper));
|
||||
}
|
||||
}
|
@ -31,12 +31,12 @@ public abstract class ValueTransformer<T1, T2> implements ValueWriter<T1> {
|
||||
private final Type<T1> inputType;
|
||||
private final Type<T2> outputType;
|
||||
|
||||
public ValueTransformer(@Nullable Type<T1> inputType, Type<T2> outputType) {
|
||||
protected ValueTransformer(@Nullable Type<T1> inputType, Type<T2> outputType) {
|
||||
this.inputType = inputType;
|
||||
this.outputType = outputType;
|
||||
}
|
||||
|
||||
public ValueTransformer(Type<T2> outputType) {
|
||||
protected ValueTransformer(Type<T2> outputType) {
|
||||
this(null, outputType);
|
||||
}
|
||||
|
||||
|
@ -35,11 +35,11 @@ public class Pair<X, Y> {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public X getKey() {
|
||||
public @Nullable X getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public Y getValue() {
|
||||
public @Nullable Y getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
|
@ -17,8 +17,8 @@
|
||||
*/
|
||||
package com.viaversion.viaversion.protocol;
|
||||
|
||||
import com.viaversion.viaversion.api.protocol.ProtocolPathEntry;
|
||||
import com.viaversion.viaversion.api.protocol.Protocol;
|
||||
import com.viaversion.viaversion.api.protocol.ProtocolPathEntry;
|
||||
|
||||
public class ProtocolPathEntryImpl implements ProtocolPathEntry {
|
||||
private final int outputProtocolVersion;
|
||||
|
@ -24,7 +24,7 @@ import com.viaversion.viaversion.api.protocol.Protocol;
|
||||
import com.viaversion.viaversion.api.protocol.packet.Direction;
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
import com.viaversion.viaversion.api.protocol.packet.State;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.ValueCreator;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.api.type.TypeConverter;
|
||||
import com.viaversion.viaversion.exception.CancelException;
|
||||
@ -326,9 +326,9 @@ public class PacketWrapperImpl implements PacketWrapper {
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketWrapperImpl create(int packetId, ValueCreator valueCreator) throws Exception {
|
||||
public PacketWrapperImpl create(int packetId, PacketHandler handler) throws Exception {
|
||||
PacketWrapperImpl wrapper = create(packetId);
|
||||
valueCreator.write(wrapper);
|
||||
handler.handle(wrapper);
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
|
@ -22,9 +22,9 @@ import com.viaversion.viaversion.api.connection.ProtocolInfo;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.platform.providers.ViaProviders;
|
||||
import com.viaversion.viaversion.api.protocol.AbstractSimpleProtocol;
|
||||
import com.viaversion.viaversion.api.protocol.Protocol;
|
||||
import com.viaversion.viaversion.api.protocol.ProtocolPathEntry;
|
||||
import com.viaversion.viaversion.api.protocol.ProtocolPipeline;
|
||||
import com.viaversion.viaversion.api.protocol.Protocol;
|
||||
import com.viaversion.viaversion.api.protocol.packet.Direction;
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
import com.viaversion.viaversion.api.protocol.packet.State;
|
||||
|
@ -27,7 +27,6 @@ import com.viaversion.viaversion.api.protocol.AbstractProtocol;
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.ValueCreator;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.ValueTransformer;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.api.type.types.version.Types1_9;
|
||||
@ -119,9 +118,9 @@ public class Protocol1_11To1_10 extends AbstractProtocol<ClientboundPackets1_9_3
|
||||
map(Type.VAR_INT); // 0 - Collected entity id
|
||||
map(Type.VAR_INT); // 1 - Collector entity id
|
||||
|
||||
create(new ValueCreator() {
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void write(PacketWrapper wrapper) throws Exception {
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
wrapper.write(Type.VAR_INT, 1); // 2 - Pickup Count
|
||||
}
|
||||
});
|
||||
|
@ -32,7 +32,6 @@ import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
import com.viaversion.viaversion.api.protocol.packet.State;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.ValueCreator;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.ValueTransformer;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.data.entity.EntityTrackerBase;
|
||||
@ -289,9 +288,9 @@ public class Protocol1_13To1_12_2 extends AbstractProtocol<ClientboundPackets1_1
|
||||
registerClientbound(ClientboundPackets1_12_1.TAB_COMPLETE, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
create(new ValueCreator() {
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void write(PacketWrapper wrapper) throws Exception {
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
wrapper.write(Type.VAR_INT, wrapper.user().get(TabCompleteTracker.class).getTransactionId());
|
||||
|
||||
String input = wrapper.user().get(TabCompleteTracker.class).getInput();
|
||||
@ -482,9 +481,9 @@ public class Protocol1_13To1_12_2 extends AbstractProtocol<ClientboundPackets1_1
|
||||
map(Type.VAR_INT); // action
|
||||
map(Type.BOOLEAN); // crafting book open
|
||||
map(Type.BOOLEAN); // crafting filter active
|
||||
create(new ValueCreator() {
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void write(PacketWrapper wrapper) throws Exception {
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
wrapper.write(Type.BOOLEAN, false); // smelting book open
|
||||
wrapper.write(Type.BOOLEAN, false); // smelting filter active
|
||||
}
|
||||
@ -502,9 +501,9 @@ public class Protocol1_13To1_12_2 extends AbstractProtocol<ClientboundPackets1_1
|
||||
wrapper.write(Type.STRING_ARRAY, stringIds);
|
||||
}
|
||||
if (action == 0) {
|
||||
wrapper.create(ClientboundPackets1_13.DECLARE_RECIPES, new ValueCreator() { // Declare recipes
|
||||
wrapper.create(ClientboundPackets1_13.DECLARE_RECIPES, new PacketHandler() { // Declare recipes
|
||||
@Override
|
||||
public void write(PacketWrapper wrapper) throws Exception {
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
wrapper.write(Type.VAR_INT, RecipeData.recipes.size());
|
||||
for (Map.Entry<String, RecipeData.Recipe> entry : RecipeData.recipes.entrySet()) {
|
||||
wrapper.write(Type.STRING, entry.getKey()); // Id
|
||||
@ -788,9 +787,9 @@ public class Protocol1_13To1_12_2 extends AbstractProtocol<ClientboundPackets1_1
|
||||
}
|
||||
});
|
||||
// Fake the end of the packet
|
||||
create(new ValueCreator() {
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void write(PacketWrapper wrapper) throws Exception {
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
wrapper.write(Type.BOOLEAN, false);
|
||||
wrapper.write(Type.OPTIONAL_POSITION, null);
|
||||
if (!wrapper.isCancelled() && Via.getConfig().get1_13TabCompleteDelay() > 0) {
|
||||
@ -830,9 +829,9 @@ public class Protocol1_13To1_12_2 extends AbstractProtocol<ClientboundPackets1_1
|
||||
registerServerbound(ServerboundPackets1_13.PICK_ITEM, ServerboundPackets1_12_1.PLUGIN_MESSAGE, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
create(new ValueCreator() {
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void write(PacketWrapper wrapper) throws Exception {
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
wrapper.write(Type.STRING, "MC|PickItem"); // Channel
|
||||
}
|
||||
});
|
||||
@ -893,7 +892,7 @@ public class Protocol1_13To1_12_2 extends AbstractProtocol<ClientboundPackets1_1
|
||||
registerServerbound(ServerboundPackets1_13.RENAME_ITEM, ServerboundPackets1_12_1.PLUGIN_MESSAGE, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
create(wrapper -> {
|
||||
handler(wrapper -> {
|
||||
wrapper.write(Type.STRING, "MC|ItemName"); // Channel
|
||||
});
|
||||
}
|
||||
@ -903,7 +902,7 @@ public class Protocol1_13To1_12_2 extends AbstractProtocol<ClientboundPackets1_1
|
||||
registerServerbound(ServerboundPackets1_13.SELECT_TRADE, ServerboundPackets1_12_1.PLUGIN_MESSAGE, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
create(wrapper -> {
|
||||
handler(wrapper -> {
|
||||
wrapper.write(Type.STRING, "MC|TrSel"); // Channel
|
||||
});
|
||||
map(Type.VAR_INT, Type.INT); // Slot
|
||||
@ -914,7 +913,7 @@ public class Protocol1_13To1_12_2 extends AbstractProtocol<ClientboundPackets1_1
|
||||
registerServerbound(ServerboundPackets1_13.SET_BEACON_EFFECT, ServerboundPackets1_12_1.PLUGIN_MESSAGE, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
create(wrapper -> {
|
||||
handler(wrapper -> {
|
||||
wrapper.write(Type.STRING, "MC|Beacon"); // Channel
|
||||
});
|
||||
map(Type.VAR_INT, Type.INT); // Primary Effect
|
||||
@ -926,7 +925,7 @@ public class Protocol1_13To1_12_2 extends AbstractProtocol<ClientboundPackets1_1
|
||||
registerServerbound(ServerboundPackets1_13.UPDATE_COMMAND_BLOCK, ServerboundPackets1_12_1.PLUGIN_MESSAGE, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
create(wrapper -> wrapper.write(Type.STRING, "MC|AutoCmd"));
|
||||
handler(wrapper -> wrapper.write(Type.STRING, "MC|AutoCmd"));
|
||||
handler(POS_TO_3_INT);
|
||||
map(Type.STRING); // Command
|
||||
handler(new PacketHandler() {
|
||||
@ -952,9 +951,9 @@ public class Protocol1_13To1_12_2 extends AbstractProtocol<ClientboundPackets1_1
|
||||
registerServerbound(ServerboundPackets1_13.UPDATE_COMMAND_BLOCK_MINECART, ServerboundPackets1_12_1.PLUGIN_MESSAGE, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
create(new ValueCreator() {
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void write(PacketWrapper wrapper) throws Exception {
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
wrapper.write(Type.STRING, "MC|AdvCmd");
|
||||
wrapper.write(Type.BYTE, (byte) 1); // Type 1 for Entity
|
||||
}
|
||||
@ -969,7 +968,7 @@ public class Protocol1_13To1_12_2 extends AbstractProtocol<ClientboundPackets1_1
|
||||
registerServerbound(ServerboundPackets1_13.UPDATE_STRUCTURE_BLOCK, ServerboundPackets1_12_1.PLUGIN_MESSAGE, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
create(wrapper -> {
|
||||
handler(wrapper -> {
|
||||
wrapper.write(Type.STRING, "MC|Struct"); // Channel
|
||||
});
|
||||
handler(POS_TO_3_INT);
|
||||
|
@ -29,7 +29,6 @@ import com.viaversion.viaversion.api.minecraft.entities.Entity1_14Types;
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.ValueCreator;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13;
|
||||
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.types.Chunk1_13Type;
|
||||
@ -106,9 +105,9 @@ public class WorldPackets {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
map(Type.UNSIGNED_BYTE);
|
||||
create(new ValueCreator() {
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void write(PacketWrapper wrapper) throws Exception {
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
wrapper.write(Type.BOOLEAN, false); // Added in 19w11a. Maybe https://bugs.mojang.com/browse/MC-44471 ?
|
||||
}
|
||||
});
|
||||
@ -352,9 +351,9 @@ public class WorldPackets {
|
||||
map(Type.VAR_INT);
|
||||
map(Type.BYTE);
|
||||
map(Type.BOOLEAN);
|
||||
create(new ValueCreator() {
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void write(PacketWrapper wrapper) throws Exception {
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
wrapper.write(Type.BOOLEAN, false); // new value, probably if the map is locked (added in 19w02a), old maps are not locked
|
||||
}
|
||||
});
|
||||
|
@ -33,7 +33,7 @@ public class PlayerPackets {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
map(Type.INT);
|
||||
create(wrapper -> wrapper.write(Type.LONG, 0L)); // Level Seed
|
||||
handler(wrapper -> wrapper.write(Type.LONG, 0L)); // Level Seed
|
||||
}
|
||||
});
|
||||
|
||||
@ -50,14 +50,14 @@ public class PlayerPackets {
|
||||
int entityId = wrapper.get(Type.INT, 0);
|
||||
tracker.addEntity(entityId, Entity1_15Types.PLAYER);
|
||||
});
|
||||
create(wrapper -> wrapper.write(Type.LONG, 0L)); // Level Seed
|
||||
handler(wrapper -> wrapper.write(Type.LONG, 0L)); // Level Seed
|
||||
|
||||
map(Type.UNSIGNED_BYTE); // 3 - Max Players
|
||||
map(Type.STRING); // 4 - Level Type
|
||||
map(Type.VAR_INT); // 5 - View Distance
|
||||
map(Type.BOOLEAN); // 6 - Reduce Debug Info
|
||||
|
||||
create(wrapper -> wrapper.write(Type.BOOLEAN, !Via.getConfig().is1_15InstantRespawn())); // Show Death Screen
|
||||
handler(wrapper -> wrapper.write(Type.BOOLEAN, !Via.getConfig().is1_15InstantRespawn())); // Show Death Screen
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -18,7 +18,6 @@
|
||||
package com.viaversion.viaversion.protocols.protocol1_16to1_15_2.storage;
|
||||
|
||||
import com.viaversion.viaversion.api.connection.StorableObject;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
|
||||
public class InventoryTracker1_16 implements StorableObject {
|
||||
private short inventory = -1;
|
||||
|
@ -60,7 +60,7 @@ public class InventoryPackets {
|
||||
map(Type.UNSIGNED_BYTE); // Window Id
|
||||
map(Type.SHORT); // Slot
|
||||
map(Type.BYTE); // Button
|
||||
create(wrapper -> wrapper.write(Type.SHORT, (short) 0)); // Action id - doesn't matter, as the sent out confirmation packet will be cancelled
|
||||
handler(wrapper -> wrapper.write(Type.SHORT, (short) 0)); // Action id - doesn't matter, as the sent out confirmation packet will be cancelled
|
||||
map(Type.VAR_INT); // Action
|
||||
|
||||
handler(wrapper -> {
|
||||
|
@ -23,7 +23,6 @@ import com.viaversion.viaversion.api.protocol.Protocol;
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.ValueCreator;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.protocols.protocol1_8.ClientboundPackets1_8;
|
||||
import com.viaversion.viaversion.protocols.protocol1_9to1_8.ItemRewriter;
|
||||
@ -56,9 +55,9 @@ public class InventoryPackets {
|
||||
// Send 2 properties, splitting it into enchantID & level
|
||||
final short level = (short) (value >> 8);
|
||||
final short enchantID = (short) (value & 0xFF);
|
||||
wrapper.create(wrapper.getId(), new ValueCreator() {
|
||||
wrapper.create(wrapper.getId(), new PacketHandler() {
|
||||
@Override
|
||||
public void write(PacketWrapper wrapper) throws Exception {
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
wrapper.write(Type.UNSIGNED_BYTE, windowId);
|
||||
wrapper.write(Type.SHORT, property);
|
||||
wrapper.write(Type.SHORT, enchantID);
|
||||
@ -238,9 +237,9 @@ public class InventoryPackets {
|
||||
public void registerMap() {
|
||||
map(Type.VAR_INT); // 0 - Map ID
|
||||
map(Type.BYTE); // 1 - Map Scale
|
||||
create(new ValueCreator() {
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void write(PacketWrapper wrapper) {
|
||||
public void handle(PacketWrapper wrapper) {
|
||||
wrapper.write(Type.BOOLEAN, true); // 2 - Show marker
|
||||
}
|
||||
});
|
||||
@ -287,9 +286,9 @@ public class InventoryPackets {
|
||||
boolean throwItem = (slot == 45);
|
||||
if (throwItem) {
|
||||
// Send a packet wiping the slot
|
||||
wrapper.create(0x16, new ValueCreator() {
|
||||
wrapper.create(0x16, new PacketHandler() {
|
||||
@Override
|
||||
public void write(PacketWrapper wrapper) throws Exception {
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
wrapper.write(Type.BYTE, (byte) 0);
|
||||
wrapper.write(Type.SHORT, slot);
|
||||
wrapper.write(Type.ITEM, null);
|
||||
@ -353,9 +352,9 @@ public class InventoryPackets {
|
||||
|
||||
if (throwItem) {
|
||||
// Send a packet wiping the slot
|
||||
wrapper.create(0x16, new ValueCreator() {
|
||||
wrapper.create(0x16, new PacketHandler() {
|
||||
@Override
|
||||
public void write(PacketWrapper wrapper) throws Exception {
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
wrapper.write(Type.BYTE, (byte) windowID);
|
||||
wrapper.write(Type.SHORT, slot);
|
||||
wrapper.write(Type.ITEM, null);
|
||||
|
@ -19,13 +19,11 @@ package com.viaversion.viaversion.protocols.protocol1_9to1_8.packets;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
import com.viaversion.viaversion.api.data.entity.EntityTracker;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.Entity1_10Types;
|
||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.ValueCreator;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.protocols.protocol1_8.ClientboundPackets1_8;
|
||||
import com.viaversion.viaversion.protocols.protocol1_9to1_8.ItemRewriter;
|
||||
@ -106,9 +104,9 @@ public class PlayerPackets {
|
||||
|
||||
map(Type.BYTE); // 5 - Player Flags
|
||||
|
||||
create(new ValueCreator() {
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void write(PacketWrapper wrapper) {
|
||||
public void handle(PacketWrapper wrapper) {
|
||||
wrapper.write(Type.VAR_INT, 0); // 6 - Teleport ID was added
|
||||
}
|
||||
});
|
||||
|
@ -25,7 +25,6 @@ import com.viaversion.viaversion.api.minecraft.metadata.types.MetaType1_9;
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.ValueCreator;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.ValueTransformer;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.api.type.types.version.Types1_8;
|
||||
@ -53,9 +52,9 @@ public class SpawnPackets {
|
||||
public void registerMap() {
|
||||
map(Type.VAR_INT); // 0 - Entity ID
|
||||
|
||||
create(new ValueCreator() {
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void write(PacketWrapper wrapper) throws Exception {
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
int entityID = wrapper.get(Type.VAR_INT, 0);
|
||||
EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
|
||||
wrapper.write(Type.UUID, tracker.getEntityUUID(entityID)); // 1 - UUID
|
||||
@ -85,9 +84,9 @@ public class SpawnPackets {
|
||||
map(Type.INT); // 8 - Data
|
||||
|
||||
// Create last 3 shorts
|
||||
create(new ValueCreator() {
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void write(PacketWrapper wrapper) throws Exception {
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
int data = wrapper.get(Type.INT, 0); // Data (1st Integer)
|
||||
|
||||
short vX = 0, vY = 0, vZ = 0;
|
||||
@ -113,9 +112,9 @@ public class SpawnPackets {
|
||||
int typeID = wrapper.get(Type.BYTE, 0);
|
||||
if (Entity1_10Types.getTypeFromId(typeID, true) == Entity1_10Types.EntityType.SPLASH_POTION) {
|
||||
// Convert this to meta data, woo!
|
||||
PacketWrapper metaPacket = wrapper.create(0x39, new ValueCreator() {
|
||||
PacketWrapper metaPacket = wrapper.create(0x39, new PacketHandler() {
|
||||
@Override
|
||||
public void write(PacketWrapper wrapper) throws Exception {
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
wrapper.write(Type.VAR_INT, entityID);
|
||||
List<Metadata> meta = new ArrayList<>();
|
||||
Item item = new Item(373, (byte) 1, (short) data, null); // Potion
|
||||
@ -185,9 +184,9 @@ public class SpawnPackets {
|
||||
public void registerMap() {
|
||||
map(Type.VAR_INT); // 0 - Entity ID
|
||||
|
||||
create(new ValueCreator() {
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void write(PacketWrapper wrapper) throws Exception {
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
int entityID = wrapper.get(Type.VAR_INT, 0);
|
||||
EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
|
||||
wrapper.write(Type.UUID, tracker.getEntityUUID(entityID)); // 1 - UUID
|
||||
@ -262,9 +261,9 @@ public class SpawnPackets {
|
||||
tracker.sendMetadataBuffer(entityID);
|
||||
}
|
||||
});
|
||||
create(new ValueCreator() {
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void write(PacketWrapper wrapper) throws Exception {
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
int entityID = wrapper.get(Type.VAR_INT, 0);
|
||||
EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
|
||||
wrapper.write(Type.UUID, tracker.getEntityUUID(entityID)); // 1 - UUID
|
||||
|
@ -27,7 +27,6 @@ import com.viaversion.viaversion.api.protocol.Protocol;
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.ValueCreator;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.api.type.types.CustomByteType;
|
||||
import com.viaversion.viaversion.protocols.protocol1_8.ClientboundPackets1_8;
|
||||
@ -370,9 +369,9 @@ public class WorldPackets {
|
||||
if (hand != 0) wrapper.cancel();
|
||||
}
|
||||
});
|
||||
create(new ValueCreator() {
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void write(PacketWrapper wrapper) throws Exception {
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
Item item = Protocol1_9To1_8.getHandItem(wrapper.user());
|
||||
wrapper.write(Type.ITEM, item); // 3 - Item
|
||||
}
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren