diff --git a/pom.xml b/pom.xml
index d0bd3ac..a4a532b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -45,7 +45,7 @@
org.bukkit
bukkit
- 1.9-SNAPSHOT
+ LATEST
provided
diff --git a/src/at/pcgamingfreaks/MinePacks/Database/Language.java b/src/at/pcgamingfreaks/MinePacks/Database/Language.java
index d356d72..c0cf1bc 100644
--- a/src/at/pcgamingfreaks/MinePacks/Database/Language.java
+++ b/src/at/pcgamingfreaks/MinePacks/Database/Language.java
@@ -28,6 +28,7 @@ public Language(JavaPlugin plugin)
super(plugin, LANG_VERSION);
}
+ @SuppressWarnings("SpellCheckingInspection")
@Override
protected void doUpdate()
{
diff --git a/src/at/pcgamingfreaks/MinePacks/Database/SQL.java b/src/at/pcgamingfreaks/MinePacks/Database/SQL.java
index cace200..1eb8c3b 100644
--- a/src/at/pcgamingfreaks/MinePacks/Database/SQL.java
+++ b/src/at/pcgamingfreaks/MinePacks/Database/SQL.java
@@ -29,12 +29,8 @@
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.ArrayList;
-import java.util.List;
+import java.sql.*;
+import java.util.*;
public abstract class SQL extends Database
{
@@ -109,37 +105,54 @@ public UpdateData(String name, String uuid, int id)
this.uuid = uuid;
}
}
- try
+ try(Connection connection = getConnection())
{
- List converter = new ArrayList<>();
- PreparedStatement ps = getConnection().prepareStatement(Query_FixUUIDs);
- ResultSet res = getConnection().createStatement().executeQuery(Query_GetUnsetOrInvalidUUIDs);
- while(res.next())
+ Map toConvert = new HashMap<>();
+ List toUpdate = new LinkedList<>();
+ try(Statement stmt = connection.createStatement(); ResultSet res = stmt.executeQuery(Query_GetUnsetOrInvalidUUIDs))
{
- if(res.isFirst())
+ while(res.next())
{
- plugin.log.info(plugin.lang.get("Console.UpdateUUIDs"));
- }
- converter.add(new UpdateData(res.getString(2), res.getString(3), res.getInt(1)));
- }
- res.close();
- if(converter.size() > 0)
- {
- for(UpdateData data : converter)
- {
- if(data.uuid == null)
+ if(res.isFirst())
{
- ps.setString(1, UUIDConverter.getUUIDFromName(data.name, true, useUUIDSeparators, false));
+ plugin.log.info(plugin.lang.get("Console.UpdateUUIDs"));
+ }
+ String uuid = res.getString(Field_UUID);
+ if(uuid == null)
+ {
+ toConvert.put(res.getString(Field_Name) ,new UpdateData(res.getString(Field_Name), null, res.getInt(Field_PlayerID)));
}
else
{
- ps.setString(1, (useUUIDSeparators) ? data.uuid.replaceAll("(\\w{8})(\\w{4})(\\w{4})(\\w{4})(\\w{12})", "$1-$2-$3-$4-$5") : data.uuid.replaceAll("-", ""));
+ uuid = (useUUIDSeparators) ? uuid.replaceAll("(\\w{8})(\\w{4})(\\w{4})(\\w{4})(\\w{12})", "$1-$2-$3-$4-$5") : uuid.replaceAll("-", "");
+ toUpdate.add(new UpdateData(res.getString(Field_Name), uuid, res.getInt(Field_PlayerID)));
}
- ps.setInt(2, data.id);
}
- plugin.log.info(String.format(plugin.lang.get("Console.UpdatedUUIDs"), converter.size()));
}
- ps.close();
+ if(toConvert.size() > 0 || toUpdate.size() > 0)
+ {
+ if(toConvert.size() > 0)
+ {
+ Map newUUIDs = UUIDConverter.getUUIDsFromNames(toConvert.keySet(), true, useUUIDSeparators);
+ for(Map.Entry entry : newUUIDs.entrySet())
+ {
+ UpdateData updateData = toConvert.get(entry.getKey());
+ updateData.uuid = entry.getValue();
+ toUpdate.add(updateData);
+ }
+ }
+ try(PreparedStatement ps = connection.prepareStatement(Query_FixUUIDs))
+ {
+ for(UpdateData updateData : toUpdate)
+ {
+ ps.setString(1, updateData.uuid);
+ ps.setInt(2, updateData.id);
+ ps.addBatch();
+ ps.executeBatch();
+ }
+ }
+ plugin.log.info(String.format(plugin.lang.get("Console.UpdatedUUIDs"), toUpdate.size()));
+ }
}
catch(SQLException e)
{