2022-11-13 15:19:56 +00:00
|
|
|
import { PacketWriter, Player, Plugin } from "../classes/classes.ts";
|
2022-06-01 22:30:34 +00:00
|
|
|
import { Server } from "../classes/Server.ts";
|
|
|
|
import { config } from "../deps.ts";
|
|
|
|
|
|
|
|
export default class CommandPlugin extends Plugin {
|
|
|
|
commands = [
|
|
|
|
"help",
|
|
|
|
"reloadplugins",
|
|
|
|
"clients",
|
2022-11-13 15:19:56 +00:00
|
|
|
"tp",
|
|
|
|
"eval"
|
2022-06-01 22:30:34 +00:00
|
|
|
];
|
|
|
|
|
2022-11-13 15:19:56 +00:00
|
|
|
async tp(from: Player, to: Player) {
|
|
|
|
if(to.world != from.world) {
|
|
|
|
from.toWorld(this.server.worlds.find((e) =>
|
|
|
|
e.name == to.world
|
|
|
|
)!);
|
|
|
|
}
|
|
|
|
|
|
|
|
await from.writeToSocket(
|
|
|
|
new PacketWriter()
|
|
|
|
.writeByte(0x08)
|
|
|
|
.writeSByte(255)
|
|
|
|
.writeShort(to.position.x)
|
|
|
|
.writeShort(to.position.y)
|
|
|
|
.writeShort(to.position.z)
|
|
|
|
.writeByte(to.rotation.yaw)
|
|
|
|
.writeByte(to.rotation.pitch)
|
|
|
|
.toPacket(),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-06-01 22:30:34 +00:00
|
|
|
constructor(server: Server) {
|
|
|
|
super();
|
|
|
|
|
|
|
|
this.server = server;
|
2022-06-03 12:36:34 +00:00
|
|
|
|
2022-11-13 15:19:56 +00:00
|
|
|
this.on("command", async (command, player, args) => {
|
2022-06-01 22:30:34 +00:00
|
|
|
if (command == "help") {
|
|
|
|
let allComamnds = "";
|
|
|
|
for (const [_k, v] of server.plugins) {
|
|
|
|
allComamnds += `${v.plugin.commands.join(", ")}, `;
|
|
|
|
}
|
|
|
|
player.message(allComamnds.slice(0, -2));
|
|
|
|
} else if (command == "reloadplugins") {
|
|
|
|
if (config.ops.includes(player.username)) {
|
|
|
|
server.broadcast(
|
|
|
|
"&cRestarting plugins. &fServer will be &4unstable.",
|
|
|
|
);
|
|
|
|
await this.server.updatePlugins();
|
|
|
|
server.broadcast("&eFinished! Server should be now &amostly stable.");
|
|
|
|
}
|
|
|
|
} else if (command == "clients") {
|
|
|
|
this.server.worlds.forEach((e) => {
|
|
|
|
const players = this.server.players.filter((b) => e.name == b.world);
|
|
|
|
if (players.length != 0) {
|
|
|
|
player.message(
|
|
|
|
`&a${e.name}&f: &a${players.map((e) => e.username).join(", ")}`,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
2022-11-13 15:19:56 +00:00
|
|
|
} else if(command == "eval") {
|
|
|
|
if(config.ops.includes(player.username)) {
|
|
|
|
|
|
|
|
server.broadcast(eval(args.join(" ")));
|
|
|
|
}
|
|
|
|
} else if (command == "tp") {
|
|
|
|
if(args.length == 1) {
|
|
|
|
const teleportTo = this.server.players.find((e) => args[0] === e.username)
|
|
|
|
|
|
|
|
if(teleportTo) {
|
|
|
|
await this.tp(player, teleportTo);
|
|
|
|
} else {
|
|
|
|
player.message("Player is missing")
|
|
|
|
}
|
|
|
|
} else if(args.length == 3) {
|
|
|
|
const x = +args[0]
|
|
|
|
const y = +args[1]
|
|
|
|
const z = +args[2]
|
|
|
|
|
|
|
|
if(isNaN(x) || isNaN(y) || isNaN(z)) {
|
|
|
|
player.message("invalid coords")
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
await player.writeToSocket(
|
|
|
|
new PacketWriter()
|
|
|
|
.writeByte(0x08)
|
|
|
|
.writeSByte(255)
|
|
|
|
.writeShort(x * 32)
|
|
|
|
.writeShort(y * 32)
|
|
|
|
.writeShort(z * 32)
|
|
|
|
.writeByte(player.rotation.yaw)
|
|
|
|
.writeByte(player.rotation.pitch)
|
|
|
|
.toPacket(),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2022-06-01 22:30:34 +00:00
|
|
|
}
|
|
|
|
}
|