initial commit
This commit is contained in:
commit
f55f51fec3
3 changed files with 91 additions and 0 deletions
51
scripts/main.js
Normal file
51
scripts/main.js
Normal file
|
@ -0,0 +1,51 @@
|
|||
import {
|
||||
world,
|
||||
system
|
||||
} from "@minecraft/server";
|
||||
import {
|
||||
http,
|
||||
HttpRequest,
|
||||
HttpHeader,
|
||||
HttpRequestMethod
|
||||
} from "@minecraft/server-net";
|
||||
|
||||
// CHANGE THIS TO YOUR WEBHOOK URL!
|
||||
const webhookUrl = ":webhook:";
|
||||
|
||||
async function makeMessage(author, message) {
|
||||
const req = new HttpRequest(webhookUrl);
|
||||
|
||||
req.body = JSON.stringify({
|
||||
username: author,
|
||||
content: message
|
||||
});
|
||||
req.method = HttpRequestMethod.Post;
|
||||
req.headers = [
|
||||
new HttpHeader("Accept", "application/json"),
|
||||
new HttpHeader("Content-Type", "application/json"),
|
||||
];
|
||||
|
||||
await http.request(req);
|
||||
}
|
||||
|
||||
world.beforeEvents.chatSend.subscribe((e) => {
|
||||
e.cancel = true;
|
||||
system.run(() => {
|
||||
world.sendMessage(`${e.sender.name}: ${e.message}`);
|
||||
makeMessage(e.sender.name, e.message);
|
||||
});
|
||||
});
|
||||
|
||||
world.afterEvents.playerJoin.subscribe((e) => {
|
||||
e.cancel = true;
|
||||
system.run(() => {
|
||||
makeMessage("Server", `> ${e.playerName} joins`);
|
||||
});
|
||||
});
|
||||
|
||||
world.afterEvents.playerLeave.subscribe((e) => {
|
||||
e.cancel = true;
|
||||
system.run(() => {
|
||||
makeMessage("Server", `> ${e.playerName} leaves`);
|
||||
});
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue