From 647533f57a365bdc1805f31a3f568d1c9df9ef37 Mon Sep 17 00:00:00 2001 From: montlikadani Date: Thu, 14 May 2020 17:32:02 +0200 Subject: [PATCH] Fixed issue when the database is not converted correctly --- .../gamingmesh/jobs/CMILib/RawMessage.java | 46 +++++++++---------- .../jobs/Placeholders/Placeholder.java | 4 +- .../com/gamingmesh/jobs/PlayerManager.java | 9 +++- .../jobs/config/BossBarManager.java | 3 ++ .../jobs/container/JobProgression.java | 3 +- .../gamingmesh/jobs/container/JobsPlayer.java | 13 +----- .../java/com/gamingmesh/jobs/dao/JobsDAO.java | 5 +- .../com/gamingmesh/jobs/dao/JobsMySQL.java | 3 +- .../jobs/economy/BufferedEconomy.java | 1 - .../jobs/tasks/BufferedPaymentTask.java | 4 +- 10 files changed, 43 insertions(+), 48 deletions(-) diff --git a/src/main/java/com/gamingmesh/jobs/CMILib/RawMessage.java b/src/main/java/com/gamingmesh/jobs/CMILib/RawMessage.java index 34d614f7..a48abf5c 100644 --- a/src/main/java/com/gamingmesh/jobs/CMILib/RawMessage.java +++ b/src/main/java/com/gamingmesh/jobs/CMILib/RawMessage.java @@ -19,7 +19,6 @@ import org.bukkit.inventory.ItemStack; import com.gamingmesh.jobs.CMILib.VersionChecker.Version; - public class RawMessage { private List parts = new ArrayList<>(); @@ -83,22 +82,21 @@ public class RawMessage { if (text.equalsIgnoreCase(" ")) return text; text = CMIChatColor.deColorize(text); - List splited = new ArrayList<>(); - + List splited = new ArrayList(); if (text.contains(" ")) { for (String one : text.split(" ")) { - /**if (this.isBreakLine() && one.contains("\\n")) { - String[] split = one.split("\\\\n"); - for (int i = 0; i < split.length; i++) { - if (i < split.length - 1) { - splited.add(split[i] + "\n"); - } else { - splited.add(split[i]); - } - } - } else {*/ +// if (this.isBreakLine() && one.contains("\\n")) { +// String[] split = one.split("\\\\n"); +// for (int i = 0; i < split.length; i++) { +// if (i < split.length - 1) { +// splited.add(split[i] + "\n"); +// } else { +// splited.add(split[i]); +// } +// } +// } else { splited.add(one); - //} +// } splited.add(" "); } if (text.length() > 1 && text.endsWith(" ")) @@ -125,9 +123,10 @@ public class RawMessage { } if (one.contains("&")) { - Pattern pattern = Pattern.compile("(&[0123456789abcdefklmnor])"); + Pattern pattern = Pattern.compile("(&[0123456789abcdefklmnorABCDEFKLMNOR])"); Matcher match = pattern.matcher(one); while (match.find()) { + String color = CMIChatColor.getLastColors(match.group(0)); CMIChatColor c = CMIChatColor.getColor(color); if (c != null) { @@ -136,7 +135,7 @@ public class RawMessage { } else if (c.isReset()) { formats.clear(); lastColor = null; - firstBlockColor = null; +// firstBlockColor = null; } else if (c.isColor()) { lastColor = c; formats.clear(); @@ -159,6 +158,7 @@ public class RawMessage { newText += colorString + one; } + return newText; } @@ -256,7 +256,7 @@ public class RawMessage { } public RawMessage add(String text, String hoverText, String command, String suggestion, String url) { - + if (text == null) return this; text = provessText(text); @@ -267,7 +267,7 @@ public class RawMessage { String f = "{\"text\":\"" + ChatColor.translateAlternateColorCodes('&', makeMessyText(text)).replace(colorReplacerPlaceholder, "&") + "\""; if (hoverText != null && !hoverText.isEmpty()) { - hoverText = provessText(hoverText); + hoverText = provessText(hoverText); hoverText = hoverText.replace(" \n", " \\n"); hoverText = hoverText.replace("\n", "\\n"); f += ",\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"" + ChatColor.translateAlternateColorCodes('&', hoverText) + "\"}]}}"; @@ -281,8 +281,8 @@ public class RawMessage { suggestion = suggestion.replace(" \\n", " \\\\n"); suggestion = suggestion.replace(" \n", " \\\\n"); - if (suggestion != null) - f += ",\"clickEvent\":{\"action\":\"suggest_command\",\"value\":\"" + CMIChatColor.deColorize(suggestion) + "\"}"; + if (suggestion != null) + f += ",\"clickEvent\":{\"action\":\"suggest_command\",\"value\":\"" + CMIChatColor.deColorize(suggestion) + "\"}"; } if (url != null) { url = provessText(url); @@ -294,7 +294,7 @@ public class RawMessage { if (command != null) { if (!command.startsWith("/")) command = "/" + command; - command = provessText(command); + command = provessText(command); f += ",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"" + command + "\"}"; } // } @@ -406,8 +406,8 @@ public class RawMessage { loreS = ",Lore:[" + loreS + "]"; } f += ",\"hoverEvent\":{\"action\":\"show_item\",\"value\":\"{id:" + itemName + ",Count:1b,tag:{display:{Name:\\\"" + CMIChatColor.translateAlternateColorCodes(ItemName) + "\\\"" + loreS - + "}" - + Enchants + "}}\"}"; + + "}" + + Enchants + "}}\"}"; if (suggestion != null) f += ",\"clickEvent\":{\"action\":\"suggest_command\",\"value\":\"" + suggestion + "\"}"; diff --git a/src/main/java/com/gamingmesh/jobs/Placeholders/Placeholder.java b/src/main/java/com/gamingmesh/jobs/Placeholders/Placeholder.java index c715a740..12d606c8 100644 --- a/src/main/java/com/gamingmesh/jobs/Placeholders/Placeholder.java +++ b/src/main/java/com/gamingmesh/jobs/Placeholders/Placeholder.java @@ -424,7 +424,7 @@ public class Placeholder { case user_jobs: List l = user.getJobProgression(); if (l.isEmpty()) { - return "none"; + return ""; } JobProgression prog = l.get(ThreadLocalRandom.current().nextInt(l.size())); @@ -475,7 +475,7 @@ public class Placeholder { Job jobs = getJobFromValue(vals.get(0)); return jobs == null ? "no" : convert(user.isInJob(jobs)); case user_job_$1: - return j == null ? "none" : j.getJob().getName(); + return j == null ? "" : j.getJob().getName(); case maxjobs: Double max = Jobs.getPermissionManager().getMaxPermission(user, "jobs.max"); diff --git a/src/main/java/com/gamingmesh/jobs/PlayerManager.java b/src/main/java/com/gamingmesh/jobs/PlayerManager.java index 20cdb435..84f9a74f 100644 --- a/src/main/java/com/gamingmesh/jobs/PlayerManager.java +++ b/src/main/java/com/gamingmesh/jobs/PlayerManager.java @@ -265,21 +265,28 @@ public class PlayerManager { int y = 0; int i = 0; int total = playersUUIDCache.size(); + for (Entry one : playersUUIDCache.entrySet()) { JobsPlayer jPlayer = one.getValue(); + if (resetID) jPlayer.setUserId(-1); + JobsDAO dao = Jobs.getJobsDAO(); dao.updateSeen(jPlayer); - if (jPlayer.getUserId() == -1) + + if (!resetID && jPlayer.getUserId() == -1) continue; + for (JobProgression oneJ : jPlayer.getJobProgression()) dao.insertJob(jPlayer, oneJ); dao.saveLog(jPlayer); dao.savePoints(jPlayer); dao.recordPlayersLimits(jPlayer); + i++; y++; + if (y >= 1000) { Jobs.consoleMsg("&e[Jobs] Saved " + i + "/" + total + " players data"); y = 0; diff --git a/src/main/java/com/gamingmesh/jobs/config/BossBarManager.java b/src/main/java/com/gamingmesh/jobs/config/BossBarManager.java index b0e5c7b6..23d58b65 100644 --- a/src/main/java/com/gamingmesh/jobs/config/BossBarManager.java +++ b/src/main/java/com/gamingmesh/jobs/config/BossBarManager.java @@ -118,6 +118,9 @@ public class BossBarManager { case 20: style = BarStyle.SEGMENTED_20; break; + default: + style = BarStyle.SEGMENTED_6; + break; } bar = Bukkit.createBossBar(message, color, style); } else diff --git a/src/main/java/com/gamingmesh/jobs/container/JobProgression.java b/src/main/java/com/gamingmesh/jobs/container/JobProgression.java index 22fbafac..cfcc613b 100644 --- a/src/main/java/com/gamingmesh/jobs/container/JobProgression.java +++ b/src/main/java/com/gamingmesh/jobs/container/JobProgression.java @@ -20,7 +20,6 @@ package com.gamingmesh.jobs.container; import java.util.HashMap; -import com.gamingmesh.jobs.stuff.Debug; import com.gamingmesh.jobs.stuff.TimeManage; public class JobProgression { @@ -255,7 +254,7 @@ public class JobProgression { return lastExperience == null ? 0D : lastExperience; } - public void setLastExperience(Double lastExperience) { + public void setLastExperience(Double lastExperience) { this.lastExperience = lastExperience; } diff --git a/src/main/java/com/gamingmesh/jobs/container/JobsPlayer.java b/src/main/java/com/gamingmesh/jobs/container/JobsPlayer.java index 450a9df9..86c5e2f4 100644 --- a/src/main/java/com/gamingmesh/jobs/container/JobsPlayer.java +++ b/src/main/java/com/gamingmesh/jobs/container/JobsPlayer.java @@ -359,17 +359,6 @@ public class JobsPlayer { return Collections.unmodifiableList(progression); } - /** - * Check if have permission - * @return true if have - */ - public boolean havePermission(String perm) { - Player player = Bukkit.getPlayer(getUniqueId()); - if (player != null) - return player.hasPermission(perm); - return false; - } - /** * Get the job progression with the certain job * @return the job progression @@ -639,7 +628,7 @@ public class JobsPlayer { public int getMaxJobLevelAllowed(Job job) { int maxLevel = 0; - if (havePermission("jobs." + job.getName() + ".vipmaxlevel")) + if (getPlayer().hasPermission("jobs." + job.getName() + ".vipmaxlevel")) maxLevel = job.getVipMaxLevel() > job.getMaxLevel() ? job.getVipMaxLevel() : job.getMaxLevel(); else maxLevel = job.getMaxLevel(); diff --git a/src/main/java/com/gamingmesh/jobs/dao/JobsDAO.java b/src/main/java/com/gamingmesh/jobs/dao/JobsDAO.java index 90383ddb..2d932fee 100644 --- a/src/main/java/com/gamingmesh/jobs/dao/JobsDAO.java +++ b/src/main/java/com/gamingmesh/jobs/dao/JobsDAO.java @@ -487,6 +487,7 @@ public abstract class JobsDAO { } } + @Deprecated protected abstract void setupConfig() throws SQLException; protected abstract void checkUpdate() throws SQLException; @@ -1522,11 +1523,9 @@ public abstract class JobsDAO { Convert convertData = list.get(i); JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(convertData.getUserUUID()); - if (jPlayer == null) - continue; Job job = Jobs.getJob(convertData.getJobId()); - insert.setInt(1, jPlayer.getUserId()); + insert.setInt(1, jPlayer != null ? jPlayer.getUserId() : -1); insert.setInt(2, convertData.getJobId()); insert.setInt(3, convertData.getLevel()); insert.setInt(4, convertData.getExp()); diff --git a/src/main/java/com/gamingmesh/jobs/dao/JobsMySQL.java b/src/main/java/com/gamingmesh/jobs/dao/JobsMySQL.java index 6e514c29..fa8c7f93 100644 --- a/src/main/java/com/gamingmesh/jobs/dao/JobsMySQL.java +++ b/src/main/java/com/gamingmesh/jobs/dao/JobsMySQL.java @@ -192,14 +192,13 @@ public class JobsMySQL extends JobsDAO { @Override public boolean truncate(String table) { Statement statement = null; - String query = null; try { if (!this.isTable(table)) { Jobs.consoleMsg("&cTable \"" + table + "\" does not exist."); return false; } statement = getConnection().createStatement(); - query = "DELETE FROM " + table + ";"; + String query = "DELETE FROM " + table + ";"; statement.executeUpdate(query); return true; } catch (SQLException e) { diff --git a/src/main/java/com/gamingmesh/jobs/economy/BufferedEconomy.java b/src/main/java/com/gamingmesh/jobs/economy/BufferedEconomy.java index 74d14a3a..2a10c7e6 100644 --- a/src/main/java/com/gamingmesh/jobs/economy/BufferedEconomy.java +++ b/src/main/java/com/gamingmesh/jobs/economy/BufferedEconomy.java @@ -23,7 +23,6 @@ import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.api.JobsPaymentEvent; import com.gamingmesh.jobs.container.CurrencyType; import com.gamingmesh.jobs.container.JobsPlayer; -import com.gamingmesh.jobs.stuff.Debug; import com.gamingmesh.jobs.stuff.ToggleBarHandling; import com.gamingmesh.jobs.tasks.BufferedPaymentTask; import org.bukkit.Bukkit; diff --git a/src/main/java/com/gamingmesh/jobs/tasks/BufferedPaymentTask.java b/src/main/java/com/gamingmesh/jobs/tasks/BufferedPaymentTask.java index a6e053bc..94335eff 100644 --- a/src/main/java/com/gamingmesh/jobs/tasks/BufferedPaymentTask.java +++ b/src/main/java/com/gamingmesh/jobs/tasks/BufferedPaymentTask.java @@ -37,9 +37,9 @@ public class BufferedPaymentTask implements Runnable { @Override public void run() { - if (payment.get(CurrencyType.MONEY) > 0) { + if (payment.get(CurrencyType.MONEY) > 0) { economy.depositPlayer(payment.getOfflinePlayer(), payment.get(CurrencyType.MONEY)); - }else { + } else { if (!economy.withdrawPlayer(payment.getOfflinePlayer(), -payment.get(CurrencyType.MONEY))) bufferedEconomy.pay(payment); }