Skip to content

Commit

Permalink
Towards configurable set back behavior.
Browse files Browse the repository at this point in the history
* 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.)
  • Loading branch information
asofold committed Apr 7, 2017
1 parent b9aab85 commit 4e2ab01
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 15 deletions.
Expand Up @@ -532,6 +532,7 @@ else if (data.hasTeleported()) {
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.
Expand All @@ -551,7 +552,7 @@ else if (TickTask.isPlayerGoingToBeSetBack(player.getUniqueId())) {
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());
}
Expand Down Expand Up @@ -1505,20 +1506,33 @@ else if (!from.getWorld().getName().equals(toWorldName)) {
}
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();
}
}

Expand Down
Expand Up @@ -8,6 +8,7 @@
*/
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)


Expand All @@ -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")) {
Expand Down

0 comments on commit 4e2ab01

Please sign in to comment.