Core: /limit without args should output the current limit.

This commit is contained in:
UnknownShadow200 2016-10-30 14:06:28 +11:00
parent 201410c661
commit 1a662ac109

View File

@ -28,47 +28,50 @@ namespace MCGalaxy.Commands {
public override void Use(Player p, string message) { public override void Use(Player p, string message) {
string[] args = message.Split(' '); string[] args = message.Split(' ');
if (args.Length < 2) { Help(p); return; } if (message == "") { Help(p); return; }
int limit; int limit = 0;
if (!int.TryParse(args[1], out limit) || limit <= 0) { bool hasLimit = args.Length > 1;
if (hasLimit && (!int.TryParse(args[1], out limit) || limit <= 0)) {
Player.Message(p, "Limit amount must be a whole number and greater than 0."); return; Player.Message(p, "Limit amount must be a whole number and greater than 0."); return;
} }
switch (args[0].ToLower()) { switch (args[0].ToLower()) {
case "rt": case "rt":
case "reloadthreshold": case "reloadthreshold":
SetLimit("Threshold before drawing reloads map set to {0}", ref Server.DrawReloadLimit, limit); SetLimit(p, "Threshold before drawing reloads map", ref Server.DrawReloadLimit, limit, hasLimit);
return; return;
case "rp": case "rp":
case "restartphysics": case "restartphysics":
SetLimit("Custom /rp's limit was changed to {0}", ref Server.rpLimit, limit); SetLimit(p, "Custom /rp limit", ref Server.rpLimit, limit, hasLimit);
return; return;
case "rpnormal": case "rpnormal":
SetLimit("Normal /rp's limit set to {0}", ref Server.rpNormLimit, limit); SetLimit(p, "Normal /rp limit", ref Server.rpNormLimit, limit, hasLimit);
return; return;
case "pu": case "pu":
case "physicsundo": case "physicsundo":
SetLimit("Physics undo max entries set to {0}", ref Server.physUndo, limit); SetLimit(p, "Physics undo max entries", ref Server.physUndo, limit, hasLimit);
return; return;
case "gen": case "gen":
case "genlimit": case "genlimit":
SetLimit("Maximum volume of maps players can generate set to {0}", ref Server.MapGenLimit, limit); SetLimit(p, "Maximum volume of maps players can generate", ref Server.MapGenLimit, limit, hasLimit);
return; return;
case "genadmin": case "genadmin":
case "genadminlimit": case "genadminlimit":
case "admingen": case "admingen":
case "admingenlimit": case "admingenlimit":
SetLimit("Maximum volume of maps admins can generate set to &b{0}", ref Server.MapGenLimitAdmin, limit); SetLimit(p, "Maximum volume of maps admins can generate", ref Server.MapGenLimitAdmin, limit, hasLimit);
return; return;
} }
if (args.Length < 2) { Help(p); return; }
if (args.Length == 2) { Player.Message(p, "You need to provide a rank name for this type."); return; } if (args.Length == 2) { Player.Message(p, "You need to provide a rank name for this type."); return; }
Group grp = Group.FindMatches(p, args[2]); Group grp = Group.FindMatches(p, args[2]);
if (grp == null) return; if (grp == null) return;
switch (args[0].ToLower()) { switch (args[0].ToLower()) {
case "dl": case "dl":
case "drawlimit": case "drawlimit":
Chat.MessageAll("{0}%S's draw limit set to &b{1}", grp.ColoredName, limit); Chat.MessageAll("{0}%S's draw limit set to &b{1}", grp.ColoredName, limit);
grp.maxBlocks = limit; break; grp.maxBlocks = limit; break;
case "mu": case "mu":
@ -81,18 +84,22 @@ namespace MCGalaxy.Commands {
Group.saveGroups(Group.GroupList); Group.saveGroups(Group.GroupList);
} }
static void SetLimit(string format, ref int target, int limit) { static void SetLimit(Player p, string format, ref int target, int value, bool hasValue) {
Chat.MessageAll(format, "&b" + limit); if (!hasValue) {
target = limit; Player.Message(p, format + ": &b" + target);
SrvProperties.Save(); } else {
target = value;
Chat.MessageAll(format + " set to &b" + target);
SrvProperties.Save();
}
} }
public override void Help(Player p) { public override void Help(Player p) {
Player.Message(p, "%T/limit [type] [amount] <rank>"); Player.Message(p, "%T/limit [type] [amount] <rank>");
Player.Message(p, "%HSets the limit for [type]"); Player.Message(p, "%HSets the limit for [type]");
Player.Message(p, "%HValid types: %Sreloadthreshold(rt), restartphysics(rp), " + Player.Message(p, "%HValid types: %Sreloadthreshold(rt), restartphysics(rp), " +
"rpnormal, physicsundo(pu), drawlimit(dl), maxundo(mu), genlimit(gen), " + "rpnormal, physicsundo(pu), drawlimit(dl), maxundo(mu), genlimit(gen), " +
"admingenlimit(admingen)"); "admingenlimit(admingen)");
Player.Message(p, "%H<rank> is required for drawlimit and maxundo types."); Player.Message(p, "%H<rank> is required for drawlimit and maxundo types.");
} }
} }