Merge pull request #235 from carlrobert/patch-15

Handle Bukkit and Canary. COLOR_CHAR introduced
This commit is contained in:
Walter Higgins 2015-04-30 14:22:22 +01:00
commit 3f5bbcf6c8

View file

@ -56,16 +56,23 @@ var colors = ['black', 'blue', 'darkgreen', 'darkaqua', 'darkred',
'brightgreen', 'aqua', 'red', 'pink',
'yellow', 'white'];
var colorCodes = {};
var COLOR_CHAR = '\u00a7';
for (var i =0;i < colors.length;i++)
colorCodes[colors[i]] = i.toString(16);
events.asyncPlayerChat( function( evt ) {
var addColor = function( evt ) {
var player = evt.player;
var playerChatColor = store.players[ player.name ];
if ( playerChatColor ) {
evt.message = '&sect;' + 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
@ -124,16 +131,24 @@ var colors = ['black', 'blue', 'darkgreen', 'darkaqua', 'darkred',
'brightgreen', 'aqua', 'red', 'pink',
'yellow', 'white'];
var colorCodes = {};
var COLOR_CHAR = '\u00a7';
for (var i =0;i < colors.length;i++)
colorCodes[colors[i]] = i.toString(16);
events.asyncPlayerChat( function( evt ) {
var addColor = function( evt ) {
var player = evt.player;
var playerChatColor = store.players[ player.name ];
if ( playerChatColor ) {
evt.message = '&sect;' + 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 ){
var color = params[0];
if (colorCodes[color]){
@ -143,6 +158,7 @@ function chat_color( params, sender ){
echo(sender, 'valid colors: ' + colors.join(', '));
}
}
command(chat_color, colors);
```