Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-12-25 15:50:10 +01:00
Commit
ab9c0434e1
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>viaversion-parent</artifactId>
|
||||
<groupId>us.myles</groupId>
|
||||
<version>2.0.2-SNAPSHOT</version>
|
||||
<version>2.1.0-1.14.1-pre1</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
@ -67,9 +67,10 @@ public class PlayerSneakListener extends ViaBukkitListener {
|
||||
Player player = event.getPlayer();
|
||||
UserConnection userConnection = getUserConnection(player);
|
||||
if (userConnection == null) return;
|
||||
if (!userConnection.has(ProtocolInfo.class)) return;
|
||||
ProtocolInfo info = userConnection.get(ProtocolInfo.class);
|
||||
if (info == null) return;
|
||||
|
||||
int protocolVersion = userConnection.get(ProtocolInfo.class).getProtocolVersion();
|
||||
int protocolVersion = info.getProtocolVersion();
|
||||
if (is1_14Fix && protocolVersion >= ProtocolVersion.v1_14.getId()) {
|
||||
setHeight(player, event.isSneaking() ? HEIGHT_1_14 : STANDING_HEIGHT);
|
||||
if (!useCache) return;
|
||||
|
@ -9,6 +9,7 @@ import us.myles.ViaVersion.ViaVersionPlugin;
|
||||
import us.myles.ViaVersion.api.PacketWrapper;
|
||||
import us.myles.ViaVersion.api.Via;
|
||||
import us.myles.ViaVersion.api.ViaVersion;
|
||||
import us.myles.ViaVersion.api.data.UserConnection;
|
||||
import us.myles.ViaVersion.api.type.Type;
|
||||
import us.myles.ViaVersion.bukkit.listeners.ViaBukkitListener;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9To1_8;
|
||||
@ -38,8 +39,9 @@ public class DeathListener extends ViaBukkitListener {
|
||||
@Override
|
||||
public void run() {
|
||||
// If online
|
||||
if (getUserConnection(p) != null) {
|
||||
PacketWrapper wrapper = new PacketWrapper(0x2C, null, getUserConnection(p));
|
||||
UserConnection userConnection = getUserConnection(p);
|
||||
if (userConnection != null) {
|
||||
PacketWrapper wrapper = new PacketWrapper(0x2C, null, userConnection);
|
||||
try {
|
||||
wrapper.write(Type.VAR_INT, 2); // Event - Entity dead
|
||||
wrapper.write(Type.VAR_INT, p.getEntityId()); // Player ID
|
||||
|
@ -25,15 +25,16 @@ public class PaperPatch extends ViaBukkitListener {
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onPlace(BlockPlaceEvent e) {
|
||||
if (isOnPipe(e.getPlayer())) {
|
||||
Location diff = e.getPlayer().getLocation().subtract(e.getBlock().getLocation().add(0.5D, 0, 0.5D));
|
||||
Location location = e.getPlayer().getLocation();
|
||||
Location diff = location.clone().subtract(e.getBlock().getLocation().add(0.5D, 0, 0.5D));
|
||||
Material block = e.getBlockPlaced().getType();
|
||||
if (!block.isSolid()) {
|
||||
if (isPlacable(block)) {
|
||||
return;
|
||||
}
|
||||
if (e.getPlayer().getLocation().getBlock().equals(e.getBlock())) {
|
||||
if (location.getBlock().equals(e.getBlock())) {
|
||||
e.setCancelled(true);
|
||||
} else {
|
||||
if (e.getPlayer().getLocation().getBlock().getRelative(BlockFace.UP).equals(e.getBlock())) {
|
||||
if (location.getBlock().getRelative(BlockFace.UP).equals(e.getBlock())) {
|
||||
e.setCancelled(true);
|
||||
} else {
|
||||
// Within radius of block
|
||||
@ -55,4 +56,18 @@ public class PaperPatch extends ViaBukkitListener {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isPlacable(Material material) {
|
||||
if (!material.isSolid()) return true;
|
||||
// signs and banners
|
||||
switch (material.getId()) {
|
||||
case 63:
|
||||
case 68:
|
||||
case 176:
|
||||
case 177:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package us.myles.ViaVersion.bukkit.platform;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.Listener;
|
||||
@ -116,8 +117,9 @@ public class BukkitViaLoader implements ViaPlatformLoader {
|
||||
@Override
|
||||
public Item call() throws Exception {
|
||||
UUID playerUUID = info.get(ProtocolInfo.class).getUuid();
|
||||
if (Bukkit.getPlayer(playerUUID) != null) {
|
||||
return HandItemCache.convert(Bukkit.getPlayer(playerUUID).getItemInHand());
|
||||
Player player = Bukkit.getPlayer(playerUUID);
|
||||
if (player != null) {
|
||||
return HandItemCache.convert(player.getItemInHand());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>viaversion-parent</artifactId>
|
||||
<groupId>us.myles</groupId>
|
||||
<version>2.0.2-SNAPSHOT</version>
|
||||
<version>2.1.0-1.14.1-pre1</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
@ -5,6 +5,7 @@ import io.netty.channel.ChannelHandler;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.handler.codec.MessageToMessageEncoder;
|
||||
import us.myles.ViaVersion.api.PacketWrapper;
|
||||
import us.myles.ViaVersion.api.Via;
|
||||
import us.myles.ViaVersion.api.data.UserConnection;
|
||||
import us.myles.ViaVersion.api.type.Type;
|
||||
import us.myles.ViaVersion.bungee.util.BungeePipelineUtil;
|
||||
@ -28,7 +29,7 @@ public class BungeeEncodeHandler extends MessageToMessageEncoder<ByteBuf> {
|
||||
@Override
|
||||
protected void encode(final ChannelHandlerContext ctx, ByteBuf bytebuf, List<Object> out) throws Exception {
|
||||
if (bytebuf.readableBytes() == 0) {
|
||||
throw new CancelException();
|
||||
throw Via.getManager().isDebug() ? new CancelException() : CancelException.CACHED;
|
||||
}
|
||||
boolean needsCompress = false;
|
||||
if (!handledCompression) {
|
||||
|
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>viaversion-parent</artifactId>
|
||||
<groupId>us.myles</groupId>
|
||||
<version>2.0.2-SNAPSHOT</version>
|
||||
<version>2.1.0-1.14.1-pre1</version>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
@ -10,10 +10,12 @@ import us.myles.ViaVersion.api.protocol.Protocol;
|
||||
import us.myles.ViaVersion.api.remapper.ValueCreator;
|
||||
import us.myles.ViaVersion.api.type.Type;
|
||||
import us.myles.ViaVersion.api.type.TypeConverter;
|
||||
import us.myles.ViaVersion.exception.CancelException;
|
||||
import us.myles.ViaVersion.exception.InformativeException;
|
||||
import us.myles.ViaVersion.packets.Direction;
|
||||
import us.myles.ViaVersion.packets.State;
|
||||
import us.myles.ViaVersion.protocols.base.ProtocolInfo;
|
||||
import us.myles.ViaVersion.util.PipelineUtil;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
@ -298,8 +300,14 @@ public class PacketWrapper {
|
||||
*/
|
||||
public void send(Class<? extends Protocol> packetProtocol, boolean skipCurrentPipeline, boolean currentThread) throws Exception {
|
||||
if (!isCancelled()) {
|
||||
ByteBuf output = constructPacket(packetProtocol, skipCurrentPipeline, Direction.OUTGOING);
|
||||
user().sendRawPacket(output, currentThread);
|
||||
try {
|
||||
ByteBuf output = constructPacket(packetProtocol, skipCurrentPipeline, Direction.OUTGOING);
|
||||
user().sendRawPacket(output, currentThread);
|
||||
} catch (Exception e) {
|
||||
if (!PipelineUtil.containsCause(e, CancelException.class)) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -493,8 +501,14 @@ public class PacketWrapper {
|
||||
*/
|
||||
public void sendToServer(Class<? extends Protocol> packetProtocol, boolean skipCurrentPipeline, boolean currentThread) throws Exception {
|
||||
if (!isCancelled()) {
|
||||
ByteBuf output = constructPacket(packetProtocol, skipCurrentPipeline, Direction.INCOMING);
|
||||
user().sendRawPacketToServer(output, currentThread);
|
||||
try {
|
||||
ByteBuf output = constructPacket(packetProtocol, skipCurrentPipeline, Direction.INCOMING);
|
||||
user().sendRawPacketToServer(output, currentThread);
|
||||
} catch (Exception e) {
|
||||
if (!PipelineUtil.containsCause(e, CancelException.class)) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -214,32 +214,41 @@ public class UserConnection {
|
||||
public void sendRawPacketToServer(final ByteBuf packet, boolean currentThread) {
|
||||
final ByteBuf buf = packet.alloc().buffer();
|
||||
try {
|
||||
Type.VAR_INT.write(buf, PacketWrapper.PASSTHROUGH_ID);
|
||||
} catch (Exception e) {
|
||||
// Should not happen
|
||||
Via.getPlatform().getLogger().warning("Type.VAR_INT.write thrown an exception: " + e);
|
||||
}
|
||||
buf.writeBytes(packet);
|
||||
packet.release();
|
||||
final ChannelHandlerContext context = PipelineUtil
|
||||
.getPreviousContext(Via.getManager().getInjector().getDecoderName(), getChannel().pipeline());
|
||||
if (currentThread) {
|
||||
if (context != null) {
|
||||
context.fireChannelRead(buf);
|
||||
} else {
|
||||
getChannel().pipeline().fireChannelRead(buf);
|
||||
try {
|
||||
Type.VAR_INT.write(buf, PacketWrapper.PASSTHROUGH_ID);
|
||||
} catch (Exception e) {
|
||||
// Should not happen
|
||||
Via.getPlatform().getLogger().warning("Type.VAR_INT.write thrown an exception: " + e);
|
||||
}
|
||||
} else {
|
||||
channel.eventLoop().submit(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (context != null) {
|
||||
context.fireChannelRead(buf);
|
||||
} else {
|
||||
getChannel().pipeline().fireChannelRead(buf);
|
||||
}
|
||||
buf.writeBytes(packet);
|
||||
final ChannelHandlerContext context = PipelineUtil
|
||||
.getPreviousContext(Via.getManager().getInjector().getDecoderName(), getChannel().pipeline());
|
||||
if (currentThread) {
|
||||
if (context != null) {
|
||||
context.fireChannelRead(buf);
|
||||
} else {
|
||||
getChannel().pipeline().fireChannelRead(buf);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
try {
|
||||
channel.eventLoop().submit(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (context != null) {
|
||||
context.fireChannelRead(buf);
|
||||
} else {
|
||||
getChannel().pipeline().fireChannelRead(buf);
|
||||
}
|
||||
}
|
||||
});
|
||||
} catch (Throwable t) {
|
||||
// Couldn't schedule
|
||||
buf.release();
|
||||
throw t;
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
packet.release();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5,6 +5,9 @@ import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import us.myles.ViaVersion.api.Via;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
// 1.10 Entity / Object ids
|
||||
public class Entity1_10Types {
|
||||
|
||||
@ -113,6 +116,8 @@ public class Entity1_10Types {
|
||||
PLAYER(-1, ENTITY_HUMAN),
|
||||
COMPLEX_PART(-1, ENTITY);
|
||||
|
||||
private static final Map<Integer, EntityType> TYPES = new HashMap<>();
|
||||
|
||||
private final int id;
|
||||
private final EntityType parent;
|
||||
|
||||
@ -121,15 +126,16 @@ public class Entity1_10Types {
|
||||
this.parent = null;
|
||||
}
|
||||
|
||||
static {
|
||||
for (EntityType type : EntityType.values()) {
|
||||
TYPES.put(type.id, type);
|
||||
}
|
||||
}
|
||||
|
||||
public static Optional<EntityType> findById(int id) {
|
||||
if (id == -1) // Check if this is called
|
||||
return Optional.absent();
|
||||
|
||||
for (EntityType ent : EntityType.values())
|
||||
if (ent.getId() == id)
|
||||
return Optional.of(ent);
|
||||
|
||||
return Optional.absent();
|
||||
return Optional.fromNullable(TYPES.get(id));
|
||||
}
|
||||
}
|
||||
|
||||
@ -162,18 +168,21 @@ public class Entity1_10Types {
|
||||
SPECTRAL_ARROW(91, EntityType.SPECTRAL_ARROW),
|
||||
DRAGON_FIREBALL(93, EntityType.DRAGON_FIREBALL);
|
||||
|
||||
private static final Map<Integer, ObjectTypes> TYPES = new HashMap<>();
|
||||
|
||||
private final int id;
|
||||
private final EntityType type;
|
||||
|
||||
static {
|
||||
for (ObjectTypes type : ObjectTypes.values()) {
|
||||
TYPES.put(type.id, type);
|
||||
}
|
||||
}
|
||||
|
||||
public static Optional<ObjectTypes> findById(int id) {
|
||||
if (id == -1)
|
||||
return Optional.absent();
|
||||
|
||||
for (ObjectTypes ent : ObjectTypes.values())
|
||||
if (ent.getId() == id)
|
||||
return Optional.of(ent);
|
||||
|
||||
return Optional.absent();
|
||||
return Optional.fromNullable(TYPES.get(id));
|
||||
}
|
||||
|
||||
public static Optional<EntityType> getPCEntity(int id) {
|
||||
|
@ -5,6 +5,9 @@ import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import us.myles.ViaVersion.api.Via;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
// 1.11 Entity / Object ids TODO maybe in the future instead of copying it, some api.
|
||||
public class Entity1_11Types {
|
||||
public static EntityType getTypeFromId(int typeID, boolean isObject) {
|
||||
@ -140,6 +143,8 @@ public class Entity1_11Types {
|
||||
COMPLEX_PART(-1, ENTITY),
|
||||
LIAMA_SPIT(-1, ENTITY);
|
||||
|
||||
private static final Map<Integer, EntityType> TYPES = new HashMap<>();
|
||||
|
||||
private final int id;
|
||||
private final EntityType parent;
|
||||
|
||||
@ -148,15 +153,16 @@ public class Entity1_11Types {
|
||||
this.parent = null;
|
||||
}
|
||||
|
||||
static {
|
||||
for (EntityType type : EntityType.values()) {
|
||||
TYPES.put(type.id, type);
|
||||
}
|
||||
}
|
||||
|
||||
public static Optional<EntityType> findById(int id) {
|
||||
if (id == -1) // Check if this is called
|
||||
return Optional.absent();
|
||||
|
||||
for (EntityType ent : EntityType.values())
|
||||
if (ent.getId() == id)
|
||||
return Optional.of(ent);
|
||||
|
||||
return Optional.absent();
|
||||
return Optional.fromNullable(TYPES.get(id));
|
||||
}
|
||||
|
||||
public boolean is(EntityType... types) {
|
||||
@ -215,18 +221,21 @@ public class Entity1_11Types {
|
||||
SPECTRAL_ARROW(91, EntityType.SPECTRAL_ARROW),
|
||||
DRAGON_FIREBALL(93, EntityType.DRAGON_FIREBALL);
|
||||
|
||||
private static final Map<Integer, ObjectTypes> TYPES = new HashMap<>();
|
||||
|
||||
private final int id;
|
||||
private final EntityType type;
|
||||
|
||||
static {
|
||||
for (ObjectTypes type : ObjectTypes.values()) {
|
||||
TYPES.put(type.id, type);
|
||||
}
|
||||
}
|
||||
|
||||
public static Optional<ObjectTypes> findById(int id) {
|
||||
if (id == -1)
|
||||
return Optional.absent();
|
||||
|
||||
for (ObjectTypes ent : ObjectTypes.values())
|
||||
if (ent.getId() == id)
|
||||
return Optional.of(ent);
|
||||
|
||||
return Optional.absent();
|
||||
return Optional.fromNullable(TYPES.get(id));
|
||||
}
|
||||
|
||||
public static Optional<EntityType> getPCEntity(int id) {
|
||||
|
@ -15,6 +15,9 @@ import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import us.myles.ViaVersion.api.Via;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
// 1.12 Entity / Object taken from https://github.com/Matsv/ViaBackwards/blob/master/core/src/main/java/nl/matsv/viabackwards/api/entities/types/EntityType1_12.java
|
||||
public class Entity1_12Types {
|
||||
public static EntityType getTypeFromId(int typeID, boolean isObject) {
|
||||
@ -153,6 +156,8 @@ public class Entity1_12Types {
|
||||
COMPLEX_PART(-1, ENTITY),
|
||||
LIAMA_SPIT(-1, ENTITY);
|
||||
|
||||
private static final Map<Integer, EntityType> TYPES = new HashMap<>();
|
||||
|
||||
private final int id;
|
||||
private final EntityType parent;
|
||||
|
||||
@ -161,15 +166,16 @@ public class Entity1_12Types {
|
||||
this.parent = null;
|
||||
}
|
||||
|
||||
static {
|
||||
for (EntityType type : EntityType.values()) {
|
||||
TYPES.put(type.id, type);
|
||||
}
|
||||
}
|
||||
|
||||
public static Optional<EntityType> findById(int id) {
|
||||
if (id == -1) // Check if this is called
|
||||
return Optional.absent();
|
||||
|
||||
for (EntityType ent : EntityType.values())
|
||||
if (ent.getId() == id)
|
||||
return Optional.of(ent);
|
||||
|
||||
return Optional.absent();
|
||||
return Optional.fromNullable(TYPES.get(id));
|
||||
}
|
||||
|
||||
public boolean is(EntityType... types) {
|
||||
@ -228,18 +234,21 @@ public class Entity1_12Types {
|
||||
SPECTRAL_ARROW(91, EntityType.SPECTRAL_ARROW),
|
||||
DRAGON_FIREBALL(93, EntityType.DRAGON_FIREBALL);
|
||||
|
||||
private static final Map<Integer, ObjectTypes> TYPES = new HashMap<>();
|
||||
|
||||
private final int id;
|
||||
private final EntityType type;
|
||||
|
||||
static {
|
||||
for (ObjectTypes type : ObjectTypes.values()) {
|
||||
TYPES.put(type.id, type);
|
||||
}
|
||||
}
|
||||
|
||||
public static Optional<ObjectTypes> findById(int id) {
|
||||
if (id == -1)
|
||||
return Optional.absent();
|
||||
|
||||
for (ObjectTypes ent : ObjectTypes.values())
|
||||
if (ent.getId() == id)
|
||||
return Optional.of(ent);
|
||||
|
||||
return Optional.absent();
|
||||
return Optional.fromNullable(TYPES.get(id));
|
||||
}
|
||||
|
||||
public static Optional<EntityType> getPCEntity(int id) {
|
||||
|
@ -5,6 +5,9 @@ import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import us.myles.ViaVersion.api.Via;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
// TODO auto generate 18w11a with PAaaS
|
||||
public class Entity1_13Types {
|
||||
@ -196,6 +199,7 @@ public class Entity1_13Types {
|
||||
SPAWNER_MINECART(44, MINECART_ABSTRACT), // amb
|
||||
BOAT(5, ENTITY); // alv
|
||||
|
||||
private static final Map<Integer, EntityType> TYPES = new HashMap<>();
|
||||
|
||||
private final int id;
|
||||
private final EntityType parent;
|
||||
@ -205,15 +209,16 @@ public class Entity1_13Types {
|
||||
this.parent = null;
|
||||
}
|
||||
|
||||
static {
|
||||
for (EntityType type : EntityType.values()) {
|
||||
TYPES.put(type.id, type);
|
||||
}
|
||||
}
|
||||
|
||||
public static Optional<EntityType> findById(int id) {
|
||||
if (id == -1) // Check if this is called
|
||||
return Optional.absent();
|
||||
|
||||
for (EntityType ent : EntityType.values())
|
||||
if (ent.getId() == id)
|
||||
return Optional.of(ent);
|
||||
|
||||
return Optional.absent();
|
||||
return Optional.fromNullable(TYPES.get(id));
|
||||
}
|
||||
|
||||
public boolean is(EntityType... types) {
|
||||
@ -273,18 +278,21 @@ public class Entity1_13Types {
|
||||
DRAGON_FIREBALL(93, EntityType.DRAGON_FIREBALL),
|
||||
TRIDENT(94, EntityType.TRIDENT);
|
||||
|
||||
private static final Map<Integer, ObjectTypes> TYPES = new HashMap<>();
|
||||
|
||||
private final int id;
|
||||
private final EntityType type;
|
||||
|
||||
static {
|
||||
for (ObjectTypes type : ObjectTypes.values()) {
|
||||
TYPES.put(type.id, type);
|
||||
}
|
||||
}
|
||||
|
||||
public static Optional<ObjectTypes> findById(int id) {
|
||||
if (id == -1)
|
||||
return Optional.absent();
|
||||
|
||||
for (ObjectTypes ent : ObjectTypes.values())
|
||||
if (ent.getId() == id)
|
||||
return Optional.of(ent);
|
||||
|
||||
return Optional.absent();
|
||||
return Optional.fromNullable(TYPES.get(id));
|
||||
}
|
||||
|
||||
public static Optional<EntityType> getPCEntity(int id) {
|
||||
|
@ -5,6 +5,9 @@ import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import us.myles.ViaVersion.api.Via;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
public class Entity1_14Types {
|
||||
public static EntityType getTypeFromId(int typeID) {
|
||||
@ -196,6 +199,8 @@ public class Entity1_14Types {
|
||||
BOAT(5, ENTITY),
|
||||
;
|
||||
|
||||
private static final Map<Integer, EntityType> TYPES = new HashMap<>();
|
||||
|
||||
private final int id;
|
||||
private final EntityType parent;
|
||||
|
||||
@ -204,15 +209,16 @@ public class Entity1_14Types {
|
||||
this.parent = null;
|
||||
}
|
||||
|
||||
static {
|
||||
for (EntityType type : EntityType.values()) {
|
||||
TYPES.put(type.id, type);
|
||||
}
|
||||
}
|
||||
|
||||
public static Optional<EntityType> findById(int id) {
|
||||
if (id == -1) // Check if this is called
|
||||
if (id == -1)
|
||||
return Optional.absent();
|
||||
|
||||
for (EntityType ent : EntityType.values())
|
||||
if (ent.getId() == id)
|
||||
return Optional.of(ent);
|
||||
|
||||
return Optional.absent();
|
||||
return Optional.fromNullable(TYPES.get(id));
|
||||
}
|
||||
|
||||
public boolean is(EntityType... types) {
|
||||
|
@ -92,8 +92,18 @@ public class ChunkSection {
|
||||
|
||||
public void setPaletteEntry(int index, int id) {
|
||||
if (index < 0 || index >= palette.size()) throw new IndexOutOfBoundsException();
|
||||
palette.set(index, id);
|
||||
int oldId = palette.set(index, id);
|
||||
if (oldId == id) return;
|
||||
inversePalette.put(id, index);
|
||||
if (inversePalette.get(oldId) == index) {
|
||||
inversePalette.remove(oldId);
|
||||
for (int i = 0; i < palette.size(); i++) {
|
||||
if (palette.get(i) == oldId) {
|
||||
inversePalette.put(oldId, i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void replacePaletteEntry(int oldId, int newId) {
|
||||
|
@ -167,8 +167,9 @@ public abstract class Protocol {
|
||||
// remap
|
||||
if (protocolPacket.getRemapper() != null) {
|
||||
protocolPacket.getRemapper().remap(packetWrapper);
|
||||
if (packetWrapper.isCancelled())
|
||||
throw new CancelException();
|
||||
if (packetWrapper.isCancelled()) {
|
||||
throw Via.getManager().isDebug() ? new CancelException() : CancelException.CACHED;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -15,6 +15,7 @@ import us.myles.ViaVersion.protocols.protocol1_12_2to1_12_1.Protocol1_12_2To1_12
|
||||
import us.myles.ViaVersion.protocols.protocol1_12to1_11_1.Protocol1_12To1_11_1;
|
||||
import us.myles.ViaVersion.protocols.protocol1_13_2to1_13_1.Protocol1_13_2To1_13_1;
|
||||
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.Protocol1_13To1_12_2;
|
||||
import us.myles.ViaVersion.protocols.protocol1_14_1to1_14.Protocol1_14_1To1_14;
|
||||
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.Protocol1_14To1_13_2;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9_1_2to1_9_3_4.Protocol1_9_1_2To1_9_3_4;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9_1to1_9.Protocol1_9_1To1_9;
|
||||
@ -62,6 +63,7 @@ public class ProtocolRegistry {
|
||||
registerProtocol(new Protocol1_13_2To1_13_1(), Arrays.asList(ProtocolVersion.v1_13_2.getId()), ProtocolVersion.v1_13_1.getId());
|
||||
|
||||
registerProtocol(new Protocol1_14To1_13_2(), Arrays.asList(ProtocolVersion.v1_14.getId()), ProtocolVersion.v1_13_2.getId());
|
||||
registerProtocol(new Protocol1_14_1To1_14(), Arrays.asList(ProtocolVersion.v1_14_1.getId()), ProtocolVersion.v1_14.getId());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -36,6 +36,7 @@ public class ProtocolVersion {
|
||||
public static final ProtocolVersion v1_13_1;
|
||||
public static final ProtocolVersion v1_13_2;
|
||||
public static final ProtocolVersion v1_14;
|
||||
public static final ProtocolVersion v1_14_1;
|
||||
public static final ProtocolVersion unknown;
|
||||
|
||||
private final int id;
|
||||
@ -68,6 +69,7 @@ public class ProtocolVersion {
|
||||
register(v1_13_1 = new ProtocolVersion(401, "1.13.1"));
|
||||
register(v1_13_2 = new ProtocolVersion(404, "1.13.2"));
|
||||
register(v1_14 = new ProtocolVersion(477, "1.14"));
|
||||
register(v1_14_1 = new ProtocolVersion(478, "1.14.1"));
|
||||
register(unknown = new ProtocolVersion(-1, "UNKNOWN"));
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,29 @@
|
||||
package us.myles.ViaVersion.exception;
|
||||
|
||||
public class CancelException extends Exception {
|
||||
public static final CancelException CACHED = new CancelException("Cached - Enable /viaver debug to not use cached exception") {
|
||||
@Override
|
||||
public synchronized Throwable fillInStackTrace() {
|
||||
return this;
|
||||
}
|
||||
};
|
||||
|
||||
public CancelException() {
|
||||
}
|
||||
|
||||
public CancelException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public CancelException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public CancelException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
public CancelException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
|
||||
super(message, cause, enableSuppression, writableStackTrace);
|
||||
}
|
||||
}
|
||||
|
@ -1144,15 +1144,15 @@ public class Protocol1_13To1_12_2 extends Protocol {
|
||||
userConnection.put(new BlockConnectionStorage(userConnection));
|
||||
}
|
||||
}
|
||||
if (Via.getConfig().get1_13TabCompleteDelay() > 0) {
|
||||
Via.getPlatform().runRepeatingSync(new TabCompleteThread(), 1L);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void register(ViaProviders providers) {
|
||||
providers.register(BlockEntityProvider.class, new BlockEntityProvider());
|
||||
providers.register(PaintingProvider.class, new PaintingProvider());
|
||||
if (Via.getConfig().get1_13TabCompleteDelay() > 0) {
|
||||
Via.getPlatform().runRepeatingSync(new TabCompleteThread(), 1L);
|
||||
}
|
||||
}
|
||||
|
||||
private int getNewSoundID(final int oldID) {
|
||||
|
@ -28,16 +28,18 @@ public class ConnectionData {
|
||||
static Set<Integer> occludingStates = new HashSet<>();
|
||||
|
||||
public static void update(UserConnection user, Position position) {
|
||||
BlockConnectionProvider connectionProvider = Via.getManager().getProviders().get(BlockConnectionProvider.class);
|
||||
for (BlockFace face : BlockFace.values()) {
|
||||
Position pos = new Position(
|
||||
position.getX() + face.getModX(),
|
||||
position.getY() + face.getModY(),
|
||||
position.getZ() + face.getModZ()
|
||||
);
|
||||
int blockState = Via.getManager().getProviders().get(BlockConnectionProvider.class).getBlockdata(user, pos);
|
||||
if (!connects(blockState)) continue;
|
||||
int newBlockState = connect(user, pos, blockState);
|
||||
int blockState = connectionProvider.getBlockdata(user, pos);
|
||||
ConnectionHandler handler = connectionHandlerMap.get(blockState);
|
||||
if (handler == null) continue;
|
||||
|
||||
int newBlockState = handler.connect(user, pos, blockState);
|
||||
PacketWrapper blockUpdatePacket = new PacketWrapper(0x0B, null, user);
|
||||
blockUpdatePacket.write(Type.POSITION, pos);
|
||||
blockUpdatePacket.write(Type.VAR_INT, newBlockState);
|
||||
@ -54,7 +56,7 @@ public class ConnectionData {
|
||||
for (int chunkDeltaZ = -1; chunkDeltaZ <= 1; chunkDeltaZ++) {
|
||||
if (Math.abs(chunkDeltaX) + Math.abs(chunkDeltaZ) == 0) continue;
|
||||
|
||||
ArrayList<BlockChangeRecord> updates = new ArrayList<>();
|
||||
List<BlockChangeRecord> updates = new ArrayList<>();
|
||||
|
||||
if (Math.abs(chunkDeltaX) + Math.abs(chunkDeltaZ) == 2) { // Corner
|
||||
for (int blockY = chunkSectionY * 16; blockY < chunkSectionY * 16 + 16; blockY++) {
|
||||
@ -116,7 +118,7 @@ public class ConnectionData {
|
||||
wrapper.write(Type.INT, chunkZ + chunkDeltaZ);
|
||||
wrapper.write(Type.BLOCK_CHANGE_RECORD_ARRAY, updates.toArray(new BlockChangeRecord[0]));
|
||||
try {
|
||||
wrapper.send(Protocol1_13To1_12_2.class);
|
||||
wrapper.send(Protocol1_13To1_12_2.class, true, true);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -127,9 +129,10 @@ public class ConnectionData {
|
||||
|
||||
public static void updateBlock(UserConnection user, Position pos, List<BlockChangeRecord> records) {
|
||||
int blockState = Via.getManager().getProviders().get(BlockConnectionProvider.class).getBlockdata(user, pos);
|
||||
if (!connects(blockState)) return;
|
||||
int newBlockState = connect(user, pos, blockState);
|
||||
ConnectionHandler handler = getConnectionHandler(blockState);
|
||||
if (handler == null) return;
|
||||
|
||||
int newBlockState = handler.connect(user, pos, blockState);
|
||||
records.add(new BlockChangeRecord((short) (((pos.getX() & 0xF) << 4) | (pos.getZ() & 0xF)), pos.getY().shortValue(), newBlockState));
|
||||
}
|
||||
|
||||
@ -181,14 +184,14 @@ public class ConnectionData {
|
||||
for (int x = 0; x < 16; x++) {
|
||||
int block = section.getFlatBlock(x, y, z);
|
||||
|
||||
if (ConnectionData.connects(block)) {
|
||||
block = ConnectionData.connect(user, new Position(xOff + x, yOff + y, zOff + z), block);
|
||||
ConnectionHandler handler = ConnectionData.getConnectionHandler(block);
|
||||
if (handler != null) {
|
||||
block = handler.connect(user, new Position(xOff + x, yOff + y, zOff + z), block);
|
||||
section.setFlatBlock(x, y, z, block);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
updateChunkSectionNeighbours(user, chunk.getX(), chunk.getZ(), i);
|
||||
}
|
||||
}
|
||||
|
||||
@ -270,12 +273,12 @@ public class ConnectionData {
|
||||
}
|
||||
|
||||
public static int connect(UserConnection user, Position position, int blockState) {
|
||||
if (connectionHandlerMap.containsKey(blockState)) {
|
||||
ConnectionHandler handler = connectionHandlerMap.get(blockState);
|
||||
return handler.connect(user, position, blockState);
|
||||
} else {
|
||||
return blockState;
|
||||
}
|
||||
ConnectionHandler handler = connectionHandlerMap.get(blockState);
|
||||
return handler != null ? handler.connect(user, position, blockState) : blockState;
|
||||
}
|
||||
|
||||
public static ConnectionHandler getConnectionHandler(int blockstate) {
|
||||
return connectionHandlerMap.get(blockstate);
|
||||
}
|
||||
|
||||
public static int getId(String key) {
|
||||
|
@ -16,6 +16,7 @@ import us.myles.ViaVersion.api.type.Type;
|
||||
import us.myles.ViaVersion.packets.State;
|
||||
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.Protocol1_13To1_12_2;
|
||||
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.blockconnections.ConnectionData;
|
||||
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.blockconnections.ConnectionHandler;
|
||||
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.MappingData;
|
||||
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.NamedSoundRewriter;
|
||||
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.Particle;
|
||||
@ -177,10 +178,7 @@ public class WorldPackets {
|
||||
if (Via.getConfig().isServersideBlockConnections()) {
|
||||
|
||||
ConnectionData.updateBlockStorage(userConnection, position, newId);
|
||||
|
||||
if (ConnectionData.connects(newId)) {
|
||||
newId = ConnectionData.connect(userConnection, position, newId);
|
||||
}
|
||||
newId = ConnectionData.connect(userConnection, position, newId);
|
||||
}
|
||||
wrapper.set(Type.VAR_INT, 0, checkStorage(wrapper.user(), position, newId));
|
||||
if (Via.getConfig().isServersideBlockConnections()) {
|
||||
@ -232,8 +230,9 @@ public class WorldPackets {
|
||||
(long) record.getY(),
|
||||
(long) (record.getHorizontal() & 15) + (chunkZ * 16));
|
||||
|
||||
if (ConnectionData.connects(blockState)) {
|
||||
blockState = ConnectionData.connect(userConnection, position, blockState);
|
||||
ConnectionHandler handler = ConnectionData.getConnectionHandler(blockState);
|
||||
if (handler != null) {
|
||||
blockState = handler.connect(userConnection, position, blockState);
|
||||
record.setBlockId(blockState);
|
||||
}
|
||||
}
|
||||
@ -367,10 +366,6 @@ public class WorldPackets {
|
||||
}
|
||||
}
|
||||
|
||||
if (Via.getConfig().isServersideBlockConnections()) {
|
||||
ConnectionData.connectBlocks(wrapper.user(), chunk);
|
||||
}
|
||||
|
||||
// Rewrite biome id 255 to plains
|
||||
if (chunk.isBiomeData()) {
|
||||
int latestBiomeWarn = Integer.MIN_VALUE;
|
||||
@ -406,6 +401,18 @@ public class WorldPackets {
|
||||
chunk.getSections()[y >> 4].setFlatBlock(x & 0xF, y & 0xF, z & 0xF, newId);
|
||||
}
|
||||
}
|
||||
|
||||
if (Via.getConfig().isServersideBlockConnections()) {
|
||||
ConnectionData.connectBlocks(wrapper.user(), chunk);
|
||||
// Workaround for packet order issue
|
||||
wrapper.send(Protocol1_13To1_12_2.class, true, true);
|
||||
wrapper.cancel();
|
||||
for (int i = 0; i < chunk.getSections().length; i++) {
|
||||
ChunkSection section = chunk.getSections()[i];
|
||||
if (section == null) continue;
|
||||
ConnectionData.updateChunkSectionNeighbours(wrapper.user(), chunk.getX(), chunk.getZ(), i);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -81,20 +81,23 @@ public class Chunk1_13Type extends PartialType<Chunk, ClientWorld> {
|
||||
Type.VAR_INT.write(output, chunk.getBitmask());
|
||||
|
||||
ByteBuf buf = output.alloc().buffer();
|
||||
for (int i = 0; i < 16; i++) {
|
||||
ChunkSection section = chunk.getSections()[i];
|
||||
if (section == null) continue; // Section not set
|
||||
Types1_13.CHUNK_SECTION.write(buf, section);
|
||||
section.writeBlockLight(buf);
|
||||
try {
|
||||
for (int i = 0; i < 16; i++) {
|
||||
ChunkSection section = chunk.getSections()[i];
|
||||
if (section == null) continue; // Section not set
|
||||
Types1_13.CHUNK_SECTION.write(buf, section);
|
||||
section.writeBlockLight(buf);
|
||||
|
||||
if (!section.hasSkyLight()) continue; // No sky light, we're done here.
|
||||
section.writeSkyLight(buf);
|
||||
if (!section.hasSkyLight()) continue; // No sky light, we're done here.
|
||||
section.writeSkyLight(buf);
|
||||
|
||||
}
|
||||
buf.readerIndex(0);
|
||||
Type.VAR_INT.write(output, buf.readableBytes() + (chunk.isBiomeData() ? 256 * 4 : 0));
|
||||
output.writeBytes(buf);
|
||||
} finally {
|
||||
buf.release(); // release buffer
|
||||
}
|
||||
buf.readerIndex(0);
|
||||
Type.VAR_INT.write(output, buf.readableBytes() + (chunk.isBiomeData() ? 256 * 4 : 0));
|
||||
output.writeBytes(buf);
|
||||
buf.release(); // release buffer
|
||||
|
||||
// Write biome data
|
||||
if (chunk.isBiomeData()) {
|
||||
|
@ -0,0 +1,33 @@
|
||||
package us.myles.ViaVersion.protocols.protocol1_14_1to1_14;
|
||||
|
||||
import us.myles.ViaVersion.api.Via;
|
||||
import us.myles.ViaVersion.api.data.UserConnection;
|
||||
import us.myles.ViaVersion.api.entities.Entity1_14Types;
|
||||
import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class MetadataRewriter {
|
||||
|
||||
public static void handleMetadata(int entityId, Entity1_14Types.EntityType type, List<Metadata> metadatas, UserConnection connection) {
|
||||
if (type == null) return;
|
||||
|
||||
for (Metadata metadata : new ArrayList<>(metadatas)) {
|
||||
try {
|
||||
if (type.is(Entity1_14Types.EntityType.VILLAGER) || type.is(Entity1_14Types.EntityType.WANDERING_TRADER)) {
|
||||
if (metadata.getId() >= 15) {
|
||||
metadata.setId(metadata.getId() + 1);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
metadatas.remove(metadata);
|
||||
if (!Via.getConfig().isSuppressMetadataErrors() || Via.getManager().isDebug()) {
|
||||
Via.getPlatform().getLogger().warning("An error occurred with entity metadata handler");
|
||||
Via.getPlatform().getLogger().warning("Metadata: " + metadata);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package us.myles.ViaVersion.protocols.protocol1_14_1to1_14;
|
||||
|
||||
import us.myles.ViaVersion.api.data.UserConnection;
|
||||
import us.myles.ViaVersion.api.protocol.Protocol;
|
||||
import us.myles.ViaVersion.protocols.protocol1_14_1to1_14.packets.EntityPackets;
|
||||
import us.myles.ViaVersion.protocols.protocol1_14_1to1_14.storage.EntityTracker;
|
||||
|
||||
public class Protocol1_14_1To1_14 extends Protocol {
|
||||
|
||||
@Override
|
||||
protected void registerPackets() {
|
||||
EntityPackets.register(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(UserConnection userConnection) {
|
||||
userConnection.put(new EntityTracker(userConnection));
|
||||
}
|
||||
}
|
@ -0,0 +1,101 @@
|
||||
package us.myles.ViaVersion.protocols.protocol1_14_1to1_14.packets;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
import us.myles.ViaVersion.api.PacketWrapper;
|
||||
import us.myles.ViaVersion.api.entities.Entity1_14Types;
|
||||
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.type.Type;
|
||||
import us.myles.ViaVersion.api.type.types.version.Types1_14;
|
||||
import us.myles.ViaVersion.packets.State;
|
||||
import us.myles.ViaVersion.protocols.protocol1_14_1to1_14.MetadataRewriter;
|
||||
import us.myles.ViaVersion.protocols.protocol1_14_1to1_14.storage.EntityTracker;
|
||||
|
||||
public class EntityPackets {
|
||||
|
||||
public static void register(Protocol protocol) {
|
||||
|
||||
// Spawn Mob
|
||||
protocol.registerOutgoing(State.PLAY, 0x03, 0x03, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
map(Type.VAR_INT); // 0 - Entity ID
|
||||
map(Type.UUID); // 1 - Entity UUID
|
||||
map(Type.VAR_INT); // 2 - Entity Type
|
||||
map(Type.DOUBLE); // 3 - X
|
||||
map(Type.DOUBLE); // 4 - Y
|
||||
map(Type.DOUBLE); // 5 - Z
|
||||
map(Type.BYTE); // 6 - Yaw
|
||||
map(Type.BYTE); // 7 - Pitch
|
||||
map(Type.BYTE); // 8 - Head Pitch
|
||||
map(Type.SHORT); // 9 - Velocity X
|
||||
map(Type.SHORT); // 10 - Velocity Y
|
||||
map(Type.SHORT); // 11 - Velocity Z
|
||||
map(Types1_14.METADATA_LIST); // 12 - Metadata
|
||||
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
int entityId = wrapper.get(Type.VAR_INT, 0);
|
||||
int type = wrapper.get(Type.VAR_INT, 1);
|
||||
|
||||
Entity1_14Types.EntityType entType = Entity1_14Types.getTypeFromId(type);
|
||||
|
||||
// Register Type ID
|
||||
wrapper.user().get(EntityTracker.class).addEntity(entityId, entType);
|
||||
|
||||
MetadataRewriter.handleMetadata(entityId, entType, wrapper.get(Types1_14.METADATA_LIST, 0), wrapper.user());
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Spawn Player
|
||||
protocol.registerOutgoing(State.PLAY, 0x05, 0x05, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
map(Type.VAR_INT); // 0 - Entity ID
|
||||
map(Type.UUID); // 1 - Player UUID
|
||||
map(Type.DOUBLE); // 2 - X
|
||||
map(Type.DOUBLE); // 3 - Y
|
||||
map(Type.DOUBLE); // 4 - Z
|
||||
map(Type.BYTE); // 5 - Yaw
|
||||
map(Type.BYTE); // 6 - Pitch
|
||||
map(Types1_14.METADATA_LIST); // 7 - Metadata
|
||||
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
int entityId = wrapper.get(Type.VAR_INT, 0);
|
||||
|
||||
Entity1_14Types.EntityType entType = Entity1_14Types.EntityType.PLAYER;
|
||||
|
||||
// Register Type ID
|
||||
wrapper.user().get(EntityTracker.class).addEntity(entityId, entType);
|
||||
MetadataRewriter.handleMetadata(entityId, entType, wrapper.get(Types1_14.METADATA_LIST, 0), wrapper.user());
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Entity Metadata
|
||||
protocol.registerOutgoing(State.PLAY, 0x43, 0x43, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
map(Type.VAR_INT); // 0 - Entity ID
|
||||
map(Types1_14.METADATA_LIST); // 1 - Metadata list
|
||||
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
int entityId = wrapper.get(Type.VAR_INT, 0);
|
||||
|
||||
Optional<Entity1_14Types.EntityType> type = wrapper.user().get(EntityTracker.class).get(entityId);
|
||||
MetadataRewriter.handleMetadata(entityId, type.orNull(), wrapper.get(Types1_14.METADATA_LIST, 0), wrapper.user());
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
package us.myles.ViaVersion.protocols.protocol1_14_1to1_14.storage;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import us.myles.ViaVersion.api.data.ExternalJoinGameListener;
|
||||
import us.myles.ViaVersion.api.data.StoredObject;
|
||||
import us.myles.ViaVersion.api.data.UserConnection;
|
||||
import us.myles.ViaVersion.api.entities.Entity1_14Types;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class EntityTracker extends StoredObject implements ExternalJoinGameListener {
|
||||
private final Map<Integer, Entity1_14Types.EntityType> clientEntityTypes = new ConcurrentHashMap<>();
|
||||
@Getter
|
||||
@Setter
|
||||
private int clientEntityId;
|
||||
|
||||
public EntityTracker(UserConnection user) {
|
||||
super(user);
|
||||
}
|
||||
|
||||
public void removeEntity(int entityId) {
|
||||
clientEntityTypes.remove(entityId);
|
||||
}
|
||||
|
||||
public void addEntity(int entityId, Entity1_14Types.EntityType type) {
|
||||
clientEntityTypes.put(entityId, type);
|
||||
}
|
||||
|
||||
public boolean has(int entityId) {
|
||||
return clientEntityTypes.containsKey(entityId);
|
||||
}
|
||||
|
||||
public Optional<Entity1_14Types.EntityType> get(int id) {
|
||||
return Optional.fromNullable(clientEntityTypes.get(id));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onExternalJoinGame(int playerEntityId) {
|
||||
clientEntityId = playerEntityId;
|
||||
clientEntityTypes.put(playerEntityId, Entity1_14Types.EntityType.PLAYER);
|
||||
}
|
||||
}
|
@ -47,13 +47,26 @@ public class MetadataRewriter {
|
||||
|
||||
if (type.isOrHasParent(Entity1_14Types.EntityType.ABSTRACT_INSENTIENT)) {
|
||||
if (metadata.getId() == 13) {
|
||||
tracker.setInsentientData(entityId, (byte) ((((Number)metadata.getValue()).byteValue() & ~0x4)
|
||||
tracker.setInsentientData(entityId, (byte) ((((Number) metadata.getValue()).byteValue() & ~0x4)
|
||||
| (tracker.getInsentientData(entityId) & 0x4))); // New attacking metadata
|
||||
metadata.setValue(tracker.getInsentientData(entityId));
|
||||
}
|
||||
}
|
||||
|
||||
if (type.isOrHasParent(Entity1_14Types.EntityType.ZOMBIE)) {
|
||||
if (type.isOrHasParent(Entity1_14Types.EntityType.PLAYER)) {
|
||||
if (entityId != tracker.getClientEntityId()) {
|
||||
if (metadata.getId() == 0) {
|
||||
byte flags = ((Number) metadata.getValue()).byteValue();
|
||||
// Mojang overrides the client-side pose updater, see OtherPlayerEntity#updateSize
|
||||
tracker.setEntityFlags(entityId, flags);
|
||||
} else if (metadata.getId() == 7) {
|
||||
tracker.setRiptide(entityId, (((Number) metadata.getValue()).byteValue() & 0x4) != 0);
|
||||
}
|
||||
if (metadata.getId() == 0 || metadata.getId() == 7) {
|
||||
metadatas.add(new Metadata(6, MetaType1_14.Pose, recalculatePlayerPose(entityId, tracker)));
|
||||
}
|
||||
}
|
||||
} else if (type.isOrHasParent(Entity1_14Types.EntityType.ZOMBIE)) {
|
||||
if (metadata.getId() == 16) {
|
||||
tracker.setInsentientData(entityId, (byte) ((tracker.getInsentientData(entityId) & ~0x4)
|
||||
| ((boolean) metadata.getValue() ? 0x4 : 0))); // New attacking
|
||||
@ -107,7 +120,8 @@ public class MetadataRewriter {
|
||||
}
|
||||
} else if (type.is(Entity1_14Types.EntityType.FIREWORKS_ROCKET)) {
|
||||
if (metadata.getId() == 8) {
|
||||
if (metadata.getValue().equals(0)) metadata.setValue(null); // https://bugs.mojang.com/browse/MC-111480
|
||||
if (metadata.getValue().equals(0))
|
||||
metadata.setValue(null); // https://bugs.mojang.com/browse/MC-111480
|
||||
metadata.setMetaType(MetaType1_14.OptVarInt);
|
||||
}
|
||||
} else if (type.isOrHasParent(Entity1_14Types.EntityType.ABSTRACT_SKELETON)) {
|
||||
@ -150,6 +164,14 @@ public class MetadataRewriter {
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isSneaking(byte flags) {
|
||||
return (flags & 0x2) != 0;
|
||||
}
|
||||
|
||||
private static boolean isSwimming(byte flags) {
|
||||
return (flags & 0x10) != 0;
|
||||
}
|
||||
|
||||
private static int getNewProfessionId(int old) {
|
||||
// profession -> career
|
||||
switch (old) {
|
||||
@ -170,6 +192,28 @@ public class MetadataRewriter {
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isFallFlying(int entityFlags) {
|
||||
return (entityFlags & 0x80) != 0;
|
||||
}
|
||||
|
||||
public static int recalculatePlayerPose(int entityId, EntityTracker tracker) {
|
||||
byte flags = tracker.getEntityFlags(entityId);
|
||||
// Mojang overrides the client-side pose updater, see OtherPlayerEntity#updateSize
|
||||
int pose = 0; // standing
|
||||
if (isFallFlying(flags)) {
|
||||
pose = 1;
|
||||
} else if (tracker.isSleeping(entityId)) {
|
||||
pose = 2;
|
||||
} else if (isSwimming(flags)) {
|
||||
pose = 3;
|
||||
} else if (tracker.isRiptide(entityId)) {
|
||||
pose = 4;
|
||||
} else if (isSneaking(flags)) {
|
||||
pose = 5;
|
||||
}
|
||||
return pose;
|
||||
}
|
||||
|
||||
public static int getNewParticleId(int id) {
|
||||
if (id >= 10) {
|
||||
id += 2; // new lava drips 10, 11
|
||||
|
@ -148,7 +148,7 @@ public class Protocol1_14To1_13_2 extends Protocol {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
int blockTagsSize = wrapper.read(Type.VAR_INT);
|
||||
wrapper.write(Type.VAR_INT, blockTagsSize + 3); // block tags
|
||||
wrapper.write(Type.VAR_INT, blockTagsSize + 5); // block tags
|
||||
for (int i = 0; i < blockTagsSize; i++) {
|
||||
wrapper.passthrough(Type.STRING);
|
||||
Integer[] blockIds = wrapper.passthrough(Type.VAR_INT_ARRAY);
|
||||
@ -169,8 +169,23 @@ public class Protocol1_14To1_13_2 extends Protocol {
|
||||
wrapper.write(Type.VAR_INT_ARRAY, new Integer[]{
|
||||
getNewBlockId(150)
|
||||
});
|
||||
// Fences and walls tags - used for block connections
|
||||
wrapper.write(Type.STRING, "minecraft:fences");
|
||||
wrapper.write(Type.VAR_INT_ARRAY, new Integer[]{
|
||||
189,
|
||||
248,
|
||||
472,
|
||||
473,
|
||||
474,
|
||||
475
|
||||
});
|
||||
wrapper.write(Type.STRING, "minecraft:walls");
|
||||
wrapper.write(Type.VAR_INT_ARRAY, new Integer[]{
|
||||
271,
|
||||
272,
|
||||
});
|
||||
int itemTagsSize = wrapper.read(Type.VAR_INT);
|
||||
wrapper.write(Type.VAR_INT, itemTagsSize + 1); // item tags
|
||||
wrapper.write(Type.VAR_INT, itemTagsSize + 2); // item tags
|
||||
for (int i = 0; i < itemTagsSize; i++) {
|
||||
wrapper.passthrough(Type.STRING);
|
||||
Integer[] itemIds = wrapper.passthrough(Type.VAR_INT_ARRAY);
|
||||
@ -183,6 +198,11 @@ public class Protocol1_14To1_13_2 extends Protocol {
|
||||
wrapper.write(Type.VAR_INT_ARRAY, new Integer[]{
|
||||
InventoryPackets.getNewItemId(541)
|
||||
});
|
||||
// Arrows tag (used by bow)
|
||||
wrapper.write(Type.STRING, "minecraft:arrows");
|
||||
wrapper.write(Type.VAR_INT_ARRAY, new Integer[]{
|
||||
526, 825, 826
|
||||
});
|
||||
int fluidTagsSize = wrapper.passthrough(Type.VAR_INT); // fluid tags
|
||||
for (int i = 0; i < fluidTagsSize; i++) {
|
||||
wrapper.passthrough(Type.STRING);
|
||||
|
@ -7,7 +7,6 @@ import java.util.Map;
|
||||
|
||||
public class EntityTypeRewriter {
|
||||
private static Map<Integer, Integer> entityTypes = new HashMap<>();
|
||||
private static Map<Integer, Integer> objectTypes = new HashMap<>();
|
||||
|
||||
static {
|
||||
regEnt(6, 7); // cave_spider
|
||||
@ -33,7 +32,8 @@ public class EntityTypeRewriter {
|
||||
regEnt(26, 28); // ghast
|
||||
regEnt(27, 29); // giant
|
||||
regEnt(28, 30); // guardian
|
||||
regEnt(29, 31); // husk
|
||||
regEnt(29, 31); // horse
|
||||
regEnt(30, 32); // husk
|
||||
regEnt(31, 33); // illusioner
|
||||
regEnt(32, 34); // item
|
||||
regEnt(33, 35); // item_frame
|
||||
|
@ -195,9 +195,16 @@ public class EntityPackets {
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
short animation = wrapper.passthrough(Type.UNSIGNED_BYTE);
|
||||
if (animation == 2) { //Leave bed
|
||||
EntityTracker tracker = wrapper.user().get(EntityTracker.class);
|
||||
int entityId = wrapper.get(Type.VAR_INT, 0);
|
||||
tracker.setSleeping(entityId, false);
|
||||
|
||||
PacketWrapper metadataPacket = wrapper.create(0x43);
|
||||
metadataPacket.write(Type.VAR_INT, wrapper.get(Type.VAR_INT, 0));
|
||||
metadataPacket.write(Type.VAR_INT, entityId);
|
||||
List<Metadata> metadataList = new LinkedList<>();
|
||||
if (tracker.getClientEntityId() != entityId) {
|
||||
metadataList.add(new Metadata(6, MetaType1_14.Pose, MetadataRewriter.recalculatePlayerPose(entityId, tracker)));
|
||||
}
|
||||
metadataList.add(new Metadata(12, MetaType1_14.OptPosition, null));
|
||||
metadataPacket.write(Types1_14.METADATA_LIST, metadataList);
|
||||
metadataPacket.send(Protocol1_14To1_13_2.class);
|
||||
@ -215,9 +222,16 @@ public class EntityPackets {
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
EntityTracker tracker = wrapper.user().get(EntityTracker.class);
|
||||
int entityId = wrapper.get(Type.VAR_INT, 0);
|
||||
tracker.setSleeping(entityId, true);
|
||||
|
||||
Position position = wrapper.read(Type.POSITION);
|
||||
List<Metadata> metadataList = new LinkedList<>();
|
||||
metadataList.add(new Metadata(12, MetaType1_14.OptPosition, position));
|
||||
if (tracker.getClientEntityId() != entityId) {
|
||||
metadataList.add(new Metadata(6, MetaType1_14.Pose, MetadataRewriter.recalculatePlayerPose(entityId, tracker)));
|
||||
}
|
||||
wrapper.write(Types1_14.METADATA_LIST, metadataList);
|
||||
}
|
||||
});
|
||||
|
@ -331,10 +331,12 @@ public class InventoryPackets {
|
||||
CompoundTag tag;
|
||||
if ((tag = item.getTag()) != null) {
|
||||
// Display Lore now uses JSON
|
||||
if (tag.get("display") instanceof CompoundTag) {
|
||||
CompoundTag display = tag.get("display");
|
||||
if (display.get("Lore") instanceof ListTag) {
|
||||
ListTag lore = display.get("Lore");
|
||||
Tag displayTag = tag.get("display");
|
||||
if (displayTag instanceof CompoundTag) {
|
||||
CompoundTag display = (CompoundTag) displayTag;
|
||||
Tag loreTag = display.get("Lore");
|
||||
if (loreTag instanceof ListTag) {
|
||||
ListTag lore = (ListTag) loreTag;
|
||||
display.put(ConverterRegistry.convertToTag(NBT_TAG_NAME + "|Lore", ConverterRegistry.convertToValue(lore)));
|
||||
for (Tag loreEntry : lore) {
|
||||
if (loreEntry instanceof StringTag) {
|
||||
@ -366,10 +368,12 @@ public class InventoryPackets {
|
||||
CompoundTag tag;
|
||||
if ((tag = item.getTag()) != null) {
|
||||
// Display Name now uses JSON
|
||||
if (tag.get("display") instanceof CompoundTag) {
|
||||
CompoundTag display = tag.get("display");
|
||||
if (((CompoundTag) tag.get("display")).get("Lore") instanceof ListTag) {
|
||||
ListTag lore = display.get("Lore");
|
||||
Tag displayTag = tag.get("display");
|
||||
if (displayTag instanceof CompoundTag) {
|
||||
CompoundTag display = (CompoundTag) displayTag;
|
||||
Tag loreTag = display.get("Lore");
|
||||
if (loreTag instanceof ListTag) {
|
||||
ListTag lore = (ListTag) loreTag;
|
||||
ListTag via = display.get(NBT_TAG_NAME + "|Lore");
|
||||
if (via != null) {
|
||||
display.put(ConverterRegistry.convertToTag("Lore", ConverterRegistry.convertToValue(via)));
|
||||
|
@ -3,7 +3,6 @@ package us.myles.ViaVersion.protocols.protocol1_14to1_13_2.packets;
|
||||
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.LongArrayTag;
|
||||
import com.google.common.primitives.Bytes;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import us.myles.ViaVersion.api.PacketWrapper;
|
||||
import us.myles.ViaVersion.api.entities.Entity1_14Types;
|
||||
import us.myles.ViaVersion.api.minecraft.BlockChangeRecord;
|
||||
@ -185,25 +184,15 @@ public class WorldPackets {
|
||||
}
|
||||
lightPacket.write(Type.VAR_INT, skyLightMask);
|
||||
lightPacket.write(Type.VAR_INT, blockLightMask);
|
||||
lightPacket.write(Type.VAR_INT, 0); //TODO find out what these two bitmasks mean
|
||||
lightPacket.write(Type.VAR_INT, 0); //TODO
|
||||
lightPacket.write(Type.VAR_INT, 0); // empty sky light mask
|
||||
lightPacket.write(Type.VAR_INT, 0); // empty block light mask
|
||||
for (ChunkSection section : chunk.getSections()) {
|
||||
if (section == null || !section.hasSkyLight()) continue;
|
||||
ByteBuf buf = wrapper.user().getChannel().alloc().buffer();
|
||||
section.writeSkyLight(buf);
|
||||
byte[] data = new byte[buf.readableBytes()];
|
||||
buf.readBytes(data);
|
||||
buf.release();
|
||||
lightPacket.write(Type.BYTE_ARRAY, Bytes.asList(data).toArray(new Byte[0]));
|
||||
lightPacket.write(Type.BYTE_ARRAY, Bytes.asList(section.getSkyLight()).toArray(new Byte[0]));
|
||||
}
|
||||
for (ChunkSection section : chunk.getSections()) {
|
||||
if (section == null) continue;
|
||||
ByteBuf buf = wrapper.user().getChannel().alloc().buffer();
|
||||
section.writeBlockLight(buf);
|
||||
byte[] data = new byte[buf.readableBytes()];
|
||||
buf.readBytes(data);
|
||||
buf.release();
|
||||
lightPacket.write(Type.BYTE_ARRAY, Bytes.asList(data).toArray(new Byte[0]));
|
||||
lightPacket.write(Type.BYTE_ARRAY, Bytes.asList(section.getBlockLight()).toArray(new Byte[0]));
|
||||
}
|
||||
|
||||
EntityTracker entityTracker = wrapper.user().get(EntityTracker.class);
|
||||
@ -220,7 +209,7 @@ public class WorldPackets {
|
||||
entityTracker.setChunkCenterZ(chunk.getZ());
|
||||
}
|
||||
|
||||
lightPacket.send(Protocol1_14To1_13_2.class, true, false);
|
||||
lightPacket.send(Protocol1_14To1_13_2.class, true, true);
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -302,7 +291,9 @@ public class WorldPackets {
|
||||
|
||||
Entity1_14Types.EntityType entType = Entity1_14Types.EntityType.PLAYER;
|
||||
// Register Type ID
|
||||
wrapper.user().get(EntityTracker.class).addEntity(entityId, entType);
|
||||
EntityTracker tracker = wrapper.user().get(EntityTracker.class);
|
||||
tracker.addEntity(entityId, entType);
|
||||
tracker.setClientEntityId(entityId);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -3,10 +3,14 @@ package us.myles.ViaVersion.protocols.protocol1_14to1_13_2.storage;
|
||||
import com.google.common.base.Optional;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import us.myles.ViaVersion.api.PacketWrapper;
|
||||
import us.myles.ViaVersion.api.data.ExternalJoinGameListener;
|
||||
import us.myles.ViaVersion.api.data.StoredObject;
|
||||
import us.myles.ViaVersion.api.data.UserConnection;
|
||||
import us.myles.ViaVersion.api.entities.Entity1_14Types;
|
||||
import us.myles.ViaVersion.api.type.Type;
|
||||
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.Protocol1_14To1_13_2;
|
||||
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.packets.WorldPackets;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
@ -14,11 +18,17 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
public class EntityTracker extends StoredObject implements ExternalJoinGameListener {
|
||||
private final Map<Integer, Entity1_14Types.EntityType> clientEntityTypes = new ConcurrentHashMap<>();
|
||||
private final Map<Integer, Byte> insentientData = new ConcurrentHashMap<>();
|
||||
// 0x1 = sleeping, 0x2 = riptide
|
||||
private final Map<Integer, Byte> sleepingAndRiptideData = new ConcurrentHashMap<>();
|
||||
private final Map<Integer, Byte> playerEntityFlags = new ConcurrentHashMap<>();
|
||||
@Getter
|
||||
@Setter
|
||||
private int latestTradeWindowId;
|
||||
@Getter
|
||||
@Setter
|
||||
private int clientEntityId;
|
||||
@Getter
|
||||
@Setter
|
||||
private boolean forceSendCenterChunk = true;
|
||||
@Getter
|
||||
@Setter
|
||||
@ -31,6 +41,8 @@ public class EntityTracker extends StoredObject implements ExternalJoinGameListe
|
||||
public void removeEntity(int entityId) {
|
||||
clientEntityTypes.remove(entityId);
|
||||
insentientData.remove(entityId);
|
||||
sleepingAndRiptideData.remove(entityId);
|
||||
playerEntityFlags.remove(entityId);
|
||||
}
|
||||
|
||||
public void addEntity(int entityId, Entity1_14Types.EntityType type) {
|
||||
@ -46,6 +58,37 @@ public class EntityTracker extends StoredObject implements ExternalJoinGameListe
|
||||
insentientData.put(entity, value);
|
||||
}
|
||||
|
||||
private static byte zeroIfNull(Byte val) {
|
||||
if (val == null) return 0;
|
||||
return val;
|
||||
}
|
||||
|
||||
public boolean isSleeping(int player) {
|
||||
return (zeroIfNull(sleepingAndRiptideData.get(player)) & 1) != 0;
|
||||
}
|
||||
|
||||
public void setSleeping(int player, boolean value) {
|
||||
byte newValue = (byte) ((zeroIfNull(sleepingAndRiptideData.get(player)) & ~1) | (value ? 1 : 0));
|
||||
if (newValue == 0) {
|
||||
sleepingAndRiptideData.remove(player);
|
||||
} else {
|
||||
sleepingAndRiptideData.put(player, newValue);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isRiptide(int player) {
|
||||
return (zeroIfNull(sleepingAndRiptideData.get(player)) & 2) != 0;
|
||||
}
|
||||
|
||||
public void setRiptide(int player, boolean value) {
|
||||
byte newValue = (byte) ((zeroIfNull(sleepingAndRiptideData.get(player)) & ~2) | (value ? 2 : 0));
|
||||
if (newValue == 0) {
|
||||
sleepingAndRiptideData.remove(player);
|
||||
} else {
|
||||
sleepingAndRiptideData.put(player, newValue);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean has(int entityId) {
|
||||
return clientEntityTypes.containsKey(entityId);
|
||||
}
|
||||
@ -56,6 +99,22 @@ public class EntityTracker extends StoredObject implements ExternalJoinGameListe
|
||||
|
||||
@Override
|
||||
public void onExternalJoinGame(int playerEntityId) {
|
||||
clientEntityId = playerEntityId;
|
||||
clientEntityTypes.put(playerEntityId, Entity1_14Types.EntityType.PLAYER);
|
||||
PacketWrapper setViewDistance = new PacketWrapper(0x41, null, getUser());
|
||||
setViewDistance.write(Type.VAR_INT, WorldPackets.SERVERSIDE_VIEW_DISTANCE);
|
||||
try {
|
||||
setViewDistance.send(Protocol1_14To1_13_2.class, true, true);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public byte getEntityFlags(int player) {
|
||||
return zeroIfNull(playerEntityFlags.get(player));
|
||||
}
|
||||
|
||||
public void setEntityFlags(int player, byte data) {
|
||||
playerEntityFlags.put(player, data);
|
||||
}
|
||||
}
|
||||
|
@ -81,16 +81,19 @@ public class Chunk1_14Type extends PartialType<Chunk, ClientWorld> {
|
||||
Type.NBT.write(output, chunk.getHeightMap());
|
||||
|
||||
ByteBuf buf = output.alloc().buffer();
|
||||
for (int i = 0; i < 16; i++) {
|
||||
ChunkSection section = chunk.getSections()[i];
|
||||
if (section == null) continue; // Section not set
|
||||
buf.writeShort(section.getNonAirBlocksCount());
|
||||
Types1_13.CHUNK_SECTION.write(buf, section);
|
||||
try {
|
||||
for (int i = 0; i < 16; i++) {
|
||||
ChunkSection section = chunk.getSections()[i];
|
||||
if (section == null) continue; // Section not set
|
||||
buf.writeShort(section.getNonAirBlocksCount());
|
||||
Types1_13.CHUNK_SECTION.write(buf, section);
|
||||
}
|
||||
buf.readerIndex(0);
|
||||
Type.VAR_INT.write(output, buf.readableBytes() + (chunk.isBiomeData() ? 256 * 4 : 0));
|
||||
output.writeBytes(buf);
|
||||
} finally {
|
||||
buf.release(); // release buffer
|
||||
}
|
||||
buf.readerIndex(0);
|
||||
Type.VAR_INT.write(output, buf.readableBytes() + (chunk.isBiomeData() ? 256 * 4 : 0));
|
||||
output.writeBytes(buf);
|
||||
buf.release(); // release buffer
|
||||
|
||||
// Write biome data
|
||||
if (chunk.isBiomeData()) {
|
||||
|
@ -82,20 +82,23 @@ public class Chunk1_9_3_4Type extends PartialType<Chunk, ClientWorld> {
|
||||
Type.VAR_INT.write(output, chunk.getBitmask());
|
||||
|
||||
ByteBuf buf = output.alloc().buffer();
|
||||
for (int i = 0; i < 16; i++) {
|
||||
ChunkSection section = chunk.getSections()[i];
|
||||
if (section == null) continue; // Section not set
|
||||
Types1_9.CHUNK_SECTION.write(buf, section);
|
||||
section.writeBlockLight(buf);
|
||||
try {
|
||||
for (int i = 0; i < 16; i++) {
|
||||
ChunkSection section = chunk.getSections()[i];
|
||||
if (section == null) continue; // Section not set
|
||||
Types1_9.CHUNK_SECTION.write(buf, section);
|
||||
section.writeBlockLight(buf);
|
||||
|
||||
if (!section.hasSkyLight()) continue; // No sky light, we're done here.
|
||||
section.writeSkyLight(buf);
|
||||
if (!section.hasSkyLight()) continue; // No sky light, we're done here.
|
||||
section.writeSkyLight(buf);
|
||||
|
||||
}
|
||||
buf.readerIndex(0);
|
||||
Type.VAR_INT.write(output, buf.readableBytes() + (chunk.isBiomeData() ? 256 : 0));
|
||||
output.writeBytes(buf);
|
||||
} finally {
|
||||
buf.release(); // release buffer
|
||||
}
|
||||
buf.readerIndex(0);
|
||||
Type.VAR_INT.write(output, buf.readableBytes() + (chunk.isBiomeData() ? 256 : 0));
|
||||
output.writeBytes(buf);
|
||||
buf.release(); // release buffer
|
||||
|
||||
// Write biome data
|
||||
if (chunk.isBiomeData()) {
|
||||
|
@ -78,20 +78,23 @@ public class Chunk1_9_1_2Type extends PartialType<Chunk, ClientWorld> {
|
||||
Type.VAR_INT.write(output, chunk.getBitmask());
|
||||
|
||||
ByteBuf buf = output.alloc().buffer();
|
||||
for (int i = 0; i < 16; i++) {
|
||||
ChunkSection section = chunk.getSections()[i];
|
||||
if (section == null) continue; // Section not set
|
||||
Types1_9.CHUNK_SECTION.write(buf, section);
|
||||
section.writeBlockLight(buf);
|
||||
try {
|
||||
for (int i = 0; i < 16; i++) {
|
||||
ChunkSection section = chunk.getSections()[i];
|
||||
if (section == null) continue; // Section not set
|
||||
Types1_9.CHUNK_SECTION.write(buf, section);
|
||||
section.writeBlockLight(buf);
|
||||
|
||||
if (!section.hasSkyLight()) continue; // No sky light, we're done here.
|
||||
section.writeSkyLight(buf);
|
||||
if (!section.hasSkyLight()) continue; // No sky light, we're done here.
|
||||
section.writeSkyLight(buf);
|
||||
|
||||
}
|
||||
buf.readerIndex(0);
|
||||
Type.VAR_INT.write(output, buf.readableBytes() + (chunk.isBiomeData() ? 256 : 0));
|
||||
output.writeBytes(buf);
|
||||
} finally {
|
||||
buf.release(); // release buffer
|
||||
}
|
||||
buf.readerIndex(0);
|
||||
Type.VAR_INT.write(output, buf.readableBytes() + (chunk.isBiomeData() ? 256 : 0));
|
||||
output.writeBytes(buf);
|
||||
buf.release(); // release buffer
|
||||
|
||||
// Write biome data
|
||||
if (chunk.isBiomeData()) {
|
||||
|
@ -4,6 +4,7 @@ import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
@Getter
|
||||
@ -31,7 +32,7 @@ public enum ArmorType {
|
||||
GOLD_BOOTS(1, 317, "minecraft:gold_boots"),
|
||||
NONE(0, 0, "none");
|
||||
|
||||
private static HashMap<Integer, ArmorType> armor;
|
||||
private static Map<Integer, ArmorType> armor;
|
||||
|
||||
static {
|
||||
armor = new HashMap<>();
|
||||
@ -51,10 +52,8 @@ public enum ArmorType {
|
||||
* @return Return the ArmourType, ArmourType.NONE if not found
|
||||
*/
|
||||
public static ArmorType findById(int id) {
|
||||
for (ArmorType a : ArmorType.values())
|
||||
if (a.getId() == id)
|
||||
return a;
|
||||
return ArmorType.NONE;
|
||||
ArmorType type = armor.get(id);
|
||||
return type == null ? ArmorType.NONE : type;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -77,10 +76,7 @@ public enum ArmorType {
|
||||
* @return True if the item is a piece of armour
|
||||
*/
|
||||
public static boolean isArmor(int id) {
|
||||
for (ArmorType a : ArmorType.values())
|
||||
if (a.getId() == id)
|
||||
return true;
|
||||
return false;
|
||||
return armor.containsKey(id);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -10,7 +10,8 @@ public class ViaIdleThread implements Runnable {
|
||||
@Override
|
||||
public void run() {
|
||||
for (UserConnection info : Via.getManager().getPortedPlayers().values()) {
|
||||
if (info.has(ProtocolInfo.class) && info.get(ProtocolInfo.class).getPipeline().contains(Protocol1_9To1_8.class)) {
|
||||
ProtocolInfo protocolInfo = info.get(ProtocolInfo.class);
|
||||
if (protocolInfo != null && protocolInfo.getPipeline().contains(Protocol1_9To1_8.class)) {
|
||||
long nextIdleUpdate = info.get(MovementTracker.class).getNextIdlePacket();
|
||||
if (nextIdleUpdate <= System.currentTimeMillis()) {
|
||||
if (info.getChannel().isOpen()) {
|
||||
|
@ -17,7 +17,6 @@ import us.myles.ViaVersion.api.type.Type;
|
||||
import us.myles.ViaVersion.packets.State;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.ItemRewriter;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9To1_8;
|
||||
import us.myles.ViaVersion.api.minecraft.chunks.Chunk1_8;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.BulkChunkTranslatorProvider;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.CommandBlockProvider;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.sounds.Effect;
|
||||
@ -163,11 +162,14 @@ public class WorldPackets {
|
||||
|
||||
PacketWrapper output = (PacketWrapper) obj;
|
||||
ByteBuf buffer = wrapper.user().getChannel().alloc().buffer();
|
||||
output.setId(-1); // -1 for no writing of id
|
||||
output.writeToBuffer(buffer);
|
||||
PacketWrapper chunkPacket = new PacketWrapper(0x21, buffer, wrapper.user());
|
||||
chunkPacket.send(Protocol1_9To1_8.class, false, true);
|
||||
buffer.release();
|
||||
try {
|
||||
output.setId(-1); // -1 for no writing of id
|
||||
output.writeToBuffer(buffer);
|
||||
PacketWrapper chunkPacket = new PacketWrapper(0x21, buffer, wrapper.user());
|
||||
chunkPacket.send(Protocol1_9To1_8.class, false, true);
|
||||
} finally {
|
||||
buffer.release();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -1,10 +1,11 @@
|
||||
package us.myles.ViaVersion.protocols.protocol1_9to1_8.sounds;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class Effect {
|
||||
|
||||
private final static HashMap<Integer, Integer> effects;
|
||||
private static final Map<Integer, Integer> effects;
|
||||
|
||||
static {
|
||||
effects = new HashMap<>();
|
||||
@ -29,9 +30,8 @@ public class Effect {
|
||||
}
|
||||
|
||||
public static int getNewId(int id) {
|
||||
if (!contains(id))
|
||||
return id;
|
||||
return effects.get(id);
|
||||
Integer newId = effects.get(id);
|
||||
return newId != null ? newId : id;
|
||||
}
|
||||
|
||||
public static boolean contains(int oldId) {
|
||||
|
@ -3,6 +3,7 @@ package us.myles.ViaVersion.protocols.protocol1_9to1_8.sounds;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Getter
|
||||
public enum SoundEffect {
|
||||
@ -259,7 +260,7 @@ public enum SoundEffect {
|
||||
private final SoundCategory category;
|
||||
private final boolean breaksound;
|
||||
|
||||
private static HashMap<String, SoundEffect> effects;
|
||||
private static Map<String, SoundEffect> effects;
|
||||
|
||||
static {
|
||||
effects = new HashMap<>();
|
||||
|
@ -141,20 +141,23 @@ public class Chunk1_9to1_8Type extends PartialType<Chunk, ClientChunks> {
|
||||
Type.VAR_INT.write(output, chunk.getBitmask());
|
||||
|
||||
ByteBuf buf = output.alloc().buffer();
|
||||
for (int i = 0; i < SECTION_COUNT; i++) {
|
||||
ChunkSection section = chunk.getSections()[i];
|
||||
if (section == null) continue; // Section not set
|
||||
Types1_9.CHUNK_SECTION.write(buf, section);
|
||||
section.writeBlockLight(buf);
|
||||
try {
|
||||
for (int i = 0; i < SECTION_COUNT; i++) {
|
||||
ChunkSection section = chunk.getSections()[i];
|
||||
if (section == null) continue; // Section not set
|
||||
Types1_9.CHUNK_SECTION.write(buf, section);
|
||||
section.writeBlockLight(buf);
|
||||
|
||||
if (!section.hasSkyLight()) continue; // No sky light, we're done here.
|
||||
section.writeSkyLight(buf);
|
||||
if (!section.hasSkyLight()) continue; // No sky light, we're done here.
|
||||
section.writeSkyLight(buf);
|
||||
|
||||
}
|
||||
buf.readerIndex(0);
|
||||
Type.VAR_INT.write(output, buf.readableBytes() + (chunk.hasBiomeData() ? 256 : 0));
|
||||
output.writeBytes(buf);
|
||||
} finally {
|
||||
buf.release(); // release buffer
|
||||
}
|
||||
buf.readerIndex(0);
|
||||
Type.VAR_INT.write(output, buf.readableBytes() + (chunk.hasBiomeData() ? 256 : 0));
|
||||
output.writeBytes(buf);
|
||||
buf.release(); // release buffer
|
||||
|
||||
// Write biome data
|
||||
if (chunk.hasBiomeData()) {
|
||||
|
@ -6,7 +6,6 @@ import io.netty.channel.ChannelPipeline;
|
||||
import io.netty.handler.codec.ByteToMessageDecoder;
|
||||
import io.netty.handler.codec.MessageToByteEncoder;
|
||||
import io.netty.handler.codec.MessageToMessageDecoder;
|
||||
import io.netty.handler.codec.MessageToMessageEncoder;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
@ -90,14 +89,15 @@ public class PipelineUtil {
|
||||
*
|
||||
* @param t The throwable
|
||||
* @param c The exception to look for
|
||||
* @return True if the stack trace contained it as its cause.
|
||||
* @return True if the stack trace contained it as its cause or if t is an instance of c.
|
||||
*/
|
||||
public static boolean containsCause(Throwable t, Class<? extends Throwable> c) {
|
||||
while (t != null) {
|
||||
t = t.getCause();
|
||||
if (t != null)
|
||||
do {
|
||||
if (t != null) {
|
||||
if (c.isAssignableFrom(t.getClass())) return true;
|
||||
}
|
||||
t = t.getCause();
|
||||
}
|
||||
} while (t != null);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
Datei-Diff unterdrückt, da er zu groß ist
Diff laden
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>viaversion-parent</artifactId>
|
||||
<groupId>us.myles</groupId>
|
||||
<version>2.0.2-SNAPSHOT</version>
|
||||
<version>2.1.0-1.14.1-pre1</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<name>viaversion-jar</name>
|
||||
|
2
pom.xml
2
pom.xml
@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>us.myles</groupId>
|
||||
<artifactId>viaversion-parent</artifactId>
|
||||
<version>2.0.2-SNAPSHOT</version>
|
||||
<version>2.1.0-1.14.1-pre1</version>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<name>viaversion-parent</name>
|
||||
|
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>viaversion-parent</artifactId>
|
||||
<groupId>us.myles</groupId>
|
||||
<version>2.0.2-SNAPSHOT</version>
|
||||
<version>2.1.0-1.14.1-pre1</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>viaversion-parent</artifactId>
|
||||
<groupId>us.myles</groupId>
|
||||
<version>2.0.2-SNAPSHOT</version>
|
||||
<version>2.1.0-1.14.1-pre1</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
@ -4,6 +4,7 @@ import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.handler.codec.MessageToByteEncoder;
|
||||
import us.myles.ViaVersion.api.PacketWrapper;
|
||||
import us.myles.ViaVersion.api.Via;
|
||||
import us.myles.ViaVersion.api.data.UserConnection;
|
||||
import us.myles.ViaVersion.api.type.Type;
|
||||
import us.myles.ViaVersion.exception.CancelException;
|
||||
@ -37,7 +38,7 @@ public class SpongeEncodeHandler extends MessageToByteEncoder {
|
||||
}
|
||||
}
|
||||
if (bytebuf.readableBytes() == 0) {
|
||||
throw new CancelException();
|
||||
throw Via.getManager().isDebug() ? new CancelException() : CancelException.CACHED;
|
||||
}
|
||||
// Increment sent
|
||||
info.incrementSent();
|
||||
|
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>viaversion-parent</artifactId>
|
||||
<groupId>us.myles</groupId>
|
||||
<version>2.0.2-SNAPSHOT</version>
|
||||
<version>2.1.0-1.14.1-pre1</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
@ -54,7 +54,7 @@
|
||||
<dependency>
|
||||
<groupId>com.velocitypowered</groupId>
|
||||
<artifactId>velocity-api</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
@ -11,7 +11,7 @@ import com.velocitypowered.api.plugin.annotation.DataDirectory;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import com.velocitypowered.api.proxy.ProxyServer;
|
||||
import lombok.Getter;
|
||||
import net.kyori.text.serializer.ComponentSerializers;
|
||||
import net.kyori.text.serializer.gson.GsonComponentSerializer;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import net.md_5.bungee.chat.ComponentSerializer;
|
||||
import org.slf4j.Logger;
|
||||
@ -148,7 +148,7 @@ public class VelocityPlugin implements ViaPlatform<Player> {
|
||||
@Override
|
||||
public void sendMessage(UUID uuid, String message) {
|
||||
PROXY.getPlayer(uuid).ifPresent(it -> it.sendMessage(
|
||||
ComponentSerializers.JSON.deserialize(
|
||||
GsonComponentSerializer.INSTANCE.deserialize(
|
||||
ComponentSerializer.toString(TextComponent.fromLegacyText(message)) // Fixes links
|
||||
)
|
||||
));
|
||||
@ -158,8 +158,8 @@ public class VelocityPlugin implements ViaPlatform<Player> {
|
||||
public boolean kickPlayer(UUID uuid, String message) {
|
||||
return PROXY.getPlayer(uuid).map(it -> {
|
||||
it.disconnect(
|
||||
ComponentSerializers.JSON.deserialize(
|
||||
ComponentSerializer.toString(TextComponent.fromLegacyText(message)) // ComponentSerializers.LEGACY is deprecated
|
||||
GsonComponentSerializer.INSTANCE.deserialize(
|
||||
ComponentSerializer.toString(TextComponent.fromLegacyText(message))
|
||||
)
|
||||
);
|
||||
return true;
|
||||
|
@ -3,7 +3,7 @@ package us.myles.ViaVersion.velocity.command;
|
||||
import com.velocitypowered.api.command.CommandSource;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import lombok.AllArgsConstructor;
|
||||
import net.kyori.text.serializer.ComponentSerializers;
|
||||
import net.kyori.text.serializer.gson.GsonComponentSerializer;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import net.md_5.bungee.chat.ComponentSerializer;
|
||||
import us.myles.ViaVersion.api.command.ViaCommandSender;
|
||||
@ -22,7 +22,7 @@ public class VelocityCommandSender implements ViaCommandSender {
|
||||
@Override
|
||||
public void sendMessage(String msg) {
|
||||
source.sendMessage(
|
||||
ComponentSerializers.JSON.deserialize(
|
||||
GsonComponentSerializer.INSTANCE.deserialize(
|
||||
ComponentSerializer.toString(TextComponent.fromLegacyText(msg)) // Fixes links
|
||||
)
|
||||
);
|
||||
|
@ -9,6 +9,7 @@ import io.netty.handler.codec.MessageToMessageEncoder;
|
||||
import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import us.myles.ViaVersion.api.PacketWrapper;
|
||||
import us.myles.ViaVersion.api.Via;
|
||||
import us.myles.ViaVersion.api.data.UserConnection;
|
||||
import us.myles.ViaVersion.api.type.Type;
|
||||
import us.myles.ViaVersion.exception.CancelException;
|
||||
@ -28,7 +29,7 @@ public class VelocityEncodeHandler extends MessageToMessageEncoder<ByteBuf> {
|
||||
@Override
|
||||
protected void encode(final ChannelHandlerContext ctx, ByteBuf bytebuf, List<Object> out) throws Exception {
|
||||
if (bytebuf.readableBytes() == 0) {
|
||||
throw new CancelException();
|
||||
throw Via.getManager().isDebug() ? new CancelException() : CancelException.CACHED;
|
||||
}
|
||||
boolean needsCompress = false;
|
||||
if (!handledCompression
|
||||
@ -76,8 +77,11 @@ public class VelocityEncodeHandler extends MessageToMessageEncoder<ByteBuf> {
|
||||
if (needsCompress) {
|
||||
ByteBuf old = bytebuf;
|
||||
bytebuf = ctx.alloc().buffer();
|
||||
PipelineUtil.callEncode((MessageToByteEncoder) ctx.pipeline().get("compression-encoder"), ctx, old, bytebuf);
|
||||
old.release();
|
||||
try {
|
||||
PipelineUtil.callEncode((MessageToByteEncoder) ctx.pipeline().get("compression-encoder"), ctx, old, bytebuf);
|
||||
} finally {
|
||||
old.release();
|
||||
}
|
||||
}
|
||||
out.add(bytebuf);
|
||||
}
|
||||
|
@ -100,99 +100,102 @@ public class VelocityServerHandler {
|
||||
|
||||
user.getVelocityLock().writeLock().lock();
|
||||
|
||||
VelocityStorage storage = user.get(VelocityStorage.class);
|
||||
try {
|
||||
VelocityStorage storage = user.get(VelocityStorage.class);
|
||||
|
||||
if (e.getServer() != null) {
|
||||
if (!e.getServer().getServerInfo().getName().equals(storage.getCurrentServer())) {
|
||||
String serverName = e.getServer().getServerInfo().getName();
|
||||
if (e.getServer() != null) {
|
||||
if (!e.getServer().getServerInfo().getName().equals(storage.getCurrentServer())) {
|
||||
String serverName = e.getServer().getServerInfo().getName();
|
||||
|
||||
storage.setCurrentServer(serverName);
|
||||
storage.setCurrentServer(serverName);
|
||||
|
||||
int protocolId = ProtocolDetectorService.getProtocolId(serverName);
|
||||
int protocolId = ProtocolDetectorService.getProtocolId(serverName);
|
||||
|
||||
if (protocolId <= ProtocolVersion.MINECRAFT_1_8.getProtocol()) { // 1.8 doesn't have BossBar packet
|
||||
if (storage.getBossbar() != null) {
|
||||
for (UUID uuid : storage.getBossbar()) {
|
||||
PacketWrapper wrapper = new PacketWrapper(0x0C, null, user);
|
||||
wrapper.write(Type.UUID, uuid);
|
||||
wrapper.write(Type.VAR_INT, 1); // remove
|
||||
wrapper.send(Protocol1_9To1_8.class, true, true);
|
||||
}
|
||||
storage.getBossbar().clear();
|
||||
}
|
||||
}
|
||||
|
||||
ProtocolInfo info = user.get(ProtocolInfo.class);
|
||||
int previousServerProtocol = info.getServerProtocolVersion();
|
||||
|
||||
// Refresh the pipes
|
||||
List<Pair<Integer, Protocol>> protocols = ProtocolRegistry.getProtocolPath(info.getProtocolVersion(), protocolId);
|
||||
ProtocolPipeline pipeline = user.get(ProtocolInfo.class).getPipeline();
|
||||
user.clearStoredObjects();
|
||||
pipeline.cleanPipes();
|
||||
if (protocols == null) {
|
||||
// TODO Check Bungee Supported Protocols? *shrugs*
|
||||
protocolId = info.getProtocolVersion();
|
||||
} else {
|
||||
for (Pair<Integer, Protocol> prot : protocols) {
|
||||
pipeline.add(prot.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
info.setServerProtocolVersion(protocolId);
|
||||
// Add version-specific base Protocol
|
||||
pipeline.add(ProtocolRegistry.getBaseProtocol(protocolId));
|
||||
|
||||
// Workaround 1.13 server change
|
||||
Object sessionHandler = ReflectionUtil.invoke(
|
||||
getMinecraftConnection.invoke(e.getPlayer()),
|
||||
"getSessionHandler"
|
||||
);
|
||||
|
||||
if (clientPlaySessionHandler.isInstance(sessionHandler)) { // It may be InitialConnectSessionHandler on the first server connection
|
||||
Set<String> knownChannels = (Set<String>) getKnownChannels.invoke(sessionHandler);
|
||||
if (previousServerProtocol != -1) {
|
||||
int id1_13 = ProtocolVersion.MINECRAFT_1_13.getProtocol();
|
||||
if (previousServerProtocol < id1_13 && protocolId >= id1_13) {
|
||||
ArrayList<String> newChannels = new ArrayList<>();
|
||||
for (String oldChannel : knownChannels) {
|
||||
String transformed = InventoryPackets.getNewPluginChannelId(oldChannel);
|
||||
if (transformed != null) {
|
||||
newChannels.add(transformed);
|
||||
}
|
||||
if (protocolId <= ProtocolVersion.MINECRAFT_1_8.getProtocol()) { // 1.8 doesn't have BossBar packet
|
||||
if (storage.getBossbar() != null) {
|
||||
for (UUID uuid : storage.getBossbar()) {
|
||||
PacketWrapper wrapper = new PacketWrapper(0x0C, null, user);
|
||||
wrapper.write(Type.UUID, uuid);
|
||||
wrapper.write(Type.VAR_INT, 1); // remove
|
||||
wrapper.send(Protocol1_9To1_8.class, true, true);
|
||||
}
|
||||
knownChannels.clear();
|
||||
knownChannels.addAll(newChannels);
|
||||
} else if (previousServerProtocol >= id1_13 && protocolId < id1_13) {
|
||||
ArrayList<String> newChannels = new ArrayList<>();
|
||||
for (String oldChannel : knownChannels) {
|
||||
String transformed = InventoryPackets.getOldPluginChannelId(oldChannel);
|
||||
if (transformed != null) {
|
||||
newChannels.add(transformed);
|
||||
}
|
||||
}
|
||||
knownChannels.clear();
|
||||
knownChannels.addAll(newChannels);
|
||||
storage.getBossbar().clear();
|
||||
}
|
||||
}
|
||||
|
||||
ProtocolInfo info = user.get(ProtocolInfo.class);
|
||||
int previousServerProtocol = info.getServerProtocolVersion();
|
||||
|
||||
// Refresh the pipes
|
||||
List<Pair<Integer, Protocol>> protocols = ProtocolRegistry.getProtocolPath(info.getProtocolVersion(), protocolId);
|
||||
ProtocolPipeline pipeline = user.get(ProtocolInfo.class).getPipeline();
|
||||
user.clearStoredObjects();
|
||||
pipeline.cleanPipes();
|
||||
if (protocols == null) {
|
||||
// TODO Check Bungee Supported Protocols? *shrugs*
|
||||
protocolId = info.getProtocolVersion();
|
||||
} else {
|
||||
for (Pair<Integer, Protocol> prot : protocols) {
|
||||
pipeline.add(prot.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
info.setServerProtocolVersion(protocolId);
|
||||
// Add version-specific base Protocol
|
||||
pipeline.add(ProtocolRegistry.getBaseProtocol(protocolId));
|
||||
|
||||
// Workaround 1.13 server change
|
||||
Object sessionHandler = ReflectionUtil.invoke(
|
||||
getMinecraftConnection.invoke(e.getPlayer()),
|
||||
"getSessionHandler"
|
||||
);
|
||||
|
||||
if (clientPlaySessionHandler.isInstance(sessionHandler)) { // It may be InitialConnectSessionHandler on the first server connection
|
||||
Set<String> knownChannels = (Set<String>) getKnownChannels.invoke(sessionHandler);
|
||||
if (previousServerProtocol != -1) {
|
||||
int id1_13 = ProtocolVersion.MINECRAFT_1_13.getProtocol();
|
||||
if (previousServerProtocol < id1_13 && protocolId >= id1_13) {
|
||||
ArrayList<String> newChannels = new ArrayList<>();
|
||||
for (String oldChannel : knownChannels) {
|
||||
String transformed = InventoryPackets.getNewPluginChannelId(oldChannel);
|
||||
if (transformed != null) {
|
||||
newChannels.add(transformed);
|
||||
}
|
||||
}
|
||||
knownChannels.clear();
|
||||
knownChannels.addAll(newChannels);
|
||||
} else if (previousServerProtocol >= id1_13 && protocolId < id1_13) {
|
||||
ArrayList<String> newChannels = new ArrayList<>();
|
||||
for (String oldChannel : knownChannels) {
|
||||
String transformed = InventoryPackets.getOldPluginChannelId(oldChannel);
|
||||
if (transformed != null) {
|
||||
newChannels.add(transformed);
|
||||
}
|
||||
}
|
||||
knownChannels.clear();
|
||||
knownChannels.addAll(newChannels);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
user.put(info);
|
||||
user.put(storage);
|
||||
|
||||
user.setActive(protocols != null);
|
||||
|
||||
// Init all protocols TODO check if this can get moved up to the previous for loop, and doesn't require the pipeline to already exist.
|
||||
for (Protocol protocol : pipeline.pipes()) {
|
||||
protocol.init(user);
|
||||
}
|
||||
|
||||
Object connection = getMinecraftConnection.invoke(e.getPlayer());
|
||||
ProtocolVersion version = (ProtocolVersion) getNextProtocolVersion.invoke(connection);
|
||||
setProtocolVersion.invoke(connection, version);
|
||||
}
|
||||
|
||||
user.put(info);
|
||||
user.put(storage);
|
||||
|
||||
user.setActive(protocols != null);
|
||||
|
||||
// Init all protocols TODO check if this can get moved up to the previous for loop, and doesn't require the pipeline to already exist.
|
||||
for (Protocol protocol : pipeline.pipes()) {
|
||||
protocol.init(user);
|
||||
}
|
||||
|
||||
Object connection = getMinecraftConnection.invoke(e.getPlayer());
|
||||
ProtocolVersion version = (ProtocolVersion) getNextProtocolVersion.invoke(connection);
|
||||
setProtocolVersion.invoke(connection, version);
|
||||
}
|
||||
} finally {
|
||||
user.getVelocityLock().writeLock().unlock();
|
||||
}
|
||||
user.getVelocityLock().writeLock().unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren