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

Don't truncate old database and insert only new entries

This commit is contained in:
Zrips 2016-06-27 14:19:54 +03:00
parent f19b715968
commit c935900eed
4 changed files with 25 additions and 16 deletions

View File

@ -43,11 +43,11 @@ public class ExploreManager {
return worlds; return worlds;
} }
public ExploreRespond ChunkRespond(Player player, Chunk chunk) { public ExploreRespond ChunkRespond(Player player, Chunk chunk, boolean isNew) {
return ChunkRespond(player.getName(), chunk.getWorld().getName(), chunk.getX(), chunk.getZ()); 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 ChunkX = x;
int ChunkZ = z; int ChunkZ = z;
@ -57,6 +57,8 @@ public class ExploreManager {
if (!worlds.containsKey(worldName)) { if (!worlds.containsKey(worldName)) {
ExploreChunk eChunk = new ExploreChunk(player, ChunkX, ChunkZ); ExploreChunk eChunk = new ExploreChunk(player, ChunkX, ChunkZ);
if (!isNew)
eChunk.setOldChunk();
ExploreRegion eRegion = new ExploreRegion(RegionX, RegionZ); ExploreRegion eRegion = new ExploreRegion(RegionX, RegionZ);
eRegion.addChunk(eChunk); eRegion.addChunk(eChunk);
worlds.put(worldName, eRegion); worlds.put(worldName, eRegion);
@ -70,11 +72,15 @@ public class ExploreManager {
if (one.getZ() != ChunkZ) if (one.getZ() != ChunkZ)
continue; continue;
eChunk = one; eChunk = one;
if (!isNew)
eChunk.setOldChunk();
break; break;
} }
if (eChunk == null) { if (eChunk == null) {
eChunk = new ExploreChunk(player, ChunkX, ChunkZ); eChunk = new ExploreChunk(player, ChunkX, ChunkZ);
if (!isNew)
eChunk.setOldChunk();
eRegion.addChunk(eChunk); eRegion.addChunk(eChunk);
return new ExploreRespond(eChunk.getCount(), true); return new ExploreRespond(eChunk.getCount(), true);
} }

View File

@ -28,7 +28,9 @@ import java.util.UUID;
import java.util.Map.Entry; import java.util.Map.Entry;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.Jobs;
@ -116,7 +118,7 @@ public abstract class JobsDAO {
protected abstract void checkUpdate9() throws SQLException; protected abstract void checkUpdate9() throws SQLException;
protected abstract boolean createDefaultLogBase(); protected abstract boolean createDefaultLogBase();
protected abstract boolean createDefaultArchiveBase(); protected abstract boolean createDefaultArchiveBase();
protected abstract boolean dropDataBase(String name); protected abstract boolean dropDataBase(String name);
@ -849,25 +851,20 @@ public abstract class JobsDAO {
return; return;
try { 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 (?, ?, ?, ?);"); PreparedStatement prest2 = conn.prepareStatement("INSERT INTO `" + prefix + "explore` (`worldname`, `chunkX`, `chunkZ`, `playerName`) VALUES (?, ?, ?, ?);");
conn.setAutoCommit(false); conn.setAutoCommit(false);
int i = 0;
for (Entry<String, ExploreRegion> worlds : Jobs.getExplore().getWorlds().entrySet()) { for (Entry<String, ExploreRegion> worlds : Jobs.getExplore().getWorlds().entrySet()) {
for (ExploreChunk oneChunk : worlds.getValue().getChunks()) { for (ExploreChunk oneChunk : worlds.getValue().getChunks()) {
if (!oneChunk.isNew())
continue;
for (String oneuser : oneChunk.getPlayers()) { for (String oneuser : oneChunk.getPlayers()) {
prest2.setString(1, worlds.getKey()); prest2.setString(1, worlds.getKey());
prest2.setInt(2, oneChunk.getX()); prest2.setInt(2, oneChunk.getX());
prest2.setInt(3, oneChunk.getZ()); prest2.setInt(3, oneChunk.getZ());
prest2.setString(4, oneuser); prest2.setString(4, oneuser);
prest2.addBatch(); prest2.addBatch();
i++;
} }
} }
} }
@ -875,6 +872,12 @@ public abstract class JobsDAO {
conn.commit(); conn.commit();
conn.setAutoCommit(true); conn.setAutoCommit(true);
prest2.close(); 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) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -896,7 +899,7 @@ public abstract class JobsDAO {
PreparedStatement prest = conn.prepareStatement("SELECT * FROM `" + prefix + "explore`;"); PreparedStatement prest = conn.prepareStatement("SELECT * FROM `" + prefix + "explore`;");
ResultSet res = prest.executeQuery(); ResultSet res = prest.executeQuery();
while (res.next()) { 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(); res.close();
prest.close(); prest.close();

View File

@ -1103,7 +1103,7 @@ public class JobsPaymentListener implements Listener {
if (!Jobs.getGCManager().payExploringWhenFlying()) if (!Jobs.getGCManager().payExploringWhenFlying())
return; return;
ExploreRespond respond = Jobs.getExplore().ChunkRespond(event.getPlayer(), event.getNewChunk()); ExploreRespond respond = Jobs.getExplore().ChunkRespond(event.getPlayer(), event.getNewChunk(), true);
if (!respond.isNewChunk()) if (!respond.isNewChunk())
return; return;

View File

@ -1,7 +1,7 @@
name: Jobs name: Jobs
description: Jobs Plugin for the BukkitAPI description: Jobs Plugin for the BukkitAPI
main: com.gamingmesh.jobs.JobsPlugin main: com.gamingmesh.jobs.JobsPlugin
version: 3.5.1 version: 3.5.2
author: phrstbrn author: phrstbrn
depend: [Vault] depend: [Vault]
softdepend: [CoreProtect, MythicMobs, McMMO] softdepend: [CoreProtect, MythicMobs, McMMO]