protected override async Task OnExecuteAsync() { if (Context.Actor.Type == KnownActorTypes.Console && Context.Parameters.Length == 0) { throw new CommandWrongUsageException(Context); } var other = false; var targetData = (UnturnedUser)null; if (Context.Parameters.Length > 0) { var otherPermission = await m_PermissionChecker.CheckPermissionAsync(Context.Actor, "vanish.other") == PermissionGrantResult.Grant; var target = await Context.Parameters.GetAsync <string>(0); targetData = await m_UnturnedUserProvider.FindUserAsync(KnownActorTypes.Player, target, UserSearchMode.NameOrId) as UnturnedUser; if (otherPermission) { if (targetData == null) { throw new UserFriendlyException( m_StringLocalizer["ldm_cmds:fail:player_not_found", target]); } if (!Context.Actor.Id.Equals(targetData.Id, StringComparison.OrdinalIgnoreCase)) { other = true; } } } if (!other) { targetData = Context.Actor as UnturnedUser; } // ReSharper disable once PossibleNullReferenceException var ldmComponent = m_Plugin.GetLdmComponent(targetData.SteamId); if (ldmComponent == null) { throw new UserFriendlyException(m_StringLocalizer["ldm_cmds:fail:invalid_user", targetData.DisplayName]); } string message; if (ldmComponent.IsVanishModeActive) { ldmComponent.ActivateVanishMode(); message = other ? m_StringLocalizer["ldm_cmds:success:vanish_other_enabled", targetData.DisplayName] : m_StringLocalizer["ldm_cmds:success:vanish_enabled"]; } else { await UniTask.SwitchToMainThread(); ldmComponent.DesactivateVanishMode(); message = other ? m_StringLocalizer["ldm_cmds:success:vanish_other_disabled", targetData.DisplayName] : m_StringLocalizer["ldm_cmds:success:vanish_disabled"]; } await PrintAsync(message); if (other) { await targetData.PrintMessageAsync(m_StringLocalizer[ ldmComponent.IsGodModeActive ? "ldm_cmds:success:vanish_enabled_by" : "ldm_cmds:success:vanish_disabled_by" , Context.Actor.DisplayName]); } var getBalanceEvent = new ChangeVanishModeEvent(targetData, ldmComponent.IsVanishModeActive); await m_EventBus.EmitAsync(m_Plugin, this, getBalanceEvent); }
protected override async Task OnExecuteAsync() { if (Context.Actor.Type == KnownActorTypes.Console && Context.Parameters.Length == 0) { throw new CommandWrongUsageException(Context); } var other = false; var targetData = (UnturnedUser)null; if (Context.Parameters.Length > 0) { var otherPermission = await m_PermissionChecker.CheckPermissionAsync(Context.Actor, "heal.other") == PermissionGrantResult.Grant; var target = await Context.Parameters.GetAsync <string>(0); targetData = await m_UnturnedUserProvider.FindUserAsync(KnownActorTypes.Player, target, UserSearchMode.NameOrId) as UnturnedUser; if (otherPermission) { if (targetData == null) { throw new UserFriendlyException( m_StringLocalizer["ldm_cmds:fail:player_not_found", target]); } if (!Context.Actor.Id.Equals(targetData.Id, StringComparison.OrdinalIgnoreCase)) { other = true; } } } if (!other) { targetData = Context.Actor as UnturnedUser; } // ReSharper disable PossibleNullReferenceException await UniTask.SwitchToMainThread(); targetData.Player.life.askHeal(100, true, true); targetData.Player.life.askDisinfect(100); targetData.Player.life.askDrink(100); targetData.Player.life.askEat(100); // ReSharper restore PossibleNullReferenceException var message = other ? m_StringLocalizer["ldm_cmds:success:heal_other", targetData.DisplayName] : m_StringLocalizer["ldm_cmds:success:heal"]; await PrintAsync(message); if (other) { await targetData.PrintMessageAsync(m_StringLocalizer["ldm_cmds:success:healed_by", Context.Actor.DisplayName]); } }