refactored a little so theres no data stored in the util
This commit is contained in:
parent
afc41c8831
commit
638406254b
@ -6,16 +6,16 @@ import org.bukkit.util.Vector;
|
||||
|
||||
public class UtilAction
|
||||
{
|
||||
private static NautHashMap<Player, Vector> _velocityFix = new NautHashMap<Player,Vector>();
|
||||
private static VelocityReceiver _velocityFix;
|
||||
|
||||
public static void velocity(Entity ent, Vector vec)
|
||||
{
|
||||
velocity(ent, vec, 1, false, 0, 0, vec.length(), false);
|
||||
}
|
||||
|
||||
public static NautHashMap<Player, Vector> getVelocityData()
|
||||
public static void registerVelocityFix(VelocityReceiver velocityFix)
|
||||
{
|
||||
return _velocityFix;
|
||||
_velocityFix = velocityFix;
|
||||
}
|
||||
|
||||
public static void velocity(Entity ent, double str, double yAdd, double yMax, boolean groundBoost)
|
||||
@ -56,7 +56,7 @@ public class UtilAction
|
||||
//Store It!
|
||||
if (ent instanceof Player)
|
||||
{
|
||||
_velocityFix.put(((Player)ent), vec);
|
||||
_velocityFix.setPlayerVelocity(((Player)ent), vec);
|
||||
}
|
||||
|
||||
ent.setVelocity(vec);
|
||||
@ -70,11 +70,11 @@ public class UtilAction
|
||||
//Store It!
|
||||
if (ent instanceof Player)
|
||||
{
|
||||
_velocityFix.put(((Player)ent), vec);
|
||||
_velocityFix.setPlayerVelocity(((Player)ent), vec);
|
||||
}
|
||||
|
||||
ent.setVelocity(vec);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,9 @@
|
||||
package mineplex.core.common.util;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
public interface VelocityReceiver
|
||||
{
|
||||
public void setPlayerVelocity(Player player, Vector velocity);
|
||||
}
|
@ -3,7 +3,9 @@ package mineplex.core.velocity;
|
||||
import java.util.Iterator;
|
||||
|
||||
import mineplex.core.MiniPlugin;
|
||||
import mineplex.core.common.util.NautHashMap;
|
||||
import mineplex.core.common.util.UtilAction;
|
||||
import mineplex.core.common.util.VelocityReceiver;
|
||||
import mineplex.core.updater.UpdateType;
|
||||
import mineplex.core.updater.event.UpdateEvent;
|
||||
|
||||
@ -13,8 +15,9 @@ import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.event.player.PlayerVelocityEvent;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
public class VelocityFix extends MiniPlugin
|
||||
public class VelocityFix extends MiniPlugin implements VelocityReceiver
|
||||
{
|
||||
/*
|
||||
* The purpose of this class is to fix a bug inherent in Minecraft,
|
||||
@ -28,22 +31,32 @@ public class VelocityFix extends MiniPlugin
|
||||
*
|
||||
*/
|
||||
|
||||
private NautHashMap<Player, Vector> _velocityData = new NautHashMap<Player,Vector>();
|
||||
|
||||
public VelocityFix(JavaPlugin plugin)
|
||||
{
|
||||
super("Velocity Fix", plugin);
|
||||
|
||||
UtilAction.registerVelocityFix(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerVelocity(Player player, Vector velocity)
|
||||
{
|
||||
_velocityData.put(player, velocity);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void fixVelocity(PlayerVelocityEvent event)
|
||||
{
|
||||
if (UtilAction.getVelocityData().containsKey(event.getPlayer()))
|
||||
event.getPlayer().setVelocity(UtilAction.getVelocityData().remove(event.getPlayer()));
|
||||
if (_velocityData.containsKey(event.getPlayer()))
|
||||
event.getPlayer().setVelocity(_velocityData.remove(event.getPlayer()));
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void cleanVelocity(PlayerQuitEvent event)
|
||||
{
|
||||
UtilAction.getVelocityData().remove(event.getPlayer());
|
||||
_velocityData.remove(event.getPlayer());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@ -52,7 +65,7 @@ public class VelocityFix extends MiniPlugin
|
||||
if (event.getType() != UpdateType.SLOW)
|
||||
return;
|
||||
|
||||
Iterator<Player> keyIter = UtilAction.getVelocityData().keySet().iterator();
|
||||
Iterator<Player> keyIter = _velocityData.keySet().iterator();
|
||||
|
||||
while (keyIter.hasNext())
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user