diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Launch.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Launch.java index 78d29ace..1e3a25f4 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Launch.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Launch.java @@ -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)); } } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/util/VelocityChecks.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/util/VelocityChecks.java new file mode 100644 index 00000000..536ce6a9 --- /dev/null +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/util/VelocityChecks.java @@ -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; + } +}