[Development] Flying by sending bed leaving packets check restored!

This commit is contained in:
NeatMonster 2012-08-08 01:55:22 +02:00
parent 113d627329
commit e783dfbe7c
3 changed files with 70 additions and 0 deletions

View File

@ -82,6 +82,7 @@ public class MovingData {
public double[] survivalFlyLastDistances = new double[] {0D, 0D}; public double[] survivalFlyLastDistances = new double[] {0D, 0D};
public int survivalFlyOnIce; public int survivalFlyOnIce;
public long survivalFlyOnLadderSince; public long survivalFlyOnLadderSince;
public boolean survivalFlyWasInBed;
// Locations shared between all checks. // Locations shared between all checks.
public Location from; public Location from;

View File

@ -13,6 +13,8 @@ import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.block.Action; import org.bukkit.event.block.Action;
import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.player.PlayerBedEnterEvent;
import org.bukkit.event.player.PlayerBedLeaveEvent;
import org.bukkit.event.player.PlayerChangedWorldEvent; import org.bukkit.event.player.PlayerChangedWorldEvent;
import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerJoinEvent;
@ -127,6 +129,49 @@ public class MovingListener implements Listener {
} }
} }
/**
* We listen to this event to prevent player from flying by sending bed leaving packets.
*
* @param event
* the event
*/
@EventHandler(
priority = EventPriority.MONITOR)
public void onPlayerBedEnter(final PlayerBedEnterEvent event) {
/*
* ____ _ ____ _ _____ _
* | _ \| | __ _ _ _ ___ _ __ | __ ) ___ __| | | ____|_ __ | |_ ___ _ __
* | |_) | |/ _` | | | |/ _ \ '__| | _ \ / _ \/ _` | | _| | '_ \| __/ _ \ '__|
* | __/| | (_| | |_| | __/ | | |_) | __/ (_| | | |___| | | | || __/ |
* |_| |_|\__,_|\__, |\___|_| |____/ \___|\__,_| |_____|_| |_|\__\___|_|
* |___/
*/
MovingData.getData(event.getPlayer()).survivalFlyWasInBed = true;
}
/**
* We listen to this event to prevent player from flying by sending bed leaving packets.
*
* @param event
* the event
*/
@EventHandler(
priority = EventPriority.MONITOR)
public void onPlayerBedLeave(final PlayerBedLeaveEvent event) {
/*
* ____ _ ____ _ _
* | _ \| | __ _ _ _ ___ _ __ | __ ) ___ __| | | | ___ __ ___ _____
* | |_) | |/ _` | | | |/ _ \ '__| | _ \ / _ \/ _` | | | / _ \/ _` \ \ / / _ \
* | __/| | (_| | |_| | __/ | | |_) | __/ (_| | | |__| __/ (_| |\ V / __/
* |_| |_|\__,_|\__, |\___|_| |____/ \___|\__,_| |_____\___|\__,_| \_/ \___|
* |___/
*/
final Player player = event.getPlayer();
if (survivalFly.isEnabled(player) && survivalFly.check(player))
// To cancel the event, we simply teleport the player to his last safe location.
player.teleport(MovingData.getData(player).lastSafeLocations[1]);
}
/** /**
* Just for security, if a player switches between worlds, reset the fly and more packets checks data, because it is * Just for security, if a player switches between worlds, reset the fly and more packets checks data, because it is
* definitely invalid now. * definitely invalid now.

View File

@ -105,6 +105,30 @@ public class SurvivalFly extends Check {
super(CheckType.MOVING_SURVIVALFLY); super(CheckType.MOVING_SURVIVALFLY);
} }
/**
* Checks a player.
*
* @param player
* the player
* @return true, if successful
*/
public boolean check(final Player player) {
final MovingData data = MovingData.getData(player);
// Check if the player has entered the bed he is trying to leave.
if (!data.survivalFlyWasInBed) {
// He hasn't, increment his violation level.
data.survivalFlyVL += 100D;
// And return if we need to do something or not.
return executeActions(player);
} else
// He has, everything is alright.
data.survivalFlyWasInBed = false;
return false;
}
/** /**
* Checks a player. * Checks a player.
* *