From 8ad0f8632b2629622ae5944f696ed96dd0fe0a95 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Fri, 1 Jun 2018 15:13:34 +1000 Subject: [PATCH] Make command aliases more flexible --- MCGalaxy/Commands/Alias.cs | 15 +++++---- MCGalaxy/Commands/Information/CmdTop.cs | 40 ++++++++--------------- MCGalaxy/Commands/building/CmdTriangle.cs | 2 +- MCGalaxy/Player/Player.cs | 3 +- 4 files changed, 24 insertions(+), 36 deletions(-) diff --git a/MCGalaxy/Commands/Alias.cs b/MCGalaxy/Commands/Alias.cs index 9319db881..88a2e423e 100644 --- a/MCGalaxy/Commands/Alias.cs +++ b/MCGalaxy/Commands/Alias.cs @@ -21,9 +21,6 @@ using System.IO; namespace MCGalaxy.Commands { - /// Describes an alias so that when the user types /trigger, - /// it is treated as /target <args given by user> - /// Note \"target\" can be in the form of either "cmdname" or "cmdname args". public class Alias { public static List coreAliases = new List(); @@ -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 ."); + 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 "); + sw.WriteLine("# trigger : command [prefix]"); + sw.WriteLine("# e.g. \"xyz : help me\" means /xyz is treated as /help me "); + sw.WriteLine("# trigger : command {args}"); + sw.WriteLine("# e.g. \"mod : setrank {args} mod \" means /mod is treated as /setrank mod"); foreach (Alias a in aliases) { if (a.Format == null) { @@ -71,7 +72,7 @@ namespace MCGalaxy.Commands { } else { sw.WriteLine(a.Trigger + " : " + a.Target + " " + a.Format); } - } + } } } diff --git a/MCGalaxy/Commands/Information/CmdTop.cs b/MCGalaxy/Commands/Information/CmdTop.cs index 0e984de75..5715de4fe 100644 --- a/MCGalaxy/Commands/Information/CmdTop.cs +++ b/MCGalaxy/Commands/Information/CmdTop.cs @@ -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; - - TopStat stat = FindTopStat(args[0]); + int maxResults = 0, offset = 0; + if (!CommandParser.GetInt(p, args[0], "Max results", ref maxResults, 1, 15)) return; + + 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] [number of players to show] "); + Player.Message(p, "%T/Top [max results] [stat] "); 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)); diff --git a/MCGalaxy/Commands/building/CmdTriangle.cs b/MCGalaxy/Commands/building/CmdTriangle.cs index 24e1181e7..ca7359dfd 100644 --- a/MCGalaxy/Commands/building/CmdTriangle.cs +++ b/MCGalaxy/Commands/building/CmdTriangle.cs @@ -26,7 +26,7 @@ namespace MCGalaxy.Commands.Building { protected override int MarksCount { get { return 3; } } protected override string PlaceMessage { get { return "Place three blocks to determine the edges."; } } - protected override DrawOp GetDrawOp(DrawArgs dArgs) { return new TriangleDrawOp(); } + protected override DrawOp GetDrawOp(DrawArgs dArgs) { return new TriangleDrawOp(); } public override void Help(Player p) { Player.Message(p, "%T/Triangle "); diff --git a/MCGalaxy/Player/Player.cs b/MCGalaxy/Player/Player.cs index 5d9446fac..4488a97cd 100644 --- a/MCGalaxy/Player/Player.cs +++ b/MCGalaxy/Player/Player.cs @@ -94,10 +94,11 @@ namespace MCGalaxy { public override bool CanSeeEntity(Entity other) { Player target = other as Player; - if (target == null) return true; // not a player + if (target == null) return true; // not a player 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;