Disable plugin when shops fail to load or reload

This commit is contained in:
Eric 2019-06-16 15:06:35 +02:00
parent 64c9c8a74d
commit 3730eb9703
4 changed files with 28 additions and 2 deletions

View File

@ -444,6 +444,12 @@ public class ShopChest extends JavaPlugin {
getLogger().info("Initialized " + result + " Shops");
debug("Initialized " + result + " Shops");
}
@Override
public void onError(Throwable throwable) {
// Database connection probably failed => disable plugin to prevent more errors
getServer().getPluginManager().disablePlugin(ShopChest.this);
}
});
}

View File

@ -198,6 +198,14 @@ class ShopCommandExecutor implements CommandExecutor {
new Replacement(Placeholder.AMOUNT, String.valueOf(result))));
plugin.debug(sender.getName() + " has reloaded " + result + " shops");
}
@Override
public void onError(Throwable throwable) {
// 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);
}
});
}

View File

@ -3,6 +3,8 @@ package de.epiceric.shopchest.listeners;
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;
@ -94,6 +96,12 @@ public class ShopUpdateListener implements Listener {
plugin.getLogger().info(String.format("Reloaded %d shops because a new world '%s' was loaded", result, worldName));
plugin.debug(String.format("Reloaded %d shops because a new world '%s' was loaded", result, worldName));
}
@Override
public void onError(Throwable throwable) {
// Database connection probably failed => disable plugin to prevent more errors
Bukkit.getPluginManager().disablePlugin(plugin);
}
});
}
}

View File

@ -3,6 +3,7 @@ package de.epiceric.shopchest.utils;
import de.epiceric.shopchest.ShopChest;
import de.epiceric.shopchest.config.Config;
import de.epiceric.shopchest.shop.Shop;
import org.bukkit.Location;
import org.bukkit.OfflinePlayer;
import org.bukkit.block.Chest;
@ -256,11 +257,14 @@ public class ShopUtils {
@Override
public void onError(Throwable throwable) {
if (callback != null) callback.callSyncError(throwable);
plugin.debug("Error while adding shops");
plugin.debug(throwable);
}
});
}
@Override
public void onError(Throwable throwable) {
if (callback != null) callback.callSyncError(throwable);
}
});
}