1
0
mirror of https://github.com/Zrips/Jobs.git synced 2024-12-01 15:03:36 +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> <modelVersion>4.0.0</modelVersion>
<groupId>Jobs</groupId> <groupId>Jobs</groupId>
<artifactId>jobs</artifactId> <artifactId>jobs</artifactId>
<version>5.0.1.0</version> <version>5.0.1.4</version>
<name>Jobs</name> <name>Jobs</name>
<url>http://maven.apache.org</url> <url>http://maven.apache.org</url>
@ -191,7 +191,7 @@
<artifactId>CMILib</artifactId> <artifactId>CMILib</artifactId>
<version>latest</version> <version>latest</version>
<scope>system</scope> <scope>system</scope>
<systemPath>${basedir}/libs/CMILib1.0.2.12.jar</systemPath> <systemPath>${basedir}/libs/CMILib1.1.0.2.jar</systemPath>
</dependency> </dependency>
<!-- WildStacker --> <!-- WildStacker -->
<dependency> <dependency>
@ -275,14 +275,14 @@
<target>1.8</target> <target>1.8</target>
</configuration> </configuration>
</plugin> </plugin>
<!-- <plugin> --> <plugin>
<!-- <groupId>org.apache.maven.plugins</groupId> --> <groupId>org.apache.maven.plugins</groupId>
<!-- <artifactId>maven-jar-plugin</artifactId> --> <artifactId>maven-jar-plugin</artifactId>
<!-- <version>2.3.1</version> --> <version>2.3.1</version>
<!-- <configuration> --> <configuration>
<!-- <outputDirectory>D:\MC\Server 1.17\plugins\</outputDirectory> --> <outputDirectory>D:\MC\Server 1.18\plugins\</outputDirectory>
<!-- </configuration> --> </configuration>
<!-- </plugin> --> </plugin>
</plugins> </plugins>
</build> </build>
</project> </project>

View File

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

View File

@ -19,7 +19,7 @@ public class explored implements Cmd {
return false; return false;
Player player = (Player) sender; 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) { if (exploreRegion == null) {
player.sendMessage(Jobs.getLanguage().getMessage("command.explored.error.noexplore")); player.sendMessage(Jobs.getLanguage().getMessage("command.explored.error.noexplore"));

View File

@ -28,8 +28,7 @@ public class resetexploreregion implements Cmd {
return true; return true;
} }
ExploreManager manager = ExploreManager.getInstane(); Jobs.getExploreManager().resetRegion(worldName);
manager.resetRegion(worldName);
sender.sendMessage(Jobs.getLanguage().getMessage("command.resetexploreregion.output.reseted", "%worldname%", worldName)); sender.sendMessage(Jobs.getLanguage().getMessage("command.resetexploreregion.output.reseted", "%worldname%", worldName));
return true; return true;
} }

View File

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

View File

@ -19,17 +19,6 @@ import com.gamingmesh.jobs.stuff.Util;
public class ExploreManager { 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 final Map<String, Map<String, ExploreRegion>> worlds = new HashMap<>();
private boolean exploreEnabled = false; private boolean exploreEnabled = false;
private int playerAmount = 1; private int playerAmount = 1;

View File

@ -13,12 +13,12 @@ public class ExploreChunk {
public ExploreRespond addPlayer(int playerId) { public ExploreRespond addPlayer(int playerId) {
if (isFullyExplored()) { if (isFullyExplored()) {
return new ExploreRespond(Jobs.getExplore().getPlayerAmount() + 1, false); return new ExploreRespond(Jobs.getExploreManager().getPlayerAmount() + 1, false);
} }
boolean newChunkForPlayer = false; boolean newChunkForPlayer = false;
if (!playerIds.contains(playerId)) { if (!playerIds.contains(playerId)) {
if (playerIds.size() < Jobs.getExplore().getPlayerAmount()) { if (playerIds.size() < Jobs.getExploreManager().getPlayerAmount()) {
playerIds.add(playerId); playerIds.add(playerId);
updated = true; updated = true;
} }
@ -26,7 +26,7 @@ public class ExploreChunk {
newChunkForPlayer = true; newChunkForPlayer = true;
} }
if (Jobs.getGCManager().ExploreCompact && playerIds.size() >= Jobs.getExplore().getPlayerAmount()) { if (Jobs.getGCManager().ExploreCompact && playerIds.size() >= Jobs.getExploreManager().getPlayerAmount()) {
playerIds = null; playerIds = null;
} }
@ -40,7 +40,7 @@ public class ExploreChunk {
} }
public int getCount() { public int getCount() {
return isFullyExplored() ? Jobs.getExplore().getPlayerAmount() : playerIds.size(); return isFullyExplored() ? Jobs.getExploreManager().getPlayerAmount() : playerIds.size();
} }
public List<Integer> getPlayers() { 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; playerIds = null;
if (!names.isEmpty()) if (!names.isEmpty())
@ -111,6 +111,6 @@ public class ExploreChunk {
} }
public boolean isFullyExplored() { 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() { public void insertExplore() {
if (!Jobs.getExplore().isExploreEnabled()) if (!Jobs.getExploreManager().isExploreEnabled())
return; return;
JobsConnection conn = getConnection(); JobsConnection conn = getConnection();
@ -2475,7 +2475,7 @@ public abstract class JobsDAO {
conn.setAutoCommit(false); conn.setAutoCommit(false);
int i = 0; 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, Map<String, ExploreRegion>> worlds : temp.entrySet()) {
for (Entry<String, ExploreRegion> region : worlds.getValue().entrySet()) { for (Entry<String, ExploreRegion> region : worlds.getValue().entrySet()) {
@ -2516,7 +2516,7 @@ public abstract class JobsDAO {
} }
public void updateExplore() { public void updateExplore() {
if (!Jobs.getExplore().isExploreEnabled()) if (!Jobs.getExploreManager().isExploreEnabled())
return; return;
JobsConnection conn = getConnection(); JobsConnection conn = getConnection();
@ -2529,7 +2529,7 @@ public abstract class JobsDAO {
int i = 0; 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, Map<String, ExploreRegion>> worlds : temp.entrySet()) {
for (Entry<String, ExploreRegion> region : worlds.getValue().entrySet()) { for (Entry<String, ExploreRegion> region : worlds.getValue().entrySet()) {
@ -2568,7 +2568,7 @@ public abstract class JobsDAO {
* @param jobexplore - the information getting saved * @param jobexplore - the information getting saved
*/ */
public void loadExplore() { public void loadExplore() {
if (!Jobs.getExplore().isExploreEnabled()) if (!Jobs.getExploreManager().isExploreEnabled())
return; return;
JobsConnection conn = getConnection(); JobsConnection conn = getConnection();
@ -2587,7 +2587,7 @@ public abstract class JobsDAO {
if (jworld == null || jworld.getWorld() == null) { if (jworld == null || jworld.getWorld() == null) {
missingWorlds.add(worldId); missingWorlds.add(worldId);
} else { } else {
Jobs.getExplore().load(res); Jobs.getExploreManager().load(res);
} }
} }
@ -2618,7 +2618,7 @@ public abstract class JobsDAO {
* @param worldName - the world getting removed * @param worldName - the world getting removed
*/ */
public boolean deleteExploredWorld(String worldName) { public boolean deleteExploredWorld(String worldName) {
if (!Jobs.getExplore().isExploreEnabled()) if (!Jobs.getExploreManager().isExploreEnabled())
return false; return false;
JobsConnection conn = getConnection(); JobsConnection conn = getConnection();
@ -2630,6 +2630,7 @@ public abstract class JobsDAO {
return false; return false;
} }
boolean res = true;
PreparedStatement prest = null; PreparedStatement prest = null;
try { try {
prest = conn.prepareStatement("DELETE FROM `" + DBTables.ExploreDataTable.getTableName() + "` WHERE `" + ExploreDataTableFields.worldid.getCollumn() + "` = ?;"); prest = conn.prepareStatement("DELETE FROM `" + DBTables.ExploreDataTable.getTableName() + "` WHERE `" + ExploreDataTableFields.worldid.getCollumn() + "` = ?;");
@ -2637,11 +2638,11 @@ public abstract class JobsDAO {
prest.execute(); prest.execute();
} catch (Throwable e) { } catch (Throwable e) {
e.printStackTrace(); e.printStackTrace();
return false; res = false;
} finally { } finally {
close(prest); close(prest);
} }
return true; return res;
} }
/** /**

View File

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