diff --git a/ClassicalSharp/ClassicalSharp.csproj b/ClassicalSharp/ClassicalSharp.csproj index c6dcda5ca..d20c9c96f 100644 --- a/ClassicalSharp/ClassicalSharp.csproj +++ b/ClassicalSharp/ClassicalSharp.csproj @@ -146,7 +146,7 @@ - + @@ -222,8 +222,6 @@ - - diff --git a/ClassicalSharp/Commands/Command.cs b/ClassicalSharp/Commands/Command.cs deleted file mode 100644 index a51de1dd1..000000000 --- a/ClassicalSharp/Commands/Command.cs +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright 2014-2017 ClassicalSharp | Licensed under BSD-3 -using System; - -namespace ClassicalSharp.Commands { - - /// Represents a client side action that optionally accepts arguments. - public abstract class Command { - - /// Full command name, note that the user does not - /// have to fully type this into chat. - public string Name; - - /// Provides help about the purpose and syntax of this - /// command. Can use colour codes. - public string[] Help; - - protected internal Game game; - - public abstract void Execute(string[] args); - } -} diff --git a/ClassicalSharp/Commands/CommandList.cs b/ClassicalSharp/Commands/CommandList.cs index e3d72f3b8..93466a3bb 100644 --- a/ClassicalSharp/Commands/CommandList.cs +++ b/ClassicalSharp/Commands/CommandList.cs @@ -4,6 +4,16 @@ using System.Collections.Generic; namespace ClassicalSharp.Commands { + /// Represents a client side action that optionally accepts arguments. + public abstract class Command { + public string Name; + public string[] Help; + public bool SingleplayerOnly; + protected internal Game game; + + public abstract void Execute(string[] args); + } + public class CommandList : IGameComponent { const string prefix = "/client"; @@ -19,13 +29,10 @@ namespace ClassicalSharp.Commands { public List RegisteredCommands = new List(); public void Init(Game game) { this.game = game; - Register(new CommandsCommand()); Register(new GpuInfoCommand()); Register(new HelpCommand()); Register(new RenderTypeCommand()); Register(new ResolutionCommand()); - - if (!game.Server.IsSinglePlayer) return; Register(new ModelCommand()); Register(new CuboidCommand()); Register(new TeleportCommand()); @@ -38,11 +45,6 @@ namespace ClassicalSharp.Commands { public void Register(Command command) { command.game = game; - for (int i = 0; i < RegisteredCommands.Count; i++) { - Command cmd = RegisteredCommands[i]; - if (Utils.CaselessEquals(cmd.Name, command.Name)) - throw new InvalidOperationException("Another command already has name : " + command.Name); - } RegisteredCommands.Add(command); } @@ -59,8 +61,15 @@ namespace ClassicalSharp.Commands { match = cmd; } - if (match == null) + if (match == null) { game.Chat.Add("&e/client: Unrecognised command: \"&f" + cmdName + "&e\"."); + game.Chat.Add("&e/client: Type &a/client &efor a list of commands."); + return null; + } + if (match.SingleplayerOnly && !game.Server.IsSinglePlayer) { + game.Chat.Add("&e/client: \"&f" + cmdName + "&e\" can only be used in singleplayer."); + return null; + } return match; } @@ -75,7 +84,7 @@ namespace ClassicalSharp.Commands { if (text.Length == 0) { // only / or /client game.Chat.Add("&eList of client commands:"); PrintDefinedCommands(game); - game.Chat.Add("&eTo see a particular command's help, type /client help [cmd name]"); + game.Chat.Add("&eTo see a particular command's help, type &a/client help [cmd name]"); return; } @@ -110,4 +119,4 @@ namespace ClassicalSharp.Commands { RegisteredCommands.Clear(); } } -} +} \ No newline at end of file diff --git a/ClassicalSharp/Commands/SinglePlayerCommands.cs b/ClassicalSharp/Commands/Commands.cs similarity index 59% rename from ClassicalSharp/Commands/SinglePlayerCommands.cs rename to ClassicalSharp/Commands/Commands.cs index fa48388c2..948916813 100644 --- a/ClassicalSharp/Commands/SinglePlayerCommands.cs +++ b/ClassicalSharp/Commands/Commands.cs @@ -1,13 +1,13 @@ // Copyright 2014-2017 ClassicalSharp | Licensed under BSD-3 using System; using System.Collections.Generic; +using System.Drawing; using System.Text; using ClassicalSharp.Entities; using ClassicalSharp.Events; using ClassicalSharp.Renderers; -using OpenTK.Input; using OpenTK; - +using OpenTK.Input; #if USE16_BIT using BlockID = System.UInt16; #else @@ -16,6 +16,99 @@ using BlockID = System.Byte; namespace ClassicalSharp.Commands { + public sealed class HelpCommand : Command { + + public HelpCommand() { + Name = "Help"; + Help = new string[] { + "&a/client help [command name]", + "&eDisplays the help for the given command.", + }; + } + + public override void Execute(string[] args) { + if (args.Length == 1) { + game.Chat.Add("&eList of client commands:"); + game.CommandList.PrintDefinedCommands(game); + game.Chat.Add("&eTo see a particular command's help, type /client help [cmd name]"); + } else { + Command cmd = game.CommandList.GetMatch(args[1]); + if (cmd == null) return; + string[] help = cmd.Help; + for (int i = 0; i < help.Length; i++) + game.Chat.Add(help[i]); + } + } + } + + public sealed class GpuInfoCommand : Command { + + public GpuInfoCommand() { + Name = "GpuInfo"; + Help = new string[] { + "&a/client gpuinfo", + "&eDisplays information about your GPU.", + }; + } + + public override void Execute(string[] args) { + string[] lines = game.Graphics.ApiInfo; + for (int i = 0; i < lines.Length; i++) + game.Chat.Add("&a" + lines[i]); + } + } + + public sealed class RenderTypeCommand : Command { + + public RenderTypeCommand() { + Name = "RenderType"; + Help = new string[] { + "&a/client rendertype [normal/legacy/legacyfast]", + "&bnormal: &eDefault renderer, with all environmental effects enabled.", + "&blegacy: &eMay be slightly slower than normal, but produces the same environmental effects.", + "&blegacyfast: &eSacrifices clouds, fog and overhead sky for faster performance.", + "&bnormalfast: &eSacrifices clouds, fog and overhead sky for faster performance.", + }; + } + + public override void Execute(string[] args) { + if (args.Length == 1) { + game.Chat.Add("&e/client: &cYou didn't specify a new render type."); + } else if (game.SetRenderType(args[1])) { + game.Chat.Add("&e/client: &fRender type is now " + args[1] + "."); + } else { + game.Chat.Add("&e/client: &cUnrecognised render type &f\"" + args[1] + "\"&c."); + } + } + } + + public sealed class ResolutionCommand : Command { + + public ResolutionCommand() { + Name = "Resolution"; + Help = new string[] { + "&a/client resolution [width] [height]", + "&ePrecisely sets the size of the rendered window.", + }; + } + + public override void Execute(string[] args) { + int width, height; + if (args.Length < 3) { + game.Chat.Add("&e/client: &cYou didn't specify width and height"); + } else if (!Int32.TryParse(args[1], out width) || !Int32.TryParse(args[2], out height)) { + game.Chat.Add("&e/client: &cWidth and height must be integers."); + } else if (width <= 0 || height <= 0) { + game.Chat.Add("&e/client: &cWidth and height must be above 0."); + } else { + game.window.ClientSize = new Size(width, height); + Options.Set(OptionsKey.WindowWidth, width); + Options.Set(OptionsKey.WindowHeight, height); + } + } + } + + public sealed class ModelCommand : Command { public ModelCommand() { @@ -25,6 +118,7 @@ namespace ClassicalSharp.Commands { "&bnames: &echibi, chicken, creeper, human, pig, sheep", "&e skeleton, spider, zombie, sitting, ", }; + SingleplayerOnly = true; } public override void Execute(string[] args) { @@ -47,6 +141,7 @@ namespace ClassicalSharp.Commands { "&e If persist is given and is \"yes\", then the command", "&e will repeatedly cuboid, without needing to be typed in again.", }; + SingleplayerOnly = true; } int block = -1; Vector3I mark1, mark2; @@ -126,11 +221,12 @@ namespace ClassicalSharp.Commands { public sealed class TeleportCommand : Command { public TeleportCommand() { - Name = "Teleport"; + Name = "TP"; Help = new string[] { - "&a/client teleport [x y z]", + "&a/client tp [x y z]", "&eMoves you to the given coordinates.", }; + SingleplayerOnly = true; } public override void Execute(string[] args) { @@ -151,4 +247,4 @@ namespace ClassicalSharp.Commands { } } } -} +} \ No newline at end of file diff --git a/ClassicalSharp/Commands/DefaultCommands.cs b/ClassicalSharp/Commands/DefaultCommands.cs deleted file mode 100644 index b1b234ca0..000000000 --- a/ClassicalSharp/Commands/DefaultCommands.cs +++ /dev/null @@ -1,120 +0,0 @@ -// Copyright 2014-2017 ClassicalSharp | Licensed under BSD-3 -using System; -using System.Collections.Generic; -using System.Drawing; -using System.Text; -using ClassicalSharp.Renderers; -using OpenTK.Input; - -namespace ClassicalSharp.Commands { - - /// Command that displays the list of all currently registered client commands. - public sealed class CommandsCommand : Command { - - public CommandsCommand() { - Name = "Commands"; - Help = new string[] { - "&a/client commands", - "&ePrints a list of all usable commands" - }; - } - - public override void Execute(string[] args) { - game.CommandList.PrintDefinedCommands(game); - } - } - - /// Command that displays information about an input client command. - public sealed class HelpCommand : Command { - - public HelpCommand() { - Name = "Help"; - Help = new string[] { - "&a/client help [command name]", - "&eDisplays the help for the given command.", - }; - } - - public override void Execute(string[] args) { - if (args.Length == 1) { - game.Chat.Add("&eList of client commands:"); - game.CommandList.PrintDefinedCommands(game); - game.Chat.Add("&eTo see a particular command's help, type /client help [cmd name]"); - } else { - Command cmd = game.CommandList.GetMatch(args[1]); - if (cmd == null) return; - string[] help = cmd.Help; - for (int i = 0; i < help.Length; i++) - game.Chat.Add(help[i]); - } - } - } - - /// Command that displays information about the user's GPU. - public sealed class GpuInfoCommand : Command { - - public GpuInfoCommand() { - Name = "GpuInfo"; - Help = new string[] { - "&a/client gpuinfo", - "&eDisplays information about your GPU.", - }; - } - - public override void Execute(string[] args) { - string[] lines = game.Graphics.ApiInfo; - for (int i = 0; i < lines.Length; i++) - game.Chat.Add("&a" + lines[i]); - } - } - - public sealed class RenderTypeCommand : Command { - - public RenderTypeCommand() { - Name = "RenderType"; - Help = new string[] { - "&a/client rendertype [normal/legacy/legacyfast]", - "&bnormal: &eDefault renderer, with all environmental effects enabled.", - "&blegacy: &eMay be slightly slower than normal, but produces the same environmental effects.", - "&blegacyfast: &eSacrifices clouds, fog and overhead sky for faster performance.", - "&bnormalfast: &eSacrifices clouds, fog and overhead sky for faster performance.", - }; - } - - public override void Execute(string[] args) { - if (args.Length == 1) { - game.Chat.Add("&e/client: &cYou didn't specify a new render type."); - } else if (game.SetRenderType(args[1])) { - game.Chat.Add("&e/client: &fRender type is now " + args[1] + "."); - } else { - game.Chat.Add("&e/client: &cUnrecognised render type &f\"" + args[1] + "\"&c."); - } - } - } - - public sealed class ResolutionCommand : Command { - - public ResolutionCommand() { - Name = "Resolution"; - Help = new string[] { - "&a/client resolution [width] [height]", - "&ePrecisely sets the size of the rendered window.", - }; - } - - public override void Execute(string[] args) { - int width, height; - if (args.Length < 3) { - game.Chat.Add("&e/client: &cYou didn't specify width and height"); - } else if (!Int32.TryParse(args[1], out width) || !Int32.TryParse(args[2], out height)) { - game.Chat.Add("&e/client: &cWidth and height must be integers."); - } else if (width <= 0 || height <= 0) { - game.Chat.Add("&e/client: &cWidth and height must be above 0."); - } else { - game.window.ClientSize = new Size(width, height); - Options.Set(OptionsKey.WindowWidth, width); - Options.Set(OptionsKey.WindowHeight, height); - } - } - } -}