public async Task ExecuteAsync(ICommandContext context) { ITranslationCollection translations = ((RocketUnturnedHost)context.Container.Resolve <IHost>()).ModuleTranslations; UnturnedPlayer player = ((UnturnedUser)context.User).Player; if (context.Parameters.Length != 1 && context.Parameters.Length != 3) { throw new CommandWrongUsageException(); } if (player.Entity.Stance == EPlayerStance.DRIVING || player.Entity.Stance == EPlayerStance.SITTING) { throw new CommandWrongUsageException( await translations.GetAsync("command_generic_teleport_while_driving_error")); } float?x = null; float?y = null; float?z = null; if (context.Parameters.Length == 3) { x = await context.Parameters.GetAsync <float>(0); y = await context.Parameters.GetAsync <float>(1); z = await context.Parameters.GetAsync <float>(2); } if (x != null) { player.Entity.Teleport(new System.Numerics.Vector3((float)x, (float)y, (float)z)); await context.User.SendLocalizedMessageAsync(translations, "command_tp_teleport_private", null, (float)x + "," + (float)y + "," + (float)z); return; } if (await context.Parameters.GetAsync <IPlayer>(0) is UnturnedPlayer otherplayer && otherplayer != player) { player.Entity.Teleport(otherplayer); await context.User.SendLocalizedMessageAsync(translations, "command_tp_teleport_private", null, otherplayer.CharacterName); return; } Node item = LevelNodes.nodes.FirstOrDefault(n => n.type == ENodeType.LOCATION && ((LocationNode)n).name.ToLower().Contains((context.Parameters.GetAsync <string>(0).GetAwaiter().GetResult()).ToLower())); if (item != null) { Vector3 c = item.point + new Vector3(0f, 0.5f, 0f); player.Entity.Teleport(c.ToSystemVector()); await context.User.SendLocalizedMessageAsync(translations, "command_tp_teleport_private", null, ((LocationNode)item).name); return; } await context.User.SendLocalizedMessageAsync(translations, "command_tp_failed_find_destination"); }
public async Task ExecuteAsync(ICommandContext context) { UnturnedPlayer player = ((UnturnedUser)context.User).Player; ITranslationCollection translations = ((RocketUnturnedHost)context.Container.Resolve <IHost>()).ModuleTranslations; if (!BarricadeManager.tryGetBed(player.CSteamID, out Vector3 pos, out byte rot)) { throw new CommandWrongUsageException(await translations.GetAsync("command_bed_no_bed_found_private")); } if (player.Entity.Stance == EPlayerStance.DRIVING || player.Entity.Stance == EPlayerStance.SITTING) { throw new CommandWrongUsageException(await translations.GetAsync("command_generic_teleport_while_driving_error")); } player.Entity.Teleport(pos.ToSystemVector(), rot); }
public async Task ExecuteAsync(ICommandContext context) { ITranslationCollection translations = ((RocketUnturnedHost)context.Container.Resolve <IHost>()).ModuleTranslations; if (context.Parameters.Length != 1) { throw new CommandWrongUsageException(); } UnturnedPlayer target = (UnturnedPlayer)await context.Parameters.GetAsync <IPlayer>(0); SteamPlayer otherPlayer = target.SteamPlayer; await context.User.SendMessageAsync(await translations.GetAsync("command_investigate_private", otherPlayer.playerID.characterName, otherPlayer.playerID.steamID.ToString())); }
[CommandUser(typeof(IConsole))] // only console can call it public async Task Broadcast(IUser sender, string[] args) { await userManager.BroadcastAsync(sender, await translations.GetAsync("broadcast", sender, string.Join(" ", args))); }
[CommandUser(typeof(IConsole))] // only console can call it public void Broadcast(IUser sender, string[] args) { userManager.BroadcastAsync(sender, translations.GetAsync("broadcast", sender, string.Join(" ", args)).Result); }
/// <summary> /// Broadcasts a localized message to all players /// </summary> /// <param name="userManager">The user manager.</param> /// <param name="translations">The translation soruce</param> /// <param name="translationKey">The key of the translated message to send</param> /// <param name="arguments">The arguments for the message</param> public static async Task BroadcastLocalizedAsync(this IUserManager userManager, ITranslationCollection translations, string translationKey, params object[] arguments) { await userManager.BroadcastAsync(null, await translations.GetAsync(translationKey, arguments)); }
/// <summary> /// Sends a localized message to the given player /// </summary> /// <param name="userManager">The user manager.</param> /// <param name="translations">The translation source.</param> /// <param name="user">The message receiver.</param> /// <param name="translationKey">The translation key.</param> /// <param name="arguments">The arguments for the message.</param> public static async Task SendLocalizedMessageAsync(this IUserManager userManager, ITranslationCollection translations, IUser user, string translationKey, params object[] arguments) { await userManager.SendMessageAsync(user, await translations.GetAsync(translationKey, arguments)); }
/// <summary> /// Sends a localized (translatable) message to the user. /// </summary> /// <param name="user">The message receiver.</param> /// <param name="translations">The translations source.</param> /// <param name="translationKey">The translation key.</param> /// <param name="color">The color to use.</param> /// <param name="arguments">The arguments for the message. See <see cref="string.Format(string, object[])" /></param> public static async Task SendLocalizedMessageAsync(this IUser user, ITranslationCollection translations, string translationKey, Color?color = null, params object[] arguments) { await user.SendMessageAsync(await translations.GetAsync(translationKey, arguments), color); }
/// <summary> /// Broadcasts a localized message to all players /// </summary> /// <param name="userManager">The user manager.</param> /// <param name="translations">The translation soruce</param> /// <param name="receivers">The message receivers.</param> /// <param name="translationKey">The key of the translated message to send</param> /// <param name="color">The color to use.</param> /// <param name="arguments">The arguments for the message</param> public static async Task BroadcastLocalizedAsync(this IUserManager userManager, ITranslationCollection translations, IEnumerable <IUser> receivers, string translationKey, Color?color = null, params object[] arguments) { await userManager.BroadcastAsync(null, receivers, await translations.GetAsync(translationKey, arguments), color); }