protected override async Task OnExecuteAsync() { UnturnedUser user = (UnturnedUser)Context.Actor; uint id = await Context.Parameters.GetAsync <uint>(0); PlayerBunch?pBunch = await m_KeysManager.TryGetPlayerBunch(user.SteamId.ToString()); if (pBunch == null || pBunch.VehiclesKey.Count == 0) { await user.PrintMessageAsync(m_StringLocalizer["translations:no_key"], System.Drawing.Color.Red, false, ""); } else if (!pBunch.VehiclesKey.Any(v => v.InstanceId == id)) { InteractableVehicle vehicle = VehicleManager.findVehicleByNetInstanceID(id); if (vehicle != null && !vehicle.isExploded && !vehicle.isDead) { await UniTask.SwitchToMainThread(); await user.PrintMessageAsync(m_StringLocalizer["translations:vehicle_position", new { vehicle = pBunch.VehiclesKey.Where(z => z.InstanceId == id).First().VehicleName }], System.Drawing.Color.Green); user.Player.Player.quests.replicateSetMarker(true, vehicle.transform.position, "Your vehicle!"); } else { await user.PrintMessageAsync(m_StringLocalizer["translations:vehicle_explode"]); await m_KeysManager.TryRemoveKeyFromBunch(user.SteamId.ToString(), id); } } else { await user.PrintMessageAsync(m_StringLocalizer["translations:no_vehicle", new { vehicleID = id }]); } }
protected override async Task OnExecuteAsync() { UnturnedUser user = (UnturnedUser)Context.Actor; InteractableVehicle?vehicle = RaycastHelper.Raycast(user.Player.Player, 6f); if (vehicle != null) { string ownerId = await m_KeysManager.CheckVehicleOwner(vehicle.instanceID); if (ownerId != "") { await m_KeysManager.TryRemoveKeyFromBunch(ownerId, vehicle.instanceID); await user.PrintMessageAsync(m_StringLocalizer["translations:vehicle_removedkey", new { vehicleID = vehicle.instanceID }]); var player = PlayerTool.getPlayer(new Steamworks.CSteamID(ulong.Parse(ownerId))); if (player != null) { ChatManager.say(player.channel.owner.playerID.steamID, m_StringLocalizer["translations:vehicle_lockpicked", new { vehicle = vehicle.asset.name, vehicleID = vehicle.instanceID }], UnityEngine.Color.red, EChatMode.SAY, true); } } } else { await user.PrintMessageAsync(m_StringLocalizer["translations:vehicle_notfound"], System.Drawing.Color.Red, false, ""); } }
protected override async UniTask OnExecuteAsync() { if (Context.Parameters.Length != 0) { throw new CommandWrongUsageException(Context); } UnturnedUser uPlayer = (UnturnedUser)Context.Actor; var currentVehicle = uPlayer.Player.Player.movement.getVehicle(); if (currentVehicle != null) { await UniTask.SwitchToMainThread(); RepairVehicle(currentVehicle); await uPlayer.PrintMessageAsync(m_StringLocalizer["repair:vehicle:current"]); } else { PlayerLook look = uPlayer.Player.Player.look; RaycastInfo raycast = DamageTool.raycast(new Ray(look.aim.position, look.aim.forward), 100f, RayMasks.VEHICLE); if (raycast.vehicle == null) { throw new UserFriendlyException(m_StringLocalizer["repair:vehicle:none"]); } await UniTask.SwitchToMainThread(); RepairVehicle(raycast.vehicle); await uPlayer.PrintMessageAsync(m_StringLocalizer["repair:vehicle:looking"]); } }
protected override async UniTask OnExecuteAsync() { if (Context.Parameters.Length > 1) { throw new CommandWrongUsageException(Context); } UnturnedUser uPlayer = (UnturnedUser)Context.Actor; ulong recipientSteamID = uPlayer.SteamId.m_SteamID; SteamPlayer requester; switch (Context.Parameters.Length) { case 0: if (!m_TpaRequestManager.IsRequestOpen(recipientSteamID)) { throw new UserFriendlyException(m_StringLocalizer["tpa:no_requests"]); } ulong firstRequester = m_TpaRequestManager.AcceptRequest(recipientSteamID); requester = PlayerTool.getSteamPlayer(firstRequester); if (requester == null) { throw new UserFriendlyException(m_StringLocalizer["tpa:disconnected", new { Requester = firstRequester.ToString() }]); } break; case 1: string requesterName = Context.Parameters[0]; if (!PlayerTool.tryGetSteamPlayer(requesterName, out requester)) { throw new UserFriendlyException(m_StringLocalizer["tpa:invalid_recipient", new { Recipient = requesterName }]); } if (!m_TpaRequestManager.IsRequestOpen(recipientSteamID, requester.playerID.steamID.m_SteamID)) { throw new UserFriendlyException(m_StringLocalizer["tpa:no_requests_from", new { Requester = requester.playerID.characterName }]); } break; default: throw new UserFriendlyException("This is a placeholder so that we can reassure the compiler that requester will never be null."); } //TODO: Change name to be less misleading. m_TpaRequestManager.AcceptRequest(recipientSteamID, requester.playerID.steamID.m_SteamID); await uPlayer.PrintMessageAsync(m_StringLocalizer["tpa:denied_self", new { Requester = requester.playerID.characterName }]); await UniTask.SwitchToMainThread(); ChatManager.serverSendMessage(m_StringLocalizer["tpa:denied_other", new { Recipient = uPlayer.DisplayName }], Color.red, toPlayer: requester, useRichTextFormatting: true); }
protected override async Task OnExecuteAsync() { UnturnedUser user = (UnturnedUser)Context.Actor; if (Context.Parameters.Count != 1) { throw new CommandWrongUsageException("Error! Correct usage: /tpa <player>"); } string tname = await Context.Parameters.GetAsync <string>(0); Player target = PlayerTool.getPlayer(tname); if (target == null) { throw new UserFriendlyException(m_StringLocalizer["plugin_translation:tpa_error_player_not_found"]); } else if (target == user.Player.Player) { throw new UserFriendlyException(m_StringLocalizer["plugin_translation:tpa_error_yourself"]); } else { UnturnedUser targetUser = (UnturnedUser)await m_UserManager.FindUserAsync(KnownActorTypes.Player, target.channel.owner.playerID.steamID.ToString(), UserSearchMode.FindById); await targetUser.PrintMessageAsync(m_StringLocalizer["plugin_translation:tpa_received", new { USER = user.DisplayName }]); SimpleTpa.PendingTeleports.Add(user, targetUser); } }
protected override async UniTask OnExecuteAsync() { if (Context.Parameters.Length < 1 || Context.Parameters.Length > 2) { throw new CommandWrongUsageException(Context); } int cooldown = Context.Parameters.Length == 2 ? await Context.Parameters.GetAsync <int>(1) : 0; var warpData = await m_DataStore.LoadAsync <WarpsData>(WarpsKey); string newWarpName = Context.Parameters[0]; if (warpData.Warps.ContainsKey(newWarpName)) { throw new UserFriendlyException(m_StringLocalizer["warps:set:exists", new { Warp = newWarpName }]); } UnturnedUser uPlayer = (UnturnedUser)Context.Actor; var newWarpLocation = uPlayer.Player.Player.transform.position.ToSerializableVector3(); warpData.Warps.Add(newWarpName, new SerializableWarp(cooldown, newWarpLocation)); await m_DataStore.SaveAsync(WarpsKey, warpData); m_PluginAccessor.Instance.RegisterNewWarpPermission(newWarpName); await uPlayer.PrintMessageAsync(m_StringLocalizer["warps:set:success", new { Warp = newWarpName }]); }
protected override async UniTask OnExecuteAsync() { UnturnedUser uPlayer = (UnturnedUser)Context.Actor; await UniTask.SwitchToMainThread(); uPlayer.Player.Player.skills.ServerUnlockAllSkills(); await uPlayer.PrintMessageAsync(m_StringLocalizer["maxskills:granted"]); }
protected override async Task OnExecuteAsync() { UnturnedUser user = (UnturnedUser)Context.Actor; PlayerBunch?pBunch = await m_KeysManager.TryGetPlayerBunch(user.SteamId.ToString()); if (pBunch == null || pBunch.VehiclesKey.Count == 0) { await user.PrintMessageAsync(m_StringLocalizer["translations:no_key"], System.Drawing.Color.Red, false, ""); } else { await user.PrintMessageAsync(m_StringLocalizer["translations:your_keys"]); for (int i = 0; i < pBunch.VehiclesKey.Count; i++) { await user.PrintMessageAsync($"{pBunch.VehiclesKey[i].VehicleName} - {pBunch.VehiclesKey[i].InstanceId}", System.Drawing.Color.FromName(m_Configuration.GetSection("configuration:keys_message_color").Get <string>()), false, ""); } } }
public async UniTask TelportPlayer(UnturnedUser target, UnturnedUser player) // player TO target { int interval = m_Configuration.GetSection("plugin_configuration:tpainterval").Get <int>() - 3; await Task.Delay(TimeSpan.FromSeconds(interval)); await player.PrintMessageAsync("3..."); await Task.Delay(TimeSpan.FromSeconds(1)); await player.PrintMessageAsync("2..."); await Task.Delay(TimeSpan.FromSeconds(1)); await player.PrintMessageAsync("1..."); await player.PrintMessageAsync(m_StringLocalizer["plugin_translation:tpa_now"]); await UniTask.SwitchToMainThread(); if (!target.Player.IsAlive) { await player.PrintMessageAsync(m_StringLocalizer["plugin_translation:tpa_error_target_dead"]); } else if (!player.Player.IsAlive) { await player.PrintMessageAsync(m_StringLocalizer["plugin_translation:tpa_error_user_dead"]); } else { player.Player.Player.teleportToLocationUnsafe(target.Player.Player.transform.position, target.Player.Player.look.yaw); } }
protected override async Task OnExecuteAsync() { UnturnedUser user = (UnturnedUser)Context.Actor; uint id = await Context.Parameters.GetAsync <uint>(1); string vic = await Context.Parameters.GetAsync <string>(0); Player player = PlayerTool.getPlayer(vic); if (player == null) { await user.PrintMessageAsync(m_StringLocalizer["translations:player_notfound"], System.Drawing.Color.Red, false, ""); } #pragma warning disable CS8602 UnturnedUser?victim = (UnturnedUser?)await m_UserManager.FindUserAsync(KnownActorTypes.Player, player.channel.owner.playerID.steamID.ToString(), UserSearchMode.FindById); #pragma warning restore CS8602 if (victim == null) { await user.PrintMessageAsync(m_StringLocalizer["translations:player_notfound"], System.Drawing.Color.Red, false, ""); } else if (victim == user) { await user.PrintMessageAsync(m_StringLocalizer["translations:yourself_error"], System.Drawing.Color.Red, false, ""); } else if (victim != null && user != null) { PlayerBunch?userBunch = await m_KeysManager.TryGetPlayerBunch(user.Id); PlayerBunch?victimBunch = await m_KeysManager.TryGetPlayerBunch(victim.Id); if (userBunch != null && victimBunch != null) { if (!userBunch.VehiclesKey.Any(v => v.InstanceId == id)) { if (victimBunch.VehiclesKey.Count >= (victimBunch.MaxKeys - 1)) { await user.PrintMessageAsync(m_StringLocalizer["translations:victim_maxkeys"]); } else { var vehicleKey = await m_KeysManager.TransferVehicle(user.Id, victim.Id, id); await user.PrintMessageAsync(m_StringLocalizer["translations:user_vehicle_transfer", new { vehicle = vehicleKey.VehicleName, victim = victim.DisplayName }], System.Drawing.Color.Green); await victim.PrintMessageAsync(m_StringLocalizer["translations:victim_vehicle_transfer", new { vehicle = vehicleKey.VehicleName, user = user.DisplayName }], System.Drawing.Color.Green); } } else { await user.PrintMessageAsync(m_StringLocalizer["translations:no_vehicle", new { vehicleID = id }]); } } } else { throw new UserFriendlyException("Internal error!"); } }
protected override async UniTask OnExecuteAsync() { if (Context.Parameters.Length > 1) { throw new CommandWrongUsageException(Context); } if (Context.Parameters.Length == 0 && Context.Actor.Type != KnownActorTypes.Player) { throw new CommandWrongUsageException(Context); } if (Context.Parameters.Length == 1 && await CheckPermissionAsync("others") == PermissionGrantResult.Deny) { throw new NotEnoughPermissionException(Context, "others"); } UnturnedUser uPlayer = Context.Parameters.Length == 0 ? (UnturnedUser)Context.Actor : await Context.Parameters.GetAsync <UnturnedUser>(0); if (uPlayer == null) { throw new UserFriendlyException(m_StringLocalizer["commands:failed_player", new { Player = Context.Parameters[0] }]); } 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.Count == 0) { throw new UserFriendlyException(m_StringLocalizer["home:no_home"]); } var stringBuilder = new StringBuilder(); foreach (var pair in homes) { stringBuilder.Append($"{pair.Key}, "); } stringBuilder.Remove(stringBuilder.Length - 2, 2); await uPlayer.PrintMessageAsync(m_StringLocalizer["home:list", new { User = uPlayer.DisplayName, Homes = stringBuilder.ToString() }]); }
protected override async UniTask OnExecuteAsync() { if (Context.Parameters.Length != 1) { throw new CommandWrongUsageException(Context); } var warpsData = await m_DataStore.LoadAsync <WarpsData>(WarpsKey); string searchTerm = Context.Parameters[0]; if (!warpsData.Warps.ContainsKey(searchTerm)) { throw new UserFriendlyException(m_StringLocalizer["warps:none", new { Warp = searchTerm }]); } if (await m_PermissionChecker.CheckPermissionAsync(Context.Actor, $"warps.{searchTerm}") == PermissionGrantResult.Deny) { throw new UserFriendlyException(m_StringLocalizer["warps:no_permission", new { Warp = searchTerm }]); } UnturnedUser uPlayer = (UnturnedUser)Context.Actor; var warp = warpsData.Warps[searchTerm]; double?cooldown = await m_CooldownManager.OnCooldownAsync(uPlayer, "warps", searchTerm, warp.Cooldown); if (cooldown.HasValue) { throw new UserFriendlyException(m_StringLocalizer["warps:cooldown", new { Time = cooldown, Warp = searchTerm }]); } // Delay warping so that they cannot escape combat int delay = m_Configuration.GetValue <int>("teleportation:delay"); bool cancelOnMove = m_Configuration.GetValue <bool>("teleportation:cancelOnMove"); bool cancelOnDamage = m_Configuration.GetValue <bool>("teleportation:cancelOnDamage"); // Tell the player of the delay and not to move await uPlayer.PrintMessageAsync(m_StringLocalizer["warps:success", new { Warp = searchTerm, 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"]); } await UniTask.SwitchToMainThread(); uPlayer.Player.Player.teleportToLocation(warp.Location.ToUnityVector3(), uPlayer.Player.Player.transform.eulerAngles.y); }
protected override async UniTask OnExecuteAsync() { if (Context.Parameters.Length > 2 || Context.Parameters.Length < 1) { throw new CommandWrongUsageException(Context); } //TODO: throw UserFriendlyException on bad input int additionReputation = await Context.Parameters.GetAsync <int>(0); if (Context.Parameters.Length == 1) { if (Context.Actor.Type == KnownActorTypes.Console) { throw new CommandWrongUsageException(Context); } UnturnedUser uPlayer = (UnturnedUser)Context.Actor; await UniTask.SwitchToMainThread(); uPlayer.Player.Player.skills.askRep(additionReputation); await uPlayer.PrintMessageAsync(m_StringLocalizer["reputation:success", new { Reputation = additionReputation.ToString() }]); } else { string nestedPermission = "give"; if (await CheckPermissionAsync(nestedPermission) == PermissionGrantResult.Deny) { throw new NotEnoughPermissionException(Context, nestedPermission); } string searchTerm = Context.Parameters[1]; if (!PlayerTool.tryGetSteamPlayer(searchTerm, out SteamPlayer player)) { throw new UserFriendlyException(m_StringLocalizer["general:invalid_player", new { Player = searchTerm }]); } await UniTask.SwitchToMainThread(); player.player.skills.askRep(additionReputation); await Context.Actor.PrintMessageAsync(m_StringLocalizer["reputation:gave", new { Player = player.playerID.characterName, Reputation = additionReputation.ToString() }]); } }
protected override async UniTask OnExecuteAsync() { if (Context.Parameters.Length != 0) { throw new CommandWrongUsageException(Context); } UnturnedUser uPlayer = (UnturnedUser)Context.Actor; PlayerInventory inventory = uPlayer.Player.Player.inventory; await UniTask.SwitchToMainThread(); foreach (SDG.Unturned.Items itemContainer in inventory.items) { if (itemContainer == null) { continue; } foreach (ItemJar itemJar in itemContainer.items) { Item item = itemJar.item; if (item.quality != 100) { inventory.sendUpdateQuality(itemContainer.page, itemJar.x, itemJar.y, 100); } if (!HasDurableBarrel(item, out ushort barrelID)) { continue; } if (barrelID == 0) { continue; } if (item.state[16] == 100) { continue; } item.state[16] = 100; inventory.sendUpdateInvState(itemContainer.page, itemJar.x, itemJar.y, item.state); } } await uPlayer.PrintMessageAsync(m_StringLocalizer["repair:inventory"]); }
protected override async Task OnExecuteAsync() { UnturnedUser user = (UnturnedUser)Context.Actor; uint id = await Context.Parameters.GetAsync <uint>(0); if (!await m_KeysManager.TryRemoveKeyFromBunch(user.Id, id)) { await user.PrintMessageAsync(m_StringLocalizer["translations:no_vehicle", new { vehicleID = id }], System.Drawing.Color.Red, false, ""); } else { InteractableVehicle vehicle = VehicleManager.findVehicleByNetInstanceID(id); await UniTask.SwitchToMainThread(); VehicleManager.instance.channel.send("tellVehicleLock", ESteamCall.ALL, ESteamPacket.UPDATE_RELIABLE_BUFFER, new object[] { vehicle.instanceID, user.SteamId, user.Player.Player.quests.groupID, false }); await user.PrintMessageAsync(m_StringLocalizer["translations:vehicle_delete", new { vehicleID = id }], System.Drawing.Color.Red, false, ""); } }
protected override async UniTask OnExecuteAsync() { if (Context.Parameters.Length != 0) { throw new CommandWrongUsageException(Context); } await UniTask.SwitchToMainThread(); UnturnedUser user = (UnturnedUser)Context.Actor; Vector3 position = user.Player.Player.transform.position; await user.PrintMessageAsync(m_StringLocalizer["position", new { X = position.x, Y = position.y, Z = position.z }]); }
protected override async UniTask OnExecuteAsync() { if (Context.Parameters.Length > 1) { throw new CommandWrongUsageException(Context); } UnturnedUser uPlayer = (UnturnedUser)Context.Actor; float direction = uPlayer.Player.Player.transform.eulerAngles.y; string directionName; //TODO: Teleporting breaks direction name for some reason if (Context.Parameters.Length == 1) { direction = Context.Parameters[0].ToUpperInvariant() switch { "N" => 0, "NORTH" => 0, "S" => 180, "SOUTH" => 180, "E" => 90, "EAST" => 90, "W" => 270, "WEST" => 270, _ => throw new CommandWrongUsageException(Context) }; await uPlayer.Player.Player.TeleportToLocationAsync(uPlayer.Player.Player.transform.position, direction); } directionName = direction switch { _ when direction <North || direction> NorthWest => m_StringLocalizer["compass:north"], _ when direction > North && direction <NorthEast => m_StringLocalizer["compass:northeast"], _ when direction> NorthEast && direction <East => m_StringLocalizer["compass:east"], _ when direction> East && direction <SouthEast => m_StringLocalizer["compass:southeast"], _ when direction> SouthEast && direction <South => m_StringLocalizer["compass:south"], _ when direction> South && direction <SouthWest => m_StringLocalizer["compass:southwest"], _ when direction> SouthWest && direction <West => m_StringLocalizer["compass:west"], _ when direction> West && direction < NorthWest => m_StringLocalizer["compass:northwest"], _ => m_StringLocalizer["compass:unknown"] }; await uPlayer.PrintMessageAsync(directionName); } }
protected override async UniTask OnExecuteAsync() { //TODO: Add support for configurable allowed effects? UnturnedUser usr = (UnturnedUser)Context.Actor; Player target; if (Context.Parameters.Length > 1 && Context.Parameters.Length < 2) { target = Provider.clients.FirstOrDefault(p => p.player.name.Contains(Context.Parameters.GetAsync <string>(1).Result))?.player; if (target == null) { throw new CommandWrongUsageException("Could not find player"); } } else if (Context.Parameters.Length == 1) { target = ((UnturnedUser)Context.Actor).Player.Player; } else { throw new CommandWrongUsageException("Unexpected amount of parameters"); } if (target == null) { return; } ushort effectId = await Context.Parameters.GetAsync <ushort>(0); await UniTask.SwitchToMainThread(); EffectManager.sendEffect(effectId, target.channel.GetOwnerTransportConnection(), target.transform.position); await usr.PrintMessageAsync( $"Successfully gave effect {effectId} to {target.channel.owner.playerID.characterName}"); }
protected override async UniTask OnExecuteAsync() { if (Context.Parameters.Length > 1) { throw new CommandWrongUsageException(Context); } UnturnedUser uPlayer = (UnturnedUser)Context.Actor; //TODO: throw UserFriendlyException on bad input Vector3 newPosition = uPlayer.Player.Player.transform.position; float downDistance = Context.Parameters.Length == 0 ? 10f : await Context.Parameters.GetAsync <float>(0); newPosition.y -= downDistance; await uPlayer.Player.Player.TeleportToLocationUnsafeAsync(newPosition); await uPlayer.PrintMessageAsync(m_StringLocalizer["descend:success", new { Distance = downDistance.ToString() }]); }
protected override async UniTask OnExecuteAsync() { if (Context.Parameters.Length != 0) { throw new CommandWrongUsageException(Context); } await UniTask.SwitchToMainThread(); UnturnedUser uPlayer = (UnturnedUser)Context.Actor; Transform aim = uPlayer.Player.Player.look.aim; if (!PhysicsUtility.raycast(new Ray(aim.position, aim.forward), out RaycastHit hit, 1024f, COLLISION_NO_SKY)) { throw new UserFriendlyException(m_StringLocalizer["jump:none"]); } await uPlayer.Player.Player.TeleportToLocationUnsafeAsync(hit.point + new Vector3(0f, 2f, 0f)); await uPlayer.PrintMessageAsync(m_StringLocalizer["jump:success"]); }
protected override async UniTask OnExecuteAsync() { if (Context.Parameters.Length > 1) { throw new CommandWrongUsageException(Context); } if (Context.Parameters.Length == 0) { //TODO: Use a more descriptive error message if (Context.Actor.Type == KnownActorTypes.Console) { throw new CommandWrongUsageException(Context); } UnturnedUser uPlayer = (UnturnedUser)Context.Actor; await UniTask.SwitchToMainThread(); uPlayer.Player.Player.ClearInventory(); await uPlayer.PrintMessageAsync(m_StringLocalizer["clear:inventory"]); } else { string searchTerm = Context.Parameters[0]; if (!PlayerTool.tryGetSteamPlayer(searchTerm, out SteamPlayer recipient)) { throw new UserFriendlyException(m_StringLocalizer["general:invalid_player", new { Player = searchTerm }]); } await UniTask.SwitchToMainThread(); recipient.player.ClearInventory(); await Context.Actor.PrintMessageAsync(m_StringLocalizer["clear:inventory_other", new { Player = recipient.playerID.characterName }]); } }
protected override async UniTask OnExecuteAsync() { if (Context.Parameters.Length > 1) { throw new CommandWrongUsageException(Context); } UnturnedUser uPlayer = (UnturnedUser)Context.Actor; ulong recipientSteamID = uPlayer.SteamId.m_SteamID; UnturnedUser requester; switch (Context.Parameters.Length) { case 0: if (!m_TpaRequestManager.IsRequestOpen(recipientSteamID)) { throw new UserFriendlyException(m_StringLocalizer["tpa:accept:no_requests"]); } ulong firstRequester = m_TpaRequestManager.AcceptRequest(recipientSteamID); requester = m_UserDirectory.FindUser(firstRequester.ToString(), UserSearchMode.FindById); if (requester == null) { throw new UserFriendlyException(m_StringLocalizer["tpa:accept:disconnected", new { Requester = firstRequester.ToString() }]); } break; case 1: string requesterName = Context.Parameters[0]; requester = m_UserDirectory.FindUser(requesterName, UserSearchMode.FindByName); if (requester == null) { throw new UserFriendlyException(m_StringLocalizer["tpa:invalid_recipient", new { Recipient = requesterName }]); } if (!m_TpaRequestManager.IsRequestOpen(recipientSteamID, requester.SteamId.m_SteamID)) { throw new UserFriendlyException(m_StringLocalizer["tpa:accept:no_requests_from", new { Requester = requester.DisplayName }]); } break; default: throw new UserFriendlyException("This is a placeholder so that we can reassure the compiler that requester will never be null."); } 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["tpa:accept:accepted_self", new { Requester = requester.DisplayName, Time = delay }]); requester.PrintMessageAsync(m_StringLocalizer["tpa:accept:accepted_other", new { Recipient = uPlayer.DisplayName, Time = delay }]); bool successful = await m_TeleportService.TeleportAsync(requester, new TeleportOptions(m_PluginAccessor.Instance, delay, cancelOnMove, cancelOnDamage)); if (!successful) { requester.PrintMessageAsync(m_StringLocalizer["teleport:canceled"], Color.DarkRed); throw new UserFriendlyException(m_StringLocalizer["teleport:canceled"]); } await requester.Player.Player.TeleportToLocationAsync(uPlayer.Player.Player.transform.position); }
protected override async UniTask OnExecuteAsync() { if (Context.Parameters.Length > 1) { throw new CommandWrongUsageException(Context); } UnturnedUser uPlayer = (UnturnedUser)Context.Actor; UserData userData = await m_UserDataStore.GetUserDataAsync(uPlayer.Id, uPlayer.Type); if (!userData.Data.ContainsKey("homes")) { userData.Data.Add("homes", new Dictionary <string, SerializableVector3>()); } var homes = (Dictionary <object, object>)userData.Data["homes"]; int amountOfHomes = homes.Count; // If this is the user's first home, or they have permission to make infinite homes, then skip the check if (amountOfHomes != 0 && await CheckPermissionAsync("infinite") == PermissionGrantResult.Deny) { bool any = false; for (int i = amountOfHomes; i < 11; i++) { // No logic unless it finds a permission with a number to limit homes if (await CheckPermissionAsync(i.ToString()) == PermissionGrantResult.Deny) { continue; } any = true; if (i > amountOfHomes) { break; } throw new UserFriendlyException(m_StringLocalizer["home:too_many"]); } // If there is no permission, only allow 1 home if (!any) { throw new UserFriendlyException(m_StringLocalizer["home:too_many"]); } } if (Context.Parameters.Length == 0) { homes["home"] = uPlayer.Player.Player.transform.position.ToSerializableVector(); userData.Data["homes"] = homes; await m_UserDataStore.SetUserDataAsync(userData); await uPlayer.PrintMessageAsync(m_StringLocalizer["home:set", new { Home = "home" }]); } else { string home = Context.Parameters[0]; homes[home] = uPlayer.Player.Player.transform.position.ToSerializableVector(); userData.Data["homes"] = homes; await m_UserDataStore.SetUserDataAsync(userData); await uPlayer.PrintMessageAsync(m_StringLocalizer["home:set", new { Home = home }]); } }
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 }]); } }