Make the IsCreate/IsDelete etc methods of the Command class public (Thanks Goodly)

This commit is contained in:
UnknownShadow200 2023-10-22 17:27:28 +11:00
parent 81785236da
commit 9d40e99695
25 changed files with 54 additions and 55 deletions

View File

@ -51,7 +51,7 @@ namespace MCGalaxy.Commands.Bots
string bot = args[1], value = args.Length > 2 ? args[2] : null;
if (args[0].CaselessEq("add")) {
AddBot(p, bot);
} else if (IsDeleteCommand(args[0])) {
} else if (IsDeleteAction(args[0])) {
RemoveBot(p, bot, value);
} else if (args[0].CaselessEq("text")) {
SetBotText(p, bot, value, data.Rank);

View File

@ -33,7 +33,7 @@ namespace MCGalaxy.Commands.Bots
public override void Use(Player p, string message, CommandData data) {
string[] args = message.SplitSpaces();
string cmd = args[0];
if (IsListCommand(cmd)) {
if (IsListAction(cmd)) {
string modifier = args.Length > 1 ? args[1] : "";
HandleList(p, modifier);
return;
@ -45,11 +45,11 @@ namespace MCGalaxy.Commands.Bots
if (!Formatter.ValidFilename(p, ai)) return;
if (ai == "hunt" || ai == "kill") { p.Message("Reserved for special AI."); return; }
if (IsCreateCommand(cmd)) {
if (IsCreateAction(cmd)) {
HandleAdd(p, ai, args);
} else if (IsDeleteCommand(cmd)) {
} else if (IsDeleteAction(cmd)) {
HandleDelete(p, ai, args);
} else if (IsInfoCommand(cmd)) {
} else if (IsInfoAction(cmd)) {
HandleInfo(p, ai);
} else {
Help(p);

View File

@ -32,13 +32,13 @@ namespace MCGalaxy.Commands.CPE
if (message.Length == 0) { Help(p); return; }
string cmd = args[0];
if (IsCreateCommand(cmd)) {
if (IsCreateAction(cmd)) {
AddHandler(p, args);
} else if (IsDeleteCommand(cmd)) {
} else if (IsDeleteAction(cmd)) {
RemoveHandler(p, args);
} else if (IsEditCommand(cmd)) {
} else if (IsEditAction(cmd)) {
EditHandler(p, args);
} else if (IsListCommand(cmd)) {
} else if (IsListAction(cmd)) {
string modifer = args.Length > 1 ? args[1] : "";
ListHandler(p, "ccols list", modifer);
} else {

View File

@ -53,7 +53,7 @@ namespace MCGalaxy.Commands.Chatting
Toggle(p, ref p.Ignores.DrawOutput, "{0} ignoring draw command output"); return;
} else if (action == "worldchanges") {
Toggle(p, ref p.Ignores.WorldChanges, "{0} ignoring world changes"); return;
} else if (IsListCommand(action)) {
} else if (IsListAction(action)) {
p.Ignores.Output(p); return;
}

View File

@ -48,7 +48,7 @@ namespace MCGalaxy.Commands.Chatting
{
Output(p, i + 1, entries[i]);
}
} else if (IsDeleteCommand(args[0])) {
} else if (IsDeleteAction(args[0])) {
if (args.Length == 1) {
p.Message("You need to provide either \"all\" or a number."); return;
} else if (args[1].CaselessEq("all")) {

View File

@ -84,25 +84,25 @@ namespace MCGalaxy
return str.CaselessEq("all") || int.TryParse(str, out ignored);
}
protected internal static bool IsCreateCommand(string str) {
public static bool IsCreateAction(string str) {
return str.CaselessEq("create") || str.CaselessEq("add") || str.CaselessEq("new");
}
protected internal static bool IsDeleteCommand(string str) {
public static bool IsDeleteAction(string str) {
return str.CaselessEq("del") || str.CaselessEq("delete") || str.CaselessEq("remove");
}
protected internal static bool IsEditCommand(string str) {
public static bool IsEditAction(string str) {
return str.CaselessEq("edit") || str.CaselessEq("change") || str.CaselessEq("modify")
|| str.CaselessEq("move") || str.CaselessEq("update");
}
protected internal static bool IsInfoCommand(string str) {
public static bool IsInfoAction(string str) {
return str.CaselessEq("about") || str.CaselessEq("info") || str.CaselessEq("status")
|| str.CaselessEq("check");
}
protected internal static bool IsListCommand(string str) {
public static bool IsListAction(string str) {
return str.CaselessEq("list") || str.CaselessEq("view");
}
}

View File

@ -29,7 +29,7 @@ namespace MCGalaxy.Commands.Fun {
RoundsGame game = Game;
if (message.CaselessEq("go")) {
HandleGo(p, game); return;
} else if (IsInfoCommand(message)) {
} else if (IsInfoAction(message)) {
HandleStatus(p, game); return;
}
if (!CheckExtraPerm(p, data, 1)) return;
@ -42,7 +42,7 @@ namespace MCGalaxy.Commands.Fun {
HandleStop(p, game);
} else if (message.CaselessEq("add")) {
RoundsGameConfig.AddMap(p, p.level.name, p.level.Config, game);
} else if (IsDeleteCommand(message)) {
} else if (IsDeleteAction(message)) {
RoundsGameConfig.RemoveMap(p, p.level.name, p.level.Config, game);
} else if (message.CaselessStarts("set ") || message.CaselessStarts("setup ")) {
HandleSet(p, game, message.SplitSpaces());

View File

@ -41,13 +41,13 @@ namespace MCGalaxy.Commands.Moderation {
Directory.CreateDirectory("extra/reported");
string cmd = args[0];
if (IsListCommand(cmd)) {
if (IsListAction(cmd)) {
HandleList(p, args, data);
} else if (cmd.CaselessEq("clear")) {
HandleClear(p, args, data);
} else if (IsDeleteCommand(cmd)) {
} else if (IsDeleteAction(cmd)) {
HandleDelete(p, args, data);
} else if (IsInfoCommand(cmd)) {
} else if (IsInfoAction(cmd)) {
HandleCheck(p, args, data);
} else {
HandleAdd(p, args);

View File

@ -38,7 +38,7 @@ namespace MCGalaxy.Commands.Moderation {
public override void Use(Player p, string message, CommandData data) {
if (message.Length == 0 || message.CaselessEq("enter")) {
HandleEnter(p, data);
} else if (IsListCommand(message)) {
} else if (IsListAction(message)) {
HandleView(p, data);
} else if (message.CaselessEq("leave")) {
HandleLeave(p);

View File

@ -32,11 +32,11 @@ namespace MCGalaxy.Commands.Moderation {
if (args.Length >= 3) {
Assign(p, args, data);
} else if (IsListCommand(cmd)) {
} else if (IsListAction(cmd)) {
List(p);
} else if (IsDeleteCommand(cmd) && args.Length > 1) {
} else if (IsDeleteAction(cmd) && args.Length > 1) {
Delete(p, args[1], data);
} else if (IsInfoCommand(cmd) && args.Length > 1) {
} else if (IsInfoAction(cmd) && args.Length > 1) {
Info(p, args[1]);
} else {
Help(p);

View File

@ -28,13 +28,13 @@ namespace MCGalaxy.Commands.Moderation {
string[] args = message.SplitSpaces();
string cmd = args[0];
if (IsCreateCommand(cmd)) {
if (IsCreateAction(cmd)) {
if (args.Length < 2) { Help(p); return; }
Add(p, args[1]);
} else if (IsDeleteCommand(cmd)) {
} else if (IsDeleteAction(cmd)) {
if (args.Length < 2) { Help(p); return; }
Remove(p, args[1]);
} else if (IsListCommand(cmd)) {
} else if (IsListAction(cmd)) {
string modifier = args.Length > 1 ? args[1] : "";
List(p, modifier);
} else if (args.Length == 1) {

View File

@ -43,10 +43,10 @@ namespace MCGalaxy.Commands.Moderation {
if (cmd.CaselessEq("add")) {
if (args.Length < 2) { Help(p); return; }
Add(p, args[1]);
} else if (IsDeleteCommand(cmd)) {
} else if (IsDeleteAction(cmd)) {
if (args.Length < 2) { Help(p); return; }
Remove(p, args[1]);
} else if (IsListCommand(cmd)) {
} else if (IsListAction(cmd)) {
string modifier = args.Length > 1 ? args[1] : "";
List(p, modifier);
} else if (args.Length == 1) {

View File

@ -40,10 +40,10 @@ namespace MCGalaxy.Commands.Moderation {
if (message.Length == 0) { Help(p); return; }
string opt = args[0];
if (IsCreateCommand(opt)) {
if (IsCreateAction(opt)) {
if (args.Length == 1) { Help(p); return; }
CreateZone(p, args, data, 1);
} else if (IsDeleteCommand(opt)) {
} else if (IsDeleteAction(opt)) {
if (args.Length == 1) { Help(p); return; }
DeleteZone(p, args, data);
} else if (opt.CaselessEq("perbuild") || opt.CaselessEq("set")) {

View File

@ -363,7 +363,7 @@ namespace MCGalaxy.Commands.World {
UseCommand(p, "ZoneList", "");
} else if (cmd == "ADD") {
UseCommand(p, "PerBuild", "+" + name);
} else if (Command.IsDeleteCommand(cmd)) {
} else if (Command.IsDeleteAction(cmd)) {
UseCommand(p, "PerBuild", "-" + name);
} else if (cmd == "BLOCK") {
UseCommand(p, "PerVisit", "-" + name);

View File

@ -34,7 +34,7 @@ namespace MCGalaxy.Commands.Scripting
public override void Use(Player p, string message, CommandData data) {
string[] args = message.SplitSpaces(2);
if (IsListCommand(args[0])) {
if (IsListAction(args[0])) {
string modifier = args.Length > 1 ? args[1] : "";
p.Message("Loaded plugins:");

View File

@ -114,7 +114,7 @@ namespace MCGalaxy.Commands {
}
public UsageResult Use(Player p, string message, bool alertNoneFound = true) {
string[] args = message.SplitSpaces(2);
string[] args = message.SplitExact(2);
string cmd = args[0];
foreach (SubCommand subCmd in subCommands)
@ -122,8 +122,7 @@ namespace MCGalaxy.Commands {
if (!subCmd.Match(cmd)) { continue; }
if (!subCmd.Allowed(p, parentCommandName)) { return UsageResult.Disallowed; }
string value = args.Length > 1 ? args[1] : "";
subCmd.behavior(p, value);
subCmd.behavior(p, args[1]);
return UsageResult.Success;
}

View File

@ -34,7 +34,7 @@ namespace MCGalaxy.Commands.World {
BlockProps[] scope = GetScope(p, data, args[0]);
if (scope == null) return;
if (IsListCommand(args[1]) && (args.Length == 2 || IsListModifier(args[2]))) {
if (IsListAction(args[1]) && (args.Length == 2 || IsListModifier(args[2]))) {
ListProps(p, scope, args); return;
}
@ -45,7 +45,7 @@ namespace MCGalaxy.Commands.World {
if (opt.CaselessEq("copy")) {
CopyProps(p, scope, block, args);
} else if (opt.CaselessEq("reset") || IsDeleteCommand(opt)) {
} else if (opt.CaselessEq("reset") || IsDeleteAction(opt)) {
ResetProps(p, scope, block);
} else {
SetProps(p, scope, block, args);

View File

@ -46,7 +46,7 @@ namespace MCGalaxy.Commands.World {
if (cmd.Length == 0) { Help(p); return; }
bool checkExtraPerms = warps == WarpList.Global;
if (IsListCommand(cmd)) {
if (IsListAction(cmd)) {
string modifier = args.Length > 1 ? args[1] : "";
Paginator.Output(p, warps.Items, PrintWarp,
group + " list", group + "s", modifier);
@ -58,20 +58,20 @@ namespace MCGalaxy.Commands.World {
}
string name = args[1];
if (IsCreateCommand(cmd)) {
if (IsCreateAction(cmd)) {
if (checkExtraPerms && !CheckExtraPerm(p, data, 1)) return;
if (warps.Exists(name)) { p.Message("{0} already exists", group); return; }
warps.Create(name, p);
p.Message("{0} {1} created.", group, name);
} else if (IsDeleteCommand(cmd)) {
} else if (IsDeleteAction(cmd)) {
if (checkExtraPerms && !CheckExtraPerm(p, data, 1)) return;
Warp warp = Matcher.FindWarps(p, warps, name);
if (warp == null) return;
warps.Remove(warp, p);
p.Message("{0} {1} deleted.", group, warp.Name);
} else if (IsEditCommand(cmd)) {
} else if (IsEditAction(cmd)) {
if (checkExtraPerms && !CheckExtraPerm(p, data, 1)) return;
Warp warp = Matcher.FindWarps(p, warps, name);
if (warp == null) return;

View File

@ -39,7 +39,7 @@ namespace MCGalaxy.Commands.Building
string[] args = message.SplitSpaces(2);
BrushFactory brush = BrushFactory.Find(args[0]);
if (IsListCommand(args[0])) {
if (IsListAction(args[0])) {
BrushFactory.List(p);
} else if (brush == null) {
p.Message("No brush found with name \"{0}\".", args[0]);

View File

@ -56,7 +56,7 @@ namespace MCGalaxy.Commands.Building
if (!Formatter.ValidFilename(p, parts[1])) return;
LoadCopy(p, parts[1]);
} else if (IsDeleteCommand(opt)) {
} else if (IsDeleteAction(opt)) {
if (parts.Length != 2) { Help(p); return; }
if (!Formatter.ValidFilename(p, parts[1])) return;
@ -64,7 +64,7 @@ namespace MCGalaxy.Commands.Building
if (path == null) { p.Message("No such copy exists."); return; }
File.Delete(path);
p.Message("Deleted copy " + parts[1]);
} else if (IsListCommand(opt)) {
} else if (IsListAction(opt)) {
string dir = "extra/savecopy/" + p.name;
if (!Directory.Exists(dir)) {
p.Message("You have no saved copies"); return;

View File

@ -36,7 +36,7 @@ namespace MCGalaxy.Commands.Building {
string[] args = message.SplitSpaces(2);
TransformFactory transform = TransformFactory.Find(args[0]);
if (IsListCommand(args[0])) {
if (IsListAction(args[0])) {
List(p);
} else if (transform == null) {
p.Message("No transform found with name \"{0}\".", args[0]);

View File

@ -115,11 +115,11 @@ namespace MCGalaxy.Eco
LevelPreset preset = FindPreset(args[2]);
string cmd = args[1];
if (Command.IsCreateCommand(cmd)) {
if (Command.IsCreateAction(cmd)) {
AddPreset(p, args, preset);
} else if (Command.IsDeleteCommand(cmd)) {
} else if (Command.IsDeleteAction(cmd)) {
RemovePreset(p, args, preset);
} else if (Command.IsEditCommand(cmd)) {
} else if (Command.IsEditAction(cmd)) {
EditPreset(p, args, preset);
} else {
OnSetupHelp(p);

View File

@ -109,7 +109,7 @@ namespace MCGalaxy.Eco
if (!CommandParser.GetInt(p, args[3], "Price", ref cost, 0)) return;
p.Message("&aSet price of rank {0} &ato &f{1} &3{2}", grp.ColoredName, cost, Server.Config.Currency);
GetOrAdd(grp.Permission).Price = cost;
} else if (Command.IsDeleteCommand(args[1])) {
} else if (Command.IsDeleteAction(args[1])) {
Group grp = Matcher.FindRanks(p, args[2]);
if (grp == null) return;
if (p.Rank < grp.Permission) { p.Message("&WCannot remove a rank higher than yours."); return; }

View File

@ -30,7 +30,7 @@ namespace MCGalaxy.Modules.Awards
string[] args = message.SplitSpaces(2);
if (args.Length < 2) { Help(p); return; }
if (IsCreateCommand(args[0])) {
if (IsCreateAction(args[0])) {
args = args[1].Split(awardArgs, 2);
if (args.Length == 1) {
p.Message("&WUse a : to separate the award name from its description.");
@ -46,7 +46,7 @@ namespace MCGalaxy.Modules.Awards
Chat.MessageGlobal("Award added: &6{0} : {1}", award, desc);
AwardsList.Save();
}
} else if (IsDeleteCommand(args[0])) {
} else if (IsDeleteAction(args[0])) {
if (!AwardsList.Remove(args[1])) {
p.Message("This award does not exist."); return;
} else {

View File

@ -207,10 +207,10 @@ namespace MCGalaxy.Modules.Games.TW
List<TWGame.TWZone> zones = noTntZone ? game.tntFreeZones : game.tntImmuneZones;
string opt = args[3];
if (IsCreateCommand(opt)) {
if (IsCreateAction(opt)) {
p.Message("Place 2 blocks to create a {0} zone", type);
p.MakeSelection(2, zones, AddZoneCallback);
} else if (IsDeleteCommand(opt)) {
} else if (IsDeleteAction(opt)) {
if (args.Length > 4 && args[4].CaselessEq("all")) {
zones.Clear();
p.Message("Deleted all {0} zones", type);