public static void MovePortal(object sender, PlayerMovingEventArgs e) { try { if (e.Player.LastUsedPortal != null && (DateTime.UtcNow - e.Player.LastUsedPortal).TotalSeconds < 4) { return; } var newPos = new Vector3I(e.NewPosition.X / 32, e.NewPosition.Y / 32, (e.NewPosition.Z / 32)); if (e.Player.World != null) { foreach (Player p in e.Player.World.Players) { foreach (Vector3I block in p.bluePortal) { if (newPos == block) { if (p.World != null && p.World.Map.GetBlock(block) == Block.Water) { if (p.orangePortal.Count > 0) { e.Player.TeleportTo(new Position { X = ( short )(((p.orangePortal[0].X) + 0.5) * 32), Y = ( short )(((p.orangePortal[0].Y) + 0.5) * 32), Z = ( short )(((p.orangePortal[0].Z) + 1.59375) * 32), R = ( byte )(p.blueOut - 128), L = e.Player.Position.L }); } e.Player.LastUsedPortal = DateTime.UtcNow; } } } foreach (Vector3I block in p.orangePortal) { if (newPos == block) { if (p.World != null && p.World.Map.GetBlock(block) == Block.Lava) { if (p.bluePortal.Count > 0) { e.Player.TeleportTo(new Position { X = ( short )(((p.bluePortal[0].X + 0.5)) * 32), Y = ( short )(((p.bluePortal[0].Y + 0.5)) * 32), Z = ( short )(((p.bluePortal[0].Z) + 1.59375) * 32), //fixed point 1.59375 lol. R = ( byte )(p.orangeOut - 128), L = e.Player.Position.L }); } e.Player.LastUsedPortal = DateTime.UtcNow; } } } } } } catch (Exception ex) { Logger.Log(LogType.SeriousError, "MovePortal: " + ex); } }
static bool RaisePlayerMovingEvent([NotNull] Player player, Position newPos) { if (player == null) { throw new ArgumentNullException("player"); } var e = new PlayerMovingEventArgs(player, newPos); MovingEvent.Raise(e); return(!e.Cancel); }
internal static bool RaisePlayerMovingEvent(Player player, Position newPos) { var h = PlayerMoving; if (h == null) { return(false); } var e = new PlayerMovingEventArgs(player, newPos); h(null, e); return(e.Cancel); }
private static void PlayerMoving(object sender, PlayerMovingEventArgs e) { if (_world != null && e.Player.World == _world) { if (_world.gameMode == GameMode.MineField && !Failed.Contains(e.Player)) { if (e.NewPosition != null) { Vector3I oldPos = new Vector3I(e.OldPosition.X / 32, e.OldPosition.Y / 32, e.OldPosition.Z / 32); Vector3I newPos = new Vector3I(e.NewPosition.X / 32, e.NewPosition.Y / 32, e.NewPosition.Z / 32); if (oldPos.X != newPos.X || oldPos.Y != newPos.Y || oldPos.Z != newPos.Z) { if (!_map.InBounds(newPos)) { e.Player.TeleportTo(_map.Spawn); newPos = ( Vector3I )_map.Spawn; } // Check if the player jumped, flew, whatevers if (newPos.Z > _ground + 2) { e.Player.TeleportTo(e.OldPosition); newPos = oldPos; } foreach (Vector3I pos in Mines.Values) { if (newPos == new Vector3I(pos.X, pos.Y, pos.Z + 2) || newPos == new Vector3I(pos.X, pos.Y, pos.Z + 1) || newPos == new Vector3I(pos.X, pos.Y, pos.Z)) { _world.Map.QueueUpdate(new BlockUpdate(null, pos, Block.TNT)); _world.AddPhysicsTask(new TNTTask(_world, pos, null, true, false), 0); Vector3I removed; Mines.TryRemove(pos.ToString(), out removed); } } if (_map.GetBlock(newPos.X, newPos.Y, newPos.Z - 2) == Block.Green && !_stopped) { _stopped = true; Stop(e.Player, true); } } } } } }
static bool RaisePlayerMovingEvent([NotNull] Player player, Position newPos) { if (player == null) { throw new ArgumentNullException("player"); } var h = Moving; if (h == null) { return(false); } var e = new PlayerMovingEventArgs(player, newPos); h(null, e); return(e.Cancel); }