Fixed Respawning

This commit is contained in:
Evenprime 2011-07-05 16:29:19 +02:00
parent 9406961f05
commit 8729400be5
4 changed files with 26 additions and 9 deletions

View File

@ -3,7 +3,7 @@ name: NoCheat
author: Evenprime
main: cc.co.evenprime.bukkit.nocheat.NoCheat
version: 1.07b
version: 1.07c
softdepend: [ Permissions, CraftIRC ]

View File

@ -384,8 +384,13 @@ public class MovingCheck extends Check {
*/
private boolean shouldBeIgnored(final Player player, final MovingData data, final Location from, final Location to) {
if(data.firstEventAfterRespawn) {
data.firstEventAfterRespawn = false;
data.teleportTo = from.clone();
}
// Now it gets complicated: (a friendly reminder to myself why this actually works in CB 950+)
// data.teleportTo gets a location assigned if a teleport event is successfully executed.
// But there is a delay between the serverside execution of the teleport (instantly) and
// the execution on the client side (may take an arbitrary time). During that time, the
@ -411,7 +416,7 @@ public class MovingCheck extends Check {
}
// If the player moved between worlds between events, don't check (wouldn't make sense
// to check coordinates between different worlds...)
if(!from.getWorld().equals(data.lastLocation)) {
if(!from.getWorld().equals(data.lastSeenInWorld)) {
return true;
}
@ -468,11 +473,13 @@ public class MovingCheck extends Check {
}
if(!event.isCancelled()) {
data.jumpPhase = 0;
data.teleportTo = event.getTo().clone();
data.setBackPoint = event.getTo().clone();
//data.lastLocation = event.getTo().clone();
}
// reset anyway - if another plugin cancelled our teleport it's no use to try and be precise
data.jumpPhase = 0;
}
/**
@ -480,8 +487,10 @@ public class MovingCheck extends Check {
* @param event
*/
public void respawned(PlayerRespawnEvent event) {
//MovingData data = MovingData.get(event.getPlayer());
//data.setBackPoint = event.getRespawnLocation().clone();
MovingData data = MovingData.get(event.getPlayer());
data.firstEventAfterRespawn = true;
data.jumpPhase = 0;
data.setBackPoint = null;
}
/**
@ -750,5 +759,6 @@ public class MovingCheck extends Check {
pm.registerEvent(Event.Type.PLAYER_MOVE, movingPlayerMonitor, Priority.Monitor, plugin);
pm.registerEvent(Event.Type.ENTITY_DAMAGE, new MovingEntityListener(this), Priority.Monitor, plugin);
pm.registerEvent(Event.Type.PLAYER_TELEPORT, new MovingPlayerMonitor(this), Priority.Monitor, plugin);
pm.registerEvent(Event.Type.PLAYER_RESPAWN, new MovingPlayerMonitor(this), Priority.Monitor, plugin);
}
}

View File

@ -36,9 +36,10 @@ public class MovingData {
public Location teleportTo = null;
// Use to track the world the player is in
public World lastLocation = null;
public World lastSeenInWorld = null;
public Location teleportInitializedByMe = null;
public boolean firstEventAfterRespawn = false;
@ -84,7 +85,7 @@ public class MovingData {
if(data.moving == null) {
data.moving = new MovingData();
data.moving.lastLocation = p.getLocation().getWorld();
data.moving.lastSeenInWorld = p.getLocation().getWorld();
}
return data.moving;

View File

@ -3,6 +3,7 @@ package cc.co.evenprime.bukkit.nocheat.listeners;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerListener;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
import cc.co.evenprime.bukkit.nocheat.checks.MovingCheck;
@ -25,6 +26,11 @@ public class MovingPlayerMonitor extends PlayerListener {
public void onPlayerTeleport(PlayerTeleportEvent event) {
check.teleported(event);
}
@Override
public void onPlayerRespawn(PlayerRespawnEvent event) {
this.check.respawned(event);
}
@Override
public void onPlayerInteract(PlayerInteractEvent event) {
@ -35,7 +41,7 @@ public class MovingPlayerMonitor extends PlayerListener {
public void onPlayerMove(PlayerMoveEvent event) {
if(!event.isCancelled()) {
MovingData data = MovingData.get(event.getPlayer());
data.lastLocation = event.getPlayer().getLocation().getWorld();
data.lastSeenInWorld = event.getPlayer().getLocation().getWorld();
if( event.getPlayer().isInsideVehicle()) {
data.setBackPoint = event.getTo();
}