Skip to content

Commit

Permalink
Rather use prepareSetBack than setTeleported before set-back.
Browse files Browse the repository at this point in the history
  • Loading branch information
asofold committed Feb 24, 2014
1 parent 8eebda8 commit 1cb9a18
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 27 deletions.
Expand Up @@ -60,8 +60,12 @@ public Location check(final Player player, final PlayerLocation from, final Play

if (!data.hasMorePacketsSetBack()){
// TODO: Check if other set-back is appropriate or if to set on other events.
if (data.hasSetBack()) data.setMorePacketsSetBack(data.getSetBack(to));
else data.setMorePacketsSetBack(from);
if (data.hasSetBack()) {
data.setMorePacketsSetBack(data.getSetBack(to));
}
else {
data.setMorePacketsSetBack(from);
}
}

// Take a packet from the buffer.
Expand All @@ -76,10 +80,8 @@ public Location check(final Player player, final PlayerLocation from, final Play

// Execute whatever actions are associated with this check and the violation level and find out if we should
// cancel the event.
if (executeActions(player, data.morePacketsVL, -data.morePacketsBuffer,
MovingConfig.getConfig(player).morePacketsActions)){
if (executeActions(player, data.morePacketsVL, -data.morePacketsBuffer, MovingConfig.getConfig(player).morePacketsActions)){
newTo = data.getMorePacketsSetBack();
data.setTeleported(newTo);
}

}
Expand All @@ -93,23 +95,28 @@ public Location check(final Player player, final PlayerLocation from, final Play

// If there was a long pause (maybe server lag?), allow buffer to grow up to 100.
if (seconds > 2) {
if (data.morePacketsBuffer > 100)
data.morePacketsBuffer = 100;
} else if (data.morePacketsBuffer > 50)
if (data.morePacketsBuffer > 100) {
data.morePacketsBuffer = 100;
}
} else if (data.morePacketsBuffer > 50) {
// Only allow growth up to 50.
data.morePacketsBuffer = 50;

}
// Set the new "last" time.
data.morePacketsLastTime = time;

// Set the new "setback" location.
if (newTo == null) data.setMorePacketsSetBack(from);
} else if (data.morePacketsLastTime > time)
if (newTo == null) {
data.setMorePacketsSetBack(from);
}
} else if (data.morePacketsLastTime > time) {
// Security check, maybe system time changed.
data.morePacketsLastTime = time;
data.morePacketsLastTime = time;
}

if (newTo == null)
return null;
if (newTo == null) {
return null;
}

// Compose a new location based on coordinates of "newTo" and viewing direction of "event.getTo()" to allow the
// player to look somewhere else despite getting pulled back by NoCheatPlus.
Expand Down
Expand Up @@ -282,18 +282,15 @@ public void onPlayerBedLeave(final PlayerBedLeaveEvent event) {
target = LocUtil.clone(loc);
}
useLoc.setWorld(null);
if (target != null) {
// Actually this should not possibly be null, this is a block for "future" purpose, feel free to criticize it.
if (sfCheck && cc.sfFallDamage && noFall.isEnabled(player)) {
// Check if to deal damage.
double y = loc.getY();
if (data.hasSetBack()) y = Math.min(y, data.getSetBackY());
noFall.checkDamage(player, data, y);
}
// Teleport.
data.setTeleported(target); // Should be enough. | new Location(target.getWorld(), target.getX(), target.getY(), target.getZ(), target.getYaw(), target.getPitch());
player.teleport(target, TeleportCause.PLUGIN);// TODO: schedule / other measures ?
if (sfCheck && cc.sfFallDamage && noFall.isEnabled(player)) {
// Check if to deal damage.
double y = loc.getY();
if (data.hasSetBack()) y = Math.min(y, data.getSetBackY());
noFall.checkDamage(player, data, y);
}
// Teleport.
data.prepareSetBack(target); // Should be enough. | new Location(target.getWorld(), target.getX(), target.getY(), target.getZ(), target.getYaw(), target.getPitch());
player.teleport(target, TeleportCause.PLUGIN);// TODO: schedule / other measures ?
}
else{
// Reset bed ...
Expand Down Expand Up @@ -1389,7 +1386,7 @@ public void onTick(final int tick, final long timeLast) {
final MovingData data = MovingData.getData(player);
final Location newTo = enforceLocation(player, player.getLocation(useLoc), data);
if (newTo != null) {
data.setTeleported(newTo);
data.prepareSetBack(newTo);
player.teleport(newTo, TeleportCause.PLUGIN);
}
}
Expand Down
Expand Up @@ -30,7 +30,7 @@ public void run() {
final MovingData data = MovingData.getData(player);
data.morePacketsVehicleTaskId = -1;
try{
data.setTeleported(location);
data.prepareSetBack(location);
TeleportUtil.teleport(vehicle, player, location, debug);
}
catch(Throwable t){
Expand Down
Expand Up @@ -23,6 +23,7 @@ public static void teleport(final Entity vehicle, final Player player, final Loc
final boolean vehicleTeleported;
final boolean playerIsPassenger = player.equals(passenger);
if (playerIsPassenger && !vehicle.isDead()){ // && vehicle.equals(player.getVehicle).
// TODO: Does VehicleExit fire here !? Consequences?
vehicle.eject();
vehicleTeleported = vehicle.teleport(location, TeleportCause.PLUGIN);

Expand All @@ -34,6 +35,7 @@ else if (passenger == null && !vehicle.isDead()){
final boolean playerTeleported = player.teleport(location);
if (playerIsPassenger && playerTeleported && vehicleTeleported && player.getLocation().distance(vehicle.getLocation(useLoc)) < 1.0){
// Somewhat check against tp showing something wrong (< 1.0).
// TODO: Does VehicleEnter fire here !? Consequences?
vehicle.setPassenger(player);
}
if (debug){
Expand Down

0 comments on commit 1cb9a18

Please sign in to comment.