1
0
mirror of https://github.com/Zrips/Jobs.git synced 2025-01-02 14:29:07 +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>
<groupId>me.clip</groupId>
<artifactId>PlaceholderAPI</artifactId>
<version>2.10.7</version>
<artifactId>placeholderapi</artifactId>
<version>2.10.8</version>
<scope>provided</scope>
<exclusions>
<exclusion>

View File

@ -136,22 +136,10 @@ public class Jobs extends JavaPlugin {
if (!getServer().getPluginManager().isPluginEnabled("PlaceholderAPI"))
return false;
try {
if (Integer.parseInt(getServer().getPluginManager().getPlugin("PlaceholderAPI")
.getDescription().getVersion().replace(".", "")) >= Integer.parseInt("2107")) {
PlaceholderAPIHook hook = new PlaceholderAPIHook(this);
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.");
if (Integer.parseInt(getServer().getPluginManager().getPlugin("PlaceholderAPI")
.getDescription().getVersion().replaceAll("[^\\d]", "")) >= 2100) {
if (new PlaceholderAPIHook(this).register()) {
consoleMsg("&e[Jobs] PlaceholderAPI hooked.");
}
}
@ -1098,6 +1086,7 @@ public class Jobs extends JavaPlugin {
else
jPlayer.getUpdateBossBarFor().add(prog.getJob().getName());
} catch (Throwable e) {
e.printStackTrace();
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"));
return false;
}
RawMessage rm = new RawMessage();
rm.addText(lManager.getMessage("general.error.permission"));
rm.addHover("&2" + perm);
rm.show((Player) sender);
new RawMessage().addText(lManager.getMessage("general.error.permission")).addHover("&2" + perm).show((Player) sender);
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) {
if (!(sender instanceof Player))
return;
if (!cmd.startsWith("/"))
cmd = "/" + cmd;
if (pageCount == 1)
return;
String pagePrefix = pagePref == null ? "" : pagePref;
int NextPage = CurrentPage + 1;
NextPage = CurrentPage < pageCount ? NextPage : CurrentPage;
int Prevpage = CurrentPage - 1;
Prevpage = CurrentPage > 1 ? Prevpage : CurrentPage;
RawMessage rm = new RawMessage();
rm.addText((CurrentPage > 1 ? lManager.getMessage("command.help.output.prevPage") : lManager.getMessage("command.help.output.prevPageOff")));
rm.addHover(CurrentPage > 1 ? "<<<" : ">|");
rm.addCommand(CurrentPage > 1 ? cmd + " " + pagePrefix + Prevpage : cmd + " " + pagePrefix + pageCount);
RawMessage rm = new RawMessage()
.addText((CurrentPage > 1 ? lManager.getMessage("command.help.output.prevPage") : lManager.getMessage("command.help.output.prevPageOff")))
.addHover(CurrentPage > 1 ? "<<<" : ">|")
.addCommand(CurrentPage > 1 ? cmd + " " + pagePrefix + Prevpage : cmd + " " + pagePrefix + pageCount);
rm.addText(lManager.getMessage("command.help.output.pageCount", "[current]", CurrentPage, "[total]", pageCount));
rm.addHover(lManager.getMessage("command.help.output.pageCountHover", "[totalEntries]", totalEntries));
rm.addText(lManager.getMessage("command.help.output.pageCount", "[current]", CurrentPage, "[total]", pageCount))
.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.addHover(pageCount > CurrentPage ? ">>>" : "|<");
rm.addCommand(pageCount > CurrentPage ? cmd + " " + pagePrefix + NextPage : cmd + " " + pagePrefix + 1);
rm.addText(pageCount > CurrentPage ? lManager.getMessage("command.help.output.nextPage") : lManager.getMessage("command.help.output.nextPageOff"))
.addHover(pageCount > CurrentPage ? ">>>" : "|<")
.addCommand(pageCount > CurrentPage ? cmd + " " + pagePrefix + NextPage : cmd + " " + pagePrefix + 1);
if (pageCount != 0)
rm.show(sender);

View File

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

View File

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

View File

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