Database.java cleanup

This commit is contained in:
GJ 2012-03-07 01:42:43 -05:00
parent a8aed1bf02
commit 653e06dd03
7 changed files with 341 additions and 299 deletions

View File

@ -1,173 +1,164 @@
/*
This file is part of mcMMO.
mcMMO is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
mcMMO is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with mcMMO. If not, see <http://www.gnu.org/licenses/>.
* Copyright (C) 2012 Matt 'The Yeti' Burnett & mcMMO Development
* Copyright (C) 2010-2011 'nossr50'
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.gmail.nossr50;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.PreparedStatement;
import java.util.HashMap;
import java.util.ArrayList;
import java.sql.PreparedStatement;
import java.util.Properties;
import com.gmail.nossr50.config.LoadProperties;
import datatypes.DatabaseUpdate;
public class Database {
private mcMMO plugin;
private String connectionString = "jdbc:mysql://" + LoadProperties.MySQLserverName + ":" + LoadProperties.MySQLport + "/" + LoadProperties.MySQLdbName + "?user=" + LoadProperties.MySQLuserName + "&password=" + LoadProperties.MySQLdbPass;
private boolean isConnected = false;
private Connection conn = null;
public void connect()
{
try
{
System.out.println("[mcMMO] Attempting connection to MySQL...");
java.util.Properties conProperties = new java.util.Properties();
conProperties.put("autoReconnect", "true");
conProperties.put("maxReconnects", "3");
conn = DriverManager.getConnection(connectionString, conProperties);
isConnected = true;
System.out.println("[mcMMO] Connection to MySQL established!");
} catch (SQLException ex)
{
isConnected = false;
ex.printStackTrace();
System.out.println("SQLException: " + ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("VendorError: " + ex.getErrorCode());
}
}
public boolean isConnected()
{
return isConnected;
}
private mcMMO plugin;
private String connectionString = "jdbc:mysql://" + LoadProperties.MySQLserverName + ":" + LoadProperties.MySQLport + "/" + LoadProperties.MySQLdbName + "?user=" + LoadProperties.MySQLuserName + "&password=" + LoadProperties.MySQLdbPass;
private boolean isConnected;
private Connection conn = null;
public Database(mcMMO instance) {
connect(); //Connect to MySQL
this.plugin = instance;
// Load the driver instance
try {
Class.forName("com.mysql.jdbc.Driver");
DriverManager.getConnection(connectionString);
} catch (ClassNotFoundException e) {
plugin.getServer().getLogger().warning(e.getLocalizedMessage());
} catch (SQLException e) {
plugin.getServer().getLogger().warning(e.getLocalizedMessage());
System.out.println("SQLException: " + e.getMessage());
System.out.println("SQLState: " + e.getSQLState());
System.out.println("VendorError: " + e.getErrorCode());
}
}
//Create the DB structure
public void createStructure() {
Write("CREATE TABLE IF NOT EXISTS `" + LoadProperties.MySQLtablePrefix + "huds` (`user_id` int(10) unsigned NOT NULL,"
+ "`hudtype` varchar(50) NOT NULL DEFAULT '',"
+ "PRIMARY KEY (`user_id`)) ENGINE=MyISAM DEFAULT CHARSET=latin1;");
Write("CREATE TABLE IF NOT EXISTS `" + LoadProperties.MySQLtablePrefix + "users` (`id` int(10) unsigned NOT NULL AUTO_INCREMENT,"
+ "`user` varchar(40) NOT NULL,"
+ "`lastlogin` int(32) unsigned NOT NULL,"
+ "`party` varchar(100) NOT NULL DEFAULT '',"
+ "PRIMARY KEY (`id`),"
+ "UNIQUE KEY `user` (`user`)) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1;");
Write("CREATE TABLE IF NOT EXISTS `" + LoadProperties.MySQLtablePrefix + "cooldowns` (`user_id` int(10) unsigned NOT NULL,"
+ "`taming` int(32) unsigned NOT NULL DEFAULT '0',"
+ "`mining` int(32) unsigned NOT NULL DEFAULT '0',"
+ "`woodcutting` int(32) unsigned NOT NULL DEFAULT '0',"
+ "`repair` int(32) unsigned NOT NULL DEFAULT '0',"
+ "`unarmed` int(32) unsigned NOT NULL DEFAULT '0',"
+ "`herbalism` int(32) unsigned NOT NULL DEFAULT '0',"
+ "`excavation` int(32) unsigned NOT NULL DEFAULT '0',"
+ "`archery` int(32) unsigned NOT NULL DEFAULT '0',"
+ "`swords` int(32) unsigned NOT NULL DEFAULT '0',"
+ "`axes` int(32) unsigned NOT NULL DEFAULT '0',"
+ "`acrobatics` int(32) unsigned NOT NULL DEFAULT '0',"
+ "`blast_mining` int(32) unsigned NOT NULL DEFAULT '0',"
+ "PRIMARY KEY (`user_id`)) ENGINE=MyISAM DEFAULT CHARSET=latin1;");
Write("CREATE TABLE IF NOT EXISTS `" + LoadProperties.MySQLtablePrefix + "skills` (`user_id` int(10) unsigned NOT NULL,"
+ "`taming` int(10) unsigned NOT NULL DEFAULT '0',"
+ "`mining` int(10) unsigned NOT NULL DEFAULT '0',"
+ "`woodcutting` int(10) unsigned NOT NULL DEFAULT '0',"
+ "`repair` int(10) unsigned NOT NULL DEFAULT '0',"
+ "`unarmed` int(10) unsigned NOT NULL DEFAULT '0',"
+ "`herbalism` int(10) unsigned NOT NULL DEFAULT '0',"
+ "`excavation` int(10) unsigned NOT NULL DEFAULT '0',"
+ "`archery` int(10) unsigned NOT NULL DEFAULT '0',"
+ "`swords` int(10) unsigned NOT NULL DEFAULT '0',"
+ "`axes` int(10) unsigned NOT NULL DEFAULT '0',"
+ "`acrobatics` int(10) unsigned NOT NULL DEFAULT '0',"
+ "PRIMARY KEY (`user_id`)) ENGINE=MyISAM DEFAULT CHARSET=latin1;");
Write("CREATE TABLE IF NOT EXISTS `" + LoadProperties.MySQLtablePrefix + "experience` (`user_id` int(10) unsigned NOT NULL,"
+ "`taming` int(10) unsigned NOT NULL DEFAULT '0',"
+ "`mining` int(10) unsigned NOT NULL DEFAULT '0',"
+ "`woodcutting` int(10) unsigned NOT NULL DEFAULT '0',"
+ "`repair` int(10) unsigned NOT NULL DEFAULT '0',"
+ "`unarmed` int(10) unsigned NOT NULL DEFAULT '0',"
+ "`herbalism` int(10) unsigned NOT NULL DEFAULT '0',"
+ "`excavation` int(10) unsigned NOT NULL DEFAULT '0',"
+ "`archery` int(10) unsigned NOT NULL DEFAULT '0',"
+ "`swords` int(10) unsigned NOT NULL DEFAULT '0',"
+ "`axes` int(10) unsigned NOT NULL DEFAULT '0',"
+ "`acrobatics` int(10) unsigned NOT NULL DEFAULT '0',"
+ "PRIMARY KEY (`user_id`)) ENGINE=MyISAM DEFAULT CHARSET=latin1;");
Write("DROP TABLE IF EXISTS `"+LoadProperties.MySQLtablePrefix+"skills2`");
Write("DROP TABLE IF EXISTS `"+LoadProperties.MySQLtablePrefix+"experience2`");
Write("DROP TABLE IF EXISTS `"+LoadProperties.MySQLtablePrefix+"spawn`");
checkDatabaseStructure();
checkDatabaseStructureForBlastMining();
}
public Database(mcMMO instance) {
connect(); //Connect to MySQL
this.plugin = instance;
public void checkDatabaseStructure()
{
String sql = "SELECT * FROM `"+LoadProperties.MySQLtablePrefix+"experience` ORDER BY `"+LoadProperties.MySQLtablePrefix+"experience`.`fishing` ASC LIMIT 0 , 30";
ResultSet rs = null;
HashMap<Integer, ArrayList<String>> Rows = new HashMap<Integer, ArrayList<String>>();
try {
PreparedStatement stmt = conn.prepareStatement(sql);
if (stmt.executeQuery() != null) {
stmt.executeQuery();
rs = stmt.getResultSet();
while (rs.next()) {
ArrayList<String> Col = new ArrayList<String>();
for (int i = 1; i <= rs.getMetaData().getColumnCount(); i++) {
Col.add(rs.getString(i));
}
Rows.put(rs.getRow(), Col);
}
}
} catch (SQLException ex) {
System.out.println("Updating mcMMO MySQL tables for Fishing...");
Write("ALTER TABLE `"+LoadProperties.MySQLtablePrefix + "skills` ADD `fishing` int(10) NOT NULL DEFAULT '0' ;");
Write("ALTER TABLE `"+LoadProperties.MySQLtablePrefix + "experience` ADD `fishing` int(10) NOT NULL DEFAULT '0' ;");
}
}
public void checkDatabaseStructureForBlastMining()
{
String sql = "SELECT * FROM `"+LoadProperties.MySQLtablePrefix+"cooldowns` ORDER BY `"+LoadProperties.MySQLtablePrefix+"cooldowns`.`blast_mining` ASC LIMIT 0 , 30";
// Load the driver instance
try {
Class.forName("com.mysql.jdbc.Driver");
DriverManager.getConnection(connectionString);
}
catch (ClassNotFoundException e) {
plugin.getServer().getLogger().warning(e.getLocalizedMessage());
}
catch (SQLException ex) {
plugin.getServer().getLogger().warning(ex.getLocalizedMessage());
printErrors(ex);
}
}
/**
* Attempt to connect to the mySQL database.
*/
public void connect() {
try {
System.out.println("[mcMMO] Attempting connection to MySQL...");
Properties conProperties = new Properties();
conProperties.put("autoReconnect", "true");
conProperties.put("maxReconnects", "3");
conn = DriverManager.getConnection(connectionString, conProperties);
isConnected = true;
System.out.println("[mcMMO] Connection to MySQL established!");
}
catch (SQLException ex) {
isConnected = false;
ex.printStackTrace();
printErrors(ex);
}
}
/**
* Attempt to create the database structure.
*/
public void createStructure() {
write("CREATE TABLE IF NOT EXISTS `" + LoadProperties.MySQLtablePrefix + "huds` (`user_id` int(10) unsigned NOT NULL,"
+ "`hudtype` varchar(50) NOT NULL DEFAULT '',"
+ "PRIMARY KEY (`user_id`)) ENGINE=MyISAM DEFAULT CHARSET=latin1;");
write("CREATE TABLE IF NOT EXISTS `" + LoadProperties.MySQLtablePrefix + "users` (`id` int(10) unsigned NOT NULL AUTO_INCREMENT,"
+ "`user` varchar(40) NOT NULL,"
+ "`lastlogin` int(32) unsigned NOT NULL,"
+ "`party` varchar(100) NOT NULL DEFAULT '',"
+ "PRIMARY KEY (`id`),"
+ "UNIQUE KEY `user` (`user`)) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1;");
write("CREATE TABLE IF NOT EXISTS `" + LoadProperties.MySQLtablePrefix + "cooldowns` (`user_id` int(10) unsigned NOT NULL,"
+ "`taming` int(32) unsigned NOT NULL DEFAULT '0',"
+ "`mining` int(32) unsigned NOT NULL DEFAULT '0',"
+ "`woodcutting` int(32) unsigned NOT NULL DEFAULT '0',"
+ "`repair` int(32) unsigned NOT NULL DEFAULT '0',"
+ "`unarmed` int(32) unsigned NOT NULL DEFAULT '0',"
+ "`herbalism` int(32) unsigned NOT NULL DEFAULT '0',"
+ "`excavation` int(32) unsigned NOT NULL DEFAULT '0',"
+ "`archery` int(32) unsigned NOT NULL DEFAULT '0',"
+ "`swords` int(32) unsigned NOT NULL DEFAULT '0',"
+ "`axes` int(32) unsigned NOT NULL DEFAULT '0',"
+ "`acrobatics` int(32) unsigned NOT NULL DEFAULT '0',"
+ "`blast_mining` int(32) unsigned NOT NULL DEFAULT '0',"
+ "PRIMARY KEY (`user_id`)) ENGINE=MyISAM DEFAULT CHARSET=latin1;");
write("CREATE TABLE IF NOT EXISTS `" + LoadProperties.MySQLtablePrefix + "skills` (`user_id` int(10) unsigned NOT NULL,"
+ "`taming` int(10) unsigned NOT NULL DEFAULT '0',"
+ "`mining` int(10) unsigned NOT NULL DEFAULT '0',"
+ "`woodcutting` int(10) unsigned NOT NULL DEFAULT '0',"
+ "`repair` int(10) unsigned NOT NULL DEFAULT '0',"
+ "`unarmed` int(10) unsigned NOT NULL DEFAULT '0',"
+ "`herbalism` int(10) unsigned NOT NULL DEFAULT '0',"
+ "`excavation` int(10) unsigned NOT NULL DEFAULT '0',"
+ "`archery` int(10) unsigned NOT NULL DEFAULT '0',"
+ "`swords` int(10) unsigned NOT NULL DEFAULT '0',"
+ "`axes` int(10) unsigned NOT NULL DEFAULT '0',"
+ "`acrobatics` int(10) unsigned NOT NULL DEFAULT '0',"
+ "PRIMARY KEY (`user_id`)) ENGINE=MyISAM DEFAULT CHARSET=latin1;");
write("CREATE TABLE IF NOT EXISTS `" + LoadProperties.MySQLtablePrefix + "experience` (`user_id` int(10) unsigned NOT NULL,"
+ "`taming` int(10) unsigned NOT NULL DEFAULT '0',"
+ "`mining` int(10) unsigned NOT NULL DEFAULT '0',"
+ "`woodcutting` int(10) unsigned NOT NULL DEFAULT '0',"
+ "`repair` int(10) unsigned NOT NULL DEFAULT '0',"
+ "`unarmed` int(10) unsigned NOT NULL DEFAULT '0',"
+ "`herbalism` int(10) unsigned NOT NULL DEFAULT '0',"
+ "`excavation` int(10) unsigned NOT NULL DEFAULT '0',"
+ "`archery` int(10) unsigned NOT NULL DEFAULT '0',"
+ "`swords` int(10) unsigned NOT NULL DEFAULT '0',"
+ "`axes` int(10) unsigned NOT NULL DEFAULT '0',"
+ "`acrobatics` int(10) unsigned NOT NULL DEFAULT '0',"
+ "PRIMARY KEY (`user_id`)) ENGINE=MyISAM DEFAULT CHARSET=latin1;");
write("DROP TABLE IF EXISTS `"+LoadProperties.MySQLtablePrefix+"skills2`");
write("DROP TABLE IF EXISTS `"+LoadProperties.MySQLtablePrefix+"experience2`");
write("DROP TABLE IF EXISTS `"+LoadProperties.MySQLtablePrefix+"spawn`");
checkDatabaseStructure(DatabaseUpdate.FISHING);
checkDatabaseStructure(DatabaseUpdate.BLAST_MINING);
}
/**
* Check database structure for missing values.
*
* @param update Type of data to check updates for
*/
public void checkDatabaseStructure(DatabaseUpdate update) {
String sql = null;
ResultSet rs = null;
HashMap<Integer, ArrayList<String>> Rows = new HashMap<Integer, ArrayList<String>>();
switch (update) {
case BLAST_MINING:
sql = "SELECT * FROM `"+LoadProperties.MySQLtablePrefix+"cooldowns` ORDER BY `"+LoadProperties.MySQLtablePrefix+"cooldowns`.`blast_mining` ASC LIMIT 0 , 30";
break;
case FISHING:
sql = "SELECT * FROM `"+LoadProperties.MySQLtablePrefix+"experience` ORDER BY `"+LoadProperties.MySQLtablePrefix+"experience`.`fishing` ASC LIMIT 0 , 30";
break;
default:
break;
}
try {
PreparedStatement stmt = conn.prepareStatement(sql);
if (stmt.executeQuery() != null) {
@ -181,111 +172,138 @@ public class Database {
Rows.put(rs.getRow(), Col);
}
}
} catch (SQLException ex) {
System.out.println("Updating mcMMO MySQL tables for Blast Mining...");
Write("ALTER TABLE `"+LoadProperties.MySQLtablePrefix + "cooldowns` ADD `blast_mining` int(32) NOT NULL DEFAULT '0' ;");
}
}
// write query
public boolean Write(String sql) {
if(conn != null)
{
try {
PreparedStatement stmt = conn.prepareStatement(sql);
stmt.executeUpdate();
return true;
} catch (SQLException ex) {
System.out.println("SQLException: " + ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("VendorError: " + ex.getErrorCode());
return false;
}
} else
{
isConnected = false;
connect(); //Attempt to reconnect
if(isConnected = true)
{
Write(sql); //Try the same operation again now that we are connected
} else {
System.out.println("[mcMMO] Unable to connect to MySQL! Make sure the SQL server is online!");
}
}
return false;
}
catch (SQLException ex) {
if (update.equals(DatabaseUpdate.BLAST_MINING)) {
System.out.println("Updating mcMMO MySQL tables for Blast Mining...");
write("ALTER TABLE `"+LoadProperties.MySQLtablePrefix + "cooldowns` ADD `blast_mining` int(32) NOT NULL DEFAULT '0' ;");
}
else if (update.equals(DatabaseUpdate.FISHING)) {
System.out.println("Updating mcMMO MySQL tables for Fishing...");
write("ALTER TABLE `"+LoadProperties.MySQLtablePrefix + "skills` ADD `fishing` int(10) NOT NULL DEFAULT '0' ;");
write("ALTER TABLE `"+LoadProperties.MySQLtablePrefix + "experience` ADD `fishing` int(10) NOT NULL DEFAULT '0' ;");
}
}
}
// Get Int
// only return first row / first field
public Integer GetInt(String sql) {
ResultSet rs = null;
Integer result = 0;
if(conn != null)
{
try {
PreparedStatement stmt = conn.prepareStatement(sql);
stmt = conn.prepareStatement(sql);
if (stmt.executeQuery() != null) {
stmt.executeQuery();
rs = stmt.getResultSet();
if (rs.next()) {
result = rs.getInt(1);
} else {
result = 0;
}
}
} catch (SQLException ex) {
System.out.println("SQLException: " + ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("VendorError: " + ex.getErrorCode());
}
} else {
isConnected = false;
/**
* Attempt to write the SQL query.
*
* @param sql Query to write.
* @return true if the query was successfully written, false otherwise.
*/
public boolean write(String sql) {
if (conn != null) {
try {
PreparedStatement stmt = conn.prepareStatement(sql);
stmt.executeUpdate();
return true;
}
catch (SQLException ex) {
printErrors(ex);
return false;
}
}
else {
isConnected = false;
connect(); //Attempt to reconnect
if(isConnected = true)
{
GetInt(sql); //Try the same operation again now that we are connected
} else {
if (isConnected) {
write(sql); //Try the same operation again now that we are connected
}
else {
System.out.println("[mcMMO] Unable to connect to MySQL! Make sure the SQL server is online!");
}
}
return result;
}
}
return false;
}
// read query
public HashMap<Integer, ArrayList<String>> Read(String sql) {
ResultSet rs = null;
HashMap<Integer, ArrayList<String>> Rows = new HashMap<Integer, ArrayList<String>>();
if(conn != null)
{
try {
PreparedStatement stmt = conn.prepareStatement(sql);
if (stmt.executeQuery() != null) {
stmt.executeQuery();
rs = stmt.getResultSet();
while (rs.next()) {
ArrayList<String> Col = new ArrayList<String>();
for (int i = 1; i <= rs.getMetaData().getColumnCount(); i++) {
Col.add(rs.getString(i));
}
Rows.put(rs.getRow(), Col);
}
}
} catch (SQLException ex) {
System.out.println("SQLException: " + ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("VendorError: " + ex.getErrorCode());
}
} else {
isConnected = false;
/**
* Get the Integer. Only return first row / first field.
*
* @param sql SQL query to execute
* @return the value in the first row / first field
*/
public Integer getInt(String sql) {
ResultSet rs = null;
Integer result = 0;
if (conn != null) {
try {
PreparedStatement stmt = conn.prepareStatement(sql);
stmt = conn.prepareStatement(sql);
if (stmt.executeQuery() != null) {
stmt.executeQuery();
rs = stmt.getResultSet();
if (rs.next()) {
result = rs.getInt(1);
}
else {
result = 0;
}
}
}
catch (SQLException ex) {
printErrors(ex);
}
}
else {
isConnected = false;
connect(); //Attempt to reconnect
if(isConnected = true)
{
Read(sql); //Attempt the same operation again now that we are connected
} else {
if (isConnected) {
getInt(sql); //Try the same operation again now that we are connected
}
else {
System.out.println("[mcMMO] Unable to connect to MySQL! Make sure the SQL server is online!");
}
}
return Rows;
}
}
return result;
}
/**
* Read SQL query.
*
* @param sql SQL query to read
* @return the rows in this SQL query
*/
public HashMap<Integer, ArrayList<String>> read(String sql) {
ResultSet rs = null;
HashMap<Integer, ArrayList<String>> Rows = new HashMap<Integer, ArrayList<String>>();
if (conn != null) {
try {
PreparedStatement stmt = conn.prepareStatement(sql);
if (stmt.executeQuery() != null) {
stmt.executeQuery();
rs = stmt.getResultSet();
while (rs.next()) {
ArrayList<String> Col = new ArrayList<String>();
for (int i = 1; i <= rs.getMetaData().getColumnCount(); i++) {
Col.add(rs.getString(i));
}
Rows.put(rs.getRow(), Col);
}
}
}
catch (SQLException ex) {
printErrors(ex);
}
}
else {
isConnected = false;
connect(); //Attempt to reconnect
if (isConnected) {
read(sql); //Attempt the same operation again now that we are connected
}
else {
System.out.println("[mcMMO] Unable to connect to MySQL! Make sure the SQL server is online!");
}
}
return Rows;
}
private static void printErrors(SQLException ex) {
System.out.println("SQLException: " + ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("VendorError: " + ex.getErrorCode());
}
}

View File

@ -38,30 +38,30 @@ public class McremoveCommand implements CommandExecutor {
//If the server is using MySQL
if(LoadProperties.useMySQL)
{
int userId = mcMMO.database.GetInt("SELECT id FROM "+LoadProperties.MySQLtablePrefix+"users WHERE user = '" + playerName + "'");
int userId = mcMMO.database.getInt("SELECT id FROM "+LoadProperties.MySQLtablePrefix+"users WHERE user = '" + playerName + "'");
//Remove user from tables
mcMMO.database.Write("DELETE FROM "
mcMMO.database.write("DELETE FROM "
+LoadProperties.MySQLdbName+"."
+LoadProperties.MySQLtablePrefix+"users WHERE "
+LoadProperties.MySQLtablePrefix+"users.id="+userId);
mcMMO.database.Write("DELETE FROM "
mcMMO.database.write("DELETE FROM "
+LoadProperties.MySQLdbName+"."
+LoadProperties.MySQLtablePrefix+"cooldowns WHERE "
+LoadProperties.MySQLtablePrefix+"cooldowns.user_id="+userId);
mcMMO.database.Write("DELETE FROM "
mcMMO.database.write("DELETE FROM "
+LoadProperties.MySQLdbName+"."
+LoadProperties.MySQLtablePrefix+"huds WHERE "
+LoadProperties.MySQLtablePrefix+"huds.user_id="+userId);
mcMMO.database.Write("DELETE FROM "
mcMMO.database.write("DELETE FROM "
+LoadProperties.MySQLdbName+"."
+LoadProperties.MySQLtablePrefix+"skills WHERE "
+LoadProperties.MySQLtablePrefix+"skills.user_id="+userId);
mcMMO.database.Write("DELETE FROM "
mcMMO.database.write("DELETE FROM "
+LoadProperties.MySQLdbName+"."
+LoadProperties.MySQLtablePrefix+"experience WHERE "
+LoadProperties.MySQLtablePrefix+"experience.user_id="+userId);

View File

@ -138,22 +138,22 @@ public class MctopCommand implements CommandExecutor {
n = n * (n2 - 1);
}
// If a page number is specified
HashMap<Integer, ArrayList<String>> userslist = mcMMO.database.Read("SELECT " + lowercase + ", user_id FROM " + LoadProperties.MySQLtablePrefix + "skills WHERE " + lowercase + " > 0 ORDER BY `" + LoadProperties.MySQLtablePrefix + "skills`.`" + lowercase + "` DESC ");
HashMap<Integer, ArrayList<String>> userslist = mcMMO.database.read("SELECT " + lowercase + ", user_id FROM " + LoadProperties.MySQLtablePrefix + "skills WHERE " + lowercase + " > 0 ORDER BY `" + LoadProperties.MySQLtablePrefix + "skills`.`" + lowercase + "` DESC ");
for (int i = n; i <= n + 10; i++) {
if (i > userslist.size() || mcMMO.database.Read("SELECT user FROM " + LoadProperties.MySQLtablePrefix + "users WHERE id = '" + Integer.valueOf(userslist.get(i).get(1)) + "'") == null)
if (i > userslist.size() || mcMMO.database.read("SELECT user FROM " + LoadProperties.MySQLtablePrefix + "users WHERE id = '" + Integer.valueOf(userslist.get(i).get(1)) + "'") == null)
break;
HashMap<Integer, ArrayList<String>> username = mcMMO.database.Read("SELECT user FROM " + LoadProperties.MySQLtablePrefix + "users WHERE id = '" + Integer.valueOf(userslist.get(i).get(1)) + "'");
HashMap<Integer, ArrayList<String>> username = mcMMO.database.read("SELECT user FROM " + LoadProperties.MySQLtablePrefix + "users WHERE id = '" + Integer.valueOf(userslist.get(i).get(1)) + "'");
player.sendMessage(String.valueOf(i) + ". " + ChatColor.GREEN + userslist.get(i).get(0) + " - " + ChatColor.WHITE + username.get(1).get(0));
}
return true;
}
// If no page number is specified
HashMap<Integer, ArrayList<String>> userslist = mcMMO.database.Read("SELECT " + lowercase + ", user_id FROM " + LoadProperties.MySQLtablePrefix + "skills WHERE " + lowercase + " > 0 ORDER BY `" + LoadProperties.MySQLtablePrefix + "skills`.`" + lowercase + "` DESC ");
HashMap<Integer, ArrayList<String>> userslist = mcMMO.database.read("SELECT " + lowercase + ", user_id FROM " + LoadProperties.MySQLtablePrefix + "skills WHERE " + lowercase + " > 0 ORDER BY `" + LoadProperties.MySQLtablePrefix + "skills`.`" + lowercase + "` DESC ");
for (int i = 1; i <= 10; i++) { // i<=userslist.size()
if (i > userslist.size() || mcMMO.database.Read("SELECT user FROM " + LoadProperties.MySQLtablePrefix + "users WHERE id = '" + Integer.valueOf(userslist.get(i).get(1)) + "'") == null)
if (i > userslist.size() || mcMMO.database.read("SELECT user FROM " + LoadProperties.MySQLtablePrefix + "users WHERE id = '" + Integer.valueOf(userslist.get(i).get(1)) + "'") == null)
break;
HashMap<Integer, ArrayList<String>> username = mcMMO.database.Read("SELECT user FROM " + LoadProperties.MySQLtablePrefix + "users WHERE id = '" + Integer.valueOf(userslist.get(i).get(1)) + "'");
HashMap<Integer, ArrayList<String>> username = mcMMO.database.read("SELECT user FROM " + LoadProperties.MySQLtablePrefix + "users WHERE id = '" + Integer.valueOf(userslist.get(i).get(1)) + "'");
player.sendMessage(String.valueOf(i) + ". " + ChatColor.GREEN + userslist.get(i).get(0) + " - " + ChatColor.WHITE + username.get(1).get(0));
}
return true;
@ -169,20 +169,20 @@ public class MctopCommand implements CommandExecutor {
n = n * (n2 - 1);
}
// If a page number is specified
HashMap<Integer, ArrayList<String>> userslist = mcMMO.database.Read("SELECT " + powerlevel + ", user_id FROM " + LoadProperties.MySQLtablePrefix + "skills WHERE " + powerlevel + " > 0 ORDER BY " + powerlevel + " DESC ");
HashMap<Integer, ArrayList<String>> userslist = mcMMO.database.read("SELECT " + powerlevel + ", user_id FROM " + LoadProperties.MySQLtablePrefix + "skills WHERE " + powerlevel + " > 0 ORDER BY " + powerlevel + " DESC ");
for (int i = n; i <= n + 10; i++) {
if (i > userslist.size() || mcMMO.database.Read("SELECT user FROM " + LoadProperties.MySQLtablePrefix + "users WHERE id = '" + Integer.valueOf(userslist.get(i).get(1)) + "'") == null)
if (i > userslist.size() || mcMMO.database.read("SELECT user FROM " + LoadProperties.MySQLtablePrefix + "users WHERE id = '" + Integer.valueOf(userslist.get(i).get(1)) + "'") == null)
break;
HashMap<Integer, ArrayList<String>> username = mcMMO.database.Read("SELECT user FROM " + LoadProperties.MySQLtablePrefix + "users WHERE id = '" + Integer.valueOf(userslist.get(i).get(1)) + "'");
HashMap<Integer, ArrayList<String>> username = mcMMO.database.read("SELECT user FROM " + LoadProperties.MySQLtablePrefix + "users WHERE id = '" + Integer.valueOf(userslist.get(i).get(1)) + "'");
player.sendMessage(String.valueOf(i) + ". " + ChatColor.GREEN + userslist.get(i).get(0) + " - " + ChatColor.WHITE + username.get(1).get(0));
}
return true;
}
HashMap<Integer, ArrayList<String>> userslist = mcMMO.database.Read("SELECT " + powerlevel + ", user_id FROM " + LoadProperties.MySQLtablePrefix + "skills WHERE " + powerlevel + " > 0 ORDER BY " + powerlevel + " DESC ");
HashMap<Integer, ArrayList<String>> userslist = mcMMO.database.read("SELECT " + powerlevel + ", user_id FROM " + LoadProperties.MySQLtablePrefix + "skills WHERE " + powerlevel + " > 0 ORDER BY " + powerlevel + " DESC ");
for (int i = 1; i <= 10; i++) {
if (i > userslist.size() || mcMMO.database.Read("SELECT user FROM " + LoadProperties.MySQLtablePrefix + "users WHERE id = '" + Integer.valueOf(userslist.get(i).get(1)) + "'") == null)
if (i > userslist.size() || mcMMO.database.read("SELECT user FROM " + LoadProperties.MySQLtablePrefix + "users WHERE id = '" + Integer.valueOf(userslist.get(i).get(1)) + "'") == null)
break;
HashMap<Integer, ArrayList<String>> username = mcMMO.database.Read("SELECT user FROM " + LoadProperties.MySQLtablePrefix + "users WHERE id = '" + Integer.valueOf(userslist.get(i).get(1)) + "'");
HashMap<Integer, ArrayList<String>> username = mcMMO.database.read("SELECT user FROM " + LoadProperties.MySQLtablePrefix + "users WHERE id = '" + Integer.valueOf(userslist.get(i).get(1)) + "'");
player.sendMessage(String.valueOf(i) + ". " + ChatColor.GREEN + userslist.get(i).get(0) + " - " + ChatColor.WHITE + username.get(1).get(0));
// System.out.println(username.get(1).get(0));
// System.out.println("Mining : " + userslist.get(i).get(0) + ", User id : " + userslist.get(i).get(1));

View File

@ -15,7 +15,7 @@ public enum AbilityType
SKULL_SPLIITER(LoadProperties.skullSplitterCooldown, mcLocale.getString("Skills.SkullSplitterOn"), mcLocale.getString("Skills.SkullSplitterOff"), "Skills.SkullSplitterPlayer", mcLocale.getString("Skills.YourSkullSplitter"), "Skills.SkullSplitterPlayerOff"),
TREE_FELLER(LoadProperties.treeFellerCooldown, mcLocale.getString("Skills.TreeFellerOn"), mcLocale.getString("Skills.TreeFellerOff"), "Skills.TreeFellerPlayer", mcLocale.getString("Skills.YourTreeFeller"), "Skills.TreeFellerPlayerOff"),
SERRATED_STRIKES(LoadProperties.skullSplitterCooldown, mcLocale.getString("Skills.SerratedStrikesOn"), mcLocale.getString("Skills.SerratedStrikesOff"), "Skills.SerratedStrikesPlayer", mcLocale.getString("Skills.YourSerratedStrikes"), "Skills.SerratedStrikesPlayerOff"),
BLAST_MINING(LoadProperties.blastMiningCooldown, "NOT NEEDED FOR BLAST MINING", "NOT NEEDED FOR BLAST MINING", "Skills.BlastMiningPlayer", mcLocale.getString("Skills.YourBlastMining"), "NOT NEEDED FOR BLAST MINING");
BLAST_MINING(LoadProperties.blastMiningCooldown, null, null, "Skills.BlastMiningPlayer", mcLocale.getString("Skills.YourBlastMining"), null);
private int cooldown;
private String abilityOn;

View File

@ -145,15 +145,15 @@ public class PlayerProfile
public boolean loadMySQL()
{
Integer id = 0;
id = mcMMO.database.GetInt("SELECT id FROM "+LoadProperties.MySQLtablePrefix+"users WHERE user = '" + playerName + "'");
id = mcMMO.database.getInt("SELECT id FROM "+LoadProperties.MySQLtablePrefix+"users WHERE user = '" + playerName + "'");
if(id == 0)
return false;
this.userid = id;
if (id > 0) {
HashMap<Integer, ArrayList<String>> huds = mcMMO.database.Read("SELECT hudtype FROM "+LoadProperties.MySQLtablePrefix+"huds WHERE user_id = " + id);
HashMap<Integer, ArrayList<String>> huds = mcMMO.database.read("SELECT hudtype FROM "+LoadProperties.MySQLtablePrefix+"huds WHERE user_id = " + id);
if(huds.get(1) == null)
{
mcMMO.database.Write("INSERT INTO "+LoadProperties.MySQLtablePrefix+"huds (user_id) VALUES ("+id+")");
mcMMO.database.write("INSERT INTO "+LoadProperties.MySQLtablePrefix+"huds (user_id) VALUES ("+id+")");
} else {
if(huds.get(1).get(0) != null)
{
@ -168,17 +168,17 @@ public class PlayerProfile
hud = LoadProperties.defaulthud;
}
}
HashMap<Integer, ArrayList<String>> users = mcMMO.database.Read("SELECT lastlogin, party FROM "+LoadProperties.MySQLtablePrefix+"users WHERE id = " + id);
HashMap<Integer, ArrayList<String>> users = mcMMO.database.read("SELECT lastlogin, party FROM "+LoadProperties.MySQLtablePrefix+"users WHERE id = " + id);
//lastlogin = Integer.parseInt(users.get(1).get(0));
party = users.get(1).get(1);
HashMap<Integer, ArrayList<String>> cooldowns = mcMMO.database.Read("SELECT mining, woodcutting, unarmed, herbalism, excavation, swords, axes, blast_mining FROM "+LoadProperties.MySQLtablePrefix+"cooldowns WHERE user_id = " + id);
HashMap<Integer, ArrayList<String>> cooldowns = mcMMO.database.read("SELECT mining, woodcutting, unarmed, herbalism, excavation, swords, axes, blast_mining FROM "+LoadProperties.MySQLtablePrefix+"cooldowns WHERE user_id = " + id);
/*
* I'm still learning MySQL, this is a fix for adding a new table
* its not pretty but it works
*/
if(cooldowns.get(1) == null)
{
mcMMO.database.Write("INSERT INTO "+LoadProperties.MySQLtablePrefix+"cooldowns (user_id) VALUES ("+id+")");
mcMMO.database.write("INSERT INTO "+LoadProperties.MySQLtablePrefix+"cooldowns (user_id) VALUES ("+id+")");
}
else
{
@ -191,7 +191,7 @@ public class PlayerProfile
skillsDATS.put(AbilityType.SKULL_SPLIITER, Integer.valueOf(cooldowns.get(1).get(6)));
skillsDATS.put(AbilityType.BLAST_MINING, Integer.valueOf(cooldowns.get(1).get(7)));
}
HashMap<Integer, ArrayList<String>> stats = mcMMO.database.Read("SELECT taming, mining, repair, woodcutting, unarmed, herbalism, excavation, archery, swords, axes, acrobatics, fishing FROM "+LoadProperties.MySQLtablePrefix+"skills WHERE user_id = " + id);
HashMap<Integer, ArrayList<String>> stats = mcMMO.database.read("SELECT taming, mining, repair, woodcutting, unarmed, herbalism, excavation, archery, swords, axes, acrobatics, fishing FROM "+LoadProperties.MySQLtablePrefix+"skills WHERE user_id = " + id);
skills.put(SkillType.TAMING, Integer.valueOf(stats.get(1).get(0)));
skills.put(SkillType.MINING, Integer.valueOf(stats.get(1).get(1)));
skills.put(SkillType.REPAIR, Integer.valueOf(stats.get(1).get(2)));
@ -204,7 +204,7 @@ public class PlayerProfile
skills.put(SkillType.AXES, Integer.valueOf(stats.get(1).get(9)));
skills.put(SkillType.ACROBATICS, Integer.valueOf(stats.get(1).get(10)));
skills.put(SkillType.FISHING, Integer.valueOf(stats.get(1).get(11)));
HashMap<Integer, ArrayList<String>> experience = mcMMO.database.Read("SELECT taming, mining, repair, woodcutting, unarmed, herbalism, excavation, archery, swords, axes, acrobatics, fishing FROM "+LoadProperties.MySQLtablePrefix+"experience WHERE user_id = " + id);
HashMap<Integer, ArrayList<String>> experience = mcMMO.database.read("SELECT taming, mining, repair, woodcutting, unarmed, herbalism, excavation, archery, swords, axes, acrobatics, fishing FROM "+LoadProperties.MySQLtablePrefix+"experience WHERE user_id = " + id);
skillsXp.put(SkillType.TAMING, Integer.valueOf(experience.get(1).get(0)));
skillsXp.put(SkillType.MINING, Integer.valueOf(experience.get(1).get(1)));
skillsXp.put(SkillType.REPAIR, Integer.valueOf(experience.get(1).get(2)));
@ -226,11 +226,11 @@ public class PlayerProfile
}
public void addMySQLPlayer() {
Integer id = 0;
mcMMO.database.Write("INSERT INTO "+LoadProperties.MySQLtablePrefix+"users (user, lastlogin) VALUES ('" + playerName + "'," + System.currentTimeMillis() / 1000 +")");
id = mcMMO.database.GetInt("SELECT id FROM "+LoadProperties.MySQLtablePrefix+"users WHERE user = '" + playerName + "'");
mcMMO.database.Write("INSERT INTO "+LoadProperties.MySQLtablePrefix+"cooldowns (user_id) VALUES ("+id+")");
mcMMO.database.Write("INSERT INTO "+LoadProperties.MySQLtablePrefix+"skills (user_id) VALUES ("+id+")");
mcMMO.database.Write("INSERT INTO "+LoadProperties.MySQLtablePrefix+"experience (user_id) VALUES ("+id+")");
mcMMO.database.write("INSERT INTO "+LoadProperties.MySQLtablePrefix+"users (user, lastlogin) VALUES ('" + playerName + "'," + System.currentTimeMillis() / 1000 +")");
id = mcMMO.database.getInt("SELECT id FROM "+LoadProperties.MySQLtablePrefix+"users WHERE user = '" + playerName + "'");
mcMMO.database.write("INSERT INTO "+LoadProperties.MySQLtablePrefix+"cooldowns (user_id) VALUES ("+id+")");
mcMMO.database.write("INSERT INTO "+LoadProperties.MySQLtablePrefix+"skills (user_id) VALUES ("+id+")");
mcMMO.database.write("INSERT INTO "+LoadProperties.MySQLtablePrefix+"experience (user_id) VALUES ("+id+")");
this.userid = id;
}
@ -345,11 +345,11 @@ public class PlayerProfile
// if we are using mysql save to database
if (LoadProperties.useMySQL)
{
mcMMO.database.Write("UPDATE "+LoadProperties.MySQLtablePrefix+"huds SET "
mcMMO.database.write("UPDATE "+LoadProperties.MySQLtablePrefix+"huds SET "
+" hudtype = '"+hud.toString()+"' WHERE user_id = "+this.userid);
mcMMO.database.Write("UPDATE "+LoadProperties.MySQLtablePrefix+"users SET lastlogin = " + timestamp.intValue() + " WHERE id = " + this.userid);
mcMMO.database.Write("UPDATE "+LoadProperties.MySQLtablePrefix+"users SET party = '"+this.party+"' WHERE id = " +this.userid);
mcMMO.database.Write("UPDATE "+LoadProperties.MySQLtablePrefix+"cooldowns SET "
mcMMO.database.write("UPDATE "+LoadProperties.MySQLtablePrefix+"users SET lastlogin = " + timestamp.intValue() + " WHERE id = " + this.userid);
mcMMO.database.write("UPDATE "+LoadProperties.MySQLtablePrefix+"users SET party = '"+this.party+"' WHERE id = " +this.userid);
mcMMO.database.write("UPDATE "+LoadProperties.MySQLtablePrefix+"cooldowns SET "
+" mining = " + skillsDATS.get(AbilityType.SUPER_BREAKER)
+", woodcutting = " + skillsDATS.get(AbilityType.TREE_FELLER)
+", unarmed = " + skillsDATS.get(AbilityType.BERSERK)
@ -359,7 +359,7 @@ public class PlayerProfile
+", axes = " + skillsDATS.get(AbilityType.SKULL_SPLIITER)
+", blast_mining = " + skillsDATS.get(AbilityType.BLAST_MINING)
+" WHERE user_id = "+this.userid);
mcMMO.database.Write("UPDATE "+LoadProperties.MySQLtablePrefix+"skills SET "
mcMMO.database.write("UPDATE "+LoadProperties.MySQLtablePrefix+"skills SET "
+" taming = "+skills.get(SkillType.TAMING)
+", mining = "+skills.get(SkillType.MINING)
+", repair = "+skills.get(SkillType.REPAIR)
@ -373,7 +373,7 @@ public class PlayerProfile
+", acrobatics = "+skills.get(SkillType.ACROBATICS)
+", fishing = "+skills.get(SkillType.FISHING)
+" WHERE user_id = "+this.userid);
mcMMO.database.Write("UPDATE "+LoadProperties.MySQLtablePrefix+"experience SET "
mcMMO.database.write("UPDATE "+LoadProperties.MySQLtablePrefix+"experience SET "
+" taming = "+skillsXp.get(SkillType.TAMING)
+", mining = "+skillsXp.get(SkillType.MINING)
+", repair = "+skillsXp.get(SkillType.REPAIR)

View File

@ -493,18 +493,18 @@ public class m
fishingXP = character[35];
//Check to see if the user is in the DB
id = mcMMO.database.GetInt("SELECT id FROM "
id = mcMMO.database.getInt("SELECT id FROM "
+ LoadProperties.MySQLtablePrefix
+ "users WHERE user = '" + playerName + "'");
if (id > 0) {
theCount++;
//Update the skill values
mcMMO.database.Write("UPDATE "
mcMMO.database.write("UPDATE "
+ LoadProperties.MySQLtablePrefix
+ "users SET lastlogin = " + 0
+ " WHERE id = " + id);
mcMMO.database.Write("UPDATE "
mcMMO.database.write("UPDATE "
+ LoadProperties.MySQLtablePrefix
+ "skills SET " + " taming = taming+"
+ getInt(taming) + ", mining = mining+"
@ -524,7 +524,7 @@ public class m
+ getInt(acrobatics)
+ ", fishing = fishing+" + getInt(fishing)
+ " WHERE user_id = " + id);
mcMMO.database.Write("UPDATE "
mcMMO.database.write("UPDATE "
+ LoadProperties.MySQLtablePrefix
+ "experience SET " + " taming = "
+ getInt(tamingXP) + ", mining = "
@ -543,33 +543,33 @@ public class m
} else {
theCount++;
//Create the user in the DB
mcMMO.database.Write("INSERT INTO "
mcMMO.database.write("INSERT INTO "
+ LoadProperties.MySQLtablePrefix
+ "users (user, lastlogin) VALUES ('"
+ playerName + "',"
+ System.currentTimeMillis() / 1000 + ")");
id = mcMMO.database
.GetInt("SELECT id FROM "
.getInt("SELECT id FROM "
+ LoadProperties.MySQLtablePrefix
+ "users WHERE user = '"
+ playerName + "'");
mcMMO.database.Write("INSERT INTO "
mcMMO.database.write("INSERT INTO "
+ LoadProperties.MySQLtablePrefix
+ "skills (user_id) VALUES (" + id + ")");
mcMMO.database.Write("INSERT INTO "
mcMMO.database.write("INSERT INTO "
+ LoadProperties.MySQLtablePrefix
+ "experience (user_id) VALUES (" + id
+ ")");
//Update the skill values
mcMMO.database.Write("UPDATE "
mcMMO.database.write("UPDATE "
+ LoadProperties.MySQLtablePrefix
+ "users SET lastlogin = " + 0
+ " WHERE id = " + id);
mcMMO.database.Write("UPDATE "
mcMMO.database.write("UPDATE "
+ LoadProperties.MySQLtablePrefix
+ "users SET party = '" + party
+ "' WHERE id = " + id);
mcMMO.database.Write("UPDATE "
mcMMO.database.write("UPDATE "
+ LoadProperties.MySQLtablePrefix
+ "skills SET " + " taming = "
+ getInt(taming) + ", mining = "
@ -585,7 +585,7 @@ public class m
+ getInt(acrobatics) + ", fishing = "
+ getInt(fishing) + " WHERE user_id = "
+ id);
mcMMO.database.Write("UPDATE "
mcMMO.database.write("UPDATE "
+ LoadProperties.MySQLtablePrefix
+ "experience SET " + " taming = "
+ getInt(tamingXP) + ", mining = "

View File

@ -0,0 +1,24 @@
/*
* Copyright (C) 2012 Matt 'The Yeti' Burnett & mcMMO Development
* Copyright (C) 2010-2011 'nossr50'
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package datatypes;
public enum DatabaseUpdate {
FISHING,
BLAST_MINING;
}