@@ -3,52 +3,95 @@ import { activeWorld } from '@engine/world';
33import { Position } from '@engine/world/position' ;
44
55const action : commandActionHandler = details => {
6- const { player, args } = details ;
6+ const { player, args } = details ;
77
8- const x = args . XorPlayerName ;
8+ const x = args . XorPlayerName ;
99
10- if ( typeof x === 'string' ) {
11- const playerWithName = activeWorld . findPlayer ( x ) ;
12- if ( playerWithName ) {
13- player . teleport ( playerWithName . position ) ;
14- return ;
15- }
10+ if ( typeof x === 'string' ) {
11+ const playerWithName = activeWorld . findPlayer ( x ) ;
12+ if ( playerWithName ) {
13+ player . teleport ( playerWithName . position ) ;
14+ return ;
1615 }
16+ }
1717
18- const xCoord : number = typeof x === 'string' ? parseInt ( x , 10 ) : x ;
18+ const xCoord : number = typeof x === 'string' ? parseInt ( x , 10 ) : x ;
1919
20- if ( isNaN ( xCoord ) ) {
21- return ;
22- }
23- const y : number = args . y as number ;
24- const level : number = args . level as number ;
20+ if ( isNaN ( xCoord ) ) {
21+ return ;
22+ }
23+ const y : number = args . y as number ;
24+ const level : number = args . level as number ;
25+
26+ player . teleport ( new Position ( xCoord , y , level ) ) ;
27+ } ;
28+
29+ const goUpAction : commandActionHandler = details => {
30+ const { player } = details ;
2531
26- player . teleport ( new Position ( xCoord , y , level ) ) ;
32+ player . teleport ( new Position ( player . position . x , player . position . y , player . position . level + 1 ) ) ;
2733} ;
2834
35+ const goDownAction : commandActionHandler = details => {
36+ const { player } = details ;
37+
38+ if ( player . position . level > 0 ) {
39+ player . teleport ( new Position ( player . position . x , player . position . y , player . position . level - 1 ) ) ;
40+ }
41+ } ;
42+
43+ const setLevelCommand : commandActionHandler = details => {
44+ const { player, args } = details ;
45+ const level : number = args . level as number ;
46+ if ( ! isNaN ( level ) && level >= 0 && level <= 255 ) {
47+ player . teleport ( new Position ( player . position . x , player . position . y , level ) ) ;
48+ }
49+ }
50+
2951export default {
30- pluginId : 'rs:teleport_command_plugin' ,
31- hooks : [
52+ pluginId : 'rs:teleport_command_plugin' ,
53+ hooks : [
54+ {
55+ type : 'player_command' ,
56+ commands : [ 'move' , 'goto' , 'teleport' , 'tele' , 'moveto' , 'setpos' ] ,
57+ args : [
3258 {
33- type : 'player_command' ,
34- commands : [ 'move' , 'goto' , 'teleport' , 'tele' , 'moveto' , 'setpos' ] ,
35- args : [
36- {
37- name : 'XorPlayerName' ,
38- type : 'string' ,
39- } ,
40- {
41- name : 'y' ,
42- type : 'number' ,
43- defaultValue : 3222 ,
44- } ,
45- {
46- name : 'level' ,
47- type : 'number' ,
48- defaultValue : 0 ,
49- } ,
50- ] ,
51- handler : action ,
59+ name : 'XorPlayerName' ,
60+ type : 'string' ,
5261 } ,
53- ] ,
62+ {
63+ name : 'y' ,
64+ type : 'number' ,
65+ defaultValue : 3222 ,
66+ } ,
67+ {
68+ name : 'level' ,
69+ type : 'number' ,
70+ defaultValue : 0 ,
71+ } ,
72+ ] ,
73+ handler : action ,
74+ } ,
75+ {
76+ type : 'player_command' ,
77+ commands : [ 'up' , 'goup' ] ,
78+ handler : goUpAction ,
79+ } ,
80+ {
81+ type : 'player_command' ,
82+ commands : [ 'down' , 'godown' ] ,
83+ handler : goDownAction ,
84+ } ,
85+ {
86+ type : 'player_command' ,
87+ commands : [ 'setheightlevel' , 'heightlevel' , 'hl' ] ,
88+ args : [
89+ {
90+ name : 'level' ,
91+ type : 'number' ,
92+ } ,
93+ ] ,
94+ handler : setLevelCommand ,
95+ }
96+ ] ,
5497} ;
0 commit comments