1
0
mirror of https://github.com/Zrips/Jobs.git synced 2024-11-26 04:25:15 +01:00
Jobs/com/gamingmesh/jobs/config/ExploreManager.java

90 lines
2.3 KiB
Java
Raw Normal View History

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;
}
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
}
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);
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;
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);
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
}