diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilAction.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilAction.java index 09160ddc7..c07d2ed4a 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilAction.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilAction.java @@ -1,6 +1,5 @@ package mineplex.core.common.util; - import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.entity.Entity; @@ -9,6 +8,8 @@ import org.bukkit.util.Vector; public class UtilAction { + public static NautHashMap VelocityFix = new NautHashMap(); + public static void velocity(Entity ent, double str, double yAdd, double yMax, boolean groundBoost) { velocity(ent, ent.getLocation().getDirection(), str, false, 0, yAdd, yMax, groundBoost); @@ -41,13 +42,13 @@ public class UtilAction //Velocity ent.setFallDistance(0); - - //Debug - if (ent instanceof Player && UtilGear.isMat(((Player)ent).getItemInHand(), Material.SUGAR)) + + //Store It! + if (ent instanceof Player) { - Bukkit.broadcastMessage(F.main("Debug", "Velocity Sent: " + vec.length())); - } - + VelocityFix.put(((Player)ent), vec); + } + ent.setVelocity(vec); } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/velocity/VelocityFix.java b/Plugins/Mineplex.Core/src/mineplex/core/velocity/VelocityFix.java new file mode 100644 index 000000000..a4124f27a --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/velocity/VelocityFix.java @@ -0,0 +1,65 @@ +package mineplex.core.velocity; + +import java.util.Iterator; + +import mineplex.core.MiniPlugin; +import mineplex.core.common.util.UtilAction; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; + +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.event.player.PlayerVelocityEvent; +import org.bukkit.plugin.java.JavaPlugin; + +public class VelocityFix extends MiniPlugin +{ + /* + * The purpose of this class is to fix a bug inherent in Minecraft, + * where player join order will somehow modify the velocity sent to players. + * + * To fix it, we simply save the velocity that the player should have received, + * then we re-set those values in CB the moment its about to actually apply the velocity to a player. + * + * The problem was caused by the fact that CB does not run a PlayerVelocityEvent the moment we + * set a players velocity, instead it waits until the next tick, and the velocity may have been changed. + * + */ + + public VelocityFix(JavaPlugin plugin) + { + super("Velocity Fix", plugin); + } + + @EventHandler(priority = EventPriority.LOWEST) + public void fixVelocity(PlayerVelocityEvent event) + { + if (UtilAction.VelocityFix.containsKey(event.getPlayer())) + event.getPlayer().setVelocity(UtilAction.VelocityFix.remove(event.getPlayer())); + } + + @EventHandler + public void cleanVelocity(PlayerQuitEvent event) + { + UtilAction.VelocityFix.remove(event.getPlayer()); + } + + @EventHandler + public void cleanVelocity(UpdateEvent event) + { + if (event.getType() != UpdateType.SLOW) + return; + + Iterator keyIter = UtilAction.VelocityFix.keySet().iterator(); + + while (keyIter.hasNext()) + { + Player player = keyIter.next(); + + if (player.isOnline()) + keyIter.remove(); + } + } +} diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java b/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java index 1cf6b3b8f..0873db91b 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java @@ -46,6 +46,7 @@ import mineplex.core.task.TaskManager; import mineplex.core.teleport.Teleport; import mineplex.core.updater.FileUpdater; import mineplex.core.updater.Updater; +import mineplex.core.velocity.VelocityFix; import mineplex.core.visibility.VisibilityManager; import mineplex.hub.modules.StackerManager; import mineplex.hub.poll.PollManager; @@ -78,6 +79,9 @@ public class Hub extends JavaPlugin implements IRelation //Logger.initialize(this); + //Velocity Fix + new VelocityFix(this); + //Static Modules CommandCenter.Initialize(this); CoreClientManager clientManager = new CoreClientManager(this, webServerAddress); diff --git a/Plugins/Mineplex.Minecraft.Game.Core/src/mineplex/minecraft/game/core/damage/DamageManager.java b/Plugins/Mineplex.Minecraft.Game.Core/src/mineplex/minecraft/game/core/damage/DamageManager.java index 1d699e938..ec5e4113c 100644 --- a/Plugins/Mineplex.Minecraft.Game.Core/src/mineplex/minecraft/game/core/damage/DamageManager.java +++ b/Plugins/Mineplex.Minecraft.Game.Core/src/mineplex/minecraft/game/core/damage/DamageManager.java @@ -395,7 +395,7 @@ public class DamageManager extends MiniPlugin if (event.GetDamageeEntity() instanceof Player && UtilGear.isMat(((Player)event.GetDamageeEntity()).getItemInHand(), Material.SUGAR)) { Bukkit.broadcastMessage("--------- " + - UtilEnt.getName(event.GetDamageeEntity()) + " hurt by " + UtilEnt.getName(event.GetDamagerEntity(true)) + "-----------" ); + UtilEnt.getName(event.GetDamageeEntity()) + " hit by " + UtilEnt.getName(event.GetDamagerEntity(true)) + "-----------" ); Bukkit.broadcastMessage(F.main("Debug", "Damage: " + event.GetDamage())); } @@ -422,15 +422,6 @@ public class DamageManager extends MiniPlugin } } - @EventHandler - public void debugVel2(PlayerVelocityEvent event) - { - if (UtilGear.isMat(((Player)event.getPlayer()).getItemInHand(), Material.SUGAR)) - { - Bukkit.broadcastMessage(F.main("Debug", "Event: " + event.getVelocity().length())); - } - } - private void DisplayDamage(CustomDamageEvent event) { for (Player player : UtilServer.getPlayers()) diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/Arcade.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/Arcade.java index b61c92d36..772f894ed 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/Arcade.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/Arcade.java @@ -48,6 +48,7 @@ import mineplex.core.status.ServerStatusManager; import mineplex.core.teleport.Teleport; import mineplex.core.updater.FileUpdater; import mineplex.core.updater.Updater; +import mineplex.core.velocity.VelocityFix; import mineplex.core.visibility.VisibilityManager; import mineplex.minecraft.game.core.combat.CombatManager; import mineplex.minecraft.game.core.damage.DamageManager; @@ -86,10 +87,14 @@ public class Arcade extends JavaPlugin _clientManager = new CoreClientManager(this, webServerAddress); CommandCenter.Instance.setClientManager(_clientManager); + ItemStackFactory.Initialize(this, false); Recharge.Initialize(this); VisibilityManager.Initialize(this); Give.Initialize(this); + + //Velocity Fix + new VelocityFix(this); _donationManager = new DonationManager(this, _clientManager, webServerAddress);