3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-12-28 00:50:13 +01:00

Move everything into the right package.

Clean up a lot of code.
Remove PacketUtil (evil laugh)
Add Pipeline Util
Organise listeners, and add protocol pipe checks
Dieser Commit ist enthalten in:
Myles 2016-03-18 21:18:48 +00:00
Ursprung 69e8ddcbf6
Commit 8a35c0235e
98 geänderte Dateien mit 1268 neuen und 1437 gelöschten Zeilen

Datei anzeigen

@ -2,11 +2,11 @@ package us.myles.ViaVersion;
import org.bukkit.scheduler.BukkitRunnable;
import us.myles.ViaVersion.api.ViaVersion;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.protocols.base.ProtocolInfo;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9TO1_8;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.MovementTracker;
import us.myles.ViaVersion.util.ReflectionUtil;
import us.myles.ViaVersion2.api.data.UserConnection;
import us.myles.ViaVersion2.api.protocol.base.ProtocolInfo;
import us.myles.ViaVersion2.api.protocol1_9to1_8.Protocol1_9TO1_8;
import us.myles.ViaVersion2.api.protocol1_9to1_8.storage.MovementTracker;
import java.util.Map;
import java.util.UUID;

Datei anzeigen

@ -17,19 +17,19 @@ import us.myles.ViaVersion.api.ViaVersionAPI;
import us.myles.ViaVersion.api.boss.BossBar;
import us.myles.ViaVersion.api.boss.BossColor;
import us.myles.ViaVersion.api.boss.BossStyle;
import us.myles.ViaVersion.armor.ArmorListener;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.protocol.ProtocolRegistry;
import us.myles.ViaVersion.protocols.base.ProtocolInfo;
import us.myles.ViaVersion.boss.ViaBossBar;
import us.myles.ViaVersion.commands.ViaVersionCommand;
import us.myles.ViaVersion.handlers.ViaVersionInitializer;
import us.myles.ViaVersion.listeners.CommandBlockListener;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.listeners.ArmorListener;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.listeners.CommandBlockListener;
import us.myles.ViaVersion.update.UpdateListener;
import us.myles.ViaVersion.update.UpdateUtil;
import us.myles.ViaVersion.util.Configuration;
import us.myles.ViaVersion.util.ListWrapper;
import us.myles.ViaVersion.util.ReflectionUtil;
import us.myles.ViaVersion2.api.data.UserConnection;
import us.myles.ViaVersion2.api.protocol.ProtocolRegistry;
import us.myles.ViaVersion2.api.protocol.base.ProtocolInfo;
import java.io.File;
import java.lang.reflect.Field;
@ -244,7 +244,7 @@ public class ViaVersionPlugin extends JavaPlugin implements ViaVersionAPI {
@Override
public int getPlayerVersion(@NonNull Player player) {
if (!isPorted(player))
return 47;
return ProtocolRegistry.SERVER_PROTOCOL;
return portedPlayers.get(player.getUniqueId()).get(ProtocolInfo.class).getProtocolVersion();
}
@ -258,6 +258,14 @@ public class ViaVersionPlugin extends JavaPlugin implements ViaVersionAPI {
return getDescription().getVersion();
}
public UserConnection getConnection(UUID playerUUID){
return portedPlayers.get(playerUUID);
}
public UserConnection getConnection(Player player){
return portedPlayers.get(player.getUniqueId());
}
public void sendRawPacket(Player player, ByteBuf packet) throws IllegalArgumentException {
sendRawPacket(player.getUniqueId(), packet);
}
@ -322,8 +330,7 @@ public class ViaVersionPlugin extends JavaPlugin implements ViaVersionAPI {
public boolean isAutoTeam() {
// Collision has to be enabled first
if (!isPreventCollision()) return false;
return getConfig().getBoolean("auto-team", true);
return isPreventCollision() && getConfig().getBoolean("auto-team", true);
}
public void addPortedClient(UserConnection info) {

Datei anzeigen

@ -1,15 +1,14 @@
package us.myles.ViaVersion2.api;
package us.myles.ViaVersion.api;
import com.google.common.base.Preconditions;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import lombok.Getter;
import lombok.Setter;
import us.myles.ViaVersion2.api.data.UserConnection;
import us.myles.ViaVersion2.api.remapper.ValueCreator;
import us.myles.ViaVersion2.api.type.Type;
import us.myles.ViaVersion2.api.type.TypeConverter;
import us.myles.ViaVersion2.api.util.Pair;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.remapper.ValueCreator;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.api.type.TypeConverter;
import java.io.IOException;
import java.util.ArrayList;

Datei anzeigen

@ -1,4 +1,4 @@
package us.myles.ViaVersion2.api.util;
package us.myles.ViaVersion.api;
import lombok.EqualsAndHashCode;
import lombok.Getter;

Datei anzeigen

@ -19,6 +19,7 @@ public interface ViaVersionAPI {
/**
* Get protocol number from a player
*
* @param player Bukkit player object
* @return Protocol ID, For example (47=1.8-1.8.8, 107=1.9, 108=1.9.1)
*/

Datei anzeigen

@ -6,13 +6,6 @@ import java.util.Set;
import java.util.UUID;
public interface BossBar {
/**
* Change the title
*
* @param title Title can be in either JSON or just text
*/
void setTitle(String title);
/**
* Get the current title
*
@ -21,11 +14,11 @@ public interface BossBar {
String getTitle();
/**
* Change the health
* Change the title
*
* @param health this float has to be between 0F - 1F
* @param title Title can be in either JSON or just text
*/
void setHealth(float health);
void setTitle(String title);
/**
* Get the health
@ -35,11 +28,11 @@ public interface BossBar {
float getHealth();
/**
* Yay colors!
* Change the health
*
* @param color Whatever color you want!
* @param health this float has to be between 0F - 1F
*/
void setColor(BossColor color);
void setHealth(float health);
/**
* Get the bossbar color
@ -49,11 +42,11 @@ public interface BossBar {
BossColor getColor();
/**
* Change the bosbar style
* Yay colors!
*
* @param style BossStyle
* @param color Whatever color you want!
*/
void setStyle(BossStyle style);
void setColor(BossColor color);
/**
* Get the bosbar style
@ -62,6 +55,13 @@ public interface BossBar {
*/
BossStyle getStyle();
/**
* Change the bosbar style
*
* @param style BossStyle
*/
void setStyle(BossStyle style);
/**
* Show the bossbar to a player.
*

Datei anzeigen

@ -1,8 +1,9 @@
package us.myles.ViaVersion2.api.data;
package us.myles.ViaVersion.api.data;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
@Getter(AccessLevel.PROTECTED)
@AllArgsConstructor
public class StoredObject {

Datei anzeigen

@ -1,4 +1,4 @@
package us.myles.ViaVersion2.api.data;
package us.myles.ViaVersion.api.data;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandler;
@ -10,13 +10,13 @@ import java.util.ArrayList;
import java.util.List;
public class UserConnection {
@Getter
private final SocketChannel channel;
List<StoredObject> storedObjects = new ArrayList<>();
@Getter
@Setter
private boolean active = true;
@Getter
private final SocketChannel channel;
@Getter
@Setter
private Object lastPacket;

Datei anzeigen

@ -1,4 +1,4 @@
package us.myles.ViaVersion2.api.util;
package us.myles.ViaVersion.api.minecraft;
import lombok.AllArgsConstructor;
import lombok.Getter;

Datei anzeigen

@ -1,4 +1,4 @@
package us.myles.ViaVersion.chunks;
package us.myles.ViaVersion.api.minecraft.chunks;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

Datei anzeigen

@ -1,10 +1,9 @@
package us.myles.ViaVersion.chunks;
package us.myles.ViaVersion.api.minecraft.chunks;
import com.google.common.collect.Lists;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import org.bukkit.Material;
import us.myles.ViaVersion.util.PacketUtil;
import us.myles.ViaVersion.api.type.Type;
import java.util.List;
@ -20,7 +19,6 @@ public class ChunkSection {
/**
* Length of the block data array.
*/
// public static final int BLOCK_LENGTH = 16 * 16 * 16 * 2; // size * size * size * 2 (char bit count)
private final List<Integer> palette = Lists.newArrayList();
private final int[] blocks;
@ -61,7 +59,7 @@ public class ChunkSection {
return z << 8 | y << 4 | x;
}
public void writeBlocks(ByteBuf output) {
public void writeBlocks(ByteBuf output) throws Exception {
// Write bits per block
int bitsPerBlock = 4;
while (palette.size() > 1 << bitsPerBlock) {
@ -71,13 +69,13 @@ public class ChunkSection {
output.writeByte(bitsPerBlock);
// Write pallet (or not)
PacketUtil.writeVarInt(palette.size(), output);
Type.VAR_INT.write(output, palette.size());
for (int mappedId : palette) {
PacketUtil.writeVarInt(mappedId, output);
Type.VAR_INT.write(output, mappedId);
}
int length = (int) Math.ceil(SIZE * bitsPerBlock / 64.0);
PacketUtil.writeVarInt(length, output);
Type.VAR_INT.write(output, length);
long[] data = new long[length];
for (int index = 0; index < blocks.length; index++) {
int value = blocks[index];
@ -91,7 +89,9 @@ public class ChunkSection {
data[endIndex] = data[endIndex] >>> endBitSubIndex << endBitSubIndex | ((long) value & maxEntryValue) >> endBitSubIndex;
}
}
PacketUtil.writeLongs(data, output);
for (long l : data) {
Type.LONG.write(output, l);
}
}
public void writeBlockLight(ByteBuf output) {
@ -111,7 +111,7 @@ public class ChunkSection {
*
* @return Amount of bytes sent by this section
*/
public int getExpectedSize() {
public int getExpectedSize() throws Exception {
int bitsPerBlock = palette.size() > 255 ? 16 : 8;
int bytes = 1; // bits per block
bytes += paletteBytes(); // palette
@ -122,7 +122,7 @@ public class ChunkSection {
return bytes;
}
private int paletteBytes() {
private int paletteBytes() throws Exception {
// Count bytes used by pallet
int bytes = countBytes(palette.size());
for (int mappedId : palette) {
@ -131,10 +131,10 @@ public class ChunkSection {
return bytes;
}
private int countBytes(int value) {
private int countBytes(int value) throws Exception {
// Count amount of bytes that would be sent if the value were sent as a VarInt
ByteBuf buf = Unpooled.buffer();
PacketUtil.writeVarInt(value, buf);
Type.VAR_INT.write(buf, value);
buf.readerIndex(0);
int bitCount = buf.readableBytes();
buf.release();

Datei anzeigen

@ -1,4 +1,4 @@
package us.myles.ViaVersion.chunks;
package us.myles.ViaVersion.api.minecraft.chunks;
import java.util.Arrays;
@ -60,6 +60,10 @@ public class NibbleArray {
Arrays.fill(handle, (byte) ((value << 4) | value));
}
public byte[] getHandle() {
return handle;
}
public void setHandle(byte[] handle) {
if (handle.length != this.handle.length) {
throw new IllegalArgumentException("Length of handle must equal to size of nibble array!");
@ -67,8 +71,4 @@ public class NibbleArray {
System.arraycopy(handle, 0, this.handle, 0, handle.length);
}
public byte[] getHandle() {
return handle;
}
}

Datei anzeigen

@ -1,4 +1,4 @@
package us.myles.ViaVersion2.api.item;
package us.myles.ViaVersion.api.minecraft.item;
import lombok.AllArgsConstructor;
import lombok.Getter;

Datei anzeigen

@ -1,9 +1,9 @@
package us.myles.ViaVersion2.api.metadata;
package us.myles.ViaVersion.api.minecraft.metadata;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;
import us.myles.ViaVersion2.api.type.Type;
import us.myles.ViaVersion.api.type.Type;
@AllArgsConstructor
@Getter

Datei anzeigen

@ -1,14 +1,14 @@
package us.myles.ViaVersion2.api.protocol;
package us.myles.ViaVersion.api.protocol;
import lombok.AllArgsConstructor;
import lombok.Getter;
import us.myles.ViaVersion.CancelException;
import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.remapper.PacketRemapper;
import us.myles.ViaVersion.packets.Direction;
import us.myles.ViaVersion.packets.State;
import us.myles.ViaVersion2.api.PacketWrapper;
import us.myles.ViaVersion2.api.data.UserConnection;
import us.myles.ViaVersion2.api.remapper.PacketRemapper;
import us.myles.ViaVersion2.api.util.Pair;
import us.myles.ViaVersion.api.Pair;
import java.util.HashMap;
import java.util.Map;

Datei anzeigen

@ -1,11 +1,11 @@
package us.myles.ViaVersion2.api.protocol;
package us.myles.ViaVersion.api.protocol;
import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.protocols.base.BaseProtocol;
import us.myles.ViaVersion.protocols.base.ProtocolInfo;
import us.myles.ViaVersion.packets.Direction;
import us.myles.ViaVersion.packets.State;
import us.myles.ViaVersion2.api.PacketWrapper;
import us.myles.ViaVersion2.api.data.UserConnection;
import us.myles.ViaVersion2.api.protocol.base.BaseProtocol;
import us.myles.ViaVersion2.api.protocol.base.ProtocolInfo;
import java.util.ArrayList;
import java.util.Collections;

Datei anzeigen

@ -1,21 +1,20 @@
package us.myles.ViaVersion2.api.protocol;
package us.myles.ViaVersion.api.protocol;
import us.myles.ViaVersion2.api.protocol1_9_1to1_9.Protocol1_9_1TO1_9;
import us.myles.ViaVersion2.api.protocol1_9to1_8.Protocol1_9TO1_8;
import us.myles.ViaVersion2.api.util.Pair;
import us.myles.ViaVersion.protocols.protocol1_9_1to1_9.Protocol1_9_1TO1_9;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9TO1_8;
import us.myles.ViaVersion.api.Pair;
import java.util.*;
public class ProtocolRegistry {
public static int SERVER_PROTOCOL = -1;
// Input Version -> Output Version & Protocol (Allows fast lookup)
private static Map<Integer, Map<Integer, Protocol>> registryMap = new HashMap<>();
public static int SERVER_PROTOCOL = -1;
static {
// Register built in protocols
registerProtocol(new Protocol1_9TO1_8(), Arrays.asList(ProtocolVersion.V1_9), ProtocolVersion.V1_8);
registerProtocol(new Protocol1_9_1TO1_9(), Arrays.asList(ProtocolVersion.V1_9_1_PRE2), ProtocolVersion.V1_9);
registerProtocol(new Protocol1_9TO1_8(), Collections.singletonList(ProtocolVersion.V1_9), ProtocolVersion.V1_8);
registerProtocol(new Protocol1_9_1TO1_9(), Collections.singletonList(ProtocolVersion.V1_9_1_PRE2), ProtocolVersion.V1_9);
}
public static void registerProtocol(Protocol protocol, List<Integer> supported, Integer output) {

Datei anzeigen

@ -1,4 +1,4 @@
package us.myles.ViaVersion2.api.protocol;
package us.myles.ViaVersion.api.protocol;
public class ProtocolVersion {
/* Defined protocol constants */

Datei anzeigen

@ -1,6 +1,6 @@
package us.myles.ViaVersion2.api.remapper;
package us.myles.ViaVersion.api.remapper;
import us.myles.ViaVersion2.api.PacketWrapper;
import us.myles.ViaVersion.api.PacketWrapper;
public abstract class PacketHandler implements ValueWriter {
public abstract void handle(PacketWrapper wrapper) throws Exception;

Datei anzeigen

@ -1,8 +1,8 @@
package us.myles.ViaVersion2.api.remapper;
package us.myles.ViaVersion.api.remapper;
import us.myles.ViaVersion2.api.PacketWrapper;
import us.myles.ViaVersion2.api.type.Type;
import us.myles.ViaVersion2.api.util.Pair;
import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.api.Pair;
import java.util.ArrayList;
import java.util.List;

Datei anzeigen

@ -1,7 +1,7 @@
package us.myles.ViaVersion2.api.remapper;
package us.myles.ViaVersion.api.remapper;
import us.myles.ViaVersion2.api.PacketWrapper;
import us.myles.ViaVersion2.api.type.Type;
import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.type.Type;
public class TypeRemapper<T> implements ValueReader<T>, ValueWriter<T> {
private final Type<T> type;

Datei anzeigen

@ -1,6 +1,6 @@
package us.myles.ViaVersion2.api.remapper;
package us.myles.ViaVersion.api.remapper;
import us.myles.ViaVersion2.api.PacketWrapper;
import us.myles.ViaVersion.api.PacketWrapper;
public abstract class ValueCreator implements ValueWriter {
public abstract void write(PacketWrapper wrapper) throws Exception;

Datei anzeigen

@ -0,0 +1,7 @@
package us.myles.ViaVersion.api.remapper;
import us.myles.ViaVersion.api.PacketWrapper;
public interface ValueReader<T> {
T read(PacketWrapper wrapper) throws Exception;
}

Datei anzeigen

@ -1,7 +1,7 @@
package us.myles.ViaVersion2.api.remapper;
package us.myles.ViaVersion.api.remapper;
import us.myles.ViaVersion2.api.PacketWrapper;
import us.myles.ViaVersion2.api.type.Type;
import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.type.Type;
public abstract class ValueTransformer<T1, T2> implements ValueWriter<T1> {
private final Type<T2> outputType;

Datei anzeigen

@ -0,0 +1,7 @@
package us.myles.ViaVersion.api.remapper;
import us.myles.ViaVersion.api.PacketWrapper;
public interface ValueWriter<T> {
void write(PacketWrapper writer, T inputValue) throws Exception;
}

Datei anzeigen

@ -0,0 +1,7 @@
package us.myles.ViaVersion.api.type;
import io.netty.buffer.ByteBuf;
public interface ByteBufReader<T> {
T read(ByteBuf buffer) throws Exception;
}

Datei anzeigen

@ -0,0 +1,7 @@
package us.myles.ViaVersion.api.type;
import io.netty.buffer.ByteBuf;
public interface ByteBufWriter<T> {
void write(ByteBuf buffer, T object) throws Exception;
}

Datei anzeigen

@ -1,4 +1,4 @@
package us.myles.ViaVersion2.api.type;
package us.myles.ViaVersion.api.type;
import io.netty.buffer.ByteBuf;
@ -10,17 +10,17 @@ public abstract class PartialType<T, X> extends Type<T> {
this.param = param;
}
public abstract T read(ByteBuf buffer, X param);
public abstract T read(ByteBuf buffer, X param) throws Exception;
public abstract void write(ByteBuf buffer, X param, T object);
public abstract void write(ByteBuf buffer, X param, T object) throws Exception;
@Override
public T read(ByteBuf buffer) {
public T read(ByteBuf buffer) throws Exception {
return read(buffer, this.param);
}
@Override
public void write(ByteBuf buffer, T object) {
public void write(ByteBuf buffer, T object) throws Exception {
write(buffer, this.param, object);
}
}

Datei anzeigen

@ -1,14 +1,14 @@
package us.myles.ViaVersion2.api.type;
package us.myles.ViaVersion.api.type;
import lombok.Getter;
import org.bukkit.util.EulerAngle;
import org.bukkit.util.Vector;
import org.spacehq.opennbt.tag.builtin.CompoundTag;
import us.myles.ViaVersion2.api.item.Item;
import us.myles.ViaVersion2.api.type.types.*;
import us.myles.ViaVersion2.api.type.types.minecraft.*;
import us.myles.ViaVersion2.api.util.Position;
import us.myles.ViaVersion.api.minecraft.Position;
import us.myles.ViaVersion.api.minecraft.item.Item;
import us.myles.ViaVersion.api.type.types.*;
import us.myles.ViaVersion.api.type.types.minecraft.*;
import java.util.UUID;

Datei anzeigen

@ -0,0 +1,5 @@
package us.myles.ViaVersion.api.type;
public interface TypeConverter<T> {
T from(Object o);
}

Datei anzeigen

@ -1,7 +1,7 @@
package us.myles.ViaVersion2.api.type.types;
package us.myles.ViaVersion.api.type.types;
import io.netty.buffer.ByteBuf;
import us.myles.ViaVersion2.api.type.Type;
import us.myles.ViaVersion.api.type.Type;
import java.lang.reflect.Array;
@ -13,25 +13,6 @@ public class ArrayType<T> extends Type<T[]> {
this.elementType = type;
}
@Override
public T[] read(ByteBuf buffer) throws Exception{
int amount = Type.VAR_INT.read(buffer);
T[] array = (T[]) Array.newInstance(elementType.getOutputClass(), amount);
for (int i = 0; i < amount; i++) {
array[i] = elementType.read(buffer);
}
return array;
}
@Override
public void write(ByteBuf buffer, T[] object) throws Exception{
Type.VAR_INT.write(buffer, object.length);
for (T o : object) {
elementType.write(buffer, o);
}
}
/* Taken from http://stackoverflow.com/questions/4901128/obtaining-the-array-class-of-a-component-type */
public static Class<?> getArrayClass(Class<?> componentType) {
ClassLoader classLoader = componentType.getClassLoader();
@ -65,4 +46,23 @@ public class ArrayType<T> extends Type<T[]> {
return null; // oh
}
}
@Override
public T[] read(ByteBuf buffer) throws Exception {
int amount = Type.VAR_INT.read(buffer);
T[] array = (T[]) Array.newInstance(elementType.getOutputClass(), amount);
for (int i = 0; i < amount; i++) {
array[i] = elementType.read(buffer);
}
return array;
}
@Override
public void write(ByteBuf buffer, T[] object) throws Exception {
Type.VAR_INT.write(buffer, object.length);
for (T o : object) {
elementType.write(buffer, o);
}
}
}

Datei anzeigen

@ -1,8 +1,8 @@
package us.myles.ViaVersion2.api.type.types;
package us.myles.ViaVersion.api.type.types;
import io.netty.buffer.ByteBuf;
import us.myles.ViaVersion2.api.type.Type;
import us.myles.ViaVersion2.api.type.TypeConverter;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.api.type.TypeConverter;
public class BooleanType extends Type<Boolean> implements TypeConverter<Boolean> {
public BooleanType() {

Datei anzeigen

@ -1,8 +1,8 @@
package us.myles.ViaVersion2.api.type.types;
package us.myles.ViaVersion.api.type.types;
import io.netty.buffer.ByteBuf;
import us.myles.ViaVersion2.api.type.Type;
import us.myles.ViaVersion2.api.type.TypeConverter;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.api.type.TypeConverter;
public class ByteType extends Type<Byte> implements TypeConverter<Byte> {
public ByteType() {
@ -26,7 +26,7 @@ public class ByteType extends Type<Byte> implements TypeConverter<Byte> {
return ((Number) o).byteValue();
}
if (o instanceof Boolean) {
return ((Boolean)o) == true ? (byte) 1 : 0;
return (Boolean) o ? (byte) 1 : 0;
}
return (Byte) o;
}

Datei anzeigen

@ -1,8 +1,8 @@
package us.myles.ViaVersion2.api.type.types;
package us.myles.ViaVersion.api.type.types;
import io.netty.buffer.ByteBuf;
import us.myles.ViaVersion2.api.type.Type;
import us.myles.ViaVersion2.api.type.TypeConverter;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.api.type.TypeConverter;
public class DoubleType extends Type<Double> implements TypeConverter<Double> {
public DoubleType() {
@ -25,7 +25,7 @@ public class DoubleType extends Type<Double> implements TypeConverter<Double>{
return ((Number) o).doubleValue();
}
if (o instanceof Boolean) {
return ((Boolean)o) == true ? 1D : 0D;
return (Boolean) o ? (byte) 1D : 0D;
}
return (Double) o;
}

Datei anzeigen

@ -1,8 +1,8 @@
package us.myles.ViaVersion2.api.type.types;
package us.myles.ViaVersion.api.type.types;
import io.netty.buffer.ByteBuf;
import us.myles.ViaVersion2.api.type.Type;
import us.myles.ViaVersion2.api.type.TypeConverter;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.api.type.TypeConverter;
public class FloatType extends Type<Float> implements TypeConverter<Float> {
public FloatType() {
@ -26,7 +26,7 @@ public class FloatType extends Type<Float> implements TypeConverter<Float>{
return ((Number) o).floatValue();
}
if (o instanceof Boolean) {
return ((Boolean)o) == true ? 1F : 0;
return ((Boolean) o) ? 1F : 0;
}
return (Float) o;
}

Datei anzeigen

@ -1,8 +1,8 @@
package us.myles.ViaVersion2.api.type.types;
package us.myles.ViaVersion.api.type.types;
import io.netty.buffer.ByteBuf;
import us.myles.ViaVersion2.api.type.Type;
import us.myles.ViaVersion2.api.type.TypeConverter;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.api.type.TypeConverter;
public class IntType extends Type<Integer> implements TypeConverter<Integer> {
public IntType() {
@ -25,7 +25,7 @@ public class IntType extends Type<Integer> implements TypeConverter<Integer>{
return ((Number) o).intValue();
}
if (o instanceof Boolean) {
return ((Boolean)o) == true ? 1 : 0;
return ((Boolean) o) ? 1 : 0;
}
return (Integer) o;
}

Datei anzeigen

@ -1,8 +1,8 @@
package us.myles.ViaVersion2.api.type.types;
package us.myles.ViaVersion.api.type.types;
import io.netty.buffer.ByteBuf;
import us.myles.ViaVersion2.api.type.Type;
import us.myles.ViaVersion2.api.type.TypeConverter;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.api.type.TypeConverter;
public class LongType extends Type<Long> implements TypeConverter<Long> {
public LongType() {
@ -26,7 +26,7 @@ public class LongType extends Type<Long> implements TypeConverter<Long> {
return ((Number) o).longValue();
}
if (o instanceof Boolean) {
return ((Boolean)o) == true ? 1L : 0;
return ((Boolean) o) ? 1L : 0;
}
return (Long) o;
}

Datei anzeigen

@ -1,7 +1,7 @@
package us.myles.ViaVersion2.api.type.types;
package us.myles.ViaVersion.api.type.types;
import io.netty.buffer.ByteBuf;
import us.myles.ViaVersion2.api.type.Type;
import us.myles.ViaVersion.api.type.Type;
public class RemainingBytesType extends Type<byte[]> {
public RemainingBytesType() {

Datei anzeigen

@ -1,8 +1,8 @@
package us.myles.ViaVersion2.api.type.types;
package us.myles.ViaVersion.api.type.types;
import io.netty.buffer.ByteBuf;
import us.myles.ViaVersion2.api.type.Type;
import us.myles.ViaVersion2.api.type.TypeConverter;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.api.type.TypeConverter;
public class ShortType extends Type<Short> implements TypeConverter<Short> {
public ShortType() {
@ -25,7 +25,7 @@ public class ShortType extends Type<Short> implements TypeConverter<Short> {
return ((Number) o).shortValue();
}
if (o instanceof Boolean) {
return ((Boolean)o) == true ? (short) 1 : 0;
return ((Boolean) o) ? (short) 1 : 0;
}
return (short) o;
}

Datei anzeigen

@ -1,9 +1,9 @@
package us.myles.ViaVersion2.api.type.types;
package us.myles.ViaVersion.api.type.types;
import com.google.common.base.Charsets;
import com.google.common.base.Preconditions;
import io.netty.buffer.ByteBuf;
import us.myles.ViaVersion2.api.type.Type;
import us.myles.ViaVersion.api.type.Type;
public class StringType extends Type<String> {
public StringType() {

Datei anzeigen

@ -1,7 +1,7 @@
package us.myles.ViaVersion2.api.type.types;
package us.myles.ViaVersion.api.type.types;
import io.netty.buffer.ByteBuf;
import us.myles.ViaVersion2.api.type.Type;
import us.myles.ViaVersion.api.type.Type;
import java.util.UUID;

Datei anzeigen

@ -1,8 +1,8 @@
package us.myles.ViaVersion2.api.type.types;
package us.myles.ViaVersion.api.type.types;
import io.netty.buffer.ByteBuf;
import us.myles.ViaVersion2.api.type.Type;
import us.myles.ViaVersion2.api.type.TypeConverter;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.api.type.TypeConverter;
public class UnsignedByteType extends Type<Short> implements TypeConverter<Short> {
public UnsignedByteType() {
@ -25,7 +25,7 @@ public class UnsignedByteType extends Type<Short> implements TypeConverter<Short
return ((Number) o).shortValue();
}
if (o instanceof Boolean) {
return ((Boolean)o) == true ? (short) 1 : 0;
return ((Boolean) o) ? (short) 1 : 0;
}
return (short) o;
}

Datei anzeigen

@ -1,8 +1,8 @@
package us.myles.ViaVersion2.api.type.types;
package us.myles.ViaVersion.api.type.types;
import io.netty.buffer.ByteBuf;
import us.myles.ViaVersion2.api.type.Type;
import us.myles.ViaVersion2.api.type.TypeConverter;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.api.type.TypeConverter;
public class UnsignedShortType extends Type<Integer> implements TypeConverter<Integer> {
public UnsignedShortType() {
@ -25,7 +25,7 @@ public class UnsignedShortType extends Type<Integer> implements TypeConverter<In
return ((Number) o).intValue();
}
if (o instanceof Boolean) {
return ((Boolean)o) == true ? 1 : 0;
return ((Boolean) o) ? 1 : 0;
}
return (Integer) o;
}

Datei anzeigen

@ -1,8 +1,8 @@
package us.myles.ViaVersion2.api.type.types;
package us.myles.ViaVersion.api.type.types;
import io.netty.buffer.ByteBuf;
import us.myles.ViaVersion2.api.type.Type;
import us.myles.ViaVersion2.api.type.TypeConverter;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.api.type.TypeConverter;
public class VarIntType extends Type<Integer> implements TypeConverter<Integer> {
@ -58,7 +58,7 @@ public class VarIntType extends Type<Integer> implements TypeConverter<Integer>
return ((Number) o).intValue();
}
if (o instanceof Boolean) {
return ((Boolean) o) == true ? 1 : 0;
return ((Boolean) o) ? 1 : 0;
}
return (Integer) o;
}

Datei anzeigen

@ -1,8 +1,8 @@
package us.myles.ViaVersion2.api.type.types;
package us.myles.ViaVersion.api.type.types;
import io.netty.buffer.ByteBuf;
import us.myles.ViaVersion2.api.type.Type;
import us.myles.ViaVersion2.api.type.TypeConverter;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.api.type.TypeConverter;
public class VoidType extends Type<Void> implements TypeConverter<Void> {
public VoidType() {

Datei anzeigen

@ -1,9 +1,8 @@
package us.myles.ViaVersion2.api.type.types.minecraft;
package us.myles.ViaVersion.api.type.types.minecraft;
import io.netty.buffer.ByteBuf;
import org.bukkit.util.EulerAngle;
import org.bukkit.util.Vector;
import us.myles.ViaVersion2.api.type.Type;
import us.myles.ViaVersion.api.type.Type;
public class EulerAngleType extends Type<EulerAngle> {
public EulerAngleType() {

Datei anzeigen

@ -1,8 +1,8 @@
package us.myles.ViaVersion2.api.type.types.minecraft;
package us.myles.ViaVersion.api.type.types.minecraft;
import io.netty.buffer.ByteBuf;
import us.myles.ViaVersion2.api.item.Item;
import us.myles.ViaVersion2.api.type.Type;
import us.myles.ViaVersion.api.minecraft.item.Item;
import us.myles.ViaVersion.api.type.Type;
public class ItemArrayType extends Type<Item[]> {

Datei anzeigen

@ -1,8 +1,8 @@
package us.myles.ViaVersion2.api.type.types.minecraft;
package us.myles.ViaVersion.api.type.types.minecraft;
import io.netty.buffer.ByteBuf;
import us.myles.ViaVersion2.api.item.Item;
import us.myles.ViaVersion2.api.type.Type;
import us.myles.ViaVersion.api.minecraft.item.Item;
import us.myles.ViaVersion.api.type.Type;
public class ItemType extends Type<Item> {
public ItemType() {

Datei anzeigen

@ -1,4 +1,4 @@
package us.myles.ViaVersion2.api.type.types.minecraft;
package us.myles.ViaVersion.api.type.types.minecraft;
import com.google.common.base.Preconditions;
import io.netty.buffer.ByteBuf;
@ -6,7 +6,7 @@ import io.netty.buffer.ByteBufInputStream;
import io.netty.buffer.ByteBufOutputStream;
import org.spacehq.opennbt.NBTIO;
import org.spacehq.opennbt.tag.builtin.CompoundTag;
import us.myles.ViaVersion2.api.type.Type;
import us.myles.ViaVersion.api.type.Type;
import java.io.DataInputStream;
import java.io.DataOutputStream;
@ -27,11 +27,8 @@ public class NBTType extends Type<CompoundTag> {
} else {
buffer.readerIndex(readerIndex);
ByteBufInputStream bytebufStream = new ByteBufInputStream(buffer);
DataInputStream dataInputStream = new DataInputStream(bytebufStream);
try {
try (DataInputStream dataInputStream = new DataInputStream(bytebufStream)) {
return (CompoundTag) NBTIO.readTag(dataInputStream);
} finally {
dataInputStream.close();
}
}
}

Datei anzeigen

@ -1,7 +1,7 @@
package us.myles.ViaVersion2.api.type.types.minecraft;
package us.myles.ViaVersion.api.type.types.minecraft;
import io.netty.buffer.ByteBuf;
import us.myles.ViaVersion2.api.type.Type;
import us.myles.ViaVersion.api.type.Type;
import java.util.UUID;
@ -21,7 +21,6 @@ public class OptUUIDType extends Type<UUID> {
public void write(ByteBuf buffer, UUID object) {
if (object == null) {
buffer.writeBoolean(false);
return;
} else {
buffer.writeBoolean(true);
buffer.writeLong(object.getMostSignificantBits());

Datei anzeigen

@ -1,8 +1,8 @@
package us.myles.ViaVersion2.api.type.types.minecraft;
package us.myles.ViaVersion.api.type.types.minecraft;
import io.netty.buffer.ByteBuf;
import us.myles.ViaVersion2.api.type.Type;
import us.myles.ViaVersion2.api.util.Position;
import us.myles.ViaVersion.api.minecraft.Position;
import us.myles.ViaVersion.api.type.Type;
public class PositionType extends Type<Position> {
public PositionType() {

Datei anzeigen

@ -1,8 +1,8 @@
package us.myles.ViaVersion2.api.type.types.minecraft;
package us.myles.ViaVersion.api.type.types.minecraft;
import io.netty.buffer.ByteBuf;
import org.bukkit.util.Vector;
import us.myles.ViaVersion2.api.type.Type;
import us.myles.ViaVersion.api.type.Type;
public class VectorType extends Type<Vector> {
public VectorType() {

Datei anzeigen

@ -11,9 +11,9 @@ import us.myles.ViaVersion.api.boss.BossBar;
import us.myles.ViaVersion.api.boss.BossColor;
import us.myles.ViaVersion.api.boss.BossFlag;
import us.myles.ViaVersion.api.boss.BossStyle;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.packets.PacketType;
import us.myles.ViaVersion.util.PacketUtil;
import us.myles.ViaVersion2.api.protocol1_9to1_8.Protocol1_9TO1_8;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9TO1_8;
import java.util.*;
@ -152,16 +152,17 @@ public class ViaBossBar implements BossBar {
}
private ByteBuf getPacket(UpdateAction action) {
try {
ByteBuf buf = Unpooled.buffer();
PacketUtil.writeVarInt(PacketType.PLAY_BOSS_BAR.getNewPacketID(), buf);
PacketUtil.writeUUID(uuid, buf);
PacketUtil.writeVarInt(action.getId(), buf);
Type.VAR_INT.write(buf, 0x0C); // Boss bar packet
Type.UUID.write(buf, uuid);
Type.VAR_INT.write(buf, action.getId());
switch (action) {
case ADD:
PacketUtil.writeString(fixJson(title), buf);
Type.STRING.write(buf, fixJson(title));
buf.writeFloat(health);
PacketUtil.writeVarInt(color.getId(), buf);
PacketUtil.writeVarInt(style.getId(), buf);
Type.VAR_INT.write(buf, color.getId());
Type.VAR_INT.write(buf, style.getId());
buf.writeByte(flagToBytes());
break;
case REMOVE:
@ -170,11 +171,11 @@ public class ViaBossBar implements BossBar {
buf.writeFloat(health);
break;
case UPDATE_TITLE:
PacketUtil.writeString(fixJson(title), buf);
Type.STRING.write(buf, fixJson(title));
break;
case UPDATE_STYLE:
PacketUtil.writeVarInt(color.getId(), buf);
PacketUtil.writeVarInt(style.getId(), buf);
Type.VAR_INT.write(buf, color.getId());
Type.VAR_INT.write(buf, style.getId());
break;
case UPDATE_FLAGS:
buf.writeByte(flagToBytes());
@ -182,6 +183,10 @@ public class ViaBossBar implements BossBar {
}
return buf;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
private int flagToBytes() {

Datei anzeigen

@ -12,9 +12,6 @@ import us.myles.ViaVersion.api.ViaVersion;
import java.util.ArrayList;
import java.util.List;
/**
* Created by fillefilip8 on 2016-03-03.
*/
@RequiredArgsConstructor
public class ViaVersionCommand implements CommandExecutor {

Datei anzeigen

@ -3,8 +3,8 @@ package us.myles.ViaVersion.handlers;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToMessageEncoder;
import us.myles.ViaVersion2.api.data.UserConnection;
import us.myles.ViaVersion2.api.protocol1_9to1_8.storage.ClientChunks;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.ClientChunks;
import java.util.List;

Datei anzeigen

@ -4,11 +4,12 @@ import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageDecoder;
import us.myles.ViaVersion.CancelException;
import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.protocols.base.ProtocolInfo;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.packets.Direction;
import us.myles.ViaVersion.util.PacketUtil;
import us.myles.ViaVersion2.api.PacketWrapper;
import us.myles.ViaVersion2.api.data.UserConnection;
import us.myles.ViaVersion2.api.protocol.base.ProtocolInfo;
import us.myles.ViaVersion.util.PipelineUtil;
import java.lang.reflect.InvocationTargetException;
import java.util.List;
@ -28,7 +29,7 @@ public class ViaDecodeHandler extends ByteToMessageDecoder {
// use transformers
if (bytebuf.readableBytes() > 0) {
if (info.isActive()) {
int id = PacketUtil.readVarInt(bytebuf);
int id = Type.VAR_INT.read(bytebuf);
// Transform
try {
@ -47,7 +48,7 @@ public class ViaDecodeHandler extends ByteToMessageDecoder {
}
// call minecraft decoder
try {
list.addAll(PacketUtil.callDecode(this.minecraftDecoder, ctx, bytebuf));
list.addAll(PipelineUtil.callDecode(this.minecraftDecoder, ctx, bytebuf));
} catch (InvocationTargetException e) {
if (e.getCause() instanceof Exception) {
throw (Exception) e.getCause();
@ -58,7 +59,7 @@ public class ViaDecodeHandler extends ByteToMessageDecoder {
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
if (PacketUtil.containsCause(cause, CancelException.class)) return;
if (PipelineUtil.containsCause(cause, CancelException.class)) return;
super.exceptionCaught(ctx, cause);
}
}

Datei anzeigen

@ -4,11 +4,12 @@ import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;
import us.myles.ViaVersion.CancelException;
import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.protocols.base.ProtocolInfo;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.packets.Direction;
import us.myles.ViaVersion.util.PacketUtil;
import us.myles.ViaVersion2.api.PacketWrapper;
import us.myles.ViaVersion2.api.data.UserConnection;
import us.myles.ViaVersion2.api.protocol.base.ProtocolInfo;
import us.myles.ViaVersion.util.PipelineUtil;
import java.lang.reflect.InvocationTargetException;
@ -28,7 +29,7 @@ public class ViaEncodeHandler extends MessageToByteEncoder {
if (!(o instanceof ByteBuf)) {
// call minecraft encoder
try {
PacketUtil.callEncode(this.minecraftEncoder, ctx, o, bytebuf);
PipelineUtil.callEncode(this.minecraftEncoder, ctx, o, bytebuf);
} catch (InvocationTargetException e) {
if (e.getCause() instanceof Exception) {
throw (Exception) e.getCause();
@ -39,7 +40,7 @@ public class ViaEncodeHandler extends MessageToByteEncoder {
throw new CancelException();
}
if (info.isActive()) {
int id = PacketUtil.readVarInt(bytebuf);
int id = Type.VAR_INT.read(bytebuf);
// Transform
ByteBuf oldPacket = bytebuf.copy();
bytebuf.clear();
@ -59,7 +60,7 @@ public class ViaEncodeHandler extends MessageToByteEncoder {
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
if (PacketUtil.containsCause(cause, CancelException.class)) return;
if (PipelineUtil.containsCause(cause, CancelException.class)) return;
super.exceptionCaught(ctx, cause);
}
}

Datei anzeigen

@ -5,8 +5,8 @@ import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.ByteToMessageDecoder;
import io.netty.handler.codec.MessageToByteEncoder;
import us.myles.ViaVersion2.api.data.UserConnection;
import us.myles.ViaVersion2.api.protocol.ProtocolPipeline;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.protocol.ProtocolPipeline;
import java.lang.reflect.Method;

Datei anzeigen

@ -2,9 +2,7 @@ package us.myles.ViaVersion.packets;
import java.util.HashMap;
import com.google.common.collect.HashBasedTable;
import com.google.common.collect.Table;
@Deprecated
public enum PacketType {
/* Handshake serverbound */
HANDSHAKE(State.HANDSHAKE, Direction.INCOMING, 0x00), // Mapped
@ -138,9 +136,19 @@ public enum PacketType {
PLAY_ENTITY_PROPERTIES(State.PLAY, Direction.OUTGOING, 0x20, 0x4B), // Mapped
PLAY_ENTITY_EFFECT(State.PLAY, Direction.OUTGOING, 0x1D, 0x4C), // Mapped
PLAY_MAP_CHUNK_BULK(State.PLAY, Direction.OUTGOING, 0x26, -1), // TODO?
PLAY_SET_COMPRESSION(State.PLAY, Direction.OUTGOING, 0x46, -1), // TODO?
PLAY_UPDATE_ENTITY_NBT(State.PLAY, Direction.OUTGOING, 0x49, -1),; // TODO?
PLAY_MAP_CHUNK_BULK(State.PLAY, Direction.OUTGOING, 0x26, -1),
PLAY_SET_COMPRESSION(State.PLAY, Direction.OUTGOING, 0x46, -1),
PLAY_UPDATE_ENTITY_NBT(State.PLAY, Direction.OUTGOING, 0x49, -1);
private static HashMap<Short, PacketType> oldids = new HashMap<>();
private static HashMap<Short, PacketType> newids = new HashMap<>();
static {
for (PacketType pt : PacketType.values()) {
oldids.put(toShort((short) pt.getPacketID(), (short) pt.getDirection().ordinal(), (short) pt.getState().ordinal()), pt);
newids.put(toShort((short) pt.getNewPacketID(), (short) pt.getDirection().ordinal(), (short) pt.getState().ordinal()), pt);
}
}
private State state;
private Direction direction;
@ -161,22 +169,6 @@ public enum PacketType {
this.newPacketID = newPacketID;
}
public State getState() {
return state;
}
public Direction getDirection() {
return direction;
}
public int getPacketID() {
return packetID;
}
public int getNewPacketID() {
return newPacketID;
}
public static PacketType findNewPacket(State state, Direction direction, int id) {
return newids.get(toShort((short) id, (short) direction.ordinal(), (short) state.ordinal()));
}
@ -197,13 +189,20 @@ public enum PacketType {
return (short) ((id & 0x00FF) | (direction << 8) & 0x0F00 | (state << 12) & 0xF000);
}
private static HashMap<Short, PacketType> oldids = new HashMap<Short, PacketType>();
private static HashMap<Short, PacketType> newids = new HashMap<Short, PacketType>();
static {
for(PacketType pt : PacketType.values()) {
oldids.put(toShort((short) pt.getPacketID(), (short)pt.getDirection().ordinal(), (short)pt.getState().ordinal()), pt);
newids.put(toShort((short) pt.getNewPacketID(), (short)pt.getDirection().ordinal(), (short)pt.getState().ordinal()), pt);
public State getState() {
return state;
}
public Direction getDirection() {
return direction;
}
public int getPacketID() {
return packetID;
}
public int getNewPacketID() {
return newPacketID;
}
}

Datei anzeigen

@ -1,20 +1,20 @@
package us.myles.ViaVersion2.api.protocol.base;
package us.myles.ViaVersion.protocols.base;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import us.myles.ViaVersion.ViaVersionPlugin;
import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.ViaVersion;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.protocol.Protocol;
import us.myles.ViaVersion.api.protocol.ProtocolPipeline;
import us.myles.ViaVersion.api.protocol.ProtocolRegistry;
import us.myles.ViaVersion.api.remapper.PacketHandler;
import us.myles.ViaVersion.api.remapper.PacketRemapper;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.packets.State;
import us.myles.ViaVersion2.api.PacketWrapper;
import us.myles.ViaVersion2.api.data.UserConnection;
import us.myles.ViaVersion2.api.protocol.Protocol;
import us.myles.ViaVersion2.api.protocol.ProtocolPipeline;
import us.myles.ViaVersion2.api.protocol.ProtocolRegistry;
import us.myles.ViaVersion2.api.remapper.PacketHandler;
import us.myles.ViaVersion2.api.remapper.PacketRemapper;
import us.myles.ViaVersion2.api.type.Type;
import us.myles.ViaVersion2.api.util.Pair;
import us.myles.ViaVersion.api.Pair;
import java.util.List;
import java.util.UUID;

Datei anzeigen

@ -1,11 +1,11 @@
package us.myles.ViaVersion2.api.protocol.base;
package us.myles.ViaVersion.protocols.base;
import lombok.Getter;
import lombok.Setter;
import us.myles.ViaVersion.api.data.StoredObject;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.protocol.ProtocolPipeline;
import us.myles.ViaVersion.packets.State;
import us.myles.ViaVersion2.api.data.StoredObject;
import us.myles.ViaVersion2.api.data.UserConnection;
import us.myles.ViaVersion2.api.protocol.ProtocolPipeline;
import java.util.UUID;

Datei anzeigen

@ -1,10 +1,10 @@
package us.myles.ViaVersion2.api.protocol1_9_1to1_9;
package us.myles.ViaVersion.protocols.protocol1_9_1to1_9;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.protocol.Protocol;
import us.myles.ViaVersion.api.remapper.PacketRemapper;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.packets.State;
import us.myles.ViaVersion2.api.data.UserConnection;
import us.myles.ViaVersion2.api.protocol.Protocol;
import us.myles.ViaVersion2.api.remapper.PacketRemapper;
import us.myles.ViaVersion2.api.type.Type;
public class Protocol1_9_1TO1_9 extends Protocol {
@Override

Datei anzeigen

@ -1,4 +1,4 @@
package us.myles.ViaVersion.armor;
package us.myles.ViaVersion.protocols.protocol1_9to1_8;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

Datei anzeigen

@ -1,11 +1,11 @@
package us.myles.ViaVersion2.api.protocol1_9to1_8;
package us.myles.ViaVersion.protocols.protocol1_9to1_8;
import org.bukkit.Material;
import org.spacehq.opennbt.tag.builtin.CompoundTag;
import org.spacehq.opennbt.tag.builtin.ListTag;
import org.spacehq.opennbt.tag.builtin.StringTag;
import org.spacehq.opennbt.tag.builtin.Tag;
import us.myles.ViaVersion2.api.item.Item;
import us.myles.ViaVersion.api.minecraft.item.Item;
import java.util.Collections;
import java.util.HashMap;

Datei anzeigen

@ -1,9 +1,9 @@
package us.myles.ViaVersion2.api.protocol1_9to1_8;
package us.myles.ViaVersion.protocols.protocol1_9to1_8;
import us.myles.ViaVersion2.api.PacketWrapper;
import us.myles.ViaVersion2.api.protocol1_9to1_8.storage.MovementTracker;
import us.myles.ViaVersion2.api.remapper.PacketHandler;
import us.myles.ViaVersion2.api.remapper.PacketRemapper;
import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.remapper.PacketHandler;
import us.myles.ViaVersion.api.remapper.PacketRemapper;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.MovementTracker;
public class PlayerMovementMapper extends PacketRemapper {
@Override

Datei anzeigen

@ -1,27 +1,25 @@
package us.myles.ViaVersion2.api.protocol1_9to1_8;
package us.myles.ViaVersion.protocols.protocol1_9to1_8;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonObject;
import org.bukkit.Bukkit;
import org.bukkit.inventory.ItemStack;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.ViaVersion;
import us.myles.ViaVersion2.api.PacketWrapper;
import us.myles.ViaVersion2.api.data.UserConnection;
import us.myles.ViaVersion2.api.metadata.Metadata;
import us.myles.ViaVersion2.api.protocol.Protocol;
import us.myles.ViaVersion2.api.protocol.base.ProtocolInfo;
import us.myles.ViaVersion2.api.protocol1_9to1_8.packets.*;
import us.myles.ViaVersion2.api.protocol1_9to1_8.storage.ClientChunks;
import us.myles.ViaVersion2.api.protocol1_9to1_8.storage.EntityTracker;
import us.myles.ViaVersion2.api.protocol1_9to1_8.storage.InventoryTracker;
import us.myles.ViaVersion2.api.protocol1_9to1_8.storage.MovementTracker;
import us.myles.ViaVersion2.api.protocol1_9to1_8.types.MetadataListType;
import us.myles.ViaVersion2.api.protocol1_9to1_8.types.MetadataType;
import us.myles.ViaVersion2.api.remapper.ValueTransformer;
import us.myles.ViaVersion2.api.type.Type;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
import us.myles.ViaVersion.api.protocol.Protocol;
import us.myles.ViaVersion.protocols.base.ProtocolInfo;
import us.myles.ViaVersion.api.remapper.ValueTransformer;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.packets.*;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.ClientChunks;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.EntityTracker;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.InventoryTracker;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.MovementTracker;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.types.MetadataListType;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.types.MetadataType;
import java.util.List;
import java.util.UUID;
@ -29,11 +27,9 @@ import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;
public class Protocol1_9TO1_8 extends Protocol {
private static Gson gson = new GsonBuilder().create();
public static Type<List<Metadata>> METADATA_LIST = new MetadataListType();
public static Type<Metadata> METADATA = new MetadataType();
private static Gson gson = new GsonBuilder().create();
public static ValueTransformer<String, String> FIX_JSON = new ValueTransformer<String, String>(Type.STRING) {
@Override
public String transform(PacketWrapper wrapper, String line) {
@ -41,27 +37,6 @@ public class Protocol1_9TO1_8 extends Protocol {
}
};
@Override
protected void registerPackets() {
SpawnPackets.register(this);
InventoryPackets.register(this);
EntityPackets.register(this);
PlayerPackets.register(this);
WorldPackets.register(this);
}
@Override
public void init(UserConnection userConnection) {
// Entity tracker
userConnection.put(new EntityTracker(userConnection));
// Chunk tracker
userConnection.put(new ClientChunks(userConnection));
// Movement tracker
userConnection.put(new MovementTracker(userConnection));
// Inventory tracker
userConnection.put(new InventoryTracker(userConnection));
}
public static String fixJson(String line) {
if (line == null || line.equalsIgnoreCase("null")) {
line = "{\"text\":\"\"}";
@ -103,4 +78,25 @@ public class Protocol1_9TO1_8 extends Protocol {
return null;
}
}
@Override
protected void registerPackets() {
SpawnPackets.register(this);
InventoryPackets.register(this);
EntityPackets.register(this);
PlayerPackets.register(this);
WorldPackets.register(this);
}
@Override
public void init(UserConnection userConnection) {
// Entity tracker
userConnection.put(new EntityTracker(userConnection));
// Chunk tracker
userConnection.put(new ClientChunks(userConnection));
// Movement tracker
userConnection.put(new MovementTracker(userConnection));
// Inventory tracker
userConnection.put(new InventoryTracker(userConnection));
}
}

Datei anzeigen

@ -1,4 +1,4 @@
package us.myles.ViaVersion.armor;
package us.myles.ViaVersion.protocols.protocol1_9to1_8.listeners;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
@ -18,12 +18,15 @@ import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.inventory.CraftingInventory;
import us.myles.ViaVersion.ViaVersionPlugin;
import us.myles.ViaVersion.api.ViaVersion;
import us.myles.ViaVersion.packets.PacketType;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.protocols.base.ProtocolInfo;
import us.myles.ViaVersion.protocols.protocol1_9_1to1_9.Protocol1_9_1TO1_9;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.ArmorType;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9TO1_8;
import java.util.UUID;
import static us.myles.ViaVersion.util.PacketUtil.*;
@RequiredArgsConstructor
public class ArmorListener implements Listener {
@ -31,20 +34,27 @@ public class ArmorListener implements Listener {
private final ViaVersionPlugin plugin;
public static void sendArmorUpdate(Player player) {
int armor = ArmorType.calculateArmorPoints(player.getInventory().getArmorContents());
// Ensure that the player is on our pipe
UserConnection userConnection = ((ViaVersionPlugin)ViaVersion.getInstance()).getConnection(player);
if(userConnection == null) return;
if(!userConnection.get(ProtocolInfo.class).getPipeline().contains(Protocol1_9TO1_8.class)) return;
int armor = ArmorType.calculateArmorPoints(player.getInventory().getArmorContents());
try {
ByteBuf buf = Unpooled.buffer();
writeVarInt(PacketType.PLAY_ENTITY_PROPERTIES.getNewPacketID(), buf);
writeVarInt(player.getEntityId(), buf);
Type.VAR_INT.write(buf, 0x4B); // Entity Properties
Type.VAR_INT.write(buf, player.getEntityId());
buf.writeInt(1); // only 1 property
writeString("generic.armor", buf);
Type.STRING.write(buf, "generic.armor");
buf.writeDouble(0); //default 0 armor
writeVarInt(1, buf); // 1 modifier
writeUUID(ARMOR_ATTRIBUTE, buf); // armor modifier uuid
Type.VAR_INT.write(buf, 1); // 1 modifier
Type.UUID.write(buf, ARMOR_ATTRIBUTE); // armor modifier uuid
buf.writeDouble((double) armor); // the modifier value
buf.writeByte(0); // the modifier operation, 0 is add number
ViaVersion.getInstance().sendRawPacket(player, buf);
} catch (Exception ignored) {
}
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)

Datei anzeigen

@ -1,4 +1,4 @@
package us.myles.ViaVersion.listeners;
package us.myles.ViaVersion.protocols.protocol1_9to1_8.listeners;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufOutputStream;
@ -19,8 +19,13 @@ import org.bukkit.event.player.PlayerRespawnEvent;
import org.spacehq.opennbt.tag.builtin.ByteTag;
import org.spacehq.opennbt.tag.builtin.CompoundTag;
import us.myles.ViaVersion.ViaVersionPlugin;
import us.myles.ViaVersion.packets.PacketType;
import us.myles.ViaVersion.util.PacketUtil;
import us.myles.ViaVersion.api.ViaVersion;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.minecraft.Position;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.protocols.base.ProtocolInfo;
import us.myles.ViaVersion.protocols.protocol1_9_1to1_9.Protocol1_9_1TO1_9;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9TO1_8;
import us.myles.ViaVersion.util.ReflectionUtil;
import java.io.DataOutput;
@ -55,6 +60,11 @@ public class CommandBlockListener implements Listener {
@EventHandler(ignoreCancelled = true)
public void onInteract(PlayerInteractEvent e) {
if (e.getAction() == Action.RIGHT_CLICK_BLOCK && plugin.isPorted(e.getPlayer()) && e.getPlayer().isOp()) {
// Ensure that the player is on our pipe
UserConnection userConnection = ((ViaVersionPlugin)ViaVersion.getInstance()).getConnection(e.getPlayer());
if(userConnection == null) return;
if(!userConnection.get(ProtocolInfo.class).getPipeline().contains(Protocol1_9TO1_8.class)) return;
try {
sendCommandBlockPacket(e.getClickedBlock(), e.getPlayer());
} catch (Exception ex) {
@ -65,11 +75,19 @@ public class CommandBlockListener implements Listener {
private void sendOp(Player p) {
if (p.isOp() && plugin.isPorted(p)) {
// Ensure that the player is on our pipe
UserConnection userConnection = ((ViaVersionPlugin) ViaVersion.getInstance()).getConnection(p);
if(userConnection == null) return;
if(!userConnection.get(ProtocolInfo.class).getPipeline().contains(Protocol1_9TO1_8.class)) return;
try {
ByteBuf buf = Unpooled.buffer();
PacketUtil.writeVarInt(PacketType.PLAY_ENTITY_STATUS.getNewPacketID(), buf);
Type.VAR_INT.write(buf, 0x1B); // Entity Status
buf.writeInt(p.getEntityId());
buf.writeByte(26);
plugin.sendRawPacket(p, buf);
} catch (Exception ignored) {
}
}
}
@ -86,9 +104,9 @@ public class CommandBlockListener implements Listener {
private ByteBuf packetToByteBuf(Object updatePacket) throws Exception {
ByteBuf buf = Unpooled.buffer();
PacketUtil.writeVarInt(PacketType.PLAY_UPDATE_BLOCK_ENTITY.getNewPacketID(), buf); //Packet ID
Type.VAR_INT.write(buf, 0x09); //Block Entity Packet ID
long[] pos = getPosition(ReflectionUtil.get(updatePacket, "a", ReflectionUtil.nms("BlockPosition")));
PacketUtil.writeBlockPosition(buf, pos[0], pos[1], pos[2]); //Block position
Type.POSITION.write(buf, new Position(pos[0], pos[1], pos[2])); //Block position
buf.writeByte(2); //Action id always 2
CompoundTag nbt = getNBT(ReflectionUtil.get(updatePacket, "c", ReflectionUtil.nms("NBTTagCompound")));
if (nbt == null) {
@ -98,7 +116,7 @@ public class CommandBlockListener implements Listener {
nbt.put(new ByteTag("powered", (byte) 0));
nbt.put(new ByteTag("auto", (byte) 0));
nbt.put(new ByteTag("conditionMet", (byte) 0));
PacketUtil.writeNBT(buf, nbt); //NBT tag
Type.NBT.write(buf, nbt); //NBT tag
return buf;
}
@ -115,7 +133,7 @@ public class CommandBlockListener implements Listener {
Method m = ReflectionUtil.nms("NBTCompressedStreamTools").getMethod("a", ReflectionUtil.nms("NBTTagCompound"), DataOutput.class);
m.invoke(null, obj, new DataOutputStream(new ByteBufOutputStream(buf)));
try {
return PacketUtil.readNBT(buf);
return Type.NBT.read(buf);
} finally {
buf.release();
}

Datei anzeigen

@ -1,4 +1,4 @@
package us.myles.ViaVersion.metadata;
package us.myles.ViaVersion.protocols.protocol1_9to1_8.metadata;
import lombok.Getter;
import org.bukkit.entity.*;

Datei anzeigen

@ -1,17 +1,14 @@
package us.myles.ViaVersion2.api.protocol1_9to1_8.metadata;
package us.myles.ViaVersion.protocols.protocol1_9to1_8.metadata;
import org.bukkit.entity.EntityType;
import org.bukkit.util.EulerAngle;
import org.bukkit.util.Vector;
import us.myles.ViaVersion.ViaVersionPlugin;
import us.myles.ViaVersion.api.ViaVersion;
import us.myles.ViaVersion.metadata.MetaIndex;
import us.myles.ViaVersion.metadata.NewType;
import us.myles.ViaVersion.metadata.Type;
import us.myles.ViaVersion2.api.item.Item;
import us.myles.ViaVersion2.api.metadata.Metadata;
import us.myles.ViaVersion2.api.protocol1_9to1_8.ItemRewriter;
import us.myles.ViaVersion2.api.protocol1_9to1_8.Protocol1_9TO1_8;
import us.myles.ViaVersion.api.minecraft.item.Item;
import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.ItemRewriter;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9TO1_8;
import java.util.ArrayList;
import java.util.List;
@ -32,7 +29,7 @@ public class MetadataRewriter {
Object value = entry.getValue();
switch (metaIndex.getNewType()) {
case Byte:
entry.setType(us.myles.ViaVersion2.api.type.Type.BYTE);
entry.setType(us.myles.ViaVersion.api.type.Type.BYTE);
// convert from int, byte
if (metaIndex.getOldType() == Type.Byte) {
entry.setValue(value);
@ -48,12 +45,12 @@ public class MetadataRewriter {
}
int newIndex = MetaIndex.PLAYER_HAND.getNewIndex();
int typeID = MetaIndex.PLAYER_HAND.getNewType().getTypeID();
Metadata metadata = new Metadata(newIndex, typeID, us.myles.ViaVersion2.api.type.Type.BYTE, val);
Metadata metadata = new Metadata(newIndex, typeID, us.myles.ViaVersion.api.type.Type.BYTE, val);
list.add(metadata);
}
break;
case OptUUID:
entry.setType(us.myles.ViaVersion2.api.type.Type.OPTIONAL_UUID);
entry.setType(us.myles.ViaVersion.api.type.Type.OPTIONAL_UUID);
String owner = (String) value;
UUID toWrite = null;
if (owner.length() != 0) {
@ -65,7 +62,7 @@ public class MetadataRewriter {
entry.setValue(toWrite);
break;
case BlockID:
entry.setType(us.myles.ViaVersion2.api.type.Type.VAR_INT);
entry.setType(us.myles.ViaVersion.api.type.Type.VAR_INT);
// if we have both sources :))
if (metaIndex.getOldType() == Type.Byte) {
data = (Byte) value;
@ -83,7 +80,7 @@ public class MetadataRewriter {
}
break;
case VarInt:
entry.setType(us.myles.ViaVersion2.api.type.Type.VAR_INT);
entry.setType(us.myles.ViaVersion.api.type.Type.VAR_INT);
// convert from int, short, byte
if (metaIndex.getOldType() == Type.Byte) {
entry.setValue(((Byte) value).intValue());
@ -96,37 +93,37 @@ public class MetadataRewriter {
}
break;
case Float:
entry.setType(us.myles.ViaVersion2.api.type.Type.FLOAT);
entry.setType(us.myles.ViaVersion.api.type.Type.FLOAT);
entry.setValue(value);
break;
case String:
entry.setType(us.myles.ViaVersion2.api.type.Type.STRING);
entry.setType(us.myles.ViaVersion.api.type.Type.STRING);
entry.setValue(value);
break;
case Boolean:
entry.setType(us.myles.ViaVersion2.api.type.Type.BOOLEAN);
entry.setType(us.myles.ViaVersion.api.type.Type.BOOLEAN);
if (metaIndex == MetaIndex.AGEABLE_AGE)
entry.setValue((Byte) value < 0);
else
entry.setValue((Byte) value != 0);
break;
case Slot:
entry.setType(us.myles.ViaVersion2.api.type.Type.ITEM);
entry.setType(us.myles.ViaVersion.api.type.Type.ITEM);
entry.setValue(value);
ItemRewriter.toClient((Item) entry.getValue());
break;
case Position:
entry.setType(us.myles.ViaVersion2.api.type.Type.VECTOR);
entry.setType(us.myles.ViaVersion.api.type.Type.VECTOR);
Vector vector = (Vector) value;
entry.setValue(vector);
break;
case Vector3F:
entry.setType(us.myles.ViaVersion2.api.type.Type.ROTATION);
entry.setType(us.myles.ViaVersion.api.type.Type.ROTATION);
EulerAngle angle = (EulerAngle) value;
entry.setValue(angle);
break;
case Chat:
entry.setType(us.myles.ViaVersion2.api.type.Type.STRING);
entry.setType(us.myles.ViaVersion.api.type.Type.STRING);
value = Protocol1_9TO1_8.fixJson((String) value);
entry.setValue(value);
break;

Datei anzeigen

@ -1,8 +1,8 @@
package us.myles.ViaVersion2.api.protocol1_9to1_8.metadata;
package us.myles.ViaVersion.protocols.protocol1_9to1_8.metadata;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import us.myles.ViaVersion2.api.type.Type;
import us.myles.ViaVersion.api.type.Type;
@RequiredArgsConstructor
@Getter

Datei anzeigen

@ -1,4 +1,4 @@
package us.myles.ViaVersion.metadata;
package us.myles.ViaVersion.protocols.protocol1_9to1_8.metadata;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

Datei anzeigen

@ -1,4 +1,4 @@
package us.myles.ViaVersion.metadata;
package us.myles.ViaVersion.protocols.protocol1_9to1_8.metadata;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

Datei anzeigen

@ -1,21 +1,21 @@
package us.myles.ViaVersion2.api.protocol1_9to1_8.packets;
package us.myles.ViaVersion.protocols.protocol1_9to1_8.packets;
import org.bukkit.Material;
import us.myles.ViaVersion.ViaVersionPlugin;
import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.ViaVersion;
import us.myles.ViaVersion.api.minecraft.item.Item;
import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
import us.myles.ViaVersion.api.protocol.Protocol;
import us.myles.ViaVersion.api.remapper.PacketHandler;
import us.myles.ViaVersion.api.remapper.PacketRemapper;
import us.myles.ViaVersion.api.remapper.ValueTransformer;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.packets.State;
import us.myles.ViaVersion2.api.PacketWrapper;
import us.myles.ViaVersion2.api.item.Item;
import us.myles.ViaVersion2.api.metadata.Metadata;
import us.myles.ViaVersion2.api.protocol.Protocol;
import us.myles.ViaVersion2.api.protocol1_9to1_8.ItemRewriter;
import us.myles.ViaVersion2.api.protocol1_9to1_8.Protocol1_9TO1_8;
import us.myles.ViaVersion2.api.protocol1_9to1_8.metadata.MetadataRewriter;
import us.myles.ViaVersion2.api.protocol1_9to1_8.storage.EntityTracker;
import us.myles.ViaVersion2.api.remapper.PacketHandler;
import us.myles.ViaVersion2.api.remapper.PacketRemapper;
import us.myles.ViaVersion2.api.remapper.ValueTransformer;
import us.myles.ViaVersion2.api.type.Type;
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;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.EntityTracker;
import java.util.List;

Datei anzeigen

@ -1,17 +1,17 @@
package us.myles.ViaVersion2.api.protocol1_9to1_8.packets;
package us.myles.ViaVersion.protocols.protocol1_9to1_8.packets;
import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.minecraft.item.Item;
import us.myles.ViaVersion.api.protocol.Protocol;
import us.myles.ViaVersion.api.remapper.PacketHandler;
import us.myles.ViaVersion.api.remapper.PacketRemapper;
import us.myles.ViaVersion.api.remapper.ValueCreator;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.packets.State;
import us.myles.ViaVersion2.api.PacketWrapper;
import us.myles.ViaVersion2.api.item.Item;
import us.myles.ViaVersion2.api.protocol.Protocol;
import us.myles.ViaVersion2.api.protocol1_9to1_8.ItemRewriter;
import us.myles.ViaVersion2.api.protocol1_9to1_8.Protocol1_9TO1_8;
import us.myles.ViaVersion2.api.protocol1_9to1_8.storage.EntityTracker;
import us.myles.ViaVersion2.api.protocol1_9to1_8.storage.InventoryTracker;
import us.myles.ViaVersion2.api.remapper.PacketHandler;
import us.myles.ViaVersion2.api.remapper.PacketRemapper;
import us.myles.ViaVersion2.api.remapper.ValueCreator;
import us.myles.ViaVersion2.api.type.Type;
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.storage.EntityTracker;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.InventoryTracker;
public class InventoryPackets {
public static void register(Protocol protocol) {

Datei anzeigen

@ -1,21 +1,21 @@
package us.myles.ViaVersion2.api.protocol1_9to1_8.packets;
package us.myles.ViaVersion.protocols.protocol1_9to1_8.packets;
import org.bukkit.Material;
import org.bukkit.entity.EntityType;
import us.myles.ViaVersion.ViaVersionPlugin;
import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.ViaVersion;
import us.myles.ViaVersion.api.minecraft.item.Item;
import us.myles.ViaVersion.api.protocol.Protocol;
import us.myles.ViaVersion.protocols.base.ProtocolInfo;
import us.myles.ViaVersion.api.remapper.PacketHandler;
import us.myles.ViaVersion.api.remapper.PacketRemapper;
import us.myles.ViaVersion.api.remapper.ValueCreator;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.packets.State;
import us.myles.ViaVersion2.api.PacketWrapper;
import us.myles.ViaVersion2.api.item.Item;
import us.myles.ViaVersion2.api.protocol.Protocol;
import us.myles.ViaVersion2.api.protocol.base.ProtocolInfo;
import us.myles.ViaVersion2.api.protocol1_9to1_8.PlayerMovementMapper;
import us.myles.ViaVersion2.api.protocol1_9to1_8.Protocol1_9TO1_8;
import us.myles.ViaVersion2.api.protocol1_9to1_8.storage.EntityTracker;
import us.myles.ViaVersion2.api.remapper.PacketHandler;
import us.myles.ViaVersion2.api.remapper.PacketRemapper;
import us.myles.ViaVersion2.api.remapper.ValueCreator;
import us.myles.ViaVersion2.api.type.Type;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.PlayerMovementMapper;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9TO1_8;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.EntityTracker;
public class PlayerPackets {
public static void register(Protocol protocol) {
@ -239,6 +239,47 @@ public class PlayerPackets {
}
});
/* Removed packets */
// Map Bulk
protocol.registerOutgoing(State.PLAY, 0x26, 0x26, new PacketRemapper() {
@Override
public void registerMap() {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
wrapper.cancel();
}
});
}
});
// Update Entity NBT
protocol.registerOutgoing(State.PLAY, 0x49, 0x49, new PacketRemapper() {
@Override
public void registerMap() {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
wrapper.cancel();
}
});
}
});
// Set Compression
protocol.registerOutgoing(State.PLAY, 0x46, 0x46, new PacketRemapper() {
@Override
public void registerMap() {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
wrapper.cancel();
}
});
}
});
/* Packets which do not have any field remapping or handlers */
protocol.registerOutgoing(State.PLAY, 0x3A, 0x0E); // Tab Complete Response Packet
@ -420,6 +461,5 @@ public class PlayerPackets {
protocol.registerIncoming(State.PLAY, 0x06, 0x0D, new PlayerMovementMapper()); // Player Move & Look Packet
protocol.registerIncoming(State.PLAY, 0x05, 0x0E, new PlayerMovementMapper()); // Player Look Packet
protocol.registerIncoming(State.PLAY, 0x03, 0x0F, new PlayerMovementMapper()); // Player Packet
}
}

Datei anzeigen

@ -1,19 +1,19 @@
package us.myles.ViaVersion2.api.protocol1_9to1_8.packets;
package us.myles.ViaVersion.protocols.protocol1_9to1_8.packets;
import org.bukkit.entity.EntityType;
import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
import us.myles.ViaVersion.api.protocol.Protocol;
import us.myles.ViaVersion.api.remapper.PacketHandler;
import us.myles.ViaVersion.api.remapper.PacketRemapper;
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.protocol1_9to1_8.Protocol1_9TO1_8;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.metadata.MetadataRewriter;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.EntityTracker;
import us.myles.ViaVersion.util.EntityUtil;
import us.myles.ViaVersion2.api.PacketWrapper;
import us.myles.ViaVersion2.api.metadata.Metadata;
import us.myles.ViaVersion2.api.protocol.Protocol;
import us.myles.ViaVersion2.api.protocol1_9to1_8.Protocol1_9TO1_8;
import us.myles.ViaVersion2.api.protocol1_9to1_8.metadata.MetadataRewriter;
import us.myles.ViaVersion2.api.protocol1_9to1_8.storage.EntityTracker;
import us.myles.ViaVersion2.api.remapper.PacketHandler;
import us.myles.ViaVersion2.api.remapper.PacketRemapper;
import us.myles.ViaVersion2.api.remapper.ValueCreator;
import us.myles.ViaVersion2.api.remapper.ValueTransformer;
import us.myles.ViaVersion2.api.type.Type;
import java.util.List;

Datei anzeigen

@ -1,25 +1,23 @@
package us.myles.ViaVersion2.api.protocol1_9to1_8.packets;
package us.myles.ViaVersion.protocols.protocol1_9to1_8.packets;
import org.spacehq.opennbt.tag.builtin.CompoundTag;
import org.spacehq.opennbt.tag.builtin.StringTag;
import us.myles.ViaVersion.CancelException;
import us.myles.ViaVersion.ViaVersionPlugin;
import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.ViaVersion;
import us.myles.ViaVersion.chunks.Chunk;
import us.myles.ViaVersion.api.minecraft.chunks.Chunk;
import us.myles.ViaVersion.api.minecraft.item.Item;
import us.myles.ViaVersion.api.protocol.Protocol;
import us.myles.ViaVersion.api.remapper.PacketHandler;
import us.myles.ViaVersion.api.remapper.PacketRemapper;
import us.myles.ViaVersion.api.remapper.ValueCreator;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.packets.State;
import us.myles.ViaVersion.sounds.SoundEffect;
import us.myles.ViaVersion.util.PacketUtil;
import us.myles.ViaVersion2.api.PacketWrapper;
import us.myles.ViaVersion2.api.item.Item;
import us.myles.ViaVersion2.api.protocol.Protocol;
import us.myles.ViaVersion2.api.protocol1_9to1_8.Protocol1_9TO1_8;
import us.myles.ViaVersion2.api.protocol1_9to1_8.storage.ClientChunks;
import us.myles.ViaVersion2.api.protocol1_9to1_8.storage.EntityTracker;
import us.myles.ViaVersion2.api.protocol1_9to1_8.types.ChunkType;
import us.myles.ViaVersion2.api.remapper.PacketHandler;
import us.myles.ViaVersion2.api.remapper.PacketRemapper;
import us.myles.ViaVersion2.api.remapper.ValueCreator;
import us.myles.ViaVersion2.api.type.Type;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9TO1_8;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.sounds.SoundEffect;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.ClientChunks;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.EntityTracker;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.types.ChunkType;
public class WorldPackets {
public static void register(Protocol protocol) {

Datei anzeigen

@ -1,4 +1,4 @@
package us.myles.ViaVersion.sounds;
package us.myles.ViaVersion.protocols.protocol1_9to1_8.sounds;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

Datei anzeigen

@ -1,4 +1,4 @@
package us.myles.ViaVersion.sounds;
package us.myles.ViaVersion.protocols.protocol1_9to1_8.sounds;
import lombok.Getter;

Datei anzeigen

@ -1,12 +1,12 @@
package us.myles.ViaVersion2.api.protocol1_9to1_8.storage;
package us.myles.ViaVersion.protocols.protocol1_9to1_8.storage;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import lombok.Getter;
import org.bukkit.Bukkit;
import us.myles.ViaVersion.api.data.StoredObject;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.util.ReflectionUtil;
import us.myles.ViaVersion2.api.data.StoredObject;
import us.myles.ViaVersion2.api.data.UserConnection;
import java.util.List;
import java.util.Set;
@ -14,8 +14,6 @@ import java.util.logging.Level;
@Getter
public class ClientChunks extends StoredObject {
private final Set<Long> loadedChunks = Sets.newConcurrentHashSet();
private final Set<Long> bulkChunks = Sets.newConcurrentHashSet();
// Reflection
private static ReflectionUtil.ClassReflection mapChunkBulkRef;
private static ReflectionUtil.ClassReflection mapChunkRef;
@ -29,10 +27,17 @@ public class ClientChunks extends StoredObject {
}
}
private final Set<Long> loadedChunks = Sets.newConcurrentHashSet();
private final Set<Long> bulkChunks = Sets.newConcurrentHashSet();
public ClientChunks(UserConnection user) {
super(user);
}
private static long toLong(int msw, int lsw) {
return ((long) msw << 32) + lsw - -2147483648L;
}
public List<Object> transformMapChunkBulk(Object packet) {
List<Object> list = Lists.newArrayList();
try {
@ -56,9 +61,4 @@ public class ClientChunks extends StoredObject {
}
return list;
}
private static long toLong(int msw, int lsw) {
return ((long) msw << 32) + lsw - -2147483648L;
}
}

Datei anzeigen

@ -1,4 +1,4 @@
package us.myles.ViaVersion2.api.protocol1_9to1_8.storage;
package us.myles.ViaVersion.protocols.protocol1_9to1_8.storage;
import io.netty.buffer.ByteBuf;
import lombok.Getter;
@ -7,18 +7,17 @@ import org.bukkit.Bukkit;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import us.myles.ViaVersion.ViaVersionPlugin;
import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.ViaVersion;
import us.myles.ViaVersion.api.boss.BossBar;
import us.myles.ViaVersion.api.boss.BossColor;
import us.myles.ViaVersion.api.boss.BossStyle;
import us.myles.ViaVersion.util.PacketUtil;
import us.myles.ViaVersion2.api.PacketWrapper;
import us.myles.ViaVersion2.api.data.StoredObject;
import us.myles.ViaVersion2.api.data.UserConnection;
import us.myles.ViaVersion2.api.item.Item;
import us.myles.ViaVersion2.api.metadata.Metadata;
import us.myles.ViaVersion2.api.protocol.base.ProtocolInfo;
import us.myles.ViaVersion2.api.type.Type;
import us.myles.ViaVersion.api.data.StoredObject;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.minecraft.item.Item;
import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
import us.myles.ViaVersion.protocols.base.ProtocolInfo;
import us.myles.ViaVersion.api.type.Type;
import java.util.*;
@ -119,15 +118,18 @@ public class EntityTracker extends StoredObject {
if ((data & 0x20) == 0x20) {
if (!knownHolograms.contains(entityID)) {
knownHolograms.add(entityID);
try {
// Send movement
ByteBuf buf = getUser().getChannel().alloc().buffer();
PacketUtil.writeVarInt(0x25, buf); // Relative Move Packet
PacketUtil.writeVarInt(entityID, buf);
Type.VAR_INT.write(buf, 0x25); // Relative Move Packet
Type.VAR_INT.write(buf, entityID);
buf.writeShort(0);
buf.writeShort((short) (128D * (((ViaVersionPlugin) ViaVersion.getInstance()).getHologramYOffset() * 32D)));
buf.writeShort(0);
buf.writeBoolean(true);
getUser().sendRawPacket(buf, false);
} catch (Exception ignored) {
}
}
}
}

Datei anzeigen

@ -1,9 +1,9 @@
package us.myles.ViaVersion2.api.protocol1_9to1_8.storage;
package us.myles.ViaVersion.protocols.protocol1_9to1_8.storage;
import lombok.Getter;
import lombok.Setter;
import us.myles.ViaVersion2.api.data.StoredObject;
import us.myles.ViaVersion2.api.data.UserConnection;
import us.myles.ViaVersion.api.data.StoredObject;
import us.myles.ViaVersion.api.data.UserConnection;
@Getter
@Setter

Datei anzeigen

@ -1,8 +1,8 @@
package us.myles.ViaVersion2.api.protocol1_9to1_8.storage;
package us.myles.ViaVersion.protocols.protocol1_9to1_8.storage;
import lombok.Getter;
import us.myles.ViaVersion2.api.data.StoredObject;
import us.myles.ViaVersion2.api.data.UserConnection;
import us.myles.ViaVersion.api.data.StoredObject;
import us.myles.ViaVersion.api.data.UserConnection;
public class MovementTracker extends StoredObject {
private static final long IDLE_PACKET_DELAY = 50L; // Update every 50ms (20tps)

Datei anzeigen

@ -1,13 +1,13 @@
package us.myles.ViaVersion2.api.protocol1_9to1_8.types;
package us.myles.ViaVersion.protocols.protocol1_9to1_8.types;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import org.bukkit.Bukkit;
import us.myles.ViaVersion.chunks.Chunk;
import us.myles.ViaVersion.chunks.ChunkSection;
import us.myles.ViaVersion.util.PacketUtil;
import us.myles.ViaVersion2.api.protocol1_9to1_8.storage.ClientChunks;
import us.myles.ViaVersion2.api.type.PartialType;
import us.myles.ViaVersion.api.minecraft.chunks.Chunk;
import us.myles.ViaVersion.api.minecraft.chunks.ChunkSection;
import us.myles.ViaVersion.api.type.PartialType;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.ClientChunks;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
@ -33,14 +33,18 @@ public class ChunkType extends PartialType<Chunk, ClientChunks> {
super(chunks, Chunk.class);
}
private static long toLong(int msw, int lsw) {
return ((long) msw << 32) + lsw - -2147483648L;
}
@Override
public Chunk read(ByteBuf input, ClientChunks param) {
public Chunk read(ByteBuf input, ClientChunks param) throws Exception {
int chunkX = input.readInt();
int chunkZ = input.readInt();
long chunkHash = toLong(chunkX, chunkZ);
boolean groundUp = input.readByte() != 0;
int bitmask = input.readUnsignedShort();
int dataLength = PacketUtil.readVarInt(input);
int dataLength = Type.VAR_INT.read(input);
// Data to be read
BitSet usedSections = new BitSet(16);
@ -123,10 +127,10 @@ public class ChunkType extends PartialType<Chunk, ClientChunks> {
}
@Override
public void write(ByteBuf output, ClientChunks param, Chunk chunk) {
public void write(ByteBuf output, ClientChunks param, Chunk chunk) throws Exception {
if (chunk.isUnloadPacket()) {
output.clear();
PacketUtil.writeVarInt(0x1D, output); // Unload packet ID
Type.VAR_INT.write(output, 0x1D); // Unload packet ID
}
// Write primary info
@ -134,7 +138,7 @@ public class ChunkType extends PartialType<Chunk, ClientChunks> {
output.writeInt(chunk.getZ());
if (chunk.isUnloadPacket()) return;
output.writeByte(chunk.isGroundUp() ? 0x01 : 0x00);
PacketUtil.writeVarInt(chunk.getPrimaryBitmask(), output);
Type.VAR_INT.write(output, chunk.getPrimaryBitmask());
ByteBuf buf = Unpooled.buffer();
for (int i = 0; i < SECTION_COUNT; i++) {
@ -146,7 +150,7 @@ public class ChunkType extends PartialType<Chunk, ClientChunks> {
section.writeSkyLight(buf);
}
buf.readerIndex(0);
PacketUtil.writeVarInt(buf.readableBytes() + (chunk.hasBiomeData() ? 256 : 0), output);
Type.VAR_INT.write(output, buf.readableBytes() + (chunk.hasBiomeData() ? 256 : 0));
output.writeBytes(buf);
buf.release(); // release buffer
@ -155,8 +159,4 @@ public class ChunkType extends PartialType<Chunk, ClientChunks> {
output.writeBytes(chunk.getBiomeData());
}
}
private static long toLong(int msw, int lsw) {
return ((long) msw << 32) + lsw - -2147483648L;
}
}

Datei anzeigen

@ -1,9 +1,9 @@
package us.myles.ViaVersion2.api.protocol1_9to1_8.types;
package us.myles.ViaVersion.protocols.protocol1_9to1_8.types;
import io.netty.buffer.ByteBuf;
import us.myles.ViaVersion2.api.metadata.Metadata;
import us.myles.ViaVersion2.api.protocol1_9to1_8.Protocol1_9TO1_8;
import us.myles.ViaVersion2.api.type.Type;
import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9TO1_8;
import java.util.ArrayList;
import java.util.List;

Datei anzeigen

@ -1,10 +1,10 @@
package us.myles.ViaVersion2.api.protocol1_9to1_8.types;
package us.myles.ViaVersion.protocols.protocol1_9to1_8.types;
import io.netty.buffer.ByteBuf;
import us.myles.ViaVersion2.api.metadata.Metadata;
import us.myles.ViaVersion2.api.protocol1_9to1_8.metadata.MetadataTypes;
import us.myles.ViaVersion2.api.type.Type;
import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.metadata.MetadataTypes;
public class MetadataType extends Type<Metadata> {

Datei anzeigen

@ -20,11 +20,10 @@ import java.util.UUID;
public class UpdateUtil {
public final static String PREFIX = ChatColor.GREEN + "" + ChatColor.BOLD + "[ViaVersion] " + ChatColor.GREEN;
private final static String URL = "http://api.spiget.org/v1/resources/";
private final static int PLUGIN = 19254;
public final static String PREFIX = ChatColor.GREEN + "" + ChatColor.BOLD + "[ViaVersion] " + ChatColor.GREEN;
public static void sendUpdateMessage(final UUID uuid, final Plugin plugin) {
new BukkitRunnable() {

Datei anzeigen

@ -17,9 +17,9 @@ import java.util.logging.Level;
import java.util.regex.Pattern;
public class Configuration extends YamlConfiguration {
private List<String> mainHeader = Lists.newArrayList();
private final Map<String, List<String>> headers = Maps.newConcurrentMap();
private final File file;
private List<String> mainHeader = Lists.newArrayList();
private boolean loadHeaders;
public Configuration(File file) {
@ -212,7 +212,7 @@ public class Configuration extends YamlConfiguration {
if (writer != null) {
try {
writer.close();
} catch(IOException e) {
} catch (IOException ignored) {
}
}
}

Datei anzeigen

@ -1,294 +0,0 @@
package us.myles.ViaVersion.util;
import com.google.common.base.Charsets;
import com.google.common.base.Preconditions;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufInputStream;
import io.netty.buffer.ByteBufOutputStream;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageDecoder;
import io.netty.handler.codec.MessageToByteEncoder;
import org.spacehq.opennbt.NBTIO;
import org.spacehq.opennbt.tag.builtin.CompoundTag;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
public class PacketUtil {
private static Method DECODE_METHOD;
private static Method ENCODE_METHOD;
static {
try {
DECODE_METHOD = ByteToMessageDecoder.class.getDeclaredMethod("decode", ChannelHandlerContext.class, ByteBuf.class, List.class);
DECODE_METHOD.setAccessible(true);
} catch (NoSuchMethodException e) {
e.printStackTrace();
System.out.println("Netty issue?");
}
try {
ENCODE_METHOD = MessageToByteEncoder.class.getDeclaredMethod("encode", ChannelHandlerContext.class, Object.class, ByteBuf.class);
ENCODE_METHOD.setAccessible(true);
} catch (NoSuchMethodException e) {
e.printStackTrace();
System.out.println("Netty issue?");
}
}
public static CompoundTag readNBT(ByteBuf input) throws IOException {
// Default client is limited to 2097152 bytes. (2.09mb)
Preconditions.checkArgument(input.readableBytes() <= 2097152, "Cannot read NBT (got %s bytes)", input.readableBytes());
int readerIndex = input.readerIndex();
byte b = input.readByte();
if (b == 0) {
return null;
} else {
input.readerIndex(readerIndex);
ByteBufInputStream bytebufStream = new ByteBufInputStream(input);
DataInputStream dataInputStream = new DataInputStream(bytebufStream);
try {
return (CompoundTag) NBTIO.readTag(dataInputStream);
} finally {
dataInputStream.close();
}
}
}
public static void writeNBT(ByteBuf output, CompoundTag tag) throws IOException {
if (tag == null) {
output.writeByte(0);
} else {
ByteBufOutputStream bytebufStream = new ByteBufOutputStream(output);
DataOutputStream dataOutputStream = new DataOutputStream(bytebufStream);
NBTIO.writeTag(dataOutputStream, tag);
dataOutputStream.close();
}
}
public static List<Object> callDecode(ByteToMessageDecoder decoder, ChannelHandlerContext ctx, Object input) throws InvocationTargetException {
List<Object> output = new ArrayList<>();
try {
PacketUtil.DECODE_METHOD.invoke(decoder, ctx, input, output);
} catch (IllegalAccessException e) {
e.printStackTrace();
}
return output;
}
public static void callEncode(MessageToByteEncoder encoder, ChannelHandlerContext ctx, Object msg, ByteBuf output) throws InvocationTargetException {
try {
PacketUtil.ENCODE_METHOD.invoke(encoder, ctx, msg, output);
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
/* I take no credit, these are taken from BungeeCord */
// https://github.com/SpigotMC/BungeeCord/blob/master/protocol/src/main/java/net/md_5/bungee/protocol/DefinedPacket.java
public static void writeString(String s, ByteBuf buf) {
Preconditions.checkArgument(s.length() <= Short.MAX_VALUE, "Cannot send string longer than Short.MAX_VALUE (got %s characters)", s.length());
byte[] b = s.getBytes(Charsets.UTF_8);
writeVarInt(b.length, buf);
buf.writeBytes(b);
}
public static String readString(ByteBuf buf) {
int len = readVarInt(buf);
Preconditions.checkArgument(len <= Short.MAX_VALUE, "Cannot receive string longer than Short.MAX_VALUE (got %s characters)", len);
byte[] b = new byte[len];
buf.readBytes(b);
return new String(b, Charsets.UTF_8);
}
public static void writeArrayLegacy(byte[] b, ByteBuf buf, boolean allowExtended) {
// (Integer.MAX_VALUE & 0x1FFF9A ) = 2097050 - Forge's current upper limit
if (allowExtended) {
Preconditions.checkArgument(b.length <= (Integer.MAX_VALUE & 0x1FFF9A), "Cannot send array longer than 2097050 (got %s bytes)", b.length);
} else {
Preconditions.checkArgument(b.length <= Short.MAX_VALUE, "Cannot send array longer than Short.MAX_VALUE (got %s bytes)", b.length);
}
// Write a 2 or 3 byte number that represents the length of the packet. (3 byte "shorts" for Forge only)
// No vanilla packet should give a 3 byte packet, this method will still retain vanilla behaviour.
writeVarShort(buf, b.length);
buf.writeBytes(b);
}
public static byte[] readArrayLegacy(ByteBuf buf) {
// Read in a 2 or 3 byte number that represents the length of the packet. (3 byte "shorts" for Forge only)
// No vanilla packet should give a 3 byte packet, this method will still retain vanilla behaviour.
int len = readVarShort(buf);
// (Integer.MAX_VALUE & 0x1FFF9A ) = 2097050 - Forge's current upper limit
Preconditions.checkArgument(len <= (Integer.MAX_VALUE & 0x1FFF9A), "Cannot receive array longer than 2097050 (got %s bytes)", len);
byte[] ret = new byte[len];
buf.readBytes(ret);
return ret;
}
public static void writeArray(byte[] b, ByteBuf buf) {
writeVarInt(b.length, buf);
buf.writeBytes(b);
}
public static byte[] readArray(ByteBuf buf) {
byte[] ret = new byte[readVarInt(buf)];
buf.readBytes(ret);
return ret;
}
public static void writeStringArray(List<String> s, ByteBuf buf) {
writeVarInt(s.size(), buf);
for (String str : s) {
writeString(str, buf);
}
}
public static List<String> readStringArray(ByteBuf buf) {
int len = readVarInt(buf);
List<String> ret = new ArrayList<>(len);
for (int i = 0; i < len; i++) {
ret.add(readString(buf));
}
return ret;
}
public static int readVarInt(ByteBuf input) {
return readVarInt(input, 5);
}
public static int readVarInt(ByteBuf input, int maxBytes) {
int out = 0;
int bytes = 0;
byte in;
while (true) {
in = input.readByte();
out |= (in & 0x7F) << (bytes++ * 7);
if (bytes > maxBytes) {
throw new RuntimeException("VarInt too big");
}
if ((in & 0x80) != 0x80) {
break;
}
}
return out;
}
public static void writeVarInt(int value, ByteBuf output) {
int part;
while (true) {
part = value & 0x7F;
value >>>= 7;
if (value != 0) {
part |= 0x80;
}
output.writeByte(part);
if (value == 0) {
break;
}
}
}
public static void writeVarIntArray(List<Integer> integers, ByteBuf output) {
writeVarInt(integers.size(), output);
for (Integer i : integers) {
writeVarInt(i, output);
}
}
public static int readVarShort(ByteBuf buf) {
int low = buf.readUnsignedShort();
int high = 0;
if ((low & 0x8000) != 0) {
low = low & 0x7FFF;
high = buf.readUnsignedByte();
}
return ((high & 0xFF) << 15) | low;
}
public static void writeVarShort(ByteBuf buf, int toWrite) {
int low = toWrite & 0x7FFF;
int high = (toWrite & 0x7F8000) >> 15;
if (high != 0) {
low = low | 0x8000;
}
buf.writeShort(low);
if (high != 0) {
buf.writeByte(high);
}
}
public static void writeUUID(UUID value, ByteBuf output) {
output.writeLong(value.getMostSignificantBits());
output.writeLong(value.getLeastSignificantBits());
}
public static UUID readUUID(ByteBuf input) {
return new UUID(input.readLong(), input.readLong());
}
public static void writeLongs(long[] data, ByteBuf output) {
for (long aData : data) {
output.writeLong(aData);
}
}
public static long[] readLongs(int amount, ByteBuf output) {
long data[] = new long[amount];
for (int index = 0; index < amount; index++) {
data[index] = output.readLong();
}
return data;
}
public static long[] readBlockPosition(ByteBuf buf) {
long val = buf.readLong();
long x = (val >> 38); // signed
long y = (val >> 26) & 0xfff; // unsigned
// this shifting madness is used to preserve sign
long z = (val << 38) >> 38; // signed
return new long[]{x, y, z};
}
public static void writeBlockPosition(ByteBuf buf, long x, long y, long z) {
buf.writeLong(((x & 0x3ffffff) << 38) | ((y & 0xfff) << 26) | (z & 0x3ffffff));
}
public static int[] readVarInts(int amount, ByteBuf input) {
int data[] = new int[amount];
for (int index = 0; index < amount; index++) {
data[index] = PacketUtil.readVarInt(input);
}
return data;
}
public static boolean containsCause(Throwable t, Class<? extends Throwable> c) {
while (t != null) {
t = t.getCause();
if (t != null)
if (c.isAssignableFrom(t.getClass())) return true;
}
return false;
}
}

Datei anzeigen

@ -0,0 +1,60 @@
package us.myles.ViaVersion.util;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageDecoder;
import io.netty.handler.codec.MessageToByteEncoder;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
public class PipelineUtil {
private static Method DECODE_METHOD;
private static Method ENCODE_METHOD;
static {
try {
DECODE_METHOD = ByteToMessageDecoder.class.getDeclaredMethod("decode", ChannelHandlerContext.class, ByteBuf.class, List.class);
DECODE_METHOD.setAccessible(true);
} catch (NoSuchMethodException e) {
e.printStackTrace();
System.out.println("Netty issue?");
}
try {
ENCODE_METHOD = MessageToByteEncoder.class.getDeclaredMethod("encode", ChannelHandlerContext.class, Object.class, ByteBuf.class);
ENCODE_METHOD.setAccessible(true);
} catch (NoSuchMethodException e) {
e.printStackTrace();
System.out.println("Netty issue?");
}
}
public static List<Object> callDecode(ByteToMessageDecoder decoder, ChannelHandlerContext ctx, Object input) throws InvocationTargetException {
List<Object> output = new ArrayList<>();
try {
PipelineUtil.DECODE_METHOD.invoke(decoder, ctx, input, output);
} catch (IllegalAccessException e) {
e.printStackTrace();
}
return output;
}
public static void callEncode(MessageToByteEncoder encoder, ChannelHandlerContext ctx, Object msg, ByteBuf output) throws InvocationTargetException {
try {
PipelineUtil.ENCODE_METHOD.invoke(encoder, ctx, msg, output);
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
public static boolean containsCause(Throwable t, Class<? extends Throwable> c) {
while (t != null) {
t = t.getCause();
if (t != null)
if (c.isAssignableFrom(t.getClass())) return true;
}
return false;
}
}

Datei anzeigen

@ -17,6 +17,7 @@ public class ReflectionUtil {
public static Class<?> nms(String className) throws ClassNotFoundException {
return Class.forName(NMS + "." + className);
}
public static Class<?> obc(String className) throws ClassNotFoundException {
return Class.forName(BASE + "." + className);
}

Datei anzeigen

@ -1,8 +0,0 @@
package us.myles.ViaVersion2.api.remapper;
import io.netty.buffer.ByteBuf;
import us.myles.ViaVersion2.api.PacketWrapper;
public interface ValueReader<T> {
public T read(PacketWrapper wrapper) throws Exception;
}

Datei anzeigen

@ -1,7 +0,0 @@
package us.myles.ViaVersion2.api.remapper;
import us.myles.ViaVersion2.api.PacketWrapper;
public interface ValueWriter<T> {
public void write(PacketWrapper writer, T inputValue) throws Exception;
}

Datei anzeigen

@ -1,7 +0,0 @@
package us.myles.ViaVersion2.api.type;
import io.netty.buffer.ByteBuf;
public interface ByteBufReader<T> {
public T read(ByteBuf buffer) throws Exception;
}

Datei anzeigen

@ -1,7 +0,0 @@
package us.myles.ViaVersion2.api.type;
import io.netty.buffer.ByteBuf;
public interface ByteBufWriter<T> {
public void write(ByteBuf buffer, T object) throws Exception;
}

Datei anzeigen

@ -1,5 +0,0 @@
package us.myles.ViaVersion2.api.type;
public interface TypeConverter<T> {
public T from(Object o);
}