Esempio n. 1
0
        protected override async UniTask OnExecuteAsync()
        {
            if (Context.Parameters.Length != 0)
            {
                throw new CommandWrongUsageException(Context);
            }

            UnturnedUser uPlayer  = (UnturnedUser)Context.Actor;
            var          userData = await m_UserDataStore.GetUserDataAsync(uPlayer.Id, uPlayer.Type);

            if (!userData.Data.ContainsKey("deathLocation"))
            {
                throw new UserFriendlyException(m_StringLocalizer["back:none"]);
            }
            var backLocation = SerializableVector3.Deserialize(userData.Data["deathLocation"]);

            if (backLocation == null)
            {
                throw new UserFriendlyException(m_StringLocalizer["back:none"]);
            }

            await uPlayer.Player.Player.TeleportToLocationAsync(backLocation.ToUnityVector3());

            await PrintAsync(m_StringLocalizer["back:success"]);
        }
Esempio n. 2
0
        protected override async UniTask OnExecuteAsync()
        {
            if (Context.Parameters.Length > 1)
            {
                throw new CommandWrongUsageException(Context);
            }

            UnturnedUser        uPlayer  = (UnturnedUser)Context.Actor;
            bool                bed      = Context.Parameters.Length == 0;
            string              homeName = Context.Parameters.Length == 1 ? Context.Parameters[0] : "";
            SerializableVector3 home     = null;

            // If user is teleporting to a home, query the datastore for the Vector3 location
            if (!bed)
            {
                UserData userData = await m_UserDataStore.GetUserDataAsync(uPlayer.Id, uPlayer.Type);

                if (!userData.Data.ContainsKey("homes"))
                {
                    throw new UserFriendlyException(m_StringLocalizer["home:no_home"]);
                }

                var homes = (Dictionary <object, object>)userData.Data["homes"];

                if (!homes.ContainsKey(homeName))
                {
                    throw new UserFriendlyException(m_StringLocalizer["home:invalid_home", new { Home = homeName }]);
                }

                home = SerializableVector3.Deserialize(homes[homeName]);
                if (home == null)
                {
                    throw new UserFriendlyException(m_StringLocalizer["home:invalid_home", new { Home = homeName }]);
                }
            }

            // Here we will delay the teleportation whether it be to a bed or home
            int  delay          = m_Configuration.GetValue <int>("teleportation:delay");
            bool cancelOnMove   = m_Configuration.GetValue <bool>("teleportation:cancelOnMove");
            bool cancelOnDamage = m_Configuration.GetValue <bool>("teleportation:cancelOnDamage");

            await uPlayer.PrintMessageAsync(m_StringLocalizer["home:success", new { Home = homeName, Time = delay }]);

            bool success = await m_TeleportService.TeleportAsync(uPlayer, new TeleportOptions(m_PluginAccessor.Instance, delay, cancelOnMove, cancelOnDamage));

            if (!success)
            {
                throw new UserFriendlyException(m_StringLocalizer["teleport:canceled"]);
            }

            // Bed-specific teleportation
            if (bed)
            {
                await UniTask.SwitchToMainThread();

                if (!uPlayer.Player.Player.teleportToBed())
                {
                    throw new UserFriendlyException(m_StringLocalizer["home:no_bed"]);
                }

                return;
            }

            if (!await uPlayer.Player.Player.TeleportToLocationAsync(home.ToUnityVector3()))
            {
                throw new UserFriendlyException(m_StringLocalizer["home:failure", new { Home = homeName }]);
            }
        }