mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-24 05:03:34 -04:00
Make command aliases more flexible
This commit is contained in:
parent
131ffb36ee
commit
8ad0f8632b
@ -21,9 +21,6 @@ using System.IO;
|
||||
|
||||
namespace MCGalaxy.Commands {
|
||||
|
||||
/// <summary> Describes an alias so that when the user types /trigger,
|
||||
/// it is treated as /target <args given by user> </summary>
|
||||
/// <remarks>Note \"target\" can be in the form of either "cmdname" or "cmdname args".</remarks>
|
||||
public class Alias {
|
||||
|
||||
public static List<Alias> coreAliases = new List<Alias>();
|
||||
@ -61,9 +58,13 @@ namespace MCGalaxy.Commands {
|
||||
|
||||
public static void Save() {
|
||||
using (StreamWriter sw = new StreamWriter(Paths.AliasesFile)) {
|
||||
sw.WriteLine("# The format goes trigger : command");
|
||||
sw.WriteLine("# For example, \"y : help me\" means that when /y is typed,");
|
||||
sw.WriteLine("# it is treated as /Help me <args given by user>.");
|
||||
sw.WriteLine("# Aliases can be in one of three formats:");
|
||||
sw.WriteLine("# trigger : command");
|
||||
sw.WriteLine("# e.g. \"xyz : help\" means /xyz is treated as /help <args given by user>");
|
||||
sw.WriteLine("# trigger : command [prefix]");
|
||||
sw.WriteLine("# e.g. \"xyz : help me\" means /xyz is treated as /help me <args given by user>");
|
||||
sw.WriteLine("# trigger : command {args}");
|
||||
sw.WriteLine("# e.g. \"mod : setrank {args} mod \" means /mod is treated as /setrank <args given by user> mod");
|
||||
|
||||
foreach (Alias a in aliases) {
|
||||
if (a.Format == null) {
|
||||
|
@ -26,25 +26,27 @@ namespace MCGalaxy.Commands.Info {
|
||||
public override string shortcut { get { return "Most"; } }
|
||||
public override string type { get { return CommandTypes.Information; } }
|
||||
public override CommandAlias[] Aliases {
|
||||
get { return new [] { new CommandAlias("TopTen", "{args} 10"), new CommandAlias("TopFive", "{args} 5"),
|
||||
new CommandAlias("Top10", "{args} 10"), }; }
|
||||
get { return new [] { new CommandAlias("TopTen", "10"), new CommandAlias("TopFive", "5"),
|
||||
new CommandAlias("Top10", "10"), }; }
|
||||
}
|
||||
|
||||
public override void Use(Player p, string message) {
|
||||
string[] args = message.SplitSpaces();
|
||||
if (args.Length < 2) { Help(p); return; }
|
||||
|
||||
int offset = ParseOffset(p, args);
|
||||
int limit = ParseLimit(p, args);
|
||||
if (limit == -1 || offset == -1) return;
|
||||
int maxResults = 0, offset = 0;
|
||||
if (!CommandParser.GetInt(p, args[0], "Max results", ref maxResults, 1, 15)) return;
|
||||
|
||||
TopStat stat = FindTopStat(args[0]);
|
||||
TopStat stat = FindTopStat(args[1]);
|
||||
if (stat == null) {
|
||||
Player.Message(p, "/Top: Unrecognised type \"{0}\".", args[0]);
|
||||
return;
|
||||
Player.Message(p, "/Top: Unrecognised type \"{0}\".", args[1]); return;
|
||||
}
|
||||
|
||||
string strLimit = " LIMIT " + offset + "," + limit;
|
||||
if (args.Length > 2) {
|
||||
if (!CommandParser.GetInt(p, args[2], "Offset", ref offset, 0)) return;
|
||||
}
|
||||
|
||||
string strLimit = " LIMIT " + offset + "," + maxResults;
|
||||
DataTable db = Database.Backend.GetRows(stat.Table, "DISTINCT Name, " + stat.Column,
|
||||
"ORDER BY" + stat.OrderBy + strLimit);
|
||||
|
||||
@ -57,22 +59,6 @@ namespace MCGalaxy.Commands.Info {
|
||||
db.Dispose();
|
||||
}
|
||||
|
||||
static int ParseLimit(Player p, string[] args) {
|
||||
int limit = 0;
|
||||
string limitArg = args[args.Length - 1];
|
||||
|
||||
if (!CommandParser.GetInt(p, limitArg, "Limit", ref limit, 1, 15)) return -1;
|
||||
return limit;
|
||||
}
|
||||
|
||||
static int ParseOffset(Player p, string[] args) {
|
||||
if (args.Length <= 2) return 0;
|
||||
int offset = 0;
|
||||
|
||||
if (!CommandParser.GetInt(p, args[1], "Offset", ref offset, 0)) return -1;
|
||||
return offset;
|
||||
}
|
||||
|
||||
static TopStat FindTopStat(string input) {
|
||||
foreach (TopStat stat in TopStat.Stats) {
|
||||
if (stat.Identifier.CaselessEq(input)) return stat;
|
||||
@ -88,7 +74,7 @@ namespace MCGalaxy.Commands.Info {
|
||||
}
|
||||
|
||||
public override void Help(Player p) {
|
||||
Player.Message(p, "%T/Top [stat] <offset> [number of players to show] ");
|
||||
Player.Message(p, "%T/Top [max results] [stat] <offset>");
|
||||
Player.Message(p, "%HPrints a list of players who have the " +
|
||||
"most/top of a particular stat. Available stats:");
|
||||
Player.Message(p, "&f" + TopStat.Stats.Join(stat => stat.Identifier));
|
||||
|
@ -98,6 +98,7 @@ namespace MCGalaxy {
|
||||
if (target == this) return true; // always see self
|
||||
|
||||
// hidden via /hide or /ohide
|
||||
// TODO: Just use Entities.CanSee
|
||||
if (target.hidden) {
|
||||
if (target.otherRankHidden) return Rank >= target.oHideRank;
|
||||
return Rank >= target.Rank;
|
||||
|
Loading…
x
Reference in New Issue
Block a user