Move set-back handling into dataOnJoin for respawn + join events.

This commit is contained in:
asofold 2014-10-28 22:33:43 +01:00
parent 87bc5edca0
commit 5ec3cd5963
2 changed files with 22 additions and 28 deletions

View File

@ -502,6 +502,9 @@ public class MovingData extends ACheckData {
teleported = null; teleported = null;
} }
/**
* Set set-back location to null.
*/
public final void resetSetBack() { public final void resetSetBack() {
setBack = null; setBack = null;
} }

View File

@ -1256,41 +1256,19 @@ public class MovingListener extends CheckListener implements TickListener, IRemo
public void onPlayerRespawn(final PlayerRespawnEvent event) { public void onPlayerRespawn(final PlayerRespawnEvent event) {
final Player player = event.getPlayer(); final Player player = event.getPlayer();
final MovingData data = MovingData.getData(player); final MovingData data = MovingData.getData(player);
final MovingConfig cc = MovingConfig.getConfig(player);
final Location loc = event.getRespawnLocation();
data.clearFlyData(); data.clearFlyData();
data.setSetBack(loc); data.resetSetBack(); // To force dataOnJoin to set it to loc.
// Handle respawn like join. // Handle respawn like join.
dataOnJoin(player, loc, data, cc); dataOnJoin(player, event.getRespawnLocation(), data, MovingConfig.getConfig(player));
} }
@Override @Override
public void playerJoins(final Player player) { public void playerJoins(final Player player) {
final MovingData data = MovingData.getData(player); dataOnJoin(player, player.getLocation(useLoc), MovingData.getData(player), MovingConfig.getConfig(player));
final MovingConfig cc = MovingConfig.getConfig(player);
final Location loc = player.getLocation(useLoc);
// Correct set-back on join.
if (data.hasSetBackWorldChanged(loc)) {
data.clearFlyData();
data.setSetBack(loc);
}
else if (!data.hasSetBack()) {
// TODO: Might consider something else like with respawn. Check if it is passable ?
data.setSetBack(loc);
}
dataOnJoin(player, loc, data, cc);
// Cleanup. // Cleanup.
useLoc.setWorld(null); useLoc.setWorld(null);
} }
/** /**
* Alter data for players joining (join, respawn).<br> * Alter data for players joining (join, respawn).<br>
* Do before, if necessary:<br> * Do before, if necessary:<br>
@ -1302,6 +1280,7 @@ public class MovingListener extends CheckListener implements TickListener, IRemo
* @param cc * @param cc
*/ */
private void dataOnJoin(Player player, Location loc, MovingData data, MovingConfig cc) { private void dataOnJoin(Player player, Location loc, MovingData data, MovingConfig cc) {
final int tick = TickTask.getTick(); final int tick = TickTask.getTick();
// Check loaded chunks. // Check loaded chunks.
if (cc.loadChunksOnJoin) { if (cc.loadChunksOnJoin) {
@ -1312,12 +1291,24 @@ public class MovingListener extends CheckListener implements TickListener, IRemo
} }
} }
// Correct set-back on join.
if (!data.hasSetBack() || data.hasSetBackWorldChanged(loc)) {
data.clearFlyData();
data.setSetBack(loc);
data.resetPositions(loc);
} else {
// TODO: Check consistency/distance.
//final Location setBack = data.getSetBack(loc);
//final double d = loc.distanceSquared(setBack);
// TODO: If to reset positions: relate to previous ones and set-back.
data.resetPositions(loc); // TODO: See above.
}
// Always reset position to this one. // Always reset position to this one.
// TODO: more fine grained reset? // TODO: more fine grained reset?
data.resetPositions(loc);
data.clearMorePacketsData(); data.clearMorePacketsData();
data.removeAllVelocity(); data.removeAllVelocity();
data.resetTrace(loc, tick, cc.traceSize, cc.traceMergeDist); data.resetTrace(loc, tick, cc.traceSize, cc.traceMergeDist); // Might reset to loc instead of set-back ?
// More resetting. // More resetting.
data.vDistAcc.clear(); data.vDistAcc.clear();