mirror of
https://github.com/Zrips/Jobs.git
synced 2025-01-04 23:37:49 +01:00
Lets save block protection in 100's batches whatever it reaches this
limit, instead of doing everything in one go on server shutdown
This commit is contained in:
parent
b1d457d2d6
commit
229be42d64
@ -659,8 +659,8 @@ public class Jobs extends JavaPlugin {
|
||||
|
||||
dao.getMap().clear();
|
||||
if (getPlayerManager().getPlayersCache().size() != 0)
|
||||
consoleMsg("&e[Jobs] Preloaded " + getPlayerManager().getPlayersCache().size() + " players data in " +
|
||||
((int) (((System.currentTimeMillis() - time) / 1000d) * 100) / 100D));
|
||||
consoleMsg("&e[Jobs] Preloaded " + getPlayerManager().getPlayersCache().size() + " players data in " +
|
||||
((int) (((System.currentTimeMillis() - time) / 1000d) * 100) / 100D));
|
||||
}
|
||||
|
||||
public static void reload() throws IOException {
|
||||
@ -988,7 +988,8 @@ public class Jobs extends JavaPlugin {
|
||||
GUIManager.CloseInventories();
|
||||
shopManager.CloseInventories();
|
||||
dao.saveExplore();
|
||||
dao.saveBlockProtection();
|
||||
|
||||
Jobs.getBpManager().saveCache();
|
||||
FurnaceBrewingHandling.save();
|
||||
ToggleBarHandling.save();
|
||||
} catch (Throwable e) {
|
||||
|
@ -4,6 +4,7 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@ -14,6 +15,7 @@ import com.gamingmesh.jobs.commands.JobCommand;
|
||||
import com.gamingmesh.jobs.config.RestrictedAreaManager;
|
||||
import com.gamingmesh.jobs.container.CuboidArea;
|
||||
import com.gamingmesh.jobs.container.RestrictedArea;
|
||||
import com.gamingmesh.jobs.stuff.Debug;
|
||||
|
||||
public class area implements Cmd {
|
||||
|
||||
@ -26,6 +28,19 @@ public class area implements Cmd {
|
||||
}
|
||||
Player player = (Player) sender;
|
||||
|
||||
Location center = player.getLocation();
|
||||
Debug.D("adding " + Jobs.getBpManager().getSize());
|
||||
for (int x = -16; x < 16; x++) {
|
||||
for (int z = -16; z < 16; z++) {
|
||||
Location lc = center.clone().add(x, 0, z);
|
||||
for (int y = 250; y > 1; y--) {
|
||||
lc.setY(y);
|
||||
Jobs.getBpManager().add(lc, 100);
|
||||
}
|
||||
}
|
||||
}
|
||||
Debug.D("added " + Jobs.getBpManager().getSize());
|
||||
|
||||
RestrictedAreaManager ra = Jobs.getRestrictedAreaManager();
|
||||
|
||||
if (args.length == 3) {
|
||||
|
@ -52,7 +52,8 @@ public class convert implements Cmd {
|
||||
Jobs.getPlayerManager().clearCache();
|
||||
|
||||
Jobs.getJobsDAO().saveExplore();
|
||||
Jobs.getJobsDAO().saveBlockProtection();
|
||||
// Do we really need to convert Block protection?
|
||||
// Jobs.getJobsDAO().saveBlockProtection();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
Jobs.consoleMsg("&cCan't write data to data base, please send error log to dev's.");
|
||||
|
@ -3,6 +3,7 @@ package com.gamingmesh.jobs.config;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
@ -16,6 +17,7 @@ import com.gamingmesh.jobs.container.DBAction;
|
||||
public class BlockProtectionManager {
|
||||
|
||||
private HashMap<World, HashMap<String, HashMap<String, HashMap<String, BlockProtection>>>> map = new HashMap<>();
|
||||
private HashMap<World, HashMap<String, BlockProtection>> tempCache = new HashMap<>();
|
||||
|
||||
public Long timer = 0L;
|
||||
|
||||
@ -83,9 +85,37 @@ public class BlockProtectionManager {
|
||||
chunks.put(chunk, Bpm);
|
||||
regions.put(region, chunks);
|
||||
map.put(loc.getWorld(), regions);
|
||||
addToCache(loc, Bp);
|
||||
return Bp;
|
||||
}
|
||||
|
||||
private void addToCache(Location loc, BlockProtection Bp) {
|
||||
if (!Jobs.getGCManager().useBlockProtection)
|
||||
return;
|
||||
String v = loc.getBlockX() + ":" + loc.getBlockY() + ":" + loc.getBlockZ();
|
||||
HashMap<String, BlockProtection> locations = tempCache.get(loc.getWorld());
|
||||
if (locations == null) {
|
||||
locations = new HashMap<String, BlockProtection>();
|
||||
tempCache.put(loc.getWorld(), locations);
|
||||
}
|
||||
|
||||
locations.put(v, Bp);
|
||||
|
||||
if (locations.size() > 100) {
|
||||
Jobs.getJobsDAO().saveBlockProtection(loc.getWorld().getName(), new HashMap<String, BlockProtection>(locations));
|
||||
locations.clear();
|
||||
}
|
||||
}
|
||||
|
||||
public void saveCache() {
|
||||
if (!Jobs.getGCManager().useBlockProtection)
|
||||
return;
|
||||
for (Entry<World, HashMap<String, BlockProtection>> one : tempCache.entrySet()) {
|
||||
Jobs.getJobsDAO().saveBlockProtection(one.getKey().getName(), one.getValue());
|
||||
}
|
||||
tempCache.clear();
|
||||
}
|
||||
|
||||
public BlockProtection remove(Block block) {
|
||||
return remove(block.getLocation());
|
||||
}
|
||||
|
@ -823,9 +823,9 @@ public class GeneralConfigManager {
|
||||
|
||||
c.addComment("ExploitProtections.General.KeepDataFor",
|
||||
"For how long in days to keep block protection data in data base", "This will clean block data which ones have -1 as cooldown value",
|
||||
"Data base cleanup will be performed on each server startup", "This cant be more then 30 days");
|
||||
"Data base cleanup will be performed on each server startup", "This cant be more then 14 days");
|
||||
BlockProtectionDays = c.get("ExploitProtections.General.KeepDataFor", 14);
|
||||
BlockProtectionDays = BlockProtectionDays > 30 ? 30 : BlockProtectionDays;
|
||||
BlockProtectionDays = BlockProtectionDays > 14 ? 14 : BlockProtectionDays;
|
||||
|
||||
c.addComment("ExploitProtections.General.GlobalBlockTimer", "All blocks will be protected X sec after player places it on ground.");
|
||||
useGlobalTimer = c.get("ExploitProtections.General.GlobalBlockTimer.use", true);
|
||||
|
@ -57,4 +57,8 @@ public class JobsConnection {
|
||||
public synchronized DatabaseMetaData getMetaData() throws SQLException {
|
||||
return conn.getMetaData();
|
||||
}
|
||||
|
||||
public synchronized void setClientInfo(String path, String value) throws SQLException {
|
||||
conn.setClientInfo(path, value);
|
||||
}
|
||||
}
|
||||
|
@ -1628,7 +1628,7 @@ public abstract class JobsDAO {
|
||||
* Save block protection information
|
||||
* @param jobBlockProtection - the information getting saved
|
||||
*/
|
||||
public void saveBlockProtection() {
|
||||
public void saveBlockProtection(String world, HashMap<String, BlockProtection> cache) {
|
||||
JobsConnection conn = getConnection();
|
||||
if (conn == null)
|
||||
return;
|
||||
@ -1641,83 +1641,55 @@ public abstract class JobsDAO {
|
||||
update = conn.prepareStatement("UPDATE `" + prefix + "blocks` SET `recorded` = ?, `resets` = ? WHERE `id` = ?;");
|
||||
delete = conn.prepareStatement("DELETE from `" + getPrefix() + "blocks` WHERE `id` = ?;");
|
||||
|
||||
Jobs.getPluginLogger().info("Saving blocks");
|
||||
|
||||
conn.setAutoCommit(false);
|
||||
int inserted = 0;
|
||||
int updated = 0;
|
||||
int deleted = 0;
|
||||
|
||||
Long current = System.currentTimeMillis();
|
||||
Long mark = System.currentTimeMillis() - (Jobs.getGCManager().BlockProtectionDays * 24L * 60L * 60L * 1000L);
|
||||
|
||||
for (Entry<World, HashMap<String, HashMap<String, HashMap<String, BlockProtection>>>> worlds : Jobs.getBpManager().getMap().entrySet()) {
|
||||
for (Entry<String, HashMap<String, HashMap<String, BlockProtection>>> regions : worlds.getValue().entrySet()) {
|
||||
for (Entry<String, HashMap<String, BlockProtection>> chunks : regions.getValue().entrySet()) {
|
||||
for (Entry<String, BlockProtection> block : chunks.getValue().entrySet()) {
|
||||
if (block.getValue() == null)
|
||||
continue;
|
||||
switch (block.getValue().getAction()) {
|
||||
case DELETE:
|
||||
delete.setInt(1, block.getValue().getId());
|
||||
delete.addBatch();
|
||||
for (Entry<String, BlockProtection> block : cache.entrySet()) {
|
||||
if (block.getValue() == null)
|
||||
continue;
|
||||
switch (block.getValue().getAction()) {
|
||||
case DELETE:
|
||||
delete.setInt(1, block.getValue().getId());
|
||||
delete.addBatch();
|
||||
|
||||
deleted++;
|
||||
if (deleted % 10000 == 0) {
|
||||
delete.executeBatch();
|
||||
Jobs.consoleMsg("&6[Jobs] Removed " + deleted + " old block protection entries.");
|
||||
}
|
||||
break;
|
||||
case INSERT:
|
||||
if (block.getValue().getTime() < current && block.getValue().getTime() != -1)
|
||||
continue;
|
||||
insert.setString(1, worlds.getKey().getName());
|
||||
insert.setInt(2, block.getValue().getPos().getBlockX());
|
||||
insert.setInt(3, block.getValue().getPos().getBlockY());
|
||||
insert.setInt(4, block.getValue().getPos().getBlockZ());
|
||||
insert.setLong(5, block.getValue().getRecorded());
|
||||
insert.setLong(6, block.getValue().getTime());
|
||||
insert.addBatch();
|
||||
break;
|
||||
case INSERT:
|
||||
if (block.getValue().getTime() < current && block.getValue().getTime() != -1)
|
||||
continue;
|
||||
insert.setString(1, world);
|
||||
insert.setInt(2, block.getValue().getPos().getBlockX());
|
||||
insert.setInt(3, block.getValue().getPos().getBlockY());
|
||||
insert.setInt(4, block.getValue().getPos().getBlockZ());
|
||||
insert.setLong(5, block.getValue().getRecorded());
|
||||
insert.setLong(6, block.getValue().getTime());
|
||||
insert.addBatch();
|
||||
block.getValue().setAction(DBAction.NONE);
|
||||
|
||||
inserted++;
|
||||
if (inserted % 10000 == 0) {
|
||||
insert.executeBatch();
|
||||
Jobs.consoleMsg("&6[Jobs] Added " + inserted + " new block protection entries.");
|
||||
}
|
||||
break;
|
||||
case UPDATE:
|
||||
if (block.getValue().getTime() < current && block.getValue().getTime() != -1)
|
||||
continue;
|
||||
update.setLong(1, block.getValue().getRecorded());
|
||||
update.setLong(2, block.getValue().getTime());
|
||||
update.setInt(3, block.getValue().getId());
|
||||
update.addBatch();
|
||||
break;
|
||||
case UPDATE:
|
||||
if (block.getValue().getTime() < current && block.getValue().getTime() != -1)
|
||||
continue;
|
||||
update.setLong(1, block.getValue().getRecorded());
|
||||
update.setLong(2, block.getValue().getTime());
|
||||
update.setInt(3, block.getValue().getId());
|
||||
update.addBatch();
|
||||
block.getValue().setAction(DBAction.NONE);
|
||||
|
||||
updated++;
|
||||
if (updated % 10000 == 0) {
|
||||
update.executeBatch();
|
||||
Jobs.consoleMsg("&6[Jobs] Upadated " + updated + " old block protection entries.");
|
||||
}
|
||||
break;
|
||||
case NONE:
|
||||
if (block.getValue().getTime() < current && block.getValue().getTime() != -1)
|
||||
continue;
|
||||
if (block.getValue().getTime() == -1 && block.getValue().getRecorded() > mark)
|
||||
continue;
|
||||
break;
|
||||
case NONE:
|
||||
if (block.getValue().getTime() < current && block.getValue().getTime() != -1)
|
||||
continue;
|
||||
if (block.getValue().getTime() == -1 && block.getValue().getRecorded() > mark)
|
||||
continue;
|
||||
|
||||
delete.setInt(1, block.getValue().getId());
|
||||
delete.addBatch();
|
||||
delete.setInt(1, block.getValue().getId());
|
||||
delete.addBatch();
|
||||
|
||||
deleted++;
|
||||
if (deleted % 10000 == 0) {
|
||||
delete.executeBatch();
|
||||
Jobs.getPluginLogger().info("[Jobs] Removed " + deleted + " old block protection entries.");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1725,16 +1697,7 @@ public abstract class JobsDAO {
|
||||
update.executeBatch();
|
||||
delete.executeBatch();
|
||||
conn.commit();
|
||||
conn.setAutoCommit(true);
|
||||
if (inserted > 0) {
|
||||
Jobs.consoleMsg("&6[Jobs] Added " + inserted + " new block protection entries.");
|
||||
}
|
||||
if (updated > 0) {
|
||||
Jobs.consoleMsg("&6[Jobs] Updated " + updated + " with new block protection entries.");
|
||||
}
|
||||
if (deleted > 0) {
|
||||
Jobs.consoleMsg("&6[Jobs] Deleted " + deleted + " old block protection entries.");
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
@ -2124,4 +2087,4 @@ public abstract class JobsDAO {
|
||||
return map;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user