Upstream Paper

This commit is contained in:
Sotr
2018-08-19 20:31:26 +08:00
parent 818f5559f7
commit 10d2d285d9
4 changed files with 43 additions and 18 deletions

View File

@@ -22,8 +22,10 @@ import net.minecraft.server.MinecraftServer;
public abstract class Watchcat extends Thread { public abstract class Watchcat extends Thread {
@Shadow private static WatchdogThread instance; @Shadow private static WatchdogThread instance;
@Shadow private @Final long timeoutTime; @Shadow private @Final long timeoutTime;
@Shadow private @Final long shortTimeout; // Paper - Timeout time for just printing a dump but not restarting @Shadow private @Final long earlyWarningEvery; // Paper - Timeout time for just printing a dump but not restarting
@Shadow private long lastShortDump; // Paper - Keep track of short dump times to avoid spamming console with short dumps @Shadow private @Final long earlyWarningDelay; // Paper
@Shadow public static volatile boolean hasStarted; // Paper
@Shadow private long lastEarlyWarning; // Paper - Keep track of short dump times to avoid spamming console with short dumps
@Shadow private @Final boolean restart; @Shadow private @Final boolean restart;
@Shadow private volatile long lastTick; @Shadow private volatile long lastTick;
@Shadow private volatile boolean stopping; @Shadow private volatile boolean stopping;
@@ -39,24 +41,23 @@ public abstract class Watchcat extends Thread {
@Overwrite @Overwrite
public void run() { public void run() {
while (!stopping) { while (!stopping) {
// // Paper start
long currentTime = System.currentTimeMillis(); // Paper - do we REALLY need to call this method multiple times? long currentTime = System.currentTimeMillis();
if (lastTick != 0 && currentTime > lastTick + shortTimeout && !Boolean.getBoolean("disable.watchdog")) // Paper - Add property to disable and short timeout if ( lastTick != 0 && currentTime > lastTick + earlyWarningEvery && !Boolean.getBoolean("disable.watchdog") )
{ {
// Paper start
boolean isLongTimeout = currentTime > lastTick + timeoutTime; boolean isLongTimeout = currentTime > lastTick + timeoutTime;
// Don't spam short dumps // Don't spam early warning dumps
if (!isLongTimeout && currentTime < lastShortDump + shortTimeout) if (!isLongTimeout && (earlyWarningEvery <= 0 || !hasStarted || currentTime < lastEarlyWarning + earlyWarningEvery || currentTime < lastTick + earlyWarningDelay))
continue; continue;
lastShortDump = currentTime; lastEarlyWarning = currentTime;
// Paper end // Paper end
Logger log = Bukkit.getServer().getLogger(); Logger log = Bukkit.getServer().getLogger();
// Paper start - Different message when it's a short timeout // Paper start - Different message when it's a short timeout
if (isLongTimeout) { if (isLongTimeout) {
log.log(Level.SEVERE, "The server has stopped responding!"); log.log(Level.SEVERE, "The server has stopped responding!");
log.log(Level.SEVERE, "Please report this to https://github.com/Akarin-project/Akarin/issues"); log.log(Level.SEVERE, "Please report this to https://github.com/Akarin-project/Akarin/issues"); // Akarin
log.log(Level.SEVERE, "Be sure to include ALL relevant console errors and Minecraft crash reports"); log.log(Level.SEVERE, "Be sure to include ALL relevant console errors and Minecraft crash reports");
log.log(Level.SEVERE, "Paper version: " + Bukkit.getServer().getVersion()); log.log(Level.SEVERE, "Akarin version: " + Bukkit.getServer().getVersion()); // Akarin
// //
if (net.minecraft.server.World.haveWeSilencedAPhysicsCrash) { if (net.minecraft.server.World.haveWeSilencedAPhysicsCrash) {
log.log(Level.SEVERE, "------------------------------"); log.log(Level.SEVERE, "------------------------------");
@@ -75,7 +76,8 @@ public abstract class Watchcat extends Thread {
} }
// Paper end // Paper end
} else { } else {
log.log(Level.SEVERE, "The server has not responded for " + shortTimeout / 1000 + " seconds! Creating thread dump"); // log.log(Level.SEVERE, "--- DO NOT REPORT THIS TO PAPER - THIS IS NOT A BUG OR A CRASH ---"); // Akarin
log.log(Level.SEVERE, "The server has not responded for " + (currentTime - lastTick) / 1000 + " seconds! Creating thread dump");
} }
// Paper end - Different message for short timeout // Paper end - Different message for short timeout
log.log(Level.SEVERE, "------------------------------"); log.log(Level.SEVERE, "------------------------------");
@@ -90,8 +92,13 @@ public abstract class Watchcat extends Thread {
for (ThreadInfo thread : threads) { for (ThreadInfo thread : threads) {
dumpThread(thread, log); dumpThread(thread, log);
} }
} else {
// log.log(Level.SEVERE, "--- DO NOT REPORT THIS TO PAPER - THIS IS NOT A BUG OR A CRASH ---"); // Akarin
}
log.log(Level.SEVERE, "------------------------------"); log.log(Level.SEVERE, "------------------------------");
if ( isLongTimeout )
{
if (restart) { if (restart) {
RestartCommand.restart(); RestartCommand.restart();
} }

View File

@@ -1315,6 +1315,7 @@ public abstract class Entity implements ICommandListener, KeyedObject { // Paper
this.lastYaw -= 360.0F; this.lastYaw -= 360.0F;
} }
world.getChunkAt((int) Math.floor(this.locX) >> 4, (int) Math.floor(this.locZ) >> 4); // Paper - ensure chunk is always loaded
this.setPosition(this.locX, this.locY, this.locZ); this.setPosition(this.locX, this.locY, this.locZ);
this.setYawPitch(f, f1); this.setYawPitch(f, f1);
} }

View File

@@ -1252,8 +1252,25 @@ public abstract class PlayerList {
} }
public void sendPacketNearby(@Nullable EntityHuman entityhuman, double d0, double d1, double d2, double d3, int i, Packet<?> packet) { public void sendPacketNearby(@Nullable EntityHuman entityhuman, double d0, double d1, double d2, double d3, int i, Packet<?> packet) {
for (int j = 0; j < this.players.size(); ++j) { // Paper start - Use world list instead of server list where preferable
EntityPlayer entityplayer = this.players.get(j); sendPacketNearby(entityhuman, d0, d1, d2, d3, i, null, packet); // Retained for compatibility
}
public void sendPacketNearby(@Nullable EntityHuman entityhuman, double d0, double d1, double d2, double d3, WorldServer world, Packet<?> packet) {
sendPacketNearby(entityhuman, d0, d1, d2, d3, world.dimension, world, packet);
}
public void sendPacketNearby(@Nullable EntityHuman entityhuman, double d0, double d1, double d2, double d3, int i, @Nullable WorldServer world, Packet<?> packet) {
if (world == null && entityhuman != null && entityhuman.world instanceof WorldServer) {
world = (WorldServer) entityhuman.world;
}
List<? extends EntityHuman> players1 = world == null ? players : world.players;
for (int j = 0; j < players1.size(); ++j) {
EntityHuman entity = players1.get(j);
if (!(entity instanceof EntityPlayer)) continue;
EntityPlayer entityplayer = (EntityPlayer) players1.get(j);
// Paper end
// CraftBukkit start - Test if player receiving packet can see the source of the packet // CraftBukkit start - Test if player receiving packet can see the source of the packet
if (entityhuman != null && entityhuman instanceof EntityPlayer && !entityplayer.getBukkitEntity().canSee(((EntityPlayer) entityhuman).getBukkitEntity())) { if (entityhuman != null && entityhuman instanceof EntityPlayer && !entityplayer.getBukkitEntity().canSee(((EntityPlayer) entityhuman).getBukkitEntity())) {
@@ -1261,7 +1278,7 @@ public abstract class PlayerList {
} }
// CraftBukkit end // CraftBukkit end
if (entityplayer != entityhuman && entityplayer.dimension == i) { if (entityplayer != entityhuman && (world != null || entityplayer.dimension == i)) { // Paper
double d4 = d0 - entityplayer.locX; double d4 = d0 - entityplayer.locX;
double d5 = d1 - entityplayer.locY; double d5 = d1 - entityplayer.locY;
double d6 = d2 - entityplayer.locZ; double d6 = d2 - entityplayer.locZ;

View File

@@ -1291,7 +1291,7 @@ public class WorldServer extends World implements IAsyncTaskHandler {
} }
// CraftBukkit end // CraftBukkit end
if (super.strikeLightning(entity)) { if (super.strikeLightning(entity)) {
this.server.getPlayerList().sendPacketNearby((EntityHuman) null, entity.locX, entity.locY, entity.locZ, 512.0D, dimension, new PacketPlayOutSpawnEntityWeather(entity)); // CraftBukkit - Use dimension this.server.getPlayerList().sendPacketNearby((EntityHuman) null, entity.locX, entity.locY, entity.locZ, 512.0D, this, new PacketPlayOutSpawnEntityWeather(entity)); // CraftBukkit - Use dimension, // Paper - use world instead of dimension
return true; return true;
} else { } else {
return false; return false;
@@ -1369,8 +1369,8 @@ public class WorldServer extends World implements IAsyncTaskHandler {
BlockActionData blockactiondata = (BlockActionData) iterator.next(); BlockActionData blockactiondata = (BlockActionData) iterator.next();
if (this.a(blockactiondata)) { if (this.a(blockactiondata)) {
// CraftBukkit - this.worldProvider.dimension -> this.dimension // CraftBukkit - this.worldProvider.dimension -> this.dimension, // Paper - dimension -> world
this.server.getPlayerList().sendPacketNearby((EntityHuman) null, blockactiondata.a().getX(), blockactiondata.a().getY(), blockactiondata.a().getZ(), 64.0D, dimension, new PacketPlayOutBlockAction(blockactiondata.a(), blockactiondata.d(), blockactiondata.b(), blockactiondata.c())); this.server.getPlayerList().sendPacketNearby((EntityHuman) null, (double) blockactiondata.a().getX(), (double) blockactiondata.a().getY(), (double) blockactiondata.a().getZ(), 64.0D, this, new PacketPlayOutBlockAction(blockactiondata.a(), blockactiondata.d(), blockactiondata.b(), blockactiondata.c()));
} }
} }