From c935900eed46c734e9aec6415046030593ad4864 Mon Sep 17 00:00:00 2001 From: Zrips Date: Mon, 27 Jun 2016 14:19:54 +0300 Subject: [PATCH] Don't truncate old database and insert only new entries --- .../jobs/config/ExploreManager.java | 12 ++++++--- com/gamingmesh/jobs/dao/JobsDAO.java | 25 +++++++++++-------- .../jobs/listeners/JobsPaymentListener.java | 2 +- plugin.yml | 2 +- 4 files changed, 25 insertions(+), 16 deletions(-) diff --git a/com/gamingmesh/jobs/config/ExploreManager.java b/com/gamingmesh/jobs/config/ExploreManager.java index 26e0afad..ab5fb46d 100644 --- a/com/gamingmesh/jobs/config/ExploreManager.java +++ b/com/gamingmesh/jobs/config/ExploreManager.java @@ -43,11 +43,11 @@ public class ExploreManager { return worlds; } - public ExploreRespond ChunkRespond(Player player, Chunk chunk) { - return ChunkRespond(player.getName(), chunk.getWorld().getName(), chunk.getX(), chunk.getZ()); + public ExploreRespond ChunkRespond(Player player, Chunk chunk, boolean isNew) { + return ChunkRespond(player.getName(), chunk.getWorld().getName(), chunk.getX(), chunk.getZ(), isNew); } - public ExploreRespond ChunkRespond(String player, String worldName, int x, int z) { + public ExploreRespond ChunkRespond(String player, String worldName, int x, int z, boolean isNew) { int ChunkX = x; int ChunkZ = z; @@ -57,6 +57,8 @@ public class ExploreManager { if (!worlds.containsKey(worldName)) { ExploreChunk eChunk = new ExploreChunk(player, ChunkX, ChunkZ); + if (!isNew) + eChunk.setOldChunk(); ExploreRegion eRegion = new ExploreRegion(RegionX, RegionZ); eRegion.addChunk(eChunk); worlds.put(worldName, eRegion); @@ -70,11 +72,15 @@ public class ExploreManager { if (one.getZ() != ChunkZ) continue; eChunk = one; + if (!isNew) + eChunk.setOldChunk(); break; } if (eChunk == null) { eChunk = new ExploreChunk(player, ChunkX, ChunkZ); + if (!isNew) + eChunk.setOldChunk(); eRegion.addChunk(eChunk); return new ExploreRespond(eChunk.getCount(), true); } diff --git a/com/gamingmesh/jobs/dao/JobsDAO.java b/com/gamingmesh/jobs/dao/JobsDAO.java index fd0303b1..7bbb17e8 100644 --- a/com/gamingmesh/jobs/dao/JobsDAO.java +++ b/com/gamingmesh/jobs/dao/JobsDAO.java @@ -28,7 +28,9 @@ import java.util.UUID; import java.util.Map.Entry; import org.bukkit.Bukkit; +import org.bukkit.ChatColor; import org.bukkit.OfflinePlayer; +import org.bukkit.command.ConsoleCommandSender; import org.bukkit.entity.Player; import com.gamingmesh.jobs.Jobs; @@ -116,7 +118,7 @@ public abstract class JobsDAO { protected abstract void checkUpdate9() throws SQLException; protected abstract boolean createDefaultLogBase(); - + protected abstract boolean createDefaultArchiveBase(); protected abstract boolean dropDataBase(String name); @@ -849,25 +851,20 @@ public abstract class JobsDAO { return; try { - PreparedStatement prest = null; - if (Jobs.getGCManager().storageMethod.equalsIgnoreCase("sqlite")) { - prest = conn.prepareStatement("DELETE from `" + prefix + "explore`;"); - } else - prest = conn.prepareStatement("TRUNCATE TABLE `" + prefix + "explore`;"); - - prest.execute(); - prest.close(); - PreparedStatement prest2 = conn.prepareStatement("INSERT INTO `" + prefix + "explore` (`worldname`, `chunkX`, `chunkZ`, `playerName`) VALUES (?, ?, ?, ?);"); conn.setAutoCommit(false); + int i = 0; for (Entry worlds : Jobs.getExplore().getWorlds().entrySet()) { for (ExploreChunk oneChunk : worlds.getValue().getChunks()) { + if (!oneChunk.isNew()) + continue; for (String oneuser : oneChunk.getPlayers()) { prest2.setString(1, worlds.getKey()); prest2.setInt(2, oneChunk.getX()); prest2.setInt(3, oneChunk.getZ()); prest2.setString(4, oneuser); prest2.addBatch(); + i++; } } } @@ -875,6 +872,12 @@ public abstract class JobsDAO { conn.commit(); conn.setAutoCommit(true); prest2.close(); + + if (i > 0) { + String message = ChatColor.translateAlternateColorCodes('&', "&e[Jobs] Saved " + i + " new explorer entries."); + ConsoleCommandSender console = Bukkit.getServer().getConsoleSender(); + console.sendMessage(message); + } } catch (SQLException e) { e.printStackTrace(); } @@ -896,7 +899,7 @@ public abstract class JobsDAO { PreparedStatement prest = conn.prepareStatement("SELECT * FROM `" + prefix + "explore`;"); ResultSet res = prest.executeQuery(); while (res.next()) { - Jobs.getExplore().ChunkRespond(res.getString("playerName"), res.getString("worldname"), res.getInt("chunkX"), res.getInt("chunkZ")); + Jobs.getExplore().ChunkRespond(res.getString("playerName"), res.getString("worldname"), res.getInt("chunkX"), res.getInt("chunkZ"), false); } res.close(); prest.close(); diff --git a/com/gamingmesh/jobs/listeners/JobsPaymentListener.java b/com/gamingmesh/jobs/listeners/JobsPaymentListener.java index 6a48aab8..7823aebd 100644 --- a/com/gamingmesh/jobs/listeners/JobsPaymentListener.java +++ b/com/gamingmesh/jobs/listeners/JobsPaymentListener.java @@ -1103,7 +1103,7 @@ public class JobsPaymentListener implements Listener { if (!Jobs.getGCManager().payExploringWhenFlying()) return; - ExploreRespond respond = Jobs.getExplore().ChunkRespond(event.getPlayer(), event.getNewChunk()); + ExploreRespond respond = Jobs.getExplore().ChunkRespond(event.getPlayer(), event.getNewChunk(), true); if (!respond.isNewChunk()) return; diff --git a/plugin.yml b/plugin.yml index a63146f6..bba1449c 100644 --- a/plugin.yml +++ b/plugin.yml @@ -1,7 +1,7 @@ name: Jobs description: Jobs Plugin for the BukkitAPI main: com.gamingmesh.jobs.JobsPlugin -version: 3.5.1 +version: 3.5.2 author: phrstbrn depend: [Vault] softdepend: [CoreProtect, MythicMobs, McMMO]