Skip to content

Commit

Permalink
Merge branch 'release/2.5.3' of https://github.com/NukkitX/Protocol
Browse files Browse the repository at this point in the history
� Conflicts:
�	README.md
�	bedrock/bedrock-common/pom.xml
�	bedrock/bedrock-v291/pom.xml
�	bedrock/bedrock-v313/pom.xml
�	bedrock/bedrock-v332/pom.xml
�	bedrock/bedrock-v340/pom.xml
�	bedrock/bedrock-v354/pom.xml
�	bedrock/bedrock-v361/pom.xml
�	bedrock/bedrock-v388/pom.xml
�	bedrock/bedrock-v389/pom.xml
�	bedrock/pom.xml
�	common/pom.xml
�	pom.xml
  • Loading branch information
SupremeMortal committed Mar 16, 2020
2 parents de292bc + 5416d47 commit 1dc26dc
Show file tree
Hide file tree
Showing 280 changed files with 1,007 additions and 939 deletions.
365 changes: 201 additions & 164 deletions LICENSE

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ server.bind().join();
<dependency>
<groupId>com.nukkitx.protocol</groupId>
<artifactId>bedrock-v(VERSION)</artifactId>
<version>2.5.2</version>
<version>2.5.3</version>
<scope>compile</scope>
</dependency>
</dependencies>
Expand Down
14 changes: 13 additions & 1 deletion bedrock/bedrock-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>bedrock-parent</artifactId>
<groupId>com.nukkitx.protocol</groupId>
<version>2.5.2</version>
<version>2.5.3</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand All @@ -30,6 +30,18 @@
<version>4.41.2</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.nukkitx.fastutil</groupId>
<artifactId>fastutil-long-common</artifactId>
<version>8.3.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.nukkitx.fastutil</groupId>
<artifactId>fastutil-long-object-maps</artifactId>
<version>8.3.1</version>
<scope>compile</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@
import com.nukkitx.protocol.bedrock.packet.PacketHeader;
import com.nukkitx.protocol.bedrock.packet.UnknownPacket;
import com.nukkitx.protocol.serializer.PacketSerializer;
import com.nukkitx.protocol.util.TIntHashBiMap;
import gnu.trove.iterator.TIntObjectIterator;
import gnu.trove.map.TIntObjectMap;
import gnu.trove.map.hash.TIntObjectHashMap;
import com.nukkitx.protocol.util.Int2ObjectBiMap;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.PooledByteBufAllocator;
import io.netty.util.ReferenceCountUtil;
import io.netty.util.internal.logging.InternalLogger;
import io.netty.util.internal.logging.InternalLoggerFactory;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
Expand All @@ -33,7 +32,7 @@ public final class BedrockPacketCodec {
@Getter
private final String minecraftVersion;
private final PacketSerializer<BedrockPacket>[] serializers;
private final TIntHashBiMap<Class<? extends BedrockPacket>> idBiMap;
private final Int2ObjectBiMap<Class<? extends BedrockPacket>> idBiMap;
private final PacketSerializer<PacketHeader> headerSerializer;

public static Builder builder() {
Expand Down Expand Up @@ -104,8 +103,8 @@ public int getId(Class<? extends BedrockPacket> clazz) {
@SuppressWarnings("unchecked")
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public static class Builder {
private final TIntObjectMap<PacketSerializer<BedrockPacket>> serializers = new TIntObjectHashMap<>();
private final TIntHashBiMap<Class<? extends BedrockPacket>> idBiMap = new TIntHashBiMap<>((Class) UnknownPacket.class);
private final Int2ObjectMap<PacketSerializer<BedrockPacket>> serializers = new Int2ObjectOpenHashMap<>();
private final Int2ObjectBiMap<Class<? extends BedrockPacket>> idBiMap = new Int2ObjectBiMap<>(UnknownPacket.class);
private int protocolVersion = -1;
private String minecraftVersion = null;
private PacketSerializer<PacketHeader> headerSerializer = null;
Expand Down Expand Up @@ -146,19 +145,16 @@ public BedrockPacketCodec build() {
Preconditions.checkNotNull(minecraftVersion, "No Minecraft version defined");
Preconditions.checkNotNull(headerSerializer, "headerSerializer cannot be null");
int largestId = -1;
for (int id : serializers.keys()) {
for (int id : serializers.keySet()) {
if (id > largestId) {
largestId = id;
}
}
Preconditions.checkArgument(largestId > -1, "Must have at least one packet registered");
PacketSerializer<BedrockPacket>[] serializers = new PacketSerializer[largestId + 1];

TIntObjectIterator<PacketSerializer<BedrockPacket>> iterator = this.serializers.iterator();

while (iterator.hasNext()) {
iterator.advance();
serializers[iterator.key()] = iterator.value();
for (Int2ObjectMap.Entry<PacketSerializer<BedrockPacket>> entry : this.serializers.int2ObjectEntrySet()) {
serializers[entry.getIntKey()] = entry.getValue();
}
return new BedrockPacketCodec(protocolVersion, minecraftVersion, serializers, idBiMap, headerSerializer);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@ public String toString() {
overloads.append("]\r\n");

StringBuilder builder = new StringBuilder("CommandData(\r\n");
List objects = Arrays.asList("name=" + name, "description=" + description, "flags=" + Arrays.toString(flags.toArray()), "permission=" + permission, "aliases=" + aliases, "overloads=" + overloads);
List<?> objects = Arrays.asList("name=" + name, "description=" + description,
"flags=" + Arrays.toString(flags.toArray()), "permission=" + permission, "aliases=" + aliases,
"overloads=" + overloads);

for (Object object : objects) {
builder.append(" ").append(Objects.toString(object).replaceAll("\r\n", "\r\n ")).append("\r\n");
}
return builder.toString();
return builder.append(")").toString();
}

@Value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public enum Type {
INT_RANGE,
STRING,
POSITION,
BLOCK_POSITION,
MESSAGE,
TEXT,
JSON,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.nukkitx.protocol.bedrock.data;

import gnu.trove.map.TIntObjectMap;
import gnu.trove.map.hash.TIntObjectHashMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;

public enum ContainerType {
UNTRACKED_UI_INTERACTION(-9),
Expand Down Expand Up @@ -29,7 +29,7 @@ public enum ContainerType {
MATERIAL_REDUCER(22),
LAB_TABLE(23);

public static final TIntObjectMap<ContainerType> BY_ID = new TIntObjectHashMap<>();
public static final Int2ObjectMap<ContainerType> BY_ID = new Int2ObjectOpenHashMap<>();

static {
for (ContainerType type : values()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,15 @@ public EntityDataMap putVector3f(EntityData key, Vector3f value) {
return this;
}

@Nonnull
public EntityFlags getOrCreateFlags() {
EntityFlags flags = this.getFlags();
if (flags == null) {
this.putFlags(flags = new EntityFlags());
}
return flags;
}

public EntityFlags getFlags() {
return (EntityFlags) this.map.get(FLAGS);
}
Expand Down Expand Up @@ -242,6 +251,19 @@ public Set<Entry<EntityData, Object>> entrySet() {
return this.map.entrySet();
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
EntityDataMap that = (EntityDataMap) o;
return this.map.equals(that.map);
}

@Override
public int hashCode() {
return this.map.hashCode();
}

@Override
public String toString() {
return map.toString();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,39 +1,20 @@
package com.nukkitx.protocol.bedrock.data;

import com.nukkitx.network.util.Preconditions;
import com.nukkitx.protocol.util.TIntHashBiMap;
import com.nukkitx.protocol.util.Int2ObjectBiMap;
import io.netty.util.internal.logging.InternalLogger;
import io.netty.util.internal.logging.InternalLoggerFactory;
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
import lombok.ToString;

import javax.annotation.Nonnull;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;

@ToString
public class EntityFlags {
private static final InternalLogger log = InternalLoggerFactory.getInstance(EntityFlags.class);

private final Set<EntityFlag> flags = new HashSet<>();

public static EntityFlags create(long value, int index, TIntHashBiMap<EntityFlag> flagMappings) {
EntityFlags flags = new EntityFlags();
final int lower = index * 64;
final int upper = lower + 64;
for (int i = lower; i < upper; i++) {
int idx = i & 0x3f;
if ((value & (1L << idx)) != 0) {
EntityFlag flag = flagMappings.get(i);
if (flag != null) {
flags.flags.add(flag);
} else {
log.debug("Unknown Metadata flag index {} detected", i);
}
}
}
return flags;
}
private final Set<EntityFlag> flags = new ObjectOpenHashSet<>();

/**
* Set {@link EntityFlag} value
Expand Down Expand Up @@ -66,7 +47,7 @@ public boolean getFlag(@Nonnull EntityFlag flag) {
return flags.contains(flag);
}

public long get(int index, TIntHashBiMap<EntityFlag> flagMappings) {
public long get(int index, Int2ObjectBiMap<EntityFlag> flagMappings) {
long value = 0;
final int lower = index * 64;
final int upper = lower + 64;
Expand All @@ -79,12 +60,28 @@ public long get(int index, TIntHashBiMap<EntityFlag> flagMappings) {
return value;
}

public void set(long value, int index, Int2ObjectBiMap<EntityFlag> flagMappings) {
final int lower = index * 64;
final int upper = lower + 64;
for (int i = lower; i < upper; i++) {
int idx = i & 0x3f;
if ((value & (1L << idx)) != 0) {
EntityFlag flag = flagMappings.get(i);
if (flag != null) {
flags.add(flag);
} else {
log.debug("Unknown entity flag index {} detected", i);
}
}
}
}

@Override
public boolean equals(Object o) {
if (o == this) return true;
if (!(o instanceof EntityFlags)) return false;
EntityFlags that = (EntityFlags) o;
return Objects.equals(this.flags, that.flags);
return this.flags.equals(that.flags);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,9 @@
public class GameRuleData<T> {
private final String name;
private final T value;

@Override
public String toString() {
return this.name + '=' + this.value;
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package com.nukkitx.protocol.bedrock.data;

import lombok.AccessLevel;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.ToString;
import lombok.*;

import java.awt.*;
import java.awt.image.BufferedImage;
Expand All @@ -12,6 +9,7 @@

@Getter
@ToString(exclude = {"image"})
@EqualsAndHashCode(doNotUseGetters = true)
@RequiredArgsConstructor(access = AccessLevel.PACKAGE)
public class ImageData {
public static final ImageData EMPTY = new ImageData(0, 0, new byte[0]);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.nukkitx.protocol.bedrock.data;

import com.nukkitx.network.util.Preconditions;
import gnu.trove.map.TIntObjectMap;
import gnu.trove.map.hash.TIntObjectHashMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import lombok.AccessLevel;
import lombok.RequiredArgsConstructor;
import lombok.Value;
Expand Down Expand Up @@ -60,7 +60,7 @@ public enum Type {
UNTRACKED_INTERACTION_UI(100),
NON_IMPLEMENTED_TODO(99999);

private static final TIntObjectMap<Type> BY_ID = new TIntObjectHashMap<>(6);
private static final Int2ObjectMap<Type> BY_ID = new Int2ObjectOpenHashMap<>(6);

static {
for (Type type : values()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package com.nukkitx.protocol.bedrock.data;

import lombok.AccessLevel;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.ToString;
import lombok.*;
import net.minidev.json.JSONObject;
import net.minidev.json.JSONValue;

Expand All @@ -15,6 +12,7 @@

@Getter
@ToString(exclude = {"geometryData"})
@EqualsAndHashCode
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
public class SerializedSkin {
private static final int PIXEL_SIZE = 4;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import lombok.EqualsAndHashCode;

@Data
@EqualsAndHashCode(callSuper = false)
@EqualsAndHashCode(doNotUseGetters = true, callSuper = false)
public class AddBehaviorTreePacket extends BedrockPacket {
private String behaviorTreeJson;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import java.util.List;

@Data
@EqualsAndHashCode(callSuper = false)
@EqualsAndHashCode(doNotUseGetters = true, callSuper = false)
public class AddEntityPacket extends BedrockPacket {
private final List<Attribute> attributes = new ArrayList<>();
private final EntityDataMap metadata = new EntityDataMap();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import lombok.EqualsAndHashCode;

@Data
@EqualsAndHashCode(callSuper = false)
@EqualsAndHashCode(doNotUseGetters = true, callSuper = false)
public class AddHangingEntityPacket extends BedrockPacket {
private long uniqueEntityId;
private long runtimeEntityId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import lombok.EqualsAndHashCode;

@Data
@EqualsAndHashCode(callSuper = false)
@EqualsAndHashCode(doNotUseGetters = true, callSuper = false)
public class AddItemEntityPacket extends BedrockPacket {
private final EntityDataMap metadata = new EntityDataMap();
private long uniqueEntityId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import lombok.ToString;

@Data
@EqualsAndHashCode(callSuper = false)
@EqualsAndHashCode(doNotUseGetters = true, callSuper = false)
@ToString(callSuper = false)
public class AddPaintingPacket extends AddHangingEntityPacket {
private String name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import java.util.UUID;

@Data
@EqualsAndHashCode(callSuper = false)
@EqualsAndHashCode(doNotUseGetters = true, callSuper = false)
public class AddPlayerPacket extends BedrockPacket {
private final EntityDataMap metadata = new EntityDataMap();
private final List<EntityLink> entityLinks = new ArrayList<>();
Expand Down
Loading

0 comments on commit 1dc26dc

Please sign in to comment.