public ECommandRunError Execute(PointBlankPlayer executor, string[] args) { try { if (CommandClass.AllowedServerState == EAllowedServerState.LOADING && PointBlankServer.IsRunning) { PointBlankPlayer.SendMessage(executor, Translations["CommandWrapper_Running"], ConsoleColor.Red); return(ECommandRunError.SERVER_RUNNING); } if (CommandClass.AllowedServerState == EAllowedServerState.RUNNING && !PointBlankServer.IsRunning) { PointBlankPlayer.SendMessage(executor, Translations["CommandWrapper_NotRunning"], ConsoleColor.Red); return(ECommandRunError.SERVER_LOADING); } if (CommandClass.AllowedCaller == EAllowedCaller.SERVER && executor != null) { executor.SendMessage(Translations["CommandWrapper_NotConsole"], Color.red); return(ECommandRunError.NOT_CONSOLE); } if (CommandClass.AllowedCaller == EAllowedCaller.PLAYER && executor == null) { executor.SendMessage(Translations["CommandWrapper_NotPlayer"], Color.red); return(ECommandRunError.NOT_PLAYER); } if (CommandClass.MinimumParams > args.Length) { PointBlankPlayer.SendMessage(executor, Translations["CommandWrapper_Arguments"], ConsoleColor.Red); return(ECommandRunError.ARGUMENT_COUNT); } if (executor != null && executor.HasCooldown(CommandClass)) { executor.SendMessage(Translations["CommandWrapper_Cooldown"], Color.red); return(ECommandRunError.COOLDOWN); } bool shouldExecute = true; PointBlankCommandEvents.RunCommandExecute(CommandClass, args, executor, ref shouldExecute); if (!shouldExecute) { return(ECommandRunError.NO_EXECUTE); } executor?.SetCooldown(CommandClass, DateTime.Now); CommandClass.Execute(executor, args); return(ECommandRunError.NONE); } catch (Exception ex) { PointBlankLogging.LogError("Error when running command: " + Class.Name, ex); return(ECommandRunError.EXCEPTION); } }
public ECommandRunError ExecuteCommand(string text, PointBlankPlayer executor) { string[] info = ParseCommand(text); List <string> args = new List <string>(); CommandWrapper wrapper = Commands.FirstOrDefault(a => a.Commands.FirstOrDefault(b => b.ToLower() == info[0].ToLower()) != null && a.Enabled); string permission = ""; if (wrapper == null) { PointBlankPlayer.SendMessage(executor, Environment.ServiceTranslations[typeof(ServiceTranslations)].Translations["CommandManager_Invalid"], ConsoleColor.Red); return(ECommandRunError.COMMAND_NOT_EXIST); } permission = wrapper.Permission; if (info.Length > 1) { for (int i = 1; i < info.Length; i++) { args.Add(info[i]); } } if (args.Count > 0) { permission += "." + string.Join(".", args.ToArray()); } if (!PointBlankPlayer.IsServer(executor) && !executor.HasPermission(permission)) { PointBlankPlayer.SendMessage(executor, Environment.ServiceTranslations[typeof(ServiceTranslations)].Translations["CommandManager_NotEnoughPermissions"], ConsoleColor.Red); return(ECommandRunError.NO_PERMISSION); } return(wrapper.Execute(executor, args.ToArray())); }
public override void Execute(PointBlankPlayer executor, string[] args) { string admins = string.Join(",", Provider.clients.Where(a => a.isAdmin).Select(a => a.playerID.playerName).ToArray()); if (executor == null) { CommandWindow.Log(Translations["Admins_List"] + admins, ConsoleColor.Green); } else { if (Provider.hideAdmins && !executor.HasPermission("unturned.revealadmins")) { executor.SendMessage(Translations["Admins_Hidden"], Color.red); return; } executor.SendMessage(Translations["Admins_List"] + admins, Color.green); } }
public override void Execute(PointBlankPlayer executor, string[] args) { if (!PlayerTool.tryGetSteamID(args[0], out CSteamID player)) { UnturnedChat.SendMessage(executor, Translations["Base_InvalidPlayer"], ConsoleColor.Red); return; } if (executor == null) { SteamAdminlist.admin(player, CSteamID.Nil); CommandWindow.Log(string.Format(Translations["Admin_Set"], player), ConsoleColor.Green); } else { SteamAdminlist.admin(player, (PointBlankPlayer.IsServer(executor) ? CSteamID.Nil : ((UnturnedPlayer)executor).SteamID)); executor.SendMessage(string.Format(Translations["Admin_Set"], player), Color.green); } }
public override void Execute(PointBlankPlayer executor, string[] args) { Provider.isWhitelisted = true; PointBlankPlayer.SendMessage(executor, Translations["Whitelisted_Set"], ConsoleColor.Green); }
/// <summary> /// Sends a message to the player or the console /// </summary> /// <param name="player">The player(null if the console)</param> /// <param name="text">The message</param> /// <param name="color">The message color</param> public static void SendMessage(PointBlankPlayer player, object text, ConsoleColor color = ConsoleColor.White) => PointBlankPlayer.SendMessage(player, text, color);