--- miscJava/bukkit-minecraft-plugins/HoerupUtils/src/main/java/dk/thoerup/bukkit/hoeruputils/MotdHandler.java 2012/09/23 12:09:50 1849 +++ miscJava/bukkit-minecraft-plugins/HoerupUtils/src/main/java/dk/thoerup/bukkit/hoeruputils/MotdHandler.java 2012/09/23 12:30:09 1850 @@ -19,9 +19,8 @@ import java.io.IOException; import java.io.File; -import java.io.RandomAccessFile; - +import java.io.*; public class MotdHandler implements Listener, CommandExecutor { @@ -31,22 +30,27 @@ this.plugin = plugin; } + private String colors(String str) { + return ChatColor.translateAlternateColorCodes('&', str ); + } + private void readMotdFile(CommandSender player) { File motd = new File(plugin.getDataFolder(), "motd.txt"); if (motd.exists()) { try { - RandomAccessFile raf = new RandomAccessFile(motd,"r"); + BufferedReader in = new BufferedReader( new InputStreamReader( new FileInputStream( motd) ) ); String line; - while ( (line=raf.readLine()) != null) { + while ( (line=in.readLine()) != null) { line = line.trim(); if (line.startsWith("#")) { continue; } if (line.length() > 0) { + line = colors(line); player.sendMessage( line ); } } - raf.close(); + in.close(); } catch (IOException e) { plugin.getLogger().severe("Could not read motd.txt:" + e.getMessage() ); }