mirror of
https://github.com/Zrips/Jobs.git
synced 2024-11-29 22:13:25 +01:00
Optimizing chunk explore methods to have better performance and use less
memory. Option to compact database
This commit is contained in:
parent
4d0ed50e2b
commit
ca8ea40f7f
@ -571,7 +571,7 @@ public class editjobs implements Cmd {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
Jobs.getExplore().setExploreEnabled();
|
Jobs.getExplore().setExploreEnabled();
|
||||||
Jobs.getExplore().setPlayerAmount(amount + 1);
|
Jobs.getExplore().setPlayerAmount(amount);
|
||||||
} else if (actionT == ActionType.CRAFT && myKey.startsWith("!"))
|
} else if (actionT == ActionType.CRAFT && myKey.startsWith("!"))
|
||||||
type = myKey.substring(1, myKey.length());
|
type = myKey.substring(1, myKey.length());
|
||||||
|
|
||||||
|
@ -525,7 +525,7 @@ public class editquests implements Cmd {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Jobs.getExplore().setExploreEnabled();
|
Jobs.getExplore().setExploreEnabled();
|
||||||
Jobs.getExplore().setPlayerAmount(a + 1);
|
Jobs.getExplore().setPlayerAmount(a);
|
||||||
} else if (actionT == ActionType.CRAFT && myKey.startsWith("!"))
|
} else if (actionT == ActionType.CRAFT && myKey.startsWith("!"))
|
||||||
type = myKey.substring(1, myKey.length());
|
type = myKey.substring(1, myKey.length());
|
||||||
|
|
||||||
|
@ -11,6 +11,7 @@ import com.gamingmesh.jobs.commands.Cmd;
|
|||||||
import com.gamingmesh.jobs.commands.JobCommand;
|
import com.gamingmesh.jobs.commands.JobCommand;
|
||||||
import com.gamingmesh.jobs.container.ExploreChunk;
|
import com.gamingmesh.jobs.container.ExploreChunk;
|
||||||
import com.gamingmesh.jobs.container.ExploreRegion;
|
import com.gamingmesh.jobs.container.ExploreRegion;
|
||||||
|
import com.gamingmesh.jobs.container.PlayerInfo;
|
||||||
|
|
||||||
public class explored implements Cmd {
|
public class explored implements Cmd {
|
||||||
|
|
||||||
@ -40,11 +41,17 @@ public class explored implements Cmd {
|
|||||||
sender.sendMessage(Jobs.getLanguage().getMessage("command.explored.error.noexplore"));
|
sender.sendMessage(Jobs.getLanguage().getMessage("command.explored.error.noexplore"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (chunk.isFullyExplored() && Jobs.getGCManager().ExploreCompact) {
|
||||||
|
sender.sendMessage(Jobs.getLanguage().getMessage("command.explored.fullExplore"));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (String one : chunk.getPlayers()) {
|
for (Integer one : chunk.getPlayers()) {
|
||||||
i++;
|
i++;
|
||||||
sender.sendMessage(Jobs.getLanguage().getMessage("command.explored.list", "%place%", i, "%playername%", one));
|
PlayerInfo ji = Jobs.getPlayerManager().getPlayerInfo(one);
|
||||||
|
if (ji != null)
|
||||||
|
sender.sendMessage(Jobs.getLanguage().getMessage("command.explored.list", "%place%", i, "%playername%", ji.getName()));
|
||||||
}
|
}
|
||||||
sender.sendMessage(Jobs.getLanguage().getMessage("general.info.separator"));
|
sender.sendMessage(Jobs.getLanguage().getMessage("general.info.separator"));
|
||||||
|
|
||||||
|
@ -1144,7 +1144,7 @@ public class ConfigManager {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
Jobs.getExplore().setExploreEnabled();
|
Jobs.getExplore().setExploreEnabled();
|
||||||
Jobs.getExplore().setPlayerAmount(amount + 1);
|
Jobs.getExplore().setPlayerAmount(amount);
|
||||||
} else if (actionType == ActionType.CRAFT && myKey.startsWith("!"))
|
} else if (actionType == ActionType.CRAFT && myKey.startsWith("!"))
|
||||||
type = myKey.substring(1, myKey.length());
|
type = myKey.substring(1, myKey.length());
|
||||||
|
|
||||||
|
@ -62,10 +62,14 @@ public class ExploreManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ExploreRespond ChunkRespond(Player player, Chunk chunk) {
|
public ExploreRespond ChunkRespond(Player player, Chunk chunk) {
|
||||||
return ChunkRespond(player.getName(), chunk.getWorld().getName(), chunk.getX(), chunk.getZ());
|
return ChunkRespond(Jobs.getPlayerManager().getJobsPlayer(player).getUserId(), chunk.getWorld().getName(), chunk.getX(), chunk.getZ());
|
||||||
}
|
}
|
||||||
|
|
||||||
public ExploreRespond ChunkRespond(String player, String world, int x, int z) {
|
public ExploreRespond ChunkRespond(int playerId, Chunk chunk) {
|
||||||
|
return ChunkRespond(playerId, chunk.getWorld().getName(), chunk.getX(), chunk.getZ());
|
||||||
|
}
|
||||||
|
|
||||||
|
public ExploreRespond ChunkRespond(int playerId, String world, int x, int z) {
|
||||||
|
|
||||||
ExploreRegion eRegions = worlds.get(world);
|
ExploreRegion eRegions = worlds.get(world);
|
||||||
if (eRegions == null) {
|
if (eRegions == null) {
|
||||||
@ -80,7 +84,7 @@ public class ExploreManager {
|
|||||||
eRegions.addChunk(chunk);
|
eRegions.addChunk(chunk);
|
||||||
worlds.put(world, eRegions);
|
worlds.put(world, eRegions);
|
||||||
|
|
||||||
return chunk.addPlayer(player);
|
return chunk.addPlayer(playerId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void load(ResultSet res) {
|
public void load(ResultSet res) {
|
||||||
|
@ -158,6 +158,8 @@ public class GeneralConfigManager {
|
|||||||
|
|
||||||
public Parser DynamicPaymentEquation;
|
public Parser DynamicPaymentEquation;
|
||||||
|
|
||||||
|
public boolean ExploreCompact;
|
||||||
|
|
||||||
public boolean DisabledWorldsUse;
|
public boolean DisabledWorldsUse;
|
||||||
public List<String> DisabledWorldsList = new ArrayList<>();
|
public List<String> DisabledWorldsList = new ArrayList<>();
|
||||||
|
|
||||||
@ -508,6 +510,10 @@ public class GeneralConfigManager {
|
|||||||
DisabledWorldsUse = c.get("Optimizations.DisabledWorlds.Use", false);
|
DisabledWorldsUse = c.get("Optimizations.DisabledWorlds.Use", false);
|
||||||
DisabledWorldsList = c.get("Optimizations.DisabledWorlds.List", Arrays.asList(Bukkit.getWorlds().get(0).getName()));
|
DisabledWorldsList = c.get("Optimizations.DisabledWorlds.List", Arrays.asList(Bukkit.getWorlds().get(0).getName()));
|
||||||
|
|
||||||
|
c.addComment("Optimizations.Explore.Compact",
|
||||||
|
"By setting this to true when there is max amount of players explored a chunk then it will be marked as fully explored and exact players who explored it will not be saved to save some memory");
|
||||||
|
ExploreCompact = c.get("Optimizations.Explore.Compact", true);
|
||||||
|
|
||||||
// c.addComment("Optimizations.Purge.Use", "By setting this to true, Jobs plugin will clean data base on startup from all jobs with level 1 and at 0 exp");
|
// c.addComment("Optimizations.Purge.Use", "By setting this to true, Jobs plugin will clean data base on startup from all jobs with level 1 and at 0 exp");
|
||||||
// PurgeUse = c.get("Optimizations.Purge.Use", false);
|
// PurgeUse = c.get("Optimizations.Purge.Use", false);
|
||||||
|
|
||||||
|
@ -425,6 +425,7 @@ public class LanguageManager {
|
|||||||
|
|
||||||
c.get("command.explored.help.info", "Check who visited this chunk");
|
c.get("command.explored.help.info", "Check who visited this chunk");
|
||||||
c.get("command.explored.error.noexplore", "No one visited this chunk");
|
c.get("command.explored.error.noexplore", "No one visited this chunk");
|
||||||
|
c.get("command.explored.fullExplore", "&aThis chunk is fully explored");
|
||||||
c.get("command.explored.list", "&e%place%. %playername%");
|
c.get("command.explored.list", "&e%place%. %playername%");
|
||||||
|
|
||||||
c.get("command.browse.help.info", "List the jobs available to you.");
|
c.get("command.browse.help.info", "List the jobs available to you.");
|
||||||
|
@ -2,6 +2,7 @@ package com.gamingmesh.jobs.container;
|
|||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import com.gamingmesh.jobs.Jobs;
|
import com.gamingmesh.jobs.Jobs;
|
||||||
@ -10,14 +11,15 @@ public class ExploreChunk {
|
|||||||
|
|
||||||
private int x;
|
private int x;
|
||||||
private int z;
|
private int z;
|
||||||
private Set<String> playerNames = new HashSet<>();
|
private Set<Integer> playerIds = new HashSet<>();
|
||||||
|
private boolean full = false;
|
||||||
private Integer dbId = null;
|
private Integer dbId = null;
|
||||||
private boolean updated = false;
|
private boolean updated = false;
|
||||||
|
|
||||||
public ExploreChunk(String playerName, int x, int z) {
|
public ExploreChunk(int playerId, int x, int z) {
|
||||||
this.x = x;
|
this.x = x;
|
||||||
this.z = z;
|
this.z = z;
|
||||||
this.playerNames.add(playerName);
|
this.playerIds.add(playerId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ExploreChunk(int x, int z) {
|
public ExploreChunk(int x, int z) {
|
||||||
@ -25,24 +27,38 @@ public class ExploreChunk {
|
|||||||
this.z = z;
|
this.z = z;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ExploreRespond addPlayer(String playerName) {
|
public ExploreRespond addPlayer(int playerId) {
|
||||||
|
if (full) {
|
||||||
|
return new ExploreRespond(Jobs.getExplore().getPlayerAmount() + 1, false);
|
||||||
|
}
|
||||||
boolean newChunkForPlayer = false;
|
boolean newChunkForPlayer = false;
|
||||||
if (!playerNames.contains(playerName)) {
|
if (!playerIds.contains(playerId)) {
|
||||||
if (playerNames.size() < Jobs.getExplore().getPlayerAmount()) {
|
if (playerIds.size() < Jobs.getExplore().getPlayerAmount()) {
|
||||||
playerNames.add(playerName);
|
playerIds.add(playerId);
|
||||||
updated = true;
|
updated = true;
|
||||||
}
|
}
|
||||||
newChunkForPlayer = true;
|
newChunkForPlayer = true;
|
||||||
}
|
}
|
||||||
return new ExploreRespond(newChunkForPlayer ? playerNames.size() : playerNames.size() + 1, newChunkForPlayer);
|
|
||||||
|
if (playerIds.size() >= Jobs.getExplore().getPlayerAmount()) {
|
||||||
|
this.full = true;
|
||||||
|
if (Jobs.getGCManager().ExploreCompact)
|
||||||
|
playerIds = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new ExploreRespond(newChunkForPlayer ? getPlayers().size() : getPlayers().size() + 1, newChunkForPlayer);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isAlreadyVisited(String playerName) {
|
public boolean isAlreadyVisited(int playerId) {
|
||||||
return playerNames.contains(playerName);
|
if (full)
|
||||||
|
return true;
|
||||||
|
return playerIds.contains(playerId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getCount() {
|
public int getCount() {
|
||||||
return playerNames.size();
|
if (full)
|
||||||
|
return Jobs.getExplore().getPlayerAmount();
|
||||||
|
return playerIds.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getX() {
|
public int getX() {
|
||||||
@ -53,13 +69,15 @@ public class ExploreChunk {
|
|||||||
return z;
|
return z;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<String> getPlayers() {
|
public Set<Integer> getPlayers() {
|
||||||
return playerNames;
|
return playerIds == null ? new HashSet<>() : playerIds;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String serializeNames() {
|
public String serializeNames() {
|
||||||
String s = "";
|
String s = "";
|
||||||
for (String one : this.playerNames) {
|
if (playerIds == null)
|
||||||
|
return "";
|
||||||
|
for (Integer one : this.playerIds) {
|
||||||
if (!s.isEmpty())
|
if (!s.isEmpty())
|
||||||
s += ";";
|
s += ";";
|
||||||
s += one;
|
s += one;
|
||||||
@ -68,10 +86,35 @@ public class ExploreChunk {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void deserializeNames(String names) {
|
public void deserializeNames(String names) {
|
||||||
if (names.contains(";"))
|
if (names.isEmpty()) {
|
||||||
playerNames.addAll(Arrays.asList(names.split(";")));
|
this.full = true;
|
||||||
else
|
playerIds = null;
|
||||||
playerNames.add(names);
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<String> split = Arrays.asList(names.split(";"));
|
||||||
|
for (String one : split) {
|
||||||
|
try {
|
||||||
|
int id = Integer.parseInt(one);
|
||||||
|
PlayerInfo info = Jobs.getPlayerManager().getPlayerInfo(id);
|
||||||
|
if (info != null)
|
||||||
|
playerIds.add(id);
|
||||||
|
} catch (Exception | Error e) {
|
||||||
|
updated = true;
|
||||||
|
JobsPlayer jp = Jobs.getPlayerManager().getJobsPlayer(one);
|
||||||
|
if (jp != null)
|
||||||
|
playerIds.add(jp.getUserId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (playerIds.size() >= Jobs.getExplore().getPlayerAmount()) {
|
||||||
|
this.full = true;
|
||||||
|
if (Jobs.getGCManager().ExploreCompact) {
|
||||||
|
playerIds = null;
|
||||||
|
if (!names.isEmpty())
|
||||||
|
updated = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Integer getDbId() {
|
public Integer getDbId() {
|
||||||
@ -89,4 +132,8 @@ public class ExploreChunk {
|
|||||||
public void setUpdated(boolean updated) {
|
public void setUpdated(boolean updated) {
|
||||||
this.updated = updated;
|
this.updated = updated;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isFullyExplored() {
|
||||||
|
return full;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,7 @@ import com.gamingmesh.jobs.Jobs;
|
|||||||
import com.gamingmesh.jobs.actions.*;
|
import com.gamingmesh.jobs.actions.*;
|
||||||
import com.gamingmesh.jobs.api.JobsChunkChangeEvent;
|
import com.gamingmesh.jobs.api.JobsChunkChangeEvent;
|
||||||
import com.gamingmesh.jobs.container.*;
|
import com.gamingmesh.jobs.container.*;
|
||||||
|
import com.gamingmesh.jobs.stuff.Debug;
|
||||||
import com.gamingmesh.jobs.stuff.FurnaceBrewingHandling;
|
import com.gamingmesh.jobs.stuff.FurnaceBrewingHandling;
|
||||||
import com.gamingmesh.jobs.stuff.FurnaceBrewingHandling.ownershipFeedback;
|
import com.gamingmesh.jobs.stuff.FurnaceBrewingHandling.ownershipFeedback;
|
||||||
import com.google.common.base.Objects;
|
import com.google.common.base.Objects;
|
||||||
@ -1743,7 +1744,7 @@ public class JobsPaymentListener implements Listener {
|
|||||||
&& !Jobs.getGCManager().payExploringWhenGliding && player.isGliding())
|
&& !Jobs.getGCManager().payExploringWhenGliding && player.isGliding())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ExploreRespond respond = Jobs.getExplore().ChunkRespond(player, event.getNewChunk());
|
ExploreRespond respond = Jobs.getExplore().ChunkRespond(Jobs.getPlayerManager().getJobsPlayer(player).getUserId(), event.getNewChunk());
|
||||||
|
|
||||||
if (!respond.isNewChunk())
|
if (!respond.isNewChunk())
|
||||||
return;
|
return;
|
||||||
|
Loading…
Reference in New Issue
Block a user