Merge pull request #267 from LoJoSho/unsafe_velocity_fix

Unsafe velocity fix
This commit is contained in:
Will FP 2022-07-21 15:24:18 +01:00 committed by GitHub
commit 97645ada4d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 1 deletions

View File

@ -4,11 +4,13 @@ import com.willfp.ecoenchants.enchantments.EcoEnchant;
import com.willfp.ecoenchants.enchantments.EcoEnchants;
import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
import com.willfp.ecoenchants.enchantments.util.EnchantChecks;
import com.willfp.ecoenchants.enchantments.util.VelocityChecks;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.util.Vector;
import org.jetbrains.annotations.NotNull;
public class Launch extends EcoEnchant {
@ -54,7 +56,12 @@ public class Launch extends EcoEnchant {
int level = EnchantChecks.getChestplateLevel(player, this);
double multiplier = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "multiplier");
double boost = 1 + (multiplier * level);
Vector vector = player.getVelocity().multiply(boost);
this.getPlugin().getScheduler().run(() -> player.setVelocity(player.getVelocity().multiply(boost)));
if (VelocityChecks.isUnsafeVelocity(vector)) {
return;
}
this.getPlugin().getScheduler().run(() -> player.setVelocity(vector));
}
}

View File

@ -0,0 +1,22 @@
package com.willfp.ecoenchants.enchantments.util;
import org.bukkit.util.Vector;
public class VelocityChecks {
/**
* Checks to see if the velocity is unsafe. This is taken from Papers 0054-Add-velocity-warnings.patch
* @param vel
* @return
*/
public 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;
}
}