Cleanup /waypoint.

This commit is contained in:
UnknownShadow200 2016-07-04 14:17:24 +10:00
parent 175e9c14e0
commit 859b66a4fc
2 changed files with 64 additions and 99 deletions

View File

@ -143,21 +143,21 @@ namespace MCGalaxy.Commands {
} }
static void PrintHelpForGroup(Player p, string sort, static void PrintHelpForGroup(Player p, string sort,
string typeName, string typeTitle) { string type, string category) {
List<Command> cmds = new List<Command>(); List<Command> cmds = new List<Command>();
foreach (Command c in Command.all.commands) { foreach (Command c in Command.all.commands) {
string disabled = Command.GetDisabledReason(c.Enabled); string disabled = Command.GetDisabledReason(c.Enabled);
if (p == null || p.group.CanExecute(c) && disabled == null) { if ((p == null || p.group.CanExecute(c)) && disabled == null) {
if (!c.type.Contains(typeName) || c.name == null) continue; if (!c.type.Contains(type) || c.name == null) continue;
cmds.Add(c); cmds.Add(c);
} }
} }
StringBuilder list = FormatCommands(cmds, sort); StringBuilder list = FormatCommands(cmds, sort);
if (list.Length == 0) { if (list.Length == 0) {
Player.Message(p, "You cannot use any of the " + typeTitle + " commands."); Player.Message(p, "You cannot use any of the " + category + " commands.");
} else { } else {
Player.Message(p, typeTitle + " commands you may use:"); Player.Message(p, category + " commands you may use:");
Player.Message(p, list.ToString(2, list.Length - 2) + "."); Player.Message(p, list.ToString(2, list.Length - 2) + ".");
} }
} }

View File

@ -1,25 +1,24 @@
/* /*
Copyright 2010 MCSharp team (Modified for use with MCZall/MCLawl/MCGalaxy) Copyright 2010 MCSharp team (Modified for use with MCZall/MCLawl/MCGalaxy)
Dual-licensed under the Educational Community License, Version 2.0 and Dual-licensed under the Educational Community License, Version 2.0 and
the GNU General Public License, Version 3 (the "Licenses"); you may the GNU General Public License, Version 3 (the "Licenses"); you may
not use this file except in compliance with the Licenses. You may not use this file except in compliance with the Licenses. You may
obtain a copy of the Licenses at obtain a copy of the Licenses at
http://www.opensource.org/licenses/ecl2.php http://www.opensource.org/licenses/ecl2.php
http://www.gnu.org/licenses/gpl-3.0.html http://www.gnu.org/licenses/gpl-3.0.html
Unless required by applicable law or agreed to in writing, Unless required by applicable law or agreed to in writing,
software distributed under the Licenses are distributed on an "AS IS" software distributed under the Licenses are distributed on an "AS IS"
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.
*/ */
using System; using System;
namespace MCGalaxy.Commands
{ namespace MCGalaxy.Commands {
public sealed class CmdWaypoint : Command public sealed class CmdWaypoint : Command {
{
public override string name { get { return "waypoint"; } } public override string name { get { return "waypoint"; } }
public override string shortcut { get { return "wp"; } } public override string shortcut { get { return "wp"; } }
public override string type { get { return CommandTypes.Other; } } public override string type { get { return CommandTypes.Other; } }
@ -27,87 +26,53 @@ namespace MCGalaxy.Commands
public override LevelPermission defaultRank { get { return LevelPermission.Builder; } } public override LevelPermission defaultRank { get { return LevelPermission.Builder; } }
public CmdWaypoint() { } public CmdWaypoint() { }
public override void Use(Player p, string message) public override void Use(Player p, string message) {
{ if (Player.IsSuper(p)) { MessageInGameOnly(p); return; }
if (p == null) { MessageInGameOnly(p); return; } string[] args = message.ToLower().Split(' ');
string[] command = message.ToLower().Split(' '); string cmd = args[0];
string cmd = String.Empty; if (cmd == "") { Help(p); return; }
string par1 = String.Empty;
try if (args.Length == 1 && cmd == "list") {
{
cmd = command[0].ToLower();
par1 = command[1];
}
catch { }
if (cmd == "create" || cmd == "new" || cmd == "add")
{
if (!p.Waypoints.Exists(par1))
{
p.Waypoints.Create(par1, p);
Player.Message(p, "Created waypoint");
return;
}
else { Player.Message(p, "That waypoint already exists"); return; }
}
else if (cmd == "goto")
{
if (p.Waypoints.Exists(par1))
{
p.Waypoints.Goto(par1, p);
return;
}
else { Player.Message(p, "That waypoint doesn't exist"); return; }
}
else if (cmd == "replace" || cmd == "update" || cmd == "edit")
{
if (p.Waypoints.Exists(par1))
{
p.Waypoints.Update(par1, p);
Player.Message(p, "Updated waypoint");
return;
}
else { Player.Message(p, "That waypoint doesn't exist"); return; }
}
else if (cmd == "delete" || cmd == "remove")
{
if (p.Waypoints.Exists(par1))
{
p.Waypoints.Remove(par1, p);
Player.Message(p, "Deleted waypoint");
return;
}
else { Player.Message(p, "That waypoint doesn't exist"); return; }
}
else if (cmd == "list")
{
Player.Message(p, "Waypoints:"); Player.Message(p, "Waypoints:");
foreach (Warp wp in p.Waypoints.Items) foreach (Warp wp in p.Waypoints.Items) {
{
if (LevelInfo.FindExact(wp.lvlname) != null) if (LevelInfo.FindExact(wp.lvlname) != null)
{ Player.Message(p, wp.name + " : " + wp.lvlname);
Player.Message(p, wp.name + ":" + wp.lvlname);
}
} }
return; return;
} else if (args.Length == 1) {
if (!p.Waypoints.Exists(cmd)) { Player.Message(p, "That waypoint does not exist"); return; }
p.Waypoints.Goto(cmd, p);
return;
} }
else
{ string name = args[1];
if (p.Waypoints.Exists(cmd)) if (cmd == "create" || cmd == "new" || cmd == "add") {
{ if (p.Waypoints.Exists(name)) { Player.Message(p, "That waypoint already exists"); return; }
p.Waypoints.Goto(cmd, p); p.Waypoints.Create(name, p);
return; Player.Message(p, "Created waypoint");
} } else if (cmd == "goto") {
else { Player.Message(p, "That waypoint or command doesn't exist"); return; } if (!p.Waypoints.Exists(name)) { Player.Message(p, "That waypoint does not exist"); return; }
p.Waypoints.Goto(name, p);
} else if (cmd == "replace" || cmd == "update" || cmd == "edit") {
if (!p.Waypoints.Exists(name)) { Player.Message(p, "That waypoint does not exist"); return; }
p.Waypoints.Update(name, p);
Player.Message(p, "Updated waypoint");
} else if (cmd == "delete" || cmd == "remove") {
if (!p.Waypoints.Exists(name)) { Player.Message(p, "That waypoint does not exist"); return; }
p.Waypoints.Remove(name, p);
Player.Message(p, "Deleted waypoint");
} else {
Help(p);
} }
} }
public override void Help(Player p)
{ public override void Help(Player p) {
Player.Message(p, "/waypoint [create] [name] - Create a new waypoint"); Player.Message(p, "%T/waypoint create [name] %H- Create a new waypoint");
Player.Message(p, "/waypoint [update] [name] - Update a waypoint"); Player.Message(p, "%T/waypoint update [name] %H- Update a waypoint");
Player.Message(p, "/waypoint [remove] [name] - Remove a waypoint"); Player.Message(p, "%T/waypoint remove [name] %H- Remove a waypoint");
Player.Message(p, "/waypoint [list] - Shows a list of waypoints"); Player.Message(p, "%T/waypoint list %H- Shows a list of waypoints");
Player.Message(p, "/waypoint [goto] [name] - Goto a waypoint"); Player.Message(p, "%T/waypoint goto [name] %H- Goto a waypoint");
Player.Message(p, "/waypoint [name] - Goto a waypoint"); Player.Message(p, "%T/waypoint [name] %H- Goto a waypoint");
} }
} }
} }