mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-26 06:43:25 -04:00
Provide more helpful messages for when a command is disabled.
This commit is contained in:
parent
23b8147464
commit
2c42168199
@ -32,7 +32,7 @@ namespace MCGalaxy
|
||||
public abstract void Use(Player p, string message);
|
||||
public abstract void Help(Player p);
|
||||
public virtual CommandPerm[] AdditionalPerms { get { return null; } }
|
||||
public virtual bool Enabled { get { return true; } }
|
||||
public virtual CommandEnable Enabled { get { return CommandEnable.Always; } }
|
||||
|
||||
public static CommandList all = new CommandList();
|
||||
public static CommandList core = new CommandList();
|
||||
@ -49,6 +49,23 @@ namespace MCGalaxy
|
||||
Scripting.Autoload();
|
||||
}
|
||||
|
||||
#region Helpers
|
||||
|
||||
const CommandEnable bothFlags = CommandEnable.Lava | CommandEnable.Zombie;
|
||||
public static string GetDisabledReason(CommandEnable enable) {
|
||||
if (enable == CommandEnable.Always) return null;
|
||||
if (enable == CommandEnable.Economy && !Economy.Enabled)
|
||||
return "economy is disabled.";
|
||||
|
||||
if (enable == bothFlags && !(Server.zombie.Running || Server.lava.active))
|
||||
return "neither zombie nor lava survival is running.";
|
||||
if (enable == CommandEnable.Zombie && !Server.zombie.Running)
|
||||
return "zombie survival is not running.";
|
||||
if (enable == CommandEnable.Lava)
|
||||
return "lava survival is not running.";
|
||||
return null;
|
||||
}
|
||||
|
||||
protected static void RevertAndClearState(Player p, ushort x, ushort y, ushort z) {
|
||||
p.ClearBlockchange();
|
||||
p.RevertBlock(x, y, z);
|
||||
@ -72,15 +89,16 @@ namespace MCGalaxy
|
||||
}
|
||||
|
||||
protected void MessageTooHighRank(Player p, string action, bool canAffectOwnRank) {
|
||||
MessageTooHighRank(p, action, p.group, canAffectOwnRank);
|
||||
MessageTooHighRank(p, action, p.group, canAffectOwnRank);
|
||||
}
|
||||
|
||||
protected void MessageTooHighRank(Player p, string action, Group grp, bool canAffectGroup) {
|
||||
if (canAffectGroup)
|
||||
Player.SendMessage(p, "Can only " + action + " players ranked " + grp.color + grp.name + " %Sor below");
|
||||
Player.SendMessage(p, "Can only " + action + " players ranked " + grp.color + grp.name + " %Sor below");
|
||||
else
|
||||
Player.SendMessage(p, "Can only " + action + " players ranked below " + grp.color + grp.name);
|
||||
Player.SendMessage(p, "Can only " + action + " players ranked below " + grp.color + grp.name);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
public struct CommandPerm {
|
||||
@ -97,6 +115,11 @@ namespace MCGalaxy
|
||||
}
|
||||
}
|
||||
|
||||
[Flags]
|
||||
public enum CommandEnable {
|
||||
Always = 0, Economy = 1, Zombie = 2, Lava = 4,
|
||||
}
|
||||
|
||||
public sealed class CommandTypes {
|
||||
public const string Building = "build";
|
||||
public const string Chat = "chat";
|
||||
|
@ -27,7 +27,7 @@ namespace MCGalaxy.Commands {
|
||||
public override string type { get { return CommandTypes.Economy; } }
|
||||
public override bool museumUsable { get { return true; } }
|
||||
public override LevelPermission defaultRank { get { return LevelPermission.Guest; } }
|
||||
public override bool Enabled { get { return Economy.Enabled; } }
|
||||
public override CommandEnable Enabled { get { return CommandEnable.Economy; } }
|
||||
|
||||
public override void Use(Player p, string message) {
|
||||
if (p == null) { MessageInGameOnly(p); return; }
|
||||
|
@ -25,11 +25,11 @@ namespace MCGalaxy.Commands {
|
||||
/// <summary> Economy Beta v1.0 QuantumHive </summary>
|
||||
public sealed class CmdStore : Command {
|
||||
public override string name { get { return "store"; } }
|
||||
public override string shortcut { get { return ""; } }
|
||||
public override string shortcut { get { return "shop"; } }
|
||||
public override string type { get { return CommandTypes.Economy; } }
|
||||
public override bool museumUsable { get { return true; } }
|
||||
public override LevelPermission defaultRank { get { return LevelPermission.Guest; } }
|
||||
public override bool Enabled { get { return Economy.Enabled; } }
|
||||
public override CommandEnable Enabled { get { return CommandEnable.Economy; } }
|
||||
|
||||
public override void Use(Player p, string message) {
|
||||
if (message == "") {
|
||||
|
@ -27,7 +27,7 @@ namespace MCGalaxy.Commands {
|
||||
public override string type { get { return CommandTypes.Games; } }
|
||||
public override bool museumUsable { get { return true; } }
|
||||
public override LevelPermission defaultRank { get { return LevelPermission.Operator; } }
|
||||
public override bool Enabled { get { return Server.zombie.Running || Server.lava.active; } }
|
||||
public override CommandEnable Enabled { get { return CommandEnable.Zombie | CommandEnable.Lava; } }
|
||||
static char[] trimChars = {' '};
|
||||
|
||||
public override void Use(Player p, string message) {
|
||||
|
@ -27,7 +27,7 @@ namespace MCGalaxy.Commands {
|
||||
public override string type { get { return CommandTypes.Games; } }
|
||||
public override bool museumUsable { get { return true; } }
|
||||
public override LevelPermission defaultRank { get { return LevelPermission.Banned; } }
|
||||
public override bool Enabled { get { return Server.zombie.Running || Server.lava.active; } }
|
||||
public override CommandEnable Enabled { get { return CommandEnable.Zombie | CommandEnable.Lava; } }
|
||||
|
||||
public override void Use(Player p, string message) {
|
||||
if (p == null) { MessageInGameOnly(p); return; }
|
||||
@ -49,7 +49,7 @@ namespace MCGalaxy.Commands {
|
||||
public override string type { get { return CommandTypes.Games; } }
|
||||
public override bool museumUsable { get { return true; } }
|
||||
public override LevelPermission defaultRank { get { return LevelPermission.Banned; } }
|
||||
public override bool Enabled { get { return Server.zombie.Running || Server.lava.active; } }
|
||||
public override CommandEnable Enabled { get { return CommandEnable.Zombie | CommandEnable.Lava; } }
|
||||
|
||||
public override void Use(Player p, string message) {
|
||||
if (p == null) { MessageInGameOnly(p); return; }
|
||||
|
@ -25,7 +25,7 @@ namespace MCGalaxy.Commands {
|
||||
public override string type { get { return CommandTypes.Games; } }
|
||||
public override bool museumUsable { get { return true; } }
|
||||
public override LevelPermission defaultRank { get { return LevelPermission.Banned; } }
|
||||
public override bool Enabled { get { return Server.zombie.Running; } }
|
||||
public override CommandEnable Enabled { get { return CommandEnable.Zombie; } }
|
||||
public CmdAlive() { }
|
||||
|
||||
public override void Use(Player p, string message) {
|
||||
|
@ -27,7 +27,7 @@ namespace MCGalaxy.Commands {
|
||||
public override string type { get { return CommandTypes.Games; } }
|
||||
public override bool museumUsable { get { return true; } }
|
||||
public override LevelPermission defaultRank { get { return LevelPermission.Banned; } }
|
||||
public override bool Enabled { get { return Server.zombie.Running; } }
|
||||
public override CommandEnable Enabled { get { return CommandEnable.Zombie; } }
|
||||
public CmdBounties() { }
|
||||
|
||||
public override void Use(Player p, string message) {
|
||||
|
@ -26,7 +26,7 @@ namespace MCGalaxy.Commands {
|
||||
public override string type { get { return CommandTypes.Games; } }
|
||||
public override bool museumUsable { get { return true; } }
|
||||
public override LevelPermission defaultRank { get { return LevelPermission.Banned; } }
|
||||
public override bool Enabled { get { return Server.zombie.Running; } }
|
||||
public override CommandEnable Enabled { get { return CommandEnable.Zombie; } }
|
||||
|
||||
public override void Use(Player p, string message) {
|
||||
string[] args = message.Split(' ');
|
||||
|
@ -24,7 +24,7 @@ namespace MCGalaxy.Commands {
|
||||
public override string type { get { return CommandTypes.Games; } }
|
||||
public override bool museumUsable { get { return true; } }
|
||||
public override LevelPermission defaultRank { get { return LevelPermission.Operator; } }
|
||||
public override bool Enabled { get { return Server.zombie.Running; } }
|
||||
public override CommandEnable Enabled { get { return CommandEnable.Zombie; } }
|
||||
public CmdDisInfect() { }
|
||||
|
||||
public override void Use(Player p, string message) {
|
||||
|
@ -24,7 +24,7 @@ namespace MCGalaxy.Commands
|
||||
public override string type { get { return CommandTypes.Moderation; } }
|
||||
public override bool museumUsable { get { return true; } }
|
||||
public override LevelPermission defaultRank { get { return LevelPermission.Banned; } }
|
||||
public override bool Enabled { get { return Server.zombie.Running; } }
|
||||
public override CommandEnable Enabled { get { return CommandEnable.Zombie; } }
|
||||
public CmdEndRound() { }
|
||||
|
||||
public override void Use(Player p, string message) {
|
||||
|
@ -24,7 +24,7 @@ namespace MCGalaxy.Commands {
|
||||
public override string type { get { return CommandTypes.Other; } }
|
||||
public override bool museumUsable { get { return true; } }
|
||||
public override LevelPermission defaultRank { get { return LevelPermission.Banned; } }
|
||||
public override bool Enabled { get { return Server.zombie.Running; } }
|
||||
public override CommandEnable Enabled { get { return CommandEnable.Zombie; } }
|
||||
public CmdFlipHead() { }
|
||||
|
||||
public override void Use(Player p, string message) {
|
||||
|
@ -25,7 +25,7 @@ namespace MCGalaxy.Commands {
|
||||
public override string type { get { return CommandTypes.Moderation; } }
|
||||
public override bool museumUsable { get { return true; } }
|
||||
public override LevelPermission defaultRank { get { return LevelPermission.Banned; } }
|
||||
public override bool Enabled { get { return Server.zombie.Running; } }
|
||||
public override CommandEnable Enabled { get { return CommandEnable.Zombie; } }
|
||||
public CmdHuman() { }
|
||||
|
||||
public override void Use(Player p, string message) {
|
||||
|
@ -24,7 +24,7 @@ namespace MCGalaxy.Commands {
|
||||
public override string type { get { return CommandTypes.Games; } }
|
||||
public override bool museumUsable { get { return true; } }
|
||||
public override LevelPermission defaultRank { get { return LevelPermission.Operator; } }
|
||||
public override bool Enabled { get { return Server.zombie.Running; } }
|
||||
public override CommandEnable Enabled { get { return CommandEnable.Zombie; } }
|
||||
public CmdInfect() { }
|
||||
|
||||
public override void Use(Player p, string message) {
|
||||
|
@ -25,7 +25,7 @@ namespace MCGalaxy.Commands {
|
||||
public override string type { get { return CommandTypes.Games; } }
|
||||
public override bool museumUsable { get { return true; } }
|
||||
public override LevelPermission defaultRank { get { return LevelPermission.Banned; } }
|
||||
public override bool Enabled { get { return Server.zombie.Running; } }
|
||||
public override CommandEnable Enabled { get { return CommandEnable.Zombie; } }
|
||||
public CmdInfected() { }
|
||||
|
||||
public override void Use(Player p, string message) {
|
||||
|
@ -25,7 +25,7 @@ namespace MCGalaxy.Commands
|
||||
public override string type { get { return CommandTypes.Games; } }
|
||||
public override bool museumUsable { get { return true; } }
|
||||
public override LevelPermission defaultRank { get { return LevelPermission.Operator; } }
|
||||
public override bool Enabled { get { return Server.zombie.Running; } }
|
||||
public override CommandEnable Enabled { get { return CommandEnable.Zombie; } }
|
||||
public CmdQueue() { }
|
||||
|
||||
public override void Use(Player p, string message) {
|
||||
|
@ -25,7 +25,7 @@ namespace MCGalaxy.Commands {
|
||||
public override string type { get { return CommandTypes.Moderation; } }
|
||||
public override bool museumUsable { get { return true; } }
|
||||
public override LevelPermission defaultRank { get { return LevelPermission.Operator; } }
|
||||
public override bool Enabled { get { return Server.zombie.Running; } }
|
||||
public override CommandEnable Enabled { get { return CommandEnable.Zombie; } }
|
||||
public CmdReferee() { }
|
||||
|
||||
public override void Use(Player p, string message) {
|
||||
|
@ -116,9 +116,11 @@ namespace MCGalaxy.Commands
|
||||
case "commands":
|
||||
case "command":
|
||||
string commandsFound = "";
|
||||
foreach (Command comm in Command.all.commands)
|
||||
if (p == null || p.group.CanExecute(comm) && comm.Enabled)
|
||||
foreach (Command comm in Command.all.commands) {
|
||||
string disabled = Command.GetDisabledReason(comm.Enabled);
|
||||
if (p == null || p.group.CanExecute(comm) && disabled == null)
|
||||
try { commandsFound += ", " + comm.name; } catch { }
|
||||
}
|
||||
Player.SendMessage(p, "Available commands:");
|
||||
Player.SendMessage(p, commandsFound.Remove(0, 2));
|
||||
Player.SendMessage(p, "Type \"/help <command>\" for more help.");
|
||||
@ -176,7 +178,8 @@ namespace MCGalaxy.Commands
|
||||
static void PrintHelpForGroup(Player p, string typeName, string typeTitle) {
|
||||
string message = "";
|
||||
foreach (Command c in Command.all.commands) {
|
||||
if (p == null || p.group.CanExecute(c) && c.Enabled) {
|
||||
string disabled = Command.GetDisabledReason(c.Enabled);
|
||||
if (p == null || p.group.CanExecute(c) && disabled == null) {
|
||||
if (c.type.Contains(typeName))
|
||||
message += ", " + getColor(c.name) + c.name;
|
||||
}
|
||||
|
@ -1289,9 +1289,9 @@ return;
|
||||
if (!group.CanExecute(command)) {
|
||||
SendMessage("You are not allowed to use \"" + cmd + "\"."); return;
|
||||
}
|
||||
if (!command.Enabled) {
|
||||
SendMessage("The game or economy associated with this command is not running, " +
|
||||
"so this command is disabled."); return;
|
||||
string reason = Command.GetDisabledReason(command.Enabled);
|
||||
if (reason != null) {
|
||||
SendMessage("Command is disabled as " + reason); return;
|
||||
}
|
||||
if (!(cmd == "repeat" || cmd == "pass" || cmd == "setpass")) {
|
||||
lastCMD = cmd + " " + message;
|
||||
|
Loading…
x
Reference in New Issue
Block a user