From 6981c78f9082c33d86babd41cc45ad9bdb082d54 Mon Sep 17 00:00:00 2001 From: LoJoSho Date: Sat, 16 Jul 2022 21:03:28 -0500 Subject: [PATCH 1/3] Adds velocity check util --- .../enchantments/util/VelocityChecks.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/util/VelocityChecks.java 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; + } +} From 51dd9d9cf4adcb03f6a730cc01b0da2c5aa235b6 Mon Sep 17 00:00:00 2001 From: LoJoSho Date: Sat, 16 Jul 2022 21:03:49 -0500 Subject: [PATCH 2/3] Launch check --- .../ecoenchants/enchantments/ecoenchants/normal/Launch.java | 5 +++++ 1 file changed, 5 insertions(+) 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..cf646b50 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,6 +4,7 @@ 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; @@ -55,6 +56,10 @@ public class Launch extends EcoEnchant { double multiplier = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "multiplier"); double boost = 1 + (multiplier * level); + if (VelocityChecks.isUnsafeVelocity(player.getVelocity().multiply(boost))) { + return; + } + this.getPlugin().getScheduler().run(() -> player.setVelocity(player.getVelocity().multiply(boost))); } } From 17a23a373d9a0f7b181f281f040615ce890f4944 Mon Sep 17 00:00:00 2001 From: LoJoSho Date: Sat, 16 Jul 2022 21:33:24 -0500 Subject: [PATCH 3/3] multiply once not twice --- .../ecoenchants/enchantments/ecoenchants/normal/Launch.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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 cf646b50..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 @@ -10,6 +10,7 @@ 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 { @@ -55,11 +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); - if (VelocityChecks.isUnsafeVelocity(player.getVelocity().multiply(boost))) { + if (VelocityChecks.isUnsafeVelocity(vector)) { return; } - this.getPlugin().getScheduler().run(() -> player.setVelocity(player.getVelocity().multiply(boost))); + this.getPlugin().getScheduler().run(() -> player.setVelocity(vector)); } }