2022-06-03 12:36:34 +00:00
|
|
|
import { Plugin, World } 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 = [
|
|
|
|
"g",
|
|
|
|
"worlds",
|
|
|
|
"world",
|
2022-07-14 13:26:27 +00:00
|
|
|
"main",
|
2022-06-01 22:30:34 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
constructor(server: Server) {
|
|
|
|
super();
|
|
|
|
|
|
|
|
this.server = server;
|
2022-06-03 12:36:34 +00:00
|
|
|
this.on("setblock", (player, _mode, _id) => {
|
2022-06-01 22:30:34 +00:00
|
|
|
const world = server.worlds.find((e) => e.name == player.world)!;
|
2024-04-28 12:32:04 +00:00
|
|
|
if (!world.metadata?.builders?.includes("*")) {
|
|
|
|
if (!world.metadata?.builders?.includes(player.username)) {
|
2022-06-01 22:30:34 +00:00
|
|
|
player.message("You are %cnot allowed &fto build in this world!");
|
2022-06-03 12:36:34 +00:00
|
|
|
return true;
|
2022-06-01 22:30:34 +00:00
|
|
|
}
|
|
|
|
}
|
2022-06-03 12:36:34 +00:00
|
|
|
|
|
|
|
return false;
|
2022-06-01 22:30:34 +00:00
|
|
|
});
|
|
|
|
this.on("command", async (command, player, args) => {
|
2022-07-14 13:26:27 +00:00
|
|
|
if (command == "main") {
|
|
|
|
await server.worlds.find((e) => e.name == player.world)!.save();
|
|
|
|
|
|
|
|
player.toWorld(
|
|
|
|
server.worlds.find((e) => e.name.toLowerCase() == config.main)!,
|
|
|
|
);
|
|
|
|
} else if (command == "g") {
|
|
|
|
await server.worlds.find((e) => e.name == player.world)!.save();
|
2022-07-10 15:19:17 +00:00
|
|
|
|
2022-06-01 22:30:34 +00:00
|
|
|
const requestedWorld = server.worlds.find((e) =>
|
|
|
|
e.name.toLowerCase() == args.join(" ").toLowerCase()
|
|
|
|
);
|
2022-07-10 15:19:17 +00:00
|
|
|
|
2022-06-01 22:30:34 +00:00
|
|
|
if (requestedWorld) {
|
|
|
|
player.toWorld(requestedWorld);
|
|
|
|
} else {
|
|
|
|
player.message(`World ${args.join(" ")} does &4not exist!`);
|
|
|
|
}
|
|
|
|
} else if (command == "worlds") {
|
|
|
|
player.message(
|
|
|
|
`Available worlds (/g): &a${
|
|
|
|
server.worlds.map((e) => e.name).join(", ")
|
|
|
|
}`,
|
|
|
|
);
|
|
|
|
} else if (command == "world") {
|
|
|
|
const category = args[0];
|
|
|
|
|
|
|
|
if (category == "create") {
|
|
|
|
if (!server.worlds.find((e) => e.name == player.username)) {
|
|
|
|
const world = new World(
|
|
|
|
{ x: 64, y: 64, z: 64 },
|
|
|
|
player.username,
|
|
|
|
);
|
2024-04-28 12:32:04 +00:00
|
|
|
world.metadata.builders = [];
|
|
|
|
world.metadata.builders.push(player.username);
|
2022-06-01 22:30:34 +00:00
|
|
|
server.worlds.push(world);
|
|
|
|
|
|
|
|
player.message(`&aWorld created!&f Use /g ${player.username}!`);
|
|
|
|
} else {
|
|
|
|
player.message(
|
|
|
|
`&cYou already own a world!&f Use /g ${player.username}!`,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
} else if (category == "delete") {
|
|
|
|
const world = server.worlds.find((e) => e.name == player.username);
|
|
|
|
if (world) {
|
|
|
|
server.broadcastPacket((e) => e.toWorld(server.worlds[0]), player);
|
|
|
|
|
|
|
|
player.toWorld(server.worlds[0]);
|
|
|
|
|
|
|
|
await world.delete();
|
|
|
|
|
|
|
|
server.worlds = server.worlds.filter((e) =>
|
|
|
|
e.name !== player.username
|
|
|
|
);
|
|
|
|
|
|
|
|
player.message(`&cWorld deleted.`);
|
|
|
|
} else {
|
|
|
|
player.message(
|
|
|
|
`&cYou don't have a world.`,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
} else if (category == "builders") {
|
|
|
|
const subcategory = args[1];
|
|
|
|
let world = server.worlds.find((e) => e.name == player.username);
|
|
|
|
|
|
|
|
if (args[3] && config.ops.includes(player.username)) {
|
|
|
|
world = server.worlds.find((e) => e.name == args[3]);
|
|
|
|
|
|
|
|
player.message(
|
|
|
|
`&aOP Overwrite detected! Operating on world ${args[3]}`,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!world) {
|
|
|
|
player.message(`&cWorld does not exist/you do not own a world.`);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-04-28 12:32:04 +00:00
|
|
|
if (!world.metadata?.builders) world.metadata.builders = [];
|
2022-06-01 22:30:34 +00:00
|
|
|
|
|
|
|
if (subcategory == "add") {
|
|
|
|
const username = args[2];
|
2024-04-28 12:32:04 +00:00
|
|
|
world.metadata.builders.push(username);
|
2022-06-01 22:30:34 +00:00
|
|
|
player.message(
|
|
|
|
`&a${username}&f sucesfully added as a builder to world &a${world.name}!`,
|
|
|
|
);
|
|
|
|
await world.save();
|
|
|
|
} else if (subcategory == "remove") {
|
|
|
|
const username = args[2];
|
|
|
|
|
2024-04-28 12:32:04 +00:00
|
|
|
const before = world.metadata.builders.length;
|
2022-06-01 22:30:34 +00:00
|
|
|
|
2024-04-28 12:32:04 +00:00
|
|
|
world.metadata.builders = world.metadata.builders.filter((
|
2022-06-01 22:30:34 +00:00
|
|
|
e: string,
|
|
|
|
) => e !== username);
|
|
|
|
|
2024-04-28 12:32:04 +00:00
|
|
|
const after = world.metadata.builders.length;
|
2022-06-01 22:30:34 +00:00
|
|
|
|
|
|
|
player.message(
|
|
|
|
`Removed &a${
|
|
|
|
before - after
|
|
|
|
}&f builder/s with name &a${username}&f in world &a${world.name}!`,
|
|
|
|
);
|
|
|
|
await world.save();
|
|
|
|
} else if (subcategory == "list") {
|
|
|
|
player.message(
|
|
|
|
`&a${world.name}&f's builders: &a${
|
2024-04-28 12:32:04 +00:00
|
|
|
world.metadata.builders.join(", ")
|
2022-06-01 22:30:34 +00:00
|
|
|
}`,
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
player.message(
|
|
|
|
`&a/world builders [add/remove/list] USERNAME`,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
player.message(
|
|
|
|
`&a/world [create/delete/builders]`,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|