mirror of
https://github.com/Auxilor/EcoEnchants.git
synced 2025-01-21 00:21:20 +01:00
Merge pull request #267 from LoJoSho/unsafe_velocity_fix
Unsafe velocity fix
This commit is contained in:
commit
97645ada4d
@ -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));
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user