mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-14 06:36:33 +01:00
89 lines
4.9 KiB
Diff
89 lines
4.9 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Joseph Hirschfeld <joe@ibj.io>
|
|
Date: Thu, 3 Mar 2016 02:48:12 -0600
|
|
Subject: [PATCH] Add velocity warnings
|
|
|
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
|
index eb7eb3fdb2f677c5d6d7503d2809f61e48900205..26428b73e23e71872e148f041c18c741ee05f4c8 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
|
@@ -301,6 +301,7 @@ public final class CraftServer implements Server {
|
|
public boolean ignoreVanillaPermissions = false;
|
|
private final List<CraftPlayer> playerView;
|
|
public int reloadCount;
|
|
+ public static Exception excessiveVelEx; // Paper - Velocity warnings
|
|
|
|
static {
|
|
ConfigurationSerialization.registerClass(CraftOfflinePlayer.class);
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
|
|
index 21f670644815474102da3fd1047f63a7a13adfa6..59d076f4e25735f4c6815dfe27904a82eefc1756 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
|
|
@@ -470,10 +470,40 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
|
|
public void setVelocity(Vector velocity) {
|
|
Preconditions.checkArgument(velocity != null, "velocity");
|
|
velocity.checkFinite();
|
|
+ // Paper start - Warn server owners when plugins try to set super high velocities
|
|
+ if (!(this instanceof org.bukkit.entity.Projectile || this instanceof org.bukkit.entity.Minecart) && isUnsafeVelocity(velocity)) {
|
|
+ CraftServer.excessiveVelEx = new Exception("Excessive velocity set detected: tried to set velocity of entity " + entity.getScoreboardName() + " id #" + getEntityId() + " to (" + velocity.getX() + "," + velocity.getY() + "," + velocity.getZ() + ").");
|
|
+ }
|
|
+ // Paper end
|
|
this.entity.setDeltaMovement(CraftVector.toNMS(velocity));
|
|
this.entity.hurtMarked = true;
|
|
}
|
|
|
|
+ // Paper start
|
|
+ /**
|
|
+ * Checks if the given velocity is not necessarily safe in all situations.
|
|
+ * This function returning true does not mean the velocity is dangerous or to be avoided, only that it may be
|
|
+ * a detriment to performance on the server.
|
|
+ *
|
|
+ * It is not to be used as a hard rule of any sort.
|
|
+ * Paper only uses it to warn server owners in watchdog crashes.
|
|
+ *
|
|
+ * @param vel incoming velocity to check
|
|
+ * @return if the velocity has the potential to be a performance detriment
|
|
+ */
|
|
+ private static boolean isUnsafeVelocity(Vector vel) {
|
|
+ final double x = vel.getX();
|
|
+ final double y = vel.getY();
|
|
+ final double z = vel.getZ();
|
|
+
|
|
+ if (x > 4 || x < -4 || y > 4 || y < -4 || z > 4 || z < -4) {
|
|
+ return true;
|
|
+ }
|
|
+
|
|
+ return false;
|
|
+ }
|
|
+ // Paper end
|
|
+
|
|
@Override
|
|
public double getHeight() {
|
|
return this.getHandle().getBbHeight();
|
|
diff --git a/src/main/java/org/spigotmc/WatchdogThread.java b/src/main/java/org/spigotmc/WatchdogThread.java
|
|
index cacbde8ac27a70b5e3bcd76ad90bc667abee3817..b5a2cbc21165e80820d6f7e2690e6e18de54c420 100644
|
|
--- a/src/main/java/org/spigotmc/WatchdogThread.java
|
|
+++ b/src/main/java/org/spigotmc/WatchdogThread.java
|
|
@@ -80,7 +80,19 @@ public final class WatchdogThread extends io.papermc.paper.util.TickThread // Pa
|
|
log.log( Level.SEVERE, "During the run of the server, a physics stackoverflow was supressed" );
|
|
log.log( Level.SEVERE, "near " + net.minecraft.world.level.Level.lastPhysicsProblem );
|
|
}
|
|
- //
|
|
+ // Paper start - Warn in watchdog if an excessive velocity was ever set
|
|
+ if ( org.bukkit.craftbukkit.CraftServer.excessiveVelEx != null )
|
|
+ {
|
|
+ log.log( Level.SEVERE, "------------------------------" );
|
|
+ log.log( Level.SEVERE, "During the run of the server, a plugin set an excessive velocity on an entity" );
|
|
+ log.log( Level.SEVERE, "This may be the cause of the issue, or it may be entirely unrelated" );
|
|
+ log.log( Level.SEVERE, org.bukkit.craftbukkit.CraftServer.excessiveVelEx.getMessage());
|
|
+ for ( StackTraceElement stack : org.bukkit.craftbukkit.CraftServer.excessiveVelEx.getStackTrace() )
|
|
+ {
|
|
+ log.log( Level.SEVERE, "\t\t" + stack );
|
|
+ }
|
|
+ }
|
|
+ // Paper end
|
|
log.log( Level.SEVERE, "------------------------------" );
|
|
log.log( Level.SEVERE, "Server thread dump (Look for plugins here before reporting to Paper!):" ); // Paper
|
|
io.papermc.paper.chunk.system.scheduling.ChunkTaskScheduler.dumpAllChunkLoadInfo(isLongTimeout); // Paper // Paper - rewrite chunk system
|