/[projects]/miscJava/bukkit-minecraft-plugins/HoerupUtils/src/main/java/dk/thoerup/bukkit/hoeruputils/MotdHandler.java
ViewVC logotype

Diff of /miscJava/bukkit-minecraft-plugins/HoerupUtils/src/main/java/dk/thoerup/bukkit/hoeruputils/MotdHandler.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1849 by torben, Sat Sep 15 09:35:24 2012 UTC revision 1850 by torben, Sun Sep 23 12:30:09 2012 UTC
# Line 19  import org.bukkit.command.CommandSender; Line 19  import org.bukkit.command.CommandSender;
19    
20  import java.io.IOException;  import java.io.IOException;
21  import java.io.File;  import java.io.File;
 import java.io.RandomAccessFile;  
   
22    
23    import java.io.*;
24    
25  public class MotdHandler implements Listener, CommandExecutor {  public class MotdHandler implements Listener, CommandExecutor {
26    
# Line 31  public class MotdHandler implements List Line 30  public class MotdHandler implements List
30                  this.plugin = plugin;                  this.plugin = plugin;
31          }          }
32    
33            private String colors(String str) {
34                    return ChatColor.translateAlternateColorCodes('&', str );
35            }
36    
37          private void readMotdFile(CommandSender player) {          private void readMotdFile(CommandSender player) {
38                  File motd = new File(plugin.getDataFolder(), "motd.txt");                  File motd = new File(plugin.getDataFolder(), "motd.txt");
39                  if (motd.exists()) {                  if (motd.exists()) {
40                          try {                          try {
41                                  RandomAccessFile raf = new RandomAccessFile(motd,"r");                                  BufferedReader in = new BufferedReader( new InputStreamReader( new FileInputStream( motd) ) );
42                                  String line;                                  String line;
43                                  while ( (line=raf.readLine()) != null) {                                  while ( (line=in.readLine()) != null) {
44                                          line = line.trim();                                          line = line.trim();
45                                          if (line.startsWith("#")) {                                          if (line.startsWith("#")) {
46                                                  continue;                                                  continue;
47                                          }                                          }
48                                          if (line.length() > 0) {                                          if (line.length() > 0) {
49                                                    line = colors(line);
50                                                  player.sendMessage( line );                                                  player.sendMessage( line );
51                                          }                                          }
52                                  }                                  }
53                                  raf.close();                                  in.close();
54                          } catch (IOException e) {                          } catch (IOException e) {
55                                  plugin.getLogger().severe("Could not read motd.txt:" + e.getMessage() );                                  plugin.getLogger().severe("Could not read motd.txt:" + e.getMessage() );
56                          }                          }

Legend:
Removed from v.1849  
changed lines
  Added in v.1850

  ViewVC Help
Powered by ViewVC 1.1.20