package net.ghostrealms;

import com.thoughtworks.xstream.XStream;

import org.bukkit.plugin.java.JavaPlugin;

import java.io.File;


public class Metro extends JavaPlugin {
  
    private static XStream xstream = new XStream();
    private static RealmsEconomy econ = null;
    private static Register register = null;
    private static JavaPlugin plugin = null;
    
    private Database db = null;
    
    @Override
    public void onLoad() {
        plugin = this;
        db = new Database("metro", this);
    }

    @Override
    public void onEnable() {
      db.execute("CREATE TABLE IF NOT EXISTS residents (" 
                   + "id VARCHAR(36) NOT NULL PRIMARY KEY," 
                   + "name VARCHAR(16) NOT NULL," 
                   + "last_seen TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP()," 
                   + "joined TIMESTAMP NOT NULL," 
                   + "town INT(3)," 
                   + "friends TEXT);");
      db.execute("CREATE TABLE IF NOT EXISTS plots ("
                   + "id INT(16) NOT NULL AUTO_INCREMENT PRIMARY KEY," 
                   + "x INT(4) NOT NULL," 
                   + "y INT(4) NOT NULL," 
                   + "owner VARCHAR(36) NOT NULL," 
                   + "townOwned BOOL NOT NULL DEFAULT 0," 
                   + "town INT(3) NOT NULL default '-1'," 
                   + "users TEXT," 
                   + "flags TEXT"
                   + ");");
      db.execute("CREATE TABLE IF NOT EXISTS requests (" 
                   + "id VARCHAR(36) NOT NULL PRIMARY KEY," 
                   + "type INT(2) NOT NULL," 
                   + "data TEXT NOT NULL," 
                   + "time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP()"
                   + ");");
      db.execute("CREATE TABLE IF NOT EXISTS town_map (" 
                   + "id INT(3) NOT NULL PRIMARY KEY," 
                   + "name VARCHAR(20) NOT NULL"
                   + ");");
        
      econ = new RealmsEconomy(this);
      register = new Register(this, db);
      
      register.loadTowns();
    }

    @Override
    public void onDisable() {
      db.close();
      register.saveTowns();
    }
    
    public static RealmsEconomy getEconomy() {
        return econ;
    }
    
    public static Register getRegister() {
        return register;
    }
    
    public static JavaPlugin plugin() {
        return plugin;
    }

    public static XStream xstream() {
      return xstream;
    }

}

@@ -115,20 +115,48 @@
 ort 
-java.io.File
+lombok.AccessLevel;%0Aimport lombok.Getter
 ;%0A%0A%0A
@@ -198,16 +198,28 @@
 in %7B%0A  %0A
+    @Getter%0A
     priv
@@ -258,24 +258,37 @@
  XStream();%0A
+    @Getter %0A
     private 
@@ -313,32 +313,44 @@
 my econ = null;%0A
+    @Getter%0A
     private stat
@@ -374,24 +374,36 @@
 ter = null;%0A
+    @Getter%0A
     private 
@@ -435,24 +435,52 @@
 = null;%0A    
+@Getter(AccessLevel.PACKAGE)
 %0A    private
@@ -480,16 +480,23 @@
 private 
+static 
 Database
@@ -1682,11 +1682,8 @@
  INT
-(2)
  NOT
@@ -1681,33 +1681,32 @@
 e INT NOT NULL,%22
- 
 %0A               
@@ -2215,13 +2215,13 @@
  db.
-close
+flush
 ();%0A
@@ -2263,166 +2263,8 @@
    %0A
-    public static RealmsEconomy getEconomy() %7B%0A        return econ;%0A    %7D%0A    %0A    public static Register getRegister() %7B%0A        return register;%0A    %7D%0A    %0A
     
@@ -2363,24 +2363,24 @@
 xstream() %7B%0A
-
       return
@@ -2394,12 +2394,78 @@
 m;%0A    %7D
+%0A  %0A    public static Database database() %7B%0A      return db;%0A    %7D
 %0A%0A%7D%0A

update a database method call