Removed almost every stack trace that might me printed

Stack traces will now be printed in the debug log (if enabled) and in the console, there will only be displayed an error message without the stack trace
This commit is contained in:
Eric 2016-08-10 13:42:02 +02:00
parent 6bce68768a
commit 51584a3d04
11 changed files with 58 additions and 48 deletions

View File

@ -95,6 +95,7 @@ public class ShopChest extends JavaPlugin {
fw = new FileWriter(debugLogFile, true); fw = new FileWriter(debugLogFile, true);
} catch (IOException e) { } catch (IOException e) {
getLogger().info("Failed to instantiate FileWriter");
e.printStackTrace(); e.printStackTrace();
} }
} }
@ -272,9 +273,9 @@ public class ShopChest extends JavaPlugin {
debug("Trying to register command \"/" + config.main_command_name + "\""); debug("Trying to register command \"/" + config.main_command_name + "\"");
ShopCommand.registerCommand(new ShopCommand(this, config.main_command_name, "Manage Shops.", "", new ArrayList<String>()), this); ShopCommand.registerCommand(new ShopCommand(this, config.main_command_name, "Manage Shops.", "", new ArrayList<String>()), this);
} catch (Exception e) { } catch (Exception e) {
getLogger().info("Failed to register command");
debug("Failed to register command"); debug("Failed to register command");
debug(e); debug(e);
e.printStackTrace();
} }
initializeShops(); initializeShops();
@ -312,6 +313,7 @@ public class ShopChest extends JavaPlugin {
try { try {
fw.close(); fw.close();
} catch (IOException e) { } catch (IOException e) {
getLogger().severe("Failed to close FileWriter");
e.printStackTrace(); e.printStackTrace();
} }
} }

View File

@ -342,7 +342,7 @@ public class Config {
langConfig.loadFromString(sb.toString()); langConfig.loadFromString(sb.toString());
} catch (IOException | InvalidConfigurationException ex) { } catch (IOException | InvalidConfigurationException ex) {
ex.printStackTrace(); plugin.debug(ex);
plugin.getLogger().warning("Using default language values"); plugin.getLogger().warning("Using default language values");
} }
} else { } else {
@ -350,7 +350,7 @@ public class Config {
langConfig.load(langDefaultFile); langConfig.load(langDefaultFile);
plugin.getLogger().info("Using locale \"en_US\""); plugin.getLogger().info("Using locale \"en_US\"");
} catch (IOException | InvalidConfigurationException e) { } catch (IOException | InvalidConfigurationException e) {
e.printStackTrace(); plugin.debug(e);
plugin.getLogger().warning("Using default language values"); plugin.getLogger().warning("Using default language values");
} }
} }
@ -359,7 +359,7 @@ public class Config {
plugin.getLogger().info("Using locale \"" + langConfigFile.getName().substring(0, langConfigFile.getName().length() - 5) + "\""); plugin.getLogger().info("Using locale \"" + langConfigFile.getName().substring(0, langConfigFile.getName().length() - 5) + "\"");
langConfig.load(langConfigFile); langConfig.load(langConfigFile);
} catch (IOException | InvalidConfigurationException ex) { } catch (IOException | InvalidConfigurationException ex) {
ex.printStackTrace(); plugin.debug(ex);
plugin.getLogger().warning("Using default language values"); plugin.getLogger().warning("Using default language values");
} }
} }

View File

@ -73,9 +73,9 @@ public class Hologram {
this.location.subtract(0, 0.25, 0); this.location.subtract(0, 0.25, 0);
count++; count++;
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | InstantiationException e) { } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | InstantiationException e) {
plugin.getLogger().severe("Could not create Hologram with reflection");
plugin.debug("Could not create Hologram with reflection"); plugin.debug("Could not create Hologram with reflection");
plugin.debug(e); plugin.debug(e);
e.printStackTrace();
} }
@ -107,9 +107,9 @@ public class Hologram {
Utils.sendPacket(plugin, packet, p); Utils.sendPacket(plugin, packet, p);
} catch (NoSuchMethodException | InstantiationException | InvocationTargetException | IllegalAccessException e) { } catch (NoSuchMethodException | InstantiationException | InvocationTargetException | IllegalAccessException e) {
plugin.getLogger().severe("Could not show Hologram to player with reflection");
plugin.debug("Could not show Hologram to player with reflection"); plugin.debug("Could not show Hologram to player with reflection");
plugin.debug(e); plugin.debug(e);
e.printStackTrace();
} }
} }
visible.add(p); visible.add(p);
@ -127,9 +127,9 @@ public class Hologram {
Utils.sendPacket(plugin, packet, p); Utils.sendPacket(plugin, packet, p);
} catch (NoSuchMethodException | InstantiationException | InvocationTargetException | IllegalAccessException e) { } catch (NoSuchMethodException | InstantiationException | InvocationTargetException | IllegalAccessException e) {
plugin.getLogger().severe("Could not hide Hologram from player with reflection");
plugin.debug("Could not hide Hologram from player with reflection"); plugin.debug("Could not hide Hologram from player with reflection");
plugin.debug(e); plugin.debug(e);
e.printStackTrace();
} }
} }
visible.remove(p); visible.remove(p);
@ -159,9 +159,9 @@ public class Hologram {
try { try {
o.getClass().getMethod("die").invoke(o); o.getClass().getMethod("die").invoke(o);
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
plugin.getLogger().severe("Could not remove Hologram with reflection");
plugin.debug("Could not remove Hologram with reflection"); plugin.debug("Could not remove Hologram with reflection");
plugin.debug(e); plugin.debug(e);
e.printStackTrace();
} }
} }
exists = false; exists = false;

View File

@ -117,9 +117,9 @@ public class JsonBuilder {
Utils.sendPacket(plugin, packetPlayOutChat, p); Utils.sendPacket(plugin, packetPlayOutChat, p);
} catch (InstantiationException | InvocationTargetException | } catch (InstantiationException | InvocationTargetException |
IllegalAccessException | NoSuchMethodException e) { IllegalAccessException | NoSuchMethodException e) {
plugin.debug("Failed to send packet with reflection"); plugin.getLogger().severe("Failed to send JSON with reflection");
plugin.debug("Failed to send JSON with reflection");
plugin.debug(e); plugin.debug(e);
e.printStackTrace();
} }
} }

View File

@ -30,9 +30,9 @@ public class SpawnEggMeta {
if (id instanceof String) return (String) id; if (id instanceof String) return (String) id;
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
plugin.debug("Could not get NBTEntityID with reflection"); plugin.getLogger().severe("Failed to get NBTEntityID with reflection");
plugin.debug("Failed to get NBTEntityID with reflection");
plugin.debug(e); plugin.debug(e);
e.printStackTrace();
} }
return null; return null;

View File

@ -42,26 +42,16 @@ public class Shop {
Block b = location.getBlock(); Block b = location.getBlock();
if (b.getType() != Material.CHEST && b.getType() != Material.TRAPPED_CHEST) { if (b.getType() != Material.CHEST && b.getType() != Material.TRAPPED_CHEST) {
try {
plugin.getShopUtils().removeShop(this, plugin.getShopChestConfig().remove_shop_on_error); plugin.getShopUtils().removeShop(this, plugin.getShopChestConfig().remove_shop_on_error);
Exception e = new Exception("No Chest found at specified Location: " + b.getX() + "; " + b.getY() + "; " + b.getZ()); plugin.getLogger().severe("No Chest found at specified Location: " + b.getX() + "; " + b.getY() + "; " + b.getZ());
plugin.debug(e); plugin.debug("No Chest found at specified Location: " + b.getX() + "; " + b.getY() + "; " + b.getZ());
throw e;
} catch (Exception ex) {
ex.printStackTrace();
return; return;
}
} else if ((b.getRelative(BlockFace.UP).getType() != Material.AIR) && plugin.getShopChestConfig().show_shop_items) { } else if ((b.getRelative(BlockFace.UP).getType() != Material.AIR) && plugin.getShopChestConfig().show_shop_items) {
try {
plugin.getShopUtils().removeShop(this, plugin.getShopChestConfig().remove_shop_on_error); plugin.getShopUtils().removeShop(this, plugin.getShopChestConfig().remove_shop_on_error);
Exception e = new Exception("No space above chest at specified Location: " + b.getX() + "; " + b.getY() + "; " + b.getZ()); plugin.getLogger().severe("No space above chest at specified Location: " + b.getX() + "; " + b.getY() + "; " + b.getZ());
plugin.debug(e); plugin.debug("No space above chest at specified Location: " + b.getX() + "; " + b.getY() + "; " + b.getZ());
throw e;
} catch (Exception ex) {
ex.printStackTrace();
return; return;
} }
}
if (hologram == null || !hologram.exists()) createHologram(); if (hologram == null || !hologram.exists()) createHologram();
if (item == null) createItem(); if (item == null) createItem();

View File

@ -80,9 +80,9 @@ public class ShopItem {
creationPackets[1] = packetPlayOutEntityMetadataClass.getConstructor(int.class, dataWatcherClass, boolean.class).newInstance(entityId, dataWatcher, true); creationPackets[1] = packetPlayOutEntityMetadataClass.getConstructor(int.class, dataWatcherClass, boolean.class).newInstance(entityId, dataWatcher, true);
creationPackets[2] = packetPlayOutEntityVelocityClass.getConstructor(int.class, double.class, double.class, double.class).newInstance(entityId, 0D, 0D, 0D); creationPackets[2] = packetPlayOutEntityVelocityClass.getConstructor(int.class, double.class, double.class, double.class).newInstance(entityId, 0D, 0D, 0D);
} catch (NoSuchMethodException | NoSuchFieldException | InstantiationException | IllegalAccessException | InvocationTargetException e) { } catch (NoSuchMethodException | NoSuchFieldException | InstantiationException | IllegalAccessException | InvocationTargetException e) {
plugin.getLogger().severe("Failed to create shop item");
plugin.debug("Failed to create shop item with reflection"); plugin.debug("Failed to create shop item with reflection");
plugin.debug(e); plugin.debug(e);
e.printStackTrace();
} }
} }
@ -120,9 +120,9 @@ public class ShopItem {
Utils.sendPacket(plugin, packetPlayOutEntityDestroy, p); Utils.sendPacket(plugin, packetPlayOutEntityDestroy, p);
} }
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | InstantiationException e) { } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | InstantiationException e) {
plugin.getLogger().severe("Failed to destroy shop item");
plugin.debug("Failed to destroy shop item with reflection"); plugin.debug("Failed to destroy shop item with reflection");
plugin.debug(e); plugin.debug(e);
e.printStackTrace();
} }
} }

View File

@ -68,9 +68,9 @@ public abstract class Database {
close(ps, rs); close(ps, rs);
} catch (SQLException ex) { } catch (SQLException ex) {
plugin.getLogger().severe("Failed to connect to database");
plugin.debug("Failed to connect to database"); plugin.debug("Failed to connect to database");
plugin.debug(ex); plugin.debug(ex);
ex.printStackTrace();
} }
} }
@ -112,7 +112,8 @@ public abstract class Database {
return highestID; return highestID;
} catch (SQLException ex) { } catch (SQLException ex) {
ex.printStackTrace(); plugin.debug("Failed to get highest used ID");
plugin.getLogger().severe("Failed to access database");
} finally { } finally {
close(ps, rs); close(ps, rs);
} }
@ -133,7 +134,9 @@ public abstract class Database {
plugin.debug("Removing shop from database (#" + shop.getID() + ")"); plugin.debug("Removing shop from database (#" + shop.getID() + ")");
ps.executeUpdate(); ps.executeUpdate();
} catch (SQLException ex) { } catch (SQLException ex) {
ex.printStackTrace(); plugin.getLogger().severe("Failed to access database");
plugin.debug("Failed to remove shop from database (#" + shop.getID() + ")");
plugin.debug(ex);
} finally { } finally {
close(ps, null); close(ps, null);
} }
@ -210,9 +213,8 @@ public abstract class Database {
plugin.debug("Getting sellprice: " + sellprice + " (#" + id + ")"); plugin.debug("Getting sellprice: " + sellprice + " (#" + id + ")");
return sellprice; return sellprice;
case SHOPTYPE: case SHOPTYPE:
ShopType shopType = ShopType.valueOf(rs.getString("shoptype"));
plugin.debug("Getting shoptype: " + rs.getString("shoptype") + " (#" + id + ")");
String shoptype = rs.getString("shoptype"); String shoptype = rs.getString("shoptype");
plugin.debug("Getting shoptype: " + shoptype + " (#" + id + ")");
if (shoptype.equals("INFINITE")) { if (shoptype.equals("INFINITE")) {
@ -236,7 +238,9 @@ public abstract class Database {
plugin.debug("Shop with ID not found, returning null. (#" + id + ")"); plugin.debug("Shop with ID not found, returning null. (#" + id + ")");
} catch (SQLException ex) { } catch (SQLException ex) {
ex.printStackTrace(); plugin.getLogger().severe("Failed to access database");
plugin.debug("Failed to get shop info " + shopInfo.toString() + "(#" + id + ")");
plugin.debug(ex);
} finally { } finally {
close(ps, rs); close(ps, rs);
} }
@ -269,7 +273,9 @@ public abstract class Database {
ps.executeUpdate(); ps.executeUpdate();
} catch (SQLException ex) { } catch (SQLException ex) {
ex.printStackTrace(); plugin.getLogger().severe("Failed to access database");
plugin.debug("Failed to add shop to database (#" + shop.getID() + ")");
plugin.debug(ex);
} finally { } finally {
close(ps, null); close(ps, null);
} }
@ -287,7 +293,8 @@ public abstract class Database {
if (rs != null) if (rs != null)
rs.close(); rs.close();
} catch (SQLException ex) { } catch (SQLException ex) {
ex.printStackTrace(); plugin.debug("Failed to close PreparedStatement/ResultSet");
plugin.debug(ex);
} }
} }
@ -296,14 +303,14 @@ public abstract class Database {
*/ */
public void disconnect() { public void disconnect() {
try { try {
if (connection != null) { if (connection != null && !connection.isClosed()) {
plugin.debug("Disconnecting from database..."); plugin.debug("Disconnecting from database...");
connection.close(); connection.close();
} }
} catch (SQLException e) { } catch (SQLException e) {
plugin.getLogger().severe("Failed to disconnect from database");
plugin.debug("Failed to disconnect from database"); plugin.debug("Failed to disconnect from database");
plugin.debug(e); plugin.debug(e);
e.printStackTrace();
} }
} }

View File

@ -27,7 +27,9 @@ public class MySQL extends Database {
return connection; return connection;
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); plugin.getLogger().severe("Failed to get database connection");
plugin.debug("Failed to get database connection");
plugin.debug(ex);
} }
return null; return null;

View File

@ -6,6 +6,7 @@ import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.sql.Connection; import java.sql.Connection;
import java.sql.DriverManager; import java.sql.DriverManager;
import java.sql.SQLException;
public class SQLite extends Database { public class SQLite extends Database {
@ -22,7 +23,9 @@ public class SQLite extends Database {
try { try {
dbFile.createNewFile(); dbFile.createNewFile();
} catch (IOException ex) { } catch (IOException ex) {
ex.printStackTrace(); plugin.getLogger().severe("Failed to create database file");
plugin.debug("Failed to create database file");
plugin.debug(ex);
} }
} }
@ -35,8 +38,10 @@ public class SQLite extends Database {
connection = DriverManager.getConnection("jdbc:sqlite:" + dbFile); connection = DriverManager.getConnection("jdbc:sqlite:" + dbFile);
return connection; return connection;
} catch (Exception ex) { } catch (ClassNotFoundException | SQLException ex) {
ex.printStackTrace(); plugin.getLogger().severe("Failed to get database connection");
plugin.debug("Failed to get database connection");
plugin.debug(ex);
} }
return null; return null;

View File

@ -3,6 +3,7 @@ package de.epiceric.shopchest.utils;
import de.epiceric.shopchest.ShopChest; import de.epiceric.shopchest.ShopChest;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
@ -135,6 +136,9 @@ public class Utils {
*/ */
public static boolean sendPacket(ShopChest plugin, Object packet, Player player) { public static boolean sendPacket(ShopChest plugin, Object packet, Player player) {
try { try {
if (packet == null)
return false;
Class<?> packetClass = Class.forName("net.minecraft.server." + getServerVersion() + ".Packet"); Class<?> packetClass = Class.forName("net.minecraft.server." + getServerVersion() + ".Packet");
Object nmsPlayer = player.getClass().getMethod("getHandle").invoke(player); Object nmsPlayer = player.getClass().getMethod("getHandle").invoke(player);
Object playerConnection = nmsPlayer.getClass().getField("playerConnection").get(nmsPlayer); Object playerConnection = nmsPlayer.getClass().getField("playerConnection").get(nmsPlayer);
@ -143,9 +147,9 @@ public class Utils {
return true; return true;
} catch (ClassNotFoundException | NoSuchMethodException | NoSuchFieldException | IllegalAccessException | InvocationTargetException e) { } catch (ClassNotFoundException | NoSuchMethodException | NoSuchFieldException | IllegalAccessException | InvocationTargetException e) {
plugin.getLogger().severe("Failed to send packet " + packet.getClass().getName());
plugin.debug("Failed to send packet " + packet.getClass().getName()); plugin.debug("Failed to send packet " + packet.getClass().getName());
plugin.debug(e); plugin.debug(e);
e.printStackTrace();
return false; return false;
} }
} }
@ -195,7 +199,7 @@ public class Utils {
YamlConfiguration config = new YamlConfiguration(); YamlConfiguration config = new YamlConfiguration();
try { try {
config.loadFromString(new String(DatatypeConverter.parseBase64Binary(string), StandardCharsets.UTF_8)); config.loadFromString(new String(DatatypeConverter.parseBase64Binary(string), StandardCharsets.UTF_8));
} catch (Exception e) { } catch (IllegalArgumentException | InvalidConfigurationException e) {
e.printStackTrace(); e.printStackTrace();
return null; return null;
} }