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:
parent
f70f2f7171
commit
1cb965c833
20
pom.xml
20
pom.xml
@ -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>
|
||||
|
@ -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();
|
||||
|
||||
|
@ -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"));
|
||||
|
@ -12,25 +12,24 @@ public class resetexploreregion implements Cmd {
|
||||
|
||||
@Override
|
||||
public boolean perform(Jobs plugin, CommandSender sender, String[] args) {
|
||||
if (args.length != 2 || !WORLD.equals(args[0])) {
|
||||
Jobs.getCommandManager().sendUsage(sender, "resetexploreregion");
|
||||
return true;
|
||||
}
|
||||
if (args.length != 2 || !WORLD.equals(args[0])) {
|
||||
Jobs.getCommandManager().sendUsage(sender, "resetexploreregion");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!Jobs.getGCManager().resetExploringData) {
|
||||
sender.sendMessage(Jobs.getLanguage().getMessage("command.resetexploreregion.output.notenabled"));
|
||||
return true;
|
||||
}
|
||||
if (!Jobs.getGCManager().resetExploringData) {
|
||||
sender.sendMessage(Jobs.getLanguage().getMessage("command.resetexploreregion.output.notenabled"));
|
||||
return true;
|
||||
}
|
||||
|
||||
final String worldName = args[1];
|
||||
if(!worldName.matches(REGEX)) {
|
||||
sender.sendMessage(Jobs.getLanguage().getMessage("command.resetexploreregion.output.invalidname"));
|
||||
return true;
|
||||
}
|
||||
final String worldName = args[1];
|
||||
if (!worldName.matches(REGEX)) {
|
||||
sender.sendMessage(Jobs.getLanguage().getMessage("command.resetexploreregion.output.invalidname"));
|
||||
return true;
|
||||
}
|
||||
|
||||
ExploreManager manager = ExploreManager.getInstane();
|
||||
manager.resetRegion(worldName);
|
||||
sender.sendMessage(Jobs.getLanguage().getMessage("command.resetexploreregion.output.reseted", "%worldname%", worldName));
|
||||
return true;
|
||||
Jobs.getExploreManager().resetRegion(worldName);
|
||||
sender.sendMessage(Jobs.getLanguage().getMessage("command.resetexploreregion.output.reseted", "%worldname%", worldName));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -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());
|
||||
|
@ -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;
|
||||
@ -150,18 +139,18 @@ public class ExploreManager {
|
||||
}
|
||||
}
|
||||
|
||||
public void resetRegion(String worldname) {
|
||||
Jobs.consoleMsg("&eReseting explorer data. World: " + worldname);
|
||||
public void resetRegion(String worldname) {
|
||||
Jobs.consoleMsg("&eReseting explorer data. World: " + worldname);
|
||||
|
||||
Map<String, Map<String, ExploreRegion>> worlds = getWorlds();
|
||||
worlds.put(worldname, new HashMap<String, ExploreRegion>());
|
||||
Map<String, Map<String, ExploreRegion>> worlds = getWorlds();
|
||||
worlds.put(worldname, new HashMap<String, ExploreRegion>());
|
||||
|
||||
boolean r = Jobs.getJobsDAO().deleteExploredWorld(worldname);
|
||||
if(!r) {
|
||||
Jobs.consoleMsg("&eFailed in DAO.");
|
||||
return;
|
||||
}
|
||||
|
||||
Jobs.consoleMsg("&eCompleted to reset explorer data.");
|
||||
boolean r = Jobs.getJobsDAO().deleteExploredWorld(worldname);
|
||||
if (!r) {
|
||||
Jobs.consoleMsg("&eFailed in DAO.");
|
||||
return;
|
||||
}
|
||||
|
||||
Jobs.consoleMsg("&eCompleted to reset explorer data.");
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2613,42 +2613,43 @@ public abstract class JobsDAO {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete player-explore information
|
||||
* @param worldName - the world getting removed
|
||||
*/
|
||||
public boolean deleteExploredWorld(String worldName) {
|
||||
if (!Jobs.getExplore().isExploreEnabled())
|
||||
return false;
|
||||
/**
|
||||
* Delete player-explore information
|
||||
* @param worldName - the world getting removed
|
||||
*/
|
||||
public boolean deleteExploredWorld(String worldName) {
|
||||
if (!Jobs.getExploreManager().isExploreEnabled())
|
||||
return false;
|
||||
|
||||
JobsConnection conn = getConnection();
|
||||
if (conn == null)
|
||||
return false;
|
||||
JobsConnection conn = getConnection();
|
||||
if (conn == null)
|
||||
return false;
|
||||
|
||||
JobsWorld target = Util.getJobsWorld(worldName);
|
||||
if (null == target) {
|
||||
return false;
|
||||
}
|
||||
|
||||
PreparedStatement prest = null;
|
||||
try {
|
||||
prest = conn.prepareStatement("DELETE FROM `" + DBTables.ExploreDataTable.getTableName() + "` WHERE `" + ExploreDataTableFields.worldid.getCollumn() + "` = ?;");
|
||||
prest.setInt(1, target.getId());
|
||||
prest.execute();
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
} finally {
|
||||
close(prest);
|
||||
}
|
||||
return true;
|
||||
JobsWorld target = Util.getJobsWorld(worldName);
|
||||
if (null == target) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save player-job information
|
||||
* @param jobInfo - the information getting saved
|
||||
* @return
|
||||
*/
|
||||
boolean res = true;
|
||||
PreparedStatement prest = null;
|
||||
try {
|
||||
prest = conn.prepareStatement("DELETE FROM `" + DBTables.ExploreDataTable.getTableName() + "` WHERE `" + ExploreDataTableFields.worldid.getCollumn() + "` = ?;");
|
||||
prest.setInt(1, target.getId());
|
||||
prest.execute();
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
res = false;
|
||||
} finally {
|
||||
close(prest);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save player-job information
|
||||
* @param jobInfo - the information getting saved
|
||||
* @return
|
||||
*/
|
||||
public List<Integer> getLognameList(int fromtime, int untiltime) {
|
||||
JobsConnection conn = getConnection();
|
||||
List<Integer> nameList = new ArrayList<>();
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user