mirror of
https://github.com/ViaVersion/ViaVersion.git
synced 2024-12-29 03:48:46 +01:00
JavaDoc for quite a lot of the API classes... yay
This commit is contained in:
parent
eccbb567e8
commit
af53275ab9
@ -8,9 +8,6 @@ import io.netty.channel.socket.SocketChannel;
|
||||
import lombok.NonNull;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import us.myles.ViaVersion.api.ViaVersion;
|
||||
import us.myles.ViaVersion.api.ViaVersionAPI;
|
||||
@ -20,12 +17,10 @@ import us.myles.ViaVersion.api.boss.BossColor;
|
||||
import us.myles.ViaVersion.api.boss.BossStyle;
|
||||
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.protocols.protocol1_9to1_8.listeners.ArmorListener;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.listeners.CommandBlockListener;
|
||||
import us.myles.ViaVersion.protocols.base.ProtocolInfo;
|
||||
import us.myles.ViaVersion.update.UpdateListener;
|
||||
import us.myles.ViaVersion.update.UpdateUtil;
|
||||
import us.myles.ViaVersion.util.Configuration;
|
||||
@ -248,11 +243,11 @@ public class ViaVersionPlugin extends JavaPlugin implements ViaVersionAPI, ViaVe
|
||||
return getDescription().getVersion();
|
||||
}
|
||||
|
||||
public UserConnection getConnection(UUID playerUUID){
|
||||
public UserConnection getConnection(UUID playerUUID) {
|
||||
return portedPlayers.get(playerUUID);
|
||||
}
|
||||
|
||||
public UserConnection getConnection(Player player){
|
||||
public UserConnection getConnection(Player player) {
|
||||
return portedPlayers.get(player.getUniqueId());
|
||||
}
|
||||
|
||||
|
@ -31,6 +31,13 @@ public class PacketWrapper {
|
||||
this.userConnection = userConnection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a part from the output
|
||||
*
|
||||
* @param type The type of the part you wish to get.
|
||||
* @param index The index of the part (relative to the type)
|
||||
* @return The requested type or throws ArrayIndexOutOfBounds
|
||||
*/
|
||||
public <T> T get(Type<T> type, int index) {
|
||||
int currentIndex = 0;
|
||||
for (Pair<Type, Object> packetValue : packetValues) {
|
||||
@ -44,6 +51,13 @@ public class PacketWrapper {
|
||||
throw new ArrayIndexOutOfBoundsException("Could not find type " + type.getTypeName() + " at " + index);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a currently existing part in the output
|
||||
*
|
||||
* @param type The type of the part you wish to set.
|
||||
* @param index The index of the part (relative to the type)
|
||||
* @param value The value of the part you wish to set it to.
|
||||
*/
|
||||
public <T> void set(Type<T> type, int index, T value) {
|
||||
int currentIndex = 0;
|
||||
for (Pair<Type, Object> packetValue : packetValues) {
|
||||
@ -58,6 +72,13 @@ public class PacketWrapper {
|
||||
throw new ArrayIndexOutOfBoundsException("Could not find type " + type.getTypeName() + " at " + index);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read a type from the input.
|
||||
*
|
||||
* @param type The type you wish to read
|
||||
* @return The requested type
|
||||
* @throws Exception If it fails to read
|
||||
*/
|
||||
public <T> T read(Type<T> type) throws Exception {
|
||||
if (type == Type.NOTHING) return null;
|
||||
if (readableObjects.isEmpty()) {
|
||||
@ -78,17 +99,35 @@ public class PacketWrapper {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Write a type to the output.
|
||||
*
|
||||
* @param type The type to write.
|
||||
* @param value The value of the type to write.
|
||||
*/
|
||||
public <T> void write(Type<T> type, T value) {
|
||||
packetValues.add(new Pair<Type, Object>(type, value));
|
||||
}
|
||||
|
||||
/**
|
||||
* Take a value from the input and write to the output.
|
||||
*
|
||||
* @param type The type to read and write.
|
||||
* @return The type which was read/written.
|
||||
* @throws Exception If it failed to read or write
|
||||
*/
|
||||
public <T> T passthrough(Type<T> type) throws Exception {
|
||||
T value = read(type);
|
||||
write(type, value);
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write the current output to a buffer.
|
||||
*
|
||||
* @param buffer The buffer to write to.
|
||||
* @throws Exception Throws an exception if it fails to write a value.
|
||||
*/
|
||||
public void writeToBuffer(ByteBuf buffer) throws Exception {
|
||||
if (id != -1) {
|
||||
Type.VAR_INT.write(buffer, id);
|
||||
@ -121,6 +160,9 @@ public class PacketWrapper {
|
||||
writeRemaining(buffer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the input buffer / readable objects
|
||||
*/
|
||||
public void clearInputBuffer() {
|
||||
if (inputBuffer != null)
|
||||
inputBuffer.clear();
|
||||
@ -133,34 +175,72 @@ public class PacketWrapper {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Send this packet to the associated user.
|
||||
* Be careful not to send packets twice.
|
||||
*
|
||||
* @throws Exception if it fails to write
|
||||
*/
|
||||
public void send() throws Exception {
|
||||
ByteBuf output = inputBuffer == null ? Unpooled.buffer() : inputBuffer.alloc().buffer();
|
||||
writeToBuffer(output);
|
||||
user().sendRawPacket(output);
|
||||
if (!isCancelled()) {
|
||||
ByteBuf output = inputBuffer == null ? Unpooled.buffer() : inputBuffer.alloc().buffer();
|
||||
writeToBuffer(output);
|
||||
user().sendRawPacket(output);
|
||||
}
|
||||
}
|
||||
|
||||
public PacketWrapper create(int packetID) throws Exception {
|
||||
/**
|
||||
* Create a new packet for the target of this packet.
|
||||
*
|
||||
* @param packetID The ID of the new packet
|
||||
* @return The newly created packet wrapper
|
||||
*/
|
||||
public PacketWrapper create(int packetID) {
|
||||
return new PacketWrapper(packetID, null, user());
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new packet with values.
|
||||
*
|
||||
* @param packetID The ID of the new packet
|
||||
* @param init A ValueCreator to write to the packet.
|
||||
* @return The newly created packet wrapper
|
||||
* @throws Exception If it failed to write the values from the ValueCreator.
|
||||
*/
|
||||
public PacketWrapper create(int packetID, ValueCreator init) throws Exception {
|
||||
PacketWrapper wrapper = create(packetID);
|
||||
init.write(wrapper);
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancel this packet from sending
|
||||
*/
|
||||
public void cancel() {
|
||||
this.send = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if this packet is cancelled.
|
||||
*
|
||||
* @return True if the packet won't be sent.
|
||||
*/
|
||||
public boolean isCancelled() {
|
||||
return !this.send;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the user associated with this Packet
|
||||
*
|
||||
* @return The user
|
||||
*/
|
||||
public UserConnection user() {
|
||||
return this.userConnection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset the reader, so that it can be read again.
|
||||
*/
|
||||
public void resetReader() {
|
||||
this.readableObjects.addAll(packetValues);
|
||||
this.packetValues.clear();
|
||||
|
@ -1,7 +1,6 @@
|
||||
package us.myles.ViaVersion.api;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import us.myles.ViaVersion.ViaVersionPlugin;
|
||||
|
||||
public class ViaVersion {
|
||||
|
@ -6,8 +6,6 @@ import io.netty.channel.socket.SocketChannel;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
@ -27,18 +25,41 @@ public class UserConnection {
|
||||
this.channel = socketChannel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an object from the storage
|
||||
*
|
||||
* @param objectClass The class of the object to get
|
||||
* @return The requested object
|
||||
*/
|
||||
public <T extends StoredObject> T get(Class<T> objectClass) {
|
||||
return (T) storedObjects.get(objectClass);
|
||||
}
|
||||
|
||||
public <T extends StoredObject> boolean has(Class<T> objectClass) {
|
||||
/**
|
||||
* Check if the storage has an object
|
||||
*
|
||||
* @param objectClass The object class to check
|
||||
* @return True if the object is in the storage
|
||||
*/
|
||||
public boolean has(Class<? extends StoredObject> objectClass) {
|
||||
return storedObjects.containsKey(objectClass);
|
||||
}
|
||||
|
||||
/**
|
||||
* Put an object into the stored objects based on class
|
||||
*
|
||||
* @param object The object to store.
|
||||
*/
|
||||
public void put(StoredObject object) {
|
||||
storedObjects.put(object.getClass(), object);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a raw packet to the player
|
||||
*
|
||||
* @param packet The raw packet to send
|
||||
* @param currentThread Should it run in the same thread
|
||||
*/
|
||||
public void sendRawPacket(final ByteBuf packet, boolean currentThread) {
|
||||
final ChannelHandler handler = channel.pipeline().get("encoder");
|
||||
if (currentThread) {
|
||||
@ -53,6 +74,11 @@ public class UserConnection {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a raw packet to the player (netty thread)
|
||||
*
|
||||
* @param packet The packet to send
|
||||
*/
|
||||
public void sendRawPacket(final ByteBuf packet) {
|
||||
sendRawPacket(packet, false);
|
||||
}
|
||||
|
@ -25,6 +25,11 @@ public class Chunk {
|
||||
this.unloadPacket = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Does this chunk have biome data
|
||||
*
|
||||
* @return True if the chunk has biome data
|
||||
*/
|
||||
public boolean hasBiomeData() {
|
||||
return biomeData != null && groundUp;
|
||||
}
|
||||
|
@ -31,10 +31,26 @@ public class ChunkSection {
|
||||
palette.add(0); // AIR
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a block in the chunk
|
||||
*
|
||||
* @param x Block X
|
||||
* @param y Block Y
|
||||
* @param z Block Z
|
||||
* @param type The type of the block
|
||||
* @param data The data value of the block
|
||||
*/
|
||||
public void setBlock(int x, int y, int z, int type, int data) {
|
||||
setBlock(index(x, y, z), type, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a block in the chunk based on the index
|
||||
*
|
||||
* @param idx Index
|
||||
* @param type The type of the block
|
||||
* @param data The data value of the block
|
||||
*/
|
||||
public void setBlock(int idx, int type, int data) {
|
||||
int hash = type << 4 | (data & 0xF);
|
||||
int index = palette.indexOf(hash);
|
||||
@ -46,10 +62,20 @@ public class ChunkSection {
|
||||
blocks[idx] = index;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the block light array
|
||||
*
|
||||
* @param data The value to set the block light to
|
||||
*/
|
||||
public void setBlockLight(byte[] data) {
|
||||
blockLight.setHandle(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the sky light array
|
||||
*
|
||||
* @param data The value to set the sky light to
|
||||
*/
|
||||
public void setSkyLight(byte[] data) {
|
||||
if (data.length != LIGHT_LENGTH) throw new IllegalArgumentException("Data length != " + LIGHT_LENGTH);
|
||||
this.skyLight = new NibbleArray(data);
|
||||
@ -59,6 +85,12 @@ public class ChunkSection {
|
||||
return z << 8 | y << 4 | x;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write the blocks to a buffer.
|
||||
*
|
||||
* @param output The buffer to write to.
|
||||
* @throws Exception Throws if it failed to write.
|
||||
*/
|
||||
public void writeBlocks(ByteBuf output) throws Exception {
|
||||
// Write bits per block
|
||||
int bitsPerBlock = 4;
|
||||
@ -94,14 +126,29 @@ public class ChunkSection {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Write the block light to a buffer
|
||||
*
|
||||
* @param output The buffer to write to
|
||||
*/
|
||||
public void writeBlockLight(ByteBuf output) {
|
||||
output.writeBytes(blockLight.getHandle());
|
||||
}
|
||||
|
||||
/**
|
||||
* Write the sky light to a buffer
|
||||
*
|
||||
* @param output The buffer to write to
|
||||
*/
|
||||
public void writeSkyLight(ByteBuf output) {
|
||||
output.writeBytes(skyLight.getHandle());
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if sky light is present
|
||||
*
|
||||
* @return True if skylight is present
|
||||
*/
|
||||
public boolean hasSkyLight() {
|
||||
return skyLight != null;
|
||||
}
|
||||
|
@ -21,10 +21,24 @@ public class NibbleArray {
|
||||
this.handle = handle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value at a desired X, Y, Z
|
||||
*
|
||||
* @param x Block X
|
||||
* @param y Block Y
|
||||
* @param z Block Z
|
||||
* @return The value at the given XYZ
|
||||
*/
|
||||
public byte get(int x, int y, int z) {
|
||||
return get(y << 8 | z << 4 | x);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value at an index
|
||||
*
|
||||
* @param index The index to lookup
|
||||
* @return The value at that index.
|
||||
*/
|
||||
public byte get(int index) {
|
||||
byte value = handle[index / 2];
|
||||
if (index % 2 == 0) {
|
||||
@ -34,10 +48,24 @@ public class NibbleArray {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the value based on an x, y, z
|
||||
*
|
||||
* @param x Block X
|
||||
* @param y Block Y
|
||||
* @param z Block Z
|
||||
* @param value Desired Value
|
||||
*/
|
||||
public void set(int x, int y, int z, int value) {
|
||||
set(y << 8 | z << 4 | x, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a value at an index
|
||||
*
|
||||
* @param index The index to set the value at.
|
||||
* @param value The desired value
|
||||
*/
|
||||
public void set(int index, int value) {
|
||||
index /= 2;
|
||||
if (index % 2 == 0) {
|
||||
@ -47,23 +75,48 @@ public class NibbleArray {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The size of this nibble
|
||||
*
|
||||
* @return The size as an int of the nibble
|
||||
*/
|
||||
public int size() {
|
||||
return handle.length * 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the actual number of bytes
|
||||
*
|
||||
* @return The number of bytes based on the handle.
|
||||
*/
|
||||
public int actualSize() {
|
||||
return handle.length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fill the array with a value
|
||||
*
|
||||
* @param value Value to fill with
|
||||
*/
|
||||
public void fill(byte value) {
|
||||
value &= 0xF; // Max nibble size (= 16)
|
||||
Arrays.fill(handle, (byte) ((value << 4) | value));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the byte array behind this nibble
|
||||
*
|
||||
* @return The byte array
|
||||
*/
|
||||
public byte[] getHandle() {
|
||||
return handle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy a byte array into this nibble
|
||||
*
|
||||
* @param handle The byte array to copy in.
|
||||
*/
|
||||
public void setHandle(byte[] handle) {
|
||||
if (handle.length != this.handle.length) {
|
||||
throw new IllegalArgumentException("Length of handle must equal to size of nibble array!");
|
||||
|
@ -17,6 +17,12 @@ public class Item {
|
||||
private short data;
|
||||
private CompoundTag tag;
|
||||
|
||||
/**
|
||||
* Create an item from a bukkit stack (doesn't save NBT)
|
||||
*
|
||||
* @param stack The stack to convert from
|
||||
* @return The output stack
|
||||
*/
|
||||
public static Item getItem(ItemStack stack) {
|
||||
if (stack == null) return null;
|
||||
return new Item((short) stack.getTypeId(), (byte) stack.getAmount(), stack.getDurability(), null);
|
||||
|
@ -23,40 +23,104 @@ public abstract class Protocol {
|
||||
registerListeners();
|
||||
}
|
||||
|
||||
/**
|
||||
* Should this protocol filter an object packet from this class.
|
||||
* Default: false
|
||||
*
|
||||
* @param packetClass The class of the current input
|
||||
* @return True if it should handle the filtering
|
||||
*/
|
||||
public boolean isFiltered(Class packetClass) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter a packet into the output
|
||||
*
|
||||
* @param info The current user connection
|
||||
* @param packet The input packet as an object (NMS)
|
||||
* @param output The list to put the object into.
|
||||
* @throws Exception Throws exception if cancelled / error.
|
||||
*/
|
||||
protected void filterPacket(UserConnection info, Object packet, List output) throws Exception {
|
||||
output.add(packet);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register listeners for this protocol
|
||||
*/
|
||||
protected void registerListeners() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the packets for this protocol
|
||||
*/
|
||||
protected abstract void registerPackets();
|
||||
|
||||
/**
|
||||
* Initialise a user for this protocol setting up objects.
|
||||
*
|
||||
* @param userConnection The user to initialise
|
||||
*/
|
||||
public abstract void init(UserConnection userConnection);
|
||||
|
||||
/**
|
||||
* Register an incoming packet, with simple id transformation.
|
||||
*
|
||||
* @param state The state which the packet is sent in.
|
||||
* @param oldPacketID The old packet ID
|
||||
* @param newPacketID The new packet ID
|
||||
*/
|
||||
public void registerIncoming(State state, int oldPacketID, int newPacketID) {
|
||||
registerIncoming(state, oldPacketID, newPacketID, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register an incoming packet, with id transformation and remapper.
|
||||
*
|
||||
* @param state The state which the packet is sent in.
|
||||
* @param oldPacketID The old packet ID
|
||||
* @param newPacketID The new packet ID
|
||||
* @param packetRemapper The remapper to use for the packet
|
||||
*/
|
||||
public void registerIncoming(State state, int oldPacketID, int newPacketID, PacketRemapper packetRemapper) {
|
||||
ProtocolPacket protocolPacket = new ProtocolPacket(state, oldPacketID, newPacketID, packetRemapper);
|
||||
incoming.put(new Pair<>(state, newPacketID), protocolPacket);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register an outgoing packet, with simple id transformation.
|
||||
*
|
||||
* @param state The state which the packet is sent in.
|
||||
* @param oldPacketID The old packet ID
|
||||
* @param newPacketID The new packet ID
|
||||
*/
|
||||
public void registerOutgoing(State state, int oldPacketID, int newPacketID) {
|
||||
registerOutgoing(state, oldPacketID, newPacketID, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register an outgoing packet, with id transformation and remapper.
|
||||
*
|
||||
* @param state The state which the packet is sent in.
|
||||
* @param oldPacketID The old packet ID
|
||||
* @param newPacketID The new packet ID
|
||||
* @param packetRemapper The remapper to use for the packet
|
||||
*/
|
||||
public void registerOutgoing(State state, int oldPacketID, int newPacketID, PacketRemapper packetRemapper) {
|
||||
ProtocolPacket protocolPacket = new ProtocolPacket(state, oldPacketID, newPacketID, packetRemapper);
|
||||
outgoing.put(new Pair<>(state, oldPacketID), protocolPacket);
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform a packet using this protocol
|
||||
*
|
||||
* @param direction The direction the packet is going in
|
||||
* @param state The current protocol state
|
||||
* @param packetWrapper The packet wrapper to transform
|
||||
* @throws Exception Throws exception if it fails to transform
|
||||
*/
|
||||
public void transform(Direction direction, State state, PacketWrapper packetWrapper) throws Exception {
|
||||
Pair<State, Integer> statePacket = new Pair<>(state, packetWrapper.getId());
|
||||
Map<Pair<State, Integer>, ProtocolPacket> packetMap = (direction == Direction.OUTGOING ? outgoing : incoming);
|
||||
|
@ -47,6 +47,12 @@ public class ProtocolPipeline extends Protocol {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a protocol to the current pipeline
|
||||
* This will call the .init method.
|
||||
*
|
||||
* @param protocol The protocol to add to the end
|
||||
*/
|
||||
public void add(Protocol protocol) {
|
||||
if (protocolList != null) {
|
||||
protocolList.addLast(protocol);
|
||||
@ -95,16 +101,16 @@ public class ProtocolPipeline extends Protocol {
|
||||
}
|
||||
|
||||
// Filter :) This would be not hard coded too, sorry :(
|
||||
if(type == PacketType.PLAY_CHUNK_DATA) return;
|
||||
if(type == PacketType.PLAY_TIME_UPDATE) return;
|
||||
if(type == PacketType.PLAY_KEEP_ALIVE) return;
|
||||
if(type == PacketType.PLAY_KEEP_ALIVE_REQUEST) return;
|
||||
if(type == PacketType.PLAY_ENTITY_LOOK_MOVE) return;
|
||||
if(type == PacketType.PLAY_ENTITY_LOOK) return;
|
||||
if(type == PacketType.PLAY_ENTITY_RELATIVE_MOVE) return;
|
||||
if(type == PacketType.PLAY_PLAYER_POSITION_LOOK_REQUEST) return;
|
||||
if(type == PacketType.PLAY_PLAYER_LOOK_REQUEST) return;
|
||||
if(type == PacketType.PLAY_PLAYER_POSITION_REQUEST) return;
|
||||
if (type == PacketType.PLAY_CHUNK_DATA) return;
|
||||
if (type == PacketType.PLAY_TIME_UPDATE) return;
|
||||
if (type == PacketType.PLAY_KEEP_ALIVE) return;
|
||||
if (type == PacketType.PLAY_KEEP_ALIVE_REQUEST) return;
|
||||
if (type == PacketType.PLAY_ENTITY_LOOK_MOVE) return;
|
||||
if (type == PacketType.PLAY_ENTITY_LOOK) return;
|
||||
if (type == PacketType.PLAY_ENTITY_RELATIVE_MOVE) return;
|
||||
if (type == PacketType.PLAY_PLAYER_POSITION_LOOK_REQUEST) return;
|
||||
if (type == PacketType.PLAY_PLAYER_LOOK_REQUEST) return;
|
||||
if (type == PacketType.PLAY_PLAYER_POSITION_REQUEST) return;
|
||||
|
||||
packet = type.name();
|
||||
}
|
||||
@ -121,6 +127,12 @@ public class ProtocolPipeline extends Protocol {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the pipeline contains a protocol
|
||||
*
|
||||
* @param pipeClass The class to check
|
||||
* @return True if the protocol class is in the pipeline
|
||||
*/
|
||||
public boolean contains(Class<? extends Protocol> pipeClass) {
|
||||
for (Protocol protocol : protocolList) {
|
||||
if (protocol.getClass().equals(pipeClass)) return true;
|
||||
@ -128,6 +140,14 @@ public class ProtocolPipeline extends Protocol {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Use the pipeline to filter a NMS packet
|
||||
*
|
||||
* @param o The NMS packet object
|
||||
* @param list The output list to write to
|
||||
* @return If it should not write the input object to te list.
|
||||
* @throws Exception If it failed to convert / packet cancelld.
|
||||
*/
|
||||
public boolean filter(Object o, List list) throws Exception {
|
||||
for (Protocol protocol : protocolList) {
|
||||
if (protocol.isFiltered(o.getClass())) {
|
||||
|
@ -1,8 +1,8 @@
|
||||
package us.myles.ViaVersion.api.protocol;
|
||||
|
||||
import us.myles.ViaVersion.api.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.*;
|
||||
|
||||
@ -17,6 +17,13 @@ public class ProtocolRegistry {
|
||||
registerProtocol(new Protocol1_9_1TO1_9(), Collections.singletonList(ProtocolVersion.V1_9_1_PRE2), ProtocolVersion.V1_9);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a protocol
|
||||
*
|
||||
* @param protocol The protocol to register.
|
||||
* @param supported Supported client versions.
|
||||
* @param output The output server version it converts to.
|
||||
*/
|
||||
public static void registerProtocol(Protocol protocol, List<Integer> supported, Integer output) {
|
||||
for (Integer version : supported) {
|
||||
if (!registryMap.containsKey(version)) {
|
||||
@ -27,6 +34,11 @@ public class ProtocolRegistry {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if this plugin is useful to the server.
|
||||
*
|
||||
* @return True if there is a useful pipe
|
||||
*/
|
||||
public static boolean isWorkingPipe() {
|
||||
for (Map<Integer, Protocol> maps : registryMap.values()) {
|
||||
if (maps.containsKey(SERVER_PROTOCOL)) return true;
|
||||
@ -34,6 +46,14 @@ public class ProtocolRegistry {
|
||||
return false; // No destination for protocol
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate a path to get from an input protocol to the servers protocol.
|
||||
*
|
||||
* @param current The current items in the path
|
||||
* @param clientVersion The current input version
|
||||
* @param serverVersion The desired output version
|
||||
* @return The path which has been generated, null if failed.
|
||||
*/
|
||||
private static List<Pair<Integer, Protocol>> getProtocolPath(List<Pair<Integer, Protocol>> current, int clientVersion, int serverVersion) {
|
||||
if (current.size() > 50) return null; // Fail safe, protocol too complicated.
|
||||
|
||||
@ -69,7 +89,15 @@ public class ProtocolRegistry {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate a path from a client version to server version
|
||||
*
|
||||
* @param clientVersion The input client version
|
||||
* @param serverVersion The desired output server version
|
||||
* @return The path it generated, null if it failed.
|
||||
*/
|
||||
public static List<Pair<Integer, Protocol>> getProtocolPath(int clientVersion, int serverVersion) {
|
||||
// TODO: Cache
|
||||
return getProtocolPath(new ArrayList<Pair<Integer, Protocol>>(), clientVersion, serverVersion);
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,12 @@ package us.myles.ViaVersion.api.remapper;
|
||||
import us.myles.ViaVersion.api.PacketWrapper;
|
||||
|
||||
public abstract class PacketHandler implements ValueWriter {
|
||||
/**
|
||||
* Handle a packet
|
||||
*
|
||||
* @param wrapper The associated wrapper
|
||||
* @throws Exception Throws exception if it failed to handle the packet
|
||||
*/
|
||||
public abstract void handle(PacketWrapper wrapper) throws Exception;
|
||||
|
||||
@Override
|
||||
|
@ -1,8 +1,8 @@
|
||||
package us.myles.ViaVersion.api.remapper;
|
||||
|
||||
import us.myles.ViaVersion.api.PacketWrapper;
|
||||
import us.myles.ViaVersion.api.type.Type;
|
||||
import us.myles.ViaVersion.api.Pair;
|
||||
import us.myles.ViaVersion.api.type.Type;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -14,33 +14,75 @@ public abstract class PacketRemapper {
|
||||
registerMap();
|
||||
}
|
||||
|
||||
/**
|
||||
* Map a type to the same type.
|
||||
*
|
||||
* @param type Type to map
|
||||
*/
|
||||
public void map(Type type) {
|
||||
TypeRemapper remapper = new TypeRemapper(type);
|
||||
map(remapper, remapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* Map a type from an old type to a new type
|
||||
*
|
||||
* @param oldType The old type
|
||||
* @param newType The new type
|
||||
*/
|
||||
public void map(Type oldType, Type newType) {
|
||||
map(new TypeRemapper(oldType), new TypeRemapper(newType));
|
||||
}
|
||||
|
||||
/**
|
||||
* Map a type from an old type to a transformed new type.
|
||||
*
|
||||
* @param oldType The old type
|
||||
* @param transformer The transformer to use to produce the new type.
|
||||
*/
|
||||
public <T1, T2> void map(Type<T1> oldType, ValueTransformer<T1, T2> transformer) {
|
||||
map(new TypeRemapper(oldType), transformer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Map a type using a basic ValueReader to a ValueWriter
|
||||
*
|
||||
* @param inputReader The reader to read with.
|
||||
* @param outputWriter The writer to write with.
|
||||
*/
|
||||
public <T> void map(ValueReader<T> inputReader, ValueWriter<T> outputWriter) {
|
||||
valueRemappers.add(new Pair<ValueReader, ValueWriter>(inputReader, outputWriter));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a value
|
||||
*
|
||||
* @param creator The creator to used to make the value(s).
|
||||
*/
|
||||
public void create(ValueCreator creator) {
|
||||
map(new TypeRemapper(Type.NOTHING), creator);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a handler
|
||||
*
|
||||
* @param handler The handler to use to handle the current packet.
|
||||
*/
|
||||
public void handler(PacketHandler handler) {
|
||||
map(new TypeRemapper(Type.NOTHING), handler);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the mappings for this packet
|
||||
*/
|
||||
public abstract void registerMap();
|
||||
|
||||
/**
|
||||
* Remap a packet wrapper
|
||||
*
|
||||
* @param packetWrapper The wrapper to remap
|
||||
* @throws Exception Throws if it fails to write / read to the packet.
|
||||
*/
|
||||
public void remap(PacketWrapper packetWrapper) throws Exception {
|
||||
// Read all the current values
|
||||
for (Pair<ValueReader, ValueWriter> valueRemapper : valueRemappers) {
|
||||
|
@ -3,6 +3,12 @@ package us.myles.ViaVersion.api.remapper;
|
||||
import us.myles.ViaVersion.api.PacketWrapper;
|
||||
|
||||
public abstract class ValueCreator implements ValueWriter {
|
||||
/**
|
||||
* Write new values to a Packet.
|
||||
*
|
||||
* @param wrapper The packet to write to
|
||||
* @throws Exception Throws exception if it fails to write.
|
||||
*/
|
||||
public abstract void write(PacketWrapper wrapper) throws Exception;
|
||||
|
||||
@Override
|
||||
|
@ -3,5 +3,12 @@ package us.myles.ViaVersion.api.remapper;
|
||||
import us.myles.ViaVersion.api.PacketWrapper;
|
||||
|
||||
public interface ValueReader<T> {
|
||||
/**
|
||||
* Reads value from a PacketWrapper
|
||||
*
|
||||
* @param wrapper The wrapper to read from
|
||||
* @return Returns the desired type
|
||||
* @throws Exception Throws exception if it fails to read
|
||||
*/
|
||||
T read(PacketWrapper wrapper) throws Exception;
|
||||
}
|
||||
|
@ -10,6 +10,14 @@ public abstract class ValueTransformer<T1, T2> implements ValueWriter<T1> {
|
||||
this.outputType = outputType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform a value from one type to another
|
||||
*
|
||||
* @param wrapper The current packet
|
||||
* @param inputValue The input value
|
||||
* @return The value to write to the wrapper
|
||||
* @throws Exception Throws exception if it fails to transform a value
|
||||
*/
|
||||
public abstract T2 transform(PacketWrapper wrapper, T1 inputValue) throws Exception;
|
||||
|
||||
@Override
|
||||
|
@ -3,5 +3,12 @@ package us.myles.ViaVersion.api.remapper;
|
||||
import us.myles.ViaVersion.api.PacketWrapper;
|
||||
|
||||
public interface ValueWriter<T> {
|
||||
/**
|
||||
* Write a value to a packet
|
||||
*
|
||||
* @param writer The packet wrapper to write to
|
||||
* @param inputValue The value to write
|
||||
* @throws Exception Throws exception if it fails to write
|
||||
*/
|
||||
void write(PacketWrapper writer, T inputValue) throws Exception;
|
||||
}
|
||||
|
@ -3,5 +3,12 @@ package us.myles.ViaVersion.api.type;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public interface ByteBufReader<T> {
|
||||
/**
|
||||
* Read a value from a ByteBuf
|
||||
*
|
||||
* @param buffer The buffer to read from.
|
||||
* @return The type based on the class type.
|
||||
* @throws Exception Throws exception if it failed reading.
|
||||
*/
|
||||
T read(ByteBuf buffer) throws Exception;
|
||||
}
|
||||
|
@ -3,5 +3,12 @@ package us.myles.ViaVersion.api.type;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public interface ByteBufWriter<T> {
|
||||
/**
|
||||
* Write an object to a type to a ByteBuf
|
||||
*
|
||||
* @param buffer The buffer to write to
|
||||
* @param object The object to write
|
||||
* @throws Exception Throws if it failed to write
|
||||
*/
|
||||
void write(ByteBuf buffer, T object) throws Exception;
|
||||
}
|
||||
|
@ -1,5 +1,11 @@
|
||||
package us.myles.ViaVersion.api.type;
|
||||
|
||||
public interface TypeConverter<T> {
|
||||
/**
|
||||
* Convert from a type to the current type
|
||||
*
|
||||
* @param o The input object
|
||||
* @return The converted type as an object
|
||||
*/
|
||||
T from(Object o);
|
||||
}
|
||||
|
@ -12,7 +12,6 @@ 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.protocols.protocol1_9to1_8.Protocol1_9TO1_8;
|
||||
|
||||
import java.util.*;
|
||||
|
@ -6,9 +6,9 @@ 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.protocols.base.ProtocolInfo;
|
||||
import us.myles.ViaVersion.util.PipelineUtil;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
@ -6,9 +6,9 @@ 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.protocols.base.ProtocolInfo;
|
||||
import us.myles.ViaVersion.util.PipelineUtil;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
@ -1,13 +1,12 @@
|
||||
package us.myles.ViaVersion.protocols.protocol1_9to1_8;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
@Getter
|
||||
public enum ArmorType {
|
||||
@ -34,21 +33,22 @@ public enum ArmorType {
|
||||
GOLD_BOOTS(1, 317, Material.GOLD_BOOTS),
|
||||
NONE(0, 0, Material.AIR);
|
||||
|
||||
private static HashMap<Material, ArmorType> armor;
|
||||
|
||||
static {
|
||||
armor = new HashMap<Material, ArmorType>();
|
||||
for (ArmorType a : ArmorType.values()) {
|
||||
armor.put(a.getType(), a);
|
||||
}
|
||||
}
|
||||
|
||||
private final int armorPoints;
|
||||
private final int id;
|
||||
private final Material type;
|
||||
|
||||
private static HashMap<Material, ArmorType> armor;
|
||||
static {
|
||||
armor = new HashMap<Material, ArmorType>();
|
||||
for(ArmorType a : ArmorType.values()) {
|
||||
armor.put(a.getType(), a);
|
||||
}
|
||||
}
|
||||
|
||||
public static ArmorType findByType(Material type) {
|
||||
ArmorType t = armor.get(type);
|
||||
return t == null ? ArmorType.NONE : t;
|
||||
ArmorType t = armor.get(type);
|
||||
return t == null ? ArmorType.NONE : t;
|
||||
}
|
||||
|
||||
public static int calculateArmorPoints(ItemStack[] armor) {
|
||||
|
@ -5,16 +5,15 @@ import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonObject;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
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.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.base.ProtocolInfo;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.listeners.ArmorListener;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.listeners.CommandBlockListener;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.packets.*;
|
||||
|
@ -21,7 +21,6 @@ import us.myles.ViaVersion.api.ViaVersion;
|
||||
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;
|
||||
|
||||
@ -35,9 +34,9 @@ public class ArmorListener implements Listener {
|
||||
|
||||
public static void sendArmorUpdate(Player player) {
|
||||
// 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;
|
||||
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 {
|
||||
|
@ -24,7 +24,6 @@ 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;
|
||||
|
||||
@ -61,9 +60,9 @@ public class CommandBlockListener implements Listener {
|
||||
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;
|
||||
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());
|
||||
@ -77,8 +76,8 @@ public class CommandBlockListener implements Listener {
|
||||
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;
|
||||
if (userConnection == null) return;
|
||||
if (!userConnection.get(ProtocolInfo.class).getPipeline().contains(Protocol1_9TO1_8.class)) return;
|
||||
|
||||
try {
|
||||
ByteBuf buf = Unpooled.buffer();
|
||||
|
@ -1,7 +1,6 @@
|
||||
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;
|
||||
@ -183,7 +182,7 @@ public class EntityPackets {
|
||||
EntityTracker tracker = wrapper.user().get(EntityTracker.class);
|
||||
if (tracker.getClientEntityTypes().containsKey(entityID)) {
|
||||
MetadataRewriter.transform(tracker.getClientEntityTypes().get(entityID), metadataList);
|
||||
} else if(!ViaVersion.getConfig().isUnknownEntitiesSuppressed()){
|
||||
} else if (!ViaVersion.getConfig().isUnknownEntitiesSuppressed()) {
|
||||
System.out.println("Unable to find entity for metadata, entity ID: " + entityID);
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,6 @@ 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.ViaVersionPlugin;
|
||||
import us.myles.ViaVersion.api.PacketWrapper;
|
||||
import us.myles.ViaVersion.api.ViaVersion;
|
||||
import us.myles.ViaVersion.api.minecraft.chunks.Chunk;
|
||||
|
@ -16,8 +16,8 @@ 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 us.myles.ViaVersion.protocols.base.ProtocolInfo;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user