Facebook
From Paltry Dormouse, 5 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 233
  1. public class ChatUtil
  2. {
  3.     public static void sendMsg(final Player p, final String msg) {
  4.         p.sendMessage(fixColor(msg).replace("{NICK}", p.getName()));
  5.     }
  6.    
  7.     public static void sendMsgS(final CommandSender sender, final String msg) {
  8.         sender.sendMessage(fixColor(msg).replace("{NICK}", sender.getName()));
  9.     }
  10.    
  11.     public static String fixColor(final String text) {
  12.         return text.replace(">>", "»").replace("<<", "«").replace("&", "§");
  13.     }
  14.    
  15.     public static boolean isInteger(final String string) {
  16.         return Pattern.matches("-?[0-9]+", string.subSequence(0, string.length()));
  17.     }
  18.    
  19.     public static String locToString(final double x, final double y, final double z) {
  20.         return String.valueOf(String.valueOf(x)) + ":" + y + ":" + z + ":" + 0.0f + ":" + 0.0f;
  21.     }
  22.    
  23.     public static String locToString(final Location loc) {
  24.         return String.valueOf(String.valueOf(loc.getX())) + ":" + loc.getY() + ":" + loc.getZ() + ":" + loc.getYaw() + ":" + loc.getPitch();
  25.     }
  26.    
  27.     public static Location locFromString(final String str) {
  28.         final String[] str2loc = str.split(":");
  29.         final Location loc = new Location((World)Bukkit.getWorlds().get(0), 0.0, 0.0, 0.0, 0.0f, 0.0f);
  30.         loc.setX(Double.parseDouble(str2loc[0]));
  31.         loc.setY(Double.parseDouble(str2loc[1]));
  32.         loc.setZ(Double.parseDouble(str2loc[2]));
  33.         loc.setYaw(Float.parseFloat(str2loc[3]));
  34.         loc.setPitch(Float.parseFloat(str2loc[4]));
  35.         return loc;
  36.     }
  37. }