Skip to content

Commit

Permalink
Hint at something extensible for how to set back technically.
Browse files Browse the repository at this point in the history
Versions, mods, ...
  • Loading branch information
asofold committed Apr 7, 2017
1 parent ef1d811 commit b9aab85
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 6 deletions.
Expand Up @@ -1367,6 +1367,7 @@ private void prepareSetBack(final Player player, final PlayerMoveEvent event, fi
aux.resetPositionsAndMediumProperties(player, newTo, data, cc); // TODO: Might move into prepareSetBack, experimental here.

// Set new to-location.
// TODO: Perhaps need to distinguish by version+settings?
// event.setTo(newTo); // LEGACY: pre-2017-03-24
event.setCancelled(true);
// NOTE: A teleport is scheduled on MONITOR priority, if still relevant.
Expand Down Expand Up @@ -1432,15 +1433,13 @@ public void onPlayerMoveMonitor(final PlayerMoveEvent event) {
* @param mData
* @param data
*/
private void onCancelledMove(final Player player, final Location from, final int tick, final long now, final MovingData mData, final MovingConfig mCc, final CombinedData data) {
private void onCancelledMove(final Player player, final Location from, final int tick, final long now,
final MovingData mData, final MovingConfig mCc, final CombinedData data) {
// Detect our own set back, choice of reference location.
if (mData.hasSetBack()) {
final Location ref = mData.getTeleported();
/*
* Attempt to control the immediate set back location, allowing to
* do without the PlayerTeleportEvent, if successful.
*/
LocUtil.set(from, ref); // Hope the from location is used for teleport (fastest way).
// TODO: Initiate further action depending on version/capabilities (update getFrom()).
LocUtil.set(from, ref); // Attempt to do without a PlayerTeleportEvent as follow up.
// Schedule the teleport, because it might be faster than the next incoming packet.
final UUID playerId = player.getUniqueId();
if (!TickTask.isPlayerGoingToBeSetBack(playerId)) {
Expand Down Expand Up @@ -1507,6 +1506,7 @@ 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.");
Expand Down
@@ -0,0 +1,76 @@
package fr.neatmonster.nocheatplus.checks.moving.player;

/**
* Provide something to be able to tell how to set back players technically.
*
* @author asofold
*
*/
public class PlayerSetBackMethod {

// TODO: Might use more speaking method names (cancelPlayerMoveEvent)


// FLAGS (Type might change to long, if so much distinction is necessary).

/** PlayerMoveEvent.setTo is used (legacy). */
private static final int SET_TO = 0x01;
/** PlayerMoveEvent.setCancelled(true) is used. */
private static final int CANCEL = 0x02;
/** PlayerMoveEvent.getFrom() is updated with the set back location. */
private static final int UPDATE_FROM = 0x04;
/** An additional teleport is scheduled for safety. */
private static final int SCHEDULE = 0x08;


// DEFAULTS

public static final PlayerSetBackMethod LEGACY = new PlayerSetBackMethod(SET_TO);
public static final PlayerSetBackMethod CAUTIOUS = new PlayerSetBackMethod(CANCEL | UPDATE_FROM | SCHEDULE);
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.
input = input.toLowerCase().replaceAll("_", "");
int flags = 0;
if (input.contains("setto")) {
flags |= SET_TO;
}
if (input.contains("cancel")) {
flags |= CANCEL;
}
if (input.contains("updatefrom")) {
flags |= UPDATE_FROM;
}
if (input.contains("schedule")) {
flags |= SCHEDULE;
}
return new PlayerSetBackMethod(flags);
}


// INSTANCE

private final int flags;

public PlayerSetBackMethod(int flags) {
this.flags = flags;
}

public boolean shouldSetTo() {
return (flags & SET_TO) != 0;
}

public boolean shouldCancel() {
return (flags & CANCEL) != 0;
}

public boolean shouldUpdateFrom() {
return (flags & UPDATE_FROM) != 0;
}

public boolean shouldSchedule() {
return (flags & SCHEDULE) != 0;
}

}

0 comments on commit b9aab85

Please sign in to comment.