From 0fa8a6cc03ce79256615053239ab17310d097922 Mon Sep 17 00:00:00 2001 From: aPunch Date: Mon, 6 Feb 2012 05:55:29 -0600 Subject: [PATCH] proper color-parsing for names --- TODO | 2 -- lib/CitizensAPI.jar | Bin 23480 -> 23756 bytes .../command/command/NPCCommands.java | 4 ++-- .../npc/entity/CitizensHumanNPC.java | 5 +++-- src/net/citizensnpcs/util/Messaging.java | 7 +------ src/net/citizensnpcs/util/StringHelper.java | 7 +++++++ 6 files changed, 13 insertions(+), 12 deletions(-) diff --git a/TODO b/TODO index c54722140..58427c9e8 100644 --- a/TODO +++ b/TODO @@ -1,7 +1,5 @@ -Citizens2 TODO List- --Better inventory handling/saving --Add proper color parsing for names -Add NPC templates -Finish pathfinding API -Add database support (MySQL and/or SQLite) \ No newline at end of file diff --git a/lib/CitizensAPI.jar b/lib/CitizensAPI.jar index d518fa676971d94c104842f9c4793b09b7cfc8bb..b1675fedb298a3b497aecaab2652dd5ec3d69ae9 100644 GIT binary patch delta 5201 zcmZWtWmHsMxSkn=k9LrfkdC2yNI^hCYUmz9O1ewHK^m2uPmq=v7*ayIq+0|5kw&^f zLZrMnc<)-?@BBE=yPy5m-s_yb)_&@0frIrxB287STlj$Aj~AC>0ucnu^BTlnVErC- z(PLnZ`!^sdfczMI1cYLcAH;?P>*D{N0oe)^#>}1oMgMq7V9*)#;5Sy4gC;>3<0W<~ z7RG?!c>ys-7C!CGR0|=;jj>7Gb~9B59=%~gN&Rk^E3zOU$#ud9Fvjr+Rw4j^k`4gi zL?)2lMV1@gLZT_|AdK+*$X2MHwGQomwDrXWpDnf1CI+g7+cBWs}gDLDQr>Q7A zp^(CR2Gr*<>lV<=C?9Gp^^nos)49BadunMR#Y&mb=`1|vdeNy=e!-O0so1=fnC@?1 zPpfSOk+e}ZIo%JW`W40!!8=;R`APYGbEJOAZs`}ieDUKM>OIJS*De*$n4LQ-ZH>X= z_XZ{|;D|eCX-j>6H46O24ME&Xsb(*n)sIu~J3pF>X5&;C@qTG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RE zRlL;r+g@_avb$N~k}xBZ7os@RUNj2SKR{WUd3w=6ZLiaP--$4|;Uljm6H%N>b4!QU zlU@^hpj=PhToopJiB6(aaQuSrLF|)baTSR(RC3f@@F_f}@7cL!FU5izhCj!q-#RQTt2TpY$7j=^Bt1elWSqDYx@UOj)^`H`LwVQUQZ$Pk zcQ5yG{I4xc>w;IIs=DZxDyp5ziu+d(Q1Ptb+t=~~5aF7_vits2@mBavE!Q|E-g?Lu zfK7JE<0HS*ekLH1QpelilC3LwBS+RUZqVI&JQQ}_yNhKDQ(rAZ*Ear#LNh#j#tglGD&(d`# z%j@!vl&wwoZ|Z-yBZpv9o>20s8$K^Wbh9UB`j#luX^0+A$c-*bSsH64&DwE((je`$tO8yzk45eC|5=I;*0F~qG7rG-FLKz)%kE6`&@ z-qfv-Om@-@K&u>qU5!=moLX=AbzXG>v4=6ShdB7ms4X0zRsVP*dwisR+Tst=1qL>C zy&QBJ%%NapAhWDr0y031@ddC&uQ3utC|U|cd9*5s7_`R813)Vp1>zsH9*71eSHL`A zqWzag0Q)9VU@T^e26K_7CLoTR8iL4YW^>A$If1%&W_IAcnz=cM>E@^T9dmmyZ*1XA z`|m*m@XSJw_hga(`A3|bocz5?qo&RQE>Z|U(~&)<41U2Ga ztPs#E5~tL81i)nt2YX9cBcL*pL|PgMvxf7YydBx}nq>#E6dSR(+CL?YrGO{}C1Amt z8Qds7G=)9)VGsx>B?O`eWLj$j!!pc(y$u{(EFT*L)I^^6fZ7QK4*O16VZVh~QHEGq z;-AV=%D`6}WpE-%TLe^6g*Xu(fK_Gr|8glrx=4i;budkDKn}#%v4e9J6KPG&|EF^ 16) { + if (name.length() > 16) { Messaging.sendError(player, "NPC names cannot be longer than 16 characters. The name has been shortened."); name = name.substring(0, 15); } @@ -55,7 +55,7 @@ public class NPCCommands { Messaging.sendError(player, "'" + args.getString(2) + "' is not a valid mob type. Using default NPC."); } NPC create = npcManager.createNPC(type, name); - String successMsg = ChatColor.GREEN + "You created " + StringHelper.wrap(create.getName()); + String successMsg = ChatColor.GREEN + "You created " + create.getName(); boolean success = true; if (args.argsLength() == 4) { if (characterManager.getInstance(args.getString(3), create) == null) { diff --git a/src/net/citizensnpcs/npc/entity/CitizensHumanNPC.java b/src/net/citizensnpcs/npc/entity/CitizensHumanNPC.java index 54a0f9633..2a88f098d 100644 --- a/src/net/citizensnpcs/npc/entity/CitizensHumanNPC.java +++ b/src/net/citizensnpcs/npc/entity/CitizensHumanNPC.java @@ -3,6 +3,7 @@ package net.citizensnpcs.npc.entity; import net.citizensnpcs.npc.CitizensNPC; import net.citizensnpcs.npc.CitizensNPCManager; import net.citizensnpcs.resource.lib.EntityHumanNPC; +import net.citizensnpcs.util.StringHelper; import net.minecraft.server.EntityLiving; import net.minecraft.server.ItemInWorldManager; import net.minecraft.server.WorldServer; @@ -31,8 +32,8 @@ public class CitizensHumanNPC extends CitizensNPC { @Override protected EntityLiving createHandle(Location loc) { WorldServer ws = ((CraftWorld) loc.getWorld()).getHandle(); - EntityHumanNPC handle = new EntityHumanNPC(ws.getServer().getServer(), ws, getFullName(), - new ItemInWorldManager(ws)); + EntityHumanNPC handle = new EntityHumanNPC(ws.getServer().getServer(), ws, + StringHelper.parseColors(getFullName()), new ItemInWorldManager(ws)); handle.removeFromPlayerMap(getFullName()); handle.setPositionRotation(loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch()); return handle; diff --git a/src/net/citizensnpcs/util/Messaging.java b/src/net/citizensnpcs/util/Messaging.java index 82cdff8ec..a6f029255 100644 --- a/src/net/citizensnpcs/util/Messaging.java +++ b/src/net/citizensnpcs/util/Messaging.java @@ -28,12 +28,7 @@ public class Messaging { } public static void send(Player player, Object msg) { - String send = msg.toString(); - - for (ChatColor color : ChatColor.values()) - send = send.replace("<" + color.getChar() + ">", color.toString()); - - player.sendMessage(send); + player.sendMessage(StringHelper.parseColors(msg.toString())); } public static void sendError(Player player, Object msg) { diff --git a/src/net/citizensnpcs/util/StringHelper.java b/src/net/citizensnpcs/util/StringHelper.java index 34a737d5e..7914b1dc6 100644 --- a/src/net/citizensnpcs/util/StringHelper.java +++ b/src/net/citizensnpcs/util/StringHelper.java @@ -56,4 +56,11 @@ public class StringHelper { public static String wrap(Object string) { return ChatColor.YELLOW + string.toString() + ChatColor.GREEN; } + + public static String parseColors(Object string) { + String parsed = string.toString(); + for (ChatColor color : ChatColor.values()) + parsed = parsed.replace("<" + color.getChar() + ">", color.toString()); + return parsed; + } } \ No newline at end of file