1
0
mirror of https://github.com/Zrips/Jobs.git synced 2025-02-27 09:43:22 +01:00

Option to disable explorer database saving

This commit is contained in:
Zrips 2023-09-25 16:36:00 +03:00
parent cbff3e6138
commit 75ca0929df
4 changed files with 117 additions and 108 deletions

View File

@ -365,13 +365,13 @@ public final class Jobs extends JavaPlugin {
*/ */
public static ScheduleManager getScheduleManager() { public static ScheduleManager getScheduleManager() {
if (scheduleManager == null) if (scheduleManager == null)
scheduleManager = new ScheduleManager(getInstance()); scheduleManager = new ScheduleManager(getInstance());
return scheduleManager; return scheduleManager;
} }
public static NameTranslatorManager getNameTranslatorManager() { public static NameTranslatorManager getNameTranslatorManager() {
if (nameTranslatorManager == null) if (nameTranslatorManager == null)
nameTranslatorManager = new NameTranslatorManager(); nameTranslatorManager = new NameTranslatorManager();
return nameTranslatorManager; return nameTranslatorManager;
} }
@ -383,7 +383,7 @@ public final class Jobs extends JavaPlugin {
public static JobsCommands getCommandManager() { public static JobsCommands getCommandManager() {
if (cManager == null) if (cManager == null)
cManager = new JobsCommands(getInstance()); cManager = new JobsCommands(getInstance());
return cManager; return cManager;
} }
@ -410,8 +410,8 @@ public final class Jobs extends JavaPlugin {
* @return the sign manager * @return the sign manager
*/ */
public static SignUtil getSignUtil() { public static SignUtil getSignUtil() {
if (signManager == null) if (signManager == null)
signManager = new SignUtil(getInstance()); signManager = new SignUtil(getInstance());
return signManager; return signManager;
} }
@ -586,7 +586,8 @@ public final class Jobs extends JavaPlugin {
getPlayerManager().clearMaps(); getPlayerManager().clearMaps();
getPlayerManager().clearCache(); getPlayerManager().clearCache();
dao.saveExplore(); if (Jobs.getGeneralConfigManager().ExploreSaveIntoDatabase)
dao.saveExplore();
// Do we really need to convert Block protection? // Do we really need to convert Block protection?
// Jobs.getJobsDAO().saveBlockProtection(); // Jobs.getJobsDAO().saveBlockProtection();
} catch (SQLException e) { } catch (SQLException e) {
@ -890,9 +891,8 @@ public final class Jobs extends JavaPlugin {
CMIMessages.consoleMessage(prefix); CMIMessages.consoleMessage(prefix);
HandlerList.unregisterAll(this); HandlerList.unregisterAll(this);
if (dao != null) { if (dao != null && Jobs.getGeneralConfigManager().ExploreSaveIntoDatabase)
dao.saveExplore(); dao.saveExplore();
}
blockOwnerShipsMaterial.values().forEach(BlockOwnerShip::save); blockOwnerShipsMaterial.values().forEach(BlockOwnerShip::save);
ToggleBarHandling.save(); ToggleBarHandling.save();

View File

@ -26,140 +26,140 @@ public class ExploreManager {
private int playerAmount = 1; private int playerAmount = 1;
public int getPlayerAmount() { public int getPlayerAmount() {
return playerAmount; return playerAmount;
} }
public void setPlayerAmount(int amount) { public void setPlayerAmount(int amount) {
if (playerAmount < amount) if (playerAmount < amount)
playerAmount = amount; playerAmount = amount;
} }
public boolean isExploreEnabled() { public boolean isExploreEnabled() {
return exploreEnabled; return exploreEnabled;
} }
public void setExploreEnabled() { public void setExploreEnabled() {
if (!exploreEnabled) { exploreEnabled = true;
exploreEnabled = true;
}
} }
public void load() { public void load() {
if (!exploreEnabled) if (!exploreEnabled)
return; return;
CMIMessages.consoleMessage("&eLoading explorer data"); if (Jobs.getGeneralConfigManager().ExploreSaveIntoDatabase) {
Long time = System.currentTimeMillis(); CMIMessages.consoleMessage("&eLoading explorer data");
Jobs.getJobsDAO().loadExplore(); Long time = System.currentTimeMillis();
int size = getSize(); Jobs.getJobsDAO().loadExplore();
CMIMessages.consoleMessage("&eLoaded explorer data" + (size != 0 ? " (&6" + size + "&e)" : " ") + " in " + (System.currentTimeMillis() - time) + " ms"); int size = getSize();
CMIMessages.consoleMessage("&eLoaded explorer data" + (size != 0 ? " (&6" + size + "&e)" : " ") + " in " + (System.currentTimeMillis() - time) + " ms");
}
} }
public Map<String, Map<String, ExploreRegion>> getWorlds() { public Map<String, Map<String, ExploreRegion>> getWorlds() {
return worlds; return worlds;
} }
public int getSize() { public int getSize() {
int i = 0; int i = 0;
for (Map<String, ExploreRegion> one : worlds.values()) { for (Map<String, ExploreRegion> one : worlds.values()) {
for (Entry<String, ExploreRegion> chunks : one.entrySet()) { for (Entry<String, ExploreRegion> chunks : one.entrySet()) {
i += chunks.getValue().getChunks().size(); i += chunks.getValue().getChunks().size();
} }
} }
return i; return i;
} }
public ExploreRespond chunkRespond(Player player, Chunk chunk) { public ExploreRespond chunkRespond(Player player, Chunk chunk) {
return chunkRespond(Jobs.getPlayerManager().getJobsPlayer(player).getUserId(), chunk.getWorld().getName(), chunk.getX(), chunk.getZ()); return chunkRespond(Jobs.getPlayerManager().getJobsPlayer(player).getUserId(), chunk.getWorld().getName(), chunk.getX(), chunk.getZ());
} }
public ExploreRespond chunkRespond(int playerId, Chunk chunk) { public ExploreRespond chunkRespond(int playerId, Chunk chunk) {
return chunkRespond(playerId, chunk.getWorld().getName(), chunk.getX(), chunk.getZ()); return chunkRespond(playerId, chunk.getWorld().getName(), chunk.getX(), chunk.getZ());
} }
public ExploreRespond chunkRespond(int playerId, String world, int x, int z) { public ExploreRespond chunkRespond(int playerId, String world, int x, int z) {
Map<String, ExploreRegion> eRegions = worlds.getOrDefault(world, new HashMap<String, ExploreRegion>()); Map<String, ExploreRegion> eRegions = worlds.getOrDefault(world, new HashMap<String, ExploreRegion>());
int RegionX = (int) Math.floor(x / 32D); int RegionX = (int) Math.floor(x / 32D);
int RegionZ = (int) Math.floor(z / 32D); int RegionZ = (int) Math.floor(z / 32D);
ExploreRegion region = eRegions.get(RegionX + ":" + RegionZ); ExploreRegion region = eRegions.get(RegionX + ":" + RegionZ);
if (region == null) { if (region == null) {
region = new ExploreRegion(RegionX, RegionZ); region = new ExploreRegion(RegionX, RegionZ);
} }
int chunkRelativeX = (RegionX * 32) - x; int chunkRelativeX = (RegionX * 32) - x;
int chunkRelativeZ = (RegionZ * 32) - z; int chunkRelativeZ = (RegionZ * 32) - z;
ExploreChunk chunk = region.getChunk(chunkRelativeX, chunkRelativeZ); ExploreChunk chunk = region.getChunk(chunkRelativeX, chunkRelativeZ);
if (chunk == null) { if (chunk == null) {
chunk = new ExploreChunk(); chunk = new ExploreChunk();
region.addChunk(chunkRelativeX, chunkRelativeZ, chunk); region.addChunk(chunkRelativeX, chunkRelativeZ, chunk);
} }
eRegions.put(RegionX + ":" + RegionZ, region); eRegions.put(RegionX + ":" + RegionZ, region);
worlds.put(world, eRegions); worlds.put(world, eRegions);
return chunk.addPlayer(playerId); return chunk.addPlayer(playerId);
} }
public void load(ResultSet res) { public void load(ResultSet res) {
try { try {
String worldName = res.getString(ExploreDataTableFields.worldname.getCollumn()); String worldName = res.getString(ExploreDataTableFields.worldname.getCollumn());
JobsWorld jobsWorld = Util.getJobsWorld(worldName); JobsWorld jobsWorld = Util.getJobsWorld(worldName);
if (jobsWorld == null) if (jobsWorld == null)
jobsWorld = Util.getJobsWorld(res.getInt(ExploreDataTableFields.worldid.getCollumn())); jobsWorld = Util.getJobsWorld(res.getInt(ExploreDataTableFields.worldid.getCollumn()));
if (jobsWorld == null) if (jobsWorld == null)
return; return;
int x = res.getInt(ExploreDataTableFields.chunkX.getCollumn()); int x = res.getInt(ExploreDataTableFields.chunkX.getCollumn());
int z = res.getInt(ExploreDataTableFields.chunkZ.getCollumn()); int z = res.getInt(ExploreDataTableFields.chunkZ.getCollumn());
String names = res.getString(ExploreDataTableFields.playerNames.getCollumn()); String names = res.getString(ExploreDataTableFields.playerNames.getCollumn());
int id = res.getInt("id"); int id = res.getInt("id");
Map<String, ExploreRegion> eRegions = worlds.getOrDefault(jobsWorld.getName(), new HashMap<String, ExploreRegion>()); Map<String, ExploreRegion> eRegions = worlds.getOrDefault(jobsWorld.getName(), new HashMap<String, ExploreRegion>());
int RegionX = (int) Math.floor(x / 32D); int RegionX = (int) Math.floor(x / 32D);
int RegionZ = (int) Math.floor(z / 32D); int RegionZ = (int) Math.floor(z / 32D);
int chunkRelativeX = RegionX * 32 - x; int chunkRelativeX = RegionX * 32 - x;
int chunkRelativeZ = RegionZ * 32 - z; int chunkRelativeZ = RegionZ * 32 - z;
ExploreRegion region = eRegions.get(RegionX + ":" + RegionZ); ExploreRegion region = eRegions.get(RegionX + ":" + RegionZ);
if (region == null) { if (region == null) {
region = new ExploreRegion(RegionX, RegionZ); region = new ExploreRegion(RegionX, RegionZ);
} }
ExploreChunk chunk = region.getChunk(chunkRelativeX, chunkRelativeZ); ExploreChunk chunk = region.getChunk(chunkRelativeX, chunkRelativeZ);
if (chunk == null) { if (chunk == null) {
chunk = new ExploreChunk(); chunk = new ExploreChunk();
region.addChunk(chunkRelativeX, chunkRelativeZ, chunk); region.addChunk(chunkRelativeX, chunkRelativeZ, chunk);
} }
chunk.deserializeNames(names); chunk.deserializeNames(names);
chunk.setDbId(id); chunk.setDbId(id);
eRegions.put(RegionX + ":" + RegionZ, region); eRegions.put(RegionX + ":" + RegionZ, region);
worlds.put(jobsWorld.getName(), eRegions); worlds.put(jobsWorld.getName(), eRegions);
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
public void resetRegion(String worldname) { public void resetRegion(String worldname) {
CMIMessages.consoleMessage("&eReseting explorer data. World: " + worldname); CMIMessages.consoleMessage("&eReseting explorer data. World: " + worldname);
Map<String, Map<String, ExploreRegion>> worlds = getWorlds(); Map<String, Map<String, ExploreRegion>> worlds = getWorlds();
worlds.put(worldname, new HashMap<String, ExploreRegion>()); worlds.put(worldname, new HashMap<String, ExploreRegion>());
boolean r = Jobs.getJobsDAO().deleteExploredWorld(worldname); boolean r = Jobs.getJobsDAO().deleteExploredWorld(worldname);
if (!r) { if (!r) {
CMIMessages.consoleMessage("&eFailed in DAO."); CMIMessages.consoleMessage("&eFailed in DAO.");
return; return;
} }
CMIMessages.consoleMessage("&eCompleted to reset explorer data."); CMIMessages.consoleMessage("&eCompleted to reset explorer data.");
} }
} }

View File

@ -107,7 +107,7 @@ public class GeneralConfigManager {
DisableJoiningJobThroughGui, FireworkLevelupUse, UseRandom, UsePerPermissionForLeaving, DisableJoiningJobThroughGui, FireworkLevelupUse, UseRandom, UsePerPermissionForLeaving,
EnableConfirmation, jobsInfoOpensBrowse, MonsterDamageUse, useMaxPaymentCurve, blockOwnershipTakeOver, EnableConfirmation, jobsInfoOpensBrowse, MonsterDamageUse, useMaxPaymentCurve, blockOwnershipTakeOver,
hideJobsInfoWithoutPermission, UseTaxes, TransferToServerAccount, TakeFromPlayersPayment, AutoJobJoinUse, AllowDelevel, RomanNumbers, hideJobsInfoWithoutPermission, UseTaxes, TransferToServerAccount, TakeFromPlayersPayment, AutoJobJoinUse, AllowDelevel, RomanNumbers,
BossBarEnabled = false, BossBarShowOnEachAction = false, BossBarsMessageByDefault = false, ExploreCompact, DBCleaningJobsUse, DBCleaningUsersUse, BossBarEnabled = false, BossBarShowOnEachAction = false, BossBarsMessageByDefault = false, ExploreCompact, ExploreSaveIntoDatabase = false, DBCleaningJobsUse, DBCleaningUsersUse,
DisabledWorldsUse, UseAsWhiteListWorldList, MythicMobsEnabled, DisabledWorldsUse, UseAsWhiteListWorldList, MythicMobsEnabled,
LoggingUse, payForCombiningItems, BlastFurnacesReassign = false, SmokerReassign = false, payForStackedEntities, payForAbove = false, LoggingUse, payForCombiningItems, BlastFurnacesReassign = false, SmokerReassign = false, payForStackedEntities, payForAbove = false,
payForEachVTradeItem, allowEnchantingBoostedItems, bossBarAsync = false, preventShopItemEnchanting; payForEachVTradeItem, allowEnchantingBoostedItems, bossBarAsync = false, preventShopItemEnchanting;
@ -427,6 +427,11 @@ public class GeneralConfigManager {
"By setting this to true when there is max amount of players explored a chunk then it will be marked as fully explored and exact players who explored it will not be saved to save some memory"); "By setting this to true when there is max amount of players explored a chunk then it will be marked as fully explored and exact players who explored it will not be saved to save some memory");
ExploreCompact = c.get("Optimizations.Explore.Compact", true); ExploreCompact = c.get("Optimizations.Explore.Compact", true);
c.addComment("Optimizations.Explore.SaveIntoDatabase",
"While enabled explored chunk data will be saved into database and will persist over server restarts",
"While disabled expored chunk data resets on every server startup which will freeup memory and speedup server startups and stop in some cases");
ExploreSaveIntoDatabase = c.get("Optimizations.Explore.SaveIntoDatabase", false);
c.addComment("Logging.Use", "With this set to true all players jobs actions will be logged to database for easy to see statistics", c.addComment("Logging.Use", "With this set to true all players jobs actions will be logged to database for easy to see statistics",
"This is still in development and in future it will expand"); "This is still in development and in future it will expand");
LoggingUse = c.get("Logging.Use", false); LoggingUse = c.get("Logging.Use", false);

View File

@ -2558,6 +2558,8 @@ public abstract class JobsDAO {
PreparedStatement prest2 = null; PreparedStatement prest2 = null;
try { try {
CMIMessages.consoleMessage("&e[Jobs] Preparing explorer data save.");
prest2 = conn.prepareStatement("INSERT INTO `" + DBTables.ExploreDataTable.getTableName() + "` (`" + ExploreDataTableFields.worldid.getCollumn() prest2 = conn.prepareStatement("INSERT INTO `" + DBTables.ExploreDataTable.getTableName() + "` (`" + ExploreDataTableFields.worldid.getCollumn()
+ "`, `" + ExploreDataTableFields.chunkX.getCollumn() + "`, `" + ExploreDataTableFields.chunkX.getCollumn()
+ "`, `" + ExploreDataTableFields.chunkZ.getCollumn() + "`, `" + ExploreDataTableFields.chunkZ.getCollumn()
@ -2570,25 +2572,27 @@ public abstract class JobsDAO {
Map<String, Map<String, ExploreRegion>> temp = new HashMap<>(Jobs.getExploreManager().getWorlds()); Map<String, Map<String, ExploreRegion>> temp = new HashMap<>(Jobs.getExploreManager().getWorlds());
for (Entry<String, Map<String, ExploreRegion>> worlds : temp.entrySet()) { for (Entry<String, Map<String, ExploreRegion>> worlds : temp.entrySet()) {
JobsWorld jobsWorld = Util.getJobsWorld(worlds.getKey());
int id = jobsWorld == null ? 0 : jobsWorld.getId();
if (id == 0)
continue;
for (Entry<String, ExploreRegion> region : worlds.getValue().entrySet()) { for (Entry<String, ExploreRegion> region : worlds.getValue().entrySet()) {
JobsWorld jobsWorld = Util.getJobsWorld(worlds.getKey()); for (Entry<Short, ExploreChunk> oneChunk : region.getValue().getChunks().entrySet()) {
ExploreChunk chunk = oneChunk.getValue();
if (chunk.getDbId() != -1)
continue;
int id = jobsWorld == null ? 0 : jobsWorld.getId(); prest2.setInt(1, id);
if (id != 0) prest2.setInt(2, region.getValue().getChunkGlobalX(oneChunk.getKey()));
for (Entry<Short, ExploreChunk> oneChunk : region.getValue().getChunks().entrySet()) { prest2.setInt(3, region.getValue().getChunkGlobalZ(oneChunk.getKey()));
ExploreChunk chunk = oneChunk.getValue(); prest2.setString(4, chunk.serializeNames());
if (chunk.getDbId() != -1) prest2.setString(5, jobsWorld != null ? jobsWorld.getName() : "");
continue; prest2.addBatch();
prest2.setInt(1, id); i++;
prest2.setInt(2, region.getValue().getChunkGlobalX(oneChunk.getKey())); }
prest2.setInt(3, region.getValue().getChunkGlobalZ(oneChunk.getKey()));
prest2.setString(4, chunk.serializeNames());
prest2.setString(5, jobsWorld != null ? jobsWorld.getName() : "");
prest2.addBatch();
i++;
}
} }
} }
prest2.executeBatch(); prest2.executeBatch();