Bugfix and code changes

Bugfix for not correctly generated mysql table when not using uuids.
Moving some variables
This commit is contained in:
GeorgH93 2015-03-30 00:02:28 +02:00
parent 06e6b73b4b
commit e1449a4bfc
6 changed files with 23 additions and 22 deletions

View File

@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>at.pcgamingfreaks</groupId>
<artifactId>MinePacks</artifactId>
<version>1.6.2</version>
<version>1.6.3</version>
<repositories>
<repository>
<id>in-project</id>

View File

@ -30,12 +30,16 @@ public class Database
{
protected MinePacks plugin;
protected boolean UseUUIDs, UseUUIDSeparators;
private HashSet<Backpack> backpacks = new HashSet<Backpack>();
protected ItemStackSerializer itsSerializer = new ItemStackSerializer();
public Database(MinePacks mp)
{
plugin = mp;
UseUUIDSeparators = plugin.config.getUseUUIDSeparators();
UseUUIDs = plugin.config.UseUUIDs();
}
public static Database getDatabase(MinePacks Plugin)

View File

@ -37,7 +37,7 @@ public MySQL(MinePacks mp)
BuildQuerys(); // Build Querys
CheckDB(); // Check Database
if(plugin.UseUUIDs && UpdatePlayer)
if(UseUUIDs && UpdatePlayer)
{
CheckUUIDs(); // Check if there are user accounts without UUID
}
@ -138,8 +138,8 @@ protected void CheckDB()
{
Statement stmt = GetConnection().createStatement();
ResultSet res;
stmt.execute("CREATE TABLE IF NOT EXISTS `" + Table_Players + "` (`" + Field_PlayerID + "` INT UNSIGNED NOT NULL AUTO_INCREMENT, `" + Field_Name + "` CHAR(16) NOT NULL UNIQUE, " + ((plugin.UseUUIDs) ? "`" + Field_UUID + "` CHAR(36) UNIQUE" : "") + ", PRIMARY KEY (`" + Field_PlayerID + "`));");
if(plugin.UseUUIDs)
stmt.execute("CREATE TABLE IF NOT EXISTS `" + Table_Players + "` (`" + Field_PlayerID + "` INT UNSIGNED NOT NULL AUTO_INCREMENT,`" + Field_Name + "` CHAR(16) NOT NULL UNIQUE" + ((UseUUIDs) ? ",`" + Field_UUID + "` CHAR(36) UNIQUE" : "") + ", PRIMARY KEY (`" + Field_PlayerID + "`));");
if(UseUUIDs)
{
res = stmt.executeQuery("SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = '" + Table_Players + "' AND COLUMN_NAME = '" + Field_UUID + "';");
if(!res.next())
@ -188,7 +188,7 @@ public void run()
PreparedStatement ps;
Connection con = DriverManager.getConnection("jdbc:mysql://" + plugin.config.GetMySQLHost() + "/" + plugin.config.GetMySQLDatabase(), plugin.config.GetMySQLUser(), plugin.config.GetMySQLPassword());;
ps = con.prepareStatement(Query_UpdatePlayerGet);
if(plugin.UseUUIDs)
if(UseUUIDs)
{
if(UseUUIDSeparators)
{
@ -208,7 +208,7 @@ public void run()
{
rs.close();
ps.close();
if(!plugin.UseUUIDs)
if(!UseUUIDs)
{
con.close();
return;
@ -230,7 +230,7 @@ public void run()
ps.close();
ps = con.prepareStatement(Query_UpdatePlayerAdd);
ps.setString(1, player.getName());
if(plugin.UseUUIDs)
if(UseUUIDs)
{
if(UseUUIDSeparators)
{

View File

@ -36,7 +36,7 @@ public class SQL extends Database
protected String Table_Players, Table_Backpacks; // Table Names
protected String Field_Name, Field_PlayerID, Field_UUID, Field_BPOwner, Field_BPITS, Field_BPVersion; // Table Fields
protected String Query_UpdatePlayerGet, Query_UpdatePlayerUUID, Query_UpdatePlayerAdd, Query_GetPlayerID, Query_InsertBP, Query_UpdateBP, Query_GetBP; // DB Querys
protected boolean UpdatePlayer, UseUUIDSeparators;
protected boolean UpdatePlayer;
public SQL(MinePacks mp)
{
@ -51,12 +51,11 @@ public SQL(MinePacks mp)
Field_BPITS = plugin.config.getDBFields("Backpack.ItemStacks");
Field_BPVersion = plugin.config.getDBFields("Backpack.Version");
UpdatePlayer = plugin.config.getUpdatePlayer();
UseUUIDSeparators = plugin.config.getUseUUIDSeparators();
}
protected void BuildQuerys()
{
if(plugin.UseUUIDs)
if(UseUUIDs)
{
Query_UpdatePlayerGet = "SELECT `" + Field_PlayerID + "` FROM `" + Table_Players + "` WHERE `" + Field_UUID + "`=?;";
Query_UpdatePlayerUUID = "UPDATE `" + Table_Players + "` SET `" + Field_Name + "`=? WHERE `" + Field_UUID + "`=?;";
@ -87,8 +86,8 @@ public void UpdatePlayer(final Player player)
try
{
PreparedStatement ps;
ps = GetConnection().prepareStatement("SELECT `player_id` FROM `" + Table_Players + "` WHERE " + ((plugin.UseUUIDs) ? "`uuid`" : "`name`") + "=?;");
if(plugin.UseUUIDs)
ps = GetConnection().prepareStatement("SELECT `player_id` FROM `" + Table_Players + "` WHERE " + ((UseUUIDs) ? "`uuid`" : "`name`") + "=?;");
if(UseUUIDs)
{
ps.setString(1, player.getUniqueId().toString().replace("-", ""));
}
@ -101,7 +100,7 @@ public void UpdatePlayer(final Player player)
{
rs.close();
ps.close();
if(!plugin.UseUUIDs)
if(!UseUUIDs)
{
return;
}
@ -113,9 +112,9 @@ public void UpdatePlayer(final Player player)
{
rs.close();
ps.close();
ps = GetConnection().prepareStatement("INSERT INTO `" + Table_Players + "` (`name`" + ((plugin.UseUUIDs) ? ",`uuid`" : "") + ") VALUES (?" + ((plugin.UseUUIDs) ? ",?" : "") + ");");
ps = GetConnection().prepareStatement("INSERT INTO `" + Table_Players + "` (`name`" + ((UseUUIDs) ? ",`uuid`" : "") + ") VALUES (?" + ((UseUUIDs) ? ",?" : "") + ");");
ps.setString(1, player.getName());
if(plugin.UseUUIDs)
if(UseUUIDs)
{
ps.setString(2, player.getUniqueId().toString().replace("-", ""));
}
@ -139,7 +138,7 @@ public void SaveBackpack(Backpack backpack)
if(backpack.getID() <= 0)
{
ps = GetConnection().prepareStatement(Query_GetPlayerID);
if(plugin.UseUUIDs)
if(UseUUIDs)
{
if(UseUUIDSeparators)
{
@ -197,7 +196,7 @@ public Backpack LoadBackpack(OfflinePlayer player)
{
PreparedStatement ps = null; // Statement Variable
ps = GetConnection().prepareStatement(Query_GetBP);
if(plugin.UseUUIDs)
if(UseUUIDs)
{
if(UseUUIDSeparators)
{

View File

@ -48,7 +48,7 @@ public SQLite(MinePacks mp)
BuildQuerys(); // Build Querys
CheckDB(); // Check Database
if(plugin.UseUUIDs && UpdatePlayer)
if(UseUUIDs && UpdatePlayer)
{
CheckUUIDs(); // Check if there are user accounts without UUID
}
@ -83,8 +83,8 @@ protected void CheckDB()
try
{
Statement stmt = GetConnection().createStatement();
stmt.execute("CREATE TABLE IF NOT EXISTS `" + Table_Players + "` (`player_id` INTEGER PRIMARY KEY AUTOINCREMENT, `name` CHAR(16) NOT NULL UNIQUE" + ((plugin.UseUUIDs) ? ", `uuid` CHAR(32) UNIQUE" : "") +");");
if(plugin.UseUUIDs)
stmt.execute("CREATE TABLE IF NOT EXISTS `" + Table_Players + "` (`player_id` INTEGER PRIMARY KEY AUTOINCREMENT, `name` CHAR(16) NOT NULL UNIQUE" + ((UseUUIDs) ? ", `uuid` CHAR(32) UNIQUE" : "") +");");
if(UseUUIDs)
{
try
{

View File

@ -33,7 +33,6 @@ public class MinePacks extends JavaPlugin
public Config config;
public Language lang;
public Database DB;
public boolean UseUUIDs;
static public String BackpackTitle;
public String Message_IvalidBackpack;
@ -43,7 +42,6 @@ public void onEnable()
log = getLogger();
config = new Config(this);
lang = new Language(this);
UseUUIDs = config.UseUUIDs();
DB = Database.getDatabase(this);
getCommand("backpack").setExecutor(new OnCommand(this));
getServer().getPluginManager().registerEvents(new EventListener(this), this);