mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-23 12:42:22 -04:00
First cleanup of /map.
This commit is contained in:
parent
d5ca11caf1
commit
c6e039759e
@ -30,34 +30,43 @@ namespace MCGalaxy.Commands.World {
|
||||
}
|
||||
|
||||
public override void Use(Player p, string message) {
|
||||
if (CheckSuper(p, message, "level name")) return;
|
||||
if (message == "") message = p.level.name;
|
||||
Level lvl;
|
||||
string[] parts = message.SplitSpaces(3);
|
||||
string opt = parts[0].ToLower();
|
||||
string value = "";
|
||||
string[] args = message.SplitSpaces(3);
|
||||
Level lvl = null;
|
||||
string opt = null, value = null;
|
||||
|
||||
if (parts.Length == 1) {
|
||||
lvl = LevelInfo.Find(opt);
|
||||
if (lvl == null) {
|
||||
if (p != null) lvl = p.level;
|
||||
if (IsMapOption(args)) {
|
||||
if (Player.IsSuper(p)) { SuperRequiresArgs(p, "level"); return; }
|
||||
|
||||
lvl = p.level; opt = args[0];
|
||||
args = message.SplitSpaces(2);
|
||||
value = args.Length > 1 ? args[1] : "";
|
||||
} else {
|
||||
PrintMapInfo(p, lvl); return;
|
||||
}
|
||||
} else {
|
||||
lvl = LevelInfo.Find(opt);
|
||||
if (lvl == null || opt == "ps" || opt == "rp") {
|
||||
lvl = p.level;
|
||||
value = parts[1];
|
||||
} else {
|
||||
opt = parts[1];
|
||||
value = parts.Length > 2 ? parts[2] : "";
|
||||
}
|
||||
lvl = LevelInfo.FindMatches(p, args[0]);
|
||||
if (lvl == null) return;
|
||||
if (args.Length == 1) { PrintMapInfo(p, lvl); return; }
|
||||
|
||||
opt = args[1];
|
||||
value = args.Length > 2 ? args[2] : "";
|
||||
}
|
||||
|
||||
if (!CheckExtraPerm(p)) { MessageNeedExtra(p, "can set map options."); return; }
|
||||
SetMapOption(p, lvl, opt, value);
|
||||
}
|
||||
|
||||
try {
|
||||
if (lvl == null) Player.Message(p, "derp");
|
||||
switch (opt) {
|
||||
static bool IsMapOption(string[] args) {
|
||||
string opt = args[0].ToLower();
|
||||
const string opts = "theme|finite|ai|edge|grass|ps|physicspeed|overload|motd|death|killer|fall"
|
||||
+ "|drown|unload|chat|load|loadongoto|flow|randomflow|tree|growtrees|buildable|deletable";
|
||||
if (!opts.Contains(opt)) return false;
|
||||
|
||||
bool optHasArg = opt == "ps" || opt == "physicspeed" || opt == "overload" || opt == "fall" || opt == "drown";
|
||||
return args.Length == (optHasArg ? 2 : 1);
|
||||
}
|
||||
|
||||
static void SetMapOption(Player p, Level lvl, string opt, string value) {
|
||||
switch (opt.ToLower()) {
|
||||
case "theme":
|
||||
lvl.theme = value;
|
||||
lvl.ChatLevel("Map theme: &b" + lvl.theme); break;
|
||||
@ -100,7 +109,6 @@ namespace MCGalaxy.Commands.World {
|
||||
case "chat":
|
||||
SetBool(p, lvl, ref lvl.worldChat, "Roleplay (level only) chat: ", true); break;
|
||||
case "load":
|
||||
case "autoload":
|
||||
case "loadongoto":
|
||||
SetBool(p, lvl, ref lvl.loadOnGoto, "Load on goto: "); break;
|
||||
case "leaf":
|
||||
@ -118,17 +126,13 @@ namespace MCGalaxy.Commands.World {
|
||||
case "deletable":
|
||||
SetBool(p, lvl, ref lvl.Deletable, "Deletable: ");
|
||||
lvl.UpdateBlockPermissions(); break;
|
||||
|
||||
default:
|
||||
Player.Message(p, "Could not find option entered."); return;
|
||||
}
|
||||
lvl.changed = true;
|
||||
if (p != null && p.level != lvl) Player.Message(p, "/map finished!");
|
||||
}
|
||||
catch { Player.Message(p, "INVALID INPUT"); }
|
||||
Level.SaveSettings(lvl);
|
||||
}
|
||||
|
||||
void PrintMapInfo(Player p, Level lvl) {
|
||||
static void PrintMapInfo(Player p, Level lvl) {
|
||||
Player.Message(p, "MOTD: &b" + lvl.motd);
|
||||
Player.Message(p, "Finite mode: " + GetBool(lvl.finite));
|
||||
Player.Message(p, "Random flow: " + GetBool(lvl.randomFlow));
|
||||
@ -149,9 +153,8 @@ namespace MCGalaxy.Commands.World {
|
||||
Player.Message(p, "Deletable: " + GetBool(lvl.Deletable));
|
||||
}
|
||||
|
||||
void SetBool(Player p, Level lvl, ref bool target, string message, bool negate = false) {
|
||||
static void SetBool(Player p, Level lvl, ref bool target, string message, bool negate = false) {
|
||||
target = !target;
|
||||
Level.SaveSettings(lvl);
|
||||
bool display = negate ? !target : target;
|
||||
lvl.ChatLevel(message + GetBool(display));
|
||||
|
||||
@ -159,7 +162,7 @@ namespace MCGalaxy.Commands.World {
|
||||
Player.Message(p, message + GetBool(display, p == null));
|
||||
}
|
||||
|
||||
string GetBool(bool value, bool console = false) {
|
||||
static string GetBool(bool value, bool console = false) {
|
||||
return console ? (value ? "ON" : "OFF") : (value ? "&aON" : "&cOFF");
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user