PageRenderTime 111ms CodeModel.GetById 1ms RepoModel.GetById 1ms app.codeStats 1ms

/MCHmkCore/Commands/Information/CmdHelp.cs

https://bitbucket.org/LegoBricker/mchmok
C# | 241 lines | 187 code | 12 blank | 42 comment | 33 complexity | b9d9a81313b79af7065135b380bfe247 MD5 | raw file
  1. /*
  2. Copyright 2016 Jjp137
  3. This file has been changed from the original source code by MCForge.
  4. Dual-licensed under the Educational Community License, Version 2.0 and
  5. the GNU General Public License, Version 3 (the "Licenses"); you may
  6. not use this file except in compliance with the Licenses. You may
  7. obtain a copy of the Licenses at
  8. http://www.opensource.org/licenses/ecl2.php
  9. http://www.gnu.org/licenses/gpl-3.0.html
  10. Unless required by applicable law or agreed to in writing,
  11. software distributed under the Licenses are distributed on an "AS IS"
  12. BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
  13. or implied. See the Licenses for the specific language governing
  14. permissions and limitations under the Licenses.
  15. */
  16. /*
  17. Copyright © 2009-2014 MCSharp team (Modified for use with MCZall/MCLawl/MCForge/MCForge-Redux)
  18. Dual-licensed under the Educational Community License, Version 2.0 and
  19. the GNU General Public License, Version 3 (the "Licenses"); you may
  20. not use this file except in compliance with the Licenses. You may
  21. obtain a copy of the Licenses at
  22. http://www.opensource.org/licenses/ecl2.php
  23. http://www.gnu.org/licenses/gpl-3.0.html
  24. Unless required by applicable law or agreed to in writing,
  25. software distributed under the Licenses are distributed on an "AS IS"
  26. BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
  27. or implied. See the Licenses for the specific language governing
  28. permissions and limitations under the Licenses.
  29. */
  30. using System;
  31. using System.Collections.ObjectModel;
  32. namespace MCHmk.Commands {
  33. public class CmdHelp : Command {
  34. private ReadOnlyCollection<string> _keywords = Array.AsReadOnly<string>(
  35. new string[] {"info", "commands", "cmd", "list"});
  36. public override string Name {
  37. get {
  38. return "help";
  39. }
  40. }
  41. public override string Shortcut {
  42. get {
  43. return String.Empty;
  44. }
  45. }
  46. public override string Type {
  47. get {
  48. return "information";
  49. }
  50. }
  51. public override ReadOnlyCollection<string> Keywords {
  52. get {
  53. return _keywords;
  54. }
  55. }
  56. public override bool MuseumUsable {
  57. get {
  58. return true;
  59. }
  60. }
  61. public override int DefaultRank {
  62. get {
  63. return DefaultRankValue.Banned;
  64. }
  65. }
  66. public CmdHelp(Server s) : base(s) { }
  67. public override void Use(Player p, string args) {
  68. try {
  69. args = args.ToLower();
  70. switch (args) {
  71. case "":
  72. p.SendMessage("Use &b/help ranks" + _s.props.DefaultColor + " for a list of ranks.");
  73. p.SendMessage("Use &b/help build" + _s.props.DefaultColor + " for a list of building commands.");
  74. p.SendMessage("Use &b/help mod" + _s.props.DefaultColor + " for a list of moderation commands.");
  75. p.SendMessage("Use &b/help information" + _s.props.DefaultColor + " for a list of information commands.");
  76. p.SendMessage("Use &b/help other" + _s.props.DefaultColor + " for a list of other commands.");
  77. p.SendMessage("Use &b/help colors" + _s.props.DefaultColor + " to view the color codes.");
  78. p.SendMessage("Use &b/help syntax" + _s.props.DefaultColor + " for a guide to /help message syntax.");
  79. p.SendMessage("Use &b/help [command?] or /help [block?] " + _s.props.DefaultColor + "to view more info.");
  80. break;
  81. case "syntax":
  82. p.SendMessage("Help message syntax:");
  83. p.SendMessage("<> is used to represent required parameters.");
  84. p.SendMessage("[] is used to represent optional parameters.");
  85. p.SendMessage("? is used to represent items that need to be filled in with appropriate input.");
  86. p.SendMessage("Any parameters of the form <param1/param2> is a multiple choice parameter. Choose only one.");
  87. p.SendMessage("Example: /kick <player?> [reason?] - Player is required, but reason is optional.");
  88. break;
  89. case "ranks":
  90. args = String.Empty;
  91. foreach (Rank grp in _s.ranks) {
  92. if (grp.name != "nobody") { // Note that -1 means max undo. Undo anything and everything.
  93. p.SendMessage(grp.color + grp.name + " - &bCmd: " + grp.maxBlocks.ToString() + " - &2Undo: " + ((grp.maxUndo != -1) ? grp.maxUndo.ToString() : "max") + " - &cPerm: " + grp.Permission);
  94. }
  95. }
  96. break;
  97. case "build":
  98. args = String.Empty;
  99. foreach (Command comm in _s.commands) {
  100. if (p.IsConsole || _s.commands.CanExecute(p.rank.Permission, comm)) {
  101. if (comm.Type.Contains("build")) {
  102. args += ", " + getColor(comm.Name) + comm.Name;
  103. }
  104. }
  105. }
  106. if (args == String.Empty) {
  107. p.SendMessage("No commands of this type are available to you.");
  108. break;
  109. }
  110. p.SendMessage("Building commands you may use:");
  111. p.SendMessage(args.Remove(0, 2) + ".");
  112. break;
  113. case "mod":
  114. case "moderation":
  115. args = String.Empty;
  116. foreach (Command comm in _s.commands) {
  117. if (p.IsConsole || _s.commands.CanExecute(p.rank.Permission, comm)) {
  118. if (comm.Type.Contains("mod")) {
  119. args += ", " + getColor(comm.Name) + comm.Name;
  120. }
  121. }
  122. }
  123. if (args == String.Empty) {
  124. p.SendMessage("No commands of this type are available to you.");
  125. break;
  126. }
  127. p.SendMessage("Moderation commands you may use:");
  128. p.SendMessage(args.Remove(0, 2) + ".");
  129. break;
  130. case "information":
  131. args = String.Empty;
  132. foreach (Command comm in _s.commands) {
  133. if (p.IsConsole || _s.commands.CanExecute(p.rank.Permission, comm)) {
  134. if (comm.Type.Contains("info")) {
  135. args += ", " + getColor(comm.Name) + comm.Name;
  136. }
  137. }
  138. }
  139. if (args == String.Empty) {
  140. p.SendMessage("No commands of this type are available to you.");
  141. break;
  142. }
  143. p.SendMessage("Information commands you may use:");
  144. p.SendMessage(args.Remove(0, 2) + ".");
  145. break;
  146. case "other":
  147. args = String.Empty;
  148. foreach (Command comm in _s.commands) {
  149. if (p.IsConsole || _s.commands.CanExecute(p.rank.Permission, comm)) {
  150. if (comm.Type.Contains("other")) {
  151. args += ", " + getColor(comm.Name) + comm.Name;
  152. }
  153. }
  154. }
  155. if (args == String.Empty) {
  156. p.SendMessage("No commands of this type are available to you.");
  157. break;
  158. }
  159. p.SendMessage("Other commands you may use:");
  160. p.SendMessage(args.Remove(0, 2) + ".");
  161. break;
  162. case "colours":
  163. case "colors":
  164. p.SendMessage("&fTo use a color simply put a '%' sign symbol before you put the color code.");
  165. p.SendMessage("Colors Available:");
  166. p.SendMessage("0 - &0Black " + _s.props.DefaultColor + "| 8 - &8Gray");
  167. p.SendMessage("1 - &1Navy " + _s.props.DefaultColor + "| 9 - &9Blue");
  168. p.SendMessage("2 - &2Green " + _s.props.DefaultColor + "| a - &aLime");
  169. p.SendMessage("3 - &3Teal " + _s.props.DefaultColor + "| b - &bAqua");
  170. p.SendMessage("4 - &4Maroon " + _s.props.DefaultColor + "| c - &cRed");
  171. p.SendMessage("5 - &5Purple " + _s.props.DefaultColor + "| d - &dPink");
  172. p.SendMessage("6 - &6Gold " + _s.props.DefaultColor + "| e - &eYellow");
  173. p.SendMessage("7 - &7Silver " + _s.props.DefaultColor + "| f - &fWhite");
  174. break;
  175. default:
  176. Command cmd = _s.commands.FindCommand(args);
  177. if (cmd != null) {
  178. cmd.Help(p);
  179. string foundRank = _s.ranks.PermToName(_s.commands.FindPermByCommand(cmd).lowestRank);
  180. // If there is a shortcut for that command, print the shortcut;
  181. // otherwise, tell the user that there is none -Jjp137
  182. string shortcut = cmd.Shortcut != String.Empty ?
  183. "&b/" + cmd.Shortcut : "&8none";
  184. p.SendMessage("Rank needed: " + getColor(cmd.Name) + foundRank
  185. + _s.props.DefaultColor + " | Shortcut: " + shortcut);
  186. return;
  187. }
  188. BlockId b = BlockData.Ushort(args);
  189. if (b != BlockId.Null) {
  190. p.SendMessage("Block \"" + args + "\" appears as &b" + BlockData.Name(BlockData.Convert(b)));
  191. Rank foundRank = _s.ranks.FindPerm(_s.blockPerms.FindById(b).lowestRank);
  192. p.SendMessage("Rank needed: " + foundRank.color + foundRank.name);
  193. return;
  194. }
  195. p.SendMessage("Could not find command or block specified.");
  196. break;
  197. }
  198. }
  199. catch (Exception e) {
  200. _s.logger.ErrorLog(e);
  201. p.SendMessage("An error occured");
  202. }
  203. }
  204. private string getColor(string commName) {
  205. foreach (CommandList.CommandPerm aV in _s.commands.Perms) {
  206. if (aV.commandName == commName) {
  207. if (_s.ranks.FindPerm(aV.lowestRank) != null) {
  208. return _s.ranks.FindPerm(aV.lowestRank).color;
  209. }
  210. }
  211. }
  212. return "&f";
  213. }
  214. /// <summary>
  215. /// Called when /help is used on /help.
  216. /// </summary>
  217. /// <param name="p"> The player that used the /help command. </param>
  218. public override void Help(Player p) {
  219. p.SendMessage("...really? Wow. Just...wow.");
  220. }
  221. }
  222. }