3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-11-08 17:20:24 +01:00

Merge pull request #1320 from Gerrygames/1.14.1

1.14.1
Dieser Commit ist enthalten in:
Myles 2019-05-07 17:23:20 +01:00 committet von GitHub
Commit ab9c0434e1
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
56 geänderte Dateien mit 830 neuen und 2986 gelöschten Zeilen

Datei anzeigen

@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>viaversion-parent</artifactId> <artifactId>viaversion-parent</artifactId>
<groupId>us.myles</groupId> <groupId>us.myles</groupId>
<version>2.0.2-SNAPSHOT</version> <version>2.1.0-1.14.1-pre1</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>

Datei anzeigen

@ -67,9 +67,10 @@ public class PlayerSneakListener extends ViaBukkitListener {
Player player = event.getPlayer(); Player player = event.getPlayer();
UserConnection userConnection = getUserConnection(player); UserConnection userConnection = getUserConnection(player);
if (userConnection == null) return; 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()) { if (is1_14Fix && protocolVersion >= ProtocolVersion.v1_14.getId()) {
setHeight(player, event.isSneaking() ? HEIGHT_1_14 : STANDING_HEIGHT); setHeight(player, event.isSneaking() ? HEIGHT_1_14 : STANDING_HEIGHT);
if (!useCache) return; if (!useCache) return;

Datei anzeigen

@ -9,6 +9,7 @@ import us.myles.ViaVersion.ViaVersionPlugin;
import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.ViaVersion; import us.myles.ViaVersion.api.ViaVersion;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.bukkit.listeners.ViaBukkitListener; import us.myles.ViaVersion.bukkit.listeners.ViaBukkitListener;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9To1_8; import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9To1_8;
@ -38,8 +39,9 @@ public class DeathListener extends ViaBukkitListener {
@Override @Override
public void run() { public void run() {
// If online // If online
if (getUserConnection(p) != null) { UserConnection userConnection = getUserConnection(p);
PacketWrapper wrapper = new PacketWrapper(0x2C, null, getUserConnection(p)); if (userConnection != null) {
PacketWrapper wrapper = new PacketWrapper(0x2C, null, userConnection);
try { try {
wrapper.write(Type.VAR_INT, 2); // Event - Entity dead wrapper.write(Type.VAR_INT, 2); // Event - Entity dead
wrapper.write(Type.VAR_INT, p.getEntityId()); // Player ID wrapper.write(Type.VAR_INT, p.getEntityId()); // Player ID

Datei anzeigen

@ -25,15 +25,16 @@ public class PaperPatch extends ViaBukkitListener {
@EventHandler(ignoreCancelled = true) @EventHandler(ignoreCancelled = true)
public void onPlace(BlockPlaceEvent e) { public void onPlace(BlockPlaceEvent e) {
if (isOnPipe(e.getPlayer())) { 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(); Material block = e.getBlockPlaced().getType();
if (!block.isSolid()) { if (isPlacable(block)) {
return; return;
} }
if (e.getPlayer().getLocation().getBlock().equals(e.getBlock())) { if (location.getBlock().equals(e.getBlock())) {
e.setCancelled(true); e.setCancelled(true);
} else { } else {
if (e.getPlayer().getLocation().getBlock().getRelative(BlockFace.UP).equals(e.getBlock())) { if (location.getBlock().getRelative(BlockFace.UP).equals(e.getBlock())) {
e.setCancelled(true); e.setCancelled(true);
} else { } else {
// Within radius of block // 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;
}
}
} }

Datei anzeigen

@ -1,6 +1,7 @@
package us.myles.ViaVersion.bukkit.platform; package us.myles.ViaVersion.bukkit.platform;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
@ -116,8 +117,9 @@ public class BukkitViaLoader implements ViaPlatformLoader {
@Override @Override
public Item call() throws Exception { public Item call() throws Exception {
UUID playerUUID = info.get(ProtocolInfo.class).getUuid(); UUID playerUUID = info.get(ProtocolInfo.class).getUuid();
if (Bukkit.getPlayer(playerUUID) != null) { Player player = Bukkit.getPlayer(playerUUID);
return HandItemCache.convert(Bukkit.getPlayer(playerUUID).getItemInHand()); if (player != null) {
return HandItemCache.convert(player.getItemInHand());
} }
return null; return null;
} }

Datei anzeigen

@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>viaversion-parent</artifactId> <artifactId>viaversion-parent</artifactId>
<groupId>us.myles</groupId> <groupId>us.myles</groupId>
<version>2.0.2-SNAPSHOT</version> <version>2.1.0-1.14.1-pre1</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>

Datei anzeigen

@ -5,6 +5,7 @@ import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToMessageEncoder; import io.netty.handler.codec.MessageToMessageEncoder;
import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.bungee.util.BungeePipelineUtil; import us.myles.ViaVersion.bungee.util.BungeePipelineUtil;
@ -28,7 +29,7 @@ public class BungeeEncodeHandler extends MessageToMessageEncoder<ByteBuf> {
@Override @Override
protected void encode(final ChannelHandlerContext ctx, ByteBuf bytebuf, List<Object> out) throws Exception { protected void encode(final ChannelHandlerContext ctx, ByteBuf bytebuf, List<Object> out) throws Exception {
if (bytebuf.readableBytes() == 0) { if (bytebuf.readableBytes() == 0) {
throw new CancelException(); throw Via.getManager().isDebug() ? new CancelException() : CancelException.CACHED;
} }
boolean needsCompress = false; boolean needsCompress = false;
if (!handledCompression) { if (!handledCompression) {

Datei anzeigen

@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>viaversion-parent</artifactId> <artifactId>viaversion-parent</artifactId>
<groupId>us.myles</groupId> <groupId>us.myles</groupId>
<version>2.0.2-SNAPSHOT</version> <version>2.1.0-1.14.1-pre1</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>

Datei anzeigen

@ -10,10 +10,12 @@ import us.myles.ViaVersion.api.protocol.Protocol;
import us.myles.ViaVersion.api.remapper.ValueCreator; import us.myles.ViaVersion.api.remapper.ValueCreator;
import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.api.type.TypeConverter; import us.myles.ViaVersion.api.type.TypeConverter;
import us.myles.ViaVersion.exception.CancelException;
import us.myles.ViaVersion.exception.InformativeException; import us.myles.ViaVersion.exception.InformativeException;
import us.myles.ViaVersion.packets.Direction; import us.myles.ViaVersion.packets.Direction;
import us.myles.ViaVersion.packets.State; import us.myles.ViaVersion.packets.State;
import us.myles.ViaVersion.protocols.base.ProtocolInfo; import us.myles.ViaVersion.protocols.base.ProtocolInfo;
import us.myles.ViaVersion.util.PipelineUtil;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
@ -298,8 +300,14 @@ public class PacketWrapper {
*/ */
public void send(Class<? extends Protocol> packetProtocol, boolean skipCurrentPipeline, boolean currentThread) throws Exception { public void send(Class<? extends Protocol> packetProtocol, boolean skipCurrentPipeline, boolean currentThread) throws Exception {
if (!isCancelled()) { if (!isCancelled()) {
try {
ByteBuf output = constructPacket(packetProtocol, skipCurrentPipeline, Direction.OUTGOING); ByteBuf output = constructPacket(packetProtocol, skipCurrentPipeline, Direction.OUTGOING);
user().sendRawPacket(output, currentThread); 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 { public void sendToServer(Class<? extends Protocol> packetProtocol, boolean skipCurrentPipeline, boolean currentThread) throws Exception {
if (!isCancelled()) { if (!isCancelled()) {
try {
ByteBuf output = constructPacket(packetProtocol, skipCurrentPipeline, Direction.INCOMING); ByteBuf output = constructPacket(packetProtocol, skipCurrentPipeline, Direction.INCOMING);
user().sendRawPacketToServer(output, currentThread); user().sendRawPacketToServer(output, currentThread);
} catch (Exception e) {
if (!PipelineUtil.containsCause(e, CancelException.class)) {
throw e;
}
}
} }
} }

Datei anzeigen

@ -213,6 +213,7 @@ public class UserConnection {
*/ */
public void sendRawPacketToServer(final ByteBuf packet, boolean currentThread) { public void sendRawPacketToServer(final ByteBuf packet, boolean currentThread) {
final ByteBuf buf = packet.alloc().buffer(); final ByteBuf buf = packet.alloc().buffer();
try {
try { try {
Type.VAR_INT.write(buf, PacketWrapper.PASSTHROUGH_ID); Type.VAR_INT.write(buf, PacketWrapper.PASSTHROUGH_ID);
} catch (Exception e) { } catch (Exception e) {
@ -220,7 +221,6 @@ public class UserConnection {
Via.getPlatform().getLogger().warning("Type.VAR_INT.write thrown an exception: " + e); Via.getPlatform().getLogger().warning("Type.VAR_INT.write thrown an exception: " + e);
} }
buf.writeBytes(packet); buf.writeBytes(packet);
packet.release();
final ChannelHandlerContext context = PipelineUtil final ChannelHandlerContext context = PipelineUtil
.getPreviousContext(Via.getManager().getInjector().getDecoderName(), getChannel().pipeline()); .getPreviousContext(Via.getManager().getInjector().getDecoderName(), getChannel().pipeline());
if (currentThread) { if (currentThread) {
@ -230,6 +230,7 @@ public class UserConnection {
getChannel().pipeline().fireChannelRead(buf); getChannel().pipeline().fireChannelRead(buf);
} }
} else { } else {
try {
channel.eventLoop().submit(new Runnable() { channel.eventLoop().submit(new Runnable() {
@Override @Override
public void run() { public void run() {
@ -240,6 +241,14 @@ public class UserConnection {
} }
} }
}); });
} catch (Throwable t) {
// Couldn't schedule
buf.release();
throw t;
}
}
} finally {
packet.release();
} }
} }

Datei anzeigen

@ -5,6 +5,9 @@ import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.Via;
import java.util.HashMap;
import java.util.Map;
// 1.10 Entity / Object ids // 1.10 Entity / Object ids
public class Entity1_10Types { public class Entity1_10Types {
@ -113,6 +116,8 @@ public class Entity1_10Types {
PLAYER(-1, ENTITY_HUMAN), PLAYER(-1, ENTITY_HUMAN),
COMPLEX_PART(-1, ENTITY); COMPLEX_PART(-1, ENTITY);
private static final Map<Integer, EntityType> TYPES = new HashMap<>();
private final int id; private final int id;
private final EntityType parent; private final EntityType parent;
@ -121,15 +126,16 @@ public class Entity1_10Types {
this.parent = null; this.parent = null;
} }
static {
for (EntityType type : EntityType.values()) {
TYPES.put(type.id, type);
}
}
public static Optional<EntityType> findById(int id) { public static Optional<EntityType> findById(int id) {
if (id == -1) // Check if this is called if (id == -1) // Check if this is called
return Optional.absent(); return Optional.absent();
return Optional.fromNullable(TYPES.get(id));
for (EntityType ent : EntityType.values())
if (ent.getId() == id)
return Optional.of(ent);
return Optional.absent();
} }
} }
@ -162,18 +168,21 @@ public class Entity1_10Types {
SPECTRAL_ARROW(91, EntityType.SPECTRAL_ARROW), SPECTRAL_ARROW(91, EntityType.SPECTRAL_ARROW),
DRAGON_FIREBALL(93, EntityType.DRAGON_FIREBALL); DRAGON_FIREBALL(93, EntityType.DRAGON_FIREBALL);
private static final Map<Integer, ObjectTypes> TYPES = new HashMap<>();
private final int id; private final int id;
private final EntityType type; private final EntityType type;
static {
for (ObjectTypes type : ObjectTypes.values()) {
TYPES.put(type.id, type);
}
}
public static Optional<ObjectTypes> findById(int id) { public static Optional<ObjectTypes> findById(int id) {
if (id == -1) if (id == -1)
return Optional.absent(); return Optional.absent();
return Optional.fromNullable(TYPES.get(id));
for (ObjectTypes ent : ObjectTypes.values())
if (ent.getId() == id)
return Optional.of(ent);
return Optional.absent();
} }
public static Optional<EntityType> getPCEntity(int id) { public static Optional<EntityType> getPCEntity(int id) {

Datei anzeigen

@ -5,6 +5,9 @@ import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
import us.myles.ViaVersion.api.Via; 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. // 1.11 Entity / Object ids TODO maybe in the future instead of copying it, some api.
public class Entity1_11Types { public class Entity1_11Types {
public static EntityType getTypeFromId(int typeID, boolean isObject) { public static EntityType getTypeFromId(int typeID, boolean isObject) {
@ -140,6 +143,8 @@ public class Entity1_11Types {
COMPLEX_PART(-1, ENTITY), COMPLEX_PART(-1, ENTITY),
LIAMA_SPIT(-1, ENTITY); LIAMA_SPIT(-1, ENTITY);
private static final Map<Integer, EntityType> TYPES = new HashMap<>();
private final int id; private final int id;
private final EntityType parent; private final EntityType parent;
@ -148,15 +153,16 @@ public class Entity1_11Types {
this.parent = null; this.parent = null;
} }
static {
for (EntityType type : EntityType.values()) {
TYPES.put(type.id, type);
}
}
public static Optional<EntityType> findById(int id) { public static Optional<EntityType> findById(int id) {
if (id == -1) // Check if this is called if (id == -1) // Check if this is called
return Optional.absent(); return Optional.absent();
return Optional.fromNullable(TYPES.get(id));
for (EntityType ent : EntityType.values())
if (ent.getId() == id)
return Optional.of(ent);
return Optional.absent();
} }
public boolean is(EntityType... types) { public boolean is(EntityType... types) {
@ -215,18 +221,21 @@ public class Entity1_11Types {
SPECTRAL_ARROW(91, EntityType.SPECTRAL_ARROW), SPECTRAL_ARROW(91, EntityType.SPECTRAL_ARROW),
DRAGON_FIREBALL(93, EntityType.DRAGON_FIREBALL); DRAGON_FIREBALL(93, EntityType.DRAGON_FIREBALL);
private static final Map<Integer, ObjectTypes> TYPES = new HashMap<>();
private final int id; private final int id;
private final EntityType type; private final EntityType type;
static {
for (ObjectTypes type : ObjectTypes.values()) {
TYPES.put(type.id, type);
}
}
public static Optional<ObjectTypes> findById(int id) { public static Optional<ObjectTypes> findById(int id) {
if (id == -1) if (id == -1)
return Optional.absent(); return Optional.absent();
return Optional.fromNullable(TYPES.get(id));
for (ObjectTypes ent : ObjectTypes.values())
if (ent.getId() == id)
return Optional.of(ent);
return Optional.absent();
} }
public static Optional<EntityType> getPCEntity(int id) { public static Optional<EntityType> getPCEntity(int id) {

Datei anzeigen

@ -15,6 +15,9 @@ import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
import us.myles.ViaVersion.api.Via; 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 // 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 class Entity1_12Types {
public static EntityType getTypeFromId(int typeID, boolean isObject) { public static EntityType getTypeFromId(int typeID, boolean isObject) {
@ -153,6 +156,8 @@ public class Entity1_12Types {
COMPLEX_PART(-1, ENTITY), COMPLEX_PART(-1, ENTITY),
LIAMA_SPIT(-1, ENTITY); LIAMA_SPIT(-1, ENTITY);
private static final Map<Integer, EntityType> TYPES = new HashMap<>();
private final int id; private final int id;
private final EntityType parent; private final EntityType parent;
@ -161,15 +166,16 @@ public class Entity1_12Types {
this.parent = null; this.parent = null;
} }
static {
for (EntityType type : EntityType.values()) {
TYPES.put(type.id, type);
}
}
public static Optional<EntityType> findById(int id) { public static Optional<EntityType> findById(int id) {
if (id == -1) // Check if this is called if (id == -1) // Check if this is called
return Optional.absent(); return Optional.absent();
return Optional.fromNullable(TYPES.get(id));
for (EntityType ent : EntityType.values())
if (ent.getId() == id)
return Optional.of(ent);
return Optional.absent();
} }
public boolean is(EntityType... types) { public boolean is(EntityType... types) {
@ -228,18 +234,21 @@ public class Entity1_12Types {
SPECTRAL_ARROW(91, EntityType.SPECTRAL_ARROW), SPECTRAL_ARROW(91, EntityType.SPECTRAL_ARROW),
DRAGON_FIREBALL(93, EntityType.DRAGON_FIREBALL); DRAGON_FIREBALL(93, EntityType.DRAGON_FIREBALL);
private static final Map<Integer, ObjectTypes> TYPES = new HashMap<>();
private final int id; private final int id;
private final EntityType type; private final EntityType type;
static {
for (ObjectTypes type : ObjectTypes.values()) {
TYPES.put(type.id, type);
}
}
public static Optional<ObjectTypes> findById(int id) { public static Optional<ObjectTypes> findById(int id) {
if (id == -1) if (id == -1)
return Optional.absent(); return Optional.absent();
return Optional.fromNullable(TYPES.get(id));
for (ObjectTypes ent : ObjectTypes.values())
if (ent.getId() == id)
return Optional.of(ent);
return Optional.absent();
} }
public static Optional<EntityType> getPCEntity(int id) { public static Optional<EntityType> getPCEntity(int id) {

Datei anzeigen

@ -5,6 +5,9 @@ import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.Via;
import java.util.HashMap;
import java.util.Map;
// TODO auto generate 18w11a with PAaaS // TODO auto generate 18w11a with PAaaS
public class Entity1_13Types { public class Entity1_13Types {
@ -196,6 +199,7 @@ public class Entity1_13Types {
SPAWNER_MINECART(44, MINECART_ABSTRACT), // amb SPAWNER_MINECART(44, MINECART_ABSTRACT), // amb
BOAT(5, ENTITY); // alv BOAT(5, ENTITY); // alv
private static final Map<Integer, EntityType> TYPES = new HashMap<>();
private final int id; private final int id;
private final EntityType parent; private final EntityType parent;
@ -205,15 +209,16 @@ public class Entity1_13Types {
this.parent = null; this.parent = null;
} }
static {
for (EntityType type : EntityType.values()) {
TYPES.put(type.id, type);
}
}
public static Optional<EntityType> findById(int id) { public static Optional<EntityType> findById(int id) {
if (id == -1) // Check if this is called if (id == -1) // Check if this is called
return Optional.absent(); return Optional.absent();
return Optional.fromNullable(TYPES.get(id));
for (EntityType ent : EntityType.values())
if (ent.getId() == id)
return Optional.of(ent);
return Optional.absent();
} }
public boolean is(EntityType... types) { public boolean is(EntityType... types) {
@ -273,18 +278,21 @@ public class Entity1_13Types {
DRAGON_FIREBALL(93, EntityType.DRAGON_FIREBALL), DRAGON_FIREBALL(93, EntityType.DRAGON_FIREBALL),
TRIDENT(94, EntityType.TRIDENT); TRIDENT(94, EntityType.TRIDENT);
private static final Map<Integer, ObjectTypes> TYPES = new HashMap<>();
private final int id; private final int id;
private final EntityType type; private final EntityType type;
static {
for (ObjectTypes type : ObjectTypes.values()) {
TYPES.put(type.id, type);
}
}
public static Optional<ObjectTypes> findById(int id) { public static Optional<ObjectTypes> findById(int id) {
if (id == -1) if (id == -1)
return Optional.absent(); return Optional.absent();
return Optional.fromNullable(TYPES.get(id));
for (ObjectTypes ent : ObjectTypes.values())
if (ent.getId() == id)
return Optional.of(ent);
return Optional.absent();
} }
public static Optional<EntityType> getPCEntity(int id) { public static Optional<EntityType> getPCEntity(int id) {

Datei anzeigen

@ -5,6 +5,9 @@ import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.Via;
import java.util.HashMap;
import java.util.Map;
public class Entity1_14Types { public class Entity1_14Types {
public static EntityType getTypeFromId(int typeID) { public static EntityType getTypeFromId(int typeID) {
@ -196,6 +199,8 @@ public class Entity1_14Types {
BOAT(5, ENTITY), BOAT(5, ENTITY),
; ;
private static final Map<Integer, EntityType> TYPES = new HashMap<>();
private final int id; private final int id;
private final EntityType parent; private final EntityType parent;
@ -204,15 +209,16 @@ public class Entity1_14Types {
this.parent = null; this.parent = null;
} }
static {
for (EntityType type : EntityType.values()) {
TYPES.put(type.id, type);
}
}
public static Optional<EntityType> findById(int id) { 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.absent();
return Optional.fromNullable(TYPES.get(id));
} }
public boolean is(EntityType... types) { public boolean is(EntityType... types) {

Datei anzeigen

@ -92,8 +92,18 @@ public class ChunkSection {
public void setPaletteEntry(int index, int id) { public void setPaletteEntry(int index, int id) {
if (index < 0 || index >= palette.size()) throw new IndexOutOfBoundsException(); 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); 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) { public void replacePaletteEntry(int oldId, int newId) {

Datei anzeigen

@ -167,8 +167,9 @@ public abstract class Protocol {
// remap // remap
if (protocolPacket.getRemapper() != null) { if (protocolPacket.getRemapper() != null) {
protocolPacket.getRemapper().remap(packetWrapper); protocolPacket.getRemapper().remap(packetWrapper);
if (packetWrapper.isCancelled()) if (packetWrapper.isCancelled()) {
throw new CancelException(); throw Via.getManager().isDebug() ? new CancelException() : CancelException.CACHED;
}
} }
} }

Datei anzeigen

@ -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_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_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_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_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_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; 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_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_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());
} }
/** /**

Datei anzeigen

@ -36,6 +36,7 @@ public class ProtocolVersion {
public static final ProtocolVersion v1_13_1; public static final ProtocolVersion v1_13_1;
public static final ProtocolVersion v1_13_2; public static final ProtocolVersion v1_13_2;
public static final ProtocolVersion v1_14; public static final ProtocolVersion v1_14;
public static final ProtocolVersion v1_14_1;
public static final ProtocolVersion unknown; public static final ProtocolVersion unknown;
private final int id; private final int id;
@ -68,6 +69,7 @@ public class ProtocolVersion {
register(v1_13_1 = new ProtocolVersion(401, "1.13.1")); register(v1_13_1 = new ProtocolVersion(401, "1.13.1"));
register(v1_13_2 = new ProtocolVersion(404, "1.13.2")); register(v1_13_2 = new ProtocolVersion(404, "1.13.2"));
register(v1_14 = new ProtocolVersion(477, "1.14")); register(v1_14 = new ProtocolVersion(477, "1.14"));
register(v1_14_1 = new ProtocolVersion(478, "1.14.1"));
register(unknown = new ProtocolVersion(-1, "UNKNOWN")); register(unknown = new ProtocolVersion(-1, "UNKNOWN"));
} }

Datei anzeigen

@ -1,4 +1,29 @@
package us.myles.ViaVersion.exception; package us.myles.ViaVersion.exception;
public class CancelException extends 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);
}
} }

Datei anzeigen

@ -1144,15 +1144,15 @@ public class Protocol1_13To1_12_2 extends Protocol {
userConnection.put(new BlockConnectionStorage(userConnection)); userConnection.put(new BlockConnectionStorage(userConnection));
} }
} }
if (Via.getConfig().get1_13TabCompleteDelay() > 0) {
Via.getPlatform().runRepeatingSync(new TabCompleteThread(), 1L);
}
} }
@Override @Override
protected void register(ViaProviders providers) { protected void register(ViaProviders providers) {
providers.register(BlockEntityProvider.class, new BlockEntityProvider()); providers.register(BlockEntityProvider.class, new BlockEntityProvider());
providers.register(PaintingProvider.class, new PaintingProvider()); providers.register(PaintingProvider.class, new PaintingProvider());
if (Via.getConfig().get1_13TabCompleteDelay() > 0) {
Via.getPlatform().runRepeatingSync(new TabCompleteThread(), 1L);
}
} }
private int getNewSoundID(final int oldID) { private int getNewSoundID(final int oldID) {

Datei anzeigen

@ -28,16 +28,18 @@ public class ConnectionData {
static Set<Integer> occludingStates = new HashSet<>(); static Set<Integer> occludingStates = new HashSet<>();
public static void update(UserConnection user, Position position) { public static void update(UserConnection user, Position position) {
BlockConnectionProvider connectionProvider = Via.getManager().getProviders().get(BlockConnectionProvider.class);
for (BlockFace face : BlockFace.values()) { for (BlockFace face : BlockFace.values()) {
Position pos = new Position( Position pos = new Position(
position.getX() + face.getModX(), position.getX() + face.getModX(),
position.getY() + face.getModY(), position.getY() + face.getModY(),
position.getZ() + face.getModZ() position.getZ() + face.getModZ()
); );
int blockState = Via.getManager().getProviders().get(BlockConnectionProvider.class).getBlockdata(user, pos); int blockState = connectionProvider.getBlockdata(user, pos);
if (!connects(blockState)) continue; ConnectionHandler handler = connectionHandlerMap.get(blockState);
int newBlockState = connect(user, pos, blockState); if (handler == null) continue;
int newBlockState = handler.connect(user, pos, blockState);
PacketWrapper blockUpdatePacket = new PacketWrapper(0x0B, null, user); PacketWrapper blockUpdatePacket = new PacketWrapper(0x0B, null, user);
blockUpdatePacket.write(Type.POSITION, pos); blockUpdatePacket.write(Type.POSITION, pos);
blockUpdatePacket.write(Type.VAR_INT, newBlockState); blockUpdatePacket.write(Type.VAR_INT, newBlockState);
@ -54,7 +56,7 @@ public class ConnectionData {
for (int chunkDeltaZ = -1; chunkDeltaZ <= 1; chunkDeltaZ++) { for (int chunkDeltaZ = -1; chunkDeltaZ <= 1; chunkDeltaZ++) {
if (Math.abs(chunkDeltaX) + Math.abs(chunkDeltaZ) == 0) continue; 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 if (Math.abs(chunkDeltaX) + Math.abs(chunkDeltaZ) == 2) { // Corner
for (int blockY = chunkSectionY * 16; blockY < chunkSectionY * 16 + 16; blockY++) { 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.INT, chunkZ + chunkDeltaZ);
wrapper.write(Type.BLOCK_CHANGE_RECORD_ARRAY, updates.toArray(new BlockChangeRecord[0])); wrapper.write(Type.BLOCK_CHANGE_RECORD_ARRAY, updates.toArray(new BlockChangeRecord[0]));
try { try {
wrapper.send(Protocol1_13To1_12_2.class); wrapper.send(Protocol1_13To1_12_2.class, true, true);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -127,9 +129,10 @@ public class ConnectionData {
public static void updateBlock(UserConnection user, Position pos, List<BlockChangeRecord> records) { public static void updateBlock(UserConnection user, Position pos, List<BlockChangeRecord> records) {
int blockState = Via.getManager().getProviders().get(BlockConnectionProvider.class).getBlockdata(user, pos); int blockState = Via.getManager().getProviders().get(BlockConnectionProvider.class).getBlockdata(user, pos);
if (!connects(blockState)) return; ConnectionHandler handler = getConnectionHandler(blockState);
int newBlockState = connect(user, pos, 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)); 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++) { for (int x = 0; x < 16; x++) {
int block = section.getFlatBlock(x, y, z); int block = section.getFlatBlock(x, y, z);
if (ConnectionData.connects(block)) { ConnectionHandler handler = ConnectionData.getConnectionHandler(block);
block = ConnectionData.connect(user, new Position(xOff + x, yOff + y, zOff + z), block); if (handler != null) {
block = handler.connect(user, new Position(xOff + x, yOff + y, zOff + z), block);
section.setFlatBlock(x, y, 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) { public static int connect(UserConnection user, Position position, int blockState) {
if (connectionHandlerMap.containsKey(blockState)) {
ConnectionHandler handler = connectionHandlerMap.get(blockState); ConnectionHandler handler = connectionHandlerMap.get(blockState);
return handler.connect(user, position, blockState); return handler != null ? handler.connect(user, position, blockState) : blockState;
} else {
return blockState;
} }
public static ConnectionHandler getConnectionHandler(int blockstate) {
return connectionHandlerMap.get(blockstate);
} }
public static int getId(String key) { public static int getId(String key) {

Datei anzeigen

@ -16,6 +16,7 @@ import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.packets.State; 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.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.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.MappingData;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.NamedSoundRewriter; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.NamedSoundRewriter;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.Particle; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.Particle;
@ -177,11 +178,8 @@ public class WorldPackets {
if (Via.getConfig().isServersideBlockConnections()) { if (Via.getConfig().isServersideBlockConnections()) {
ConnectionData.updateBlockStorage(userConnection, position, newId); 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)); wrapper.set(Type.VAR_INT, 0, checkStorage(wrapper.user(), position, newId));
if (Via.getConfig().isServersideBlockConnections()) { if (Via.getConfig().isServersideBlockConnections()) {
// Workaround for packet order issue // Workaround for packet order issue
@ -232,8 +230,9 @@ public class WorldPackets {
(long) record.getY(), (long) record.getY(),
(long) (record.getHorizontal() & 15) + (chunkZ * 16)); (long) (record.getHorizontal() & 15) + (chunkZ * 16));
if (ConnectionData.connects(blockState)) { ConnectionHandler handler = ConnectionData.getConnectionHandler(blockState);
blockState = ConnectionData.connect(userConnection, position, blockState); if (handler != null) {
blockState = handler.connect(userConnection, position, blockState);
record.setBlockId(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 // Rewrite biome id 255 to plains
if (chunk.isBiomeData()) { if (chunk.isBiomeData()) {
int latestBiomeWarn = Integer.MIN_VALUE; int latestBiomeWarn = Integer.MIN_VALUE;
@ -406,6 +401,18 @@ public class WorldPackets {
chunk.getSections()[y >> 4].setFlatBlock(x & 0xF, y & 0xF, z & 0xF, newId); 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);
}
}
} }
}); });
} }

Datei anzeigen

@ -81,6 +81,7 @@ public class Chunk1_13Type extends PartialType<Chunk, ClientWorld> {
Type.VAR_INT.write(output, chunk.getBitmask()); Type.VAR_INT.write(output, chunk.getBitmask());
ByteBuf buf = output.alloc().buffer(); ByteBuf buf = output.alloc().buffer();
try {
for (int i = 0; i < 16; i++) { for (int i = 0; i < 16; i++) {
ChunkSection section = chunk.getSections()[i]; ChunkSection section = chunk.getSections()[i];
if (section == null) continue; // Section not set if (section == null) continue; // Section not set
@ -94,7 +95,9 @@ public class Chunk1_13Type extends PartialType<Chunk, ClientWorld> {
buf.readerIndex(0); buf.readerIndex(0);
Type.VAR_INT.write(output, buf.readableBytes() + (chunk.isBiomeData() ? 256 * 4 : 0)); Type.VAR_INT.write(output, buf.readableBytes() + (chunk.isBiomeData() ? 256 * 4 : 0));
output.writeBytes(buf); output.writeBytes(buf);
} finally {
buf.release(); // release buffer buf.release(); // release buffer
}
// Write biome data // Write biome data
if (chunk.isBiomeData()) { if (chunk.isBiomeData()) {

Datei anzeigen

@ -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();
}
}
}
}
}

Datei anzeigen

@ -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));
}
}

Datei anzeigen

@ -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());
}
});
}
});
}
}

Datei anzeigen

@ -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);
}
}

Datei anzeigen

@ -47,13 +47,26 @@ public class MetadataRewriter {
if (type.isOrHasParent(Entity1_14Types.EntityType.ABSTRACT_INSENTIENT)) { if (type.isOrHasParent(Entity1_14Types.EntityType.ABSTRACT_INSENTIENT)) {
if (metadata.getId() == 13) { 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 | (tracker.getInsentientData(entityId) & 0x4))); // New attacking metadata
metadata.setValue(tracker.getInsentientData(entityId)); 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) { if (metadata.getId() == 16) {
tracker.setInsentientData(entityId, (byte) ((tracker.getInsentientData(entityId) & ~0x4) tracker.setInsentientData(entityId, (byte) ((tracker.getInsentientData(entityId) & ~0x4)
| ((boolean) metadata.getValue() ? 0x4 : 0))); // New attacking | ((boolean) metadata.getValue() ? 0x4 : 0))); // New attacking
@ -107,7 +120,8 @@ public class MetadataRewriter {
} }
} else if (type.is(Entity1_14Types.EntityType.FIREWORKS_ROCKET)) { } else if (type.is(Entity1_14Types.EntityType.FIREWORKS_ROCKET)) {
if (metadata.getId() == 8) { 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); metadata.setMetaType(MetaType1_14.OptVarInt);
} }
} else if (type.isOrHasParent(Entity1_14Types.EntityType.ABSTRACT_SKELETON)) { } 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) { private static int getNewProfessionId(int old) {
// profession -> career // profession -> career
switch (old) { 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) { public static int getNewParticleId(int id) {
if (id >= 10) { if (id >= 10) {
id += 2; // new lava drips 10, 11 id += 2; // new lava drips 10, 11

Datei anzeigen

@ -148,7 +148,7 @@ public class Protocol1_14To1_13_2 extends Protocol {
@Override @Override
public void handle(PacketWrapper wrapper) throws Exception { public void handle(PacketWrapper wrapper) throws Exception {
int blockTagsSize = wrapper.read(Type.VAR_INT); 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++) { for (int i = 0; i < blockTagsSize; i++) {
wrapper.passthrough(Type.STRING); wrapper.passthrough(Type.STRING);
Integer[] blockIds = wrapper.passthrough(Type.VAR_INT_ARRAY); 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[]{ wrapper.write(Type.VAR_INT_ARRAY, new Integer[]{
getNewBlockId(150) 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); 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++) { for (int i = 0; i < itemTagsSize; i++) {
wrapper.passthrough(Type.STRING); wrapper.passthrough(Type.STRING);
Integer[] itemIds = wrapper.passthrough(Type.VAR_INT_ARRAY); 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[]{ wrapper.write(Type.VAR_INT_ARRAY, new Integer[]{
InventoryPackets.getNewItemId(541) 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 int fluidTagsSize = wrapper.passthrough(Type.VAR_INT); // fluid tags
for (int i = 0; i < fluidTagsSize; i++) { for (int i = 0; i < fluidTagsSize; i++) {
wrapper.passthrough(Type.STRING); wrapper.passthrough(Type.STRING);

Datei anzeigen

@ -7,7 +7,6 @@ import java.util.Map;
public class EntityTypeRewriter { public class EntityTypeRewriter {
private static Map<Integer, Integer> entityTypes = new HashMap<>(); private static Map<Integer, Integer> entityTypes = new HashMap<>();
private static Map<Integer, Integer> objectTypes = new HashMap<>();
static { static {
regEnt(6, 7); // cave_spider regEnt(6, 7); // cave_spider
@ -33,7 +32,8 @@ public class EntityTypeRewriter {
regEnt(26, 28); // ghast regEnt(26, 28); // ghast
regEnt(27, 29); // giant regEnt(27, 29); // giant
regEnt(28, 30); // guardian regEnt(28, 30); // guardian
regEnt(29, 31); // husk regEnt(29, 31); // horse
regEnt(30, 32); // husk
regEnt(31, 33); // illusioner regEnt(31, 33); // illusioner
regEnt(32, 34); // item regEnt(32, 34); // item
regEnt(33, 35); // item_frame regEnt(33, 35); // item_frame

Datei anzeigen

@ -195,9 +195,16 @@ public class EntityPackets {
public void handle(PacketWrapper wrapper) throws Exception { public void handle(PacketWrapper wrapper) throws Exception {
short animation = wrapper.passthrough(Type.UNSIGNED_BYTE); short animation = wrapper.passthrough(Type.UNSIGNED_BYTE);
if (animation == 2) { //Leave bed 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); 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<>(); 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)); metadataList.add(new Metadata(12, MetaType1_14.OptPosition, null));
metadataPacket.write(Types1_14.METADATA_LIST, metadataList); metadataPacket.write(Types1_14.METADATA_LIST, metadataList);
metadataPacket.send(Protocol1_14To1_13_2.class); metadataPacket.send(Protocol1_14To1_13_2.class);
@ -215,9 +222,16 @@ public class EntityPackets {
handler(new PacketHandler() { handler(new PacketHandler() {
@Override @Override
public void handle(PacketWrapper wrapper) throws Exception { 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); Position position = wrapper.read(Type.POSITION);
List<Metadata> metadataList = new LinkedList<>(); List<Metadata> metadataList = new LinkedList<>();
metadataList.add(new Metadata(12, MetaType1_14.OptPosition, position)); 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); wrapper.write(Types1_14.METADATA_LIST, metadataList);
} }
}); });

Datei anzeigen

@ -331,10 +331,12 @@ public class InventoryPackets {
CompoundTag tag; CompoundTag tag;
if ((tag = item.getTag()) != null) { if ((tag = item.getTag()) != null) {
// Display Lore now uses JSON // Display Lore now uses JSON
if (tag.get("display") instanceof CompoundTag) { Tag displayTag = tag.get("display");
CompoundTag display = tag.get("display"); if (displayTag instanceof CompoundTag) {
if (display.get("Lore") instanceof ListTag) { CompoundTag display = (CompoundTag) displayTag;
ListTag lore = display.get("Lore"); Tag loreTag = display.get("Lore");
if (loreTag instanceof ListTag) {
ListTag lore = (ListTag) loreTag;
display.put(ConverterRegistry.convertToTag(NBT_TAG_NAME + "|Lore", ConverterRegistry.convertToValue(lore))); display.put(ConverterRegistry.convertToTag(NBT_TAG_NAME + "|Lore", ConverterRegistry.convertToValue(lore)));
for (Tag loreEntry : lore) { for (Tag loreEntry : lore) {
if (loreEntry instanceof StringTag) { if (loreEntry instanceof StringTag) {
@ -366,10 +368,12 @@ public class InventoryPackets {
CompoundTag tag; CompoundTag tag;
if ((tag = item.getTag()) != null) { if ((tag = item.getTag()) != null) {
// Display Name now uses JSON // Display Name now uses JSON
if (tag.get("display") instanceof CompoundTag) { Tag displayTag = tag.get("display");
CompoundTag display = tag.get("display"); if (displayTag instanceof CompoundTag) {
if (((CompoundTag) tag.get("display")).get("Lore") instanceof ListTag) { CompoundTag display = (CompoundTag) displayTag;
ListTag lore = display.get("Lore"); Tag loreTag = display.get("Lore");
if (loreTag instanceof ListTag) {
ListTag lore = (ListTag) loreTag;
ListTag via = display.get(NBT_TAG_NAME + "|Lore"); ListTag via = display.get(NBT_TAG_NAME + "|Lore");
if (via != null) { if (via != null) {
display.put(ConverterRegistry.convertToTag("Lore", ConverterRegistry.convertToValue(via))); display.put(ConverterRegistry.convertToTag("Lore", ConverterRegistry.convertToValue(via)));

Datei anzeigen

@ -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.CompoundTag;
import com.github.steveice10.opennbt.tag.builtin.LongArrayTag; import com.github.steveice10.opennbt.tag.builtin.LongArrayTag;
import com.google.common.primitives.Bytes; import com.google.common.primitives.Bytes;
import io.netty.buffer.ByteBuf;
import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.entities.Entity1_14Types; import us.myles.ViaVersion.api.entities.Entity1_14Types;
import us.myles.ViaVersion.api.minecraft.BlockChangeRecord; 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, skyLightMask);
lightPacket.write(Type.VAR_INT, blockLightMask); 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); // empty sky light mask
lightPacket.write(Type.VAR_INT, 0); //TODO lightPacket.write(Type.VAR_INT, 0); // empty block light mask
for (ChunkSection section : chunk.getSections()) { for (ChunkSection section : chunk.getSections()) {
if (section == null || !section.hasSkyLight()) continue; if (section == null || !section.hasSkyLight()) continue;
ByteBuf buf = wrapper.user().getChannel().alloc().buffer(); lightPacket.write(Type.BYTE_ARRAY, Bytes.asList(section.getSkyLight()).toArray(new Byte[0]));
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]));
} }
for (ChunkSection section : chunk.getSections()) { for (ChunkSection section : chunk.getSections()) {
if (section == null) continue; if (section == null) continue;
ByteBuf buf = wrapper.user().getChannel().alloc().buffer(); lightPacket.write(Type.BYTE_ARRAY, Bytes.asList(section.getBlockLight()).toArray(new Byte[0]));
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]));
} }
EntityTracker entityTracker = wrapper.user().get(EntityTracker.class); EntityTracker entityTracker = wrapper.user().get(EntityTracker.class);
@ -220,7 +209,7 @@ public class WorldPackets {
entityTracker.setChunkCenterZ(chunk.getZ()); 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; Entity1_14Types.EntityType entType = Entity1_14Types.EntityType.PLAYER;
// Register Type ID // 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);
} }
}); });

Datei anzeigen

@ -3,10 +3,14 @@ package us.myles.ViaVersion.protocols.protocol1_14to1_13_2.storage;
import com.google.common.base.Optional; import com.google.common.base.Optional;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.data.ExternalJoinGameListener; import us.myles.ViaVersion.api.data.ExternalJoinGameListener;
import us.myles.ViaVersion.api.data.StoredObject; import us.myles.ViaVersion.api.data.StoredObject;
import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.entities.Entity1_14Types; 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.Map;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
@ -14,11 +18,17 @@ import java.util.concurrent.ConcurrentHashMap;
public class EntityTracker extends StoredObject implements ExternalJoinGameListener { public class EntityTracker extends StoredObject implements ExternalJoinGameListener {
private final Map<Integer, Entity1_14Types.EntityType> clientEntityTypes = new ConcurrentHashMap<>(); private final Map<Integer, Entity1_14Types.EntityType> clientEntityTypes = new ConcurrentHashMap<>();
private final Map<Integer, Byte> insentientData = 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 @Getter
@Setter @Setter
private int latestTradeWindowId; private int latestTradeWindowId;
@Getter @Getter
@Setter @Setter
private int clientEntityId;
@Getter
@Setter
private boolean forceSendCenterChunk = true; private boolean forceSendCenterChunk = true;
@Getter @Getter
@Setter @Setter
@ -31,6 +41,8 @@ public class EntityTracker extends StoredObject implements ExternalJoinGameListe
public void removeEntity(int entityId) { public void removeEntity(int entityId) {
clientEntityTypes.remove(entityId); clientEntityTypes.remove(entityId);
insentientData.remove(entityId); insentientData.remove(entityId);
sleepingAndRiptideData.remove(entityId);
playerEntityFlags.remove(entityId);
} }
public void addEntity(int entityId, Entity1_14Types.EntityType type) { public void addEntity(int entityId, Entity1_14Types.EntityType type) {
@ -46,6 +58,37 @@ public class EntityTracker extends StoredObject implements ExternalJoinGameListe
insentientData.put(entity, value); 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) { public boolean has(int entityId) {
return clientEntityTypes.containsKey(entityId); return clientEntityTypes.containsKey(entityId);
} }
@ -56,6 +99,22 @@ public class EntityTracker extends StoredObject implements ExternalJoinGameListe
@Override @Override
public void onExternalJoinGame(int playerEntityId) { public void onExternalJoinGame(int playerEntityId) {
clientEntityId = playerEntityId;
clientEntityTypes.put(playerEntityId, Entity1_14Types.EntityType.PLAYER); 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);
} }
} }

Datei anzeigen

@ -81,6 +81,7 @@ public class Chunk1_14Type extends PartialType<Chunk, ClientWorld> {
Type.NBT.write(output, chunk.getHeightMap()); Type.NBT.write(output, chunk.getHeightMap());
ByteBuf buf = output.alloc().buffer(); ByteBuf buf = output.alloc().buffer();
try {
for (int i = 0; i < 16; i++) { for (int i = 0; i < 16; i++) {
ChunkSection section = chunk.getSections()[i]; ChunkSection section = chunk.getSections()[i];
if (section == null) continue; // Section not set if (section == null) continue; // Section not set
@ -90,7 +91,9 @@ public class Chunk1_14Type extends PartialType<Chunk, ClientWorld> {
buf.readerIndex(0); buf.readerIndex(0);
Type.VAR_INT.write(output, buf.readableBytes() + (chunk.isBiomeData() ? 256 * 4 : 0)); Type.VAR_INT.write(output, buf.readableBytes() + (chunk.isBiomeData() ? 256 * 4 : 0));
output.writeBytes(buf); output.writeBytes(buf);
} finally {
buf.release(); // release buffer buf.release(); // release buffer
}
// Write biome data // Write biome data
if (chunk.isBiomeData()) { if (chunk.isBiomeData()) {

Datei anzeigen

@ -82,6 +82,7 @@ public class Chunk1_9_3_4Type extends PartialType<Chunk, ClientWorld> {
Type.VAR_INT.write(output, chunk.getBitmask()); Type.VAR_INT.write(output, chunk.getBitmask());
ByteBuf buf = output.alloc().buffer(); ByteBuf buf = output.alloc().buffer();
try {
for (int i = 0; i < 16; i++) { for (int i = 0; i < 16; i++) {
ChunkSection section = chunk.getSections()[i]; ChunkSection section = chunk.getSections()[i];
if (section == null) continue; // Section not set if (section == null) continue; // Section not set
@ -95,7 +96,9 @@ public class Chunk1_9_3_4Type extends PartialType<Chunk, ClientWorld> {
buf.readerIndex(0); buf.readerIndex(0);
Type.VAR_INT.write(output, buf.readableBytes() + (chunk.isBiomeData() ? 256 : 0)); Type.VAR_INT.write(output, buf.readableBytes() + (chunk.isBiomeData() ? 256 : 0));
output.writeBytes(buf); output.writeBytes(buf);
} finally {
buf.release(); // release buffer buf.release(); // release buffer
}
// Write biome data // Write biome data
if (chunk.isBiomeData()) { if (chunk.isBiomeData()) {

Datei anzeigen

@ -78,6 +78,7 @@ public class Chunk1_9_1_2Type extends PartialType<Chunk, ClientWorld> {
Type.VAR_INT.write(output, chunk.getBitmask()); Type.VAR_INT.write(output, chunk.getBitmask());
ByteBuf buf = output.alloc().buffer(); ByteBuf buf = output.alloc().buffer();
try {
for (int i = 0; i < 16; i++) { for (int i = 0; i < 16; i++) {
ChunkSection section = chunk.getSections()[i]; ChunkSection section = chunk.getSections()[i];
if (section == null) continue; // Section not set if (section == null) continue; // Section not set
@ -91,7 +92,9 @@ public class Chunk1_9_1_2Type extends PartialType<Chunk, ClientWorld> {
buf.readerIndex(0); buf.readerIndex(0);
Type.VAR_INT.write(output, buf.readableBytes() + (chunk.isBiomeData() ? 256 : 0)); Type.VAR_INT.write(output, buf.readableBytes() + (chunk.isBiomeData() ? 256 : 0));
output.writeBytes(buf); output.writeBytes(buf);
} finally {
buf.release(); // release buffer buf.release(); // release buffer
}
// Write biome data // Write biome data
if (chunk.isBiomeData()) { if (chunk.isBiomeData()) {

Datei anzeigen

@ -4,6 +4,7 @@ import lombok.Getter;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map;
@RequiredArgsConstructor @RequiredArgsConstructor
@Getter @Getter
@ -31,7 +32,7 @@ public enum ArmorType {
GOLD_BOOTS(1, 317, "minecraft:gold_boots"), GOLD_BOOTS(1, 317, "minecraft:gold_boots"),
NONE(0, 0, "none"); NONE(0, 0, "none");
private static HashMap<Integer, ArmorType> armor; private static Map<Integer, ArmorType> armor;
static { static {
armor = new HashMap<>(); armor = new HashMap<>();
@ -51,10 +52,8 @@ public enum ArmorType {
* @return Return the ArmourType, ArmourType.NONE if not found * @return Return the ArmourType, ArmourType.NONE if not found
*/ */
public static ArmorType findById(int id) { public static ArmorType findById(int id) {
for (ArmorType a : ArmorType.values()) ArmorType type = armor.get(id);
if (a.getId() == id) return type == null ? ArmorType.NONE : type;
return a;
return ArmorType.NONE;
} }
/** /**
@ -77,10 +76,7 @@ public enum ArmorType {
* @return True if the item is a piece of armour * @return True if the item is a piece of armour
*/ */
public static boolean isArmor(int id) { public static boolean isArmor(int id) {
for (ArmorType a : ArmorType.values()) return armor.containsKey(id);
if (a.getId() == id)
return true;
return false;
} }
/** /**

Datei anzeigen

@ -10,7 +10,8 @@ public class ViaIdleThread implements Runnable {
@Override @Override
public void run() { public void run() {
for (UserConnection info : Via.getManager().getPortedPlayers().values()) { 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(); long nextIdleUpdate = info.get(MovementTracker.class).getNextIdlePacket();
if (nextIdleUpdate <= System.currentTimeMillis()) { if (nextIdleUpdate <= System.currentTimeMillis()) {
if (info.getChannel().isOpen()) { if (info.getChannel().isOpen()) {

Datei anzeigen

@ -17,7 +17,6 @@ import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.packets.State; import us.myles.ViaVersion.packets.State;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.ItemRewriter; import us.myles.ViaVersion.protocols.protocol1_9to1_8.ItemRewriter;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9To1_8; import us.myles.ViaVersion.protocols.protocol1_9to1_8.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.BulkChunkTranslatorProvider;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.CommandBlockProvider; import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.CommandBlockProvider;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.sounds.Effect; import us.myles.ViaVersion.protocols.protocol1_9to1_8.sounds.Effect;
@ -163,13 +162,16 @@ public class WorldPackets {
PacketWrapper output = (PacketWrapper) obj; PacketWrapper output = (PacketWrapper) obj;
ByteBuf buffer = wrapper.user().getChannel().alloc().buffer(); ByteBuf buffer = wrapper.user().getChannel().alloc().buffer();
try {
output.setId(-1); // -1 for no writing of id output.setId(-1); // -1 for no writing of id
output.writeToBuffer(buffer); output.writeToBuffer(buffer);
PacketWrapper chunkPacket = new PacketWrapper(0x21, buffer, wrapper.user()); PacketWrapper chunkPacket = new PacketWrapper(0x21, buffer, wrapper.user());
chunkPacket.send(Protocol1_9To1_8.class, false, true); chunkPacket.send(Protocol1_9To1_8.class, false, true);
} finally {
buffer.release(); buffer.release();
} }
} }
}
}); });
} }
}); });

Datei anzeigen

@ -1,10 +1,11 @@
package us.myles.ViaVersion.protocols.protocol1_9to1_8.sounds; package us.myles.ViaVersion.protocols.protocol1_9to1_8.sounds;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map;
public class Effect { public class Effect {
private final static HashMap<Integer, Integer> effects; private static final Map<Integer, Integer> effects;
static { static {
effects = new HashMap<>(); effects = new HashMap<>();
@ -29,9 +30,8 @@ public class Effect {
} }
public static int getNewId(int id) { public static int getNewId(int id) {
if (!contains(id)) Integer newId = effects.get(id);
return id; return newId != null ? newId : id;
return effects.get(id);
} }
public static boolean contains(int oldId) { public static boolean contains(int oldId) {

Datei anzeigen

@ -3,6 +3,7 @@ package us.myles.ViaVersion.protocols.protocol1_9to1_8.sounds;
import lombok.Getter; import lombok.Getter;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map;
@Getter @Getter
public enum SoundEffect { public enum SoundEffect {
@ -259,7 +260,7 @@ public enum SoundEffect {
private final SoundCategory category; private final SoundCategory category;
private final boolean breaksound; private final boolean breaksound;
private static HashMap<String, SoundEffect> effects; private static Map<String, SoundEffect> effects;
static { static {
effects = new HashMap<>(); effects = new HashMap<>();

Datei anzeigen

@ -141,6 +141,7 @@ public class Chunk1_9to1_8Type extends PartialType<Chunk, ClientChunks> {
Type.VAR_INT.write(output, chunk.getBitmask()); Type.VAR_INT.write(output, chunk.getBitmask());
ByteBuf buf = output.alloc().buffer(); ByteBuf buf = output.alloc().buffer();
try {
for (int i = 0; i < SECTION_COUNT; i++) { for (int i = 0; i < SECTION_COUNT; i++) {
ChunkSection section = chunk.getSections()[i]; ChunkSection section = chunk.getSections()[i];
if (section == null) continue; // Section not set if (section == null) continue; // Section not set
@ -154,7 +155,9 @@ public class Chunk1_9to1_8Type extends PartialType<Chunk, ClientChunks> {
buf.readerIndex(0); buf.readerIndex(0);
Type.VAR_INT.write(output, buf.readableBytes() + (chunk.hasBiomeData() ? 256 : 0)); Type.VAR_INT.write(output, buf.readableBytes() + (chunk.hasBiomeData() ? 256 : 0));
output.writeBytes(buf); output.writeBytes(buf);
} finally {
buf.release(); // release buffer buf.release(); // release buffer
}
// Write biome data // Write biome data
if (chunk.hasBiomeData()) { if (chunk.hasBiomeData()) {

Datei anzeigen

@ -6,7 +6,6 @@ import io.netty.channel.ChannelPipeline;
import io.netty.handler.codec.ByteToMessageDecoder; import io.netty.handler.codec.ByteToMessageDecoder;
import io.netty.handler.codec.MessageToByteEncoder; import io.netty.handler.codec.MessageToByteEncoder;
import io.netty.handler.codec.MessageToMessageDecoder; import io.netty.handler.codec.MessageToMessageDecoder;
import io.netty.handler.codec.MessageToMessageEncoder;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
@ -90,14 +89,15 @@ public class PipelineUtil {
* *
* @param t The throwable * @param t The throwable
* @param c The exception to look for * @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) { public static boolean containsCause(Throwable t, Class<? extends Throwable> c) {
while (t != null) { do {
t = t.getCause(); if (t != null) {
if (t != null)
if (c.isAssignableFrom(t.getClass())) return true; if (c.isAssignableFrom(t.getClass())) return true;
t = t.getCause();
} }
} while (t != null);
return false; return false;
} }

Datei anzeigen

@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>viaversion-parent</artifactId> <artifactId>viaversion-parent</artifactId>
<groupId>us.myles</groupId> <groupId>us.myles</groupId>
<version>2.0.2-SNAPSHOT</version> <version>2.1.0-1.14.1-pre1</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<name>viaversion-jar</name> <name>viaversion-jar</name>

Datei anzeigen

@ -6,7 +6,7 @@
<groupId>us.myles</groupId> <groupId>us.myles</groupId>
<artifactId>viaversion-parent</artifactId> <artifactId>viaversion-parent</artifactId>
<version>2.0.2-SNAPSHOT</version> <version>2.1.0-1.14.1-pre1</version>
<packaging>pom</packaging> <packaging>pom</packaging>
<name>viaversion-parent</name> <name>viaversion-parent</name>

Datei anzeigen

@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>viaversion-parent</artifactId> <artifactId>viaversion-parent</artifactId>
<groupId>us.myles</groupId> <groupId>us.myles</groupId>
<version>2.0.2-SNAPSHOT</version> <version>2.1.0-1.14.1-pre1</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>

Datei anzeigen

@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>viaversion-parent</artifactId> <artifactId>viaversion-parent</artifactId>
<groupId>us.myles</groupId> <groupId>us.myles</groupId>
<version>2.0.2-SNAPSHOT</version> <version>2.1.0-1.14.1-pre1</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>

Datei anzeigen

@ -4,6 +4,7 @@ import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder; import io.netty.handler.codec.MessageToByteEncoder;
import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.exception.CancelException; import us.myles.ViaVersion.exception.CancelException;
@ -37,7 +38,7 @@ public class SpongeEncodeHandler extends MessageToByteEncoder {
} }
} }
if (bytebuf.readableBytes() == 0) { if (bytebuf.readableBytes() == 0) {
throw new CancelException(); throw Via.getManager().isDebug() ? new CancelException() : CancelException.CACHED;
} }
// Increment sent // Increment sent
info.incrementSent(); info.incrementSent();

Datei anzeigen

@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>viaversion-parent</artifactId> <artifactId>viaversion-parent</artifactId>
<groupId>us.myles</groupId> <groupId>us.myles</groupId>
<version>2.0.2-SNAPSHOT</version> <version>2.1.0-1.14.1-pre1</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
@ -54,7 +54,7 @@
<dependency> <dependency>
<groupId>com.velocitypowered</groupId> <groupId>com.velocitypowered</groupId>
<artifactId>velocity-api</artifactId> <artifactId>velocity-api</artifactId>
<version>1.0-SNAPSHOT</version> <version>1.0.0-SNAPSHOT</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
</dependencies> </dependencies>

Datei anzeigen

@ -11,7 +11,7 @@ import com.velocitypowered.api.plugin.annotation.DataDirectory;
import com.velocitypowered.api.proxy.Player; import com.velocitypowered.api.proxy.Player;
import com.velocitypowered.api.proxy.ProxyServer; import com.velocitypowered.api.proxy.ProxyServer;
import lombok.Getter; 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.api.chat.TextComponent;
import net.md_5.bungee.chat.ComponentSerializer; import net.md_5.bungee.chat.ComponentSerializer;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -148,7 +148,7 @@ public class VelocityPlugin implements ViaPlatform<Player> {
@Override @Override
public void sendMessage(UUID uuid, String message) { public void sendMessage(UUID uuid, String message) {
PROXY.getPlayer(uuid).ifPresent(it -> it.sendMessage( PROXY.getPlayer(uuid).ifPresent(it -> it.sendMessage(
ComponentSerializers.JSON.deserialize( GsonComponentSerializer.INSTANCE.deserialize(
ComponentSerializer.toString(TextComponent.fromLegacyText(message)) // Fixes links ComponentSerializer.toString(TextComponent.fromLegacyText(message)) // Fixes links
) )
)); ));
@ -158,8 +158,8 @@ public class VelocityPlugin implements ViaPlatform<Player> {
public boolean kickPlayer(UUID uuid, String message) { public boolean kickPlayer(UUID uuid, String message) {
return PROXY.getPlayer(uuid).map(it -> { return PROXY.getPlayer(uuid).map(it -> {
it.disconnect( it.disconnect(
ComponentSerializers.JSON.deserialize( GsonComponentSerializer.INSTANCE.deserialize(
ComponentSerializer.toString(TextComponent.fromLegacyText(message)) // ComponentSerializers.LEGACY is deprecated ComponentSerializer.toString(TextComponent.fromLegacyText(message))
) )
); );
return true; return true;

Datei anzeigen

@ -3,7 +3,7 @@ package us.myles.ViaVersion.velocity.command;
import com.velocitypowered.api.command.CommandSource; import com.velocitypowered.api.command.CommandSource;
import com.velocitypowered.api.proxy.Player; import com.velocitypowered.api.proxy.Player;
import lombok.AllArgsConstructor; 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.api.chat.TextComponent;
import net.md_5.bungee.chat.ComponentSerializer; import net.md_5.bungee.chat.ComponentSerializer;
import us.myles.ViaVersion.api.command.ViaCommandSender; import us.myles.ViaVersion.api.command.ViaCommandSender;
@ -22,7 +22,7 @@ public class VelocityCommandSender implements ViaCommandSender {
@Override @Override
public void sendMessage(String msg) { public void sendMessage(String msg) {
source.sendMessage( source.sendMessage(
ComponentSerializers.JSON.deserialize( GsonComponentSerializer.INSTANCE.deserialize(
ComponentSerializer.toString(TextComponent.fromLegacyText(msg)) // Fixes links ComponentSerializer.toString(TextComponent.fromLegacyText(msg)) // Fixes links
) )
); );

Datei anzeigen

@ -9,6 +9,7 @@ import io.netty.handler.codec.MessageToMessageEncoder;
import lombok.NonNull; import lombok.NonNull;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.exception.CancelException; import us.myles.ViaVersion.exception.CancelException;
@ -28,7 +29,7 @@ public class VelocityEncodeHandler extends MessageToMessageEncoder<ByteBuf> {
@Override @Override
protected void encode(final ChannelHandlerContext ctx, ByteBuf bytebuf, List<Object> out) throws Exception { protected void encode(final ChannelHandlerContext ctx, ByteBuf bytebuf, List<Object> out) throws Exception {
if (bytebuf.readableBytes() == 0) { if (bytebuf.readableBytes() == 0) {
throw new CancelException(); throw Via.getManager().isDebug() ? new CancelException() : CancelException.CACHED;
} }
boolean needsCompress = false; boolean needsCompress = false;
if (!handledCompression if (!handledCompression
@ -76,9 +77,12 @@ public class VelocityEncodeHandler extends MessageToMessageEncoder<ByteBuf> {
if (needsCompress) { if (needsCompress) {
ByteBuf old = bytebuf; ByteBuf old = bytebuf;
bytebuf = ctx.alloc().buffer(); bytebuf = ctx.alloc().buffer();
try {
PipelineUtil.callEncode((MessageToByteEncoder) ctx.pipeline().get("compression-encoder"), ctx, old, bytebuf); PipelineUtil.callEncode((MessageToByteEncoder) ctx.pipeline().get("compression-encoder"), ctx, old, bytebuf);
} finally {
old.release(); old.release();
} }
}
out.add(bytebuf); out.add(bytebuf);
} }

Datei anzeigen

@ -100,6 +100,7 @@ public class VelocityServerHandler {
user.getVelocityLock().writeLock().lock(); user.getVelocityLock().writeLock().lock();
try {
VelocityStorage storage = user.get(VelocityStorage.class); VelocityStorage storage = user.get(VelocityStorage.class);
if (e.getServer() != null) { if (e.getServer() != null) {
@ -192,7 +193,9 @@ public class VelocityServerHandler {
setProtocolVersion.invoke(connection, version); setProtocolVersion.invoke(connection, version);
} }
} }
} finally {
user.getVelocityLock().writeLock().unlock(); user.getVelocityLock().writeLock().unlock();
} }
} }
}
} }