diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/editjobs.java b/src/main/java/com/gamingmesh/jobs/commands/list/editjobs.java index 4fd9ccae..145284b5 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/editjobs.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/editjobs.java @@ -571,7 +571,7 @@ public class editjobs implements Cmd { break; } Jobs.getExplore().setExploreEnabled(); - Jobs.getExplore().setPlayerAmount(amount + 1); + Jobs.getExplore().setPlayerAmount(amount); } else if (actionT == ActionType.CRAFT && myKey.startsWith("!")) type = myKey.substring(1, myKey.length()); diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/editquests.java b/src/main/java/com/gamingmesh/jobs/commands/list/editquests.java index c180dbfd..441548b7 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/editquests.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/editquests.java @@ -525,7 +525,7 @@ public class editquests implements Cmd { } Jobs.getExplore().setExploreEnabled(); - Jobs.getExplore().setPlayerAmount(a + 1); + Jobs.getExplore().setPlayerAmount(a); } else if (actionT == ActionType.CRAFT && myKey.startsWith("!")) type = myKey.substring(1, myKey.length()); diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/explored.java b/src/main/java/com/gamingmesh/jobs/commands/list/explored.java index 5b60f530..bfd277b3 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/explored.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/explored.java @@ -11,6 +11,7 @@ import com.gamingmesh.jobs.commands.Cmd; import com.gamingmesh.jobs.commands.JobCommand; import com.gamingmesh.jobs.container.ExploreChunk; import com.gamingmesh.jobs.container.ExploreRegion; +import com.gamingmesh.jobs.container.PlayerInfo; public class explored implements Cmd { @@ -40,11 +41,17 @@ public class explored implements Cmd { sender.sendMessage(Jobs.getLanguage().getMessage("command.explored.error.noexplore")); return false; } + if (chunk.isFullyExplored() && Jobs.getGCManager().ExploreCompact) { + sender.sendMessage(Jobs.getLanguage().getMessage("command.explored.fullExplore")); + return true; + } int i = 0; - for (String one : chunk.getPlayers()) { + for (Integer one : chunk.getPlayers()) { i++; - sender.sendMessage(Jobs.getLanguage().getMessage("command.explored.list", "%place%", i, "%playername%", one)); + PlayerInfo ji = Jobs.getPlayerManager().getPlayerInfo(one); + if (ji != null) + sender.sendMessage(Jobs.getLanguage().getMessage("command.explored.list", "%place%", i, "%playername%", ji.getName())); } sender.sendMessage(Jobs.getLanguage().getMessage("general.info.separator")); diff --git a/src/main/java/com/gamingmesh/jobs/config/ConfigManager.java b/src/main/java/com/gamingmesh/jobs/config/ConfigManager.java index 89d00b4c..a1e2c2d6 100644 --- a/src/main/java/com/gamingmesh/jobs/config/ConfigManager.java +++ b/src/main/java/com/gamingmesh/jobs/config/ConfigManager.java @@ -1144,7 +1144,7 @@ public class ConfigManager { continue; } Jobs.getExplore().setExploreEnabled(); - Jobs.getExplore().setPlayerAmount(amount + 1); + Jobs.getExplore().setPlayerAmount(amount); } else if (actionType == ActionType.CRAFT && myKey.startsWith("!")) type = myKey.substring(1, myKey.length()); diff --git a/src/main/java/com/gamingmesh/jobs/config/ExploreManager.java b/src/main/java/com/gamingmesh/jobs/config/ExploreManager.java index 4711b22d..139eca7d 100644 --- a/src/main/java/com/gamingmesh/jobs/config/ExploreManager.java +++ b/src/main/java/com/gamingmesh/jobs/config/ExploreManager.java @@ -62,10 +62,14 @@ public class ExploreManager { } public ExploreRespond ChunkRespond(Player player, Chunk chunk) { - return ChunkRespond(player.getName(), chunk.getWorld().getName(), chunk.getX(), chunk.getZ()); + return ChunkRespond(Jobs.getPlayerManager().getJobsPlayer(player).getUserId(), chunk.getWorld().getName(), chunk.getX(), chunk.getZ()); } - public ExploreRespond ChunkRespond(String player, String world, int x, int z) { + public ExploreRespond ChunkRespond(int playerId, Chunk chunk) { + return ChunkRespond(playerId, chunk.getWorld().getName(), chunk.getX(), chunk.getZ()); + } + + public ExploreRespond ChunkRespond(int playerId, String world, int x, int z) { ExploreRegion eRegions = worlds.get(world); if (eRegions == null) { @@ -80,7 +84,7 @@ public class ExploreManager { eRegions.addChunk(chunk); worlds.put(world, eRegions); - return chunk.addPlayer(player); + return chunk.addPlayer(playerId); } public void load(ResultSet res) { diff --git a/src/main/java/com/gamingmesh/jobs/config/GeneralConfigManager.java b/src/main/java/com/gamingmesh/jobs/config/GeneralConfigManager.java index 95beaf67..3ec2e2de 100644 --- a/src/main/java/com/gamingmesh/jobs/config/GeneralConfigManager.java +++ b/src/main/java/com/gamingmesh/jobs/config/GeneralConfigManager.java @@ -158,6 +158,8 @@ public class GeneralConfigManager { public Parser DynamicPaymentEquation; + public boolean ExploreCompact; + public boolean DisabledWorldsUse; public List DisabledWorldsList = new ArrayList<>(); @@ -508,6 +510,10 @@ public class GeneralConfigManager { DisabledWorldsUse = c.get("Optimizations.DisabledWorlds.Use", false); DisabledWorldsList = c.get("Optimizations.DisabledWorlds.List", Arrays.asList(Bukkit.getWorlds().get(0).getName())); + c.addComment("Optimizations.Explore.Compact", + "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); + // c.addComment("Optimizations.Purge.Use", "By setting this to true, Jobs plugin will clean data base on startup from all jobs with level 1 and at 0 exp"); // PurgeUse = c.get("Optimizations.Purge.Use", false); diff --git a/src/main/java/com/gamingmesh/jobs/config/LanguageManager.java b/src/main/java/com/gamingmesh/jobs/config/LanguageManager.java index cc0e6616..84057519 100644 --- a/src/main/java/com/gamingmesh/jobs/config/LanguageManager.java +++ b/src/main/java/com/gamingmesh/jobs/config/LanguageManager.java @@ -425,6 +425,7 @@ public class LanguageManager { c.get("command.explored.help.info", "Check who visited this chunk"); c.get("command.explored.error.noexplore", "No one visited this chunk"); + c.get("command.explored.fullExplore", "&aThis chunk is fully explored"); c.get("command.explored.list", "&e%place%. %playername%"); c.get("command.browse.help.info", "List the jobs available to you."); diff --git a/src/main/java/com/gamingmesh/jobs/container/ExploreChunk.java b/src/main/java/com/gamingmesh/jobs/container/ExploreChunk.java index ebb18685..e34673ef 100644 --- a/src/main/java/com/gamingmesh/jobs/container/ExploreChunk.java +++ b/src/main/java/com/gamingmesh/jobs/container/ExploreChunk.java @@ -2,6 +2,7 @@ package com.gamingmesh.jobs.container; import java.util.Arrays; import java.util.HashSet; +import java.util.List; import java.util.Set; import com.gamingmesh.jobs.Jobs; @@ -10,14 +11,15 @@ public class ExploreChunk { private int x; private int z; - private Set playerNames = new HashSet<>(); + private Set playerIds = new HashSet<>(); + private boolean full = false; private Integer dbId = null; private boolean updated = false; - public ExploreChunk(String playerName, int x, int z) { + public ExploreChunk(int playerId, int x, int z) { this.x = x; this.z = z; - this.playerNames.add(playerName); + this.playerIds.add(playerId); } public ExploreChunk(int x, int z) { @@ -25,24 +27,38 @@ public class ExploreChunk { this.z = z; } - public ExploreRespond addPlayer(String playerName) { + public ExploreRespond addPlayer(int playerId) { + if (full) { + return new ExploreRespond(Jobs.getExplore().getPlayerAmount() + 1, false); + } boolean newChunkForPlayer = false; - if (!playerNames.contains(playerName)) { - if (playerNames.size() < Jobs.getExplore().getPlayerAmount()) { - playerNames.add(playerName); + if (!playerIds.contains(playerId)) { + if (playerIds.size() < Jobs.getExplore().getPlayerAmount()) { + playerIds.add(playerId); updated = true; } newChunkForPlayer = true; } - return new ExploreRespond(newChunkForPlayer ? playerNames.size() : playerNames.size() + 1, newChunkForPlayer); + + if (playerIds.size() >= Jobs.getExplore().getPlayerAmount()) { + this.full = true; + if (Jobs.getGCManager().ExploreCompact) + playerIds = null; + } + + return new ExploreRespond(newChunkForPlayer ? getPlayers().size() : getPlayers().size() + 1, newChunkForPlayer); } - public boolean isAlreadyVisited(String playerName) { - return playerNames.contains(playerName); + public boolean isAlreadyVisited(int playerId) { + if (full) + return true; + return playerIds.contains(playerId); } public int getCount() { - return playerNames.size(); + if (full) + return Jobs.getExplore().getPlayerAmount(); + return playerIds.size(); } public int getX() { @@ -53,13 +69,15 @@ public class ExploreChunk { return z; } - public Set getPlayers() { - return playerNames; + public Set getPlayers() { + return playerIds == null ? new HashSet<>() : playerIds; } public String serializeNames() { String s = ""; - for (String one : this.playerNames) { + if (playerIds == null) + return ""; + for (Integer one : this.playerIds) { if (!s.isEmpty()) s += ";"; s += one; @@ -68,10 +86,35 @@ public class ExploreChunk { } public void deserializeNames(String names) { - if (names.contains(";")) - playerNames.addAll(Arrays.asList(names.split(";"))); - else - playerNames.add(names); + if (names.isEmpty()) { + this.full = true; + playerIds = null; + return; + } + + List split = Arrays.asList(names.split(";")); + for (String one : split) { + try { + int id = Integer.parseInt(one); + PlayerInfo info = Jobs.getPlayerManager().getPlayerInfo(id); + if (info != null) + playerIds.add(id); + } catch (Exception | Error e) { + updated = true; + JobsPlayer jp = Jobs.getPlayerManager().getJobsPlayer(one); + if (jp != null) + playerIds.add(jp.getUserId()); + } + } + + if (playerIds.size() >= Jobs.getExplore().getPlayerAmount()) { + this.full = true; + if (Jobs.getGCManager().ExploreCompact) { + playerIds = null; + if (!names.isEmpty()) + updated = true; + } + } } public Integer getDbId() { @@ -89,4 +132,8 @@ public class ExploreChunk { public void setUpdated(boolean updated) { this.updated = updated; } + + public boolean isFullyExplored() { + return full; + } } diff --git a/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java b/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java index ad060196..33c604c2 100644 --- a/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java +++ b/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java @@ -26,6 +26,7 @@ import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.actions.*; import com.gamingmesh.jobs.api.JobsChunkChangeEvent; import com.gamingmesh.jobs.container.*; +import com.gamingmesh.jobs.stuff.Debug; import com.gamingmesh.jobs.stuff.FurnaceBrewingHandling; import com.gamingmesh.jobs.stuff.FurnaceBrewingHandling.ownershipFeedback; import com.google.common.base.Objects; @@ -938,10 +939,10 @@ public class JobsPaymentListener implements Listener { try { if (!plugin.isEnabled()) return; - + if (!Jobs.getGCManager().PreventHopperFillUps) return; - + String type = event.getDestination().getType().toString(); if (!type.equalsIgnoreCase("FURNACE") && !type.equalsIgnoreCase("SMOKER") && !type.equalsIgnoreCase("BLAST_FURNACE")) return; @@ -963,7 +964,7 @@ public class JobsPaymentListener implements Listener { block = ((org.bukkit.block.BlastFurnace) event.getDestination().getHolder()).getBlock(); break; } - + if (block == null) return; @@ -1743,7 +1744,7 @@ public class JobsPaymentListener implements Listener { && !Jobs.getGCManager().payExploringWhenGliding && player.isGliding()) return; - ExploreRespond respond = Jobs.getExplore().ChunkRespond(player, event.getNewChunk()); + ExploreRespond respond = Jobs.getExplore().ChunkRespond(Jobs.getPlayerManager().getJobsPlayer(player).getUserId(), event.getNewChunk()); if (!respond.isNewChunk()) return;