-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
70 lines (61 loc) · 4.04 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/**
* Player Sleep Plugin - Enables 50% or 1 Player to sleep for everyone!
* Github: @BRadHoc/bdsx-sleep Discord: @Brad (BDSX)
*/
/* ------- Configs ---------- */
let OnePlayerSleep = false;
let SleepRemind = true;
/*----------------------------*/
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const { bedrockServer } = require("bdsx/launcher");
const { events } = require("bdsx/event");
const { ServerPlayer } = require("bdsx");
const { procHacker } = require("bdsx/bds/proc");
const { void_t, bool_t } = require("bdsx/nativetype");
const command = require("bdsx/commandresult");
console.log('[@BRadHoc/bdsx-sleep] Successfully loaded plugin');
events.serverOpen.on(() => {
console.log('[@BRadHoc/bdsx-sleep] ' + (OnePlayerSleep ? "Setting: One Player Sleep (Enabled)" : "Setting: 50% of online players are required to sleep"));
});
let wakeUp = procHacker.js('?stopSleepInBed@ServerPlayer@@UEAAX_N0@Z', void_t, {this: ServerPlayer}, bool_t, bool_t);
events.playerSleepInBed.on((ev) => {
setTimeout(() => {
if (ev.player.isSleeping()) {
const players = bedrockServer.level.getPlayers();
const sleepingPlayers = players.filter((player) => player.isSleeping()).length;
if (SleepRemind && !OnePlayerSleep) {
SleepRemind = false;
bedrockServer.executeCommand(`tellraw @a {"rawtext":[{"text":"§bThere are ${sleepingPlayers}/${players.length} players in-bed."}]}`, () => { });
bedrockServer.executeCommand('tellraw @a {"rawtext":[{"text":"§b' + (!OnePlayerSleep ? "50% of the players online are required to sleep." : ev.player.getNameTag().toString() + " just slept for everyone...") + '"}]}', () => { });
setTimeout(() => { SleepRemind = true; }, 30000);
}
setTimeout(() => {
if (sleepingPlayers >= players.length / 2 || OnePlayerSleep) {
if (ev.player.isSleeping()) {
let weather = bedrockServer.executeCommand("weather query", command.CommandResultType.OutputAndData);
weather = weather.data.statusMessage.substring(18);
if (weather === "thunder" || weather === "rain") bedrockServer.executeCommand(`weather clear`);
let time = bedrockServer.executeCommand("time query daytime", command.CommandResultType.OutputAndData);
time = parseInt(time.data.statusMessage.substring(11));
const t_offset = (23999-time);
bedrockServer.executeCommand(`time add ${t_offset}`);
for (let x = 0; x < players.length; x++) {
if (players[x].isPlayer()) {
if (players[x].isSleeping()) {
wakeUp.call(players[x], true, true);
}
let player = players[x].save();
player.SleepTimer._value = 0;
players[x].load(player);
}
}
if (OnePlayerSleep) bedrockServer.executeCommand(`tellraw @a {"rawtext":[{"text":"§b${ev.player.getNameTag()} just slept for everyone!"}]}`, () => { });
bedrockServer.executeCommand(`tellraw @a {"rawtext":[{"text":"§aGood Morning!"}]}`, () => { });
}
}
}, 2000);
}
}, 2000);
});
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyJpbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUNBLHNDQUFvQztBQUVwQyxPQUFPLENBQUMsR0FBRyxDQUFDLDhCQUE4QixDQUFDLENBQUM7QUFFNUMsY0FBTSxDQUFDLFVBQVUsQ0FBQyxFQUFFLENBQUMsR0FBRSxFQUFFO0lBQ3JCLE9BQU8sQ0FBQyxHQUFHLENBQUMsOEJBQThCLENBQUMsQ0FBQztBQUNoRCxDQUFDLENBQUMsQ0FBQztBQUVILGNBQU0sQ0FBQyxXQUFXLENBQUMsRUFBRSxDQUFDLEdBQUUsRUFBRTtJQUN0QixPQUFPLENBQUMsR0FBRyxDQUFDLDJCQUEyQixDQUFDLENBQUM7QUFDN0MsQ0FBQyxDQUFDLENBQUMifQ==