Esempio n. 1
0
        public void AddPlayer(Player player)
        {
            var identifier = player.GetIdentifier();

            if (PlayerDictionary.ContainsKey(identifier))
            {
                throw new PlayerAlreadyExistsException(identifier.GetPlayerName());
            }
            PlayerDictionary[identifier] = player;
            EventManager.TriggerEvent <PlayerAdded>(this, player);
        }
Esempio n. 2
0
 public void RemovePlayer(Identifier <Player> playerIdentifier)
 {
     if (!PlayerDictionary.ContainsKey(playerIdentifier))
     {
         throw new PlayerNotExistsException(playerIdentifier.GetPlayerName());
     }
     if (!PlayerDictionary.TryRemove(playerIdentifier, out _))
     {
         throw new OperationFailedException("remove player");                                                       //TODO i18n
     }
     EventManager.TriggerEvent <PlayerRemoved>(this, playerIdentifier);
 }
        public override void Execute(ICommandContext context)
        {
            var player = src.ToPlayer();

            if (args.Length == 0 || args.Length > 1)
            {
                return(CommandResult.ShowUsage());
            }

            if (!WarpModule.Instance.WarpManager.Contains(args[0].ToString()))
            {
                return(CommandResult.LangError("WARP_NOT_EXIST", args[0]));
            }

            if (player.Stance == EPlayerStance.DRIVING ||
                player.Stance == EPlayerStance.SITTING)
            {
                return(CommandResult.LangError("CANNOT_TELEPORT_DRIVING"));
            }

            if (Delay.ContainsKey(player.CSteamId.m_SteamID))
            {
                return(CommandResult.LangError("ALREADY_WAITING"));
            }

            var targetWarp = WarpModule.Instance.WarpManager.GetByName(args[0].ToString());
            var cooldown   = UEssentials.Config.Warp.TeleportDelay;

            if (!targetWarp.CanBeUsedBy(src))
            {
                return(CommandResult.LangError("WARP_NO_PERMISSION", args[0]));
            }

            if (cooldown > 0 && !player.HasPermission("essentials.bypass.warpcooldown"))
            {
                context.User.SendLocalizedMessage(Translations, "WARP_COOLDOWN", cooldown);
            }

            var task = Task.Create()
                       .Id($"Warp teleport '{player.DisplayName}'")
                       .Delay(player.HasPermission("essentials.bypass.warpcooldown") ? 0 : cooldown * 1000)
                       .Action(t =>
            {
                Delay.Remove(player.CSteamId.m_SteamID);
                player.Teleport(targetWarp.Location, targetWarp.Rotation);
                context.User.SendLocalizedMessage(Translations, "WARP_TELEPORTED", args[0]);
            })
                       .Submit();

            Delay.Add(player.CSteamId.m_SteamID, task);

            return(CommandResult.Success());
        }
Esempio n. 4
0
        public override CommandResult OnExecute(ICommandSource src, ICommandArgs args)
        {
            var player = src.ToPlayer();

            if (args.Length == 0 || args.Length > 1)
            {
                return(CommandResult.ShowUsage());
            }

            if (!WarpModule.Instance.WarpManager.Contains(args[0].ToString()))
            {
                return(CommandResult.Lang("WARP_NOT_EXIST", args[0]));
            }

            if (!player.HasPermission($"essentials.warp.{args[0]}"))
            {
                return(CommandResult.Lang("WARP_NO_PERMISSION", args[0]));
            }

            if (player.RocketPlayer.Stance == EPlayerStance.DRIVING ||
                player.RocketPlayer.Stance == EPlayerStance.SITTING)
            {
                return(CommandResult.Lang("CANNOT_TELEPORT_DRIVING"));
            }

            if (Delay.ContainsKey(player.CSteamId.m_SteamID))
            {
                return(CommandResult.Lang("ALREADY_WAITING"));
            }

            var dest     = WarpModule.Instance.WarpManager.GetByName(args[0].ToString());
            var cooldown = UEssentials.Config.Warp.TeleportDelay;

            if (cooldown > 0 && !player.HasPermission("essentials.bypass.warpcooldown"))
            {
                EssLang.Send(src, "WARP_COOLDOWN", cooldown);
            }

            var task = Task.Create()
                       .Id($"Warp teleport '{player.DisplayName}'")
                       .Delay(player.HasPermission("essentials.bypass.warpcooldown") ? 0 : cooldown * 1000)
                       .Action(t => {
                Delay.Remove(player.CSteamId.m_SteamID);
                player.Teleport(dest.Location, dest.Rotation);
                EssLang.Send(src, "WARP_TELEPORTED", args[0]);
            })
                       .Submit();

            Delay.Add(player.CSteamId.m_SteamID, task);

            return(CommandResult.Success());
        }
Esempio n. 5
0
        public override CommandResult OnExecute(ICommandSource src, ICommandArgs args)
        {
            var player   = src.ToPlayer();
            var playerId = player.CSteamId;

            Vector3 position;
            byte    angle;

            if (player.RocketPlayer.Stance == EPlayerStance.DRIVING ||
                player.RocketPlayer.Stance == EPlayerStance.SITTING)
            {
                return(CommandResult.Lang("CANNOT_TELEPORT_DRIVING"));
            }

            if (!BarricadeManager.tryGetBed(player.CSteamId, out position, out angle))
            {
                return(CommandResult.Lang("WITHOUT_BED"));
            }

            if (Delay.ContainsKey(player.CSteamId.m_SteamID))
            {
                return(CommandResult.Lang("ALREADY_WAITING"));
            }

            var homeCommand = UEssentials.Config.Home;
            var delay       = homeCommand.TeleportDelay;

            if (player.HasPermission("essentials.bypass.homecooldown"))
            {
                delay = 0;
            }

            if (delay > 0)
            {
                EssLang.Send(src, "TELEPORT_DELAY", TimeUtil.FormatSeconds((uint)delay));
            }

            var task = Task.Create()
                       .Delay(TimeSpan.FromSeconds(delay))
                       .Action(t => {
                Delay.Remove(playerId.m_SteamID);
                player.Teleport(position, angle);
                EssLang.Send(src, "TELEPORTED_BED");
            })
                       .Submit();

            Delay.Add(playerId.m_SteamID, task);

            return(CommandResult.Success());
        }
        public void SendMessage(Player player, string message, TimeSpan duration, int priority = 10, bool monospaced = false)
        {
            if (!_stack.ContainsKey(player))
            {
                _stack[player] = new SortedDictionary <int, BroadcastMessage>();
            }

            if (_stack[player].Count == 0 || priority <= _stack[player].First().Key)
            {
                if (!_dirtySlots.Contains(player.PlayerId))
                {
                    _dirtySlots.Add(player.PlayerId);
                }

                _stack[player][priority] = new BroadcastMessage(message, duration, monospaced);
            }
        }
        public override void Execute(ICommandContext context)
        {
            var player    = ((UnturnedUser)context.User).Player;
            var playerId  = player.CSteamID;
            var scheduler = context.Container.Resolve <ITaskScheduler>();

            if (player.Entity.Stance == EPlayerStance.DRIVING ||
                player.Entity.Stance == EPlayerStance.SITTING)
            {
                throw new CommandWrongUsageException(Translations.Get("CANNOT_TELEPORT_DRIVING"));
            }

            if (!BarricadeManager.tryGetBed(player.CSteamID, out var bedPosition, out var bedAngle))
            {
                throw new CommandWrongUsageException(Translations.Get("WITHOUT_BED"));
            }

            if (Delay.ContainsKey(player.CSteamID.m_SteamID))
            {
                throw new CommandWrongUsageException(Translations.Get("ALREADY_WAITING"));
            }

            var homeCommand = UEssentials.Config.Home;
            var delay       = homeCommand.TeleportDelay;

            if (player.CheckPermission("essentials.bypass.homecooldown") == PermissionResult.Grant)
            {
                delay = 0;
            }

            if (delay > 0)
            {
                context.User.SendLocalizedMessage(Translations, "TELEPORT_DELAY", TimeUtil.FormatSeconds((uint)delay));
            }

            var task = scheduler.ScheduleDelayed(UEssentials, () =>
            {
                Delay.Remove(playerId.m_SteamID);
                player.Entity.Teleport(bedPosition.ToSystemVector(), bedAngle);
                context.User.SendLocalizedMessage(Translations, "TELEPORTED_BED");
            }, "EssentialsHomeTeleport", TimeSpan.FromSeconds(delay));

            Delay.Add(playerId.m_SteamID, task);
        }