Skip to content

Commit

Permalink
Update Main.
Browse files Browse the repository at this point in the history
  • Loading branch information
caoli5288 committed Jul 8, 2015
1 parent 390f785 commit a3e20f5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 32 deletions.
24 changes: 16 additions & 8 deletions src/main/java/com/mengcraft/playersql/Main.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.mengcraft.playersql;

import java.io.IOException;
import java.sql.Connection;
import java.sql.Statement;
import java.util.LinkedList;
Expand All @@ -9,6 +10,7 @@
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitScheduler;
import org.mcstats.Metrics;

import com.mengcraft.playersql.SyncManager.State;
import com.mengcraft.playersql.jdbc.ConnectionFactory;
Expand Down Expand Up @@ -36,7 +38,7 @@ public void onEnable() {
} catch (Exception e) {
throw new RuntimeException(e);
}

exp = new ExpUtilHandler(this).handle();
manager = new SyncManager(this);

Expand All @@ -47,6 +49,7 @@ public void onEnable() {
getConfig().getString("plugin.password"));
ConnectionManager manager = ConnectionManager.DEFAULT;
ConnectionHandler handler = manager.getHandler("playersql", factory);

try {
Connection connection = handler.getConnection();
String sql = "CREATE TABLE IF NOT EXISTS PlayerData("
Expand All @@ -59,21 +62,26 @@ public void onEnable() {
Statement action = connection.createStatement();
action.executeUpdate(sql);
action.close();

handler.release(connection);
scheduler().runTask(this, new MetricsTask(this));
scheduler().runTaskTimer(this, new TimerCheckTask(this), 0, 0);
register(new Events(this), this);
} catch (Exception e) {
getLogger().warning("Unable to connect to database.");
setEnabled(false);
throw new RuntimeException(e);
}

scheduler().runTaskTimer(this, new TimerCheckTask(this), 0, 0);
register(new Events(this));

DataCompound compond = DataCompound.DEFAULT;
for (Player p : getServer().getOnlinePlayers()) {
UUID uuid = p.getUniqueId();
compond.state(uuid, State.JOIN_WAIT);
new LoadTask(uuid).run();
}
try {
new Metrics(this).start();
} catch (IOException e) {
getLogger().warning(e.toString());
}
enable = true;
}

Expand All @@ -99,8 +107,8 @@ public BukkitScheduler scheduler() {
return getServer().getScheduler();
}

private void register(Events events, Main main) {
getServer().getPluginManager().registerEvents(events, main);
private void register(Events events) {
getServer().getPluginManager().registerEvents(events, this);
}

public void info(String string) {
Expand Down
24 changes: 0 additions & 24 deletions src/main/java/com/mengcraft/playersql/MetricsTask.java

This file was deleted.

0 comments on commit a3e20f5

Please sign in to comment.