2016-03-30 15:42:36 +02:00
|
|
|
package com.gamingmesh.jobs.config;
|
2016-01-09 13:58:33 +01:00
|
|
|
|
|
|
|
import java.util.HashMap;
|
2016-06-09 17:35:24 +02:00
|
|
|
|
2016-01-09 13:58:33 +01:00
|
|
|
import org.bukkit.Chunk;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
|
|
|
import com.gamingmesh.jobs.Jobs;
|
|
|
|
import com.gamingmesh.jobs.container.ExploreChunk;
|
|
|
|
import com.gamingmesh.jobs.container.ExploreRegion;
|
|
|
|
import com.gamingmesh.jobs.container.ExploreRespond;
|
|
|
|
|
2016-03-30 15:42:36 +02:00
|
|
|
public class ExploreManager {
|
2016-01-09 13:58:33 +01:00
|
|
|
|
|
|
|
private HashMap<String, ExploreRegion> worlds = new HashMap<String, ExploreRegion>();
|
|
|
|
private boolean exploreEnabled = false;
|
|
|
|
private int playerAmount = 1;
|
|
|
|
|
2016-03-30 15:42:36 +02:00
|
|
|
public ExploreManager() {
|
2016-01-09 13:58:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public int getPlayerAmount() {
|
|
|
|
return this.playerAmount;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setPlayerAmount(int amount) {
|
|
|
|
if (this.playerAmount < amount)
|
|
|
|
this.playerAmount = amount;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isExploreEnabled() {
|
|
|
|
return this.exploreEnabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setExploreEnabled() {
|
2016-06-09 17:35:24 +02:00
|
|
|
if (!exploreEnabled) {
|
|
|
|
this.exploreEnabled = true;
|
|
|
|
Jobs.getJobsDAO().loadExplore();
|
|
|
|
}
|
2016-01-09 13:58:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public HashMap<String, ExploreRegion> getWorlds() {
|
|
|
|
return worlds;
|
|
|
|
}
|
|
|
|
|
2016-06-27 13:19:54 +02:00
|
|
|
public ExploreRespond ChunkRespond(Player player, Chunk chunk, boolean isNew) {
|
|
|
|
return ChunkRespond(player.getName(), chunk.getWorld().getName(), chunk.getX(), chunk.getZ(), isNew);
|
2016-01-09 13:58:33 +01:00
|
|
|
}
|
|
|
|
|
2016-06-27 13:19:54 +02:00
|
|
|
public ExploreRespond ChunkRespond(String player, String worldName, int x, int z, boolean isNew) {
|
2016-01-09 13:58:33 +01:00
|
|
|
|
|
|
|
int ChunkX = x;
|
|
|
|
int ChunkZ = z;
|
|
|
|
|
|
|
|
int RegionX = (int) Math.floor(ChunkX / 32D);
|
|
|
|
int RegionZ = (int) Math.floor(ChunkZ / 32D);
|
|
|
|
|
|
|
|
if (!worlds.containsKey(worldName)) {
|
|
|
|
ExploreChunk eChunk = new ExploreChunk(player, ChunkX, ChunkZ);
|
2016-06-27 13:19:54 +02:00
|
|
|
if (!isNew)
|
|
|
|
eChunk.setOldChunk();
|
2016-01-09 13:58:33 +01:00
|
|
|
ExploreRegion eRegion = new ExploreRegion(RegionX, RegionZ);
|
|
|
|
eRegion.addChunk(eChunk);
|
|
|
|
worlds.put(worldName, eRegion);
|
|
|
|
return new ExploreRespond(eChunk.getCount(), true);
|
|
|
|
}
|
2016-06-25 15:27:01 +02:00
|
|
|
ExploreRegion eRegion = worlds.get(worldName);
|
|
|
|
ExploreChunk eChunk = null;
|
|
|
|
for (ExploreChunk one : eRegion.getChunks()) {
|
|
|
|
if (one.getX() != ChunkX)
|
|
|
|
continue;
|
|
|
|
if (one.getZ() != ChunkZ)
|
|
|
|
continue;
|
|
|
|
eChunk = one;
|
2016-06-27 13:19:54 +02:00
|
|
|
if (!isNew)
|
|
|
|
eChunk.setOldChunk();
|
2016-06-25 15:27:01 +02:00
|
|
|
break;
|
|
|
|
}
|
2016-01-09 13:58:33 +01:00
|
|
|
|
2016-06-25 15:27:01 +02:00
|
|
|
if (eChunk == null) {
|
|
|
|
eChunk = new ExploreChunk(player, ChunkX, ChunkZ);
|
2016-06-27 13:19:54 +02:00
|
|
|
if (!isNew)
|
|
|
|
eChunk.setOldChunk();
|
2016-06-25 15:27:01 +02:00
|
|
|
eRegion.addChunk(eChunk);
|
|
|
|
return new ExploreRespond(eChunk.getCount(), true);
|
|
|
|
}
|
|
|
|
return eChunk.addPlayer(player);
|
|
|
|
}
|
2016-01-09 13:58:33 +01:00
|
|
|
}
|