add /client teleport

This commit is contained in:
UnknownShadow200 2017-03-04 22:24:59 +11:00
parent 8fc9a9bd72
commit 8f81cb6d9a
2 changed files with 29 additions and 0 deletions

View File

@ -27,6 +27,7 @@ namespace ClassicalSharp.Commands {
if (!game.Server.IsSinglePlayer) return;
Register(new ModelCommand());
Register(new CuboidCommand());
Register(new TeleportCommand());
}
public void Ready(Game game) { }

View File

@ -2,6 +2,7 @@
using System;
using System.Collections.Generic;
using System.Text;
using ClassicalSharp.Entities;
using ClassicalSharp.Events;
using ClassicalSharp.Renderers;
using OpenTK.Input;
@ -126,4 +127,31 @@ namespace ClassicalSharp.Commands {
}
}
}
public sealed class TeleportCommand : Command {
public TeleportCommand() {
Name = "Teleport";
Help = new string[] {
"&a/client teleport [x y z]",
"&eMoves you to the given coordinates.",
};
}
public override void Execute(string[] args) {
if (args.Length != 4) {
game.Chat.Add("&e/client teleport: &cYou didn't specify X, Y and Z coordinates.");
} else {
float x = 0, y = 0, z = 0;
if (!Utils.TryParseDecimal(args[1], out x) ||
!Utils.TryParseDecimal(args[2], out y) ||
!Utils.TryParseDecimal(args[3], out z)) {
game.Chat.Add("&e/client teleport: &cCoordinates must be decimals");
}
LocationUpdate update = LocationUpdate.MakePos(x, y, z, false);
game.LocalPlayer.SetLocation(update, false);
}
}
}
}