mirror of
https://github.com/Zrips/Jobs.git
synced 2025-01-04 23:37:49 +01:00
Optimize for explorer loading
This commit is contained in:
parent
d9d2a791a3
commit
0870a3abe2
@ -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();
|
||||||
|
@ -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();
|
||||||
|
1
com/gamingmesh/jobs/config/.gitignore
vendored
1
com/gamingmesh/jobs/config/.gitignore
vendored
@ -31,3 +31,4 @@
|
|||||||
/BossBarManager.class
|
/BossBarManager.class
|
||||||
/BlockProtectionManager.class
|
/BlockProtectionManager.class
|
||||||
/ScheduleManager$3.class
|
/ScheduleManager$3.class
|
||||||
|
/ExploreManager$1.class
|
||||||
|
@ -2,6 +2,8 @@ package com.gamingmesh.jobs.config;
|
|||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Chunk;
|
import org.bukkit.Chunk;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
@ -16,9 +18,6 @@ public class ExploreManager {
|
|||||||
private boolean exploreEnabled = false;
|
private boolean exploreEnabled = false;
|
||||||
private int playerAmount = 1;
|
private int playerAmount = 1;
|
||||||
|
|
||||||
public ExploreManager() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getPlayerAmount() {
|
public int getPlayerAmount() {
|
||||||
return this.playerAmount;
|
return this.playerAmount;
|
||||||
}
|
}
|
||||||
@ -35,10 +34,17 @@ public class ExploreManager {
|
|||||||
public void setExploreEnabled() {
|
public void setExploreEnabled() {
|
||||||
if (!exploreEnabled) {
|
if (!exploreEnabled) {
|
||||||
this.exploreEnabled = true;
|
this.exploreEnabled = true;
|
||||||
Jobs.getJobsDAO().loadExplore();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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() {
|
public HashMap<String, ExploreRegion> getWorlds() {
|
||||||
return worlds;
|
return worlds;
|
||||||
}
|
}
|
||||||
@ -65,17 +71,7 @@ public class ExploreManager {
|
|||||||
return new ExploreRespond(eChunk.getCount(), true);
|
return new ExploreRespond(eChunk.getCount(), true);
|
||||||
}
|
}
|
||||||
ExploreRegion eRegion = worlds.get(worldName);
|
ExploreRegion eRegion = worlds.get(worldName);
|
||||||
ExploreChunk eChunk = null;
|
ExploreChunk eChunk = eRegion.getChunk(ChunkX + ":" + ChunkZ);
|
||||||
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) {
|
if (eChunk == null) {
|
||||||
eChunk = new ExploreChunk(player, ChunkX, ChunkZ);
|
eChunk = new ExploreChunk(player, ChunkX, ChunkZ);
|
||||||
@ -84,6 +80,29 @@ public class ExploreManager {
|
|||||||
eRegion.addChunk(eChunk);
|
eRegion.addChunk(eChunk);
|
||||||
return new ExploreRespond(eChunk.getCount(), true);
|
return new ExploreRespond(eChunk.getCount(), true);
|
||||||
}
|
}
|
||||||
|
eChunk.setOldChunk();
|
||||||
return eChunk.addPlayer(player);
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,12 @@
|
|||||||
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;
|
||||||
List<ExploreChunk> chunks = new ArrayList<ExploreChunk>();
|
HashMap<String, ExploreChunk> chunks = new HashMap<String, ExploreChunk>();
|
||||||
|
|
||||||
public ExploreRegion(int x, int z) {
|
public ExploreRegion(int x, int z) {
|
||||||
this.x = x;
|
this.x = x;
|
||||||
@ -15,10 +14,14 @@ public class ExploreRegion {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void addChunk(ExploreChunk chunk) {
|
public void addChunk(ExploreChunk chunk) {
|
||||||
chunks.add(chunk);
|
chunks.put(chunk.getX() + ":" + chunk.getZ(), chunk);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<ExploreChunk> getChunks() {
|
public HashMap<String, ExploreChunk> getChunks() {
|
||||||
return chunks;
|
return chunks;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ExploreChunk getChunk(String cord) {
|
||||||
|
return chunks.get(cord);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -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++;
|
||||||
|
Loading…
Reference in New Issue
Block a user