Skip to content

Commit 8da2fe6

Browse files
bot174JaylyDev
andauthored
add Cancel Watchdog Terminate and get-gamemode (JaylyDev#13)
* add Cancel Watchdog Terminate * add image * Delete mojang-minecraft.d.ts * add package "get-gamemode" Co-authored-by: Jayly <[email protected]>
1 parent 4840ad6 commit 8da2fe6

6 files changed

Lines changed: 69 additions & 1 deletion

File tree

mojang-minecraft/README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,8 @@
1414

1515
### [Set item lore](./setLore/index.js)
1616

17-
### [Get/Set Scoreboard](./scoreboard/index.js)
17+
### [Get/Set Scoreboard](./scoreboard/index.js)
18+
19+
### [Cancel Watchdog Terminate](./watchdog/beforeWatchdogTerminate.js)
20+
21+
![](https://media.discordapp.net/attachments/852517995308646410/1009680002209546240/unknown.png)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { system } from "mojang-minecraft";
2+
3+
system.events.beforeWatchdogTerminate.subscribe((eventData) => {
4+
eventData.cancel = true;
5+
});

scripts/get-gamemode/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) each contributor listed at every package.
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

scripts/get-gamemode/index.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* Get player gamemode
3+
* @param player
4+
* @returns gamemode number
5+
*/
6+
export function getGamemode(player) {
7+
const GameModes = ['survival', 'creative', 'adventure', 'spectator'];
8+
for (let i of GameModes) {
9+
try {
10+
player.runCommand(`testfor @s[m=${i}]`);
11+
return i;
12+
} catch {};
13+
};
14+
};

scripts/get-gamemode/index.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { Player } from "mojang-minecraft";
2+
3+
/**
4+
* Get player gamemode
5+
* @param player
6+
* @returns gamemode number
7+
*/
8+
export function getGamemode(player: Player): string {
9+
const GameModes = ['survival', 'creative', 'adventure', 'spectator'];
10+
for (let i of GameModes) {
11+
try {
12+
player.runCommand(`testfor @s[m=${i}]`);
13+
return i;
14+
} catch {};
15+
};
16+
};
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { world } from "mojang-minecraft";
2+
import { getGamemode } from "./index";
3+
4+
world.events.leverActivate.subscribe(({player}) => {
5+
let gamemode = getGamemode(player);
6+
7+
player.tell(`Your game mode is ${gamemode}`);
8+
});

0 commit comments

Comments
 (0)