Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bc1d57853c | ||
|
|
d6edec3a55 | ||
|
|
c57d0f60f9 | ||
|
|
dd5cd1ca48 | ||
|
|
ab4a565700 | ||
|
|
f8ac54e237 | ||
|
|
089e07fe49 | ||
|
|
1d3b8f802c |
No files matched your search
@@ -1,10 +1,7 @@
|
||||
# ViaVersion 0.8.4
|
||||
# ViaVersion 0.9.3
|
||||
[](https://travis-ci.org/MylesIsCool/ViaVersion)
|
||||
[](https://gitter.im/MylesIsCool/ViaVersion)
|
||||
|
||||
## This is an experimental branch for 1.10, we do not recommend you to use this on a production server
|
||||
**Direct download link:** [Latest builds](https://ci.viaversion.com/job/ViaVersion%201.10%20DEV/)
|
||||
|
||||
**Allows the connection of 1.9 clients to 1.8**
|
||||
**1.10 clients on 1.8 / 1.9 servers**
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>us.myles</groupId>
|
||||
<artifactId>viaversion</artifactId>
|
||||
<version>0.9.1</version>
|
||||
<version>0.9.3</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>ViaVersion</name>
|
||||
|
||||
@@ -3,18 +3,24 @@ package us.myles.ViaVersion.api;
|
||||
import com.google.common.base.Preconditions;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import lombok.Data;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import us.myles.ViaVersion.api.data.UserConnection;
|
||||
import us.myles.ViaVersion.api.protocol.Protocol;
|
||||
import us.myles.ViaVersion.api.remapper.ValueCreator;
|
||||
import us.myles.ViaVersion.api.type.Type;
|
||||
import us.myles.ViaVersion.api.type.TypeConverter;
|
||||
import us.myles.ViaVersion.exception.InformativeException;
|
||||
import us.myles.ViaVersion.handlers.ViaDecodeHandler;
|
||||
import us.myles.ViaVersion.packets.Direction;
|
||||
import us.myles.ViaVersion.packets.State;
|
||||
import us.myles.ViaVersion.protocols.base.ProtocolInfo;
|
||||
import us.myles.ViaVersion.util.PipelineUtil;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -250,10 +256,44 @@ public class PacketWrapper {
|
||||
* Be careful not to send packets twice.
|
||||
* (Sends it after current)
|
||||
*
|
||||
* @param packetProtocol - The protocol version of the packet.
|
||||
* @throws Exception if it fails to write
|
||||
*/
|
||||
public void send(Class<? extends Protocol> packetProtocol) throws Exception {
|
||||
if (!isCancelled()) {
|
||||
// Apply current pipeline
|
||||
List<Protocol> protocols = new ArrayList<>(user().get(ProtocolInfo.class).getPipeline().pipes());
|
||||
// Other way if outgoing
|
||||
Collections.reverse(protocols);
|
||||
int index = 0;
|
||||
for (int i = 0; i < protocols.size(); i++) {
|
||||
if (protocols.get(i).getClass().equals(packetProtocol)) {
|
||||
index = i + 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// Apply other protocols
|
||||
apply(Direction.OUTGOING, user().get(ProtocolInfo.class).getState(), index, protocols);
|
||||
// Send
|
||||
ByteBuf output = inputBuffer == null ? Unpooled.buffer() : inputBuffer.alloc().buffer();
|
||||
writeToBuffer(output);
|
||||
user().sendRawPacket(output);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Send this packet to the associated user.
|
||||
* Be careful not to send packets twice.
|
||||
* (Sends it after current)
|
||||
* <br />
|
||||
* <b>This method is no longer used, it's favoured to use send(Protocol) as it will handle the pipeline properly.</b>
|
||||
*
|
||||
* @throws Exception if it fails to write
|
||||
*/
|
||||
@Deprecated
|
||||
public void send() throws Exception {
|
||||
if (!isCancelled()) {
|
||||
// Send
|
||||
ByteBuf output = inputBuffer == null ? Unpooled.buffer() : inputBuffer.alloc().buffer();
|
||||
writeToBuffer(output);
|
||||
user().sendRawPacket(output);
|
||||
@@ -284,6 +324,26 @@ public class PacketWrapper {
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies a pipeline from an index to the wrapper
|
||||
*
|
||||
* @param direction The direction
|
||||
* @param state The state
|
||||
* @param index The index to start from
|
||||
* @param pipeline The pipeline
|
||||
* @return The current packetwrapper
|
||||
* @throws Exception
|
||||
*/
|
||||
public PacketWrapper apply(Direction direction, State state, int index, List<Protocol> pipeline) throws Exception {
|
||||
for (int i = index; i < pipeline.size(); i++) { // Copy to prevent from removal.
|
||||
pipeline.get(i).transform(direction, state, this);
|
||||
// Reset the reader for the packetWrapper (So it can be recycled across packets)
|
||||
resetReader();
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancel this packet from sending
|
||||
*/
|
||||
|
||||
@@ -69,11 +69,9 @@ public class ProtocolPipeline extends Protocol {
|
||||
if (direction == Direction.OUTGOING)
|
||||
Collections.reverse(protocols);
|
||||
|
||||
for (Protocol protocol : protocols) { // Copy to prevent from removal.
|
||||
protocol.transform(direction, state, packetWrapper);
|
||||
// Reset the reader for the packetWrapper (So it can be recycled across packets)
|
||||
packetWrapper.resetReader();
|
||||
}
|
||||
// Apply protocols
|
||||
packetWrapper.apply(direction, state, 0, protocols);
|
||||
|
||||
super.transform(direction, state, packetWrapper);
|
||||
|
||||
if (ViaVersion.getInstance().isDebug()) {
|
||||
|
||||
@@ -34,7 +34,7 @@ public class ProtocolRegistry {
|
||||
// Only supported for 1.9.4 server to 1.9 (nothing else)
|
||||
registerProtocol(new Protocol1_9TO1_9_1(), Arrays.asList(ProtocolVersion.v1_9.getId()), ProtocolVersion.v1_9_2.getId());
|
||||
registerProtocol(new Protocol1_9_1_2TO1_9_3_4(), Arrays.asList(ProtocolVersion.v1_9_1.getId(), ProtocolVersion.v1_9_2.getId()), ProtocolVersion.v1_9_3.getId());
|
||||
registerProtocol(new Protocol1_10To1_9_3_4(), Collections.singletonList(ProtocolVersion.SNAPSHOT.getId()), ProtocolVersion.v1_9_3.getId());
|
||||
registerProtocol(new Protocol1_10To1_9_3_4(), Collections.singletonList(ProtocolVersion.v1_10.getId()), ProtocolVersion.v1_9_3.getId());
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ public class ProtocolVersion {
|
||||
public static final ProtocolVersion v1_9_1;
|
||||
public static final ProtocolVersion v1_9_2;
|
||||
public static final ProtocolVersion v1_9_3;
|
||||
public static final ProtocolVersion SNAPSHOT;
|
||||
public static final ProtocolVersion v1_10;
|
||||
|
||||
private final int id;
|
||||
private final String name;
|
||||
@@ -29,7 +29,7 @@ public class ProtocolVersion {
|
||||
register(v1_9_1 = new ProtocolVersion(108, "1.9.1"));
|
||||
register(v1_9_2 = new ProtocolVersion(109, "1.9.2"));
|
||||
register(v1_9_3 = new ProtocolVersion(110, "1.9.3/4"));
|
||||
register(SNAPSHOT = new ProtocolVersion(210, "1.10"));
|
||||
register(v1_10 = new ProtocolVersion(210, "1.10"));
|
||||
}
|
||||
|
||||
public static void register(@NonNull ProtocolVersion protocol) {
|
||||
|
||||
+4
-4
@@ -10,14 +10,14 @@ import us.myles.ViaVersion.api.remapper.ValueTransformer;
|
||||
import us.myles.ViaVersion.api.type.Type;
|
||||
import us.myles.ViaVersion.packets.State;
|
||||
import us.myles.ViaVersion.protocols.protocol1_10to1_9_3.storage.ResourcePackTracker;
|
||||
import us.myles.ViaVersion.protocols.protocol1_10to1_9_3.types.MetaListSnapshotType;
|
||||
import us.myles.ViaVersion.protocols.protocol1_10to1_9_3.types.MetaSnapshotType;
|
||||
import us.myles.ViaVersion.protocols.protocol1_10to1_9_3.types.MetaList1_10Type;
|
||||
import us.myles.ViaVersion.protocols.protocol1_10to1_9_3.types.Meta1_10Type;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Protocol1_10To1_9_3_4 extends Protocol {
|
||||
public static final Type<List<Metadata>> METADATA_LIST = new MetaListSnapshotType();
|
||||
public static final Type<Metadata> METADATA = new MetaSnapshotType();
|
||||
public static final Type<List<Metadata>> METADATA_LIST = new MetaList1_10Type();
|
||||
public static final Type<Metadata> METADATA = new Meta1_10Type();
|
||||
public static ValueTransformer<Short, Float> toNewPitch = new ValueTransformer<Short, Float>(Type.FLOAT) {
|
||||
@Override
|
||||
public Float transform(PacketWrapper wrapper, Short inputValue) throws Exception {
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@ import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
|
||||
import us.myles.ViaVersion.api.type.types.minecraft.MetaTypeTemplate;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.metadata.NewType;
|
||||
|
||||
public class MetaSnapshotType extends MetaTypeTemplate {
|
||||
public class Meta1_10Type extends MetaTypeTemplate {
|
||||
|
||||
@Override
|
||||
public Metadata read(ByteBuf buffer) throws Exception {
|
||||
+1
-1
@@ -10,7 +10,7 @@ import us.myles.ViaVersion.protocols.protocol1_9to1_8.metadata.NewType;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class MetaListSnapshotType extends MetaListTypeTemplate {
|
||||
public class MetaList1_10Type extends MetaListTypeTemplate {
|
||||
|
||||
@Override
|
||||
public List<Metadata> read(ByteBuf buffer) throws Exception {
|
||||
+2
-2
@@ -75,7 +75,7 @@ public class BlockEntity {
|
||||
wrapper.write(Type.POSITION, pos);
|
||||
wrapper.write(Type.UNSIGNED_BYTE, id);
|
||||
wrapper.write(Type.NBT, tag);
|
||||
wrapper.send();
|
||||
wrapper.send(Protocol1_9_1_2TO1_9_3_4.class);
|
||||
}
|
||||
|
||||
private static void updateSign(Position pos, String[] lines, UserConnection connection) throws Exception {
|
||||
@@ -83,6 +83,6 @@ public class BlockEntity {
|
||||
wrapper.write(Type.POSITION, pos);
|
||||
for (String s : lines)
|
||||
wrapper.write(Type.STRING, s);
|
||||
wrapper.send();
|
||||
wrapper.send(Protocol1_9_1_2TO1_9_3_4.class);
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -55,7 +55,7 @@ public class DeathListener implements Listener {
|
||||
wrapper.write(Type.VAR_INT, p.getEntityId());
|
||||
wrapper.write(Type.INT, p.getEntityId());
|
||||
Protocol1_9TO1_8.FIX_JSON.write(wrapper, msg);
|
||||
wrapper.send();
|
||||
wrapper.send(Protocol1_9TO1_8.class);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
wrapper.clearInputBuffer();
|
||||
|
||||
+1
-1
@@ -57,7 +57,7 @@ public class EntityPackets {
|
||||
passengerPacket.write(Type.VAR_INT_ARRAY, new Integer[]{passenger});
|
||||
tracker.getVehicleMap().put(passenger, vehicle);
|
||||
}
|
||||
passengerPacket.send(); // Send the packet
|
||||
passengerPacket.send(Protocol1_9TO1_8.class); // Send the packet
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
+3
-3
@@ -44,7 +44,7 @@ public class InventoryPackets {
|
||||
wrapper.write(Type.SHORT, property);
|
||||
wrapper.write(Type.SHORT, enchantID);
|
||||
}
|
||||
}).send();
|
||||
}).send(Protocol1_9TO1_8.class);
|
||||
|
||||
wrapper.set(Type.SHORT, 0, (short) (property + 3));
|
||||
wrapper.set(Type.SHORT, 1, level);
|
||||
@@ -230,7 +230,7 @@ public class InventoryPackets {
|
||||
wrapper.write(Type.SHORT, slot);
|
||||
wrapper.write(Type.SHORT, (short) -1);
|
||||
}
|
||||
}).send();
|
||||
}).send(Protocol1_9TO1_8.class);
|
||||
// Finally reset to simulate throwing item
|
||||
wrapper.set(Type.SHORT, 0, (short) -999); // Set slot to -999
|
||||
}
|
||||
@@ -285,7 +285,7 @@ public class InventoryPackets {
|
||||
wrapper.write(Type.SHORT, slot);
|
||||
wrapper.write(Type.SHORT, (short) -1);
|
||||
}
|
||||
}).send();
|
||||
}).send(Protocol1_9TO1_8.class);
|
||||
// Finally reset to simulate throwing item
|
||||
wrapper.set(Type.BYTE, 0, (byte) 0); // Set button to 0
|
||||
wrapper.set(Type.BYTE, 1, (byte) 0); // Set mode to 0
|
||||
|
||||
+5
-3
@@ -12,6 +12,8 @@ import us.myles.ViaVersion.api.remapper.ValueCreator;
|
||||
import us.myles.ViaVersion.api.remapper.ValueTransformer;
|
||||
import us.myles.ViaVersion.api.type.Type;
|
||||
import us.myles.ViaVersion.packets.State;
|
||||
import us.myles.ViaVersion.protocols.base.ProtocolInfo;
|
||||
import us.myles.ViaVersion.protocols.protocol1_10to1_9_3.Protocol1_10To1_9_3_4;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.ItemRewriter;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9TO1_8;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.metadata.MetadataRewriter;
|
||||
@@ -104,13 +106,13 @@ public class SpawnPackets {
|
||||
List<Metadata> meta = new ArrayList<>();
|
||||
Item item = new Item((short) Material.POTION.getId(), (byte) 1, (short) data, null);
|
||||
ItemRewriter.toClient(item); // Rewrite so that it gets the right nbt
|
||||
|
||||
// TEMP FIX FOR POTIONS UNTIL WE FIGURE OUT HOW TO TRANSFORM SENT PACKETS
|
||||
Metadata potion = new Metadata(5, NewType.Slot.getTypeID(), Type.ITEM, item);
|
||||
meta.add(potion);
|
||||
wrapper.write(Protocol1_9TO1_8.METADATA_LIST, meta);
|
||||
}
|
||||
});
|
||||
metaPacket.send();
|
||||
metaPacket.send(Protocol1_9TO1_8.class);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -303,7 +305,7 @@ public class SpawnPackets {
|
||||
packet.write(Type.VAR_INT, 0);
|
||||
packet.write(Type.ITEM, new Item(item, (byte) 1, (short) 0, null));
|
||||
try {
|
||||
packet.send();
|
||||
packet.send(Protocol1_9TO1_8.class);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
+2
-2
@@ -64,7 +64,7 @@ public enum SoundEffect {
|
||||
MOB_HORSE_WOOD("mob.horse.wood", "entity.horse.step_wood", SoundCategory.NEUTRAL),
|
||||
MOB_ZOMBIE_UNFECT("mob.zombie.unfect", "entity.zombie_villager.converted", SoundCategory.HOSTILE),
|
||||
RANDOM_ANVIL_USE("random.anvil_use", "block.anvil.use", SoundCategory.BLOCK),
|
||||
RANDOM_CHESTCLOSED("random.chestclosed", "block.enderchest.close", SoundCategory.BLOCK),
|
||||
RANDOM_CHESTCLOSED("random.chestclosed", "block.chest.close", SoundCategory.BLOCK),
|
||||
MOB_SHEEP_SHEAR("mob.sheep.shear", "entity.sheep.shear", SoundCategory.NEUTRAL),
|
||||
RANDOM_POP("random.pop", "entity.item.pickup", SoundCategory.PLAYER),
|
||||
MOB_BAT_DEATH("mob.bat.death", "entity.bat.death", SoundCategory.NEUTRAL),
|
||||
@@ -85,7 +85,7 @@ public enum SoundEffect {
|
||||
MOB_HORSE_SKELETON_DEATH("mob.horse.skeleton.death", "entity.skeleton_horse.death", SoundCategory.NEUTRAL),
|
||||
AMBIENT_WEATHER_RAIN("ambient.weather.rain", "weather.rain.above", SoundCategory.WEATHER),
|
||||
PORTAL_TRIGGER("portal.trigger", "block.portal.trigger", SoundCategory.BLOCK),
|
||||
RANDOM_CHESTOPEN("random.chestopen", "block.enderchest.open", SoundCategory.BLOCK),
|
||||
RANDOM_CHESTOPEN("random.chestopen", "block.chest.open", SoundCategory.BLOCK),
|
||||
MOB_HORSE_LAND("mob.horse.land", "entity.horse.land", SoundCategory.NEUTRAL),
|
||||
MOB_SILVERFISH_STEP("mob.silverfish.step", "entity.silverfish.step", SoundCategory.HOSTILE),
|
||||
MOB_BAT_TAKEOFF("mob.bat.takeoff", "entity.bat.takeoff", SoundCategory.NEUTRAL),
|
||||
|
||||
+3
-3
@@ -77,7 +77,7 @@ public class EntityTracker extends StoredObject {
|
||||
wrapper.write(Type.VAR_INT, 1); // slot
|
||||
wrapper.write(Type.ITEM, item);
|
||||
try {
|
||||
wrapper.send();
|
||||
wrapper.send(Protocol1_9TO1_8.class);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -258,7 +258,7 @@ public class EntityTracker extends StoredObject {
|
||||
}
|
||||
teamExists = b;
|
||||
try {
|
||||
wrapper.send();
|
||||
wrapper.send(Protocol1_9TO1_8.class);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -281,7 +281,7 @@ public class EntityTracker extends StoredObject {
|
||||
handleMetadata(entityID, metadataBuffer.get(entityID));
|
||||
if (metadataBuffer.get(entityID).size() > 0) {
|
||||
try {
|
||||
wrapper.send();
|
||||
wrapper.send(Protocol1_9TO1_8.class);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user