Exemplo n.º 1
0
        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());
        }
Exemplo n.º 2
0
        public override CommandResult OnExecute(ICommandSource src, ICommandArgs args)
        {
            var player   = src.ToPlayer();
            var playerId = player.CSteamId;

            if (Cooldown.HasEntry(playerId))
            {
                return(CommandResult.Lang("USE_COOLDOWN",
                                          TimeUtil.FormatSeconds((uint)Cooldown.GetRemainingTime(playerId))));
            }

            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"));
            }

            var homeCommand = UEssentials.Config.HomeCommand;
            var delay       = homeCommand.Delay;
            var cooldown    = homeCommand.Cooldown;

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

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

            var task = Tasks.New(t => {
                Delay.Remove(playerId.m_SteamID);
                player.Teleport(position, angle);
                EssLang.Send(src, "TELEPORTED_BED");
            }).Delay(delay * 1000);

            task.Go();

            Delay.Add(playerId.m_SteamID, task);
            Cooldown.AddEntry(playerId, cooldown);

            return(CommandResult.Success());
        }
Exemplo n.º 3
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());
        }
Exemplo n.º 4
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());
        }
Exemplo n.º 5
0
        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);
        }