1
0
mirror of https://github.com/Zrips/Jobs.git synced 2025-01-04 23:37:49 +01:00

Fixed issue when the database is not converted correctly

This commit is contained in:
montlikadani 2020-05-14 17:32:02 +02:00
parent edfe56803a
commit 647533f57a
10 changed files with 43 additions and 48 deletions

View File

@ -19,7 +19,6 @@ import org.bukkit.inventory.ItemStack;
import com.gamingmesh.jobs.CMILib.VersionChecker.Version;
public class RawMessage {
private List<String> parts = new ArrayList<>();
@ -83,22 +82,21 @@ public class RawMessage {
if (text.equalsIgnoreCase(" "))
return text;
text = CMIChatColor.deColorize(text);
List<String> splited = new ArrayList<>();
List<String> splited = new ArrayList<String>();
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 + "\"}";

View File

@ -424,7 +424,7 @@ public class Placeholder {
case user_jobs:
List<JobProgression> 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");

View File

@ -265,21 +265,28 @@ public class PlayerManager {
int y = 0;
int i = 0;
int total = playersUUIDCache.size();
for (Entry<UUID, JobsPlayer> 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;

View File

@ -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

View File

@ -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;
}

View File

@ -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();

View File

@ -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());

View File

@ -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) {

View File

@ -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;

View File

@ -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);
}