1
0
mirror of https://github.com/Zrips/Jobs.git synced 2025-01-02 14:29:07 +01:00

Lets deal with relative chunk coordinates

Changed base save mechanic for explorer, mainly Long type got converted
into Short which decreases memory usage.
Fixing general issue relating to incorrect chunk detection for explorer
job
This commit is contained in:
Zrips 2022-05-25 17:12:09 +03:00
parent b69a4f1397
commit 0fab191980
7 changed files with 73 additions and 33 deletions

View File

@ -1127,7 +1127,6 @@ public class PlayerManager {
boost.add(BoostOf.Dynamic, new BoostMultiplier().add(prog.getBonus())); boost.add(BoostOf.Dynamic, new BoostMultiplier().add(prog.getBonus()));
if (pl != null) { if (pl != null) {
CMIDebug.d(getItemBoostNBT(pl, prog).get(CurrencyType.MONEY));
boost.add(BoostOf.Item, getItemBoostNBT(pl, prog)); boost.add(BoostOf.Item, getItemBoostNBT(pl, prog));
} }

View File

@ -31,14 +31,14 @@ public class explored implements Cmd {
ExploreRegion region = exploreRegion.get(RegionX + ":" + RegionZ); ExploreRegion region = exploreRegion.get(RegionX + ":" + RegionZ);
if (region == null) { if (region == null) {
player.sendMessage(Jobs.getLanguage().getMessage("command.explored.error.noexplore")); player.sendMessage(Jobs.getLanguage().getMessage("command.explored.error.noexplore"));
return false; return true;
} }
ExploreChunk chunk = region.getChunk(player.getLocation().getChunk()); ExploreChunk chunk = region.getChunk(player.getLocation().getChunk());
if (chunk == null) { if (chunk == null) {
player.sendMessage(Jobs.getLanguage().getMessage("command.explored.error.noexplore")); player.sendMessage(Jobs.getLanguage().getMessage("command.explored.error.noexplore"));
return false; return true;
} }
if (Jobs.getGCManager().ExploreCompact && chunk.isFullyExplored()) { if (Jobs.getGCManager().ExploreCompact && chunk.isFullyExplored()) {
@ -51,7 +51,7 @@ public class explored implements Cmd {
for (int i = 0; i < players.size(); i++) { for (int i = 0; i < players.size(); i++) {
PlayerInfo ji = Jobs.getPlayerManager().getPlayerInfo(players.get(i)); PlayerInfo ji = Jobs.getPlayerManager().getPlayerInfo(players.get(i));
if (ji != null) if (ji != null)
player.sendMessage(Jobs.getLanguage().getMessage("command.explored.list", "%place%", i, "%playername%", ji.getName())); player.sendMessage(Jobs.getLanguage().getMessage("command.explored.list", "%place%", i + 1, "%playername%", ji.getName()));
} }
player.sendMessage(Jobs.getLanguage().getMessage("general.info.separator")); player.sendMessage(Jobs.getLanguage().getMessage("general.info.separator"));

View File

@ -17,6 +17,8 @@ import com.gamingmesh.jobs.container.JobsWorld;
import com.gamingmesh.jobs.dao.JobsDAO.ExploreDataTableFields; import com.gamingmesh.jobs.dao.JobsDAO.ExploreDataTableFields;
import com.gamingmesh.jobs.stuff.Util; import com.gamingmesh.jobs.stuff.Util;
import net.Zrips.CMILib.Logs.CMIDebug;
public class ExploreManager { public class ExploreManager {
private final Map<String, Map<String, ExploreRegion>> worlds = new HashMap<>(); private final Map<String, Map<String, ExploreRegion>> worlds = new HashMap<>();
@ -85,10 +87,14 @@ public class ExploreManager {
if (region == null) { if (region == null) {
region = new ExploreRegion(RegionX, RegionZ); region = new ExploreRegion(RegionX, RegionZ);
} }
ExploreChunk chunk = region.getChunk(x, z);
int chunkRelativeX = (RegionX * 32) - x;
int chunkRelativeZ = (RegionZ * 32) - z;
ExploreChunk chunk = region.getChunk(chunkRelativeX, chunkRelativeZ);
if (chunk == null) { if (chunk == null) {
chunk = new ExploreChunk(); chunk = new ExploreChunk();
region.addChunk(x, z, chunk); region.addChunk(chunkRelativeX, chunkRelativeZ, chunk);
} }
eRegions.put(RegionX + ":" + RegionZ, region); eRegions.put(RegionX + ":" + RegionZ, region);
@ -119,14 +125,17 @@ public class ExploreManager {
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 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(x, z); ExploreChunk chunk = region.getChunk(chunkRelativeX, chunkRelativeZ);
if (chunk == null) { if (chunk == null) {
chunk = new ExploreChunk(); chunk = new ExploreChunk();
region.addChunk(x, z, chunk); region.addChunk(chunkRelativeX, chunkRelativeZ, chunk);
} }
chunk.deserializeNames(names); chunk.deserializeNames(names);
chunk.setDbId(id); chunk.setDbId(id);

View File

@ -5,6 +5,8 @@ import java.util.List;
import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.Jobs;
import net.Zrips.CMILib.Logs.CMIDebug;
public class ExploreChunk { public class ExploreChunk {
private List<Integer> playerIds = new ArrayList<>(); private List<Integer> playerIds = new ArrayList<>();
@ -31,7 +33,7 @@ public class ExploreChunk {
} }
List<Integer> players = getPlayers(); List<Integer> players = getPlayers();
return new ExploreRespond(newChunkForPlayer ? players.size() : players.size() + 1, newChunkForPlayer); return new ExploreRespond(newChunkForPlayer ? players.size() : players.size() + 1, newChunkForPlayer);
} }

View File

@ -7,49 +7,79 @@ import org.bukkit.Chunk;
public class ExploreRegion { public class ExploreRegion {
int x; private int x;
int z; private int z;
private final Map<Long, ExploreChunk> chunks = new HashMap<>(); private final Map<Short, ExploreChunk> chunks = new HashMap<>();
public ExploreRegion(int x, int z) { public ExploreRegion(int x, int z) {
this.x = x; this.x = x;
this.z = z; this.z = z;
} }
public void addChunk(int x, int z, ExploreChunk chunk) { public void addChunk(int relativeX, int relativeZ, ExploreChunk chunk) {
chunks.put(getPlace(x, z), chunk); chunks.put(getPlace(relativeX, relativeZ), chunk);
} }
public Map<Long, ExploreChunk> getChunks() { public Map<Short, ExploreChunk> getChunks() {
return chunks; return chunks;
} }
public ExploreChunk getChunk(int x, int z) { public ExploreChunk getChunk(int relativeX, int relativeZ) {
return getChunk(getPlace(x, z)); return getChunk(getPlace(relativeX, relativeZ));
} }
public ExploreChunk getChunk(Chunk chunk) { public ExploreChunk getChunk(Chunk chunk) {
return getChunk(getPlace(chunk)); return getChunk(getPlace(chunk));
} }
public ExploreChunk getChunk(long place) { public ExploreChunk getChunk(long place) {
return chunks.get(place); return chunks.get((short) place);
} }
private static long getPlace(Chunk chunk) { public ExploreChunk getChunk(Short place) {
return getPlace(chunk.getX(), chunk.getZ()); return chunks.get(place);
} }
private static long getPlace(int x, int z) { private long getPlace(Chunk chunk) {
return (((long) x) << 32) | (z & 0xffffffff); return getPlace((x * 32) - chunk.getX(), (z * 32) - chunk.getZ());
} }
private static short getPlace(int relativeX, int relativeZ) {
return (short) (relativeX * 32 + relativeZ);
}
@Deprecated
public int getChunkX(long place) { public int getChunkX(long place) {
return (int)(place >> 32); return (int) (place / 32);
} }
public int getChunkRelativeX(short place) {
return place / 32;
}
public int getChunkGlobalX(short place) {
return (getX() * 32) - getChunkRelativeX(place);
}
@Deprecated
public int getChunkZ(long place) { public int getChunkZ(long place) {
return (int) place; return (int) place % 32;
}
public int getChunkRelativeZ(short place) {
return place % 32;
}
public int getChunkGlobalZ(short place) {
return (getZ() * 32) - getChunkRelativeZ(place);
}
public int getX() {
return x;
}
public int getZ() {
return z;
} }
} }

View File

@ -2484,14 +2484,14 @@ public abstract class JobsDAO {
int id = jobsWorld == null ? 0 : jobsWorld.getId(); int id = jobsWorld == null ? 0 : jobsWorld.getId();
if (id != 0) if (id != 0)
for (Entry<Long, ExploreChunk> oneChunk : region.getValue().getChunks().entrySet()) { for (Entry<Short, ExploreChunk> oneChunk : region.getValue().getChunks().entrySet()) {
ExploreChunk chunk = oneChunk.getValue(); ExploreChunk chunk = oneChunk.getValue();
if (chunk.getDbId() != -1) if (chunk.getDbId() != -1)
continue; continue;
prest2.setInt(1, id); prest2.setInt(1, id);
prest2.setInt(2, region.getValue().getChunkX(oneChunk.getKey())); prest2.setInt(2, region.getValue().getChunkGlobalX(oneChunk.getKey()));
prest2.setInt(3, region.getValue().getChunkZ(oneChunk.getKey())); prest2.setInt(3, region.getValue().getChunkGlobalZ(oneChunk.getKey()));
prest2.setString(4, chunk.serializeNames()); prest2.setString(4, chunk.serializeNames());
prest2.setString(5, jobsWorld != null ? jobsWorld.getName() : ""); prest2.setString(5, jobsWorld != null ? jobsWorld.getName() : "");
prest2.addBatch(); prest2.addBatch();
i++; i++;

View File

@ -129,6 +129,7 @@ import net.Zrips.CMILib.Entities.CMIEntityType;
import net.Zrips.CMILib.Items.CMIItemStack; import net.Zrips.CMILib.Items.CMIItemStack;
import net.Zrips.CMILib.Items.CMIMaterial; import net.Zrips.CMILib.Items.CMIMaterial;
import net.Zrips.CMILib.Locale.LC; import net.Zrips.CMILib.Locale.LC;
import net.Zrips.CMILib.Logs.CMIDebug;
import net.Zrips.CMILib.Messages.CMIMessages; import net.Zrips.CMILib.Messages.CMIMessages;
import net.Zrips.CMILib.Version.Version; import net.Zrips.CMILib.Version.Version;
@ -1806,7 +1807,6 @@ public final class JobsPaymentListener implements Listener {
@EventHandler(ignoreCancelled = true) @EventHandler(ignoreCancelled = true)
public void onExplore(JobsChunkChangeEvent event) { public void onExplore(JobsChunkChangeEvent event) {
if (!Jobs.getExploreManager().isExploreEnabled()) if (!Jobs.getExploreManager().isExploreEnabled())
return; return;