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) { throw new CommandWrongUsageException(); } UnturnedPlayer otherPlayer = (UnturnedPlayer)await context.Parameters.GetAsync <IPlayer>(0); if (otherPlayer.IsInVehicle) { await context.User.SendLocalizedMessage(translations, "command_tphere_vehicle"); return; } otherPlayer.Entity.Teleport(player); await context.User.SendLocalizedMessage(translations, "command_tphere_teleport_from_private", null, otherPlayer.CharacterName); await otherPlayer.User.SendLocalizedMessage(translations, "command_tphere_teleport_to_private", null, player.CharacterName); }
public async Task ExecuteAsync(ICommandContext context) { ITranslationCollection translations = ((RocketUnturnedHost)context.Container.Resolve <IHost>()).ModuleTranslations; if (context.Parameters.Length != 1) { throw new CommandWrongUsageException(); } byte amount = await context.Parameters.GetAsync <byte>(0); UnturnedPlayer player = ((UnturnedUser)context).Player; ushort itemId = player.NativePlayer.equipment.itemID; if (itemId == 0) { await context.User.SendLocalizedMessage(translations, "command_more_dequipped"); return; } await context.User.SendLocalizedMessage(translations, "command_more_give", null, amount, itemId); player.GiveItem(itemId, amount); }
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) { 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())); }
public void Execute(ICommandContext context) { ITranslationCollection translations = ((RocketUnturnedHost)context.Container.Resolve <IHost>()).ModuleTranslations; UnturnedPlayer player = ((UnturnedUser)context.User).Player; if (context.Parameters.Length != 1 && context.Parameters.Length != 2) { throw new CommandWrongUsageException(); } byte amount = 1; string itemString = context.Parameters.Get <string>(0); if (!ushort.TryParse(itemString, out ushort id)) { List <ItemAsset> sortedAssets = new List <ItemAsset>(Assets.find(EAssetType.ITEM).Cast <ItemAsset>()); ItemAsset asset = sortedAssets.Where(i => i.itemName != null) .OrderBy(i => i.itemName.Length) .FirstOrDefault(i => i.itemName.ToLower().Contains(itemString.ToLower())); if (asset != null) { id = asset.id; } if (string.IsNullOrEmpty(itemString.Trim()) || id == 0) { throw new CommandWrongUsageException(); } } Asset a = Assets.find(EAssetType.ITEM, id); if (a == null) { throw new CommandWrongUsageException(); } if (context.Parameters.Length == 2) { amount = context.Parameters.Get <byte>(1); } string assetName = ((ItemAsset)a).itemName; context.User.SendLocalizedMessage(translations, player.GiveItem(id, amount) ? "command_i_giving_private" : "command_i_giving_failed_private", null, amount, assetName, id); }
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) { IPermissionChecker permissions = context.Container.Resolve <IPermissionChecker>(); ITranslationCollection translations = ((RocketUnturnedHost)context.Container.Resolve <IHost>()).ModuleTranslations; IPlayer target; if (await permissions.CheckPermissionAsync(context.User, Permission + ".Others") == PermissionResult.Grant && context.Parameters.Length >= 1) { target = await context.Parameters.GetAsync <IPlayer>(0); } else { target = ((UnturnedUser)context.User).Player; } if (!(target is UnturnedPlayer uPlayer)) { await context.User.SendMessageAsync($"Could not heal {target.User.DisplayName}", ConsoleColor.Red); return; } uPlayer.Entity.Heal(100); uPlayer.Entity.Bleeding = false; uPlayer.Entity.Broken = false; uPlayer.Entity.Infection = 0; uPlayer.Entity.Hunger = 0; uPlayer.Entity.Thirst = 0; if (target == context.User) { await context.User.SendLocalizedMessageAsync(translations, "command_heal_success"); return; } await context.User.SendLocalizedMessageAsync(translations, "command_heal_success_me", null, target.User.DisplayName); await target.User.SendLocalizedMessageAsync(translations, "command_heal_success_other", null, context.User.DisplayName); }
public void Execute(ICommandContext context) { ITranslationCollection translations = ((RocketUnturnedHost)context.Container.Resolve <IHost>()).ModuleTranslations; UnturnedPlayer player = (UnturnedPlayer)context.Player; if (context.Parameters.Length != 1) { throw new CommandWrongUsageException(); } string param = context.Parameters.Get <string>(0); if (!ushort.TryParse(param, out ushort id)) { bool found = false; Asset[] assets = SDG.Unturned.Assets.find(EAssetType.VEHICLE); foreach (VehicleAsset ia in assets) { if (ia?.vehicleName == null || !ia.vehicleName.ToLower().Contains(param.ToLower())) { continue; } id = ia.id; found = true; break; } if (!found) { throw new CommandWrongUsageException(); } } Asset a = Assets.find(EAssetType.VEHICLE, id); string assetName = ((VehicleAsset)a).vehicleName; context.User.SendLocalizedMessage(translations, VehicleTool.giveVehicle(player.NativePlayer, id) ? "command_v_giving_private" : "command_v_giving_failed_private", null, assetName, id); }
public void Migrate(IDependencyContainer container, string basePath) { IHost host = container.Resolve <IHost>(); ITranslationCollection translationsLocator = container.Resolve <ITranslationCollection>(); ConfigurationContext toContext = new ConfigurationContext(host.WorkingDirectory, "Rocket.Unturned.Translations"); translationsLocator.Load(toContext, new Dictionary <string, string>()); ILogger logger = container.Resolve <ILogger>(); XmlConfiguration xmlConfiguration = (XmlConfiguration)container.Resolve <IConfiguration>("xml"); xmlConfiguration.ConfigurationRoot = "Translations"; ConfigurationContext fromContext = new ConfigurationContext(basePath, "Rocket.en.translation"); if (!xmlConfiguration.Exists(fromContext)) { logger.LogError( "Translations migration failed: Rocket.en.translation.xml was not found in: " + basePath); return; } xmlConfiguration.Load(fromContext); JArray translations = (JArray)((JsonNetConfigurationSection)xmlConfiguration["Translation"]).Node; foreach (JToken translation in translations) { JToken id = translation["@Id"]; JToken value = translation["@Value"]; translationsLocator.Set(id.Value <string>(), value.Value <string>()); } translationsLocator.Save(); }
/// <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); }
/// <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 void SendLocalizedMessage(this IUserManager userManager, ITranslationCollection translations, IUser user, string translationKey, params object[] arguments) { userManager.SendMessage(user, translations.Get(translationKey, arguments)); }
/// <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 void BroadcastLocalized(this IUserManager userManager, ITranslationCollection translations, string translationKey, params object[] arguments) { userManager.Broadcast(null, translations.Get(translationKey, arguments)); }
/// <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 void BroadcastLocalized(this IUserManager userManager, ITranslationCollection translations, IEnumerable <IUser> receivers, string translationKey, Color?color = null, params object[] arguments) { userManager.Broadcast(null, receivers, translations.Get(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="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="arguments">The arguments for the message. See <see cref="string.Format(string, object[])" /></param> public static void SendLocalizedMessage(this IUser User, ITranslationCollection translations, string translationKey, Color?color = null, params object[] arguments) { User.SendMessage(translations.Get(translationKey, arguments), color); }
public CommandsCollection(IUserManager userManager, ITranslationCollection translations) { this.userManager = userManager; this.translations = translations; }
/// <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); }
protected EssCommand(IPlugin plugin) { UEssentials = (EssCore)plugin; Translations = UEssentials.Translations; }