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,
string typeName, string typeTitle) {
string type, string category) {
List<Command> cmds = new List<Command>();
foreach (Command c in Command.all.commands) {
string disabled = Command.GetDisabledReason(c.Enabled);
if (p == null || p.group.CanExecute(c) && disabled == null) {
if (!c.type.Contains(typeName) || c.name == null) continue;
if ((p == null || p.group.CanExecute(c)) && disabled == null) {
if (!c.type.Contains(type) || c.name == null) continue;
cmds.Add(c);
}
}
StringBuilder list = FormatCommands(cmds, sort);
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 {
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) + ".");
}
}

View File

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