mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-12-22 17:18:47 +01:00
Fixed MySQL bug for loading individual objects.
The code was not loading the uniqueId object. Added a lot of debug code in to help debug.
This commit is contained in:
parent
f109c956bb
commit
fe6159e87b
@ -46,6 +46,8 @@ public abstract class AbstractCommand implements CommandExecutor, TabCompleter {
|
|||||||
private final boolean help;
|
private final boolean help;
|
||||||
private static final int MAX_PER_PAGE = 7;
|
private static final int MAX_PER_PAGE = 7;
|
||||||
|
|
||||||
|
private static final boolean DEBUG = false;
|
||||||
|
|
||||||
protected AbstractCommand(BSkyBlock plugin, String label, String[] aliases, boolean help) {
|
protected AbstractCommand(BSkyBlock plugin, String label, String[] aliases, boolean help) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
this.argumentsMap = new LinkedHashMap<>();
|
this.argumentsMap = new LinkedHashMap<>();
|
||||||
@ -252,6 +254,8 @@ public abstract class AbstractCommand implements CommandExecutor, TabCompleter {
|
|||||||
* @param sender
|
* @param sender
|
||||||
*/
|
*/
|
||||||
private void checkForPlayer(CommandSender sender) {
|
private void checkForPlayer(CommandSender sender) {
|
||||||
|
if (DEBUG)
|
||||||
|
plugin.getLogger().info("DEBUG: checkForPlayer");
|
||||||
// Check if the command sender is a player or not
|
// Check if the command sender is a player or not
|
||||||
if (sender instanceof Player) {
|
if (sender instanceof Player) {
|
||||||
isPlayer = true;
|
isPlayer = true;
|
||||||
@ -262,9 +266,19 @@ public abstract class AbstractCommand implements CommandExecutor, TabCompleter {
|
|||||||
}
|
}
|
||||||
// Check if the player is in a team or not and if so, grab the team leader's UUID
|
// Check if the player is in a team or not and if so, grab the team leader's UUID
|
||||||
if (plugin.getPlayers().inTeam(playerUUID)) {
|
if (plugin.getPlayers().inTeam(playerUUID)) {
|
||||||
|
if (DEBUG)
|
||||||
|
plugin.getLogger().info("DEBUG: player in team");
|
||||||
inTeam = true;
|
inTeam = true;
|
||||||
teamLeaderUUID = plugin.getIslands().getTeamLeader(playerUUID);
|
teamLeaderUUID = plugin.getIslands().getTeamLeader(playerUUID);
|
||||||
|
if (DEBUG)
|
||||||
|
plugin.getLogger().info("DEBUG: team leader UUID = " + teamLeaderUUID);
|
||||||
teamMembers = plugin.getIslands().getMembers(teamLeaderUUID);
|
teamMembers = plugin.getIslands().getMembers(teamLeaderUUID);
|
||||||
|
if (DEBUG) {
|
||||||
|
plugin.getLogger().info("DEBUG: teammembers = ");
|
||||||
|
for (UUID member: teamMembers) {
|
||||||
|
plugin.getLogger().info("DEBUG: " + member);
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
inTeam = false;
|
inTeam = false;
|
||||||
}
|
}
|
||||||
|
@ -501,6 +501,8 @@ public class IslandCommand extends AbstractCommand {
|
|||||||
Util.sendMessage(player, getLocale(sender).get("team.listingMembers"));
|
Util.sendMessage(player, getLocale(sender).get("team.listingMembers"));
|
||||||
// Display members in the list
|
// Display members in the list
|
||||||
for (UUID m : teamMembers) {
|
for (UUID m : teamMembers) {
|
||||||
|
if (DEBUG)
|
||||||
|
plugin.getLogger().info("DEBUG: member " + m);
|
||||||
if (teamLeaderUUID.equals(m)) {
|
if (teamLeaderUUID.equals(m)) {
|
||||||
Util.sendMessage(player, getLocale(sender).get("team.leader-color") + getPlayers().getName(m) + getLocale(sender).get("team.leader"));
|
Util.sendMessage(player, getLocale(sender).get("team.leader-color") + getPlayers().getName(m) + getLocale(sender).get("team.leader"));
|
||||||
} else {
|
} else {
|
||||||
|
@ -49,7 +49,7 @@ import us.tastybento.bskyblock.util.Util;
|
|||||||
*/
|
*/
|
||||||
public class IslandsManager {
|
public class IslandsManager {
|
||||||
|
|
||||||
private static final boolean DEBUG = true;
|
private static final boolean DEBUG = false;
|
||||||
private static final boolean DEBUG2 = false;
|
private static final boolean DEBUG2 = false;
|
||||||
private BSkyBlock plugin;
|
private BSkyBlock plugin;
|
||||||
private BSBDatabase database;
|
private BSBDatabase database;
|
||||||
@ -92,10 +92,20 @@ public class IslandsManager {
|
|||||||
islandsByUUID.clear();
|
islandsByUUID.clear();
|
||||||
spawn = null;
|
spawn = null;
|
||||||
try {
|
try {
|
||||||
|
if (DEBUG)
|
||||||
|
plugin.getLogger().info("DEBUG: loading grid");
|
||||||
for (Island island : handler.loadObjects()) {
|
for (Island island : handler.loadObjects()) {
|
||||||
|
if (DEBUG)
|
||||||
|
plugin.getLogger().info("DEBUG: addin island at "+ island.getCenter());
|
||||||
islandsByLocation.put(island.getCenter(), island);
|
islandsByLocation.put(island.getCenter(), island);
|
||||||
|
if (DEBUG)
|
||||||
|
plugin.getLogger().info("DEBUG: owner = " + island.getOwner());
|
||||||
islandsByUUID.put(island.getOwner(), island);
|
islandsByUUID.put(island.getOwner(), island);
|
||||||
|
if (DEBUG)
|
||||||
|
plugin.getLogger().info("DEBUG: island has " + island.getMembers().size() + " members");
|
||||||
for (UUID member: island.getMembers()) {
|
for (UUID member: island.getMembers()) {
|
||||||
|
if (DEBUG)
|
||||||
|
plugin.getLogger().info("DEBUG: " + member);
|
||||||
islandsByUUID.put(member, island);
|
islandsByUUID.put(member, island);
|
||||||
}
|
}
|
||||||
addToGrid(island);
|
addToGrid(island);
|
||||||
|
@ -66,8 +66,12 @@ public class PlayersManager{
|
|||||||
* @param async - if true, save async
|
* @param async - if true, save async
|
||||||
*/
|
*/
|
||||||
public void save(boolean async){
|
public void save(boolean async){
|
||||||
|
if (DEBUG)
|
||||||
|
plugin.getLogger().info("DEBUG: saving " + async);
|
||||||
Runnable save = () -> {
|
Runnable save = () -> {
|
||||||
for(Players player : playerCache.values()){
|
for(Players player : playerCache.values()){
|
||||||
|
if (DEBUG)
|
||||||
|
plugin.getLogger().info("DEBUG: saving player " + player.getPlayerName() + " "+ player.getUniqueId());
|
||||||
try {
|
try {
|
||||||
handler.saveObject(player);
|
handler.saveObject(player);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@ -331,8 +335,10 @@ public class PlayersManager{
|
|||||||
* @param name
|
* @param name
|
||||||
*/
|
*/
|
||||||
public void setPlayerName(UUID uniqueId, String name) {
|
public void setPlayerName(UUID uniqueId, String name) {
|
||||||
|
if (DEBUG)
|
||||||
|
plugin.getLogger().info("DEBUG: Setting player name to " + name + " for " + uniqueId);
|
||||||
addPlayer(uniqueId);
|
addPlayer(uniqueId);
|
||||||
playerCache.get(uniqueId).setPlayerN(name);
|
playerCache.get(uniqueId).setPlayerName(name);
|
||||||
//database.savePlayerName(name, uniqueId);
|
//database.savePlayerName(name, uniqueId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -344,10 +350,14 @@ public class PlayersManager{
|
|||||||
* @return String - playerName
|
* @return String - playerName
|
||||||
*/
|
*/
|
||||||
public String getName(UUID playerUUID) {
|
public String getName(UUID playerUUID) {
|
||||||
|
if (DEBUG)
|
||||||
|
plugin.getLogger().info("DEBUG: Geting player name");
|
||||||
if (playerUUID == null) {
|
if (playerUUID == null) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
addPlayer(playerUUID);
|
addPlayer(playerUUID);
|
||||||
|
if (DEBUG)
|
||||||
|
plugin.getLogger().info("DEBUG: name is " + playerCache.get(playerUUID).getPlayerName());
|
||||||
return playerCache.get(playerUUID).getPlayerName();
|
return playerCache.get(playerUUID).getPlayerName();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -595,11 +605,12 @@ public class PlayersManager{
|
|||||||
*/
|
*/
|
||||||
public void save(UUID playerUUID) {
|
public void save(UUID playerUUID) {
|
||||||
if (playerCache.containsKey(playerUUID)) {
|
if (playerCache.containsKey(playerUUID)) {
|
||||||
Players player = playerCache.get(playerUUID);
|
final Players player = playerCache.get(playerUUID);
|
||||||
try {
|
try {
|
||||||
handler.saveObject(player);
|
|
||||||
if (DEBUG)
|
if (DEBUG)
|
||||||
plugin.getLogger().info("DEBUG: " + playerUUID + " saved");
|
plugin.getLogger().info("DEBUG: saving player by uuid " + player.getPlayerName() + " " + playerUUID + " saved");
|
||||||
|
handler.saveObject(player);
|
||||||
|
|
||||||
} catch (IllegalAccessException | IllegalArgumentException
|
} catch (IllegalAccessException | IllegalArgumentException
|
||||||
| InvocationTargetException | SecurityException
|
| InvocationTargetException | SecurityException
|
||||||
| InstantiationException | NoSuchMethodException
|
| InstantiationException | NoSuchMethodException
|
||||||
|
@ -45,6 +45,7 @@ import us.tastybento.bskyblock.util.Util;
|
|||||||
*/
|
*/
|
||||||
public class MySQLDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
public class MySQLDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
||||||
|
|
||||||
|
private static final boolean DEBUG = false;
|
||||||
/**
|
/**
|
||||||
* Connection to the database
|
* Connection to the database
|
||||||
*/
|
*/
|
||||||
@ -85,6 +86,9 @@ public class MySQLDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
|||||||
mySQLmapping.put(HashMap.class.getTypeName(), "BOOL");
|
mySQLmapping.put(HashMap.class.getTypeName(), "BOOL");
|
||||||
mySQLmapping.put(ArrayList.class.getTypeName(), "BOOL");
|
mySQLmapping.put(ArrayList.class.getTypeName(), "BOOL");
|
||||||
|
|
||||||
|
// Enums
|
||||||
|
mySQLmapping.put(Enum.class.getTypeName(), "VARCHAR(254)");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -132,7 +136,11 @@ public class MySQLDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
|||||||
// The SQL column name is the name of the field
|
// The SQL column name is the name of the field
|
||||||
String columnName = field.getName();
|
String columnName = field.getName();
|
||||||
// Get the mapping for this field from the hashmap
|
// Get the mapping for this field from the hashmap
|
||||||
String mapping = mySQLmapping.get(propertyDescriptor.getPropertyType().getTypeName());
|
String typeName = propertyDescriptor.getPropertyType().getTypeName();
|
||||||
|
if (propertyDescriptor.getPropertyType().isEnum()) {
|
||||||
|
typeName = "Enum";
|
||||||
|
}
|
||||||
|
String mapping = mySQLmapping.get(typeName);
|
||||||
// If it exists, then create the SQL
|
// If it exists, then create the SQL
|
||||||
if (mapping != null) {
|
if (mapping != null) {
|
||||||
// Note that the column name must be enclosed in `'s because it may include reserved words.
|
// Note that the column name must be enclosed in `'s because it may include reserved words.
|
||||||
@ -153,6 +161,8 @@ public class MySQLDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
|||||||
//plugin.getLogger().info(setSql);
|
//plugin.getLogger().info(setSql);
|
||||||
// Execute the statement
|
// Execute the statement
|
||||||
PreparedStatement collections = connection.prepareStatement(setSql);
|
PreparedStatement collections = connection.prepareStatement(setSql);
|
||||||
|
if (DEBUG)
|
||||||
|
plugin.getLogger().info("DEBUG: collections prepared statement = " + collections.toString());
|
||||||
collections.executeUpdate();
|
collections.executeUpdate();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -160,6 +170,7 @@ public class MySQLDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
|||||||
// This should NOT be used in general because every type should be in the hashmap
|
// This should NOT be used in general because every type should be in the hashmap
|
||||||
sql += field.getName() + " VARCHAR(254),";
|
sql += field.getName() + " VARCHAR(254),";
|
||||||
plugin.getLogger().severe("Unknown type! Hoping it'll fit in a string!");
|
plugin.getLogger().severe("Unknown type! Hoping it'll fit in a string!");
|
||||||
|
plugin.getLogger().severe(propertyDescriptor.getPropertyType().getTypeName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//plugin.getLogger().info("DEBUG: SQL before trim string = " + sql);
|
//plugin.getLogger().info("DEBUG: SQL before trim string = " + sql);
|
||||||
@ -168,6 +179,8 @@ public class MySQLDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
|||||||
//plugin.getLogger().info("DEBUG: SQL string = " + sql);
|
//plugin.getLogger().info("DEBUG: SQL string = " + sql);
|
||||||
// Prepare and execute the database statements
|
// Prepare and execute the database statements
|
||||||
pstmt = connection.prepareStatement(sql);
|
pstmt = connection.prepareStatement(sql);
|
||||||
|
if (DEBUG)
|
||||||
|
plugin.getLogger().info("DEBUG: pstmt = " + pstmt.toString());
|
||||||
pstmt.executeUpdate();
|
pstmt.executeUpdate();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -234,7 +247,6 @@ public class MySQLDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
|||||||
if (createSchema) {
|
if (createSchema) {
|
||||||
// If this is the schema, then guess the mapping type
|
// If this is the schema, then guess the mapping type
|
||||||
columns += " VARCHAR(254)";
|
columns += " VARCHAR(254)";
|
||||||
plugin.getLogger().warning("Unknown type! Hoping it'll fit in a string!");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -318,33 +330,40 @@ public class MySQLDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
|||||||
|
|
||||||
Connection connection = null;
|
Connection connection = null;
|
||||||
PreparedStatement preparedStatement = null;
|
PreparedStatement preparedStatement = null;
|
||||||
|
if (DEBUG)
|
||||||
|
plugin.getLogger().info("DEBUG: saveObject ");
|
||||||
try {
|
try {
|
||||||
// Try to connect to the database
|
// Try to connect to the database
|
||||||
connection = databaseConnecter.createConnection();
|
connection = databaseConnecter.createConnection();
|
||||||
// insertQuery is created in super from the createInsertQuery() method
|
// insertQuery is created in super from the createInsertQuery() method
|
||||||
preparedStatement = connection.prepareStatement(insertQuery);
|
preparedStatement = connection.prepareStatement(insertQuery);
|
||||||
// Get the uniqueId. As each class extends DataObject, it must have this method in it.
|
// Get the uniqueId. As each class extends DataObject, it must have this method in it.
|
||||||
Method getUniqueId = type.getMethod("getUniqueId");
|
PropertyDescriptor propertyDescriptor = new PropertyDescriptor("uniqueId", type);
|
||||||
String uniqueId = (String) getUniqueId.invoke(instance);
|
Method getUniqueId = propertyDescriptor.getReadMethod();
|
||||||
//plugin.getLogger().info("DEBUG: Unique Id = " + uniqueId);
|
final String uniqueId = (String) getUniqueId.invoke(instance);
|
||||||
|
if (DEBUG) {
|
||||||
|
plugin.getLogger().info("DEBUG: Unique Id = " + uniqueId);
|
||||||
|
}
|
||||||
if (uniqueId.isEmpty()) {
|
if (uniqueId.isEmpty()) {
|
||||||
throw new SQLException("uniqueId is blank");
|
throw new SQLException("uniqueId is blank");
|
||||||
}
|
}
|
||||||
// Create the insertion
|
// Create the insertion
|
||||||
int i = 0;
|
int i = 0;
|
||||||
//plugin.getLogger().info("DEBUG: insert Query " + insertQuery);
|
if (DEBUG)
|
||||||
|
plugin.getLogger().info("DEBUG: insert Query " + insertQuery);
|
||||||
// Run through the fields in the class using introspection
|
// Run through the fields in the class using introspection
|
||||||
for (Field field : type.getDeclaredFields()) {
|
for (Field field : type.getDeclaredFields()) {
|
||||||
// Get the field's property descriptor
|
// Get the field's property descriptor
|
||||||
PropertyDescriptor propertyDescriptor = new PropertyDescriptor(field.getName(), type);
|
propertyDescriptor = new PropertyDescriptor(field.getName(), type);
|
||||||
// Get the read method for this field
|
// Get the read method for this field
|
||||||
Method method = propertyDescriptor.getReadMethod();
|
Method method = propertyDescriptor.getReadMethod();
|
||||||
//plugin.getLogger().info("DEBUG: Field = " + field.getName() + "(" + propertyDescriptor.getPropertyType().getTypeName() + ")");
|
if (DEBUG)
|
||||||
|
plugin.getLogger().info("DEBUG: Field = " + field.getName() + "(" + propertyDescriptor.getPropertyType().getTypeName() + ")");
|
||||||
//sql += "`" + field.getName() + "` " + mapping + ",";
|
//sql += "`" + field.getName() + "` " + mapping + ",";
|
||||||
// Invoke the read method to obtain the value from the class - this is the value we need to store in the database
|
// Invoke the read method to obtain the value from the class - this is the value we need to store in the database
|
||||||
Object value = method.invoke(instance);
|
Object value = method.invoke(instance);
|
||||||
|
if (DEBUG)
|
||||||
|
plugin.getLogger().info("DEBUG: value = " + value);
|
||||||
// Create set and map table inserts if this is a Collection
|
// Create set and map table inserts if this is a Collection
|
||||||
if (propertyDescriptor.getPropertyType().equals(Set.class) ||
|
if (propertyDescriptor.getPropertyType().equals(Set.class) ||
|
||||||
propertyDescriptor.getPropertyType().equals(Map.class) ||
|
propertyDescriptor.getPropertyType().equals(Map.class) ||
|
||||||
@ -356,6 +375,8 @@ public class MySQLDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
|||||||
PreparedStatement collStatement = connection.prepareStatement(clearTableSql);
|
PreparedStatement collStatement = connection.prepareStatement(clearTableSql);
|
||||||
collStatement.setString(1, uniqueId);
|
collStatement.setString(1, uniqueId);
|
||||||
collStatement.execute();
|
collStatement.execute();
|
||||||
|
if (DEBUG)
|
||||||
|
plugin.getLogger().info("DEBUG: collStatement " + collStatement.toString());
|
||||||
// Insert into the table
|
// Insert into the table
|
||||||
String setSql = "INSERT INTO `" + type.getCanonicalName() + "." + field.getName() + "` (uniqueId, ";
|
String setSql = "INSERT INTO `" + type.getCanonicalName() + "." + field.getName() + "` (uniqueId, ";
|
||||||
// Get the columns we are going to insert, just the names of them
|
// Get the columns we are going to insert, just the names of them
|
||||||
@ -364,7 +385,8 @@ public class MySQLDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
|||||||
setSql += "VALUES ('" + uniqueId + "'," + getCollectionColumns(propertyDescriptor.getWriteMethod(), true, false) + ")";
|
setSql += "VALUES ('" + uniqueId + "'," + getCollectionColumns(propertyDescriptor.getWriteMethod(), true, false) + ")";
|
||||||
// Prepare the statement
|
// Prepare the statement
|
||||||
collStatement = connection.prepareStatement(setSql);
|
collStatement = connection.prepareStatement(setSql);
|
||||||
//plugin.getLogger().info("DEBUG: collection insert =" + setSql);
|
if (DEBUG)
|
||||||
|
plugin.getLogger().info("DEBUG: collection insert =" + setSql);
|
||||||
// Do single dimension types (set and list)
|
// Do single dimension types (set and list)
|
||||||
if (propertyDescriptor.getPropertyType().equals(Set.class) ||
|
if (propertyDescriptor.getPropertyType().equals(Set.class) ||
|
||||||
propertyDescriptor.getPropertyType().equals(ArrayList.class)) {
|
propertyDescriptor.getPropertyType().equals(ArrayList.class)) {
|
||||||
@ -381,7 +403,8 @@ public class MySQLDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
|||||||
//}
|
//}
|
||||||
// Set the value from ? to whatever it is
|
// Set the value from ? to whatever it is
|
||||||
collStatement.setObject(1, setValue);
|
collStatement.setObject(1, setValue);
|
||||||
//plugin.getLogger().info("DEBUG: " + collStatement.toString());
|
if (DEBUG)
|
||||||
|
plugin.getLogger().info("DEBUG: " + collStatement.toString());
|
||||||
// Execute the SQL in the database
|
// Execute the SQL in the database
|
||||||
collStatement.execute();
|
collStatement.execute();
|
||||||
}
|
}
|
||||||
@ -400,7 +423,8 @@ public class MySQLDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
|||||||
// Write the objects into prepared statement
|
// Write the objects into prepared statement
|
||||||
collStatement.setObject(1, key);
|
collStatement.setObject(1, key);
|
||||||
collStatement.setObject(2, mapValue);
|
collStatement.setObject(2, mapValue);
|
||||||
//plugin.getLogger().info("DEBUG: " + collStatement.toString());
|
if (DEBUG)
|
||||||
|
plugin.getLogger().info("DEBUG: " + collStatement.toString());
|
||||||
// Write to database
|
// Write to database
|
||||||
collStatement.execute();
|
collStatement.execute();
|
||||||
}
|
}
|
||||||
@ -419,6 +443,8 @@ public class MySQLDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
|||||||
// Add the statements to a batch
|
// Add the statements to a batch
|
||||||
preparedStatement.addBatch();
|
preparedStatement.addBatch();
|
||||||
// Execute
|
// Execute
|
||||||
|
if (DEBUG)
|
||||||
|
plugin.getLogger().info("DEBUG: prepared statement = " + preparedStatement.toString());
|
||||||
preparedStatement.executeBatch();
|
preparedStatement.executeBatch();
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
@ -497,6 +523,8 @@ public class MySQLDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
|||||||
try {
|
try {
|
||||||
connection = databaseConnecter.createConnection();
|
connection = databaseConnecter.createConnection();
|
||||||
statement = connection.createStatement();
|
statement = connection.createStatement();
|
||||||
|
if (DEBUG)
|
||||||
|
plugin.getLogger().info("DEBUG: selectQuery = " + selectQuery);
|
||||||
resultSet = statement.executeQuery(selectQuery);
|
resultSet = statement.executeQuery(selectQuery);
|
||||||
|
|
||||||
return createObjects(resultSet);
|
return createObjects(resultSet);
|
||||||
@ -518,11 +546,16 @@ public class MySQLDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
|||||||
Connection connection = null;
|
Connection connection = null;
|
||||||
Statement statement = null;
|
Statement statement = null;
|
||||||
ResultSet resultSet = null;
|
ResultSet resultSet = null;
|
||||||
|
if (DEBUG)
|
||||||
|
plugin.getLogger().info("DEBUG: loading object for " + uniqueId);
|
||||||
try {
|
try {
|
||||||
connection = databaseConnecter.createConnection();
|
connection = databaseConnecter.createConnection();
|
||||||
statement = connection.createStatement();
|
String query = "SELECT " + super.getColumns(false) + " FROM `" + type.getCanonicalName() + "` WHERE uniqueId = ? LIMIT 1";
|
||||||
resultSet = statement.executeQuery(selectQuery);
|
PreparedStatement preparedStatement = connection.prepareStatement(query);
|
||||||
|
preparedStatement.setString(1, uniqueId);
|
||||||
|
if (DEBUG)
|
||||||
|
plugin.getLogger().info("DEBUG: load Object query = " + preparedStatement.toString());
|
||||||
|
resultSet = preparedStatement.executeQuery();
|
||||||
|
|
||||||
List<T> result = createObjects(resultSet);
|
List<T> result = createObjects(resultSet);
|
||||||
if (!result.isEmpty()) {
|
if (!result.isEmpty()) {
|
||||||
@ -605,22 +638,25 @@ public class MySQLDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
|||||||
PreparedStatement collStatement = connection.prepareStatement(setSql);
|
PreparedStatement collStatement = connection.prepareStatement(setSql);
|
||||||
// Set the unique ID
|
// Set the unique ID
|
||||||
collStatement.setObject(1, uniqueId);
|
collStatement.setObject(1, uniqueId);
|
||||||
//plugin.getLogger().info("DEBUG: collStatement = " + collStatement.toString());
|
if (DEBUG)
|
||||||
|
plugin.getLogger().info("DEBUG: collStatement = " + collStatement.toString());
|
||||||
ResultSet collectionResultSet = collStatement.executeQuery();
|
ResultSet collectionResultSet = collStatement.executeQuery();
|
||||||
//plugin.getLogger().info("DEBUG: collectionResultSet = " + collectionResultSet.toString());
|
//plugin.getLogger().info("DEBUG: collectionResultSet = " + collectionResultSet.toString());
|
||||||
// Do single dimension types (set and list)
|
// Do single dimension types (set and list)
|
||||||
if (propertyDescriptor.getPropertyType().equals(Set.class)) {
|
if (propertyDescriptor.getPropertyType().equals(Set.class)) {
|
||||||
//plugin.getLogger().info("DEBUG: adding a set");
|
if (DEBUG)
|
||||||
|
plugin.getLogger().info("DEBUG: adding a set");
|
||||||
// Loop through the collection resultset
|
// Loop through the collection resultset
|
||||||
// Note that we have no idea what type this is
|
// Note that we have no idea what type this is
|
||||||
List<Type> collectionTypes = Util.getCollectionParameterTypes(method);
|
List<Type> collectionTypes = Util.getCollectionParameterTypes(method);
|
||||||
// collectionTypes should be only 1 long
|
// collectionTypes should be only 1 long
|
||||||
Type setType = collectionTypes.get(0);
|
Type setType = collectionTypes.get(0);
|
||||||
value = new HashSet<Object>();
|
value = new HashSet<Object>();
|
||||||
//plugin.getLogger().info("DEBUG: collection type argument = " + collectionTypes);
|
if (DEBUG) {
|
||||||
//plugin.getLogger().info("DEBUG: setType = " + setType.getTypeName());
|
plugin.getLogger().info("DEBUG: collection type argument = " + collectionTypes);
|
||||||
|
plugin.getLogger().info("DEBUG: setType = " + setType.getTypeName());
|
||||||
|
}
|
||||||
while (collectionResultSet.next()) {
|
while (collectionResultSet.next()) {
|
||||||
//plugin.getLogger().info("DEBUG: collectionResultSet size = " + collectionResultSet.getFetchSize());
|
|
||||||
((Set<Object>) value).add(deserialize(collectionResultSet.getObject(1),Class.forName(setType.getTypeName())));
|
((Set<Object>) value).add(deserialize(collectionResultSet.getObject(1),Class.forName(setType.getTypeName())));
|
||||||
}
|
}
|
||||||
} else if (propertyDescriptor.getPropertyType().equals(ArrayList.class)) {
|
} else if (propertyDescriptor.getPropertyType().equals(ArrayList.class)) {
|
||||||
@ -750,6 +786,7 @@ public class MySQLDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
|||||||
// Second is the unique ID
|
// Second is the unique ID
|
||||||
preparedStatement.setString(1, uniqueId);
|
preparedStatement.setString(1, uniqueId);
|
||||||
preparedStatement.addBatch();
|
preparedStatement.addBatch();
|
||||||
|
if (DEBUG)
|
||||||
plugin.getLogger().info("DEBUG: DELETE Query " + preparedStatement.toString());
|
plugin.getLogger().info("DEBUG: DELETE Query " + preparedStatement.toString());
|
||||||
preparedStatement.executeBatch();
|
preparedStatement.executeBatch();
|
||||||
// Delete from any sub tables created from the object
|
// Delete from any sub tables created from the object
|
||||||
@ -768,6 +805,7 @@ public class MySQLDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
|||||||
preparedStatement.setString(1, uniqueId);
|
preparedStatement.setString(1, uniqueId);
|
||||||
preparedStatement.addBatch();
|
preparedStatement.addBatch();
|
||||||
// Execute
|
// Execute
|
||||||
|
if (DEBUG)
|
||||||
plugin.getLogger().info("DEBUG: " + preparedStatement.toString());
|
plugin.getLogger().info("DEBUG: " + preparedStatement.toString());
|
||||||
preparedStatement.executeBatch();
|
preparedStatement.executeBatch();
|
||||||
}
|
}
|
||||||
@ -784,16 +822,25 @@ public class MySQLDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean objectExits(String key) {
|
public boolean objectExits(String key) {
|
||||||
|
if (DEBUG)
|
||||||
|
plugin.getLogger().info("DEBUG: checking if " + key + " exists in the database");
|
||||||
Connection connection = null;
|
Connection connection = null;
|
||||||
PreparedStatement preparedStatement = null;
|
PreparedStatement preparedStatement = null;
|
||||||
ResultSet resultSet = null;
|
ResultSet resultSet = null;
|
||||||
String query = "SELECT * FROM `" + type.getCanonicalName() + "` WHERE uniqueId = ?";
|
String query = "SELECT IF ( EXISTS( SELECT * FROM `" + type.getCanonicalName() + "` WHERE `uniqueId` = ?), 1, 0)";
|
||||||
|
//String query = "SELECT * FROM `" + type.getCanonicalName() + "` WHERE uniqueId = ?";
|
||||||
try {
|
try {
|
||||||
connection = databaseConnecter.createConnection();
|
connection = databaseConnecter.createConnection();
|
||||||
preparedStatement = connection.prepareStatement(query);
|
preparedStatement = connection.prepareStatement(query);
|
||||||
preparedStatement.setString(1, key);
|
preparedStatement.setString(1, key);
|
||||||
resultSet = preparedStatement.executeQuery();
|
resultSet = preparedStatement.executeQuery();
|
||||||
return resultSet.next();
|
if (DEBUG)
|
||||||
|
plugin.getLogger().info("DEBUG: object exists sql " + preparedStatement.toString());
|
||||||
|
if (resultSet.next()) {
|
||||||
|
if (DEBUG)
|
||||||
|
plugin.getLogger().info("DEBUG: result is " + resultSet.getBoolean(1));
|
||||||
|
return resultSet.getBoolean(1);
|
||||||
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} finally {
|
} finally {
|
||||||
|
@ -680,6 +680,7 @@ public class Island extends DataObject {
|
|||||||
* @param members - the members to set
|
* @param members - the members to set
|
||||||
*/
|
*/
|
||||||
public void setMembers(Set<UUID> members){
|
public void setMembers(Set<UUID> members){
|
||||||
|
//Bukkit.getLogger().info("DEBUG: members size = " + members.size());
|
||||||
this.members = members;
|
this.members = members;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -135,10 +135,6 @@ public class Players extends DataObject {
|
|||||||
return playerName;
|
return playerName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPlayerN(String playerName) {
|
|
||||||
this.playerName = playerName;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the resetsLeft
|
* @return the resetsLeft
|
||||||
*/
|
*/
|
||||||
|
@ -2,7 +2,6 @@ package us.tastybento.bskyblock.listeners;
|
|||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
|
@ -65,12 +65,12 @@ public class SchematicsMgr {
|
|||||||
// built-in island generation
|
// built-in island generation
|
||||||
schematics.put("default",new Schematic(plugin));
|
schematics.put("default",new Schematic(plugin));
|
||||||
}
|
}
|
||||||
plugin.getLogger().info("Loaded default nether schematic");
|
//plugin.getLogger().info("Loaded default nether schematic");
|
||||||
} else {
|
} else {
|
||||||
// It exists, so load it
|
// It exists, so load it
|
||||||
try {
|
try {
|
||||||
schematics.put("default",new Schematic(plugin, schematicFile));
|
schematics.put("default",new Schematic(plugin, schematicFile));
|
||||||
plugin.getLogger().info("Loaded default island schematic.");
|
//plugin.getLogger().info("Loaded default island schematic.");
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
plugin.getLogger().severe("Could not load default schematic!");
|
plugin.getLogger().severe("Could not load default schematic!");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -86,7 +86,7 @@ public class SchematicsMgr {
|
|||||||
Schematic netherIsland = new Schematic(plugin, netherFile);
|
Schematic netherIsland = new Schematic(plugin, netherFile);
|
||||||
netherIsland.setVisible(false);
|
netherIsland.setVisible(false);
|
||||||
schematics.put("nether", netherIsland);
|
schematics.put("nether", netherIsland);
|
||||||
plugin.getLogger().info("Loaded default nether schematic.");
|
//plugin.getLogger().info("Loaded default nether schematic.");
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
plugin.getLogger().severe("Could not load default nether schematic!");
|
plugin.getLogger().severe("Could not load default nether schematic!");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -100,7 +100,7 @@ public class SchematicsMgr {
|
|||||||
Schematic netherIsland = new Schematic(plugin, netherFile);
|
Schematic netherIsland = new Schematic(plugin, netherFile);
|
||||||
netherIsland.setVisible(false);
|
netherIsland.setVisible(false);
|
||||||
schematics.put("nether", netherIsland);
|
schematics.put("nether", netherIsland);
|
||||||
plugin.getLogger().info("Loaded default nether schematic.");
|
//plugin.getLogger().info("Loaded default nether schematic.");
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
plugin.getLogger().severe("Could not load default nether schematic!");
|
plugin.getLogger().severe("Could not load default nether schematic!");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
Loading…
Reference in New Issue
Block a user