1
0
mirror of https://github.com/Zrips/Jobs.git synced 2024-11-29 14:05:25 +01:00

Lets maintain one instance of explore manager

This commit is contained in:
Zrips 2022-03-07 14:35:58 +02:00
parent f70f2f7171
commit 1cb965c833
9 changed files with 95 additions and 101 deletions

20
pom.xml
View File

@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>Jobs</groupId>
<artifactId>jobs</artifactId>
<version>5.0.1.0</version>
<version>5.0.1.4</version>
<name>Jobs</name>
<url>http://maven.apache.org</url>
@ -191,7 +191,7 @@
<artifactId>CMILib</artifactId>
<version>latest</version>
<scope>system</scope>
<systemPath>${basedir}/libs/CMILib1.0.2.12.jar</systemPath>
<systemPath>${basedir}/libs/CMILib1.1.0.2.jar</systemPath>
</dependency>
<!-- WildStacker -->
<dependency>
@ -275,14 +275,14 @@
<target>1.8</target>
</configuration>
</plugin>
<!-- <plugin> -->
<!-- <groupId>org.apache.maven.plugins</groupId> -->
<!-- <artifactId>maven-jar-plugin</artifactId> -->
<!-- <version>2.3.1</version> -->
<!-- <configuration> -->
<!-- <outputDirectory>D:\MC\Server 1.17\plugins\</outputDirectory> -->
<!-- </configuration> -->
<!-- </plugin> -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.1</version>
<configuration>
<outputDirectory>D:\MC\Server 1.18\plugins\</outputDirectory>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@ -387,9 +387,14 @@ public final class Jobs extends JavaPlugin {
return cManager;
}
public static ExploreManager getExplore() {
// @Deprecated
// public static ExploreManager getExplore() {
// return getExploreManager();
// }
public static ExploreManager getExploreManager() {
if (exploreManager == null)
exploreManager = ExploreManager.getInstane();
exploreManager = new ExploreManager();
return exploreManager;
}
@ -776,7 +781,7 @@ public final class Jobs extends JavaPlugin {
getServer().getScheduler().runTask(this, new HookEconomyTask(this));
dao.loadBlockProtection();
getExplore().load();
getExploreManager().load();
getCommandManager().fillCommands();
getDBManager().getDB().triggerTableIdUpdate();

View File

@ -19,7 +19,7 @@ public class explored implements Cmd {
return false;
Player player = (Player) sender;
Map<String, ExploreRegion> exploreRegion = Jobs.getExplore().getWorlds().get(player.getWorld().getName());
Map<String, ExploreRegion> exploreRegion = Jobs.getExploreManager().getWorlds().get(player.getWorld().getName());
if (exploreRegion == null) {
player.sendMessage(Jobs.getLanguage().getMessage("command.explored.error.noexplore"));

View File

@ -23,13 +23,12 @@ public class resetexploreregion implements Cmd {
}
final String worldName = args[1];
if(!worldName.matches(REGEX)) {
if (!worldName.matches(REGEX)) {
sender.sendMessage(Jobs.getLanguage().getMessage("command.resetexploreregion.output.invalidname"));
return true;
}
ExploreManager manager = ExploreManager.getInstane();
manager.resetRegion(worldName);
Jobs.getExploreManager().resetRegion(worldName);
sender.sendMessage(Jobs.getLanguage().getMessage("command.resetexploreregion.output.reseted", "%worldname%", worldName));
return true;
}

View File

@ -806,8 +806,8 @@ public class ConfigManager {
return null;
}
Jobs.getExplore().setExploreEnabled();
Jobs.getExplore().setPlayerAmount(amount);
Jobs.getExploreManager().setExploreEnabled();
Jobs.getExploreManager().setPlayerAmount(amount);
} else if (actionType == ActionType.CRAFT) {
if (myKey.startsWith("!")) {
type = myKey.substring(1, myKey.length());

View File

@ -19,17 +19,6 @@ import com.gamingmesh.jobs.stuff.Util;
public class ExploreManager {
private static ExploreManager instance;
public static ExploreManager getInstane() {
if(null == instance) {
instance = new ExploreManager();
}
return instance;
}
private ExploreManager() {
}
private final Map<String, Map<String, ExploreRegion>> worlds = new HashMap<>();
private boolean exploreEnabled = false;
private int playerAmount = 1;
@ -157,7 +146,7 @@ public class ExploreManager {
worlds.put(worldname, new HashMap<String, ExploreRegion>());
boolean r = Jobs.getJobsDAO().deleteExploredWorld(worldname);
if(!r) {
if (!r) {
Jobs.consoleMsg("&eFailed in DAO.");
return;
}

View File

@ -13,12 +13,12 @@ public class ExploreChunk {
public ExploreRespond addPlayer(int playerId) {
if (isFullyExplored()) {
return new ExploreRespond(Jobs.getExplore().getPlayerAmount() + 1, false);
return new ExploreRespond(Jobs.getExploreManager().getPlayerAmount() + 1, false);
}
boolean newChunkForPlayer = false;
if (!playerIds.contains(playerId)) {
if (playerIds.size() < Jobs.getExplore().getPlayerAmount()) {
if (playerIds.size() < Jobs.getExploreManager().getPlayerAmount()) {
playerIds.add(playerId);
updated = true;
}
@ -26,7 +26,7 @@ public class ExploreChunk {
newChunkForPlayer = true;
}
if (Jobs.getGCManager().ExploreCompact && playerIds.size() >= Jobs.getExplore().getPlayerAmount()) {
if (Jobs.getGCManager().ExploreCompact && playerIds.size() >= Jobs.getExploreManager().getPlayerAmount()) {
playerIds = null;
}
@ -40,7 +40,7 @@ public class ExploreChunk {
}
public int getCount() {
return isFullyExplored() ? Jobs.getExplore().getPlayerAmount() : playerIds.size();
return isFullyExplored() ? Jobs.getExploreManager().getPlayerAmount() : playerIds.size();
}
public List<Integer> getPlayers() {
@ -86,7 +86,7 @@ public class ExploreChunk {
}
}
if (Jobs.getGCManager().ExploreCompact && playerIds.size() >= Jobs.getExplore().getPlayerAmount()) {
if (Jobs.getGCManager().ExploreCompact && playerIds.size() >= Jobs.getExploreManager().getPlayerAmount()) {
playerIds = null;
if (!names.isEmpty())
@ -111,6 +111,6 @@ public class ExploreChunk {
}
public boolean isFullyExplored() {
return playerIds == null || playerIds.size() >= Jobs.getExplore().getPlayerAmount();
return playerIds == null || playerIds.size() >= Jobs.getExploreManager().getPlayerAmount();
}
}

View File

@ -2457,7 +2457,7 @@ public abstract class JobsDAO {
}
public void insertExplore() {
if (!Jobs.getExplore().isExploreEnabled())
if (!Jobs.getExploreManager().isExploreEnabled())
return;
JobsConnection conn = getConnection();
@ -2475,7 +2475,7 @@ public abstract class JobsDAO {
conn.setAutoCommit(false);
int i = 0;
Map<String, Map<String, ExploreRegion>> temp = new HashMap<>(Jobs.getExplore().getWorlds());
Map<String, Map<String, ExploreRegion>> temp = new HashMap<>(Jobs.getExploreManager().getWorlds());
for (Entry<String, Map<String, ExploreRegion>> worlds : temp.entrySet()) {
for (Entry<String, ExploreRegion> region : worlds.getValue().entrySet()) {
@ -2516,7 +2516,7 @@ public abstract class JobsDAO {
}
public void updateExplore() {
if (!Jobs.getExplore().isExploreEnabled())
if (!Jobs.getExploreManager().isExploreEnabled())
return;
JobsConnection conn = getConnection();
@ -2529,7 +2529,7 @@ public abstract class JobsDAO {
int i = 0;
Map<String, Map<String, ExploreRegion>> temp = new HashMap<>(Jobs.getExplore().getWorlds());
Map<String, Map<String, ExploreRegion>> temp = new HashMap<>(Jobs.getExploreManager().getWorlds());
for (Entry<String, Map<String, ExploreRegion>> worlds : temp.entrySet()) {
for (Entry<String, ExploreRegion> region : worlds.getValue().entrySet()) {
@ -2568,7 +2568,7 @@ public abstract class JobsDAO {
* @param jobexplore - the information getting saved
*/
public void loadExplore() {
if (!Jobs.getExplore().isExploreEnabled())
if (!Jobs.getExploreManager().isExploreEnabled())
return;
JobsConnection conn = getConnection();
@ -2587,7 +2587,7 @@ public abstract class JobsDAO {
if (jworld == null || jworld.getWorld() == null) {
missingWorlds.add(worldId);
} else {
Jobs.getExplore().load(res);
Jobs.getExploreManager().load(res);
}
}
@ -2618,7 +2618,7 @@ public abstract class JobsDAO {
* @param worldName - the world getting removed
*/
public boolean deleteExploredWorld(String worldName) {
if (!Jobs.getExplore().isExploreEnabled())
if (!Jobs.getExploreManager().isExploreEnabled())
return false;
JobsConnection conn = getConnection();
@ -2630,6 +2630,7 @@ public abstract class JobsDAO {
return false;
}
boolean res = true;
PreparedStatement prest = null;
try {
prest = conn.prepareStatement("DELETE FROM `" + DBTables.ExploreDataTable.getTableName() + "` WHERE `" + ExploreDataTableFields.worldid.getCollumn() + "` = ?;");
@ -2637,11 +2638,11 @@ public abstract class JobsDAO {
prest.execute();
} catch (Throwable e) {
e.printStackTrace();
return false;
res = false;
} finally {
close(prest);
}
return true;
return res;
}
/**

View File

@ -1775,7 +1775,7 @@ public final class JobsPaymentListener implements Listener {
@EventHandler(ignoreCancelled = true)
public void onExplore(JobsChunkChangeEvent event) {
if (!Jobs.getExplore().isExploreEnabled())
if (!Jobs.getExploreManager().isExploreEnabled())
return;
Player player = event.getPlayer();
@ -1810,7 +1810,7 @@ public final class JobsPaymentListener implements Listener {
if (jPlayer == null)
return;
ExploreRespond respond = Jobs.getExplore().chunkRespond(jPlayer.getUserId(), event.getNewChunk());
ExploreRespond respond = Jobs.getExploreManager().chunkRespond(jPlayer.getUserId(), event.getNewChunk());
if (!respond.isNewChunk())
return;