1
0
mirror of https://github.com/Zrips/Jobs.git synced 2024-12-30 21:07:48 +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()));
if (pl != null) {
CMIDebug.d(getItemBoostNBT(pl, prog).get(CurrencyType.MONEY));
boost.add(BoostOf.Item, getItemBoostNBT(pl, prog));
}

View File

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

View File

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

View File

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

View File

@ -7,49 +7,79 @@ import org.bukkit.Chunk;
public class ExploreRegion {
int x;
int z;
private int x;
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) {
this.x = x;
this.z = z;
this.x = x;
this.z = z;
}
public void addChunk(int x, int z, ExploreChunk chunk) {
chunks.put(getPlace(x, z), chunk);
public void addChunk(int relativeX, int relativeZ, ExploreChunk chunk) {
chunks.put(getPlace(relativeX, relativeZ), chunk);
}
public Map<Long, ExploreChunk> getChunks() {
return chunks;
public Map<Short, ExploreChunk> getChunks() {
return chunks;
}
public ExploreChunk getChunk(int x, int z) {
return getChunk(getPlace(x, z));
public ExploreChunk getChunk(int relativeX, int relativeZ) {
return getChunk(getPlace(relativeX, relativeZ));
}
public ExploreChunk getChunk(Chunk chunk) {
return getChunk(getPlace(chunk));
return getChunk(getPlace(chunk));
}
public ExploreChunk getChunk(long place) {
return chunks.get(place);
return chunks.get((short) place);
}
private static long getPlace(Chunk chunk) {
return getPlace(chunk.getX(), chunk.getZ());
public ExploreChunk getChunk(Short place) {
return chunks.get(place);
}
private static long getPlace(int x, int z) {
return (((long) x) << 32) | (z & 0xffffffff);
private long getPlace(Chunk chunk) {
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) {
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) {
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();
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();
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.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++;

View File

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