Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-11-08 17:20:24 +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:
Ursprung
69e8ddcbf6
Commit
8a35c0235e
@ -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;
|
||||
@ -19,15 +19,15 @@ public class ViaIdleThread extends BukkitRunnable {
|
||||
this.portedPlayers = portedPlayers;
|
||||
try {
|
||||
this.idlePacketClass = ReflectionUtil.nms("PacketPlayInFlying");
|
||||
} catch(ClassNotFoundException e) {
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new RuntimeException("Couldn't find player idle packet, help!", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
for(UserConnection info : portedPlayers.values()) {
|
||||
if(info.get(ProtocolInfo.class).getPipeline().contains(Protocol1_9TO1_8.class)) {
|
||||
for (UserConnection info : portedPlayers.values()) {
|
||||
if (info.get(ProtocolInfo.class).getPipeline().contains(Protocol1_9TO1_8.class)) {
|
||||
long nextIdleUpdate = info.get(MovementTracker.class).getNextIdlePacket();
|
||||
if (nextIdleUpdate <= System.currentTimeMillis()) {
|
||||
try {
|
||||
|
@ -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);
|
||||
}
|
||||
@ -292,8 +300,8 @@ public class ViaVersionPlugin extends JavaPlugin implements ViaVersionAPI {
|
||||
return getConfig().getBoolean("prevent-collision", true);
|
||||
}
|
||||
|
||||
public boolean isNewEffectIndicator(){
|
||||
return getConfig().getBoolean("use-new-effect-indicator",true);
|
||||
public boolean isNewEffectIndicator() {
|
||||
return getConfig().getBoolean("use-new-effect-indicator", true);
|
||||
}
|
||||
|
||||
public boolean isSuppressMetadataErrors() {
|
||||
@ -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) {
|
||||
|
@ -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;
|
||||
@ -60,7 +59,7 @@ public class PacketWrapper {
|
||||
}
|
||||
|
||||
public <T> T read(Type<T> type) throws Exception {
|
||||
if(type == Type.NOTHING) return null;
|
||||
if (type == Type.NOTHING) return null;
|
||||
if (readableObjects.isEmpty()) {
|
||||
Preconditions.checkNotNull(inputBuffer, "This packet does not have an input buffer.");
|
||||
// We could in the future log input read values, but honestly for things like bulk maps, mem waste D:
|
@ -1,4 +1,4 @@
|
||||
package us.myles.ViaVersion2.api.util;
|
||||
package us.myles.ViaVersion.api;
|
||||
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
@ -13,7 +13,7 @@ public class Pair<X, Y> {
|
||||
private X key;
|
||||
private Y value;
|
||||
|
||||
public Pair(X key, Y value){
|
||||
public Pair(X key, Y value) {
|
||||
this.key = key;
|
||||
this.value = value;
|
||||
}
|
@ -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)
|
||||
*/
|
||||
|
@ -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.
|
||||
*
|
||||
|
@ -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 {
|
@ -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;
|
||||
|
@ -1,4 +1,4 @@
|
||||
package us.myles.ViaVersion2.api.util;
|
||||
package us.myles.ViaVersion.api.minecraft;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
@ -1,4 +1,4 @@
|
||||
package us.myles.ViaVersion.chunks;
|
||||
package us.myles.ViaVersion.api.minecraft.chunks;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
@ -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;
|
||||
@ -40,7 +38,7 @@ public class ChunkSection {
|
||||
public void setBlock(int idx, int type, int data) {
|
||||
int hash = type << 4 | (data & 0xF);
|
||||
int index = palette.indexOf(hash);
|
||||
if(index == -1) {
|
||||
if (index == -1) {
|
||||
index = palette.size();
|
||||
palette.add(hash);
|
||||
}
|
||||
@ -53,7 +51,7 @@ public class ChunkSection {
|
||||
}
|
||||
|
||||
public void setSkyLight(byte[] data) {
|
||||
if(data.length != LIGHT_LENGTH) throw new IllegalArgumentException("Data length != " + LIGHT_LENGTH);
|
||||
if (data.length != LIGHT_LENGTH) throw new IllegalArgumentException("Data length != " + LIGHT_LENGTH);
|
||||
this.skyLight = new NibbleArray(data);
|
||||
}
|
||||
|
||||
@ -61,37 +59,39 @@ 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) {
|
||||
while (palette.size() > 1 << bitsPerBlock) {
|
||||
bitsPerBlock += 1;
|
||||
}
|
||||
long maxEntryValue = (1L << bitsPerBlock) - 1;
|
||||
output.writeByte(bitsPerBlock);
|
||||
|
||||
// Write pallet (or not)
|
||||
PacketUtil.writeVarInt(palette.size(), output);
|
||||
for(int mappedId : palette) {
|
||||
PacketUtil.writeVarInt(mappedId, output);
|
||||
Type.VAR_INT.write(output, palette.size());
|
||||
for (int mappedId : palette) {
|
||||
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++) {
|
||||
for (int index = 0; index < blocks.length; index++) {
|
||||
int value = blocks[index];
|
||||
int bitIndex = index * bitsPerBlock;
|
||||
int startIndex = bitIndex / 64;
|
||||
int endIndex = ((index + 1) * bitsPerBlock - 1) / 64;
|
||||
int startBitSubIndex = bitIndex % 64;
|
||||
data[startIndex] = data[startIndex] & ~(maxEntryValue << startBitSubIndex) | ((long) value & maxEntryValue) << startBitSubIndex;
|
||||
if(startIndex != endIndex) {
|
||||
if (startIndex != endIndex) {
|
||||
int endBitSubIndex = 64 - startBitSubIndex;
|
||||
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,19 +122,19 @@ 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) {
|
||||
for (int mappedId : palette) {
|
||||
bytes += countBytes(mappedId);
|
||||
}
|
||||
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();
|
@ -1,4 +1,4 @@
|
||||
package us.myles.ViaVersion.chunks;
|
||||
package us.myles.ViaVersion.api.minecraft.chunks;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
@ -6,7 +6,7 @@ public class NibbleArray {
|
||||
private final byte[] handle;
|
||||
|
||||
public NibbleArray(int length) {
|
||||
if(length == 0 || length % 2 != 0) {
|
||||
if (length == 0 || length % 2 != 0) {
|
||||
throw new IllegalArgumentException("Length of nibble array must be a positive number dividable by 2!");
|
||||
}
|
||||
|
||||
@ -14,7 +14,7 @@ public class NibbleArray {
|
||||
}
|
||||
|
||||
public NibbleArray(byte[] handle) {
|
||||
if(handle.length == 0 || handle.length % 2 != 0) {
|
||||
if (handle.length == 0 || handle.length % 2 != 0) {
|
||||
throw new IllegalArgumentException("Length of nibble array must be a positive number dividable by 2!");
|
||||
}
|
||||
|
||||
@ -27,7 +27,7 @@ public class NibbleArray {
|
||||
|
||||
public byte get(int index) {
|
||||
byte value = handle[index / 2];
|
||||
if(index % 2 == 0) {
|
||||
if (index % 2 == 0) {
|
||||
return (byte) (value & 0xF);
|
||||
} else {
|
||||
return (byte) ((value >> 4) & 0xF);
|
||||
@ -40,7 +40,7 @@ public class NibbleArray {
|
||||
|
||||
public void set(int index, int value) {
|
||||
index /= 2;
|
||||
if(index % 2 == 0) {
|
||||
if (index % 2 == 0) {
|
||||
handle[index] = (byte) (handle[index] & 0xF0 | value & 0xF);
|
||||
} else {
|
||||
handle[index] = (byte) (handle[index] & 0xF | (value & 0xF) << 4);
|
||||
@ -60,15 +60,15 @@ 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) {
|
||||
if (handle.length != this.handle.length) {
|
||||
throw new IllegalArgumentException("Length of handle must equal to size of nibble array!");
|
||||
}
|
||||
|
||||
System.arraycopy(handle, 0, this.handle, 0, handle.length);
|
||||
}
|
||||
|
||||
public byte[] getHandle() {
|
||||
return handle;
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package us.myles.ViaVersion2.api.item;
|
||||
package us.myles.ViaVersion.api.minecraft.item;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
@ -18,7 +18,7 @@ public class Item {
|
||||
private CompoundTag tag;
|
||||
|
||||
public static Item getItem(ItemStack stack) {
|
||||
if(stack == null) return null;
|
||||
if (stack == null) return null;
|
||||
return new Item((short) stack.getTypeId(), (byte) stack.getAmount(), stack.getDurability(), null);
|
||||
}
|
||||
}
|
@ -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
|
@ -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;
|
@ -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;
|
@ -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) {
|
@ -1,4 +1,4 @@
|
||||
package us.myles.ViaVersion2.api.protocol;
|
||||
package us.myles.ViaVersion.api.protocol;
|
||||
|
||||
public class ProtocolVersion {
|
||||
/* Defined protocol constants */
|
@ -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;
|
@ -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;
|
||||
@ -41,7 +41,7 @@ public abstract class PacketRemapper {
|
||||
|
||||
public abstract void registerMap();
|
||||
|
||||
public void remap(PacketWrapper packetWrapper) throws Exception{
|
||||
public void remap(PacketWrapper packetWrapper) throws Exception {
|
||||
// Read all the current values
|
||||
for (Pair<ValueReader, ValueWriter> valueRemapper : valueRemappers) {
|
||||
Object object = valueRemapper.getKey().read(packetWrapper);
|
@ -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;
|
@ -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;
|
7
src/main/java/us/myles/ViaVersion/api/remapper/ValueReader.java
Normale Datei
7
src/main/java/us/myles/ViaVersion/api/remapper/ValueReader.java
Normale Datei
@ -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;
|
||||
}
|
@ -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;
|
7
src/main/java/us/myles/ViaVersion/api/remapper/ValueWriter.java
Normale Datei
7
src/main/java/us/myles/ViaVersion/api/remapper/ValueWriter.java
Normale Datei
@ -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;
|
||||
}
|
7
src/main/java/us/myles/ViaVersion/api/type/ByteBufReader.java
Normale Datei
7
src/main/java/us/myles/ViaVersion/api/type/ByteBufReader.java
Normale Datei
@ -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;
|
||||
}
|
7
src/main/java/us/myles/ViaVersion/api/type/ByteBufWriter.java
Normale Datei
7
src/main/java/us/myles/ViaVersion/api/type/ByteBufWriter.java
Normale Datei
@ -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;
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
@ -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;
|
||||
|
5
src/main/java/us/myles/ViaVersion/api/type/TypeConverter.java
Normale Datei
5
src/main/java/us/myles/ViaVersion/api/type/TypeConverter.java
Normale Datei
@ -0,0 +1,5 @@
|
||||
package us.myles.ViaVersion.api.type;
|
||||
|
||||
public interface TypeConverter<T> {
|
||||
T from(Object o);
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,10 +1,10 @@
|
||||
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 class BooleanType extends Type<Boolean> implements TypeConverter<Boolean> {
|
||||
public BooleanType() {
|
||||
super(Boolean.class);
|
||||
}
|
@ -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() {
|
||||
@ -25,8 +25,8 @@ public class ByteType extends Type<Byte> implements TypeConverter<Byte> {
|
||||
if (o instanceof Number) {
|
||||
return ((Number) o).byteValue();
|
||||
}
|
||||
if(o instanceof Boolean){
|
||||
return ((Boolean)o) == true ? (byte) 1 : 0;
|
||||
if (o instanceof Boolean) {
|
||||
return (Boolean) o ? (byte) 1 : 0;
|
||||
}
|
||||
return (Byte) o;
|
||||
}
|
@ -1,10 +1,10 @@
|
||||
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 class DoubleType extends Type<Double> implements TypeConverter<Double> {
|
||||
public DoubleType() {
|
||||
super(Double.class);
|
||||
}
|
||||
@ -24,8 +24,8 @@ public class DoubleType extends Type<Double> implements TypeConverter<Double>{
|
||||
if (o instanceof Number) {
|
||||
return ((Number) o).doubleValue();
|
||||
}
|
||||
if(o instanceof Boolean){
|
||||
return ((Boolean)o) == true ? 1D : 0D;
|
||||
if (o instanceof Boolean) {
|
||||
return (Boolean) o ? (byte) 1D : 0D;
|
||||
}
|
||||
return (Double) o;
|
||||
}
|
@ -1,10 +1,10 @@
|
||||
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 class FloatType extends Type<Float> implements TypeConverter<Float> {
|
||||
public FloatType() {
|
||||
super(Float.class);
|
||||
}
|
||||
@ -25,8 +25,8 @@ public class FloatType extends Type<Float> implements TypeConverter<Float>{
|
||||
if (o instanceof Number) {
|
||||
return ((Number) o).floatValue();
|
||||
}
|
||||
if(o instanceof Boolean){
|
||||
return ((Boolean)o) == true ? 1F : 0;
|
||||
if (o instanceof Boolean) {
|
||||
return ((Boolean) o) ? 1F : 0;
|
||||
}
|
||||
return (Float) o;
|
||||
}
|
@ -1,10 +1,10 @@
|
||||
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 class IntType extends Type<Integer> implements TypeConverter<Integer> {
|
||||
public IntType() {
|
||||
super(Integer.class);
|
||||
}
|
||||
@ -24,8 +24,8 @@ public class IntType extends Type<Integer> implements TypeConverter<Integer>{
|
||||
if (o instanceof Number) {
|
||||
return ((Number) o).intValue();
|
||||
}
|
||||
if(o instanceof Boolean){
|
||||
return ((Boolean)o) == true ? 1 : 0;
|
||||
if (o instanceof Boolean) {
|
||||
return ((Boolean) o) ? 1 : 0;
|
||||
}
|
||||
return (Integer) o;
|
||||
}
|
@ -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() {
|
||||
@ -25,8 +25,8 @@ public class LongType extends Type<Long> implements TypeConverter<Long> {
|
||||
if (o instanceof Number) {
|
||||
return ((Number) o).longValue();
|
||||
}
|
||||
if(o instanceof Boolean){
|
||||
return ((Boolean)o) == true ? 1L : 0;
|
||||
if (o instanceof Boolean) {
|
||||
return ((Boolean) o) ? 1L : 0;
|
||||
}
|
||||
return (Long) o;
|
||||
}
|
@ -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() {
|
@ -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() {
|
||||
@ -24,8 +24,8 @@ public class ShortType extends Type<Short> implements TypeConverter<Short> {
|
||||
if (o instanceof Number) {
|
||||
return ((Number) o).shortValue();
|
||||
}
|
||||
if(o instanceof Boolean){
|
||||
return ((Boolean)o) == true ? (short) 1 : 0;
|
||||
if (o instanceof Boolean) {
|
||||
return ((Boolean) o) ? (short) 1 : 0;
|
||||
}
|
||||
return (short) o;
|
||||
}
|
@ -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() {
|
@ -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;
|
||||
|
@ -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() {
|
||||
@ -24,8 +24,8 @@ public class UnsignedByteType extends Type<Short> implements TypeConverter<Short
|
||||
if (o instanceof Number) {
|
||||
return ((Number) o).shortValue();
|
||||
}
|
||||
if(o instanceof Boolean){
|
||||
return ((Boolean)o) == true ? (short) 1 : 0;
|
||||
if (o instanceof Boolean) {
|
||||
return ((Boolean) o) ? (short) 1 : 0;
|
||||
}
|
||||
return (short) o;
|
||||
}
|
@ -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() {
|
||||
@ -24,8 +24,8 @@ public class UnsignedShortType extends Type<Integer> implements TypeConverter<In
|
||||
if (o instanceof Number) {
|
||||
return ((Number) o).intValue();
|
||||
}
|
||||
if(o instanceof Boolean){
|
||||
return ((Boolean)o) == true ? 1 : 0;
|
||||
if (o instanceof Boolean) {
|
||||
return ((Boolean) o) ? 1 : 0;
|
||||
}
|
||||
return (Integer) o;
|
||||
}
|
@ -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;
|
||||
}
|
@ -1,10 +1,10 @@
|
||||
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 class VoidType extends Type<Void> implements TypeConverter<Void> {
|
||||
public VoidType() {
|
||||
super(Void.class);
|
||||
}
|
@ -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() {
|
@ -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[]> {
|
||||
|
@ -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() {
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
@ -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;
|
||||
|
||||
@ -13,16 +13,15 @@ public class OptUUIDType extends Type<UUID> {
|
||||
@Override
|
||||
public UUID read(ByteBuf buffer) {
|
||||
boolean present = buffer.readBoolean();
|
||||
if(!present) return null;
|
||||
if (!present) return null;
|
||||
return new UUID(buffer.readLong(), buffer.readLong());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ByteBuf buffer, UUID object) {
|
||||
if(object == null){
|
||||
if (object == null) {
|
||||
buffer.writeBoolean(false);
|
||||
return;
|
||||
}else{
|
||||
} else {
|
||||
buffer.writeBoolean(true);
|
||||
buffer.writeLong(object.getMostSignificantBits());
|
||||
buffer.writeLong(object.getLeastSignificantBits());
|
@ -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() {
|
@ -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() {
|
@ -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() {
|
||||
|
@ -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 {
|
||||
|
||||
@ -62,7 +59,7 @@ public class ViaVersionCommand implements CommandExecutor {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void sendHelp(CommandSender sender){
|
||||
public void sendHelp(CommandSender sender) {
|
||||
sender.sendMessage(color("&aViaVersion &c" + ViaVersion.getInstance().getVersion()));
|
||||
sender.sendMessage(color("&6Commands:"));
|
||||
sender.sendMessage(color("&2/viaversion list &7- &6Shows lists of all 1.9 clients and 1.8 clients."));
|
||||
|
@ -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;
|
||||
|
||||
@ -23,7 +23,7 @@ public class ViaChunkHandler extends MessageToMessageEncoder {
|
||||
if (!(o instanceof ByteBuf)) {
|
||||
info.setLastPacket(o);
|
||||
/* This transformer is more for fixing issues which we find hard at packet level :) */
|
||||
if(o.getClass().getName().endsWith("PacketPlayOutMapChunkBulk") && info.isActive()) {
|
||||
if (o.getClass().getName().endsWith("PacketPlayOutMapChunkBulk") && info.isActive()) {
|
||||
list.addAll(info.get(ClientChunks.class).transformMapChunkBulk(o));
|
||||
return;
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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,6 +169,26 @@ public enum PacketType {
|
||||
this.newPacketID = newPacketID;
|
||||
}
|
||||
|
||||
public static PacketType findNewPacket(State state, Direction direction, int id) {
|
||||
return newids.get(toShort((short) id, (short) direction.ordinal(), (short) state.ordinal()));
|
||||
}
|
||||
|
||||
public static PacketType findOldPacket(State state, Direction direction, int id) {
|
||||
return oldids.get(toShort((short) id, (short) direction.ordinal(), (short) state.ordinal()));
|
||||
}
|
||||
|
||||
public static PacketType getIncomingPacket(State state, int id) {
|
||||
return findNewPacket(state, Direction.INCOMING, id);
|
||||
}
|
||||
|
||||
public static PacketType getOutgoingPacket(State state, int id) {
|
||||
return findOldPacket(state, Direction.OUTGOING, id);
|
||||
}
|
||||
|
||||
private static short toShort(short id, short direction, short state) {
|
||||
return (short) ((id & 0x00FF) | (direction << 8) & 0x0F00 | (state << 12) & 0xF000);
|
||||
}
|
||||
|
||||
public State getState() {
|
||||
return state;
|
||||
}
|
||||
@ -177,33 +205,4 @@ public enum PacketType {
|
||||
return newPacketID;
|
||||
}
|
||||
|
||||
public static PacketType findNewPacket(State state, Direction direction, int id) {
|
||||
return newids.get(toShort((short) id, (short)direction.ordinal(), (short) state.ordinal()));
|
||||
}
|
||||
|
||||
public static PacketType findOldPacket(State state, Direction direction, int id) {
|
||||
return oldids.get(toShort((short) id, (short)direction.ordinal(), (short) state.ordinal()));
|
||||
}
|
||||
|
||||
public static PacketType getIncomingPacket(State state, int id) {
|
||||
return findNewPacket(state, Direction.INCOMING, id);
|
||||
}
|
||||
|
||||
public static PacketType getOutgoingPacket(State state, int id) {
|
||||
return findOldPacket(state, Direction.OUTGOING, id);
|
||||
}
|
||||
|
||||
private static short toShort(short id, short direction, short state) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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;
|
@ -1,17 +1,17 @@
|
||||
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;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class ProtocolInfo extends StoredObject{
|
||||
public class ProtocolInfo extends StoredObject {
|
||||
private State state = State.HANDSHAKE;
|
||||
private int protocolVersion = -1;
|
||||
private String username;
|
@ -1,12 +1,12 @@
|
||||
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{
|
||||
public class Protocol1_9_1TO1_9 extends Protocol {
|
||||
@Override
|
||||
protected void registerPackets() {
|
||||
// Currently supports 1.9.1 PRE 2
|
@ -1,4 +1,4 @@
|
||||
package us.myles.ViaVersion.armor;
|
||||
package us.myles.ViaVersion.protocols.protocol1_9to1_8;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@ -36,8 +36,8 @@ public enum ArmorType {
|
||||
private final Material type;
|
||||
|
||||
public static ArmorType findByType(Material type) {
|
||||
for(ArmorType a : ArmorType.values())
|
||||
if(a.getType() == type)
|
||||
for (ArmorType a : ArmorType.values())
|
||||
if (a.getType() == type)
|
||||
return a;
|
||||
return ArmorType.NONE;
|
||||
}
|
||||
@ -52,15 +52,15 @@ public enum ArmorType {
|
||||
}
|
||||
|
||||
public static ArmorType findById(int id) {
|
||||
for(ArmorType a : ArmorType.values())
|
||||
if(a.getId() == id)
|
||||
for (ArmorType a : ArmorType.values())
|
||||
if (a.getId() == id)
|
||||
return a;
|
||||
return ArmorType.NONE;
|
||||
}
|
||||
|
||||
public static boolean isArmor(Material material){
|
||||
for(ArmorType a : ArmorType.values())
|
||||
if(a.getType() == material)
|
||||
public static boolean isArmor(Material material) {
|
||||
for (ArmorType a : ArmorType.values())
|
||||
if (a.getType() == material)
|
||||
return true;
|
||||
return false;
|
||||
}
|
@ -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;
|
@ -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
|
@ -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));
|
||||
}
|
||||
}
|
@ -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)
|
@ -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();
|
||||
}
|
@ -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.*;
|
@ -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;
|
@ -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
|
@ -1,4 +1,4 @@
|
||||
package us.myles.ViaVersion.metadata;
|
||||
package us.myles.ViaVersion.protocols.protocol1_9to1_8.metadata;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
@ -1,4 +1,4 @@
|
||||
package us.myles.ViaVersion.metadata;
|
||||
package us.myles.ViaVersion.protocols.protocol1_9to1_8.metadata;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
@ -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;
|
||||
|
||||
@ -187,8 +187,8 @@ public class EntityPackets {
|
||||
int entityID = wrapper.get(Type.VAR_INT, 0);
|
||||
Item stack = wrapper.get(Type.ITEM, 0);
|
||||
|
||||
if(stack != null){
|
||||
if(Material.getMaterial(stack.getId()).name().endsWith("SWORD")){
|
||||
if (stack != null) {
|
||||
if (Material.getMaterial(stack.getId()).name().endsWith("SWORD")) {
|
||||
entityTracker.getValidBlocking().add(entityID);
|
||||
return;
|
||||
}
|
||||
@ -211,9 +211,9 @@ public class EntityPackets {
|
||||
List<Metadata> metadataList = wrapper.get(Protocol1_9TO1_8.METADATA_LIST, 0);
|
||||
int entityID = wrapper.get(Type.VAR_INT, 0);
|
||||
EntityTracker tracker = wrapper.user().get(EntityTracker.class);
|
||||
if(tracker.getClientEntityTypes().containsKey(entityID)) {
|
||||
if (tracker.getClientEntityTypes().containsKey(entityID)) {
|
||||
MetadataRewriter.transform(tracker.getClientEntityTypes().get(entityID), metadataList);
|
||||
}else{
|
||||
} else {
|
||||
System.out.println("Unable to find entity for metadata, entity ID: " + entityID);
|
||||
}
|
||||
}
|
@ -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) {
|
@ -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) {
|
||||
@ -230,7 +230,7 @@ public class PlayerPackets {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
String name = wrapper.get(Type.STRING, 0);
|
||||
if(name.equalsIgnoreCase("MC|BOpen")){
|
||||
if (name.equalsIgnoreCase("MC|BOpen")) {
|
||||
wrapper.passthrough(Type.REMAINING_BYTES); // This is so ugly, :(
|
||||
wrapper.write(Type.VAR_INT, 0);
|
||||
}
|
||||
@ -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
|
||||
@ -383,13 +424,13 @@ public class PlayerPackets {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
String name = wrapper.get(Type.STRING, 0);
|
||||
if(name.equalsIgnoreCase("MC|BSign")){
|
||||
if (name.equalsIgnoreCase("MC|BSign")) {
|
||||
Item item = wrapper.passthrough(Type.ITEM);
|
||||
if(item != null){
|
||||
if (item != null) {
|
||||
item.setId((short) Material.WRITTEN_BOOK.getId());
|
||||
}
|
||||
}
|
||||
if(name.equalsIgnoreCase("MC|AutoCmd")){
|
||||
if (name.equalsIgnoreCase("MC|AutoCmd")) {
|
||||
wrapper.set(Type.STRING, 0, "MC|AdvCdm");
|
||||
wrapper.write(Type.BYTE, (byte) 0);
|
||||
wrapper.passthrough(Type.INT); // X
|
||||
@ -399,7 +440,7 @@ public class PlayerPackets {
|
||||
wrapper.passthrough(Type.BOOLEAN); // Flag
|
||||
wrapper.clearInputBuffer();
|
||||
}
|
||||
if(name.equalsIgnoreCase("MC|AdvCmd")){
|
||||
if (name.equalsIgnoreCase("MC|AdvCmd")) {
|
||||
wrapper.set(Type.STRING, 0, "MC|AdvCdm");
|
||||
}
|
||||
}
|
||||
@ -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
|
||||
|
||||
}
|
||||
}
|
@ -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;
|
||||
|
||||
@ -176,9 +176,9 @@ public class SpawnPackets {
|
||||
List<Metadata> metadataList = wrapper.get(Protocol1_9TO1_8.METADATA_LIST, 0);
|
||||
int entityID = wrapper.get(Type.VAR_INT, 0);
|
||||
EntityTracker tracker = wrapper.user().get(EntityTracker.class);
|
||||
if(tracker.getClientEntityTypes().containsKey(entityID)) {
|
||||
if (tracker.getClientEntityTypes().containsKey(entityID)) {
|
||||
MetadataRewriter.transform(tracker.getClientEntityTypes().get(entityID), metadataList);
|
||||
}else{
|
||||
} else {
|
||||
System.out.println("Unable to find entity for metadata, entity ID: " + entityID);
|
||||
}
|
||||
}
|
||||
@ -252,9 +252,9 @@ public class SpawnPackets {
|
||||
List<Metadata> metadataList = wrapper.get(Protocol1_9TO1_8.METADATA_LIST, 0);
|
||||
int entityID = wrapper.get(Type.VAR_INT, 0);
|
||||
EntityTracker tracker = wrapper.user().get(EntityTracker.class);
|
||||
if(tracker.getClientEntityTypes().containsKey(entityID)) {
|
||||
if (tracker.getClientEntityTypes().containsKey(entityID)) {
|
||||
MetadataRewriter.transform(tracker.getClientEntityTypes().get(entityID), metadataList);
|
||||
}else{
|
||||
} else {
|
||||
System.out.println("Unable to find entity for metadata, entity ID: " + entityID);
|
||||
}
|
||||
}
|
@ -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) {
|
@ -1,4 +1,4 @@
|
||||
package us.myles.ViaVersion.sounds;
|
||||
package us.myles.ViaVersion.protocols.protocol1_9to1_8.sounds;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
@ -1,4 +1,4 @@
|
||||
package us.myles.ViaVersion.sounds;
|
||||
package us.myles.ViaVersion.protocols.protocol1_9to1_8.sounds;
|
||||
|
||||
import lombok.Getter;
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
@ -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) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -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
|
@ -1,10 +1,10 @@
|
||||
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{
|
||||
public class MovementTracker extends StoredObject {
|
||||
private static final long IDLE_PACKET_DELAY = 50L; // Update every 50ms (20tps)
|
||||
private static final long IDLE_PACKET_LIMIT = 20; // Max 20 ticks behind
|
||||
@Getter
|
@ -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,40 +127,36 @@ public class ChunkType extends PartialType<Chunk, ClientChunks> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ByteBuf output, ClientChunks param, Chunk chunk) {
|
||||
if(chunk.isUnloadPacket()) {
|
||||
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
|
||||
output.writeInt(chunk.getX());
|
||||
output.writeInt(chunk.getZ());
|
||||
if(chunk.isUnloadPacket()) return;
|
||||
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++) {
|
||||
for (int i = 0; i < SECTION_COUNT; i++) {
|
||||
ChunkSection section = chunk.getSections()[i];
|
||||
if(section == null) continue; // Section not set
|
||||
if (section == null) continue; // Section not set
|
||||
section.writeBlocks(buf);
|
||||
section.writeBlockLight(buf);
|
||||
if(!section.hasSkyLight()) continue; // No sky light, we're done here.
|
||||
if (!section.hasSkyLight()) continue; // No sky light, we're done here.
|
||||
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
|
||||
|
||||
// Write biome data
|
||||
if(chunk.hasBiomeData()) {
|
||||
if (chunk.hasBiomeData()) {
|
||||
output.writeBytes(chunk.getBiomeData());
|
||||
}
|
||||
}
|
||||
|
||||
private static long toLong(int msw, int lsw) {
|
||||
return ((long) msw << 32) + lsw - -2147483648L;
|
||||
}
|
||||
}
|
@ -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;
|
@ -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> {
|
||||
|
@ -13,7 +13,7 @@ public class UpdateListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onJoin(PlayerJoinEvent e) {
|
||||
if(e.getPlayer().hasPermission("viaversion.update")
|
||||
if (e.getPlayer().hasPermission("viaversion.update")
|
||||
&& plugin.getConfig().getBoolean("checkforupdates", true)) {
|
||||
UpdateUtil.sendUpdateMessage(e.getPlayer().getUniqueId(), plugin);
|
||||
}
|
||||
|
@ -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() {
|
||||
|
||||
|
@ -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) {
|
||||
@ -85,14 +85,14 @@ public class Configuration extends YamlConfiguration {
|
||||
this.loadHeaders = loadHeaders;
|
||||
try {
|
||||
load(file);
|
||||
} catch(Exception e) {
|
||||
} catch (Exception e) {
|
||||
Bukkit.getLogger().log(Level.WARNING, "failed to reload file", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadFromString(String contents) throws InvalidConfigurationException {
|
||||
if(!loadHeaders) {
|
||||
if (!loadHeaders) {
|
||||
super.loadFromString(contents);
|
||||
return;
|
||||
}
|
||||
@ -105,12 +105,12 @@ public class Configuration extends YamlConfiguration {
|
||||
int currentIndents = 0;
|
||||
String key = "";
|
||||
List<String> headers = Lists.newArrayList();
|
||||
for(String line : contents.split("\n")) {
|
||||
if(line.isEmpty()) continue; // Skip empty lines
|
||||
for (String line : contents.split("\n")) {
|
||||
if (line.isEmpty()) continue; // Skip empty lines
|
||||
int indent = getSuccessiveCharCount(line, ' ');
|
||||
String subline = indent > 0 ? line.substring(indent) : line;
|
||||
if(subline.startsWith("#")) {
|
||||
if(subline.startsWith("#>")) {
|
||||
if (subline.startsWith("#")) {
|
||||
if (subline.startsWith("#>")) {
|
||||
String txt = subline.startsWith("#> ") ? subline.substring(3) : subline.substring(2);
|
||||
mainHeader.add(txt);
|
||||
continue; // Main header, handled by bukkit
|
||||
@ -123,7 +123,7 @@ public class Configuration extends YamlConfiguration {
|
||||
}
|
||||
|
||||
int indents = indent / indentLength;
|
||||
if(indents <= currentIndents) {
|
||||
if (indents <= currentIndents) {
|
||||
// Remove last section of key
|
||||
String[] array = key.split(Pattern.quote(pathSeparator));
|
||||
int backspace = currentIndents - indents + 1;
|
||||
@ -138,7 +138,7 @@ public class Configuration extends YamlConfiguration {
|
||||
currentIndents = indents;
|
||||
|
||||
memoryData.append(line).append('\n');
|
||||
if(!headers.isEmpty()) {
|
||||
if (!headers.isEmpty()) {
|
||||
this.headers.put(key, headers);
|
||||
headers = Lists.newArrayList();
|
||||
}
|
||||
@ -155,10 +155,10 @@ public class Configuration extends YamlConfiguration {
|
||||
* Save config to file
|
||||
*/
|
||||
public void save() {
|
||||
if(headers.isEmpty() && mainHeader.isEmpty()) {
|
||||
if (headers.isEmpty() && mainHeader.isEmpty()) {
|
||||
try {
|
||||
super.save(file);
|
||||
} catch(IOException e) {
|
||||
} catch (IOException e) {
|
||||
Bukkit.getLogger().log(Level.WARNING, "Failed to save file", e);
|
||||
}
|
||||
return;
|
||||
@ -171,17 +171,17 @@ public class Configuration extends YamlConfiguration {
|
||||
StringBuilder fileData = new StringBuilder(buildHeader());
|
||||
int currentIndents = 0;
|
||||
String key = "";
|
||||
for(String h : mainHeader) {
|
||||
for (String h : mainHeader) {
|
||||
// Append main header to top of file
|
||||
fileData.append("#> ").append(h).append('\n');
|
||||
}
|
||||
|
||||
for(String line : content.split("\n")) {
|
||||
if(line.isEmpty()) continue; // Skip empty lines
|
||||
for (String line : content.split("\n")) {
|
||||
if (line.isEmpty()) continue; // Skip empty lines
|
||||
int indent = getSuccessiveCharCount(line, ' ');
|
||||
int indents = indent / indentLength;
|
||||
String indentText = indent > 0 ? line.substring(0, indent) : "";
|
||||
if(indents <= currentIndents) {
|
||||
if (indents <= currentIndents) {
|
||||
// Remove last section of key
|
||||
String[] array = key.split(Pattern.quote(pathSeparator));
|
||||
int backspace = currentIndents - indents + 1;
|
||||
@ -206,13 +206,13 @@ public class Configuration extends YamlConfiguration {
|
||||
writer = new FileWriter(file);
|
||||
writer.write(fileData.toString());
|
||||
writer.flush();
|
||||
} catch(IOException e) {
|
||||
} catch (IOException e) {
|
||||
Bukkit.getLogger().log(Level.WARNING, "Failed to save file", e);
|
||||
} finally {
|
||||
if(writer != null) {
|
||||
if (writer != null) {
|
||||
try {
|
||||
writer.close();
|
||||
} catch(IOException e) {
|
||||
} catch (IOException ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -220,7 +220,7 @@ public class Configuration extends YamlConfiguration {
|
||||
|
||||
private String addHeaderTags(List<String> header, String indent) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for(String line : header) {
|
||||
for (String line : header) {
|
||||
builder.append(indent).append("# ").append(line).append('\n');
|
||||
}
|
||||
return builder.toString();
|
||||
@ -234,8 +234,8 @@ public class Configuration extends YamlConfiguration {
|
||||
|
||||
private int getSuccessiveCharCount(String text, char key) {
|
||||
int count = 0;
|
||||
for(int i = 0; i < text.length(); i++) {
|
||||
if(text.charAt(i) == key) {
|
||||
for (int i = 0; i < text.length(); i++) {
|
||||
if (text.charAt(i) == key) {
|
||||
count += 1;
|
||||
} else {
|
||||
break;
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
60
src/main/java/us/myles/ViaVersion/util/PipelineUtil.java
Normale Datei
60
src/main/java/us/myles/ViaVersion/util/PipelineUtil.java
Normale Datei
@ -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;
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
@ -77,22 +78,22 @@ public class ReflectionUtil {
|
||||
}
|
||||
|
||||
private void scanFields(Class<?> host, boolean recursive) {
|
||||
if(host.getSuperclass() != null && recursive) {
|
||||
if (host.getSuperclass() != null && recursive) {
|
||||
scanFields(host.getSuperclass(), true);
|
||||
}
|
||||
|
||||
for(Field field : host.getDeclaredFields()) {
|
||||
for (Field field : host.getDeclaredFields()) {
|
||||
field.setAccessible(true);
|
||||
fields.put(field.getName(), field);
|
||||
}
|
||||
}
|
||||
|
||||
private void scanMethods(Class<?> host, boolean recursive) {
|
||||
if(host.getSuperclass() != null && recursive) {
|
||||
if (host.getSuperclass() != null && recursive) {
|
||||
scanMethods(host.getSuperclass(), true);
|
||||
}
|
||||
|
||||
for(Method method : host.getDeclaredMethods()) {
|
||||
for (Method method : host.getDeclaredMethods()) {
|
||||
method.setAccessible(true);
|
||||
methods.put(method.getName(), method);
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
@ -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;
|
||||
}
|
@ -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;
|
||||
}
|
@ -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;
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
package us.myles.ViaVersion2.api.type;
|
||||
|
||||
public interface TypeConverter<T> {
|
||||
public T from(Object o);
|
||||
}
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren