3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-12-28 09:00:09 +01: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:
KennyTV 2021-06-02 22:00:20 +02:00
Ursprung a8b3444ff5
Commit 7b1f9c199a
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 6BE3B555EBC5982B
19 geänderte Dateien mit 140 neuen und 161 gelöschten Zeilen

Datei anzeigen

@ -25,7 +25,7 @@ package com.viaversion.viaversion.api.protocol.packet;
import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.protocol.Protocol; 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.api.type.Type;
import com.viaversion.viaversion.exception.InformativeException; import com.viaversion.viaversion.exception.InformativeException;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
@ -241,13 +241,13 @@ public interface PacketWrapper {
/** /**
* Creates a new packet with values. * Creates a new packet with values.
* *
* @param packetType packet type of the new packet * @param packetType packet type of the new packet
* @param valueCreator ValueCreator to write to the packet * @param handler handler to write to the packet
* @return newly created packet wrapper * @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 { default PacketWrapper create(PacketType packetType, PacketHandler handler) throws Exception {
return create(packetType.getId(), valueCreator); return create(packetType.getId(), handler);
} }
/** /**
@ -261,12 +261,12 @@ public interface PacketWrapper {
/** /**
* Creates a new packet with values. * Creates a new packet with values.
* *
* @param packetId id of the packet * @param packetId id of the packet
* @param valueCreator ValueCreator to write to the packet. * @param handler handler to write to the packet
* @return newly created packet wrapper * @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. * Applies a pipeline from an index to the wrapper.

Datei anzeigen

@ -23,25 +23,15 @@
package com.viaversion.viaversion.api.protocol.remapper; package com.viaversion.viaversion.api.protocol.remapper;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.exception.InformativeException;
@FunctionalInterface @FunctionalInterface
public interface PacketHandler extends ValueWriter { public interface PacketHandler {
/** /**
* Handle a packet * Handles a packet.
* *
* @param wrapper The associated wrapper * @param wrapper packet wrapper
* @throws Exception Throws exception if it failed to handle the packet * @throws Exception if an error occurs during the packet handling
*/ */
void handle(PacketWrapper wrapper) throws Exception; 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;
}
}
} }

Datei anzeigen

@ -26,23 +26,22 @@ import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.exception.CancelException; import com.viaversion.viaversion.exception.CancelException;
import com.viaversion.viaversion.exception.InformativeException; import com.viaversion.viaversion.exception.InformativeException;
import com.viaversion.viaversion.util.Pair;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.function.Function; import java.util.function.Function;
public abstract class PacketRemapper { public abstract class PacketRemapper {
private final List<Pair<ValueReader, ValueWriter>> valueRemappers = new ArrayList<>(); private final List<PacketHandler> valueRemappers = new ArrayList<>();
protected PacketRemapper() { protected PacketRemapper() {
registerMap(); 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) { public void map(Type type) {
TypeRemapper remapper = new TypeRemapper(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 oldType old type
* @param newType The new type * @param newType new type
*/ */
public void map(Type oldType, Type newType) { public void map(Type oldType, Type newType) {
map(new TypeRemapper(oldType), new TypeRemapper(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> old value type
* @param <T1> The old return type. * @param <T2> new value type
* @param newType The new type * @param oldType old type
* @param <T2> The new return type. * @param newType new type
* @param transformer The transformer to use to produce the 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) { public <T1, T2> void map(Type<T1> oldType, Type<T2> newType, Function<T1, T2> transformer) {
map(new TypeRemapper<>(oldType), new ValueTransformer<T1, T2>(newType) { 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 <T1> old value type
* @param transformer The transformer to use to produce the new type. * @param <T2> new value type
* @param <T2> The new return type. * @param transformer transformer to produce the new type
*/ */
public <T1, T2> void map(ValueTransformer<T1, T2> transformer) { public <T1, T2> void map(ValueTransformer<T1, T2> transformer) {
if (transformer.getInputType() == null) { 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> old value type
* @param <T1> The old return type. * @param <T2> new value type
* @param transformer The transformer to use to produce the new type. * @param oldType old type
* @param <T2> The new return type. * @param transformer transformer to produce the new type
*/ */
public <T1, T2> void map(Type<T1> oldType, ValueTransformer<T1, T2> transformer) { public <T1, T2> void map(Type<T1> oldType, ValueTransformer<T1, T2> transformer) {
map(new TypeRemapper(oldType), 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 inputReader reader to read with
* @param outputWriter The writer to write with * @param outputWriter writer to write with
* @param <T> The return type * @param <T> read/write type
*/ */
public <T> void map(ValueReader<T> inputReader, ValueWriter<T> outputWriter) { 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). * @param handler packet handler
*/
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.
*/ */
public void handler(PacketHandler 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(); public abstract void registerMap();
/** /**
* Remap a packet wrapper * Processes a packet wrapper.
* *
* @param packetWrapper The wrapper to remap * @param packetWrapper packet wrapper to remap
* @throws InformativeException if it fails to write / read to the packet * @throws InformativeException if packet reading or writing fails
* @throws CancelException if the packet should be cancelled * @throws CancelException if the packet should be cancelled
*/ */
public void remap(PacketWrapper packetWrapper) throws Exception { public void remap(PacketWrapper packetWrapper) throws Exception {
try { try {
// Read all the current values for (PacketHandler handler : valueRemappers) {
for (Pair<ValueReader, ValueWriter> valueRemapper : valueRemappers) { handler.handle(packetWrapper);
Object object = valueRemapper.getKey().read(packetWrapper);
// Convert object to write type :O!!!
valueRemapper.getValue().write(packetWrapper, object);
} }
// If we had handlers we'd put them here
} catch (InformativeException e) {
e.addSource(this.getClass());
throw e;
} catch (CancelException e) { } catch (CancelException e) {
// Pass through CancelExceptions // Pass through CancelExceptions
throw e; throw e;
} catch (InformativeException e) {
e.addSource(this.getClass());
throw e;
} catch (Exception e) { } catch (Exception e) {
// Wrap other exceptions during packet handling // Wrap other exceptions during packet handling
InformativeException ex = new InformativeException(e); InformativeException ex = new InformativeException(e);

Datei anzeigen

@ -23,25 +23,18 @@
package com.viaversion.viaversion.api.protocol.remapper; package com.viaversion.viaversion.api.protocol.remapper;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.exception.InformativeException;
@FunctionalInterface public final class ReadWriteValueHandler implements PacketHandler {
public interface ValueCreator extends ValueWriter { private final ValueReader reader;
/** private final ValueWriter writer;
* Write new values to a Packet.
* public ReadWriteValueHandler(ValueReader reader, ValueWriter writer) {
* @param wrapper The packet to write to this.reader = reader;
* @throws Exception Throws exception if it fails to write. this.writer = writer;
*/ }
void write(PacketWrapper wrapper) throws Exception;
@Override @Override
default void write(PacketWrapper writer, Object inputValue) throws Exception { public void handle(PacketWrapper wrapper) throws Exception {
try { writer.write(wrapper, reader.read(wrapper));
write(writer);
} catch (InformativeException e) {
e.addSource(this.getClass());
throw e;
}
} }
} }

Datei anzeigen

@ -31,12 +31,12 @@ public abstract class ValueTransformer<T1, T2> implements ValueWriter<T1> {
private final Type<T1> inputType; private final Type<T1> inputType;
private final Type<T2> outputType; 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.inputType = inputType;
this.outputType = outputType; this.outputType = outputType;
} }
public ValueTransformer(Type<T2> outputType) { protected ValueTransformer(Type<T2> outputType) {
this(null, outputType); this(null, outputType);
} }

Datei anzeigen

@ -35,11 +35,11 @@ public class Pair<X, Y> {
this.value = value; this.value = value;
} }
public X getKey() { public @Nullable X getKey() {
return key; return key;
} }
public Y getValue() { public @Nullable Y getValue() {
return value; return value;
} }

Datei anzeigen

@ -17,8 +17,8 @@
*/ */
package com.viaversion.viaversion.protocol; 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.Protocol;
import com.viaversion.viaversion.api.protocol.ProtocolPathEntry;
public class ProtocolPathEntryImpl implements ProtocolPathEntry { public class ProtocolPathEntryImpl implements ProtocolPathEntry {
private final int outputProtocolVersion; private final int outputProtocolVersion;

Datei anzeigen

@ -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.Direction;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.protocol.packet.State; 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.Type;
import com.viaversion.viaversion.api.type.TypeConverter; import com.viaversion.viaversion.api.type.TypeConverter;
import com.viaversion.viaversion.exception.CancelException; import com.viaversion.viaversion.exception.CancelException;
@ -326,9 +326,9 @@ public class PacketWrapperImpl implements PacketWrapper {
} }
@Override @Override
public PacketWrapperImpl create(int packetId, ValueCreator valueCreator) throws Exception { public PacketWrapperImpl create(int packetId, PacketHandler handler) throws Exception {
PacketWrapperImpl wrapper = create(packetId); PacketWrapperImpl wrapper = create(packetId);
valueCreator.write(wrapper); handler.handle(wrapper);
return wrapper; return wrapper;
} }

Datei anzeigen

@ -22,9 +22,9 @@ import com.viaversion.viaversion.api.connection.ProtocolInfo;
import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.platform.providers.ViaProviders; import com.viaversion.viaversion.api.platform.providers.ViaProviders;
import com.viaversion.viaversion.api.protocol.AbstractSimpleProtocol; 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.ProtocolPathEntry;
import com.viaversion.viaversion.api.protocol.ProtocolPipeline; 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.Direction;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.protocol.packet.State; import com.viaversion.viaversion.api.protocol.packet.State;

Datei anzeigen

@ -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.packet.PacketWrapper;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandler; import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper; 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.protocol.remapper.ValueTransformer;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.types.version.Types1_9; 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); // 0 - Collected entity id
map(Type.VAR_INT); // 1 - Collector entity id map(Type.VAR_INT); // 1 - Collector entity id
create(new ValueCreator() { handler(new PacketHandler() {
@Override @Override
public void write(PacketWrapper wrapper) throws Exception { public void handle(PacketWrapper wrapper) throws Exception {
wrapper.write(Type.VAR_INT, 1); // 2 - Pickup Count wrapper.write(Type.VAR_INT, 1); // 2 - Pickup Count
} }
}); });

Datei anzeigen

@ -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.packet.State;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandler; import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper; 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.protocol.remapper.ValueTransformer;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.data.entity.EntityTrackerBase; 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() { registerClientbound(ClientboundPackets1_12_1.TAB_COMPLETE, new PacketRemapper() {
@Override @Override
public void registerMap() { public void registerMap() {
create(new ValueCreator() { handler(new PacketHandler() {
@Override @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()); wrapper.write(Type.VAR_INT, wrapper.user().get(TabCompleteTracker.class).getTransactionId());
String input = wrapper.user().get(TabCompleteTracker.class).getInput(); 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.VAR_INT); // action
map(Type.BOOLEAN); // crafting book open map(Type.BOOLEAN); // crafting book open
map(Type.BOOLEAN); // crafting filter active map(Type.BOOLEAN); // crafting filter active
create(new ValueCreator() { handler(new PacketHandler() {
@Override @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 book open
wrapper.write(Type.BOOLEAN, false); // smelting filter active 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); wrapper.write(Type.STRING_ARRAY, stringIds);
} }
if (action == 0) { if (action == 0) {
wrapper.create(ClientboundPackets1_13.DECLARE_RECIPES, new ValueCreator() { // Declare recipes wrapper.create(ClientboundPackets1_13.DECLARE_RECIPES, new PacketHandler() { // Declare recipes
@Override @Override
public void write(PacketWrapper wrapper) throws Exception { public void handle(PacketWrapper wrapper) throws Exception {
wrapper.write(Type.VAR_INT, RecipeData.recipes.size()); wrapper.write(Type.VAR_INT, RecipeData.recipes.size());
for (Map.Entry<String, RecipeData.Recipe> entry : RecipeData.recipes.entrySet()) { for (Map.Entry<String, RecipeData.Recipe> entry : RecipeData.recipes.entrySet()) {
wrapper.write(Type.STRING, entry.getKey()); // Id 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 // Fake the end of the packet
create(new ValueCreator() { handler(new PacketHandler() {
@Override @Override
public void write(PacketWrapper wrapper) throws Exception { public void handle(PacketWrapper wrapper) throws Exception {
wrapper.write(Type.BOOLEAN, false); wrapper.write(Type.BOOLEAN, false);
wrapper.write(Type.OPTIONAL_POSITION, null); wrapper.write(Type.OPTIONAL_POSITION, null);
if (!wrapper.isCancelled() && Via.getConfig().get1_13TabCompleteDelay() > 0) { 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() { registerServerbound(ServerboundPackets1_13.PICK_ITEM, ServerboundPackets1_12_1.PLUGIN_MESSAGE, new PacketRemapper() {
@Override @Override
public void registerMap() { public void registerMap() {
create(new ValueCreator() { handler(new PacketHandler() {
@Override @Override
public void write(PacketWrapper wrapper) throws Exception { public void handle(PacketWrapper wrapper) throws Exception {
wrapper.write(Type.STRING, "MC|PickItem"); // Channel 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() { registerServerbound(ServerboundPackets1_13.RENAME_ITEM, ServerboundPackets1_12_1.PLUGIN_MESSAGE, new PacketRemapper() {
@Override @Override
public void registerMap() { public void registerMap() {
create(wrapper -> { handler(wrapper -> {
wrapper.write(Type.STRING, "MC|ItemName"); // Channel 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() { registerServerbound(ServerboundPackets1_13.SELECT_TRADE, ServerboundPackets1_12_1.PLUGIN_MESSAGE, new PacketRemapper() {
@Override @Override
public void registerMap() { public void registerMap() {
create(wrapper -> { handler(wrapper -> {
wrapper.write(Type.STRING, "MC|TrSel"); // Channel wrapper.write(Type.STRING, "MC|TrSel"); // Channel
}); });
map(Type.VAR_INT, Type.INT); // Slot 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() { registerServerbound(ServerboundPackets1_13.SET_BEACON_EFFECT, ServerboundPackets1_12_1.PLUGIN_MESSAGE, new PacketRemapper() {
@Override @Override
public void registerMap() { public void registerMap() {
create(wrapper -> { handler(wrapper -> {
wrapper.write(Type.STRING, "MC|Beacon"); // Channel wrapper.write(Type.STRING, "MC|Beacon"); // Channel
}); });
map(Type.VAR_INT, Type.INT); // Primary Effect 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() { registerServerbound(ServerboundPackets1_13.UPDATE_COMMAND_BLOCK, ServerboundPackets1_12_1.PLUGIN_MESSAGE, new PacketRemapper() {
@Override @Override
public void registerMap() { public void registerMap() {
create(wrapper -> wrapper.write(Type.STRING, "MC|AutoCmd")); handler(wrapper -> wrapper.write(Type.STRING, "MC|AutoCmd"));
handler(POS_TO_3_INT); handler(POS_TO_3_INT);
map(Type.STRING); // Command map(Type.STRING); // Command
handler(new PacketHandler() { 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() { registerServerbound(ServerboundPackets1_13.UPDATE_COMMAND_BLOCK_MINECART, ServerboundPackets1_12_1.PLUGIN_MESSAGE, new PacketRemapper() {
@Override @Override
public void registerMap() { public void registerMap() {
create(new ValueCreator() { handler(new PacketHandler() {
@Override @Override
public void write(PacketWrapper wrapper) throws Exception { public void handle(PacketWrapper wrapper) throws Exception {
wrapper.write(Type.STRING, "MC|AdvCmd"); wrapper.write(Type.STRING, "MC|AdvCmd");
wrapper.write(Type.BYTE, (byte) 1); // Type 1 for Entity 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() { registerServerbound(ServerboundPackets1_13.UPDATE_STRUCTURE_BLOCK, ServerboundPackets1_12_1.PLUGIN_MESSAGE, new PacketRemapper() {
@Override @Override
public void registerMap() { public void registerMap() {
create(wrapper -> { handler(wrapper -> {
wrapper.write(Type.STRING, "MC|Struct"); // Channel wrapper.write(Type.STRING, "MC|Struct"); // Channel
}); });
handler(POS_TO_3_INT); handler(POS_TO_3_INT);

Datei anzeigen

@ -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.packet.PacketWrapper;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandler; import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper; 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.Type;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13; import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.types.Chunk1_13Type; import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.types.Chunk1_13Type;
@ -106,9 +105,9 @@ public class WorldPackets {
@Override @Override
public void registerMap() { public void registerMap() {
map(Type.UNSIGNED_BYTE); map(Type.UNSIGNED_BYTE);
create(new ValueCreator() { handler(new PacketHandler() {
@Override @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 ? 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.VAR_INT);
map(Type.BYTE); map(Type.BYTE);
map(Type.BOOLEAN); map(Type.BOOLEAN);
create(new ValueCreator() { handler(new PacketHandler() {
@Override @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 wrapper.write(Type.BOOLEAN, false); // new value, probably if the map is locked (added in 19w02a), old maps are not locked
} }
}); });

Datei anzeigen

@ -33,7 +33,7 @@ public class PlayerPackets {
@Override @Override
public void registerMap() { public void registerMap() {
map(Type.INT); 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); int entityId = wrapper.get(Type.INT, 0);
tracker.addEntity(entityId, Entity1_15Types.PLAYER); 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.UNSIGNED_BYTE); // 3 - Max Players
map(Type.STRING); // 4 - Level Type map(Type.STRING); // 4 - Level Type
map(Type.VAR_INT); // 5 - View Distance map(Type.VAR_INT); // 5 - View Distance
map(Type.BOOLEAN); // 6 - Reduce Debug Info 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
} }
}); });
} }

Datei anzeigen

@ -18,7 +18,6 @@
package com.viaversion.viaversion.protocols.protocol1_16to1_15_2.storage; package com.viaversion.viaversion.protocols.protocol1_16to1_15_2.storage;
import com.viaversion.viaversion.api.connection.StorableObject; import com.viaversion.viaversion.api.connection.StorableObject;
import com.viaversion.viaversion.api.connection.UserConnection;
public class InventoryTracker1_16 implements StorableObject { public class InventoryTracker1_16 implements StorableObject {
private short inventory = -1; private short inventory = -1;

Datei anzeigen

@ -60,7 +60,7 @@ public class InventoryPackets {
map(Type.UNSIGNED_BYTE); // Window Id map(Type.UNSIGNED_BYTE); // Window Id
map(Type.SHORT); // Slot map(Type.SHORT); // Slot
map(Type.BYTE); // Button 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 map(Type.VAR_INT); // Action
handler(wrapper -> { handler(wrapper -> {

Datei anzeigen

@ -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.packet.PacketWrapper;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandler; import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper; 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.Type;
import com.viaversion.viaversion.protocols.protocol1_8.ClientboundPackets1_8; import com.viaversion.viaversion.protocols.protocol1_8.ClientboundPackets1_8;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.ItemRewriter; import com.viaversion.viaversion.protocols.protocol1_9to1_8.ItemRewriter;
@ -56,9 +55,9 @@ public class InventoryPackets {
// Send 2 properties, splitting it into enchantID & level // Send 2 properties, splitting it into enchantID & level
final short level = (short) (value >> 8); final short level = (short) (value >> 8);
final short enchantID = (short) (value & 0xFF); final short enchantID = (short) (value & 0xFF);
wrapper.create(wrapper.getId(), new ValueCreator() { wrapper.create(wrapper.getId(), new PacketHandler() {
@Override @Override
public void write(PacketWrapper wrapper) throws Exception { public void handle(PacketWrapper wrapper) throws Exception {
wrapper.write(Type.UNSIGNED_BYTE, windowId); wrapper.write(Type.UNSIGNED_BYTE, windowId);
wrapper.write(Type.SHORT, property); wrapper.write(Type.SHORT, property);
wrapper.write(Type.SHORT, enchantID); wrapper.write(Type.SHORT, enchantID);
@ -238,9 +237,9 @@ public class InventoryPackets {
public void registerMap() { public void registerMap() {
map(Type.VAR_INT); // 0 - Map ID map(Type.VAR_INT); // 0 - Map ID
map(Type.BYTE); // 1 - Map Scale map(Type.BYTE); // 1 - Map Scale
create(new ValueCreator() { handler(new PacketHandler() {
@Override @Override
public void write(PacketWrapper wrapper) { public void handle(PacketWrapper wrapper) {
wrapper.write(Type.BOOLEAN, true); // 2 - Show marker wrapper.write(Type.BOOLEAN, true); // 2 - Show marker
} }
}); });
@ -287,9 +286,9 @@ public class InventoryPackets {
boolean throwItem = (slot == 45); boolean throwItem = (slot == 45);
if (throwItem) { if (throwItem) {
// Send a packet wiping the slot // Send a packet wiping the slot
wrapper.create(0x16, new ValueCreator() { wrapper.create(0x16, new PacketHandler() {
@Override @Override
public void write(PacketWrapper wrapper) throws Exception { public void handle(PacketWrapper wrapper) throws Exception {
wrapper.write(Type.BYTE, (byte) 0); wrapper.write(Type.BYTE, (byte) 0);
wrapper.write(Type.SHORT, slot); wrapper.write(Type.SHORT, slot);
wrapper.write(Type.ITEM, null); wrapper.write(Type.ITEM, null);
@ -353,9 +352,9 @@ public class InventoryPackets {
if (throwItem) { if (throwItem) {
// Send a packet wiping the slot // Send a packet wiping the slot
wrapper.create(0x16, new ValueCreator() { wrapper.create(0x16, new PacketHandler() {
@Override @Override
public void write(PacketWrapper wrapper) throws Exception { public void handle(PacketWrapper wrapper) throws Exception {
wrapper.write(Type.BYTE, (byte) windowID); wrapper.write(Type.BYTE, (byte) windowID);
wrapper.write(Type.SHORT, slot); wrapper.write(Type.SHORT, slot);
wrapper.write(Type.ITEM, null); wrapper.write(Type.ITEM, null);

Datei anzeigen

@ -19,13 +19,11 @@ package com.viaversion.viaversion.protocols.protocol1_9to1_8.packets;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.viaversion.viaversion.api.Via; 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.entities.Entity1_10Types;
import com.viaversion.viaversion.api.minecraft.item.Item; import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandler; import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper; 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.Type;
import com.viaversion.viaversion.protocols.protocol1_8.ClientboundPackets1_8; import com.viaversion.viaversion.protocols.protocol1_8.ClientboundPackets1_8;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.ItemRewriter; import com.viaversion.viaversion.protocols.protocol1_9to1_8.ItemRewriter;
@ -106,9 +104,9 @@ public class PlayerPackets {
map(Type.BYTE); // 5 - Player Flags map(Type.BYTE); // 5 - Player Flags
create(new ValueCreator() { handler(new PacketHandler() {
@Override @Override
public void write(PacketWrapper wrapper) { public void handle(PacketWrapper wrapper) {
wrapper.write(Type.VAR_INT, 0); // 6 - Teleport ID was added wrapper.write(Type.VAR_INT, 0); // 6 - Teleport ID was added
} }
}); });

Datei anzeigen

@ -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.packet.PacketWrapper;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandler; import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper; 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.protocol.remapper.ValueTransformer;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.types.version.Types1_8; import com.viaversion.viaversion.api.type.types.version.Types1_8;
@ -53,9 +52,9 @@ public class SpawnPackets {
public void registerMap() { public void registerMap() {
map(Type.VAR_INT); // 0 - Entity ID map(Type.VAR_INT); // 0 - Entity ID
create(new ValueCreator() { handler(new PacketHandler() {
@Override @Override
public void write(PacketWrapper wrapper) throws Exception { public void handle(PacketWrapper wrapper) throws Exception {
int entityID = wrapper.get(Type.VAR_INT, 0); int entityID = wrapper.get(Type.VAR_INT, 0);
EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class); EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
wrapper.write(Type.UUID, tracker.getEntityUUID(entityID)); // 1 - UUID wrapper.write(Type.UUID, tracker.getEntityUUID(entityID)); // 1 - UUID
@ -85,9 +84,9 @@ public class SpawnPackets {
map(Type.INT); // 8 - Data map(Type.INT); // 8 - Data
// Create last 3 shorts // Create last 3 shorts
create(new ValueCreator() { handler(new PacketHandler() {
@Override @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) int data = wrapper.get(Type.INT, 0); // Data (1st Integer)
short vX = 0, vY = 0, vZ = 0; short vX = 0, vY = 0, vZ = 0;
@ -113,9 +112,9 @@ public class SpawnPackets {
int typeID = wrapper.get(Type.BYTE, 0); int typeID = wrapper.get(Type.BYTE, 0);
if (Entity1_10Types.getTypeFromId(typeID, true) == Entity1_10Types.EntityType.SPLASH_POTION) { if (Entity1_10Types.getTypeFromId(typeID, true) == Entity1_10Types.EntityType.SPLASH_POTION) {
// Convert this to meta data, woo! // Convert this to meta data, woo!
PacketWrapper metaPacket = wrapper.create(0x39, new ValueCreator() { PacketWrapper metaPacket = wrapper.create(0x39, new PacketHandler() {
@Override @Override
public void write(PacketWrapper wrapper) throws Exception { public void handle(PacketWrapper wrapper) throws Exception {
wrapper.write(Type.VAR_INT, entityID); wrapper.write(Type.VAR_INT, entityID);
List<Metadata> meta = new ArrayList<>(); List<Metadata> meta = new ArrayList<>();
Item item = new Item(373, (byte) 1, (short) data, null); // Potion Item item = new Item(373, (byte) 1, (short) data, null); // Potion
@ -185,9 +184,9 @@ public class SpawnPackets {
public void registerMap() { public void registerMap() {
map(Type.VAR_INT); // 0 - Entity ID map(Type.VAR_INT); // 0 - Entity ID
create(new ValueCreator() { handler(new PacketHandler() {
@Override @Override
public void write(PacketWrapper wrapper) throws Exception { public void handle(PacketWrapper wrapper) throws Exception {
int entityID = wrapper.get(Type.VAR_INT, 0); int entityID = wrapper.get(Type.VAR_INT, 0);
EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class); EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
wrapper.write(Type.UUID, tracker.getEntityUUID(entityID)); // 1 - UUID wrapper.write(Type.UUID, tracker.getEntityUUID(entityID)); // 1 - UUID
@ -262,9 +261,9 @@ public class SpawnPackets {
tracker.sendMetadataBuffer(entityID); tracker.sendMetadataBuffer(entityID);
} }
}); });
create(new ValueCreator() { handler(new PacketHandler() {
@Override @Override
public void write(PacketWrapper wrapper) throws Exception { public void handle(PacketWrapper wrapper) throws Exception {
int entityID = wrapper.get(Type.VAR_INT, 0); int entityID = wrapper.get(Type.VAR_INT, 0);
EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class); EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
wrapper.write(Type.UUID, tracker.getEntityUUID(entityID)); // 1 - UUID wrapper.write(Type.UUID, tracker.getEntityUUID(entityID)); // 1 - UUID

Datei anzeigen

@ -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.packet.PacketWrapper;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandler; import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper; 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.Type;
import com.viaversion.viaversion.api.type.types.CustomByteType; import com.viaversion.viaversion.api.type.types.CustomByteType;
import com.viaversion.viaversion.protocols.protocol1_8.ClientboundPackets1_8; import com.viaversion.viaversion.protocols.protocol1_8.ClientboundPackets1_8;
@ -370,9 +369,9 @@ public class WorldPackets {
if (hand != 0) wrapper.cancel(); if (hand != 0) wrapper.cancel();
} }
}); });
create(new ValueCreator() { handler(new PacketHandler() {
@Override @Override
public void write(PacketWrapper wrapper) throws Exception { public void handle(PacketWrapper wrapper) throws Exception {
Item item = Protocol1_9To1_8.getHandItem(wrapper.user()); Item item = Protocol1_9To1_8.getHandItem(wrapper.user());
wrapper.write(Type.ITEM, item); // 3 - Item wrapper.write(Type.ITEM, item); // 3 - Item
} }