mirror of
https://github.com/amalthea-mc/ShopChest.git
synced 2024-11-08 19:51:05 +00:00
Improve output of database errors
This commit is contained in:
parent
67c55be518
commit
e82c28e5e8
@ -448,6 +448,8 @@ public class ShopChest extends JavaPlugin {
|
||||
@Override
|
||||
public void onError(Throwable throwable) {
|
||||
// Database connection probably failed => disable plugin to prevent more errors
|
||||
getLogger().severe("No database access. Disabling ShopChest");
|
||||
if (throwable != null) getLogger().severe(throwable.getMessage());
|
||||
getServer().getPluginManager().disablePlugin(ShopChest.this);
|
||||
}
|
||||
});
|
||||
|
@ -204,7 +204,9 @@ class ShopCommandExecutor implements CommandExecutor {
|
||||
// Database connection probably failed => disable plugin to prevent more errors
|
||||
sender.sendMessage(LanguageUtils.getMessage(Message.ERROR_OCCURRED,
|
||||
new Replacement(Placeholder.ERROR, "No database access: Disabling ShopChest")));
|
||||
Bukkit.getPluginManager().disablePlugin(plugin);
|
||||
plugin.getLogger().severe("No database access: Disabling ShopChest");
|
||||
if (throwable != null) plugin.getLogger().severe(throwable.getMessage());
|
||||
plugin.getServer().getPluginManager().disablePlugin(plugin);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -4,7 +4,6 @@ import de.epiceric.shopchest.ShopChest;
|
||||
import de.epiceric.shopchest.shop.Shop;
|
||||
import de.epiceric.shopchest.utils.Callback;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@ -53,11 +52,9 @@ public class ShopUpdateListener implements Listener {
|
||||
final Player p = e.getPlayer();
|
||||
|
||||
// Wait till the chunk should have loaded on the client
|
||||
// Update IF worlds are different OR chunks are different (as many teleports are in same chunk)
|
||||
if (!from.getWorld().getName().equals(to.getWorld().getName())
|
||||
|| from.getChunk().getX() != to.getChunk().getX()
|
||||
|| from.getChunk().getZ() != to.getChunk().getZ()) {
|
||||
// Wait for 15 ticks before we actually put it in the queue
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@ -71,7 +68,6 @@ public class ShopUpdateListener implements Listener {
|
||||
shop.getHologram().hidePlayer(p);
|
||||
}
|
||||
}
|
||||
// so next update will update correctly
|
||||
plugin.getShopUtils().resetPlayerLocation(p);
|
||||
}
|
||||
});
|
||||
@ -100,7 +96,9 @@ public class ShopUpdateListener implements Listener {
|
||||
@Override
|
||||
public void onError(Throwable throwable) {
|
||||
// Database connection probably failed => disable plugin to prevent more errors
|
||||
Bukkit.getPluginManager().disablePlugin(plugin);
|
||||
plugin.getLogger().severe("No database access. Disabling ShopChest");
|
||||
if (throwable != null) plugin.getLogger().severe(throwable.getMessage());
|
||||
plugin.getServer().getPluginManager().disablePlugin(plugin);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -255,10 +255,18 @@ public abstract class Database {
|
||||
public void run() {
|
||||
disconnect();
|
||||
|
||||
try {
|
||||
dataSource = getDataSource();
|
||||
} catch (Exception e) {
|
||||
callback.onError(e);
|
||||
plugin.debug(e);
|
||||
return;
|
||||
}
|
||||
|
||||
if (dataSource == null) {
|
||||
callback.onError(new SQLException("Failed to get data source"));
|
||||
Exception e = new IllegalStateException("Data source is null");
|
||||
callback.onError(e);
|
||||
plugin.debug(e);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -719,6 +727,7 @@ public abstract class Database {
|
||||
public void disconnect() {
|
||||
if (dataSource != null) {
|
||||
dataSource.close();
|
||||
dataSource = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user