Towards configurable set back behavior.

* Don't unset teleported, if event.getTo is the same position as the
teleported (set back) location.
* Prepare (with) comments.

(Main driver is to be able to adjust quickly without shifting code
to-fro legacy etc., while dealing with much differing side conditions
for server mod + version, client versions with multi protocol support,
and other like bungee or not bungee.)
This commit is contained in:
asofold 2017-04-07 14:42:56 +02:00
parent b9aab8513a
commit 4e2ab0164e
2 changed files with 30 additions and 15 deletions

View File

@ -532,6 +532,7 @@ public class MovingListener extends CheckListener implements TickListener, IRemo
private boolean handleTeleportedOnMove(final Player player, final PlayerMoveEvent event,
final MovingData data, final MovingConfig cc) {
// This could also happen with a packet based set back such as with cancelling move events.
// TODO: Alter the move from location and let it get through?
if (data.isTeleportedPosition(event.getFrom())) {
// Treat as ACK (!).
// Adjust.
@ -551,7 +552,7 @@ public class MovingListener extends CheckListener implements TickListener, IRemo
return true;
}
else {
// Left-over.
// Left-over (Demand: schedule or teleport before moving events arrive).
if (data.debug) {
debug(player, "Invalidate left-over teleported (set back) location: " + data.getTeleported());
}
@ -1505,23 +1506,36 @@ public class MovingListener extends CheckListener implements TickListener, IRemo
}
mData.updateTrace(player, to, tick, mcAccess.getHandle());
if (mData.hasTeleported()) {
if (TickTask.isPlayerGoingToBeSetBack(player.getUniqueId())) {
// TODO: If legacy behavior with setTo is supported, adjust to it here as well.
// Skip.
if (mData.debug) {
debug(player, "Event not cancelled, despite a set back has been scheduled. Ignore set back.");
}
}
else {
if (mData.debug) {
debug(player, "Inconsistent state (move MONITOR): teleported has been set, but no set back is scheduled. Ignore set back.");
}
}
mData.resetTeleported(); // (TickTask will notice it's not set.)
onPlayerMoveMonitorNotCancelledHasTeleported(player, to, mData);
}
}
}
private void onPlayerMoveMonitorNotCancelledHasTeleported(final Player player, final Location to,
final MovingData mData) {
if (mData.isTeleportedPosition(to)) {
// Skip resetting, especially if legacy setTo is enabled.
// TODO: Might skip this condition, if legacy setTo is not enabled.
if (mData.debug) {
debug(player, "Event not cancelled, with teleported (set back) set, assume legacy behavior.");
}
}
else if (TickTask.isPlayerGoingToBeSetBack(player.getUniqueId())) {
// Skip, because the scheduled teleport has been overridden.
// TODO: Only do this, if cancel is set, because it is not an un-cancel otherwise.
if (mData.debug) {
debug(player, "Event not cancelled, despite a set back has been scheduled. Ignore set back.");
}
mData.resetTeleported(); // (TickTask will notice it's not set.)
}
else {
if (mData.debug) {
debug(player, "Inconsistent state (move MONITOR): teleported has been set, but no set back is scheduled. Ignore set back.");
}
mData.resetTeleported();
}
}
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
public void onPlayerPortalLowest(final PlayerPortalEvent event) {
final Player player = event.getPlayer();

View File

@ -8,6 +8,7 @@ package fr.neatmonster.nocheatplus.checks.moving.player;
*/
public class PlayerSetBackMethod {
// TODO: Distinguish (detected/assumed) capabilities from methods to use (e.g. getFrom can be used or not)?
// TODO: Might use more speaking method names (cancelPlayerMoveEvent)
@ -30,7 +31,7 @@ public class PlayerSetBackMethod {
public static final PlayerSetBackMethod MODERN = new PlayerSetBackMethod(CANCEL | UPDATE_FROM);
public static final PlayerSetBackMethod fromString(String input) {
// TODO: Perhpas complain for incomplete/wrong content, much later.
// TODO: Perhaps complain for incomplete/wrong content, much later.
input = input.toLowerCase().replaceAll("_", "");
int flags = 0;
if (input.contains("setto")) {