Handle Bukkit and Canary. COLOR_CHAR introduced
NOTE: I have tested this code on Canary only. 1. Canary's events.chat introduced. 2. The COLOR_CHAR (§) was a real mystery until I found the answer in string-exts.js :)
This commit is contained in:
parent
e1e78587f4
commit
6b0202491a
1 changed files with 22 additions and 6 deletions
|
@ -56,16 +56,23 @@ var colors = ['black', 'blue', 'darkgreen', 'darkaqua', 'darkred',
|
||||||
'brightgreen', 'aqua', 'red', 'pink',
|
'brightgreen', 'aqua', 'red', 'pink',
|
||||||
'yellow', 'white'];
|
'yellow', 'white'];
|
||||||
var colorCodes = {};
|
var colorCodes = {};
|
||||||
|
var COLOR_CHAR = '\u00a7';
|
||||||
for (var i =0;i < colors.length;i++)
|
for (var i =0;i < colors.length;i++)
|
||||||
colorCodes[colors[i]] = i.toString(16);
|
colorCodes[colors[i]] = i.toString(16);
|
||||||
|
|
||||||
events.asyncPlayerChat( function( evt ) {
|
var addColor = function( evt ) {
|
||||||
var player = evt.player;
|
var player = evt.player;
|
||||||
var playerChatColor = store.players[ player.name ];
|
var playerChatColor = store.players[ player.name ];
|
||||||
if ( playerChatColor ) {
|
if ( playerChatColor ) {
|
||||||
evt.message = '§' + colorCodes[ playerChatColor ] + evt.message;
|
evt.message = COLOR_CHAR + colorCodes[ playerChatColor ] + evt.message;
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
|
|
||||||
|
if (__plugin.bukkit) {
|
||||||
|
events.asyncPlayerChat(addColor);
|
||||||
|
} else if (__plugin.canary) {
|
||||||
|
events.chat(addColor);
|
||||||
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
The next step is to declare a lookup table of colors / names and add an event
|
The next step is to declare a lookup table of colors / names and add an event
|
||||||
|
@ -124,16 +131,24 @@ var colors = ['black', 'blue', 'darkgreen', 'darkaqua', 'darkred',
|
||||||
'brightgreen', 'aqua', 'red', 'pink',
|
'brightgreen', 'aqua', 'red', 'pink',
|
||||||
'yellow', 'white'];
|
'yellow', 'white'];
|
||||||
var colorCodes = {};
|
var colorCodes = {};
|
||||||
|
var COLOR_CHAR = '\u00a7';
|
||||||
for (var i =0;i < colors.length;i++)
|
for (var i =0;i < colors.length;i++)
|
||||||
colorCodes[colors[i]] = i.toString(16);
|
colorCodes[colors[i]] = i.toString(16);
|
||||||
|
|
||||||
events.asyncPlayerChat( function( evt ) {
|
var addColor = function( evt ) {
|
||||||
var player = evt.player;
|
var player = evt.player;
|
||||||
var playerChatColor = store.players[ player.name ];
|
var playerChatColor = store.players[ player.name ];
|
||||||
if ( playerChatColor ) {
|
if ( playerChatColor ) {
|
||||||
evt.message = '§' + colorCodes[ playerChatColor ] + evt.message;
|
evt.message = COLOR_CHAR + colorCodes[ playerChatColor ] + evt.message;
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
|
|
||||||
|
if (__plugin.bukkit) {
|
||||||
|
events.asyncPlayerChat(addColor);
|
||||||
|
} else if (__plugin.canary) {
|
||||||
|
events.chat(addColor);
|
||||||
|
};
|
||||||
|
|
||||||
function chat_color( params, sender ){
|
function chat_color( params, sender ){
|
||||||
var color = params[0];
|
var color = params[0];
|
||||||
if (colorCodes[color]){
|
if (colorCodes[color]){
|
||||||
|
@ -143,6 +158,7 @@ function chat_color( params, sender ){
|
||||||
echo(sender, 'valid colors: ' + colors.join(', '));
|
echo(sender, 'valid colors: ' + colors.join(', '));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
command(chat_color, colors);
|
command(chat_color, colors);
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
Reference in a new issue