mirror of
https://github.com/Zrips/Jobs.git
synced 2024-11-29 14:05:25 +01:00
Fixing explore job
This commit is contained in:
parent
6a073dd68c
commit
7822f9a194
@ -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<String, ExploreRegion> 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;
|
||||
|
@ -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<String, ExploreRegion> worlds = new HashMap<>();
|
||||
private final Map<String, Map<String, ExploreRegion>> 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<String, ExploreRegion> getWorlds() {
|
||||
public Map<String, Map<String, ExploreRegion>> getWorlds() {
|
||||
return worlds;
|
||||
}
|
||||
|
||||
public int getSize() {
|
||||
int i = 0;
|
||||
for (ExploreRegion one : worlds.values()) {
|
||||
i += one.getChunks().size();
|
||||
for (Map<String, ExploreRegion> one : worlds.values()) {
|
||||
for (Entry<String, ExploreRegion> 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<String, ExploreRegion> eRegions = worlds.getOrDefault(world, new HashMap<String, ExploreRegion>());
|
||||
|
||||
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<String, ExploreRegion> eRegions = worlds.getOrDefault(jobsWorld.getName(), new HashMap<String, ExploreRegion>());
|
||||
|
||||
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) {
|
||||
|
@ -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,6 +33,7 @@ public class ExploreChunk {
|
||||
}
|
||||
|
||||
List<Integer> players = getPlayers();
|
||||
|
||||
return new ExploreRespond(newChunkForPlayer ? players.size() : players.size() + 1, newChunkForPlayer);
|
||||
}
|
||||
|
||||
|
@ -2397,25 +2397,27 @@ public abstract class JobsDAO {
|
||||
conn.setAutoCommit(false);
|
||||
int i = 0;
|
||||
|
||||
Map<String, ExploreRegion> temp = new HashMap<>(Jobs.getExplore().getWorlds());
|
||||
Map<String, Map<String, ExploreRegion>> temp = new HashMap<>(Jobs.getExplore().getWorlds());
|
||||
|
||||
for (Entry<String, ExploreRegion> worlds : temp.entrySet()) {
|
||||
JobsWorld jobsWorld = Util.getJobsWorld(worlds.getKey());
|
||||
for (Entry<String, Map<String, ExploreRegion>> worlds : temp.entrySet()) {
|
||||
for (Entry<String, ExploreRegion> region : worlds.getValue().entrySet()) {
|
||||
JobsWorld jobsWorld = Util.getJobsWorld(worlds.getKey());
|
||||
|
||||
int id = jobsWorld == null ? 0 : jobsWorld.getId();
|
||||
if (id != 0)
|
||||
for (Entry<Short, ExploreChunk> 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<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.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<String, ExploreRegion> temp = new HashMap<>(Jobs.getExplore().getWorlds());
|
||||
Map<String, Map<String, ExploreRegion>> 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<String, Map<String, ExploreRegion>> worlds : temp.entrySet()) {
|
||||
for (Entry<String, ExploreRegion> 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();
|
||||
|
@ -1725,6 +1725,7 @@ public final class JobsPaymentListener implements Listener {
|
||||
return;
|
||||
|
||||
ExploreRespond respond = Jobs.getExplore().chunkRespond(jPlayer.getUserId(), event.getNewChunk());
|
||||
|
||||
if (!respond.isNewChunk())
|
||||
return;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user