Skip to content

Commit

Permalink
Merge pull request #238 from FatSaw/ver/1.12.2
Browse files Browse the repository at this point in the history
Fix plates
  • Loading branch information
josephworks authored Feb 18, 2023
2 parents 7dcfc13 + c398827 commit 104045e
Show file tree
Hide file tree
Showing 9 changed files with 130 additions and 29 deletions.
19 changes: 19 additions & 0 deletions sources/src/main/java/net/minecraft/server/ChunkRegionLoader.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
package net.minecraft.server;

import com.google.common.collect.Maps;
import java.io.DataInputStream;
import java.io.DataOutput;
import java.io.DataOutputStream;
import java.io.File;
import java.io.IOException;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.annotation.Nullable;
import java.util.concurrent.ConcurrentLinkedQueue; // Paper
import org.apache.logging.log4j.LogManager;
Expand Down Expand Up @@ -89,8 +94,22 @@ public boolean chunkExists(int i, int j) {
return nbttagcompound != null ? true : RegionFileCache.chunkExists(this.d, i, j);
}

// Paper start
private static final int CURRENT_DATA_VERSION = 1343; // Paper
private static final boolean JUST_CORRUPT_IT = Boolean.valueOf("Paper.ignoreWorldDataVersion");
// Paper end

@Nullable
protected Object[] a(World world, int i, int j, NBTTagCompound nbttagcompound) { // CraftBukkit - return Chunk -> Object[]
// Paper start - Do NOT attempt to load chunks saved with newer versions
if (nbttagcompound.hasKeyOfType("DataVersion", 3)) {
int dataVersion = nbttagcompound.getInt("DataVersion");
if (!JUST_CORRUPT_IT && dataVersion > CURRENT_DATA_VERSION) {
new RuntimeException("Server attempted to load chunk saved with newer version of minecraft! " + dataVersion + " > " + CURRENT_DATA_VERSION).printStackTrace();
System.exit(1);
}
}
// Paper end
if (!nbttagcompound.hasKeyOfType("Level", 10)) {
ChunkRegionLoader.a.error("Chunk file at {},{} is missing level data, skipping", Integer.valueOf(i), Integer.valueOf(j));
return null;
Expand Down
2 changes: 1 addition & 1 deletion sources/src/main/java/net/minecraft/server/Entity.java
Original file line number Diff line number Diff line change
Expand Up @@ -2965,7 +2965,7 @@ public boolean bI() {
return entity instanceof EntityHuman ? ((EntityHuman) entity).cZ() : !this.world.isClientSide;
}

@Nullable
@Nullable Entity getVehicleDirect() { return this.bJ(); } // Paper - OBFHELPER
public Entity bJ() {
return this.au;
}
Expand Down
7 changes: 7 additions & 0 deletions sources/src/main/java/net/minecraft/server/EntityPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -1096,6 +1096,13 @@ public void b(List<IRecipe> list) {
public void s() {
this.cu = true;
this.ejectPassengers();

// Paper start - "Fixes" an issue where the vehicle doesn't track the passenger disconnection dismount.
if (this.isPassenger() && this.getVehicleDirect() instanceof EntityLiving) {
this.stopRiding();
}
// Paper end

if (this.sleeping) {
this.a(true, false, false);
}
Expand Down
34 changes: 22 additions & 12 deletions sources/src/main/java/net/minecraft/server/NetworkManager.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package net.minecraft.server;

import com.google.common.util.concurrent.ThreadFactoryBuilder;
import com.googlecode.concurentlocks.ReentrantReadWriteUpdateLock;

import io.akarin.api.internal.utils.CheckedConcurrentLinkedQueue;

import com.google.common.collect.Queues;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener;
Expand All @@ -18,9 +19,9 @@
import io.netty.util.AttributeKey;
import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.GenericFutureListener;

import java.net.SocketAddress;
import java.util.Queue;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import javax.annotation.Nullable;
import javax.crypto.SecretKey;
import org.apache.commons.lang3.ArrayUtils;
Expand All @@ -29,7 +30,6 @@
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.Marker;
import org.apache.logging.log4j.MarkerManager;

/**
* Akarin Changes Note
* 2) Expose private members (nsc)
Expand All @@ -47,7 +47,6 @@ protected NioEventLoopGroup a() {
return new NioEventLoopGroup(0, (new ThreadFactoryBuilder()).setNameFormat("Netty Client IO #%d").setDaemon(true).build());
}

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

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

@Override
protected Object init() {
return this.a();
}
Expand Down Expand Up @@ -96,7 +93,6 @@ public NetworkManager(EnumProtocolDirection enumprotocoldirection) {
this.h = enumprotocoldirection;
}

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

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

@Override
public void exceptionCaught(ChannelHandlerContext channelhandlercontext, Throwable throwable) throws Exception {
// Paper start
if (throwable instanceof io.netty.handler.codec.EncoderException && throwable.getCause() instanceof PacketEncoder.PacketTooLargeException) {
if (((PacketEncoder.PacketTooLargeException) throwable.getCause()).getPacket().packetTooLarge(this)) {
return;
} else {
throwable = throwable.getCause();
}
}
// Paper end
ChatMessage chatmessage;

if (throwable instanceof TimeoutException) {
Expand Down Expand Up @@ -212,7 +215,6 @@ private void a(final Packet<?> packet, @Nullable final GenericFutureListener<? e
channelfuture.addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE);
} else {
this.channel.eventLoop().execute(new Runnable() {
@Override
public void run() {
if (enumprotocol != enumprotocol1) {
NetworkManager.this.setProtocol(enumprotocol);
Expand All @@ -229,6 +231,15 @@ public void run() {
});
}

// Paper start
java.util.List<Packet> extraPackets = packet.getExtraPackets();
if (extraPackets != null && !extraPackets.isEmpty()) {
for (Packet extraPacket : extraPackets) {
this.dispatchPacket(extraPacket, agenericfuturelistener);
}
}
// Paper end

}

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

@Override
protected void channelRead0(ChannelHandlerContext channelhandlercontext, Packet object) throws Exception { // CraftBukkit - fix decompile error
// FlamePaper - Check if channel is opened before reading packet
if (isConnected()) {
Expand Down
77 changes: 70 additions & 7 deletions sources/src/main/java/net/minecraft/server/PlayerConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,13 @@ public void a(PacketPlayInVehicleMove packetplayinvehiclemove) {
}
speed *= 2f; // TODO: Get the speed of the vehicle instead of the player

// Paper start - Prevent moving into unloaded chunks
if (player.world.paperConfig.preventMovingIntoUnloadedChunks && !worldserver.isChunkLoaded((int) Math.floor(packetplayinvehiclemove.getX()) >> 4, (int) Math.floor(packetplayinvehiclemove.getZ()) >> 4, false)) {
this.networkManager.sendPacket(new PacketPlayOutVehicleMove(entity));
return;
}
// Paper end

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
// CraftBukkit end
PlayerConnection.LOGGER.warn("{} (vehicle of {}) moved too quickly! {},{},{}", entity.getName(), this.player.getName(), Double.valueOf(d6), Double.valueOf(d7), Double.valueOf(d8));
Expand Down Expand Up @@ -386,13 +393,13 @@ public void a(PacketPlayInVehicleMove packetplayinvehiclemove) {
}

entity.setLocation(d3, d4, d5, f, f1);
Location curPos = getPlayer().getLocation(); // Paper
player.setLocation(d3, d4, d5, f, f1); // Paper
Location curPos = getPlayer().getLocation(); // Paper
player.setLocation(d3, d4, d5, player.yaw, player.pitch); // CraftBukkit // Paper
boolean flag2 = worldserver.getCubes(entity, entity.getBoundingBox().shrink(0.0625D)).isEmpty();

if (flag && (flag1 || !flag2)) {
entity.setLocation(d0, d1, d2, f, f1);
player.setLocation(d0, d1, d2, f, f1); // Paper
player.setLocation(d3, d4, d5, player.yaw, player.pitch); // CraftBukkit // Paper
this.networkManager.sendPacket(new PacketPlayOutVehicleMove(entity));
return;
}
Expand Down Expand Up @@ -552,9 +559,9 @@ public void a(PacketPlayInFlying packetplayinflying) {
double d1 = this.player.locY;
double d2 = this.player.locZ;
double d3 = this.player.locY;
double d4 = packetplayinflying.a(this.player.locX);
double d4 = packetplayinflying.a(this.player.locX); double toX = d4; // Paper - OBFHELPER
double d5 = packetplayinflying.b(this.player.locY);
double d6 = packetplayinflying.c(this.player.locZ);
double d6 = packetplayinflying.c(this.player.locZ); double toZ = d6; // Paper - OBFHELPER
float f = packetplayinflying.a(this.player.yaw);
float f1 = packetplayinflying.b(this.player.pitch);
double d7 = d4 - this.l;
Expand Down Expand Up @@ -594,6 +601,13 @@ public void a(PacketPlayInFlying packetplayinflying) {
speed = player.abilities.walkSpeed * 10f;
}

// Paper start - Prevent moving into unloaded chunks
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)) {
this.internalTeleport(this.player.locX, this.player.locY, this.player.locZ, this.player.yaw, this.player.pitch, Collections.emptySet());
return;
}
// Paper end

if (!this.player.L() && (!this.player.x().getGameRules().getBoolean("disableElytraMovementCheck") || !this.player.cP())) {
float f2 = this.player.cP() ? 300.0F : 100.0F;

Expand Down Expand Up @@ -1695,7 +1709,7 @@ public void a(PacketPlayInUseEntity packetplayinuseentity) {

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

if (event.isCancelled()) {
Expand Down Expand Up @@ -2232,7 +2246,7 @@ public void a(PacketPlayInUpdateSign packetplayinupdatesign) {

TileEntitySign tileentitysign = (TileEntitySign) tileentity;

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

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

// Paper start
private boolean validateBook(ItemStack testStack) {
NBTTagList pageList = testStack.getTag().getList("pages", 8);
long byteTotal = 0;
int maxBookPageSize = com.destroystokyo.paper.PaperConfig.maxBookPageSize;
double multiplier = Math.max(0.3D, Math.min(1D, com.destroystokyo.paper.PaperConfig.maxBookTotalSizeMultiplier));
long byteAllowed = maxBookPageSize;
for (int i = 0; i < pageList.size(); ++i) {
String testString = pageList.getString(i);
int byteLength = testString.getBytes(java.nio.charset.StandardCharsets.UTF_8).length;
byteTotal += byteLength;

int length = testString.length();
int multibytes = 0;
if (length != byteLength) {
for (char c : testString.toCharArray()) {
if (c > 127) {
multibytes++;
}
}
}
byteAllowed += (maxBookPageSize * Math.min(1, Math.max(0.1D, (double) length / 255D))) * multiplier;

if (multibytes > 1) {
// penalize MB
byteAllowed -= multibytes;
}
}

if (byteTotal > byteAllowed) {
PlayerConnection.LOGGER.warn(this.player.getName() + " tried to send too large of a book. Book Size: " + byteTotal + " - Allowed: "+ byteAllowed + " - Pages: " + pageList.size());
minecraftServer.postToMainThread(() -> this.disconnect("Book too large!"));
return false;
}

return true;
}
// Paper end

public void a(PacketPlayInCustomPayload packetplayincustompayload) {
PlayerConnectionUtils.ensureMainThread(packetplayincustompayload, this, this.player.x());
String s = packetplayincustompayload.a();
Expand Down Expand Up @@ -2383,6 +2444,7 @@ public void a(PacketPlayInCustomPayload packetplayincustompayload) {
}

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

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

itemstack2.a("author", (NBTBase) (new NBTTagString(this.player.getName())));
Expand Down
10 changes: 5 additions & 5 deletions sources/src/main/java/net/minecraft/server/PlayerList.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public abstract class PlayerList {
// private final Map<UUID, AdvancementDataPlayer> p;
// CraftBukkit end
public IPlayerFileData playerFileData;
private boolean hasWhitelist;
//private boolean hasWhitelist; // Paper - moved to whitelist object so not duplicated
protected int maxPlayers;
private int s;
private EnumGamemode t;
Expand Down Expand Up @@ -1241,9 +1241,9 @@ public boolean isWhitelisted(GameProfile gameprofile) {
}
public boolean isWhitelisted(GameProfile gameprofile, org.bukkit.event.player.PlayerLoginEvent loginEvent) {
boolean isOp = this.operators.d(gameprofile);
boolean isWhitelisted = !this.hasWhitelist || isOp || this.whitelist.d(gameprofile);
boolean isWhitelisted = !this.getHasWhitelist() || isOp || this.whitelist.d(gameprofile);
final com.destroystokyo.paper.event.profile.ProfileWhitelistVerifyEvent event;
event = new com.destroystokyo.paper.event.profile.ProfileWhitelistVerifyEvent(MCUtil.toBukkit(gameprofile), this.hasWhitelist, isWhitelisted, isOp, org.spigotmc.SpigotConfig.whitelistMessage);
event = new com.destroystokyo.paper.event.profile.ProfileWhitelistVerifyEvent(MCUtil.toBukkit(gameprofile), this.getHasWhitelist(), isWhitelisted, isOp, org.spigotmc.SpigotConfig.whitelistMessage);
event.callEvent();
if (!event.isWhitelisted()) {
if (loginEvent != null) {
Expand Down Expand Up @@ -1392,11 +1392,11 @@ public String[] getSeenPlayers() {
}

public boolean getHasWhitelist() {
return this.hasWhitelist;
return this.whitelist.isEnabled(); // Paper
}

public void setHasWhitelist(boolean flag) {
this.hasWhitelist = flag;
this.whitelist.setEnabled(flag); // Paper
}

public List<EntityPlayer> b(String s) {
Expand Down
6 changes: 4 additions & 2 deletions sources/src/main/java/net/minecraft/server/World.java
Original file line number Diff line number Diff line change
Expand Up @@ -936,7 +936,8 @@ public MovingObjectPosition rayTrace(Vec3D vec3d, Vec3D vec3d1, boolean flag, bo
int i1 = MathHelper.floor(vec3d.y);
int j1 = MathHelper.floor(vec3d.z);
BlockPosition blockposition = new BlockPosition(l, i1, j1);
IBlockData iblockdata = this.getType(blockposition);
IBlockData iblockdata = this.getTypeIfLoaded(blockposition); // Paper
if (iblockdata == null) return null; // Paper
Block block = iblockdata.getBlock();

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

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

0 comments on commit 104045e

Please sign in to comment.