This commit is contained in:
boy0001 2015-02-20 15:32:40 +11:00
parent d836286b6f
commit d11679aa1e
3 changed files with 11 additions and 10 deletions

View File

@ -16,6 +16,7 @@ import com.intellectualcrafters.plot.database.SQLManager;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.util.PlayerFunctions; import com.intellectualcrafters.plot.util.PlayerFunctions;
import com.intellectualcrafters.plot.util.StringComparison; import com.intellectualcrafters.plot.util.StringComparison;
import com.intellectualcrafters.plot.util.TaskManager;
import com.intellectualcrafters.plot.util.UUIDHandler; import com.intellectualcrafters.plot.util.UUIDHandler;
/** /**
@ -46,9 +47,8 @@ public class Database extends SubCommand {
} }
public static void insertPlots(final SQLManager manager, final UUID requester, final Connection c) { public static void insertPlots(final SQLManager manager, final UUID requester, final Connection c) {
final Plugin p = PlotSquared.getMain();
final java.util.Set<Plot> plots = PlotSquared.getPlots(); final java.util.Set<Plot> plots = PlotSquared.getPlots();
p.getServer().getScheduler().runTaskAsynchronously(p, new Runnable() { TaskManager.runTaskAsync(new Runnable() {
@Override @Override
public void run() { public void run() {
try { try {
@ -94,7 +94,7 @@ public class Database extends SubCommand {
} }
Connection n; Connection n;
try { try {
n = new MySQL(PlotSquared.getMain(), host, port, database, username, password).openConnection(); n = new MySQL(PlotSquared.THIS, host, port, database, username, password).openConnection();
// Connection // Connection
if (n.isClosed()) { if (n.isClosed()) {
return sendMessage(plr, "Failed to open connection"); return sendMessage(plr, "Failed to open connection");

View File

@ -49,6 +49,7 @@ import com.intellectualcrafters.plot.object.PlotClusterId;
import com.intellectualcrafters.plot.object.PlotComment; import com.intellectualcrafters.plot.object.PlotComment;
import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.util.ClusterManager; import com.intellectualcrafters.plot.util.ClusterManager;
import com.intellectualcrafters.plot.util.TaskManager;
import com.intellectualcrafters.plot.util.bukkit.BukkitTaskManager; import com.intellectualcrafters.plot.util.bukkit.BukkitTaskManager;
/** /**
@ -92,7 +93,7 @@ public class SQLManager implements AbstractDB {
// schedule reconnect // schedule reconnect
if (PlotSquared.getMySQL() != null) { if (PlotSquared.getMySQL() != null) {
Bukkit.getScheduler().runTaskTimer(PlotSquared.getMain(), new Runnable() { TaskManager.runTaskRepeat(new Runnable() {
@Override @Override
public void run() { public void run() {
try { try {
@ -101,7 +102,7 @@ public class SQLManager implements AbstractDB {
e.printStackTrace(); e.printStackTrace();
} }
} }
}, 11000, 11000); }, 11000);
} }
} }
@ -1078,7 +1079,7 @@ public class SQLManager implements AbstractDB {
String comparison = below ? ">=" : "="; String comparison = below ? ">=" : "=";
if (plot != null) { if (plot != null) {
statement = this.connection.prepareStatement("SELECT * FROM `" + this.prefix + "plot_comments` WHERE `plot_plot_id` = ? AND `tier` " + comparison + " ?"); statement = this.connection.prepareStatement("SELECT * FROM `" + this.prefix + "plot_comments` WHERE `plot_plot_id` = ? AND `tier` " + comparison + " ?");
statement.setInt(1, getId(plot.world.getName(), plot.id)); statement.setInt(1, getId(plot.world, plot.id));
statement.setInt(2, tier); statement.setInt(2, tier);
} }
else { else {
@ -1284,7 +1285,7 @@ public class SQLManager implements AbstractDB {
public double getRatings(final Plot plot) { public double getRatings(final Plot plot) {
try { try {
final PreparedStatement statement = this.connection.prepareStatement("SELECT AVG(`rating`) AS `rating` FROM `" + this.prefix + "plot_ratings` WHERE `plot_plot_id` = ? "); final PreparedStatement statement = this.connection.prepareStatement("SELECT AVG(`rating`) AS `rating` FROM `" + this.prefix + "plot_ratings` WHERE `plot_plot_id` = ? ");
statement.setInt(1, getId(plot.world.getName(), plot.id)); statement.setInt(1, getId(plot.world, plot.id));
final ResultSet set = statement.executeQuery(); final ResultSet set = statement.executeQuery();
double rating = 0; double rating = 0;
while (set.next()) { while (set.next()) {

View File

@ -59,15 +59,15 @@ public class SQLite extends Database {
if (checkConnection()) { if (checkConnection()) {
return this.connection; return this.connection;
} }
if (!this.plotsquared.IMP.getDirectory().exists()) { if (!PlotSquared.IMP.getDirectory().exists()) {
this.plugin.getDataFolder().mkdirs(); PlotSquared.IMP.getDirectory().mkdirs();
} }
final File file = new File(this.dbLocation); final File file = new File(this.dbLocation);
if (!(file.exists())) { if (!(file.exists())) {
try { try {
file.createNewFile(); file.createNewFile();
} catch (final IOException e) { } catch (final IOException e) {
this.plugin.getLogger().log(Level.SEVERE, "Unable to create database!"); PlotSquared.log("&cUnable to create database!");
} }
} }
Class.forName("org.sqlite.JDBC"); Class.forName("org.sqlite.JDBC");