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 1ad1e493..09452c1b 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/explored.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/explored.java @@ -1,5 +1,7 @@ package com.gamingmesh.jobs.commands.list; +import java.util.Map; + import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -17,14 +19,23 @@ public class explored implements Cmd { return false; Player player = (Player) sender; - ExploreRegion exploreRegion = Jobs.getExplore().getWorlds().get(player.getWorld().getName()); + Map exploreRegion = Jobs.getExplore().getWorlds().get(player.getWorld().getName()); if (exploreRegion == null) { player.sendMessage(Jobs.getLanguage().getMessage("command.explored.error.noexplore")); return true; } - ExploreChunk chunk = exploreRegion.getChunk(player.getLocation().getChunk()); + int RegionX = (int) Math.floor(player.getLocation().getChunk().getX() / 32D); + int RegionZ = (int) Math.floor(player.getLocation().getChunk().getZ() / 32D); + ExploreRegion region = exploreRegion.get(RegionX + ":" + RegionZ); + if (region == null) { + player.sendMessage(Jobs.getLanguage().getMessage("command.explored.error.noexplore")); + return false; + } + + ExploreChunk chunk = region.getChunk(player.getLocation().getChunk()); + if (chunk == null) { player.sendMessage(Jobs.getLanguage().getMessage("command.explored.error.noexplore")); return false; diff --git a/src/main/java/com/gamingmesh/jobs/config/ExploreManager.java b/src/main/java/com/gamingmesh/jobs/config/ExploreManager.java index 5ec9fc4f..b00ae6a2 100644 --- a/src/main/java/com/gamingmesh/jobs/config/ExploreManager.java +++ b/src/main/java/com/gamingmesh/jobs/config/ExploreManager.java @@ -4,6 +4,7 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.util.HashMap; import java.util.Map; +import java.util.Map.Entry; import org.bukkit.Chunk; import org.bukkit.entity.Player; @@ -18,7 +19,7 @@ import com.gamingmesh.jobs.stuff.Util; public class ExploreManager { - private final Map worlds = new HashMap<>(); + private final Map> worlds = new HashMap<>(); private boolean exploreEnabled = false; private int playerAmount = 1; @@ -52,14 +53,16 @@ public class ExploreManager { Jobs.consoleMsg("&e[Jobs] Loaded explorer data" + (size != 0 ? " (" + size + ")" : ".")); } - public Map getWorlds() { + public Map> getWorlds() { return worlds; } public int getSize() { int i = 0; - for (ExploreRegion one : worlds.values()) { - i += one.getChunks().size(); + for (Map one : worlds.values()) { + for (Entry chunks : one.entrySet()) { + i += chunks.getValue().getChunks().size(); + } } return i; } @@ -73,18 +76,23 @@ public class ExploreManager { } public ExploreRespond chunkRespond(int playerId, String world, int x, int z) { - ExploreRegion eRegions = worlds.get(world); - if (eRegions == null) { - int RegionX = (int) Math.floor(x / 32D); - int RegionZ = (int) Math.floor(z / 32D); - eRegions = new ExploreRegion(RegionX, RegionZ); + Map eRegions = worlds.getOrDefault(world, new HashMap()); + + int RegionX = (int) Math.floor(x / 32D); + int RegionZ = (int) Math.floor(z / 32D); + + ExploreRegion region = eRegions.get(RegionX + ":" + RegionZ); + if (region == null) { + region = new ExploreRegion(RegionX, RegionZ); + } + ExploreChunk chunk = region.getChunk(x, z); + if (chunk == null) { + chunk = new ExploreChunk(); + region.addChunk(x, z, chunk); } - ExploreChunk chunk = eRegions.getChunk(x, z); - if (chunk == null) - chunk = new ExploreChunk(); + eRegions.put(RegionX + ":" + RegionZ, region); - eRegions.addChunk(x, z, chunk); worlds.put(world, eRegions); return chunk.addPlayer(playerId); @@ -106,19 +114,24 @@ public class ExploreManager { String names = res.getString(ExploreDataTableFields.playerNames.getCollumn()); int id = res.getInt("id"); - ExploreRegion eRegions = worlds.get(jobsWorld.getName()); - if (eRegions == null) { - int RegionX = (int) Math.floor(x / 32D); - int RegionZ = (int) Math.floor(z / 32D); - eRegions = new ExploreRegion(RegionX, RegionZ); + Map eRegions = worlds.getOrDefault(jobsWorld.getName(), new HashMap()); + + int RegionX = (int) Math.floor(x / 32D); + int RegionZ = (int) Math.floor(z / 32D); + + ExploreRegion region = eRegions.get(RegionX + ":" + RegionZ); + if (region == null) { + region = new ExploreRegion(RegionX, RegionZ); } - ExploreChunk chunk = eRegions.getChunk(x, z); - if (chunk == null) + ExploreChunk chunk = region.getChunk(x, z); + if (chunk == null) { chunk = new ExploreChunk(); + region.addChunk(x, z, chunk); + } chunk.deserializeNames(names); chunk.setDbId(id); - eRegions.addChunk(x, z, chunk); + eRegions.put(RegionX + ":" + RegionZ, region); worlds.put(jobsWorld.getName(), eRegions); } catch (SQLException e) { diff --git a/src/main/java/com/gamingmesh/jobs/container/ExploreChunk.java b/src/main/java/com/gamingmesh/jobs/container/ExploreChunk.java index e096c5b2..62606aa3 100644 --- a/src/main/java/com/gamingmesh/jobs/container/ExploreChunk.java +++ b/src/main/java/com/gamingmesh/jobs/container/ExploreChunk.java @@ -5,6 +5,8 @@ import java.util.List; import com.gamingmesh.jobs.Jobs; +import net.Zrips.CMILib.Logs.CMIDebug; + public class ExploreChunk { private List playerIds = new ArrayList<>(); @@ -31,6 +33,7 @@ public class ExploreChunk { } List players = getPlayers(); + return new ExploreRespond(newChunkForPlayer ? players.size() : players.size() + 1, newChunkForPlayer); } diff --git a/src/main/java/com/gamingmesh/jobs/dao/JobsDAO.java b/src/main/java/com/gamingmesh/jobs/dao/JobsDAO.java index c1a63aa6..92d01eab 100644 --- a/src/main/java/com/gamingmesh/jobs/dao/JobsDAO.java +++ b/src/main/java/com/gamingmesh/jobs/dao/JobsDAO.java @@ -2397,25 +2397,27 @@ public abstract class JobsDAO { conn.setAutoCommit(false); int i = 0; - Map temp = new HashMap<>(Jobs.getExplore().getWorlds()); + Map> temp = new HashMap<>(Jobs.getExplore().getWorlds()); - for (Entry worlds : temp.entrySet()) { - JobsWorld jobsWorld = Util.getJobsWorld(worlds.getKey()); + for (Entry> worlds : temp.entrySet()) { + for (Entry region : worlds.getValue().entrySet()) { + JobsWorld jobsWorld = Util.getJobsWorld(worlds.getKey()); - int id = jobsWorld == null ? 0 : jobsWorld.getId(); - if (id != 0) - for (Entry oneChunk : worlds.getValue().getChunks().entrySet()) { - ExploreChunk chunk = oneChunk.getValue(); - if (chunk.getDbId() != -1) - continue; - prest2.setInt(1, id); - prest2.setInt(2, worlds.getValue().getChunkX(oneChunk.getKey())); - prest2.setInt(3, worlds.getValue().getChunkZ(oneChunk.getKey())); - prest2.setString(4, chunk.serializeNames()); - prest2.setString(5, jobsWorld != null ? jobsWorld.getName() : ""); - prest2.addBatch(); - i++; - } + int id = jobsWorld == null ? 0 : jobsWorld.getId(); + if (id != 0) + for (Entry oneChunk : region.getValue().getChunks().entrySet()) { + ExploreChunk chunk = oneChunk.getValue(); + if (chunk.getDbId() != -1) + continue; + prest2.setInt(1, id); + prest2.setInt(2, region.getValue().getChunkX(oneChunk.getKey())); + prest2.setInt(3, region.getValue().getChunkZ(oneChunk.getKey())); + prest2.setString(4, chunk.serializeNames()); + prest2.setString(5, jobsWorld != null ? jobsWorld.getName() : ""); + prest2.addBatch(); + i++; + } + } } prest2.executeBatch(); conn.commit(); @@ -2449,17 +2451,19 @@ public abstract class JobsDAO { int i = 0; - Map temp = new HashMap<>(Jobs.getExplore().getWorlds()); + Map> temp = new HashMap<>(Jobs.getExplore().getWorlds()); - for (ExploreRegion worlds : temp.values()) { - for (ExploreChunk oneChunk : worlds.getChunks().values()) { - if (oneChunk.getDbId() == -1 || !oneChunk.isUpdated()) - continue; + for (Entry> worlds : temp.entrySet()) { + for (Entry region : worlds.getValue().entrySet()) { + for (ExploreChunk oneChunk : region.getValue().getChunks().values()) { + if (oneChunk.getDbId() == -1 || !oneChunk.isUpdated()) + continue; - prest.setString(1, oneChunk.serializeNames()); - prest.setInt(2, oneChunk.getDbId()); - prest.addBatch(); - i++; + prest.setString(1, oneChunk.serializeNames()); + prest.setInt(2, oneChunk.getDbId()); + prest.addBatch(); + i++; + } } } prest.executeBatch(); diff --git a/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java b/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java index c6cc25d4..bb6f02e9 100644 --- a/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java +++ b/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java @@ -1725,6 +1725,7 @@ public final class JobsPaymentListener implements Listener { return; ExploreRespond respond = Jobs.getExplore().chunkRespond(jPlayer.getUserId(), event.getNewChunk()); + if (!respond.isNewChunk()) return;