public override void Execute(ICommandSender sender, string label, string[] args, string origMessage) { if (sender.IsPlayer()) { if (args.Length == 0) { sender.SendChat("Your current gamemode is [" + ((Player)sender).Gamemode + "]", TextColor.Gray); } else if (args.Length >= 1) { switch (args[0].ToLower()) { case "0": case "s": case "survival": ((Player)sender).SetGamemode(Gamemode.Survival); break; case "3": case "sp": case "spectator": ((Player)sender).SetGamemode(Gamemode.Spectator); break; case "2": case "a": case "adventure": ((Player)sender).SetGamemode(Gamemode.Adventure); break; default: ((Player)sender).SetGamemode(Gamemode.Creative); break; } } sender.SendChat($"Set your gamemode to [{((Player) sender).Gamemode}]", TextColor.Green); } else { ConsoleFunctions.WriteInfoLine("Cannot change gamemode through console."); } }
public override void Execute(ICommandSender sender, string label, string[] args, string origMessage) { if (sender.IsPlayer()) { var player = (Player)sender; if (args.Length == 0) { sender.SendChat($"Current level: {player.Level.LvlName}"); return; } var level = Globals.LevelManager.GetLevel(args[0]); if (level == null) { sender.SendChat("That level doesn't exist!", TextColor.Red); return; } Globals.LevelManager.TeleportToLevel(player, level); } else { ConsoleFunctions.WriteInfoLine("Cannot teleport console."); } }
public override void Execute(ICommandSender sender, string label, string[] args, string origMessage) { if (sender.IsPlayer()) { var player = (Player)sender; if (args.Length != 3 && args.Length != 5) { SendUsage(sender, label); return; } //player.Teleport(new PlayerLocation(player.KnownPosition.X, 80, player.KnownPosition.Z)); //todo: ~ is relative then get int from arg and tell player if it's not a number var rotation = args.Length == 5; var relX = args[0].StartsWith("~"); var relY = args[1].StartsWith("~"); var relZ = args[2].StartsWith("~"); double posX = 0; double posY = 0; double posZ = 0; var yaw = player.KnownPosition.Yaw; var pitch = player.KnownPosition.Pitch; var msg = "x"; var attemptConversion = ""; try { if (!relX || args[0].Length > 1) { posX = Convert.ToDouble(attemptConversion = relX ? args[0].Substring(1) : args[0]); } msg = "y"; if (!relY || args[1].Length > 1) { posY = Convert.ToDouble(attemptConversion = relY ? args[1].Substring(1) : args[1]); } msg = "z"; if (!relZ || args[2].Length > 1) { posZ = Convert.ToDouble(attemptConversion = relZ ? args[2].Substring(1) : args[2]); } if (rotation) { msg = "yaw"; yaw = (float)Convert.ToDouble(attemptConversion = args[3]); msg = "pitch"; pitch = (float)Convert.ToDouble(attemptConversion = args[4]); } } catch (FormatException e) { sender.SendChat($"Not a number argument {msg}: {attemptConversion}"); return; } player.Teleport(new PlayerLocation(posX += (relX ? player.KnownPosition.X : 0), posY += (relY ? player.KnownPosition.Y : 0), posZ += (relZ ? player.KnownPosition.Z : 0), yaw, pitch)); sender.SendChat($"Teleported to: {posX}, {posY}, {posZ}" + (rotation ? $", {yaw}, {pitch}" : "")); } else { ConsoleFunctions.WriteInfoLine("Cannot teleport console."); } }