1
0
mirror of https://github.com/Zrips/Jobs.git synced 2024-11-29 14:05:25 +01:00

When converting, include user table

This commit is contained in:
Zrips 2016-09-23 15:07:35 +03:00
parent 81a02dbbe0
commit d009b5b782
12 changed files with 2871 additions and 2837 deletions

View File

@ -289,7 +289,8 @@ public class PlayerManager {
if (!jPlayer.leaveJob(job)) if (!jPlayer.leaveJob(job))
return false; return false;
Jobs.getJobsDAO().quitJob(jPlayer, job); if (!Jobs.getJobsDAO().quitJob(jPlayer, job))
return false;
PerformCommands.PerformCommandsOnLeave(jPlayer, job); PerformCommands.PerformCommandsOnLeave(jPlayer, job);
Jobs.leaveSlot(job); Jobs.leaveSlot(job);
@ -319,18 +320,20 @@ public class PlayerManager {
* @param oldjob - the old job * @param oldjob - the old job
* @param newjob - the new job * @param newjob - the new job
*/ */
public void transferJob(JobsPlayer jPlayer, Job oldjob, Job newjob) { public boolean transferJob(JobsPlayer jPlayer, Job oldjob, Job newjob) {
// synchronized (jPlayer.saveLock) { // synchronized (jPlayer.saveLock) {
if (!jPlayer.transferJob(oldjob, newjob)) if (!jPlayer.transferJob(oldjob, newjob))
return; return false;
JobsDAO dao = Jobs.getJobsDAO(); JobsDAO dao = Jobs.getJobsDAO();
dao.quitJob(jPlayer, oldjob); if (!dao.quitJob(jPlayer, oldjob))
return false;
oldjob.updateTotalPlayers(); oldjob.updateTotalPlayers();
dao.joinJob(jPlayer, newjob); dao.joinJob(jPlayer, newjob);
newjob.updateTotalPlayers(); newjob.updateTotalPlayers();
jPlayer.save(); jPlayer.save();
// } // }
return true;
} }
/** /**

View File

@ -21,7 +21,7 @@ public class convert implements Cmd {
if (sender instanceof Player) { if (sender instanceof Player) {
sender.sendMessage(Jobs.getLanguage().getMessage("general.error.fromconsole")); sender.sendMessage(Jobs.getLanguage().getMessage("general.error.fromconsole"));
return false; return true;
} }
if (args.length > 0) { if (args.length > 0) {
@ -38,8 +38,9 @@ public class convert implements Cmd {
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
sender.sendMessage(ChatColor.RED + "Can't read data from data base, please send error log to dev's."); sender.sendMessage(ChatColor.RED + "Can't read data from data base, please send error log to dev's.");
return false; return true;
} }
Jobs.ChangeDatabase(); Jobs.ChangeDatabase();
if (list == null & archivelist == null) if (list == null & archivelist == null)
@ -47,10 +48,11 @@ public class convert implements Cmd {
try { try {
Jobs.getJobsDAO().continueConvertions(list, "jobs"); Jobs.getJobsDAO().continueConvertions(list, "jobs");
Jobs.getJobsDAO().continueConvertions(archivelist, "archive"); Jobs.getJobsDAO().continueConvertions(archivelist, "archive");
Jobs.getJobsDAO().transferUsers();
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
sender.sendMessage(ChatColor.RED + "Can't write data to data base, please send error log to dev's."); sender.sendMessage(ChatColor.RED + "Can't write data to data base, please send error log to dev's.");
return false; return true;
} }
try { try {

View File

@ -1,7 +1,5 @@
package com.gamingmesh.jobs.commands.list; package com.gamingmesh.jobs.commands.list;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;

View File

@ -1,7 +1,5 @@
package com.gamingmesh.jobs.commands.list; package com.gamingmesh.jobs.commands.list;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;

View File

@ -540,7 +540,7 @@ public class ConfigManager {
break; break;
} }
} else if (actionType == ActionType.ENCHANT && material == null) { } else if (actionType == ActionType.ENCHANT) {
Enchantment enchant = Enchantment.getByName(myKey); Enchantment enchant = Enchantment.getByName(myKey);
if (enchant != null) if (enchant != null)
id = enchant.getId(); id = enchant.getId();

View File

@ -42,7 +42,6 @@ public class LanguageManager {
for (String lang : languages) { for (String lang : languages) {
YmlMaker langFile = new YmlMaker(plugin, "locale" + File.separator + "messages_" + lang + ".yml"); YmlMaker langFile = new YmlMaker(plugin, "locale" + File.separator + "messages_" + lang + ".yml");
if (langFile != null)
langFile.saveDefaultConfig(); langFile.saveDefaultConfig();
} }

View File

@ -176,7 +176,6 @@ public class NameTranslatorManager {
for (String lang : languages) { for (String lang : languages) {
YmlMaker langFile = new YmlMaker(plugin, "TranslatableWords" + File.separator + "Words_" + lang + ".yml"); YmlMaker langFile = new YmlMaker(plugin, "TranslatableWords" + File.separator + "Words_" + lang + ".yml");
if (langFile != null)
langFile.saveDefaultConfig(); langFile.saveDefaultConfig();
} }

View File

@ -128,7 +128,7 @@ public class JobsPlayer {
* @return the Multiplier * @return the Multiplier
*/ */
public double getVipSpawnerMultiplier() { public double getVipSpawnerMultiplier() {
if (OffPlayer == null || !this.OffPlayer.isOnline()) if (this.getPlayer() == null || !this.getPlayer().isOnline())
return 1.0; return 1.0;
if (VipSpawnerMultiplier < 0) if (VipSpawnerMultiplier < 0)
updateVipSpawnerMultiplier(); updateVipSpawnerMultiplier();

View File

@ -448,16 +448,49 @@ public abstract class JobsDAO {
} }
} }
public void transferUsers() throws SQLException {
JobsConnection conns = this.getConnection();
if (conns == null)
return;
PreparedStatement insert = null;
Statement statement = null;
try {
statement = conns.createStatement();
if (Jobs.getGCManager().storageMethod.equalsIgnoreCase("sqlite")) {
statement.executeUpdate("TRUNCATE `" + getPrefix() + "users`");
} else {
statement.executeUpdate("DELETE from `" + getPrefix() + "users`");
}
insert = conns.prepareStatement("INSERT INTO `" + getPrefix() + "users` (`id`, `player_uuid`, `username`) VALUES (?, ?, ?);");
conns.setAutoCommit(false);
for (Entry<String, JobsPlayer> oneUser : Jobs.getPlayerManager().getPlayersCache().entrySet()) {
insert.setInt(1, oneUser.getValue().getUserId());
insert.setString(2, oneUser.getValue().getPlayerUUID().toString());
insert.setString(3, oneUser.getValue().getUserName());
insert.addBatch();
}
insert.executeBatch();
conns.commit();
conns.setAutoCommit(true);
} finally {
close(statement);
close(insert);
}
}
/** /**
* Quit a job (delete player-job entry from storage) * Quit a job (delete player-job entry from storage)
* @param player - player that wishes to quit the job * @param player - player that wishes to quit the job
* @param job - job that the player wishes to quit * @param job - job that the player wishes to quit
*/ */
public synchronized void quitJob(JobsPlayer jPlayer, Job job) { public synchronized boolean quitJob(JobsPlayer jPlayer, Job job) {
JobsConnection conn = getConnection(); JobsConnection conn = getConnection();
if (conn == null) if (conn == null)
return; return false;
PreparedStatement prest = null; PreparedStatement prest = null;
boolean ok = true;
try { try {
prest = conn.prepareStatement("DELETE FROM `" + prefix + "jobs` WHERE `userid` = ? AND `job` = ?;"); prest = conn.prepareStatement("DELETE FROM `" + prefix + "jobs` WHERE `userid` = ? AND `job` = ?;");
prest.setInt(1, jPlayer.getUserId()); prest.setInt(1, jPlayer.getUserId());
@ -465,9 +498,11 @@ public abstract class JobsDAO {
prest.execute(); prest.execute();
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
ok = false;
} finally { } finally {
close(prest); close(prest);
} }
return ok;
} }
/** /**

View File

@ -567,7 +567,7 @@ public class JobsPaymentListener implements Listener {
ItemStack toCraft = event.getCurrentItem(); ItemStack toCraft = event.getCurrentItem();
ItemStack toStore = event.getCursor(); ItemStack toStore = event.getCursor();
// Make sure we are actually crafting anything // Make sure we are actually crafting anything
if (player != null && hasItems(toCraft)) if (hasItems(toCraft))
if (event.isShiftClick()) if (event.isShiftClick())
schedulePostDetection(player, toCraft, jPlayer, resultStack, multiplier); schedulePostDetection(player, toCraft, jPlayer, resultStack, multiplier);
else { else {
@ -627,7 +627,7 @@ public class JobsPaymentListener implements Listener {
if (a == null) if (a == null)
return b == null; return b == null;
else if (b == null) else if (b == null)
return a == null; return false;
return a.getTypeId() == b.getTypeId() && a.getDurability() == b.getDurability() && Objects.equal(a.getData(), b.getData()) && Objects.equal(a.getEnchantments(), b return a.getTypeId() == b.getTypeId() && a.getDurability() == b.getDurability() && Objects.equal(a.getData(), b.getData()) && Objects.equal(a.getEnchantments(), b
.getEnchantments()); .getEnchantments());
} }