2020-05-06 11:48:49 +02:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
2016-03-01 00:09:49 +01:00
|
|
|
From: Joseph Hirschfeld <joe@ibj.io>
|
|
|
|
Date: Thu, 3 Mar 2016 02:48:12 -0600
|
|
|
|
Subject: [PATCH] Add velocity warnings
|
|
|
|
|
|
|
|
|
2017-01-08 23:43:08 +01:00
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
2021-06-11 08:29:15 +02:00
|
|
|
index f78f5e4f2c04b64dff1d2229a137c600f18e7051..22b4dec4944b7f823996645af95fbef2d1d8a83b 100644
|
2017-01-08 23:43:08 +01:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
2021-05-18 00:32:29 +02:00
|
|
|
@@ -261,6 +261,7 @@ public final class CraftServer implements Server {
|
2018-07-15 03:53:17 +02:00
|
|
|
public boolean ignoreVanillaPermissions = false;
|
2017-01-08 23:43:08 +01:00
|
|
|
private final List<CraftPlayer> playerView;
|
|
|
|
public int reloadCount;
|
|
|
|
+ public static Exception excessiveVelEx; // Paper - Velocity warnings
|
|
|
|
|
2019-04-26 03:24:00 +02:00
|
|
|
static {
|
|
|
|
ConfigurationSerialization.registerClass(CraftOfflinePlayer.class);
|
2016-03-01 00:09:49 +01:00
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
|
2021-03-16 08:19:45 +01:00
|
|
|
index 220bad90bbb9a90c3f23562bf0fb109fce379682..a58626b1a0160983a738a45c8a1d411eb347e6a2 100644
|
2016-03-01 00:09:49 +01:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
|
2021-03-16 08:19:45 +01:00
|
|
|
@@ -424,10 +424,41 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
|
2017-06-03 06:41:05 +02:00
|
|
|
public void setVelocity(Vector velocity) {
|
|
|
|
Preconditions.checkArgument(velocity != null, "velocity");
|
|
|
|
velocity.checkFinite();
|
2016-03-01 00:09:49 +01:00
|
|
|
+ // Paper start - Warn server owners when plugins try to set super high velocities
|
2017-06-03 06:41:05 +02:00
|
|
|
+ if (!(this instanceof org.bukkit.entity.Projectile) && isUnsafeVelocity(velocity)) {
|
|
|
|
+ CraftServer.excessiveVelEx = new Exception("Excessive velocity set detected: tried to set velocity of entity " + entity.getName() + " id #" + getEntityId() + " to (" + velocity.getX() + "," + velocity.getY() + "," + velocity.getZ() + ").");
|
2016-03-01 00:09:49 +01:00
|
|
|
+ }
|
|
|
|
+ // Paper end
|
2017-06-03 06:41:05 +02:00
|
|
|
+
|
2019-04-26 03:24:00 +02:00
|
|
|
entity.setMot(CraftVector.toNMS(velocity));
|
2017-05-28 07:06:26 +02:00
|
|
|
entity.velocityChanged = 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() {
|
2019-04-26 03:24:00 +02:00
|
|
|
return getHandle().getHeight();
|
2017-01-08 23:43:08 +01:00
|
|
|
diff --git a/src/main/java/org/spigotmc/WatchdogThread.java b/src/main/java/org/spigotmc/WatchdogThread.java
|
2021-03-16 08:19:45 +01:00
|
|
|
index 1b3a14784cac8e855633fae6172ad5479ebe9877..69e5054886b5858664fed333aca8c25a76e5cb11 100644
|
2017-01-08 23:43:08 +01:00
|
|
|
--- a/src/main/java/org/spigotmc/WatchdogThread.java
|
|
|
|
+++ b/src/main/java/org/spigotmc/WatchdogThread.java
|
2021-01-12 21:06:27 +01:00
|
|
|
@@ -80,7 +80,19 @@ public class WatchdogThread extends Thread
|
2017-01-08 23:43:08 +01:00
|
|
|
log.log( Level.SEVERE, "During the run of the server, a physics stackoverflow was supressed" );
|
2021-03-16 08:19:45 +01:00
|
|
|
log.log( Level.SEVERE, "near " + net.minecraft.world.level.World.lastPhysicsProblem );
|
2017-01-08 23:43:08 +01:00
|
|
|
}
|
|
|
|
- //
|
|
|
|
+ // 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, "------------------------------" );
|
2019-04-26 03:24:00 +02:00
|
|
|
log.log( Level.SEVERE, "Server thread dump (Look for plugins here before reporting to Paper!):" ); // Paper
|
|
|
|
dumpThread( ManagementFactory.getThreadMXBean().getThreadInfo( MinecraftServer.getServer().serverThread.getId(), Integer.MAX_VALUE ), log );
|