@@ -14,6 +14,8 @@ export interface CommandActionDetails {
14
14
player : Player ;
15
15
// The command that the player entered.
16
16
command : string ;
17
+ // If the player used the console
18
+ isConsole : boolean ;
17
19
// The arguments that the player entered for their command.
18
20
args : { [ key : string ] : number | string } ;
19
21
}
@@ -37,8 +39,7 @@ export interface CommandActionPlugin extends ActionPlugin {
37
39
/**
38
40
* A directory of all command interaction plugins.
39
41
*/
40
- let commandInteractions : CommandActionPlugin [ ] = [
41
- ] ;
42
+ let commandInteractions : CommandActionPlugin [ ] = [ ] ;
42
43
43
44
/**
44
45
* Sets the list of command interaction plugins.
@@ -48,23 +49,23 @@ export const setCommandPlugins = (plugins: ActionPlugin[]): void => {
48
49
commandInteractions = plugins as CommandActionPlugin [ ] ;
49
50
} ;
50
51
51
- export const inputCommandAction = ( player : Player , command : string , inputArgs : string [ ] ) : void => {
52
+ export const inputCommandAction = ( player : Player , command : string , isConsole : boolean , inputArgs : string [ ] ) : void => {
52
53
const plugins = commandInteractions . filter ( plugin => {
53
- if ( Array . isArray ( plugin . commands ) ) {
54
+ if ( Array . isArray ( plugin . commands ) ) {
54
55
return plugin . commands . indexOf ( command ) !== - 1 ;
55
56
} else {
56
57
return plugin . commands === command ;
57
58
}
58
59
} ) ;
59
60
60
- if ( plugins . length === 0 ) {
61
- player . outgoingPackets . chatboxMessage ( `Unhandled command: ${ command } ` ) ;
61
+ if ( plugins . length === 0 ) {
62
+ player . sendLogMessage ( `Unhandled command: ${ command } ` , isConsole ) ;
62
63
return ;
63
64
}
64
65
65
66
plugins . forEach ( plugin => {
66
67
try {
67
- if ( plugin . args ) {
68
+ if ( plugin . args ) {
68
69
const pluginArgs = plugin . args ;
69
70
let syntaxError = `Syntax error. Try ::${ command } ` ;
70
71
@@ -73,34 +74,34 @@ export const inputCommandAction = (player: Player, command: string, inputArgs: s
73
74
} ) ;
74
75
75
76
const requiredArgLength = plugin . args . filter ( arg => arg . defaultValue !== undefined ) . length ;
76
- if ( requiredArgLength > inputArgs . length ) {
77
- player . outgoingPackets . chatboxMessage ( syntaxError ) ;
77
+ if ( requiredArgLength > inputArgs . length ) {
78
+ player . sendLogMessage ( syntaxError , isConsole ) ;
78
79
return ;
79
80
}
80
81
81
82
const actionArgs = { } ;
82
83
83
- for ( let i = 0 ; i < plugin . args . length ; i ++ ) {
84
+ for ( let i = 0 ; i < plugin . args . length ; i ++ ) {
84
85
let argValue : string | number = inputArgs [ i ] || null ;
85
86
const pluginArg = plugin . args [ i ] ;
86
87
87
- if ( argValue === null ) {
88
- if ( pluginArg . defaultValue === undefined ) {
89
- player . outgoingPackets . chatboxMessage ( syntaxError ) ;
88
+ if ( argValue === null ) {
89
+ if ( pluginArg . defaultValue === undefined ) {
90
+ player . sendLogMessage ( syntaxError , isConsole ) ;
90
91
return ;
91
92
} else {
92
93
argValue = pluginArg . defaultValue ;
93
94
}
94
95
} else {
95
- if ( pluginArg . type === 'number' ) {
96
+ if ( pluginArg . type === 'number' ) {
96
97
argValue = parseInt ( argValue ) ;
97
- if ( isNaN ( argValue ) ) {
98
- player . outgoingPackets . chatboxMessage ( syntaxError ) ;
98
+ if ( isNaN ( argValue ) ) {
99
+ player . sendLogMessage ( syntaxError , isConsole ) ;
99
100
return ;
100
101
}
101
102
} else {
102
- if ( ! argValue || argValue . trim ( ) === '' ) {
103
- player . outgoingPackets . chatboxMessage ( syntaxError ) ;
103
+ if ( ! argValue || argValue . trim ( ) === '' ) {
104
+ player . sendLogMessage ( syntaxError , isConsole ) ;
104
105
return ;
105
106
}
106
107
}
@@ -109,12 +110,12 @@ export const inputCommandAction = (player: Player, command: string, inputArgs: s
109
110
actionArgs [ pluginArg . name ] = argValue ;
110
111
}
111
112
112
- plugin . action ( { player, command, args : actionArgs } ) ;
113
+ plugin . action ( { player, command, isConsole , args : actionArgs } ) ;
113
114
} else {
114
- plugin . action ( { player, command, args : { } } ) ;
115
+ plugin . action ( { player, command, isConsole , args : { } } ) ;
115
116
}
116
- } catch ( commandError ) {
117
- player . outgoingPackets . chatboxMessage ( `Command error: ${ commandError } ` ) ;
117
+ } catch ( commandError ) {
118
+ player . sendLogMessage ( `Command error: ${ commandError } ` , isConsole ) ;
118
119
}
119
120
} ) ;
120
121
} ;
0 commit comments