Add velocity warnings
This commit is contained in:
@@ -132,10 +132,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();
|
||||
|
||||
Reference in New Issue
Block a user