mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-22 18:45:29 +01:00
proper color-parsing for names
This commit is contained in:
parent
0e3f29c6f8
commit
68cc28eb05
2
TODO
2
TODO
@ -1,7 +1,5 @@
|
|||||||
-Citizens2 TODO List-
|
-Citizens2 TODO List-
|
||||||
|
|
||||||
-Better inventory handling/saving
|
|
||||||
-Add proper color parsing for names
|
|
||||||
-Add NPC templates
|
-Add NPC templates
|
||||||
-Finish pathfinding API
|
-Finish pathfinding API
|
||||||
-Add database support (MySQL and/or SQLite)
|
-Add database support (MySQL and/or SQLite)
|
Binary file not shown.
@ -43,7 +43,7 @@ public class NPCCommands {
|
|||||||
@Requirements
|
@Requirements
|
||||||
public void createNPC(CommandContext args, Player player, NPC npc) {
|
public void createNPC(CommandContext args, Player player, NPC npc) {
|
||||||
String name = args.getString(1);
|
String name = args.getString(1);
|
||||||
if (args.getString(1).length() > 16) {
|
if (name.length() > 16) {
|
||||||
Messaging.sendError(player, "NPC names cannot be longer than 16 characters. The name has been shortened.");
|
Messaging.sendError(player, "NPC names cannot be longer than 16 characters. The name has been shortened.");
|
||||||
name = name.substring(0, 15);
|
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.");
|
Messaging.sendError(player, "'" + args.getString(2) + "' is not a valid mob type. Using default NPC.");
|
||||||
}
|
}
|
||||||
NPC create = npcManager.createNPC(type, name);
|
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;
|
boolean success = true;
|
||||||
if (args.argsLength() == 4) {
|
if (args.argsLength() == 4) {
|
||||||
if (characterManager.getInstance(args.getString(3), create) == null) {
|
if (characterManager.getInstance(args.getString(3), create) == null) {
|
||||||
|
@ -3,6 +3,7 @@ package net.citizensnpcs.npc.entity;
|
|||||||
import net.citizensnpcs.npc.CitizensNPC;
|
import net.citizensnpcs.npc.CitizensNPC;
|
||||||
import net.citizensnpcs.npc.CitizensNPCManager;
|
import net.citizensnpcs.npc.CitizensNPCManager;
|
||||||
import net.citizensnpcs.resource.lib.EntityHumanNPC;
|
import net.citizensnpcs.resource.lib.EntityHumanNPC;
|
||||||
|
import net.citizensnpcs.util.StringHelper;
|
||||||
import net.minecraft.server.EntityLiving;
|
import net.minecraft.server.EntityLiving;
|
||||||
import net.minecraft.server.ItemInWorldManager;
|
import net.minecraft.server.ItemInWorldManager;
|
||||||
import net.minecraft.server.WorldServer;
|
import net.minecraft.server.WorldServer;
|
||||||
@ -31,8 +32,8 @@ public class CitizensHumanNPC extends CitizensNPC {
|
|||||||
@Override
|
@Override
|
||||||
protected EntityLiving createHandle(Location loc) {
|
protected EntityLiving createHandle(Location loc) {
|
||||||
WorldServer ws = ((CraftWorld) loc.getWorld()).getHandle();
|
WorldServer ws = ((CraftWorld) loc.getWorld()).getHandle();
|
||||||
EntityHumanNPC handle = new EntityHumanNPC(ws.getServer().getServer(), ws, getFullName(),
|
EntityHumanNPC handle = new EntityHumanNPC(ws.getServer().getServer(), ws,
|
||||||
new ItemInWorldManager(ws));
|
StringHelper.parseColors(getFullName()), new ItemInWorldManager(ws));
|
||||||
handle.removeFromPlayerMap(getFullName());
|
handle.removeFromPlayerMap(getFullName());
|
||||||
handle.setPositionRotation(loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch());
|
handle.setPositionRotation(loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch());
|
||||||
return handle;
|
return handle;
|
||||||
|
@ -28,12 +28,7 @@ public class Messaging {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void send(Player player, Object msg) {
|
public static void send(Player player, Object msg) {
|
||||||
String send = msg.toString();
|
player.sendMessage(StringHelper.parseColors(msg.toString()));
|
||||||
|
|
||||||
for (ChatColor color : ChatColor.values())
|
|
||||||
send = send.replace("<" + color.getChar() + ">", color.toString());
|
|
||||||
|
|
||||||
player.sendMessage(send);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void sendError(Player player, Object msg) {
|
public static void sendError(Player player, Object msg) {
|
||||||
|
@ -56,4 +56,11 @@ public class StringHelper {
|
|||||||
public static String wrap(Object string) {
|
public static String wrap(Object string) {
|
||||||
return ChatColor.YELLOW + string.toString() + ChatColor.GREEN;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user