1
0
mirror of https://github.com/Zrips/Jobs.git synced 2025-01-17 21:51:20 +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. // all loaded properly.
dao.loadBlockProtection(); dao.loadBlockProtection();
dao.loadExplore(); getExplore().load();
String message = ChatColor.translateAlternateColorCodes('&', "&e[Jobs] Plugin has been enabled succesfully."); String message = ChatColor.translateAlternateColorCodes('&', "&e[Jobs] Plugin has been enabled succesfully.");
ConsoleCommandSender console = Bukkit.getServer().getConsoleSender(); ConsoleCommandSender console = Bukkit.getServer().getConsoleSender();

View File

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

View File

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

View File

@ -1,89 +1,108 @@
package com.gamingmesh.jobs.config; package com.gamingmesh.jobs.config;
import java.util.HashMap; import java.util.HashMap;
import org.bukkit.Chunk; import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.ChatColor;
import org.bukkit.Chunk;
import com.gamingmesh.jobs.Jobs; import org.bukkit.entity.Player;
import com.gamingmesh.jobs.container.ExploreChunk;
import com.gamingmesh.jobs.container.ExploreRegion; import com.gamingmesh.jobs.Jobs;
import com.gamingmesh.jobs.container.ExploreRespond; import com.gamingmesh.jobs.container.ExploreChunk;
import com.gamingmesh.jobs.container.ExploreRegion;
public class ExploreManager { import com.gamingmesh.jobs.container.ExploreRespond;
private HashMap<String, ExploreRegion> worlds = new HashMap<String, ExploreRegion>(); public class ExploreManager {
private boolean exploreEnabled = false;
private int playerAmount = 1; private HashMap<String, ExploreRegion> worlds = new HashMap<String, ExploreRegion>();
private boolean exploreEnabled = false;
public ExploreManager() { private int playerAmount = 1;
}
public int getPlayerAmount() {
public int getPlayerAmount() { return this.playerAmount;
return this.playerAmount; }
}
public void setPlayerAmount(int amount) {
public void setPlayerAmount(int amount) { if (this.playerAmount < amount)
if (this.playerAmount < amount) this.playerAmount = amount;
this.playerAmount = amount; }
}
public boolean isExploreEnabled() {
public boolean isExploreEnabled() { return this.exploreEnabled;
return this.exploreEnabled; }
}
public void setExploreEnabled() {
public void setExploreEnabled() { if (!exploreEnabled) {
if (!exploreEnabled) { this.exploreEnabled = true;
this.exploreEnabled = true; }
Jobs.getJobsDAO().loadExplore(); }
}
} public void load() {
if (!exploreEnabled)
public HashMap<String, ExploreRegion> getWorlds() { return;
return worlds; Bukkit.getConsoleSender().sendMessage(ChatColor.YELLOW + "[Jobs] Loading explorer data");
} Jobs.getJobsDAO().loadExplore();
Bukkit.getConsoleSender().sendMessage(ChatColor.YELLOW + "[Jobs] Loaded explorer data");
public ExploreRespond ChunkRespond(Player player, Chunk chunk, boolean isNew) { }
return ChunkRespond(player.getName(), chunk.getWorld().getName(), chunk.getX(), chunk.getZ(), isNew);
} public HashMap<String, ExploreRegion> getWorlds() {
return worlds;
public ExploreRespond ChunkRespond(String player, String worldName, int x, int z, boolean isNew) { }
int ChunkX = x; public ExploreRespond ChunkRespond(Player player, Chunk chunk, boolean isNew) {
int ChunkZ = z; return ChunkRespond(player.getName(), chunk.getWorld().getName(), chunk.getX(), chunk.getZ(), isNew);
}
int RegionX = (int) Math.floor(ChunkX / 32D);
int RegionZ = (int) Math.floor(ChunkZ / 32D); public ExploreRespond ChunkRespond(String player, String worldName, int x, int z, boolean isNew) {
if (!worlds.containsKey(worldName)) { int ChunkX = x;
ExploreChunk eChunk = new ExploreChunk(player, ChunkX, ChunkZ); int ChunkZ = z;
if (!isNew)
eChunk.setOldChunk(); int RegionX = (int) Math.floor(ChunkX / 32D);
ExploreRegion eRegion = new ExploreRegion(RegionX, RegionZ); int RegionZ = (int) Math.floor(ChunkZ / 32D);
eRegion.addChunk(eChunk);
worlds.put(worldName, eRegion); if (!worlds.containsKey(worldName)) {
return new ExploreRespond(eChunk.getCount(), true); ExploreChunk eChunk = new ExploreChunk(player, ChunkX, ChunkZ);
} if (!isNew)
ExploreRegion eRegion = worlds.get(worldName); eChunk.setOldChunk();
ExploreChunk eChunk = null; ExploreRegion eRegion = new ExploreRegion(RegionX, RegionZ);
for (ExploreChunk one : eRegion.getChunks()) { eRegion.addChunk(eChunk);
if (one.getX() != ChunkX) worlds.put(worldName, eRegion);
continue; return new ExploreRespond(eChunk.getCount(), true);
if (one.getZ() != ChunkZ) }
continue; ExploreRegion eRegion = worlds.get(worldName);
eChunk = one; ExploreChunk eChunk = eRegion.getChunk(ChunkX + ":" + ChunkZ);
if (!isNew)
eChunk.setOldChunk(); if (eChunk == null) {
break; eChunk = new ExploreChunk(player, ChunkX, ChunkZ);
} if (!isNew)
eChunk.setOldChunk();
if (eChunk == null) { eRegion.addChunk(eChunk);
eChunk = new ExploreChunk(player, ChunkX, ChunkZ); return new ExploreRespond(eChunk.getCount(), true);
if (!isNew) }
eChunk.setOldChunk(); eChunk.setOldChunk();
eRegion.addChunk(eChunk); return eChunk.addPlayer(player);
return new ExploreRespond(eChunk.getCount(), true); }
}
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; package com.gamingmesh.jobs.container;
import java.util.ArrayList; import java.util.HashMap;
import java.util.List;
public class ExploreRegion {
public class ExploreRegion {
int x;
int x; int z;
int z; HashMap<String, ExploreChunk> chunks = new HashMap<String, ExploreChunk>();
List<ExploreChunk> chunks = new ArrayList<ExploreChunk>();
public ExploreRegion(int x, int z) {
public ExploreRegion(int x, int z) { this.x = x;
this.x = x; this.z = z;
this.z = z; }
}
public void addChunk(ExploreChunk chunk) {
public void addChunk(ExploreChunk chunk) { chunks.put(chunk.getX() + ":" + chunk.getZ(), chunk);
chunks.add(chunk); }
}
public HashMap<String, ExploreChunk> getChunks() {
public List<ExploreChunk> getChunks() { return chunks;
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()); HashMap<String, ExploreRegion> temp = new HashMap<String, ExploreRegion>(Jobs.getExplore().getWorlds());
for (Entry<String, ExploreRegion> worlds : temp.entrySet()) { for (Entry<String, ExploreRegion> worlds : temp.entrySet()) {
for (ExploreChunk oneChunk : worlds.getValue().getChunks()) { for (Entry<String, ExploreChunk> oneChunk : worlds.getValue().getChunks().entrySet()) {
if (!oneChunk.isNew()) if (!oneChunk.getValue().isNew())
continue; continue;
for (String oneuser : oneChunk.getPlayers()) { for (String oneuser : oneChunk.getValue().getPlayers()) {
prest2.setString(1, worlds.getKey()); prest2.setString(1, worlds.getKey());
prest2.setInt(2, oneChunk.getX()); prest2.setInt(2, oneChunk.getValue().getX());
prest2.setInt(3, oneChunk.getZ()); prest2.setInt(3, oneChunk.getValue().getZ());
prest2.setString(4, oneuser); prest2.setString(4, oneuser);
prest2.addBatch(); prest2.addBatch();
i++; i++;