Move: Only get data and config once and pass as arguments.

This commit is contained in:
asofold 2012-09-21 23:56:46 +02:00
parent d35617a862
commit dc18dded88
5 changed files with 18 additions and 16 deletions

View File

@ -56,9 +56,9 @@ public class CreativeFly extends Check {
* the to
* @return the location
*/
public Location check(final Player player, final PlayerLocation from, final PlayerLocation to) {
final MovingConfig cc = MovingConfig.getConfig(player);
final MovingData data = MovingData.getData(player);
public Location check(final Player player, final MovingData data, final MovingConfig cc) {
final PlayerLocation from = data.from;
final PlayerLocation to = data.to;
// If we have no setback, define one now.
if (data.setBack == null)

View File

@ -60,11 +60,12 @@ public class MorePackets extends Check {
* the to
* @return the location
*/
public Location check(final Player player, final PlayerLocation from, final PlayerLocation to) {
public Location check(final Player player, final MovingData data, final MovingConfig cc) {
final PlayerLocation from = data.from;
final PlayerLocation to = data.to;
// Take time once, first:
final long time = System.currentTimeMillis();
final MovingData data = MovingData.getData(player);
Location newTo = null;

View File

@ -324,6 +324,7 @@ public class MovingListener implements Listener {
return;
final MovingData data = MovingData.getData(player);
final MovingConfig cc = MovingConfig.getConfig(player);
// Just try to estimate velocities over time. Not very precise, but works good enough most of the time. Do
// general data modifications one for each event.
@ -351,21 +352,21 @@ public class MovingListener implements Listener {
if ((player.getGameMode() == GameMode.CREATIVE || player.getAllowFlight()) && creativeFly.isEnabled(player))
// If the player is handled by the creative fly check, execute it.
newTo = creativeFly.check(player, data.from, data.to);
newTo = creativeFly.check(player, data, cc);
else if (survivalFly.isEnabled(player)) {
// If he is handled by the survival fly check, execute it.
newTo = survivalFly.check(player, data.from, data.to);
newTo = survivalFly.check(player, data, cc);
// If don't have a new location and if he is handled by the no fall check, execute it.
if (newTo == null && noFall.isEnabled(player))
// NOTE: noFall might set yOnGround for the positions.
noFall.check(player, data.from, data.to);
noFall.check(player, data, cc);
} else
// He isn't handled by any fly check, clear his data.
data.clearFlyData();
if (newTo == null && morePackets.isEnabled(player))
// If he hasn't been stopped by any other check and is handled by the more packets check, execute it.
newTo = morePackets.check(player, data.from, data.to);
newTo = morePackets.check(player, data, cc);
else
// Otherwise we need to clear his data.
data.clearMorePacketsData();

View File

@ -46,10 +46,10 @@ public class NoFall extends Check {
* @param to
* the to
*/
public void check(final Player player, final PlayerLocation from, final PlayerLocation to) {
final MovingConfig cc = MovingConfig.getConfig(player);
final MovingData data = MovingData.getData(player);
public void check(final Player player, final MovingData data, final MovingConfig cc) {
final PlayerLocation from = data.from;
final PlayerLocation to = data.to;
if (from.getY() > to.getY()){
// Reset the on ground properties only if necessary.
if (from.getyOnGround() != cc.noFallyOnGround && (from.getY() - (double) Location.locToBlock(from.getY()) < cc.noFallyOnGround))

View File

@ -77,9 +77,9 @@ public class SurvivalFly extends Check {
* the to
* @return the location
*/
public Location check(final Player player, final PlayerLocation from, final PlayerLocation to) {
final MovingConfig cc = MovingConfig.getConfig(player);
final MovingData data = MovingData.getData(player);
public Location check(final Player player, final MovingData data, final MovingConfig cc) {
final PlayerLocation from = data.from;
final PlayerLocation to = data.to;
// A player is considered sprinting if the flag is set and if he has enough food level.
final boolean sprinting = player.isSprinting() && player.getFoodLevel() > 5;