Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ snakeyaml = { group = "org.yaml", name = "snakeyaml", version = "1.33" }
leveldb = { group = "org.iq80.leveldb", name = "leveldb", version = "0.11.1-SNAPSHOT" }
leveldbjni = { group = "net.daporkchop", name = "leveldb-mcpe-jni", version = "0.0.10-SNAPSHOT" }
snappy = { group = "org.xerial.snappy", name = "snappy-java", version = "1.1.10.7" }
jwt = { group = "com.nimbusds", name = "nimbus-jose-jwt", version = "9.23" }
jwt = { group = "com.nimbusds", name = "nimbus-jose-jwt", version = "10.3.1" }
jopt-simple = { group = "net.sf.jopt-simple", name = "jopt-simple", version = "5.0.4" }
blockstateupdater = { group = "org.cloudburstmc", name = "block-state-updater", version = "1.21.40-SNAPSHOT" }
lmbda = { group = "org.lanternpowered", name = "lmbda", version = "2.0.0" }
Expand Down
189 changes: 108 additions & 81 deletions src/main/java/cn/nukkit/Player.java

Large diffs are not rendered by default.

36 changes: 22 additions & 14 deletions src/main/java/cn/nukkit/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,7 @@
import cn.nukkit.network.Network;
import cn.nukkit.network.RakNetInterface;
import cn.nukkit.network.SourceInterface;
import cn.nukkit.network.protocol.BiomeDefinitionListPacket;
import cn.nukkit.network.protocol.DataPacket;
import cn.nukkit.network.protocol.PlayerListPacket;
import cn.nukkit.network.protocol.ProtocolInfo;
import cn.nukkit.network.protocol.*;
import cn.nukkit.network.query.QueryHandler;
import cn.nukkit.network.rcon.RCON;
import cn.nukkit.permission.BanEntry;
Expand Down Expand Up @@ -88,12 +85,19 @@
import org.iq80.leveldb.Options;
import org.iq80.leveldb.impl.Iq80DBFactory;

import java.io.*;
import java.net.*;
import java.awt.*;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.UnknownHostException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.List;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.regex.Pattern;
Expand Down Expand Up @@ -485,6 +489,8 @@ public Level remove(Object key) {
EntityManager.get();
//noinspection ResultOfMethodCallIgnored
BiomeDefinitionListPacket.getCachedPacket();
//noinspection ResultOfMethodCallIgnored
TrimDataPacket.getCachedPacket();

// Convert legacy data before plugins get the chance to mess with it
try {
Expand Down Expand Up @@ -1002,18 +1008,13 @@ public void tickProcessor() {
}
}

public void onPlayerCompleteLoginSequence(Player player) {
this.playerList.put(player.getUniqueId(), player);
this.updatePlayerListData(player.getUniqueId(), player.getId(), player.getDisplayName(), player.getSkin(), player.getLoginChainData().getXUID());
}

public void addPlayer(InetSocketAddress socketAddress, Player player) {
this.players.put(socketAddress, player);
}

public void addOnlinePlayer(Player player) {
this.playerList.put(player.getUniqueId(), player);
this.updatePlayerListData(player.getUniqueId(), player.getId(), player.getDisplayName(), player.getSkin(), player.getLoginChainData().getXUID());
player.updatePlayerListData(false);
}

public void removeOnlinePlayer(Player player) {
Expand Down Expand Up @@ -1042,9 +1043,13 @@ public void updatePlayerListData(UUID uuid, long entityId, String name, Skin ski
}

public void updatePlayerListData(UUID uuid, long entityId, String name, Skin skin, String xboxUserId, Player[] players) {
this.updatePlayerListData(new PlayerListPacket.Entry(uuid, entityId, name, skin, xboxUserId, Color.WHITE), players);
}

public void updatePlayerListData(PlayerListPacket.Entry playerListEntry, Player[] players) {
PlayerListPacket pk = new PlayerListPacket();
pk.type = PlayerListPacket.TYPE_ADD;
pk.entries = new PlayerListPacket.Entry[]{new PlayerListPacket.Entry(uuid, entityId, name, skin, xboxUserId)};
pk.entries = new PlayerListPacket.Entry[]{playerListEntry};
this.batchPackets(players, new DataPacket[]{pk}); // This is sent "directly" so it always gets through before possible TYPE_REMOVE packet for NPCs etc.
}

Expand Down Expand Up @@ -1083,7 +1088,8 @@ public void sendFullPlayerListData(Player player) {
p.getId(),
p.getDisplayName(),
p.getSkin(),
p.getLoginChainData().getXUID()))
p.getLoginChainData().getXUID(),
p.getLocatorBarColor()))
.toArray(PlayerListPacket.Entry[]::new);
player.dataPacket(pk);
}
Expand Down Expand Up @@ -2730,6 +2736,8 @@ private static void registerEntities() {
Entity.registerEntity("Camel", EntityCamel.class);
Entity.registerEntity("Sniffer", EntitySniffer.class);
Entity.registerEntity("Armadillo", EntityArmadillo.class);
Entity.registerEntity("HappyGhast", EntityHappyGhast.class);
Entity.registerEntity("CopperGolem", EntityCopperGolem.class);
//Vehicles
Entity.registerEntity("MinecartRideable", EntityMinecartEmpty.class);
Entity.registerEntity("MinecartChest", EntityMinecartChest.class);
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/cn/nukkit/block/BlockGrindstone.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cn.nukkit.block;

import cn.nukkit.Player;
import cn.nukkit.inventory.GrindstoneInventory;
import cn.nukkit.item.Item;
import cn.nukkit.item.ItemBlock;
import cn.nukkit.math.BlockFace;
Expand Down Expand Up @@ -132,4 +133,17 @@ private boolean checkSupport() {

return false;
}

@Override
public boolean canBeActivated() {
return true;
}

@Override
public boolean onActivate(Item item, Player player) {
if (player != null) {
player.addWindow(new GrindstoneInventory(player.getUIInventory(), this), Player.GRINDSTONE_WINDOW_ID);
}
return true;
}
}
2 changes: 1 addition & 1 deletion src/main/java/cn/nukkit/block/BlockKelp.java
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ public boolean onActivate(Item item, Player player) {
int x = (int) this.x;
int z = (int) this.z;

for (int y = (int) this.y + 1; y < 255; y++) {
for (int y = (int) this.y + 1; y < this.getLevel().getMaxBlockY(); y++) {
int blockIdAbove = this.getLevel().getBlockIdAt(x, y, z);
if (blockIdAbove == BLOCK_KELP) continue;
if (!Block.isWater(blockIdAbove)) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/cn/nukkit/blockentity/BlockEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ protected void initBlockEntity() {
public static BlockEntity createBlockEntity(String type, FullChunk chunk, CompoundTag nbt, Object... args) {
BlockEntity blockEntity = null;

if (knownBlockEntities.containsKey(type)) {
Class<? extends BlockEntity> clazz = knownBlockEntities.get(type);
Class<? extends BlockEntity> clazz = knownBlockEntities.get(type);
if (clazz != null) {

if (clazz == null) {
return null;
Expand Down
48 changes: 7 additions & 41 deletions src/main/java/cn/nukkit/blockentity/BlockEntityItemFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import cn.nukkit.level.format.FullChunk;
import cn.nukkit.nbt.NBTIO;
import cn.nukkit.nbt.tag.CompoundTag;
import cn.nukkit.nbt.tag.ListTag;
import cn.nukkit.network.protocol.LevelEventPacket;

import java.util.concurrent.ThreadLocalRandom;
Expand Down Expand Up @@ -119,50 +118,17 @@ public CompoundTag getSpawnCompound() {
int itemId = itemOriginal.getShort("id");
if (itemId != Item.AIR) {
CompoundTag item;
if (itemId == Item.MAP) {
item = itemOriginal.copy();
item.setName("Item");
item = itemOriginal.copy();
item.setName("Item");

String identifier = RuntimeItems.getMapping().toRuntime(itemId, itemOriginal.getShort("Damage")).getIdentifier();
item.putString("Name", identifier);
item.remove("id");
String identifier = RuntimeItems.getMapping().toRuntime(itemId, itemOriginal.getShort("Damage")).getIdentifier();
item.putString("Name", identifier);
item.remove("id");

if (itemId == Item.MAP) {
item.getCompound("tag").remove("Colors");
} else {
// Instead of copying the item's whole nbt just send the data necessary to display the item
item = new CompoundTag("Item")
.putByte("Count", itemOriginal.getByte("Count"))
.putShort("Damage", itemOriginal.getShort("Damage"));

String identifier = RuntimeItems.getMapping().toRuntime(itemId, itemOriginal.getShort("Damage")).getIdentifier();
item.putString("Name", identifier);

if (itemOriginal.contains("tag")) {
CompoundTag oldTag = itemOriginal.getCompound("tag");
CompoundTag newTag = new CompoundTag();

if (oldTag.contains("ench")) {
newTag.putList(new ListTag<>("ench"));
}

if (oldTag.contains("Base")) {
newTag.put("Base", oldTag.get("Base"));
}

if (oldTag.contains("Patterns")) {
newTag.put("Patterns", oldTag.get("Patterns"));
}

if (oldTag.contains("customColor")) {
newTag.put("customColor", oldTag.get("customColor"));
}

if (oldTag.contains("display") && oldTag.get("display") instanceof CompoundTag) {
newTag.putCompound("display", new CompoundTag("display").putString("Name", ((CompoundTag) oldTag.get("display")).getString("Name")));
}

item.put("tag", newTag);
}
item.getCompound("tag").remove("Items");
}

tag.putCompound("Item", item)
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/cn/nukkit/command/SimpleCommandMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ private boolean registerAlias(Command command, boolean isAlias, String fallbackP
this.knownCommands.put(fallbackPrefix + ':' + label, command);

//if you're registering a command alias that is already registered, then return false
boolean alreadyRegistered = this.knownCommands.containsKey(label);
Command existingCommand = this.knownCommands.get(label);
boolean alreadyRegistered = existingCommand != null;
boolean existingCommandIsNotVanilla = alreadyRegistered && !(existingCommand instanceof VanillaCommand);
//basically, if we're an alias and it's already registered, or we're a vanilla command, then we can't override it
if ((command instanceof VanillaCommand || isAlias) && alreadyRegistered && existingCommandIsNotVanilla) {
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/cn/nukkit/entity/Attribute.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,9 @@ public static Attribute addAttribute(int id, String name, float minValue, float
}

public static Attribute getAttribute(int id) {
if (attributes.containsKey(id)) {
return attributes.get(id).clone();
Attribute attribute = attributes.get(id);
if (attribute != null) {
return attribute.clone();
}
throw new ServerException("Attribute id: " + id + " not found");
}
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/cn/nukkit/entity/Entity.java
Original file line number Diff line number Diff line change
Expand Up @@ -846,9 +846,8 @@ public void removeEffect(int effectId) {
}

public void removeEffect(int effectId, EntityPotionEffectEvent.Cause cause) {
if (this.effects.containsKey(effectId)) {
Effect effect = this.effects.get(effectId);

Effect effect = this.effects.get(effectId);
if (effect != null) {
if (cause != null) {
EntityPotionEffectEvent event =
new EntityPotionEffectEvent(this, effect, null, EntityPotionEffectEvent.Action.REMOVED, cause);
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/cn/nukkit/entity/EntityHuman.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import cn.nukkit.nbt.tag.StringTag;
import cn.nukkit.network.protocol.AddPlayerPacket;
import cn.nukkit.network.protocol.MobArmorEquipmentPacket;
import cn.nukkit.network.protocol.PlayerListPacket;
import cn.nukkit.network.protocol.SetEntityLinkPacket;
import cn.nukkit.utils.*;

Expand Down Expand Up @@ -293,7 +294,9 @@ public void spawnTo(Player player) {
}

if (this instanceof Player) {
this.server.updatePlayerListData(this.uuid, this.getId(), ((Player) this).getDisplayName(), this.skin, ((Player) this).getLoginChainData().getXUID(), new Player[]{player});
this.server.updatePlayerListData(
new PlayerListPacket.Entry(this.uuid, this.getId(), ((Player) this).getDisplayName(), this.skin, ((Player) this).getLoginChainData().getXUID(), ((Player) this).getLocatorBarColor()),
new Player[]{player});
} else {
this.server.updatePlayerListData(this.uuid, this.getId(), this.getName(), this.skin, new Player[]{player});
}
Expand Down
16 changes: 10 additions & 6 deletions src/main/java/cn/nukkit/entity/data/Skin.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@
import cn.nukkit.nbt.stream.FastByteArrayOutputStream;
import cn.nukkit.utils.*;
import com.google.common.base.Preconditions;
import com.nimbusds.jose.shaded.json.JSONObject;
import com.nimbusds.jose.shaded.json.JSONValue;
import com.google.gson.Gson;
import lombok.ToString;

import java.awt.*;
import java.awt.image.BufferedImage;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.*;
import java.util.List;

/**
* @author MagicDroidX
Expand All @@ -30,6 +29,8 @@ public class Skin {

private static final int MAX_DATA_SIZE = 262144;

private static final Gson GSON = new Gson();

public static final String GEOMETRY_CUSTOM = convertLegacyGeometryName("geometry.humanoid.custom");
public static final String GEOMETRY_CUSTOM_SLIM = convertLegacyGeometryName("geometry.humanoid.customSlim");

Expand Down Expand Up @@ -86,9 +87,12 @@ private boolean isValidResourcePatch() {
return false;
}
try {
JSONObject geometry = (JSONObject) ((JSONObject) JSONValue.parse(skinResourcePatch)).get("geometry");
return geometry.containsKey("default") && geometry.get("default") instanceof String;
} catch (ClassCastException | NullPointerException e) {
Map<String, Object> geometry = (Map<String, Object>) GSON.fromJson(skinResourcePatch, Map.class).get("geometry");
if (geometry == null) {
return false;
}
return geometry.get("default") instanceof String;
} catch (ClassCastException e) {
return false;
}
}
Expand Down
39 changes: 39 additions & 0 deletions src/main/java/cn/nukkit/entity/passive/EntityCopperGolem.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package cn.nukkit.entity.passive;

import cn.nukkit.level.format.FullChunk;
import cn.nukkit.nbt.tag.CompoundTag;

public class EntityCopperGolem extends EntityWalkingAnimal {

public static final int NETWORK_ID = 148;

public EntityCopperGolem(FullChunk chunk, CompoundTag nbt) {
super(chunk, nbt);
}

@Override
public int getNetworkId() {
return NETWORK_ID;
}

@Override
public void initEntity() {
this.setMaxHealth(12);
super.initEntity();
}

@Override
public float getWidth() {
return 0.875f;
}

@Override
public float getHeight() {
return 1f;
}

@Override
public int getKillExperience() {
return 0;
}
}
Loading
Loading