1
0
mirror of https://github.com/Zrips/Jobs.git synced 2024-11-25 20:16:13 +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;
}
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);
}

View File

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

View File

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

View File

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