mirror of
https://github.com/Zrips/Jobs.git
synced 2025-01-07 00:38:42 +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();
|
dao.getMap().clear();
|
||||||
if (getPlayerManager().getPlayersCache().size() != 0)
|
if (getPlayerManager().getPlayersCache().size() != 0)
|
||||||
consoleMsg("&e[Jobs] Preloaded " + getPlayerManager().getPlayersCache().size() + " players data in " +
|
consoleMsg("&e[Jobs] Preloaded " + getPlayerManager().getPlayersCache().size() + " players data in " +
|
||||||
((int) (((System.currentTimeMillis() - time) / 1000d) * 100) / 100D));
|
((int) (((System.currentTimeMillis() - time) / 1000d) * 100) / 100D));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void reload() throws IOException {
|
public static void reload() throws IOException {
|
||||||
@ -988,7 +988,8 @@ public class Jobs extends JavaPlugin {
|
|||||||
GUIManager.CloseInventories();
|
GUIManager.CloseInventories();
|
||||||
shopManager.CloseInventories();
|
shopManager.CloseInventories();
|
||||||
dao.saveExplore();
|
dao.saveExplore();
|
||||||
dao.saveBlockProtection();
|
|
||||||
|
Jobs.getBpManager().saveCache();
|
||||||
FurnaceBrewingHandling.save();
|
FurnaceBrewingHandling.save();
|
||||||
ToggleBarHandling.save();
|
ToggleBarHandling.save();
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
|
@ -4,6 +4,7 @@ import java.util.HashMap;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
|
import org.bukkit.Location;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
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.config.RestrictedAreaManager;
|
||||||
import com.gamingmesh.jobs.container.CuboidArea;
|
import com.gamingmesh.jobs.container.CuboidArea;
|
||||||
import com.gamingmesh.jobs.container.RestrictedArea;
|
import com.gamingmesh.jobs.container.RestrictedArea;
|
||||||
|
import com.gamingmesh.jobs.stuff.Debug;
|
||||||
|
|
||||||
public class area implements Cmd {
|
public class area implements Cmd {
|
||||||
|
|
||||||
@ -26,6 +28,19 @@ public class area implements Cmd {
|
|||||||
}
|
}
|
||||||
Player player = (Player) sender;
|
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();
|
RestrictedAreaManager ra = Jobs.getRestrictedAreaManager();
|
||||||
|
|
||||||
if (args.length == 3) {
|
if (args.length == 3) {
|
||||||
|
@ -52,7 +52,8 @@ public class convert implements Cmd {
|
|||||||
Jobs.getPlayerManager().clearCache();
|
Jobs.getPlayerManager().clearCache();
|
||||||
|
|
||||||
Jobs.getJobsDAO().saveExplore();
|
Jobs.getJobsDAO().saveExplore();
|
||||||
Jobs.getJobsDAO().saveBlockProtection();
|
// Do we really need to convert Block protection?
|
||||||
|
// Jobs.getJobsDAO().saveBlockProtection();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
Jobs.consoleMsg("&cCan't write data to data base, please send error log to dev's.");
|
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.HashMap;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
@ -16,6 +17,7 @@ import com.gamingmesh.jobs.container.DBAction;
|
|||||||
public class BlockProtectionManager {
|
public class BlockProtectionManager {
|
||||||
|
|
||||||
private HashMap<World, HashMap<String, HashMap<String, HashMap<String, BlockProtection>>>> map = new HashMap<>();
|
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;
|
public Long timer = 0L;
|
||||||
|
|
||||||
@ -83,9 +85,37 @@ public class BlockProtectionManager {
|
|||||||
chunks.put(chunk, Bpm);
|
chunks.put(chunk, Bpm);
|
||||||
regions.put(region, chunks);
|
regions.put(region, chunks);
|
||||||
map.put(loc.getWorld(), regions);
|
map.put(loc.getWorld(), regions);
|
||||||
|
addToCache(loc, Bp);
|
||||||
return 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) {
|
public BlockProtection remove(Block block) {
|
||||||
return remove(block.getLocation());
|
return remove(block.getLocation());
|
||||||
}
|
}
|
||||||
|
@ -823,9 +823,9 @@ public class GeneralConfigManager {
|
|||||||
|
|
||||||
c.addComment("ExploitProtections.General.KeepDataFor",
|
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",
|
"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 = 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.");
|
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);
|
useGlobalTimer = c.get("ExploitProtections.General.GlobalBlockTimer.use", true);
|
||||||
|
@ -57,4 +57,8 @@ public class JobsConnection {
|
|||||||
public synchronized DatabaseMetaData getMetaData() throws SQLException {
|
public synchronized DatabaseMetaData getMetaData() throws SQLException {
|
||||||
return conn.getMetaData();
|
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
|
* Save block protection information
|
||||||
* @param jobBlockProtection - the information getting saved
|
* @param jobBlockProtection - the information getting saved
|
||||||
*/
|
*/
|
||||||
public void saveBlockProtection() {
|
public void saveBlockProtection(String world, HashMap<String, BlockProtection> cache) {
|
||||||
JobsConnection conn = getConnection();
|
JobsConnection conn = getConnection();
|
||||||
if (conn == null)
|
if (conn == null)
|
||||||
return;
|
return;
|
||||||
@ -1641,83 +1641,55 @@ public abstract class JobsDAO {
|
|||||||
update = conn.prepareStatement("UPDATE `" + prefix + "blocks` SET `recorded` = ?, `resets` = ? WHERE `id` = ?;");
|
update = conn.prepareStatement("UPDATE `" + prefix + "blocks` SET `recorded` = ?, `resets` = ? WHERE `id` = ?;");
|
||||||
delete = conn.prepareStatement("DELETE from `" + getPrefix() + "blocks` WHERE `id` = ?;");
|
delete = conn.prepareStatement("DELETE from `" + getPrefix() + "blocks` WHERE `id` = ?;");
|
||||||
|
|
||||||
Jobs.getPluginLogger().info("Saving blocks");
|
|
||||||
|
|
||||||
conn.setAutoCommit(false);
|
conn.setAutoCommit(false);
|
||||||
int inserted = 0;
|
|
||||||
int updated = 0;
|
|
||||||
int deleted = 0;
|
|
||||||
Long current = System.currentTimeMillis();
|
Long current = System.currentTimeMillis();
|
||||||
Long mark = System.currentTimeMillis() - (Jobs.getGCManager().BlockProtectionDays * 24L * 60L * 60L * 1000L);
|
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, BlockProtection> block : cache.entrySet()) {
|
||||||
for (Entry<String, HashMap<String, HashMap<String, BlockProtection>>> regions : worlds.getValue().entrySet()) {
|
if (block.getValue() == null)
|
||||||
for (Entry<String, HashMap<String, BlockProtection>> chunks : regions.getValue().entrySet()) {
|
continue;
|
||||||
for (Entry<String, BlockProtection> block : chunks.getValue().entrySet()) {
|
switch (block.getValue().getAction()) {
|
||||||
if (block.getValue() == null)
|
case DELETE:
|
||||||
continue;
|
delete.setInt(1, block.getValue().getId());
|
||||||
switch (block.getValue().getAction()) {
|
delete.addBatch();
|
||||||
case DELETE:
|
|
||||||
delete.setInt(1, block.getValue().getId());
|
|
||||||
delete.addBatch();
|
|
||||||
|
|
||||||
deleted++;
|
break;
|
||||||
if (deleted % 10000 == 0) {
|
case INSERT:
|
||||||
delete.executeBatch();
|
if (block.getValue().getTime() < current && block.getValue().getTime() != -1)
|
||||||
Jobs.consoleMsg("&6[Jobs] Removed " + deleted + " old block protection entries.");
|
continue;
|
||||||
}
|
insert.setString(1, world);
|
||||||
break;
|
insert.setInt(2, block.getValue().getPos().getBlockX());
|
||||||
case INSERT:
|
insert.setInt(3, block.getValue().getPos().getBlockY());
|
||||||
if (block.getValue().getTime() < current && block.getValue().getTime() != -1)
|
insert.setInt(4, block.getValue().getPos().getBlockZ());
|
||||||
continue;
|
insert.setLong(5, block.getValue().getRecorded());
|
||||||
insert.setString(1, worlds.getKey().getName());
|
insert.setLong(6, block.getValue().getTime());
|
||||||
insert.setInt(2, block.getValue().getPos().getBlockX());
|
insert.addBatch();
|
||||||
insert.setInt(3, block.getValue().getPos().getBlockY());
|
block.getValue().setAction(DBAction.NONE);
|
||||||
insert.setInt(4, block.getValue().getPos().getBlockZ());
|
|
||||||
insert.setLong(5, block.getValue().getRecorded());
|
|
||||||
insert.setLong(6, block.getValue().getTime());
|
|
||||||
insert.addBatch();
|
|
||||||
|
|
||||||
inserted++;
|
break;
|
||||||
if (inserted % 10000 == 0) {
|
case UPDATE:
|
||||||
insert.executeBatch();
|
if (block.getValue().getTime() < current && block.getValue().getTime() != -1)
|
||||||
Jobs.consoleMsg("&6[Jobs] Added " + inserted + " new block protection entries.");
|
continue;
|
||||||
}
|
update.setLong(1, block.getValue().getRecorded());
|
||||||
break;
|
update.setLong(2, block.getValue().getTime());
|
||||||
case UPDATE:
|
update.setInt(3, block.getValue().getId());
|
||||||
if (block.getValue().getTime() < current && block.getValue().getTime() != -1)
|
update.addBatch();
|
||||||
continue;
|
block.getValue().setAction(DBAction.NONE);
|
||||||
update.setLong(1, block.getValue().getRecorded());
|
|
||||||
update.setLong(2, block.getValue().getTime());
|
|
||||||
update.setInt(3, block.getValue().getId());
|
|
||||||
update.addBatch();
|
|
||||||
|
|
||||||
updated++;
|
break;
|
||||||
if (updated % 10000 == 0) {
|
case NONE:
|
||||||
update.executeBatch();
|
if (block.getValue().getTime() < current && block.getValue().getTime() != -1)
|
||||||
Jobs.consoleMsg("&6[Jobs] Upadated " + updated + " old block protection entries.");
|
continue;
|
||||||
}
|
if (block.getValue().getTime() == -1 && block.getValue().getRecorded() > mark)
|
||||||
break;
|
continue;
|
||||||
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.setInt(1, block.getValue().getId());
|
||||||
delete.addBatch();
|
delete.addBatch();
|
||||||
|
|
||||||
deleted++;
|
break;
|
||||||
if (deleted % 10000 == 0) {
|
default:
|
||||||
delete.executeBatch();
|
continue;
|
||||||
Jobs.getPluginLogger().info("[Jobs] Removed " + deleted + " old block protection entries.");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1725,16 +1697,7 @@ public abstract class JobsDAO {
|
|||||||
update.executeBatch();
|
update.executeBatch();
|
||||||
delete.executeBatch();
|
delete.executeBatch();
|
||||||
conn.commit();
|
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) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} finally {
|
} finally {
|
||||||
@ -2124,4 +2087,4 @@ public abstract class JobsDAO {
|
|||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user