Skip to content

Commit 104045e

Browse files
authored
Merge pull request #238 from FatSaw/ver/1.12.2
Fix plates
2 parents 7dcfc13 + c398827 commit 104045e

File tree

9 files changed

+130
-29
lines changed

9 files changed

+130
-29
lines changed

sources/src/main/java/net/minecraft/server/ChunkRegionLoader.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
package net.minecraft.server;
22

33
import com.google.common.collect.Maps;
4+
import java.io.DataInputStream;
5+
import java.io.DataOutput;
6+
import java.io.DataOutputStream;
47
import java.io.File;
58
import java.io.IOException;
9+
import java.util.Collections;
610
import java.util.Iterator;
711
import java.util.List;
812
import java.util.Map;
13+
import java.util.Set;
914
import javax.annotation.Nullable;
1015
import java.util.concurrent.ConcurrentLinkedQueue; // Paper
1116
import org.apache.logging.log4j.LogManager;
@@ -89,8 +94,22 @@ public boolean chunkExists(int i, int j) {
8994
return nbttagcompound != null ? true : RegionFileCache.chunkExists(this.d, i, j);
9095
}
9196

97+
// Paper start
98+
private static final int CURRENT_DATA_VERSION = 1343; // Paper
99+
private static final boolean JUST_CORRUPT_IT = Boolean.valueOf("Paper.ignoreWorldDataVersion");
100+
// Paper end
101+
92102
@Nullable
93103
protected Object[] a(World world, int i, int j, NBTTagCompound nbttagcompound) { // CraftBukkit - return Chunk -> Object[]
104+
// Paper start - Do NOT attempt to load chunks saved with newer versions
105+
if (nbttagcompound.hasKeyOfType("DataVersion", 3)) {
106+
int dataVersion = nbttagcompound.getInt("DataVersion");
107+
if (!JUST_CORRUPT_IT && dataVersion > CURRENT_DATA_VERSION) {
108+
new RuntimeException("Server attempted to load chunk saved with newer version of minecraft! " + dataVersion + " > " + CURRENT_DATA_VERSION).printStackTrace();
109+
System.exit(1);
110+
}
111+
}
112+
// Paper end
94113
if (!nbttagcompound.hasKeyOfType("Level", 10)) {
95114
ChunkRegionLoader.a.error("Chunk file at {},{} is missing level data, skipping", Integer.valueOf(i), Integer.valueOf(j));
96115
return null;

sources/src/main/java/net/minecraft/server/Entity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2965,7 +2965,7 @@ public boolean bI() {
29652965
return entity instanceof EntityHuman ? ((EntityHuman) entity).cZ() : !this.world.isClientSide;
29662966
}
29672967

2968-
@Nullable
2968+
@Nullable Entity getVehicleDirect() { return this.bJ(); } // Paper - OBFHELPER
29692969
public Entity bJ() {
29702970
return this.au;
29712971
}

sources/src/main/java/net/minecraft/server/EntityPlayer.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1096,6 +1096,13 @@ public void b(List<IRecipe> list) {
10961096
public void s() {
10971097
this.cu = true;
10981098
this.ejectPassengers();
1099+
1100+
// Paper start - "Fixes" an issue where the vehicle doesn't track the passenger disconnection dismount.
1101+
if (this.isPassenger() && this.getVehicleDirect() instanceof EntityLiving) {
1102+
this.stopRiding();
1103+
}
1104+
// Paper end
1105+
10991106
if (this.sleeping) {
11001107
this.a(true, false, false);
11011108
}

sources/src/main/java/net/minecraft/server/NetworkManager.java

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
package net.minecraft.server;
22

3-
import com.google.common.util.concurrent.ThreadFactoryBuilder;
43
import com.googlecode.concurentlocks.ReentrantReadWriteUpdateLock;
5-
64
import io.akarin.api.internal.utils.CheckedConcurrentLinkedQueue;
5+
6+
import com.google.common.collect.Queues;
7+
import com.google.common.util.concurrent.ThreadFactoryBuilder;
78
import io.netty.channel.Channel;
89
import io.netty.channel.ChannelFuture;
910
import io.netty.channel.ChannelFutureListener;
@@ -18,9 +19,9 @@
1819
import io.netty.util.AttributeKey;
1920
import io.netty.util.concurrent.Future;
2021
import io.netty.util.concurrent.GenericFutureListener;
21-
2222
import java.net.SocketAddress;
2323
import java.util.Queue;
24+
import java.util.concurrent.locks.ReentrantReadWriteLock;
2425
import javax.annotation.Nullable;
2526
import javax.crypto.SecretKey;
2627
import org.apache.commons.lang3.ArrayUtils;
@@ -29,7 +30,6 @@
2930
import org.apache.logging.log4j.Logger;
3031
import org.apache.logging.log4j.Marker;
3132
import org.apache.logging.log4j.MarkerManager;
32-
3333
/**
3434
* Akarin Changes Note
3535
* 2) Expose private members (nsc)
@@ -47,7 +47,6 @@ protected NioEventLoopGroup a() {
4747
return new NioEventLoopGroup(0, (new ThreadFactoryBuilder()).setNameFormat("Netty Client IO #%d").setDaemon(true).build());
4848
}
4949

50-
@Override
5150
protected Object init() {
5251
return this.a();
5352
}
@@ -57,7 +56,6 @@ protected EpollEventLoopGroup a() {
5756
return new EpollEventLoopGroup(0, (new ThreadFactoryBuilder()).setNameFormat("Netty Epoll Client IO #%d").setDaemon(true).build());
5857
}
5958

60-
@Override
6159
protected Object init() {
6260
return this.a();
6361
}
@@ -67,7 +65,6 @@ protected LocalEventLoopGroup a() {
6765
return new LocalEventLoopGroup(0, (new ThreadFactoryBuilder()).setNameFormat("Netty Local Client IO #%d").setDaemon(true).build());
6866
}
6967

70-
@Override
7168
protected Object init() {
7269
return this.a();
7370
}
@@ -96,7 +93,6 @@ public NetworkManager(EnumProtocolDirection enumprotocoldirection) {
9693
this.h = enumprotocoldirection;
9794
}
9895

99-
@Override
10096
public void channelActive(ChannelHandlerContext channelhandlercontext) throws Exception {
10197
super.channelActive(channelhandlercontext);
10298
this.channel = channelhandlercontext.channel();
@@ -119,13 +115,20 @@ public void setProtocol(EnumProtocol enumprotocol) {
119115
NetworkManager.g.debug("Enabled auto read");
120116
}
121117

122-
@Override
123118
public void channelInactive(ChannelHandlerContext channelhandlercontext) throws Exception {
124119
this.close(new ChatMessage("disconnect.endOfStream", new Object[0]));
125120
}
126121

127-
@Override
128122
public void exceptionCaught(ChannelHandlerContext channelhandlercontext, Throwable throwable) throws Exception {
123+
// Paper start
124+
if (throwable instanceof io.netty.handler.codec.EncoderException && throwable.getCause() instanceof PacketEncoder.PacketTooLargeException) {
125+
if (((PacketEncoder.PacketTooLargeException) throwable.getCause()).getPacket().packetTooLarge(this)) {
126+
return;
127+
} else {
128+
throwable = throwable.getCause();
129+
}
130+
}
131+
// Paper end
129132
ChatMessage chatmessage;
130133

131134
if (throwable instanceof TimeoutException) {
@@ -212,7 +215,6 @@ private void a(final Packet<?> packet, @Nullable final GenericFutureListener<? e
212215
channelfuture.addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE);
213216
} else {
214217
this.channel.eventLoop().execute(new Runnable() {
215-
@Override
216218
public void run() {
217219
if (enumprotocol != enumprotocol1) {
218220
NetworkManager.this.setProtocol(enumprotocol);
@@ -229,6 +231,15 @@ public void run() {
229231
});
230232
}
231233

234+
// Paper start
235+
java.util.List<Packet> extraPackets = packet.getExtraPackets();
236+
if (extraPackets != null && !extraPackets.isEmpty()) {
237+
for (Packet extraPacket : extraPackets) {
238+
this.dispatchPacket(extraPacket, agenericfuturelistener);
239+
}
240+
}
241+
// Paper end
242+
232243
}
233244

234245
// Paper start - Async-Anti-Xray - Stop dispatching further packets and return false if the peeked packet is a chunk packet which is not ready
@@ -363,7 +374,6 @@ public void handleDisconnection() {
363374
}
364375
}
365376

366-
@Override
367377
protected void channelRead0(ChannelHandlerContext channelhandlercontext, Packet object) throws Exception { // CraftBukkit - fix decompile error
368378
// FlamePaper - Check if channel is opened before reading packet
369379
if (isConnected()) {

sources/src/main/java/net/minecraft/server/PlayerConnection.java

Lines changed: 70 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,13 @@ public void a(PacketPlayInVehicleMove packetplayinvehiclemove) {
355355
}
356356
speed *= 2f; // TODO: Get the speed of the vehicle instead of the player
357357

358+
// Paper start - Prevent moving into unloaded chunks
359+
if (player.world.paperConfig.preventMovingIntoUnloadedChunks && !worldserver.isChunkLoaded((int) Math.floor(packetplayinvehiclemove.getX()) >> 4, (int) Math.floor(packetplayinvehiclemove.getZ()) >> 4, false)) {
360+
this.networkManager.sendPacket(new PacketPlayOutVehicleMove(entity));
361+
return;
362+
}
363+
// Paper end
364+
358365
if (d10 - d9 > Math.max(100.0D, Math.pow((double) (org.spigotmc.SpigotConfig.movedTooQuicklyMultiplier * (float) i * speed), 2)) && (!this.minecraftServer.R() || !this.minecraftServer.Q().equals(entity.getName()))) { // Spigot
359366
// CraftBukkit end
360367
PlayerConnection.LOGGER.warn("{} (vehicle of {}) moved too quickly! {},{},{}", entity.getName(), this.player.getName(), Double.valueOf(d6), Double.valueOf(d7), Double.valueOf(d8));
@@ -386,13 +393,13 @@ public void a(PacketPlayInVehicleMove packetplayinvehiclemove) {
386393
}
387394

388395
entity.setLocation(d3, d4, d5, f, f1);
389-
Location curPos = getPlayer().getLocation(); // Paper
390-
player.setLocation(d3, d4, d5, f, f1); // Paper
396+
Location curPos = getPlayer().getLocation(); // Paper
397+
player.setLocation(d3, d4, d5, player.yaw, player.pitch); // CraftBukkit // Paper
391398
boolean flag2 = worldserver.getCubes(entity, entity.getBoundingBox().shrink(0.0625D)).isEmpty();
392399

393400
if (flag && (flag1 || !flag2)) {
394401
entity.setLocation(d0, d1, d2, f, f1);
395-
player.setLocation(d0, d1, d2, f, f1); // Paper
402+
player.setLocation(d3, d4, d5, player.yaw, player.pitch); // CraftBukkit // Paper
396403
this.networkManager.sendPacket(new PacketPlayOutVehicleMove(entity));
397404
return;
398405
}
@@ -552,9 +559,9 @@ public void a(PacketPlayInFlying packetplayinflying) {
552559
double d1 = this.player.locY;
553560
double d2 = this.player.locZ;
554561
double d3 = this.player.locY;
555-
double d4 = packetplayinflying.a(this.player.locX);
562+
double d4 = packetplayinflying.a(this.player.locX); double toX = d4; // Paper - OBFHELPER
556563
double d5 = packetplayinflying.b(this.player.locY);
557-
double d6 = packetplayinflying.c(this.player.locZ);
564+
double d6 = packetplayinflying.c(this.player.locZ); double toZ = d6; // Paper - OBFHELPER
558565
float f = packetplayinflying.a(this.player.yaw);
559566
float f1 = packetplayinflying.b(this.player.pitch);
560567
double d7 = d4 - this.l;
@@ -594,6 +601,13 @@ public void a(PacketPlayInFlying packetplayinflying) {
594601
speed = player.abilities.walkSpeed * 10f;
595602
}
596603

604+
// Paper start - Prevent moving into unloaded chunks
605+
if (player.world.paperConfig.preventMovingIntoUnloadedChunks && (this.player.locX != toX || this.player.locZ != toZ) && !worldserver.isChunkLoaded((int) Math.floor(toX) >> 4, (int) Math.floor(toZ) >> 4, false)) {
606+
this.internalTeleport(this.player.locX, this.player.locY, this.player.locZ, this.player.yaw, this.player.pitch, Collections.emptySet());
607+
return;
608+
}
609+
// Paper end
610+
597611
if (!this.player.L() && (!this.player.x().getGameRules().getBoolean("disableElytraMovementCheck") || !this.player.cP())) {
598612
float f2 = this.player.cP() ? 300.0F : 100.0F;
599613

@@ -1695,7 +1709,7 @@ public void a(PacketPlayInUseEntity packetplayinuseentity) {
16951709

16961710
if (event.isCancelled() || this.player.inventory.getItemInHand() == null || this.player.inventory.getItemInHand().getItem() != origItem) {
16971711
// Refresh the current entity metadata
1698-
this.sendPacket(new PacketPlayOutEntityMetadata(entity.getId(), entity.datawatcher, true));
1712+
entity.tracker.broadcast(new PacketPlayOutEntityMetadata(entity.getId(), entity.datawatcher, true)); // Paper - update entity for all players
16991713
}
17001714

17011715
if (event.isCancelled()) {
@@ -2232,7 +2246,7 @@ public void a(PacketPlayInUpdateSign packetplayinupdatesign) {
22322246

22332247
TileEntitySign tileentitysign = (TileEntitySign) tileentity;
22342248

2235-
if (!tileentitysign.a() || tileentitysign.e() != this.player) {
2249+
if (!tileentitysign.a() || tileentitysign.signEditor == null || !tileentitysign.signEditor.equals(this.player.getUniqueID())) { // Paper
22362250
this.minecraftServer.warning("Player " + this.player.getName() + " just tried to change non-editable sign");
22372251
this.sendPacket(tileentity.getUpdatePacket()); // CraftBukkit
22382252
return;
@@ -2248,6 +2262,14 @@ public void a(PacketPlayInUpdateSign packetplayinupdatesign) {
22482262
String[] lines = new String[4];
22492263

22502264
for (int i = 0; i < astring.length; ++i) {
2265+
// Paper start - cap line length - modified clients can send longer data than normal
2266+
if (astring[i].length() > TileEntitySign.MAX_SIGN_LINE_LENGTH && TileEntitySign.MAX_SIGN_LINE_LENGTH > 0) {
2267+
int offset = astring[i].codePoints().limit(TileEntitySign.MAX_SIGN_LINE_LENGTH).map(Character::charCount).sum();
2268+
if (offset > astring.length) {
2269+
astring[i] = astring[i].substring(0, offset);
2270+
}
2271+
}
2272+
// Paper end
22512273
lines[i] = SharedConstants.a(astring[i]); //Paper - Replaced with anvil color stripping method to stop exploits that allow colored signs to be created.
22522274
}
22532275
SignChangeEvent event = new SignChangeEvent((org.bukkit.craftbukkit.block.CraftBlock) player.getWorld().getBlockAt(x, y, z), this.server.getPlayer(this.player), lines);
@@ -2350,6 +2372,45 @@ public void a(PacketPlayInSettings packetplayinsettings) {
23502372
this.player.a(packetplayinsettings);
23512373
}
23522374

2375+
// Paper start
2376+
private boolean validateBook(ItemStack testStack) {
2377+
NBTTagList pageList = testStack.getTag().getList("pages", 8);
2378+
long byteTotal = 0;
2379+
int maxBookPageSize = com.destroystokyo.paper.PaperConfig.maxBookPageSize;
2380+
double multiplier = Math.max(0.3D, Math.min(1D, com.destroystokyo.paper.PaperConfig.maxBookTotalSizeMultiplier));
2381+
long byteAllowed = maxBookPageSize;
2382+
for (int i = 0; i < pageList.size(); ++i) {
2383+
String testString = pageList.getString(i);
2384+
int byteLength = testString.getBytes(java.nio.charset.StandardCharsets.UTF_8).length;
2385+
byteTotal += byteLength;
2386+
2387+
int length = testString.length();
2388+
int multibytes = 0;
2389+
if (length != byteLength) {
2390+
for (char c : testString.toCharArray()) {
2391+
if (c > 127) {
2392+
multibytes++;
2393+
}
2394+
}
2395+
}
2396+
byteAllowed += (maxBookPageSize * Math.min(1, Math.max(0.1D, (double) length / 255D))) * multiplier;
2397+
2398+
if (multibytes > 1) {
2399+
// penalize MB
2400+
byteAllowed -= multibytes;
2401+
}
2402+
}
2403+
2404+
if (byteTotal > byteAllowed) {
2405+
PlayerConnection.LOGGER.warn(this.player.getName() + " tried to send too large of a book. Book Size: " + byteTotal + " - Allowed: "+ byteAllowed + " - Pages: " + pageList.size());
2406+
minecraftServer.postToMainThread(() -> this.disconnect("Book too large!"));
2407+
return false;
2408+
}
2409+
2410+
return true;
2411+
}
2412+
// Paper end
2413+
23532414
public void a(PacketPlayInCustomPayload packetplayincustompayload) {
23542415
PlayerConnectionUtils.ensureMainThread(packetplayincustompayload, this, this.player.x());
23552416
String s = packetplayincustompayload.a();
@@ -2383,6 +2444,7 @@ public void a(PacketPlayInCustomPayload packetplayincustompayload) {
23832444
}
23842445

23852446
if (itemstack.getItem() == Items.WRITABLE_BOOK && itemstack.getItem() == itemstack1.getItem()) {
2447+
if (!validateBook(itemstack)) return; // Paper
23862448
itemstack1.a("pages", (NBTBase) itemstack.getTag().getList("pages", 8));
23872449
CraftEventFactory.handleEditBookEvent(player, itemstack1); // CraftBukkit
23882450
}
@@ -2418,6 +2480,7 @@ public void a(PacketPlayInCustomPayload packetplayincustompayload) {
24182480
}
24192481

24202482
if (itemstack.getItem() == Items.WRITABLE_BOOK && itemstack1.getItem() == Items.WRITABLE_BOOK) {
2483+
if (!validateBook(itemstack)) return; // Paper
24212484
ItemStack itemstack2 = new ItemStack(Items.WRITTEN_BOOK);
24222485

24232486
itemstack2.a("author", (NBTBase) (new NBTTagString(this.player.getName())));

sources/src/main/java/net/minecraft/server/PlayerList.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public abstract class PlayerList {
7171
// private final Map<UUID, AdvancementDataPlayer> p;
7272
// CraftBukkit end
7373
public IPlayerFileData playerFileData;
74-
private boolean hasWhitelist;
74+
//private boolean hasWhitelist; // Paper - moved to whitelist object so not duplicated
7575
protected int maxPlayers;
7676
private int s;
7777
private EnumGamemode t;
@@ -1241,9 +1241,9 @@ public boolean isWhitelisted(GameProfile gameprofile) {
12411241
}
12421242
public boolean isWhitelisted(GameProfile gameprofile, org.bukkit.event.player.PlayerLoginEvent loginEvent) {
12431243
boolean isOp = this.operators.d(gameprofile);
1244-
boolean isWhitelisted = !this.hasWhitelist || isOp || this.whitelist.d(gameprofile);
1244+
boolean isWhitelisted = !this.getHasWhitelist() || isOp || this.whitelist.d(gameprofile);
12451245
final com.destroystokyo.paper.event.profile.ProfileWhitelistVerifyEvent event;
1246-
event = new com.destroystokyo.paper.event.profile.ProfileWhitelistVerifyEvent(MCUtil.toBukkit(gameprofile), this.hasWhitelist, isWhitelisted, isOp, org.spigotmc.SpigotConfig.whitelistMessage);
1246+
event = new com.destroystokyo.paper.event.profile.ProfileWhitelistVerifyEvent(MCUtil.toBukkit(gameprofile), this.getHasWhitelist(), isWhitelisted, isOp, org.spigotmc.SpigotConfig.whitelistMessage);
12471247
event.callEvent();
12481248
if (!event.isWhitelisted()) {
12491249
if (loginEvent != null) {
@@ -1392,11 +1392,11 @@ public String[] getSeenPlayers() {
13921392
}
13931393

13941394
public boolean getHasWhitelist() {
1395-
return this.hasWhitelist;
1395+
return this.whitelist.isEnabled(); // Paper
13961396
}
13971397

13981398
public void setHasWhitelist(boolean flag) {
1399-
this.hasWhitelist = flag;
1399+
this.whitelist.setEnabled(flag); // Paper
14001400
}
14011401

14021402
public List<EntityPlayer> b(String s) {

sources/src/main/java/net/minecraft/server/World.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -936,7 +936,8 @@ public MovingObjectPosition rayTrace(Vec3D vec3d, Vec3D vec3d1, boolean flag, bo
936936
int i1 = MathHelper.floor(vec3d.y);
937937
int j1 = MathHelper.floor(vec3d.z);
938938
BlockPosition blockposition = new BlockPosition(l, i1, j1);
939-
IBlockData iblockdata = this.getType(blockposition);
939+
IBlockData iblockdata = this.getTypeIfLoaded(blockposition); // Paper
940+
if (iblockdata == null) return null; // Paper
940941
Block block = iblockdata.getBlock();
941942

942943
if ((!flag1 || iblockdata.d(this, blockposition) != Block.k) && block.a(iblockdata, flag)) {
@@ -1038,7 +1039,8 @@ public MovingObjectPosition rayTrace(Vec3D vec3d, Vec3D vec3d1, boolean flag, bo
10381039
i1 = MathHelper.floor(vec3d.y) - (enumdirection == EnumDirection.UP ? 1 : 0);
10391040
j1 = MathHelper.floor(vec3d.z) - (enumdirection == EnumDirection.SOUTH ? 1 : 0);
10401041
blockposition = new BlockPosition(l, i1, j1);
1041-
IBlockData iblockdata1 = this.getType(blockposition);
1042+
IBlockData iblockdata1 = this.getTypeIfLoaded(blockposition); // Paper
1043+
if (iblockdata1 == null) return null; // Paper
10421044
Block block1 = iblockdata1.getBlock();
10431045

10441046
if (!flag1 || iblockdata1.getMaterial() == Material.PORTAL || iblockdata1.d(this, blockposition) != Block.k) {

0 commit comments

Comments
 (0)