refactored a little so theres no data stored in the util

This commit is contained in:
Mini-Chiss 2015-08-02 12:07:00 +02:00
parent afc41c8831
commit 638406254b
3 changed files with 33 additions and 11 deletions

View File

@ -6,16 +6,16 @@ import org.bukkit.util.Vector;
public class UtilAction 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) public static void velocity(Entity ent, Vector vec)
{ {
velocity(ent, vec, 1, false, 0, 0, vec.length(), false); 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) public static void velocity(Entity ent, double str, double yAdd, double yMax, boolean groundBoost)
@ -56,7 +56,7 @@ public class UtilAction
//Store It! //Store It!
if (ent instanceof Player) if (ent instanceof Player)
{ {
_velocityFix.put(((Player)ent), vec); _velocityFix.setPlayerVelocity(((Player)ent), vec);
} }
ent.setVelocity(vec); ent.setVelocity(vec);
@ -70,11 +70,11 @@ public class UtilAction
//Store It! //Store It!
if (ent instanceof Player) if (ent instanceof Player)
{ {
_velocityFix.put(((Player)ent), vec); _velocityFix.setPlayerVelocity(((Player)ent), vec);
} }
ent.setVelocity(vec); ent.setVelocity(vec);
} }
} }

View File

@ -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);
}

View File

@ -3,7 +3,9 @@ package mineplex.core.velocity;
import java.util.Iterator; import java.util.Iterator;
import mineplex.core.MiniPlugin; import mineplex.core.MiniPlugin;
import mineplex.core.common.util.NautHashMap;
import mineplex.core.common.util.UtilAction; import mineplex.core.common.util.UtilAction;
import mineplex.core.common.util.VelocityReceiver;
import mineplex.core.updater.UpdateType; import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent; 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.PlayerQuitEvent;
import org.bukkit.event.player.PlayerVelocityEvent; import org.bukkit.event.player.PlayerVelocityEvent;
import org.bukkit.plugin.java.JavaPlugin; 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, * 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) public VelocityFix(JavaPlugin plugin)
{ {
super("Velocity Fix", plugin); super("Velocity Fix", plugin);
UtilAction.registerVelocityFix(this);
}
@Override
public void setPlayerVelocity(Player player, Vector velocity)
{
_velocityData.put(player, velocity);
} }
@EventHandler(priority = EventPriority.LOWEST) @EventHandler(priority = EventPriority.LOWEST)
public void fixVelocity(PlayerVelocityEvent event) public void fixVelocity(PlayerVelocityEvent event)
{ {
if (UtilAction.getVelocityData().containsKey(event.getPlayer())) if (_velocityData.containsKey(event.getPlayer()))
event.getPlayer().setVelocity(UtilAction.getVelocityData().remove(event.getPlayer())); event.getPlayer().setVelocity(_velocityData.remove(event.getPlayer()));
} }
@EventHandler @EventHandler
public void cleanVelocity(PlayerQuitEvent event) public void cleanVelocity(PlayerQuitEvent event)
{ {
UtilAction.getVelocityData().remove(event.getPlayer()); _velocityData.remove(event.getPlayer());
} }
@EventHandler @EventHandler
@ -52,7 +65,7 @@ public class VelocityFix extends MiniPlugin
if (event.getType() != UpdateType.SLOW) if (event.getType() != UpdateType.SLOW)
return; return;
Iterator<Player> keyIter = UtilAction.getVelocityData().keySet().iterator(); Iterator<Player> keyIter = _velocityData.keySet().iterator();
while (keyIter.hasNext()) while (keyIter.hasNext())
{ {