diff --git a/src/fr/neatmonster/nocheatplus/checks/moving/MovingData.java b/src/fr/neatmonster/nocheatplus/checks/moving/MovingData.java index 793ed067..92132923 100644 --- a/src/fr/neatmonster/nocheatplus/checks/moving/MovingData.java +++ b/src/fr/neatmonster/nocheatplus/checks/moving/MovingData.java @@ -82,6 +82,7 @@ public class MovingData { public double[] survivalFlyLastDistances = new double[] {0D, 0D}; public int survivalFlyOnIce; public long survivalFlyOnLadderSince; + public boolean survivalFlyWasInBed; // Locations shared between all checks. public Location from; diff --git a/src/fr/neatmonster/nocheatplus/checks/moving/MovingListener.java b/src/fr/neatmonster/nocheatplus/checks/moving/MovingListener.java index 32aa43d0..a2bf592e 100644 --- a/src/fr/neatmonster/nocheatplus/checks/moving/MovingListener.java +++ b/src/fr/neatmonster/nocheatplus/checks/moving/MovingListener.java @@ -13,6 +13,8 @@ import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.block.Action; 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.PlayerInteractEvent; 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 * definitely invalid now. diff --git a/src/fr/neatmonster/nocheatplus/checks/moving/SurvivalFly.java b/src/fr/neatmonster/nocheatplus/checks/moving/SurvivalFly.java index a615fc19..835d2261 100644 --- a/src/fr/neatmonster/nocheatplus/checks/moving/SurvivalFly.java +++ b/src/fr/neatmonster/nocheatplus/checks/moving/SurvivalFly.java @@ -105,6 +105,30 @@ public class SurvivalFly extends Check { 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. *