1 |
package dk.thoerup.bukkit.hoeruputils; |
2 |
|
3 |
import java.io.*; |
4 |
|
5 |
import org.bukkit.*; |
6 |
import org.bukkit.event.*; |
7 |
import org.bukkit.event.player.*; |
8 |
|
9 |
import org.bukkit.configuration.*; |
10 |
import org.bukkit.configuration.file.*; |
11 |
|
12 |
|
13 |
public class LogintimeHandler extends PlayerListener { |
14 |
|
15 |
static final String FILENAME = "logintime.yml"; |
16 |
|
17 |
FileConfiguration config = new YamlConfiguration(); |
18 |
|
19 |
File pluginFolder; |
20 |
|
21 |
public LogintimeHandler( File pluginFolder) { |
22 |
this.pluginFolder = pluginFolder; |
23 |
|
24 |
loadTimes(); |
25 |
} |
26 |
|
27 |
Configuration getConfig() { |
28 |
return config; |
29 |
} |
30 |
|
31 |
public void onPlayerLogin(PlayerLoginEvent event) { |
32 |
config.set( event.getPlayer().getName() + ".logintime", System.currentTimeMillis() ); |
33 |
saveTimes(); |
34 |
} |
35 |
|
36 |
public void onPlayerQuit(PlayerQuitEvent event) { |
37 |
config.set( event.getPlayer().getName() + ".logintime", null); |
38 |
saveTimes(); |
39 |
} |
40 |
|
41 |
protected void loadTimes() { |
42 |
File file = new File(pluginFolder, FILENAME); |
43 |
if (file.exists() ) { |
44 |
try { |
45 |
config.load(file); |
46 |
} catch (Exception e) { |
47 |
System.out.println("[HoerupUtils] Could not load logintime.yml " + e.getMessage() ); |
48 |
} |
49 |
} |
50 |
} |
51 |
|
52 |
protected void saveTimes() { |
53 |
File file = new File(pluginFolder, FILENAME); |
54 |
try { |
55 |
config.save(file); |
56 |
} catch (IOException e) { |
57 |
System.out.println("[HoerupUtils] Could not save logintime.yml " + e.getMessage() ); |
58 |
} |
59 |
} |
60 |
|
61 |
} |