This repository was archived by the owner on Feb 17, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 10 files changed +61
-29
lines changed
Expand file tree Collapse file tree 10 files changed +61
-29
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ export * from "./src/utils.js";
22export { Event } from "./src/event.js" ;
33export { GameRule } from "./src/gamerule.js" ;
44export { Command } from "./src/command.js" ;
5+ export { World } from "./src/world.js" ;
56export { Tick } from "./src/tick.js" ;
67export { Tag } from "./src/tag.js" ;
78export { Player } from "./src/player.js" ;
Original file line number Diff line number Diff line change 1- import { Commands } from "Minecraft" ;
2- import { CommandExecutionError } from "./errors.js" ;
1+ import { Commands , World } from "mojang-minecraft" ;
32
43
54export const Command = new ( class {
6- #run( command , dimension ) {
7- if ( dimension ) {
8- return Commands . run ( command , dimension ) ;
5+ #run( command , dimension = "overworld" ) {
6+ if ( typeof dimension === "string" ) {
7+ dimension = World . getDimension ( dimension ) ;
98 }
10- return Commands . run ( command ) ;
9+ return Commands . run ( command , dimension ) ;
1110 }
1211
1312 run ( command , dimension ) {
14- try {
15- return this . #run( command , dimension ) ;
16- }
17- catch ( e ) {
18- const status = JSON . parse ( e ) ;
19- throw new CommandExecutionError ( command , status ) ;
20- }
13+ return this . #run( command , dimension ) ;
2114 }
2215
2316 runSafe ( command , dimension ) {
2417 try {
2518 return this . #run( command , dimension ) ;
2619 }
2720 catch ( e ) {
28- return JSON . parse ( e ) ;
21+ return e ;
2922 }
3023 }
3124
Original file line number Diff line number Diff line change 1+ import { Command } from "./command.js" ;
2+
3+
4+ export class Dimension {
5+ #dimension;
6+
7+ constructor ( dimension ) {
8+ this . #dimension = dimension ;
9+
10+ for ( const attr in dimension ) {
11+ this [ attr ] = dimension [ attr ] ;
12+ }
13+ }
14+ commandRun ( command ) {
15+ return Command . run ( command , this . #dimension) ;
16+ }
17+ commandRunSafe ( command ) {
18+ return Command . runSafe ( command , this . #dimension) ;
19+ }
20+ }
Original file line number Diff line number Diff line change @@ -14,12 +14,3 @@ export class EventNotDefined extends Error {
1414 super ( `${ eventName } event is not defined.` ) ;
1515 }
1616}
17-
18- export class CommandExecutionError extends Error {
19- name = "CommandExecutionError" ;
20- constructor ( command , { statusMessage, statusCode } ) {
21- super ( statusMessage ) ;
22- this . code = statusCode ;
23- this . command = command ;
24- }
25- }
Original file line number Diff line number Diff line change 1- import { World } from "Minecraft " ;
1+ import { World } from "mojang-minecraft " ;
22import { EventNotDefined } from "./errors.js" ;
33import { print } from "./utils.js" ;
44
Original file line number Diff line number Diff line change 1- import { Commands } from "Minecraft" ;
21import { Command } from "./command.js" ;
3- import { print } from "./utils.js" ;
42
53
64export const GameRule = new ( class {
Original file line number Diff line number Diff line change 1- import { World } from "Minecraft " ;
1+ import { World } from "mojang-minecraft " ;
22import { Command } from "./command.js" ;
33import { Tag } from "./tag.js" ;
44
@@ -39,4 +39,8 @@ export class Player {
3939 removeTag ( tag ) {
4040 return Tag . removeTag ( this . #tagSelector, tag ) ;
4141 }
42+
43+ toString ( ) {
44+ return this . name ;
45+ }
4246}
Original file line number Diff line number Diff line change 1- import { Player , Entity } from "Minecraft " ;
1+ import { Player , Entity } from "mojang-minecraft " ;
22import { Command } from "./command.js" ;
33
44
Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ import { Command } from "./command.js";
33
44export function print ( ...obj ) {
55 const rawtext = JSON . stringify ( {
6- rawtext : [ { text : obj . join ( " " ) } ]
6+ rawtext : [ { text : obj . map ( String ) . join ( " " ) } ]
77 } ) . replaceAll ( "\\r\\n" , "\\n" ) ;
88 Command . run ( "tellraw @a " + rawtext ) ;
99}
@@ -48,6 +48,9 @@ export function toJson(data, indent = 4) {
4848 }
4949 return obj ;
5050
51+ case "undefined" :
52+ return null ;
53+
5154 default :
5255 return value ;
5356 }
Original file line number Diff line number Diff line change 1+ import { World as _World } from "mojang-minecraft" ;
2+ import { Dimension } from "./dimension.js" ;
3+ import { Player } from "./player.js" ;
4+
5+
6+ export const World = new ( class {
7+ #excludeAttrs = [ "getDimension" , "getPlayers" ] ;
8+
9+ constructor ( ) {
10+ for ( const attr in _World ) {
11+ if ( this . #excludeAttrs. includes ( attr ) ) continue ;
12+ this [ attr ] = _World [ attr ] ;
13+ }
14+ }
15+ getDimension ( name ) {
16+ const dimension = _World . getDimension ( name ) ;
17+ return new Dimension ( dimension ) ;
18+ }
19+ getPlayers ( ) {
20+ return Player . getAll ( ) ;
21+ }
22+ } ) ( ) ;
You can’t perform that action at this time.
0 commit comments