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 |
|
|
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 |
} |
} |