Replaced raw stack trace dumps with helpful error messages.

This commit is contained in:
tastybento 2018-02-06 16:37:34 -08:00
parent aac17990bc
commit bb404380f5
8 changed files with 34 additions and 49 deletions

View File

@ -60,9 +60,8 @@ public class IslandCreateCommand extends CompositeCommand {
.reason(Reason.CREATE)
.build();
} catch (IOException e) {
getPlugin().getLogger().severe("Could not create island for player.");
getPlugin().getLogger().severe("Could not create island for player. " + e.getMessage());
user.sendMessage("commands.island.create.unable-create-island");
e.printStackTrace();
}
}
}

View File

@ -62,9 +62,8 @@ public class IslandResetCommand extends CompositeCommand {
.oldIsland(oldIsland)
.build();
} catch (IOException e) {
getPlugin().getLogger().severe("Could not create island for player.");
getPlugin().getLogger().severe("Could not create island for player. " + e.getMessage());
user.sendMessage("commands.island.create.unable-create-island");
e.printStackTrace();
}
return true;
}

View File

@ -5,6 +5,7 @@ import java.sql.Connection;
import java.sql.SQLException;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.Plugin;
@ -52,7 +53,7 @@ public class FlatFileDatabaseConnecter implements DatabaseConnecter {
config = new YamlConfiguration();
config.load(yamlFile);
} catch (Exception e) {
e.printStackTrace();
Bukkit.getLogger().severe("Could not load yaml file from database " + tableName + " " + fileName + " " + e.getMessage());
}
} else {
// Create the missing file
@ -93,7 +94,7 @@ public class FlatFileDatabaseConnecter implements DatabaseConnecter {
try {
yamlConfig.save(file);
} catch (Exception e) {
e.printStackTrace();
Bukkit.getLogger().severe("Could not save yaml file to database " + tableName + " " + fileName + " " + e.getMessage());
}
}

View File

@ -361,24 +361,23 @@ public class FlatFileDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
storageLocation = configEntry.path();
}
// TODO: add in game-specific saving
}
Adapter adapterNotation = field.getAnnotation(Adapter.class);
if (adapterNotation != null && AdapterInterface.class.isAssignableFrom(adapterNotation.value())) {
if (DEBUG)
plugin.getLogger().info("DEBUG: there is an adapter");
// A conversion adapter has been defined
// A conversion adapter has been defined
// A conversion adapter has been defined
try {
config.set(storageLocation, ((AdapterInterface<?,?>)adapterNotation.value().newInstance()).deserialize(value));
} catch (InstantiationException e) {
e.printStackTrace();
plugin.getLogger().severe("Could not instatiate adapter " + adapterNotation.value().getName() + " " + e.getMessage());
}
// We are done here
continue fields;
}
//plugin.getLogger().info("DEBUG: property desc = " + propertyDescriptor.getPropertyType().getTypeName());
// Depending on the vale type, it'll need serializing differenty
// Check if this field is the mandatory UniqueId field. This is used to identify this instantiation of the class
@ -503,7 +502,7 @@ public class FlatFileDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
} catch (Exception e) {
// Maybe this value does not exist?
// TODO return something?
e.printStackTrace();
plugin.getLogger().severe("Could not deserialize enum: " + clazz.getCanonicalName() + " " + value);
}
}
return value;
@ -522,7 +521,9 @@ public class FlatFileDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
File tableFolder = new File(dataFolder, dataObject.getSimpleName());
if (tableFolder.exists()) {
File file = new File(tableFolder, fileName);
file.delete();
if (!file.delete()) {
plugin.getLogger().severe("Could not delete yaml database object! " + file.getName());
}
}
}

View File

@ -31,7 +31,6 @@ public class PlayersManager{
private HashMap<UUID, Players> playerCache;
private Set<UUID> inTeleport;
private HashMap<String, UUID> nameCache;
/**
* Provides a memory cache of online player information
@ -62,7 +61,7 @@ public class PlayersManager{
playerCache.put(player.getPlayerUUID(), player);
}
} catch (Exception e) {
e.printStackTrace();
plugin.getLogger().severe("Could not load players from the database!" + e.getMessage());
}
}
@ -82,7 +81,7 @@ public class PlayersManager{
try {
handler.saveObject(player);
} catch (Exception e) {
e.printStackTrace();
plugin.getLogger().severe("Could not save player " + player.getPlayerName() + " "+ player.getUniqueId() + " " + e.getMessage());
}
}
};
@ -94,7 +93,7 @@ public class PlayersManager{
try {
handler.saveObject(player);
} catch (Exception e) {
e.printStackTrace();
plugin.getLogger().severe("Could not save player " + player.getPlayerName() + " "+ player.getUniqueId() + " " + e.getMessage());
}
}
}
@ -137,7 +136,7 @@ public class PlayersManager{
try {
player = handler.loadObject(playerUUID.toString());
} catch (Exception e) {
e.printStackTrace();
plugin.getLogger().severe("Could not load player " + playerUUID + " " + e.getMessage());
}
} else {
if (DEBUG)
@ -160,26 +159,16 @@ public class PlayersManager{
*
*/
public void removeOnlinePlayer(final UUID player) {
// plugin.getLogger().info("Removing player from cache: " + player);
if (playerCache.containsKey(player)) {
try {
handler.saveObject(playerCache.get(player));
playerCache.remove(player);
} catch (IllegalAccessException | IllegalArgumentException
| InvocationTargetException | SecurityException
| InstantiationException | NoSuchMethodException
| IntrospectionException | SQLException e) {
e.printStackTrace();
}
}
save(player);
playerCache.remove(player);
}
/**
* Removes all players on the server now from cache and saves their info
* Saves all players on the server and clears the cache
*/
public void removeAllPlayers() {
for (UUID pl : playerCache.keySet()) {
removeOnlinePlayer(pl);
save(pl);
}
playerCache.clear();
}
@ -597,7 +586,7 @@ public class PlayersManager{
| InvocationTargetException | SecurityException
| InstantiationException | NoSuchMethodException
| IntrospectionException | SQLException e) {
e.printStackTrace();
plugin.getLogger().severe("Could not save player to database: " + playerUUID + " " + e.getMessage());
}
} else {
if (DEBUG)

View File

@ -271,7 +271,7 @@ public class IslandsManager {
try {
handler.deleteObject(island);
} catch (Exception e) {
e.printStackTrace();
plugin.getLogger().severe("Could not delete island from database! " + e.getMessage());
}
// Remove blocks from world
new DeleteIslandChunks(plugin, island);
@ -716,7 +716,7 @@ public class IslandsManager {
islandCache.addIsland(island);
}
} catch (Exception e) {
e.printStackTrace();
plugin.getLogger().severe("Could not load islands to cache! " + e.getMessage());
}
if (DEBUG)
plugin.getLogger().info("DEBUG: islands loaded");
@ -930,7 +930,7 @@ public class IslandsManager {
try {
handler.saveObject(island);
} catch (Exception e) {
e.printStackTrace();
plugin.getLogger().severe("Could not save island to datavase when running async! " + e.getMessage());
}
}
};
@ -943,7 +943,7 @@ public class IslandsManager {
try {
handler.saveObject(island);
} catch (Exception e) {
e.printStackTrace();
plugin.getLogger().severe("Could not save island to datavase when running sync! " + e.getMessage());
}
}
}

View File

@ -4,6 +4,7 @@ import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.YamlConfiguration;
import us.tastybento.bskyblock.database.DatabaseConnecter;
@ -24,8 +25,7 @@ public class MySQLDatabaseConnecter implements DatabaseConnecter {
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
Bukkit.getLogger().severe("Could not instantiate JDBC driver! " + e.getMessage());
}
// jdbc:mysql://localhost:3306/Peoples?autoReconnect=true&useSSL=false
connectionUrl = "jdbc:mysql://" + dbSettings.getHost() + "/" + dbSettings.getDatabaseName() + "?autoReconnect=true&useSSL=false&allowMultiQueries=true";

View File

@ -113,10 +113,8 @@ public class MySQLDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
// Check if the table exists in the database and if not, create it
try {
createSchema();
} catch (IntrospectionException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
} catch (IntrospectionException | SQLException e) {
plugin.getLogger().severe("Could not create database schema! " + e.getMessage());
}
}
@ -188,7 +186,7 @@ public class MySQLDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
plugin.getLogger().info("DEBUG: pstmt = " + pstmt.toString());
pstmt.executeUpdate();
} catch (Exception e) {
e.printStackTrace();
plugin.getLogger().severe("Could not create database schema! " + e.getMessage());
} finally {
// Close the database properly
MySQLDatabaseResourceCloser.close(pstmt);
@ -858,9 +856,7 @@ public class MySQLDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
Class<Enum> enumClass = (Class<Enum>)clazz;
value = Enum.valueOf(enumClass, (String)value);
} catch (Exception e) {
// Maybe this value does not exist?
// TODO return something?
e.printStackTrace();
plugin.getLogger().severe("Could not deserialize enum! " + e.getMessage());
}
}
return value;
@ -952,7 +948,7 @@ public class MySQLDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
return resultSet.getBoolean(1);
}
} catch (SQLException e) {
e.printStackTrace();
plugin.getLogger().severe("Could not check if key exists in database! " + key + " " + e.getMessage());
} finally {
MySQLDatabaseResourceCloser.close(resultSet);
MySQLDatabaseResourceCloser.close(preparedStatement);