diff --git a/src/main/java/com/gamingmesh/jobs/container/ExploreRegion.java b/src/main/java/com/gamingmesh/jobs/container/ExploreRegion.java index 2e179229..a08c17b6 100644 --- a/src/main/java/com/gamingmesh/jobs/container/ExploreRegion.java +++ b/src/main/java/com/gamingmesh/jobs/container/ExploreRegion.java @@ -1,75 +1,55 @@ -package com.gamingmesh.jobs.container; - -import java.util.HashMap; -import java.util.Map; - -import org.bukkit.Chunk; - -public class ExploreRegion { - - int x; - int z; - - private final Map chunks = new HashMap<>(); - - public ExploreRegion(int x, int z) { - this.x = x; - this.z = z; - } - - public void addChunk(int x, int z, ExploreChunk chunk) { - chunks.put(getPlace(x, z), chunk); - } - - public Map getChunks() { - return chunks; - } - - public ExploreChunk getChunk(int x, int z) { - return getChunk(getPlace(x, z)); - } - - public ExploreChunk getChunk(Chunk chunk) { - return getChunk(getPlace(chunk)); - } - - public ExploreChunk getChunk(short place) { - return chunks.get(place); - } - - private static short getPlace(Chunk chunk) { - return getPlace(chunk.getX(), chunk.getZ()); - } - - private static short getPlace(int x, int z) { - return (short) ((x - ((x >> 5) * 32)) + ((z - ((z >> 5) * 32)) * 32)); - } - - public int getChunkX(short place) { - int endX = place % 32; - - if (x < 0) - endX = -endX; - - endX = x * 32 + endX; - - if (endX < 0) { - endX += 32; - } - - return endX; - } - - public int getChunkZ(short place) { - int endZ = (place - (place % 32)) / 32; - if (z < 0) - endZ = -endZ; - endZ = z * 32 + endZ; - - if (endZ < 0) { - endZ += 32; - } - - return endZ; - } -} +package com.gamingmesh.jobs.container; + +import java.util.HashMap; +import java.util.Map; + +import org.bukkit.Chunk; + +public class ExploreRegion { + + int x; + int z; + + private final Map chunks = new HashMap<>(); + + public ExploreRegion(int x, int z) { + this.x = x; + this.z = z; + } + + public void addChunk(int x, int z, ExploreChunk chunk) { + chunks.put(getPlace(x, z), chunk); + } + + public Map getChunks() { + return chunks; + } + + public ExploreChunk getChunk(int x, int z) { + return getChunk(getPlace(x, z)); + } + + public ExploreChunk getChunk(Chunk chunk) { + return getChunk(getPlace(chunk)); + } + + public ExploreChunk getChunk(long place) { + return chunks.get(place); + } + + private static long getPlace(Chunk chunk) { + return getPlace(chunk.getX(), chunk.getZ()); + } + + private static long getPlace(int x, int z) { + return (((long) x) << 32) | (z & 0xffffffff); + } + + public int getChunkX(long place) { + return (int)(place >> 32); + } + + public int getChunkZ(long place) { + return (int) place; + } +} diff --git a/src/main/java/com/gamingmesh/jobs/dao/JobsDAO.java b/src/main/java/com/gamingmesh/jobs/dao/JobsDAO.java index 45ffa0c5..4eab49ff 100644 --- a/src/main/java/com/gamingmesh/jobs/dao/JobsDAO.java +++ b/src/main/java/com/gamingmesh/jobs/dao/JobsDAO.java @@ -1541,7 +1541,7 @@ public abstract class JobsDAO { * Join a job (create player-job entry from storage) * @param player - player that wishes to join the job * @param job - job that the player wishes to join - * @throws SQLException + * @throws SQLException */ public List convertDatabase() throws SQLException { List list = new ArrayList<>(); @@ -2465,7 +2465,7 @@ public abstract class JobsDAO { int id = jobsWorld == null ? 0 : jobsWorld.getId(); if (id != 0) - for (Entry oneChunk : region.getValue().getChunks().entrySet()) { + for (Entry oneChunk : region.getValue().getChunks().entrySet()) { ExploreChunk chunk = oneChunk.getValue(); if (chunk.getDbId() != -1) continue; @@ -2598,7 +2598,7 @@ public abstract class JobsDAO { /** * Save player-job information * @param jobInfo - the information getting saved - * @return + * @return */ public List getLognameList(int fromtime, int untiltime) { JobsConnection conn = getConnection(); @@ -2630,7 +2630,7 @@ public abstract class JobsDAO { /** * Show top list * @param toplist - toplist by jobs name - * @return + * @return */ public List toplist(String jobsname) { return toplist(jobsname, 0); @@ -2639,7 +2639,7 @@ public abstract class JobsDAO { /** * Show top list * @param toplist - toplist by jobs name - * @return + * @return */ public List toplist(String jobsname, int limit) { List jobs = new ArrayList<>(); @@ -2790,4 +2790,4 @@ public abstract class JobsDAO { return DBTables.JobsTable.getTableName(); } -} \ No newline at end of file +}