First attempt at cleaning up /map.

This commit is contained in:
UnknownShadow200 2016-07-17 22:11:34 +10:00
parent 171dcfed8f
commit d5ca11caf1

View File

@ -14,7 +14,7 @@
BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
or implied. See the Licenses for the specific language governing or implied. See the Licenses for the specific language governing
permissions and limitations under the Licenses. permissions and limitations under the Licenses.
*/ */
namespace MCGalaxy.Commands.World { namespace MCGalaxy.Commands.World {
public sealed class CmdMap : Command { public sealed class CmdMap : Command {
public override string name { get { return "map"; } } public override string name { get { return "map"; } }
@ -29,61 +29,38 @@ namespace MCGalaxy.Commands.World {
get { return new[] { new CommandAlias("ps", "ps") }; } get { return new[] { new CommandAlias("ps", "ps") }; }
} }
public override void Use(Player p, string message) public override void Use(Player p, string message) {
{
if (message == "") message = p.level.name; if (message == "") message = p.level.name;
Level lvl; Level lvl;
string[] parts = message.SplitSpaces(3);
string opt = parts[0].ToLower();
string value = "";
if (message.IndexOf(' ') == -1) if (parts.Length == 1) {
{ lvl = LevelInfo.Find(opt);
lvl = LevelInfo.Find(message); if (lvl == null) {
if (lvl == null) if (p != null) lvl = p.level;
{ } else {
if (p != null) PrintMapInfo(p, lvl); return;
}
} else {
lvl = LevelInfo.Find(opt);
if (lvl == null || opt == "ps" || opt == "rp") {
lvl = p.level; lvl = p.level;
value = parts[1];
} else {
opt = parts[1];
value = parts.Length > 2 ? parts[2] : "";
} }
else
{
Player.Message(p, "MOTD: &b" + lvl.motd);
Player.Message(p, "Finite mode: " + GetBool(lvl.finite));
Player.Message(p, "Random flow: " + GetBool(lvl.randomFlow));
Player.Message(p, "Animal AI: " + GetBool(lvl.ai));
Player.Message(p, "Edge water: " + GetBool(lvl.edgeWater));
Player.Message(p, "Grass growing: " + GetBool(lvl.GrassGrow));
Player.Message(p, "Tree growing: " + GetBool(lvl.growTrees));
Player.Message(p, "Leaf decay: " + GetBool(lvl.leafDecay));
Player.Message(p, "Physics speed: &b" + lvl.speedPhysics);
Player.Message(p, "Physics overload: &b" + lvl.overload);
Player.Message(p, "Survival death: " + GetBool(lvl.Death) + "(Fall: " + lvl.fall + ", Drown: " + lvl.drown + ")");
Player.Message(p, "Killer blocks: " + GetBool(lvl.Killer));
Player.Message(p, "Unload: " + GetBool(lvl.unload));
Player.Message(p, "Load on /goto: " + GetBool(lvl.loadOnGoto));
Player.Message(p, "Roleplay (level only) chat: " + GetBool(!lvl.worldChat));
Player.Message(p, "Guns: " + GetBool(lvl.guns));
Player.Message(p, "Buildable: " + GetBool(lvl.Buildable));
Player.Message(p, "Deletable: " + GetBool(lvl.Deletable));
return;
}
}
else
{
lvl = LevelInfo.Find(message.Split(' ')[0]);
if (lvl == null || message.Split(' ')[0].ToLower() == "ps" || message.Split(' ')[0].ToLower() == "rp") lvl = p.level;
else message = message.Substring(message.IndexOf(' ') + 1);
} }
if (!CheckExtraPerm(p)) { MessageNeedExtra(p, "can set map options."); return; } if (!CheckExtraPerm(p)) { MessageNeedExtra(p, "can set map options."); return; }
string foundStart; try {
if (message.IndexOf(' ') == -1) foundStart = message.ToLower();
else foundStart = message.Split(' ')[0].ToLower();
try
{
if (lvl == null) Player.Message(p, "derp"); if (lvl == null) Player.Message(p, "derp");
switch (foundStart) switch (opt) {
{ case "theme":
case "theme": lvl.theme = message.Substring(message.IndexOf(' ') + 1); lvl.ChatLevel("Map theme: &b" + lvl.theme); break; lvl.theme = value;
lvl.ChatLevel("Map theme: &b" + lvl.theme); break;
case "finite": case "finite":
SetBool(p, lvl, ref lvl.finite, "Finite mode: "); break; SetBool(p, lvl, ref lvl.finite, "Finite mode: "); break;
case "ai": case "ai":
@ -94,27 +71,30 @@ namespace MCGalaxy.Commands.World {
SetBool(p, lvl, ref lvl.GrassGrow, "Growing grass: "); break; SetBool(p, lvl, ref lvl.GrassGrow, "Growing grass: "); break;
case "ps": case "ps":
case "physicspeed": case "physicspeed":
if (int.Parse(message.Split(' ')[1]) < 10) { Player.Message(p, "Cannot go below 10"); return; } if (int.Parse(value) < 10) { Player.Message(p, "Cannot go below 10"); return; }
lvl.speedPhysics = int.Parse(message.Split(' ')[1]); lvl.speedPhysics = int.Parse(value);
lvl.ChatLevel("Physics speed: &b" + lvl.speedPhysics); lvl.ChatLevel("Physics speed: &b" + lvl.speedPhysics);
break; break;
case "overload": case "overload":
if (int.Parse(message.Split(' ')[1]) < 500) { Player.Message(p, "Cannot go below 500 (default is 1500)"); return; } if (int.Parse(value) < 500) { Player.Message(p, "Cannot go below 500 (default is 1500)"); return; }
if (p != null && p.Rank < LevelPermission.Admin && int.Parse(message.Split(' ')[1]) > 2500) { Player.Message(p, "Only SuperOPs may set higher than 2500"); return; } if (p != null && p.Rank < LevelPermission.Admin && int.Parse(value) > 2500) { Player.Message(p, "Only SuperOPs may set higher than 2500"); return; }
lvl.overload = int.Parse(message.Split(' ')[1]); lvl.overload = int.Parse(value);
lvl.ChatLevel("Physics overload: &b" + lvl.overload); lvl.ChatLevel("Physics overload: &b" + lvl.overload);
break; break;
case "motd": case "motd":
if (message.Split(' ').Length == 1) lvl.motd = "ignore"; lvl.motd = value == "" ? "ignore" : value;
else lvl.motd = message.Substring(message.IndexOf(' ') + 1);
lvl.ChatLevel("Map's MOTD was changed to: &b" + lvl.motd); lvl.ChatLevel("Map's MOTD was changed to: &b" + lvl.motd);
break; break;
case "death": case "death":
SetBool(p, lvl, ref lvl.Death, "Survival death: "); break; SetBool(p, lvl, ref lvl.Death, "Survival death: "); break;
case "killer": case "killer":
SetBool(p, lvl, ref lvl.Killer, "Killer blocks: "); break; SetBool(p, lvl, ref lvl.Killer, "Killer blocks: "); break;
case "fall": lvl.fall = int.Parse(message.Split(' ')[1]); lvl.ChatLevel("Fall distance: &b" + lvl.fall); break; case "fall":
case "drown": lvl.drown = int.Parse(message.Split(' ')[1]); lvl.ChatLevel("Drown time: &b" + ((float)lvl.drown / 10)); break; lvl.fall = int.Parse(value);
lvl.ChatLevel("Fall distance: &b" + lvl.fall); break;
case "drown":
lvl.drown = int.Parse(value);
lvl.ChatLevel("Drown time: &b" + ((float)lvl.drown / 10)); break;
case "unload": case "unload":
SetBool(p, lvl, ref lvl.unload, "Auto unload: "); break; SetBool(p, lvl, ref lvl.unload, "Auto unload: "); break;
case "chat": case "chat":
@ -148,14 +128,35 @@ namespace MCGalaxy.Commands.World {
catch { Player.Message(p, "INVALID INPUT"); } catch { Player.Message(p, "INVALID INPUT"); }
} }
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));
Player.Message(p, "Animal AI: " + GetBool(lvl.ai));
Player.Message(p, "Edge water: " + GetBool(lvl.edgeWater));
Player.Message(p, "Grass growing: " + GetBool(lvl.GrassGrow));
Player.Message(p, "Tree growing: " + GetBool(lvl.growTrees));
Player.Message(p, "Leaf decay: " + GetBool(lvl.leafDecay));
Player.Message(p, "Physics speed: &b" + lvl.speedPhysics);
Player.Message(p, "Physics overload: &b" + lvl.overload);
Player.Message(p, "Survival death: " + GetBool(lvl.Death) + "(Fall: " + lvl.fall + ", Drown: " + lvl.drown + ")");
Player.Message(p, "Killer blocks: " + GetBool(lvl.Killer));
Player.Message(p, "Unload: " + GetBool(lvl.unload));
Player.Message(p, "Load on /goto: " + GetBool(lvl.loadOnGoto));
Player.Message(p, "Roleplay (level only) chat: " + GetBool(!lvl.worldChat));
Player.Message(p, "Guns: " + GetBool(lvl.guns));
Player.Message(p, "Buildable: " + GetBool(lvl.Buildable));
Player.Message(p, "Deletable: " + GetBool(lvl.Deletable));
}
void SetBool(Player p, Level lvl, ref bool target, string message, bool negate = false) { void SetBool(Player p, Level lvl, ref bool target, string message, bool negate = false) {
target = !target; target = !target;
Level.SaveSettings(lvl); Level.SaveSettings(lvl);
bool display = negate ? !target : target; bool display = negate ? !target : target;
lvl.ChatLevel(message + GetBool(display)); lvl.ChatLevel(message + GetBool(display));
if (p == null) if (p == null || p.level != lvl)
Player.Message(p, message + GetBool(display, true)); Player.Message(p, message + GetBool(display, p == null));
} }
string GetBool(bool value, bool console = false) { string GetBool(bool value, bool console = false) {