Skip to content

Commit 6a7c34c

Browse files
authored
1.21.100 & updates (#2237)
- Added support for Minecraft 1.21.100 - Implemented grindstone inventory - Implemented armor trims - Made happy ghast and copper golem spawnable - Added a method to set player color in locator bar - Fixed kelp growing above y 255 - More inventory transaction validation - Updated nimbus-jose-jwt dependency - Some cleanup
1 parent b43931a commit 6a7c34c

File tree

95 files changed

+1702
-465
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+1702
-465
lines changed

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ snakeyaml = { group = "org.yaml", name = "snakeyaml", version = "1.33" }
1616
leveldb = { group = "org.iq80.leveldb", name = "leveldb", version = "0.11.1-SNAPSHOT" }
1717
leveldbjni = { group = "net.daporkchop", name = "leveldb-mcpe-jni", version = "0.0.10-SNAPSHOT" }
1818
snappy = { group = "org.xerial.snappy", name = "snappy-java", version = "1.1.10.7" }
19-
jwt = { group = "com.nimbusds", name = "nimbus-jose-jwt", version = "9.23" }
19+
jwt = { group = "com.nimbusds", name = "nimbus-jose-jwt", version = "10.3.1" }
2020
jopt-simple = { group = "net.sf.jopt-simple", name = "jopt-simple", version = "5.0.4" }
2121
blockstateupdater = { group = "org.cloudburstmc", name = "block-state-updater", version = "1.21.40-SNAPSHOT" }
2222
lmbda = { group = "org.lanternpowered", name = "lmbda", version = "2.0.0" }

src/main/java/cn/nukkit/Player.java

Lines changed: 108 additions & 81 deletions
Large diffs are not rendered by default.

src/main/java/cn/nukkit/Server.java

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,7 @@
5454
import cn.nukkit.network.Network;
5555
import cn.nukkit.network.RakNetInterface;
5656
import cn.nukkit.network.SourceInterface;
57-
import cn.nukkit.network.protocol.BiomeDefinitionListPacket;
58-
import cn.nukkit.network.protocol.DataPacket;
59-
import cn.nukkit.network.protocol.PlayerListPacket;
60-
import cn.nukkit.network.protocol.ProtocolInfo;
57+
import cn.nukkit.network.protocol.*;
6158
import cn.nukkit.network.query.QueryHandler;
6259
import cn.nukkit.network.rcon.RCON;
6360
import cn.nukkit.permission.BanEntry;
@@ -88,12 +85,19 @@
8885
import org.iq80.leveldb.Options;
8986
import org.iq80.leveldb.impl.Iq80DBFactory;
9087

91-
import java.io.*;
92-
import java.net.*;
88+
import java.awt.*;
89+
import java.io.File;
90+
import java.io.IOException;
91+
import java.io.InputStream;
92+
import java.io.OutputStream;
93+
import java.net.InetAddress;
94+
import java.net.InetSocketAddress;
95+
import java.net.UnknownHostException;
9396
import java.nio.ByteBuffer;
9497
import java.nio.ByteOrder;
9598
import java.nio.charset.StandardCharsets;
9699
import java.util.*;
100+
import java.util.List;
97101
import java.util.concurrent.ThreadLocalRandom;
98102
import java.util.concurrent.atomic.AtomicBoolean;
99103
import java.util.regex.Pattern;
@@ -485,6 +489,8 @@ public Level remove(Object key) {
485489
EntityManager.get();
486490
//noinspection ResultOfMethodCallIgnored
487491
BiomeDefinitionListPacket.getCachedPacket();
492+
//noinspection ResultOfMethodCallIgnored
493+
TrimDataPacket.getCachedPacket();
488494

489495
// Convert legacy data before plugins get the chance to mess with it
490496
try {
@@ -1002,18 +1008,13 @@ public void tickProcessor() {
10021008
}
10031009
}
10041010

1005-
public void onPlayerCompleteLoginSequence(Player player) {
1006-
this.playerList.put(player.getUniqueId(), player);
1007-
this.updatePlayerListData(player.getUniqueId(), player.getId(), player.getDisplayName(), player.getSkin(), player.getLoginChainData().getXUID());
1008-
}
1009-
10101011
public void addPlayer(InetSocketAddress socketAddress, Player player) {
10111012
this.players.put(socketAddress, player);
10121013
}
10131014

10141015
public void addOnlinePlayer(Player player) {
10151016
this.playerList.put(player.getUniqueId(), player);
1016-
this.updatePlayerListData(player.getUniqueId(), player.getId(), player.getDisplayName(), player.getSkin(), player.getLoginChainData().getXUID());
1017+
player.updatePlayerListData(false);
10171018
}
10181019

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

10441045
public void updatePlayerListData(UUID uuid, long entityId, String name, Skin skin, String xboxUserId, Player[] players) {
1046+
this.updatePlayerListData(new PlayerListPacket.Entry(uuid, entityId, name, skin, xboxUserId, Color.WHITE), players);
1047+
}
1048+
1049+
public void updatePlayerListData(PlayerListPacket.Entry playerListEntry, Player[] players) {
10451050
PlayerListPacket pk = new PlayerListPacket();
10461051
pk.type = PlayerListPacket.TYPE_ADD;
1047-
pk.entries = new PlayerListPacket.Entry[]{new PlayerListPacket.Entry(uuid, entityId, name, skin, xboxUserId)};
1052+
pk.entries = new PlayerListPacket.Entry[]{playerListEntry};
10481053
this.batchPackets(players, new DataPacket[]{pk}); // This is sent "directly" so it always gets through before possible TYPE_REMOVE packet for NPCs etc.
10491054
}
10501055

@@ -1083,7 +1088,8 @@ public void sendFullPlayerListData(Player player) {
10831088
p.getId(),
10841089
p.getDisplayName(),
10851090
p.getSkin(),
1086-
p.getLoginChainData().getXUID()))
1091+
p.getLoginChainData().getXUID(),
1092+
p.getLocatorBarColor()))
10871093
.toArray(PlayerListPacket.Entry[]::new);
10881094
player.dataPacket(pk);
10891095
}
@@ -2730,6 +2736,8 @@ private static void registerEntities() {
27302736
Entity.registerEntity("Camel", EntityCamel.class);
27312737
Entity.registerEntity("Sniffer", EntitySniffer.class);
27322738
Entity.registerEntity("Armadillo", EntityArmadillo.class);
2739+
Entity.registerEntity("HappyGhast", EntityHappyGhast.class);
2740+
Entity.registerEntity("CopperGolem", EntityCopperGolem.class);
27332741
//Vehicles
27342742
Entity.registerEntity("MinecartRideable", EntityMinecartEmpty.class);
27352743
Entity.registerEntity("MinecartChest", EntityMinecartChest.class);

src/main/java/cn/nukkit/block/BlockGrindstone.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cn.nukkit.block;
22

33
import cn.nukkit.Player;
4+
import cn.nukkit.inventory.GrindstoneInventory;
45
import cn.nukkit.item.Item;
56
import cn.nukkit.item.ItemBlock;
67
import cn.nukkit.math.BlockFace;
@@ -132,4 +133,17 @@ private boolean checkSupport() {
132133

133134
return false;
134135
}
136+
137+
@Override
138+
public boolean canBeActivated() {
139+
return true;
140+
}
141+
142+
@Override
143+
public boolean onActivate(Item item, Player player) {
144+
if (player != null) {
145+
player.addWindow(new GrindstoneInventory(player.getUIInventory(), this), Player.GRINDSTONE_WINDOW_ID);
146+
}
147+
return true;
148+
}
135149
}

src/main/java/cn/nukkit/block/BlockKelp.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ public boolean onActivate(Item item, Player player) {
214214
int x = (int) this.x;
215215
int z = (int) this.z;
216216

217-
for (int y = (int) this.y + 1; y < 255; y++) {
217+
for (int y = (int) this.y + 1; y < this.getLevel().getMaxBlockY(); y++) {
218218
int blockIdAbove = this.getLevel().getBlockIdAt(x, y, z);
219219
if (blockIdAbove == BLOCK_KELP) continue;
220220
if (!Block.isWater(blockIdAbove)) {

src/main/java/cn/nukkit/blockentity/BlockEntity.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ protected void initBlockEntity() {
124124
public static BlockEntity createBlockEntity(String type, FullChunk chunk, CompoundTag nbt, Object... args) {
125125
BlockEntity blockEntity = null;
126126

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

130130
if (clazz == null) {
131131
return null;

src/main/java/cn/nukkit/blockentity/BlockEntityItemFrame.java

Lines changed: 7 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import cn.nukkit.level.format.FullChunk;
1212
import cn.nukkit.nbt.NBTIO;
1313
import cn.nukkit.nbt.tag.CompoundTag;
14-
import cn.nukkit.nbt.tag.ListTag;
1514
import cn.nukkit.network.protocol.LevelEventPacket;
1615

1716
import java.util.concurrent.ThreadLocalRandom;
@@ -119,50 +118,17 @@ public CompoundTag getSpawnCompound() {
119118
int itemId = itemOriginal.getShort("id");
120119
if (itemId != Item.AIR) {
121120
CompoundTag item;
122-
if (itemId == Item.MAP) {
123-
item = itemOriginal.copy();
124-
item.setName("Item");
121+
item = itemOriginal.copy();
122+
item.setName("Item");
125123

126-
String identifier = RuntimeItems.getMapping().toRuntime(itemId, itemOriginal.getShort("Damage")).getIdentifier();
127-
item.putString("Name", identifier);
128-
item.remove("id");
124+
String identifier = RuntimeItems.getMapping().toRuntime(itemId, itemOriginal.getShort("Damage")).getIdentifier();
125+
item.putString("Name", identifier);
126+
item.remove("id");
129127

128+
if (itemId == Item.MAP) {
130129
item.getCompound("tag").remove("Colors");
131130
} else {
132-
// Instead of copying the item's whole nbt just send the data necessary to display the item
133-
item = new CompoundTag("Item")
134-
.putByte("Count", itemOriginal.getByte("Count"))
135-
.putShort("Damage", itemOriginal.getShort("Damage"));
136-
137-
String identifier = RuntimeItems.getMapping().toRuntime(itemId, itemOriginal.getShort("Damage")).getIdentifier();
138-
item.putString("Name", identifier);
139-
140-
if (itemOriginal.contains("tag")) {
141-
CompoundTag oldTag = itemOriginal.getCompound("tag");
142-
CompoundTag newTag = new CompoundTag();
143-
144-
if (oldTag.contains("ench")) {
145-
newTag.putList(new ListTag<>("ench"));
146-
}
147-
148-
if (oldTag.contains("Base")) {
149-
newTag.put("Base", oldTag.get("Base"));
150-
}
151-
152-
if (oldTag.contains("Patterns")) {
153-
newTag.put("Patterns", oldTag.get("Patterns"));
154-
}
155-
156-
if (oldTag.contains("customColor")) {
157-
newTag.put("customColor", oldTag.get("customColor"));
158-
}
159-
160-
if (oldTag.contains("display") && oldTag.get("display") instanceof CompoundTag) {
161-
newTag.putCompound("display", new CompoundTag("display").putString("Name", ((CompoundTag) oldTag.get("display")).getString("Name")));
162-
}
163-
164-
item.put("tag", newTag);
165-
}
131+
item.getCompound("tag").remove("Items");
166132
}
167133

168134
tag.putCompound("Item", item)

src/main/java/cn/nukkit/command/SimpleCommandMap.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,8 @@ private boolean registerAlias(Command command, boolean isAlias, String fallbackP
156156
this.knownCommands.put(fallbackPrefix + ':' + label, command);
157157

158158
//if you're registering a command alias that is already registered, then return false
159-
boolean alreadyRegistered = this.knownCommands.containsKey(label);
160159
Command existingCommand = this.knownCommands.get(label);
160+
boolean alreadyRegistered = existingCommand != null;
161161
boolean existingCommandIsNotVanilla = alreadyRegistered && !(existingCommand instanceof VanillaCommand);
162162
//basically, if we're an alias and it's already registered, or we're a vanilla command, then we can't override it
163163
if ((command instanceof VanillaCommand || isAlias) && alreadyRegistered && existingCommandIsNotVanilla) {

src/main/java/cn/nukkit/entity/Attribute.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,9 @@ public static Attribute addAttribute(int id, String name, float minValue, float
8484
}
8585

8686
public static Attribute getAttribute(int id) {
87-
if (attributes.containsKey(id)) {
88-
return attributes.get(id).clone();
87+
Attribute attribute = attributes.get(id);
88+
if (attribute != null) {
89+
return attribute.clone();
8990
}
9091
throw new ServerException("Attribute id: " + id + " not found");
9192
}

src/main/java/cn/nukkit/entity/Entity.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -846,9 +846,8 @@ public void removeEffect(int effectId) {
846846
}
847847

848848
public void removeEffect(int effectId, EntityPotionEffectEvent.Cause cause) {
849-
if (this.effects.containsKey(effectId)) {
850-
Effect effect = this.effects.get(effectId);
851-
849+
Effect effect = this.effects.get(effectId);
850+
if (effect != null) {
852851
if (cause != null) {
853852
EntityPotionEffectEvent event =
854853
new EntityPotionEffectEvent(this, effect, null, EntityPotionEffectEvent.Action.REMOVED, cause);

0 commit comments

Comments
 (0)