1
0
mirror of https://github.com/Zrips/Jobs.git synced 2024-12-30 21:07:48 +01:00

Optimize for explorer loading

This commit is contained in:
Zrips 2017-01-14 14:05:32 +02:00
parent d9d2a791a3
commit 0870a3abe2
6 changed files with 156 additions and 126 deletions

View File

@ -737,7 +737,7 @@ public class Jobs extends JavaPlugin {
// all loaded properly.
dao.loadBlockProtection();
dao.loadExplore();
getExplore().load();
String message = ChatColor.translateAlternateColorCodes('&', "&e[Jobs] Plugin has been enabled succesfully.");
ConsoleCommandSender console = Bukkit.getServer().getConsoleSender();

View File

@ -97,18 +97,26 @@ public class PlayerManager {
public void addPlayerToCache(JobsPlayer jPlayer) {
if (jPlayer.getUserName() != null)
this.playersCache.put(jPlayer.getUserName(), jPlayer);
this.playersCache.put(jPlayer.getUserName().toLowerCase(), jPlayer);
if (jPlayer.getPlayerUUID() != null)
this.playersUUIDCache.put(jPlayer.getPlayerUUID(), jPlayer);
}
public void addPlayer(JobsPlayer jPlayer) {
if (jPlayer.getUserName() != null)
this.players.put(jPlayer.getUserName(), jPlayer);
this.players.put(jPlayer.getUserName().toLowerCase(), jPlayer);
if (jPlayer.getPlayerUUID() != null)
this.playersUUID.put(jPlayer.getPlayerUUID(), jPlayer);
}
public JobsPlayer removePlayer(Player player) {
if (player == null)
return null;
this.players.remove(player.getName().toLowerCase());
JobsPlayer jPlayer = this.playersUUID.remove(player.getUniqueId());
return jPlayer;
}
public ConcurrentHashMap<UUID, JobsPlayer> getPlayersCache() {
return this.playersUUIDCache;
}
@ -148,14 +156,13 @@ public class PlayerManager {
* @param playername
*/
public void playerJoin(Player player) {
JobsPlayer jPlayer = this.playersCache.get(player.getName().toLowerCase());
JobsPlayer jPlayer = this.playersUUIDCache.get(player.getUniqueId());
if (jPlayer == null || Jobs.getGCManager().MultiServerCompatability()) {
jPlayer = Jobs.getJobsDAO().loadFromDao(player);
jPlayer.loadLogFromDao();
this.playersCache.put(player.getName().toLowerCase(), jPlayer);
}
this.players.put(player.getName().toLowerCase(), jPlayer);
this.addPlayer(jPlayer);
jPlayer.setPlayer(player);
AutoJoinJobs(player);
jPlayer.onConnect();
@ -169,12 +176,12 @@ public class PlayerManager {
* @param playername
*/
public void playerQuit(Player player) {
JobsPlayer jPlayer = this.players.remove(player.getName().toLowerCase());
JobsPlayer jPlayer = this.removePlayer(player);
if (jPlayer == null)
jPlayer = Jobs.getPlayerManager().getJobsPlayer(player);
if (jPlayer == null)
return;
playersCache.put(player.getName().toLowerCase(), jPlayer);
addPlayerToCache(jPlayer);
if (Jobs.getGCManager().saveOnDisconnect()) {
jPlayer.save();
jPlayer.onDisconnect();

View File

@ -31,3 +31,4 @@
/BossBarManager.class
/BlockProtectionManager.class
/ScheduleManager$3.class
/ExploreManager$1.class

View File

@ -1,89 +1,108 @@
package com.gamingmesh.jobs.config;
import java.util.HashMap;
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;
public class ExploreManager {
private HashMap<String, ExploreRegion> worlds = new HashMap<String, ExploreRegion>();
private boolean exploreEnabled = false;
private int playerAmount = 1;
public ExploreManager() {
}
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() {
if (!exploreEnabled) {
this.exploreEnabled = true;
Jobs.getJobsDAO().loadExplore();
}
}
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);
}
public ExploreRespond ChunkRespond(String player, String worldName, int x, int z, boolean isNew) {
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();
ExploreRegion eRegion = new ExploreRegion(RegionX, RegionZ);
eRegion.addChunk(eChunk);
worlds.put(worldName, eRegion);
return new ExploreRespond(eChunk.getCount(), true);
}
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();
break;
}
if (eChunk == null) {
eChunk = new ExploreChunk(player, ChunkX, ChunkZ);
if (!isNew)
eChunk.setOldChunk();
eRegion.addChunk(eChunk);
return new ExploreRespond(eChunk.getCount(), true);
}
return eChunk.addPlayer(player);
}
}
package com.gamingmesh.jobs.config;
import java.util.HashMap;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
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;
public class ExploreManager {
private HashMap<String, ExploreRegion> worlds = new HashMap<String, ExploreRegion>();
private boolean exploreEnabled = false;
private int playerAmount = 1;
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() {
if (!exploreEnabled) {
this.exploreEnabled = true;
}
}
public void load() {
if (!exploreEnabled)
return;
Bukkit.getConsoleSender().sendMessage(ChatColor.YELLOW + "[Jobs] Loading explorer data");
Jobs.getJobsDAO().loadExplore();
Bukkit.getConsoleSender().sendMessage(ChatColor.YELLOW + "[Jobs] Loaded explorer data");
}
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);
}
public ExploreRespond ChunkRespond(String player, String worldName, int x, int z, boolean isNew) {
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();
ExploreRegion eRegion = new ExploreRegion(RegionX, RegionZ);
eRegion.addChunk(eChunk);
worlds.put(worldName, eRegion);
return new ExploreRespond(eChunk.getCount(), true);
}
ExploreRegion eRegion = worlds.get(worldName);
ExploreChunk eChunk = eRegion.getChunk(ChunkX + ":" + ChunkZ);
if (eChunk == null) {
eChunk = new ExploreChunk(player, ChunkX, ChunkZ);
if (!isNew)
eChunk.setOldChunk();
eRegion.addChunk(eChunk);
return new ExploreRespond(eChunk.getCount(), true);
}
eChunk.setOldChunk();
return eChunk.addPlayer(player);
}
public void addChunk(String player, String worldName, int x, int z) {
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);
eChunk.setOldChunk();
ExploreRegion eRegion = new ExploreRegion(RegionX, RegionZ);
eRegion.addChunk(eChunk);
worlds.put(worldName, eRegion);
}
ExploreRegion eRegion = worlds.get(worldName);
ExploreChunk eChunk = eRegion.getChunk(ChunkX + ":" + ChunkZ);
if (eChunk == null) {
eChunk = new ExploreChunk(player, ChunkX, ChunkZ);
eChunk.setOldChunk();
eRegion.addChunk(eChunk);
} else
eChunk.setOldChunk();
}
}

View File

@ -1,24 +1,27 @@
package com.gamingmesh.jobs.container;
import java.util.ArrayList;
import java.util.List;
public class ExploreRegion {
int x;
int z;
List<ExploreChunk> chunks = new ArrayList<ExploreChunk>();
public ExploreRegion(int x, int z) {
this.x = x;
this.z = z;
}
public void addChunk(ExploreChunk chunk) {
chunks.add(chunk);
}
public List<ExploreChunk> getChunks() {
return chunks;
}
}
package com.gamingmesh.jobs.container;
import java.util.HashMap;
public class ExploreRegion {
int x;
int z;
HashMap<String, ExploreChunk> chunks = new HashMap<String, ExploreChunk>();
public ExploreRegion(int x, int z) {
this.x = x;
this.z = z;
}
public void addChunk(ExploreChunk chunk) {
chunks.put(chunk.getX() + ":" + chunk.getZ(), chunk);
}
public HashMap<String, ExploreChunk> getChunks() {
return chunks;
}
public ExploreChunk getChunk(String cord) {
return chunks.get(cord);
}
}

View File

@ -1310,13 +1310,13 @@ public abstract class JobsDAO {
HashMap<String, ExploreRegion> temp = new HashMap<String, ExploreRegion>(Jobs.getExplore().getWorlds());
for (Entry<String, ExploreRegion> worlds : temp.entrySet()) {
for (ExploreChunk oneChunk : worlds.getValue().getChunks()) {
if (!oneChunk.isNew())
for (Entry<String, ExploreChunk> oneChunk : worlds.getValue().getChunks().entrySet()) {
if (!oneChunk.getValue().isNew())
continue;
for (String oneuser : oneChunk.getPlayers()) {
for (String oneuser : oneChunk.getValue().getPlayers()) {
prest2.setString(1, worlds.getKey());
prest2.setInt(2, oneChunk.getX());
prest2.setInt(3, oneChunk.getZ());
prest2.setInt(2, oneChunk.getValue().getX());
prest2.setInt(3, oneChunk.getValue().getZ());
prest2.setString(4, oneuser);
prest2.addBatch();
i++;