Fixed incorrect velocity
This commit is contained in:
parent
7910170327
commit
ac4755a5a9
@ -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<Player, Vector> VelocityFix = new NautHashMap<Player,Vector>();
|
||||
|
||||
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);
|
||||
@ -42,10 +43,10 @@ public class UtilAction
|
||||
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);
|
||||
|
@ -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<Player> keyIter = UtilAction.VelocityFix.keySet().iterator();
|
||||
|
||||
while (keyIter.hasNext())
|
||||
{
|
||||
Player player = keyIter.next();
|
||||
|
||||
if (player.isOnline())
|
||||
keyIter.remove();
|
||||
}
|
||||
}
|
||||
}
|
@ -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);
|
||||
|
@ -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())
|
||||
|
@ -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,11 +87,15 @@ 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);
|
||||
|
||||
_serverConfiguration = new ServerConfiguration(this, _clientManager);
|
||||
|
Loading…
Reference in New Issue
Block a user