/[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 1847 by torben, Sat Sep 15 09:35:24 2012 UTC revision 2255 by torben, Fri Jan 2 09:57:38 2015 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.util.Collection;
24    import java.io.*;
25    
26  public class MotdHandler implements Listener, CommandExecutor {  public class MotdHandler implements Listener, CommandExecutor {
27    
# Line 31  public class MotdHandler implements List Line 31  public class MotdHandler implements List
31                  this.plugin = plugin;                  this.plugin = plugin;
32          }          }
33    
34            private String colors(String str) {
35                    return ChatColor.translateAlternateColorCodes('&', str );
36            }
37    
38          private void readMotdFile(CommandSender player) {          private void readMotdFile(CommandSender player) {
39                  File motd = new File(plugin.getDataFolder(), "motd.txt");                  File motd = new File(plugin.getDataFolder(), "motd.txt");
40                  if (motd.exists()) {                  if (motd.exists()) {
41                          try {                          try {
42                                  RandomAccessFile raf = new RandomAccessFile(motd,"r");                                  BufferedReader in = new BufferedReader( new InputStreamReader( new FileInputStream( motd) ) );
43                                  String line;                                  String line;
44                                  while ( (line=raf.readLine()) != null) {                                  while ( (line=in.readLine()) != null) {
45                                          line = line.trim();                                          line = line.trim();
46                                          if (line.startsWith("#")) {                                          if (line.startsWith("#")) {
47                                                  continue;                                                  continue;
48                                          }                                          }
49                                          if (line.length() > 0) {                                          if (line.length() > 0) {
50                                                    line = colors(line);
51                                                  player.sendMessage( line );                                                  player.sendMessage( line );
52                                          }                                          }
53                                  }                                  }
54                                  raf.close();                                  in.close();
55                          } catch (IOException e) {                          } catch (IOException e) {
56                                  plugin.getLogger().severe("Could not read motd.txt:" + e.getMessage() );                                  plugin.getLogger().severe("Could not read motd.txt:" + e.getMessage() );
57                          }                          }
# Line 67  public class MotdHandler implements List Line 72  public class MotdHandler implements List
72                  //////////////////////////////////////////////////////                  //////////////////////////////////////////////////////
73    
74    
                 Player players[] = plugin.getServer().getOnlinePlayers();  
75    
76                  StringBuilder sb = new StringBuilder();                  StringBuilder sb = new StringBuilder();
77                  for (Player player : players) {                  for (Player player : plugin.getServer().getOnlinePlayers() ) {
78                          sb.append(", ");                          sb.append(", ");
79                          sb.append( player.getName() );                          sb.append( player.getName() );
80                  }                  }

Legend:
Removed from v.1847  
changed lines
  Added in v.2255

  ViewVC Help
Powered by ViewVC 1.1.20