1
0
mirror of https://github.com/Zrips/Jobs.git synced 2025-01-06 16:27:59 +01:00

Try to fix SQLiteException when UNIQUE constraint failed for sqlite

Fixes #870
This commit is contained in:
montlikadani 2020-08-02 18:53:36 +02:00
parent be6474e9ef
commit 6d21e14725
5 changed files with 37 additions and 36 deletions

View File

@ -155,8 +155,8 @@
</dependency> </dependency>
<dependency> <dependency>
<groupId>me.clip</groupId> <groupId>me.clip</groupId>
<artifactId>PlaceholderAPI</artifactId> <artifactId>placeholderapi</artifactId>
<version>2.10.7</version> <version>2.10.8</version>
<scope>provided</scope> <scope>provided</scope>
<exclusions> <exclusions>
<exclusion> <exclusion>

View File

@ -136,21 +136,9 @@ public class Jobs extends JavaPlugin {
if (!getServer().getPluginManager().isPluginEnabled("PlaceholderAPI")) if (!getServer().getPluginManager().isPluginEnabled("PlaceholderAPI"))
return false; return false;
try {
if (Integer.parseInt(getServer().getPluginManager().getPlugin("PlaceholderAPI") if (Integer.parseInt(getServer().getPluginManager().getPlugin("PlaceholderAPI")
.getDescription().getVersion().replace(".", "")) >= Integer.parseInt("2107")) { .getDescription().getVersion().replaceAll("[^\\d]", "")) >= 2100) {
PlaceholderAPIHook hook = new PlaceholderAPIHook(this); if (new PlaceholderAPIHook(this).register()) {
if (hook.canRegister()) {
hook.getPlaceholderAPI().getLocalExpansionManager().register(hook);
if (hook.isRegistered())
consoleMsg("&e[Jobs] PlaceholderAPI hooked.");
}
}
} catch (NumberFormatException e) { // when using a dev build
PlaceholderAPIHook hook = new PlaceholderAPIHook(this);
if (hook.canRegister()) {
hook.getPlaceholderAPI().getLocalExpansionManager().register(hook);
if (hook.isRegistered())
consoleMsg("&e[Jobs] PlaceholderAPI hooked."); consoleMsg("&e[Jobs] PlaceholderAPI hooked.");
} }
} }
@ -1098,6 +1086,7 @@ public class Jobs extends JavaPlugin {
else else
jPlayer.getUpdateBossBarFor().add(prog.getJob().getName()); jPlayer.getUpdateBossBarFor().add(prog.getJob().getName());
} catch (Throwable e) { } catch (Throwable e) {
e.printStackTrace();
consoleMsg("&c[Jobs] Some issues with boss bar feature accured, try disabling it to avoid it."); consoleMsg("&c[Jobs] Some issues with boss bar feature accured, try disabling it to avoid it.");
} }
@ -1295,10 +1284,7 @@ public class Jobs extends JavaPlugin {
((Player) sender).sendMessage(lManager.getMessage("general.error.permission")); ((Player) sender).sendMessage(lManager.getMessage("general.error.permission"));
return false; return false;
} }
RawMessage rm = new RawMessage(); new RawMessage().addText(lManager.getMessage("general.error.permission")).addHover("&2" + perm).show((Player) sender);
rm.addText(lManager.getMessage("general.error.permission"));
rm.addHover("&2" + perm);
rm.show((Player) sender);
return false; return false;
} }
@ -1314,27 +1300,32 @@ public class Jobs extends JavaPlugin {
public void ShowPagination(CommandSender sender, int pageCount, int CurrentPage, int totalEntries, String cmd, String pagePref) { public void ShowPagination(CommandSender sender, int pageCount, int CurrentPage, int totalEntries, String cmd, String pagePref) {
if (!(sender instanceof Player)) if (!(sender instanceof Player))
return; return;
if (!cmd.startsWith("/")) if (!cmd.startsWith("/"))
cmd = "/" + cmd; cmd = "/" + cmd;
if (pageCount == 1) if (pageCount == 1)
return; return;
String pagePrefix = pagePref == null ? "" : pagePref; String pagePrefix = pagePref == null ? "" : pagePref;
int NextPage = CurrentPage + 1; int NextPage = CurrentPage + 1;
NextPage = CurrentPage < pageCount ? NextPage : CurrentPage; NextPage = CurrentPage < pageCount ? NextPage : CurrentPage;
int Prevpage = CurrentPage - 1; int Prevpage = CurrentPage - 1;
Prevpage = CurrentPage > 1 ? Prevpage : CurrentPage; Prevpage = CurrentPage > 1 ? Prevpage : CurrentPage;
RawMessage rm = new RawMessage(); RawMessage rm = new RawMessage()
rm.addText((CurrentPage > 1 ? lManager.getMessage("command.help.output.prevPage") : lManager.getMessage("command.help.output.prevPageOff"))); .addText((CurrentPage > 1 ? lManager.getMessage("command.help.output.prevPage") : lManager.getMessage("command.help.output.prevPageOff")))
rm.addHover(CurrentPage > 1 ? "<<<" : ">|"); .addHover(CurrentPage > 1 ? "<<<" : ">|")
rm.addCommand(CurrentPage > 1 ? cmd + " " + pagePrefix + Prevpage : cmd + " " + pagePrefix + pageCount); .addCommand(CurrentPage > 1 ? cmd + " " + pagePrefix + Prevpage : cmd + " " + pagePrefix + pageCount);
rm.addText(lManager.getMessage("command.help.output.pageCount", "[current]", CurrentPage, "[total]", pageCount)); rm.addText(lManager.getMessage("command.help.output.pageCount", "[current]", CurrentPage, "[total]", pageCount))
rm.addHover(lManager.getMessage("command.help.output.pageCountHover", "[totalEntries]", totalEntries)); .addHover(lManager.getMessage("command.help.output.pageCountHover", "[totalEntries]", totalEntries));
rm.addText(pageCount > CurrentPage ? lManager.getMessage("command.help.output.nextPage") : lManager.getMessage("command.help.output.nextPageOff")); rm.addText(pageCount > CurrentPage ? lManager.getMessage("command.help.output.nextPage") : lManager.getMessage("command.help.output.nextPageOff"))
rm.addHover(pageCount > CurrentPage ? ">>>" : "|<"); .addHover(pageCount > CurrentPage ? ">>>" : "|<")
rm.addCommand(pageCount > CurrentPage ? cmd + " " + pagePrefix + NextPage : cmd + " " + pagePrefix + 1); .addCommand(pageCount > CurrentPage ? cmd + " " + pagePrefix + NextPage : cmd + " " + pagePrefix + 1);
if (pageCount != 0) if (pageCount != 0)
rm.show(sender); rm.show(sender);

View File

@ -80,10 +80,8 @@ public class JobsCommands implements CommandExecutor {
if (!hasCommandPermission(sender, cmd)) { if (!hasCommandPermission(sender, cmd)) {
if (sender instanceof Player) { if (sender instanceof Player) {
RawMessage rm = new RawMessage(); new RawMessage().addText(Jobs.getLanguage().getMessage("general.error.permission"))
rm.addText(Jobs.getLanguage().getMessage("general.error.permission")); .addHover("&2" + label + ".command." + cmd).show(sender);
rm.addHover("&2" + label + ".command." + cmd);
rm.show(sender);
} else } else
sender.sendMessage(Jobs.getLanguage().getMessage("general.error.permission")); sender.sendMessage(Jobs.getLanguage().getMessage("general.error.permission"));
return true; return true;

View File

@ -13,6 +13,10 @@ public class JobsConnection {
this.conn = conn; this.conn = conn;
} }
public synchronized Connection getConnection() {
return conn;
}
public synchronized boolean isClosed() { public synchronized boolean isClosed() {
try { try {
return conn.isClosed(); return conn.isClosed();

View File

@ -1120,16 +1120,24 @@ public abstract class JobsDAO {
PreparedStatement prestt = null; PreparedStatement prestt = null;
ResultSet res2 = null; ResultSet res2 = null;
try { try {
conn.setAutoCommit(false);
prestt = conn.prepareStatement("INSERT INTO `" + DBTables.JobNameTable.getTableName() + "` (`" + jobsNameTableFields.name.getCollumn() + "`) VALUES (?);", prestt = conn.prepareStatement("INSERT INTO `" + DBTables.JobNameTable.getTableName() + "` (`" + jobsNameTableFields.name.getCollumn() + "`) VALUES (?);",
Statement.RETURN_GENERATED_KEYS); Statement.RETURN_GENERATED_KEYS);
prestt.setString(1, job.getName()); prestt.setString(1, job.getName());
prestt.executeUpdate(); int rowAffected = prestt.executeUpdate();
res2 = prestt.getGeneratedKeys(); res2 = prestt.getGeneratedKeys();
int id = 0; int id = 0;
if (res2.next()) if (res2.next())
id = res2.getInt(1); id = res2.getInt(1);
job.setId(id); job.setId(id);
if (rowAffected != 1) {
conn.getConnection().rollback();
}
conn.commit();
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
} finally { } finally {