Use Bukkit's ChatColor class for more reliable...

...output.
Also, cleans up String.prototype[method] by removing the non-used parameter "method"
This commit is contained in:
Ivan Kondratyev 2013-12-20 10:11:34 -06:00
parent db88a51cbf
commit 852a755819

View file

@ -3,29 +3,33 @@ String class extensions
-----------------------
The following chat-formatting methods are added to the javascript String class..
* aqua()
* black()
* darkblue()
* blue()
* darkgreen()
* bold()
* brightgreen()
* darkaqua()
* darkred()
* darkblue()
* darkgray()
* darkgreen()
* purple()
* darkpurple()
* darkred()
* gold()
* gray()
* darkgray()
* indigo()
* brightgreen()
* green()
* aqua()
* italic()
* lightpurple()
* indigo()
* green()
* red()
* pink()
* yellow()
* white()
* bold()
* random()
* strike()
* random()
* magic()
* underline()
* italic()
* reset()
Example
@ -38,35 +42,40 @@ Example
***/
(function(){
var c = org.bukkit.ChatColor;
var formattingCodes = {
black: 0,
darkblue: 1,
blue: 1,
darkgreen: 2,
darkaqua: 3,
darkred: 4,
purple: 5,
gold: 6,
gray: 7,
darkgray: 8,
indigo: 9,
brightgreen: 'a',
green: 'a',
aqua: 'b',
red: 'c',
pink: 'd',
yellow: 'e',
white: 'f',
bold: 'l',
random:'k',
strike: 'm',
underline: 'n',
italic: 'o',
reset: 'r'
aqua: c.AQUA,
black: c.BLACK,
blue: c.BLUE,
bold: c.BOLD,
brightgreen: c.GREEN,
darkaqua: c.DARK_AQUA,
darkblue: c.DARK_BLUE,
darkgray: c.DARK_GRAY,
darkgreen: c.DARK_GREEN,
purple: c.LIGHT_PURPLE,
darkpurple: c.DARK_PURPLE,
darkred: c.DARK_RED,
gold: c.GOLD,
gray: c.GRAY,
green: c.GREEN,
italic: c.ITALIC,
lightpurple: c.LIGHT_PURPLE,
indigo: c.BLUE,
green: c.GREEN,
red: c.RED,
pink: c.LIGHT_PURPLE,
yellow: c.YELLOW,
white: c.WHITE,
strike: c.STRIKETHROUGH,
random: c.MAGIC,
magic: c.MAGIC,
underline: c.UNDERLINE,
reset: c.RESET
};
for (var method in formattingCodes){
String.prototype[method] = function(m,c){
return function(){ return "§"+c + this;};
}(method,formattingCodes[method]);
String.prototype[method] = function(c){
return function(){return c+this;};
}(formattingCodes[method]);
}
}());