mirror of
https://github.com/amalthea-mc/ShopChest.git
synced 2024-11-22 10:22:29 +00:00
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:
parent
6bce68768a
commit
51584a3d04
@ -95,6 +95,7 @@ public class ShopChest extends JavaPlugin {
|
||||
|
||||
fw = new FileWriter(debugLogFile, true);
|
||||
} catch (IOException e) {
|
||||
getLogger().info("Failed to instantiate FileWriter");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
@ -272,9 +273,9 @@ public class ShopChest extends JavaPlugin {
|
||||
debug("Trying to register command \"/" + config.main_command_name + "\"");
|
||||
ShopCommand.registerCommand(new ShopCommand(this, config.main_command_name, "Manage Shops.", "", new ArrayList<String>()), this);
|
||||
} catch (Exception e) {
|
||||
getLogger().info("Failed to register command");
|
||||
debug("Failed to register command");
|
||||
debug(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
initializeShops();
|
||||
@ -312,6 +313,7 @@ public class ShopChest extends JavaPlugin {
|
||||
try {
|
||||
fw.close();
|
||||
} catch (IOException e) {
|
||||
getLogger().severe("Failed to close FileWriter");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
@ -342,7 +342,7 @@ public class Config {
|
||||
|
||||
langConfig.loadFromString(sb.toString());
|
||||
} catch (IOException | InvalidConfigurationException ex) {
|
||||
ex.printStackTrace();
|
||||
plugin.debug(ex);
|
||||
plugin.getLogger().warning("Using default language values");
|
||||
}
|
||||
} else {
|
||||
@ -350,7 +350,7 @@ public class Config {
|
||||
langConfig.load(langDefaultFile);
|
||||
plugin.getLogger().info("Using locale \"en_US\"");
|
||||
} catch (IOException | InvalidConfigurationException e) {
|
||||
e.printStackTrace();
|
||||
plugin.debug(e);
|
||||
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) + "\"");
|
||||
langConfig.load(langConfigFile);
|
||||
} catch (IOException | InvalidConfigurationException ex) {
|
||||
ex.printStackTrace();
|
||||
plugin.debug(ex);
|
||||
plugin.getLogger().warning("Using default language values");
|
||||
}
|
||||
}
|
||||
|
@ -73,9 +73,9 @@ public class Hologram {
|
||||
this.location.subtract(0, 0.25, 0);
|
||||
count++;
|
||||
} 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(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
@ -107,9 +107,9 @@ public class Hologram {
|
||||
|
||||
Utils.sendPacket(plugin, packet, p);
|
||||
} 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(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
visible.add(p);
|
||||
@ -127,9 +127,9 @@ public class Hologram {
|
||||
|
||||
Utils.sendPacket(plugin, packet, p);
|
||||
} 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(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
visible.remove(p);
|
||||
@ -159,9 +159,9 @@ public class Hologram {
|
||||
try {
|
||||
o.getClass().getMethod("die").invoke(o);
|
||||
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
|
||||
plugin.getLogger().severe("Could not remove Hologram with reflection");
|
||||
plugin.debug("Could not remove Hologram with reflection");
|
||||
plugin.debug(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
exists = false;
|
||||
|
@ -117,9 +117,9 @@ public class JsonBuilder {
|
||||
Utils.sendPacket(plugin, packetPlayOutChat, p);
|
||||
} catch (InstantiationException | InvocationTargetException |
|
||||
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);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -30,9 +30,9 @@ public class SpawnEggMeta {
|
||||
if (id instanceof String) return (String) id;
|
||||
|
||||
} 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);
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
|
@ -42,26 +42,16 @@ public class Shop {
|
||||
|
||||
Block b = location.getBlock();
|
||||
if (b.getType() != Material.CHEST && b.getType() != Material.TRAPPED_CHEST) {
|
||||
try {
|
||||
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.debug(e);
|
||||
throw e;
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
plugin.getLogger().severe("No Chest found at specified Location: " + b.getX() + "; " + b.getY() + "; " + b.getZ());
|
||||
plugin.debug("No Chest found at specified Location: " + b.getX() + "; " + b.getY() + "; " + b.getZ());
|
||||
return;
|
||||
}
|
||||
} 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);
|
||||
Exception e = new Exception("No space above chest at specified Location: " + b.getX() + "; " + b.getY() + "; " + b.getZ());
|
||||
plugin.debug(e);
|
||||
throw e;
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
plugin.getLogger().severe("No space above chest at specified Location: " + b.getX() + "; " + b.getY() + "; " + b.getZ());
|
||||
plugin.debug("No space above chest at specified Location: " + b.getX() + "; " + b.getY() + "; " + b.getZ());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (hologram == null || !hologram.exists()) createHologram();
|
||||
if (item == null) createItem();
|
||||
|
@ -80,9 +80,9 @@ public class ShopItem {
|
||||
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);
|
||||
} 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(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@ -120,9 +120,9 @@ public class ShopItem {
|
||||
Utils.sendPacket(plugin, packetPlayOutEntityDestroy, p);
|
||||
}
|
||||
} 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(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -68,9 +68,9 @@ public abstract class Database {
|
||||
close(ps, rs);
|
||||
|
||||
} catch (SQLException ex) {
|
||||
plugin.getLogger().severe("Failed to connect to database");
|
||||
plugin.debug("Failed to connect to database");
|
||||
plugin.debug(ex);
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@ -112,7 +112,8 @@ public abstract class Database {
|
||||
return highestID;
|
||||
|
||||
} catch (SQLException ex) {
|
||||
ex.printStackTrace();
|
||||
plugin.debug("Failed to get highest used ID");
|
||||
plugin.getLogger().severe("Failed to access database");
|
||||
} finally {
|
||||
close(ps, rs);
|
||||
}
|
||||
@ -133,7 +134,9 @@ public abstract class Database {
|
||||
plugin.debug("Removing shop from database (#" + shop.getID() + ")");
|
||||
ps.executeUpdate();
|
||||
} 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 {
|
||||
close(ps, null);
|
||||
}
|
||||
@ -210,9 +213,8 @@ public abstract class Database {
|
||||
plugin.debug("Getting sellprice: " + sellprice + " (#" + id + ")");
|
||||
return sellprice;
|
||||
case SHOPTYPE:
|
||||
ShopType shopType = ShopType.valueOf(rs.getString("shoptype"));
|
||||
plugin.debug("Getting shoptype: " + rs.getString("shoptype") + " (#" + id + ")");
|
||||
String shoptype = rs.getString("shoptype");
|
||||
plugin.debug("Getting shoptype: " + shoptype + " (#" + id + ")");
|
||||
|
||||
if (shoptype.equals("INFINITE")) {
|
||||
|
||||
@ -236,7 +238,9 @@ public abstract class Database {
|
||||
plugin.debug("Shop with ID not found, returning null. (#" + id + ")");
|
||||
|
||||
} 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 {
|
||||
close(ps, rs);
|
||||
}
|
||||
@ -269,7 +273,9 @@ public abstract class Database {
|
||||
|
||||
ps.executeUpdate();
|
||||
} 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 {
|
||||
close(ps, null);
|
||||
}
|
||||
@ -287,7 +293,8 @@ public abstract class Database {
|
||||
if (rs != null)
|
||||
rs.close();
|
||||
} 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() {
|
||||
try {
|
||||
if (connection != null) {
|
||||
if (connection != null && !connection.isClosed()) {
|
||||
plugin.debug("Disconnecting from database...");
|
||||
connection.close();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
plugin.getLogger().severe("Failed to disconnect from database");
|
||||
plugin.debug("Failed to disconnect from database");
|
||||
plugin.debug(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -27,7 +27,9 @@ public class MySQL extends Database {
|
||||
|
||||
return connection;
|
||||
} 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;
|
||||
|
@ -6,6 +6,7 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class SQLite extends Database {
|
||||
|
||||
@ -22,7 +23,9 @@ public class SQLite extends Database {
|
||||
try {
|
||||
dbFile.createNewFile();
|
||||
} 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);
|
||||
|
||||
return connection;
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
} catch (ClassNotFoundException | SQLException ex) {
|
||||
plugin.getLogger().severe("Failed to get database connection");
|
||||
plugin.debug("Failed to get database connection");
|
||||
plugin.debug(ex);
|
||||
}
|
||||
|
||||
return null;
|
||||
|
@ -3,6 +3,7 @@ package de.epiceric.shopchest.utils;
|
||||
import de.epiceric.shopchest.ShopChest;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
@ -135,6 +136,9 @@ public class Utils {
|
||||
*/
|
||||
public static boolean sendPacket(ShopChest plugin, Object packet, Player player) {
|
||||
try {
|
||||
if (packet == null)
|
||||
return false;
|
||||
|
||||
Class<?> packetClass = Class.forName("net.minecraft.server." + getServerVersion() + ".Packet");
|
||||
Object nmsPlayer = player.getClass().getMethod("getHandle").invoke(player);
|
||||
Object playerConnection = nmsPlayer.getClass().getField("playerConnection").get(nmsPlayer);
|
||||
@ -143,9 +147,9 @@ public class Utils {
|
||||
|
||||
return true;
|
||||
} 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(e);
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -195,7 +199,7 @@ public class Utils {
|
||||
YamlConfiguration config = new YamlConfiguration();
|
||||
try {
|
||||
config.loadFromString(new String(DatatypeConverter.parseBase64Binary(string), StandardCharsets.UTF_8));
|
||||
} catch (Exception e) {
|
||||
} catch (IllegalArgumentException | InvalidConfigurationException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user