Skip to content

Commit 02f55d0

Browse files
authored
1.21.80 & updates (#2233)
- Added support for Minecraft 1.21.80 - Added missing map colors for some blocks - Added new boat variants - Fixed lectern and stonecutter block drop meta - Fixed observer dupe - Fixed pistons moving pistons - Fixed packet violation warning logging - server.properties now ignores whitespaces and case sensitivity for integers and booleans
1 parent 5165bb7 commit 02f55d0

File tree

113 files changed

+902
-10425
lines changed

Some content is hidden

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

113 files changed

+902
-10425
lines changed

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

Lines changed: 13 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,9 @@
7777
import it.unimi.dsi.fastutil.ints.IntArrayList;
7878
import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
7979
import it.unimi.dsi.fastutil.longs.Long2ObjectLinkedOpenHashMap;
80-
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
8180
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
8281
import it.unimi.dsi.fastutil.longs.LongIterator;
83-
import it.unimi.dsi.fastutil.objects.ObjectIterator;
82+
import it.unimi.dsi.fastutil.longs.LongLinkedOpenHashSet;
8483
import lombok.Getter;
8584
import lombok.Setter;
8685
import lombok.extern.log4j.Log4j2;
@@ -90,7 +89,6 @@
9089
import java.awt.image.BufferedImage;
9190
import java.io.File;
9291
import java.io.IOException;
93-
import java.lang.reflect.Field;
9492
import java.net.InetSocketAddress;
9593
import java.nio.ByteOrder;
9694
import java.util.*;
@@ -101,7 +99,6 @@
10199
import java.util.concurrent.TimeUnit;
102100
import java.util.concurrent.atomic.AtomicReference;
103101
import java.util.function.Consumer;
104-
import java.util.stream.Stream;
105102

106103
/**
107104
* The Player class
@@ -200,7 +197,7 @@ public class Player extends EntityHuman implements CommandSender, InventoryHolde
200197
protected int chunkRadius;
201198
protected int viewDistance;
202199
public final Map<Long, Boolean> usedChunks = new Long2ObjectOpenHashMap<>();
203-
protected final Long2ObjectLinkedOpenHashMap<Boolean> loadQueue = new Long2ObjectLinkedOpenHashMap<>();
200+
protected final LongLinkedOpenHashSet loadQueue = new LongLinkedOpenHashSet();
204201

205202
protected final Map<UUID, Player> hiddenPlayers = new HashMap<>();
206203

@@ -269,8 +266,6 @@ public class Player extends EntityHuman implements CommandSender, InventoryHolde
269266
private AsyncTask preLoginEventTask;
270267
protected boolean shouldLogin;
271268

272-
private static Stream<Field> pkIDs;
273-
274269
protected int startAction = -1;
275270
private int lastEmote;
276271
protected int lastEnderPearl = 20;
@@ -1135,14 +1130,13 @@ protected void sendNextChunk() {
11351130

11361131
if (!loadQueue.isEmpty()) {
11371132
int count = 0;
1138-
ObjectIterator<Long2ObjectMap.Entry<Boolean>> iter = loadQueue.long2ObjectEntrySet().fastIterator();
1133+
LongIterator iter = loadQueue.longIterator();
11391134
while (iter.hasNext()) {
11401135
if (count >= server.chunksPerTick) {
11411136
break;
11421137
}
11431138

1144-
Long2ObjectMap.Entry<Boolean> entry = iter.next();
1145-
long index = entry.getLongKey();
1139+
long index = iter.nextLong();
11461140
int chunkX = Level.getHashX(index);
11471141
int chunkZ = Level.getHashZ(index);
11481142

@@ -1284,43 +1278,43 @@ protected boolean orderChunks() {
12841278

12851279
/* Top right quadrant */
12861280
if (this.usedChunks.get(index = Level.chunkHash(centerX + x, centerZ + z)) != Boolean.TRUE) {
1287-
this.loadQueue.put(index, Boolean.TRUE);
1281+
this.loadQueue.add(index);
12881282
}
12891283
lastChunk.remove(index);
12901284
/* Top left quadrant */
12911285
if (this.usedChunks.get(index = Level.chunkHash(centerX - x - 1, centerZ + z)) != Boolean.TRUE) {
1292-
this.loadQueue.put(index, Boolean.TRUE);
1286+
this.loadQueue.add(index);
12931287
}
12941288
lastChunk.remove(index);
12951289
/* Bottom right quadrant */
12961290
if (this.usedChunks.get(index = Level.chunkHash(centerX + x, centerZ - z - 1)) != Boolean.TRUE) {
1297-
this.loadQueue.put(index, Boolean.TRUE);
1291+
this.loadQueue.add(index);
12981292
}
12991293
lastChunk.remove(index);
13001294
/* Bottom left quadrant */
13011295
if (this.usedChunks.get(index = Level.chunkHash(centerX - x - 1, centerZ - z - 1)) != Boolean.TRUE) {
1302-
this.loadQueue.put(index, Boolean.TRUE);
1296+
this.loadQueue.add(index);
13031297
}
13041298
lastChunk.remove(index);
13051299
if (x != z) {
13061300
/* Top right quadrant mirror */
13071301
if (this.usedChunks.get(index = Level.chunkHash(centerX + z, centerZ + x)) != Boolean.TRUE) {
1308-
this.loadQueue.put(index, Boolean.TRUE);
1302+
this.loadQueue.add(index);
13091303
}
13101304
lastChunk.remove(index);
13111305
/* Top left quadrant mirror */
13121306
if (this.usedChunks.get(index = Level.chunkHash(centerX - z - 1, centerZ + x)) != Boolean.TRUE) {
1313-
this.loadQueue.put(index, Boolean.TRUE);
1307+
this.loadQueue.add(index);
13141308
}
13151309
lastChunk.remove(index);
13161310
/* Bottom right quadrant mirror */
13171311
if (this.usedChunks.get(index = Level.chunkHash(centerX + z, centerZ - x - 1)) != Boolean.TRUE) {
1318-
this.loadQueue.put(index, Boolean.TRUE);
1312+
this.loadQueue.add(index);
13191313
}
13201314
lastChunk.remove(index);
13211315
/* Bottom left quadrant mirror */
13221316
if (this.usedChunks.get(index = Level.chunkHash(centerX - z - 1, centerZ - x - 1)) != Boolean.TRUE) {
1323-
this.loadQueue.put(index, Boolean.TRUE);
1317+
this.loadQueue.add(index);
13241318
}
13251319
lastChunk.remove(index);
13261320
}
@@ -4667,19 +4661,7 @@ public void onCompletion(Server server) {
46674661
}
46684662
return;
46694663
case ProtocolInfo.PACKET_VIOLATION_WARNING_PACKET:
4670-
PacketViolationWarningPacket PVWpk = (PacketViolationWarningPacket) packet;
4671-
if (pkIDs == null) {
4672-
pkIDs = Arrays.stream(ProtocolInfo.class.getDeclaredFields()).filter(field -> field.getType() == Byte.TYPE);
4673-
}
4674-
Optional<String> PVWpkName = pkIDs
4675-
.filter(field -> {
4676-
try {
4677-
return field.getByte(null) == ((PacketViolationWarningPacket) packet).packetId;
4678-
} catch (IllegalAccessException e) {
4679-
return false;
4680-
}
4681-
}).map(Field::getName).findFirst();
4682-
this.getServer().getLogger().warning("PacketViolationWarningPacket" + PVWpkName.map(name -> " for " + name).orElse(" UNKNOWN") + " from " + this.username + ": " + PVWpk.toString());
4664+
this.getServer().getLogger().warning("Packet violation warning 0x" + Integer.toHexString(((PacketViolationWarningPacket) packet).packetId) + " from " + this.username + ": " + packet);
46834665
return;
46844666
case ProtocolInfo.EMOTE_PACKET:
46854667
if (!this.spawned || server.getTick() - this.lastEmote < 20 || this.isSpectator()) {

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2353,7 +2353,17 @@ public int getPropertyInt(String variable) {
23532353
*/
23542354
public int getPropertyInt(String variable, Integer defaultValue) {
23552355
Object value = this.properties.get(variable);
2356-
return value == null || (value instanceof String && ((String) value).isEmpty()) ? defaultValue : Integer.parseInt(String.valueOf(value));
2356+
if (value == null) {
2357+
value = defaultValue;
2358+
}
2359+
if (value instanceof Integer) {
2360+
return (Integer) value;
2361+
}
2362+
String trimmed = String.valueOf(value).trim();
2363+
if (trimmed.isEmpty()) {
2364+
return defaultValue;
2365+
}
2366+
return Integer.parseInt(trimmed);
23572367
}
23582368

23592369
/**
@@ -2392,7 +2402,7 @@ public boolean getPropertyBoolean(String variable, Object defaultValue) {
23922402
if (value instanceof Boolean) {
23932403
return (Boolean) value;
23942404
}
2395-
switch (String.valueOf(value)) {
2405+
switch (String.valueOf(value).trim().toLowerCase(Locale.ROOT)) {
23962406
case "on":
23972407
case "true":
23982408
case "1":
@@ -2409,7 +2419,7 @@ public boolean getPropertyBoolean(String variable, Object defaultValue) {
24092419
* @param value value
24102420
*/
24112421
public void setPropertyBoolean(String variable, boolean value) {
2412-
this.properties.set(variable, value ? "1" : "0");
2422+
this.properties.set(variable, value);
24132423
this.properties.save();
24142424
}
24152425

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

Lines changed: 6 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.item.ItemTool;
4+
import cn.nukkit.utils.BlockColor;
45

56
public class BlockAmethyst extends BlockSolid {
67

@@ -38,6 +39,11 @@ public boolean canHarvestWithHand() {
3839
return false;
3940
}
4041

42+
@Override
43+
public BlockColor getColor() {
44+
return BlockColor.PURPLE_BLOCK_COLOR;
45+
}
46+
4147
// TODO:
4248
/*@Override
4349
public boolean isLavaResistant() {

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import cn.nukkit.math.AxisAlignedBB;
88
import cn.nukkit.math.BlockFace;
99
import cn.nukkit.math.SimpleAxisAlignedBB;
10+
import cn.nukkit.utils.BlockColor;
1011
import cn.nukkit.utils.Faceable;
1112

1213
public abstract class BlockAmethystBud extends BlockTransparentMeta implements Faceable {
@@ -110,4 +111,9 @@ public WaterloggingType getWaterloggingType() {
110111
public Item[] getDrops(Item item) {
111112
return new Item[0];
112113
}
114+
115+
@Override
116+
public BlockColor getColor() {
117+
return BlockColor.PURPLE_BLOCK_COLOR;
118+
}
113119
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,6 @@ public boolean canHarvestWithHand() {
9292

9393
@Override
9494
public BlockColor getColor() {
95-
return BlockColor.GRAY_BLOCK_COLOR;
95+
return BlockColor.BLACK_BLOCK_COLOR;
9696
}
9797
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,6 @@ public int getToolTier() {
4545

4646
@Override
4747
public BlockColor getColor() {
48-
return BlockColor.DEEPSLATE_GRAY;
48+
return BlockColor.DEEPSLATE_GRAY_BLOCK_COLOR;
4949
}
5050
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import cn.nukkit.item.Item;
66
import cn.nukkit.item.ItemTool;
77
import cn.nukkit.math.BlockFace;
8+
import cn.nukkit.utils.BlockColor;
89

910
public class BlockConduit extends BlockTransparentMeta {
1011

@@ -69,4 +70,9 @@ public boolean place(Item item, Block block, Block target, BlockFace face, doubl
6970
}
7071
return false;
7172
}
73+
74+
@Override
75+
public BlockColor getColor() {
76+
return BlockColor.DIAMOND_BLOCK_COLOR;
77+
}
7278
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import cn.nukkit.item.enchantment.Enchantment;
66
import cn.nukkit.level.Level;
77
import cn.nukkit.math.BlockFace;
8+
import cn.nukkit.utils.BlockColor;
89

910
public class BlockCoral extends BlockTransparentMeta {
1011

@@ -111,4 +112,9 @@ public Item[] getDrops(Item item) {
111112
public boolean canPassThrough() {
112113
return true;
113114
}
115+
116+
@Override
117+
public BlockColor getColor() {
118+
return BlockColor.BLUE_BLOCK_COLOR;
119+
}
114120
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import cn.nukkit.item.enchantment.Enchantment;
88
import cn.nukkit.level.Level;
99
import cn.nukkit.math.BlockFace;
10+
import cn.nukkit.utils.BlockColor;
1011

1112
import java.util.concurrent.ThreadLocalRandom;
1213

@@ -121,4 +122,8 @@ public void setDead(boolean dead) {
121122
}
122123
}
123124

125+
@Override
126+
public BlockColor getColor() {
127+
return BlockColor.BLUE_BLOCK_COLOR;
128+
}
124129
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,6 @@ public boolean canSilkTouch() {
101101

102102
@Override
103103
public BlockColor getColor() {
104-
return BlockColor.DEEPSLATE_GRAY;
104+
return BlockColor.DEEPSLATE_GRAY_BLOCK_COLOR;
105105
}
106106
}

0 commit comments

Comments
 (0)