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

Annotation of /miscJava/bukkit-minecraft-plugins/HoerupUtils/src/main/java/dk/thoerup/bukkit/hoeruputils/LogintimeHandler.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3201 - (hide annotations) (download)
Wed May 31 08:56:00 2017 UTC (7 years ago) by torben
File size: 1578 byte(s)
Code cleanup(still doesn't compile)
1 torben 1667 package dk.thoerup.bukkit.hoeruputils;
2    
3 torben 3201 import java.io.File;
4     import java.io.IOException;
5 torben 1667
6 torben 3201 import org.bukkit.configuration.Configuration;
7     import org.bukkit.configuration.file.FileConfiguration;
8     import org.bukkit.configuration.file.YamlConfiguration;
9     import org.bukkit.event.EventHandler;
10     import org.bukkit.event.Listener;
11     import org.bukkit.event.player.PlayerLoginEvent;
12     import org.bukkit.event.player.PlayerQuitEvent;
13 torben 1667
14    
15 torben 1680 public class LogintimeHandler implements Listener {
16 torben 1667
17     static final String FILENAME = "logintime.yml";
18    
19     FileConfiguration config = new YamlConfiguration();
20    
21     File pluginFolder;
22    
23     public LogintimeHandler( File pluginFolder) {
24     this.pluginFolder = pluginFolder;
25    
26     loadTimes();
27     }
28    
29     Configuration getConfig() {
30     return config;
31     }
32    
33 torben 1680 @EventHandler
34 torben 1667 public void onPlayerLogin(PlayerLoginEvent event) {
35     config.set( event.getPlayer().getName() + ".logintime", System.currentTimeMillis() );
36     saveTimes();
37     }
38    
39 torben 1680 @EventHandler
40 torben 1667 public void onPlayerQuit(PlayerQuitEvent event) {
41     config.set( event.getPlayer().getName() + ".logintime", null);
42     saveTimes();
43     }
44    
45     protected void loadTimes() {
46     File file = new File(pluginFolder, FILENAME);
47     if (file.exists() ) {
48     try {
49     config.load(file);
50     } catch (Exception e) {
51     System.out.println("[HoerupUtils] Could not load logintime.yml " + e.getMessage() );
52     }
53     }
54     }
55    
56     protected void saveTimes() {
57     File file = new File(pluginFolder, FILENAME);
58     try {
59     config.save(file);
60     } catch (IOException e) {
61     System.out.println("[HoerupUtils] Could not save logintime.yml " + e.getMessage() );
62     }
63     }
64    
65     }

  ViewVC Help
Powered by ViewVC 1.1.20