diff --git a/libs/CMILib1.5.0.2.jar b/libs/CMILib1.5.0.3.jar similarity index 91% rename from libs/CMILib1.5.0.2.jar rename to libs/CMILib1.5.0.3.jar index 52aab659..22309199 100644 Binary files a/libs/CMILib1.5.0.2.jar and b/libs/CMILib1.5.0.3.jar differ diff --git a/src/main/java/com/gamingmesh/jobs/Jobs.java b/src/main/java/com/gamingmesh/jobs/Jobs.java index 6aa25b62..6c85949f 100644 --- a/src/main/java/com/gamingmesh/jobs/Jobs.java +++ b/src/main/java/com/gamingmesh/jobs/Jobs.java @@ -49,6 +49,7 @@ import com.gamingmesh.jobs.api.JobsPrePaymentEvent; import com.gamingmesh.jobs.commands.JobsCommands; import com.gamingmesh.jobs.config.BlockProtectionManager; import com.gamingmesh.jobs.config.BossBarManager; +import com.gamingmesh.jobs.config.ChunkExplorationManager; import com.gamingmesh.jobs.config.ConfigManager; import com.gamingmesh.jobs.config.ExploitProtectionManager; import com.gamingmesh.jobs.config.ExploreManager; @@ -133,13 +134,16 @@ public final class Jobs extends JavaPlugin { private static SignUtil signManager; private static ScheduleManager scheduleManager; private static NameTranslatorManager nameTranslatorManager; + @Deprecated private static ExploreManager exploreManager; + private static ChunkExplorationManager chunkExplorationManager; private static TitleManager titleManager; private static RestrictedBlockManager rbManager; private static RestrictedAreaManager raManager; private static BossBarManager bbManager; private static ShopManager shopManager; private static Loging loging; + @Deprecated private static BlockProtectionManager bpManager; private static ExploitProtectionManager exploitManager; private static JobsManager dbManager; @@ -405,12 +409,19 @@ public final class Jobs extends JavaPlugin { return getExploreManager(); } + @Deprecated public static ExploreManager getExploreManager() { if (exploreManager == null) exploreManager = new ExploreManager(); return exploreManager; } + public static ChunkExplorationManager getChunkExplorationManager() { + if (chunkExplorationManager == null) + chunkExplorationManager = new ChunkExplorationManager(); + return chunkExplorationManager; + } + /** * @return returns this class object instance */ @@ -786,7 +797,8 @@ public final class Jobs extends JavaPlugin { } dao.loadBlockProtection(); - getExploreManager().load(); + if (!getGCManager().useNewExploration) + getExploreManager().load(); getCommandManager().fillCommands(); getDBManager().getDB().triggerTableIdUpdate(); @@ -820,7 +832,7 @@ public final class Jobs extends JavaPlugin { if (Version.isCurrentEqualOrHigher(Version.v1_20_R1)) { pm.registerEvents(new PlayerSignEdit1_20Listeners(), getInstance()); - pm.registerEvents(new JobsPayment1_20Listener(), getInstance()); + pm.registerEvents(new JobsPayment1_20Listener(), getInstance()); } if (getGCManager().useBlockProtection) { diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/explored.java b/src/main/java/com/gamingmesh/jobs/commands/list/explored.java index aaa046aa..ab678c8c 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/explored.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/explored.java @@ -1,14 +1,12 @@ package com.gamingmesh.jobs.commands.list; -import java.util.Map; +import java.util.List; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.commands.Cmd; -import com.gamingmesh.jobs.container.ExploreChunk; -import com.gamingmesh.jobs.container.ExploreRegion; import com.gamingmesh.jobs.container.PlayerInfo; import com.gamingmesh.jobs.i18n.Language; @@ -24,35 +22,25 @@ public class explored implements Cmd { } Player player = (Player) sender; - Map exploreRegion = Jobs.getExploreManager().getWorlds().get(player.getWorld().getName()); - if (exploreRegion == null) { + List players = null; + + if (Jobs.getGCManager().useNewExploration) { + players = Jobs.getChunkExplorationManager().getVisitors(player.getLocation().getChunk()); + } else { + players = Jobs.getExploreManager().getVisitors(player.getLocation().getChunk()); + } + + if (players == null) { Language.sendMessage(sender, "command.explored.error.noexplore"); return true; } - int RegionX = (int) Math.floor(player.getLocation().getChunk().getX() / 32D); - int RegionZ = (int) Math.floor(player.getLocation().getChunk().getZ() / 32D); - ExploreRegion region = exploreRegion.get(RegionX + ":" + RegionZ); - if (region == null) { + if (players.isEmpty()) { Language.sendMessage(sender, "command.explored.error.noexplore"); return true; } - ExploreChunk chunk = region.getChunk(player.getLocation().getChunk()); - - if (chunk == null) { - Language.sendMessage(sender, "command.explored.error.noexplore"); - return true; - } - - if (Jobs.getGCManager().ExploreCompact && chunk.isFullyExplored()) { - Language.sendMessage(sender, "command.explored.fullExplore"); - return true; - } - - java.util.List players = chunk.getPlayers(); - for (int i = 0; i < players.size(); i++) { PlayerInfo ji = Jobs.getPlayerManager().getPlayerInfo(players.get(i)); if (ji != null) diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/resetexploreregion.java b/src/main/java/com/gamingmesh/jobs/commands/list/resetexploreregion.java index 1d08d370..ad326f4a 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/resetexploreregion.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/resetexploreregion.java @@ -28,7 +28,10 @@ public class resetexploreregion implements Cmd { return true; } - Jobs.getExploreManager().resetRegion(worldName); + if (Jobs.getGCManager().useNewExploration) { + Jobs.getChunkExplorationManager().resetRegion(worldName); + } else + Jobs.getExploreManager().resetRegion(worldName); Language.sendMessage(sender, "command.resetexploreregion.output.reseted", "%worldname%", worldName); return true; } diff --git a/src/main/java/com/gamingmesh/jobs/config/ChunkExplorationManager.java b/src/main/java/com/gamingmesh/jobs/config/ChunkExplorationManager.java new file mode 100644 index 00000000..e148f61b --- /dev/null +++ b/src/main/java/com/gamingmesh/jobs/config/ChunkExplorationManager.java @@ -0,0 +1,79 @@ +package com.gamingmesh.jobs.config; + +import java.util.ArrayList; +import java.util.List; + +import org.bukkit.Chunk; +import org.bukkit.entity.Player; +import org.jetbrains.annotations.Nullable; + +import com.gamingmesh.jobs.Jobs; +import com.gamingmesh.jobs.container.ExploreRespond; + +import net.Zrips.CMILib.Messages.CMIMessages; +import net.Zrips.CMILib.PersistentData.CMIChunkPersistentDataContainer; + +public class ChunkExplorationManager { + + private static final String NAME = "JobsExplore"; + private static final String SUBNAME = "Explorers"; + + private boolean exploreEnabled = false; + private int playerAmount = 1; + + public int getPlayerAmount() { + return playerAmount; + } + + public void setPlayerAmount(int amount) { + if (playerAmount < amount) + playerAmount = amount; + } + + public boolean isExploreEnabled() { + return exploreEnabled; + } + + public void setExploreEnabled() { + exploreEnabled = true; + } + + public List getVisitors(Chunk chunk) { + return new CMIChunkPersistentDataContainer(NAME, chunk).getListInt(SUBNAME); + } + + public ExploreRespond chunkRespond(Player player, Chunk chunk) { + return chunkRespond(Jobs.getPlayerManager().getJobsPlayer(player).getUserId(), chunk); + } + + public ExploreRespond chunkRespond(int playerId, Chunk chunk) { + + CMIChunkPersistentDataContainer container = new CMIChunkPersistentDataContainer(NAME, chunk); + + @Nullable + List list = container.getListInt(SUBNAME); + + ExploreRespond response = new ExploreRespond(); + + if (list == null || !list.contains(playerId)) { + if (list == null) + list = new ArrayList(); + else + list = new ArrayList(list); + list.add(playerId); + container.setIntList(SUBNAME, list); + container.save(); + response.setNewChunk(true); + } + + response.setCount(list.size()); + + return response; + } + + public void resetRegion(String worldname) { + CMIMessages.consoleMessage("&eReseting explorer data. World: " + worldname); +// Needs to pick new way of tracking data + CMIMessages.consoleMessage("&eCompleted to reset explorer data."); + } +} diff --git a/src/main/java/com/gamingmesh/jobs/config/ConfigManager.java b/src/main/java/com/gamingmesh/jobs/config/ConfigManager.java index 74994665..26642062 100644 --- a/src/main/java/com/gamingmesh/jobs/config/ConfigManager.java +++ b/src/main/java/com/gamingmesh/jobs/config/ConfigManager.java @@ -813,6 +813,10 @@ public class ConfigManager { Jobs.getExploreManager().setExploreEnabled(); Jobs.getExploreManager().setPlayerAmount(amount); + + Jobs.getChunkExplorationManager().setExploreEnabled(); + Jobs.getChunkExplorationManager().setPlayerAmount(amount); + } else if (actionType == ActionType.CRAFT) { if (myKey.startsWith("!")) { type = myKey.substring(1, myKey.length()); diff --git a/src/main/java/com/gamingmesh/jobs/config/ExploreManager.java b/src/main/java/com/gamingmesh/jobs/config/ExploreManager.java index 1b0d62fd..3cff6fb0 100644 --- a/src/main/java/com/gamingmesh/jobs/config/ExploreManager.java +++ b/src/main/java/com/gamingmesh/jobs/config/ExploreManager.java @@ -2,12 +2,16 @@ package com.gamingmesh.jobs.config; import java.sql.ResultSet; import java.sql.SQLException; +import java.util.Collections; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.Map.Entry; import org.bukkit.Chunk; import org.bukkit.entity.Player; +import org.bukkit.persistence.PersistentDataType; +import org.jetbrains.annotations.Nullable; import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.container.ExploreChunk; @@ -15,10 +19,13 @@ import com.gamingmesh.jobs.container.ExploreRegion; import com.gamingmesh.jobs.container.ExploreRespond; import com.gamingmesh.jobs.container.JobsWorld; import com.gamingmesh.jobs.dao.JobsDAO.ExploreDataTableFields; +import com.gamingmesh.jobs.i18n.Language; import com.gamingmesh.jobs.stuff.Util; import net.Zrips.CMILib.Messages.CMIMessages; +import net.Zrips.CMILib.PersistentData.CMIChunkPersistentDataContainer; +@Deprecated public class ExploreManager { private final Map> worlds = new HashMap<>(); @@ -42,6 +49,31 @@ public class ExploreManager { exploreEnabled = true; } + public List getVisitors(Chunk chunk) { + + Map exploreRegion = worlds.get(chunk.getWorld().getName()); + + if (exploreRegion == null) + return null; + + int RegionX = (int) Math.floor(chunk.getX() / 32D); + int RegionZ = (int) Math.floor(chunk.getZ() / 32D); + ExploreRegion region = exploreRegion.get(RegionX + ":" + RegionZ); + if (region == null) + return null; + + ExploreChunk echunk = region.getChunk(chunk); + + if (echunk == null) + return null; + + if (Jobs.getGCManager().ExploreCompact && echunk.isFullyExplored()) { + return Collections.emptyList(); + } + + return echunk.getPlayers(); + } + public void load() { if (!exploreEnabled) return; diff --git a/src/main/java/com/gamingmesh/jobs/config/GeneralConfigManager.java b/src/main/java/com/gamingmesh/jobs/config/GeneralConfigManager.java index b25c9c28..008eff9d 100644 --- a/src/main/java/com/gamingmesh/jobs/config/GeneralConfigManager.java +++ b/src/main/java/com/gamingmesh/jobs/config/GeneralConfigManager.java @@ -93,7 +93,8 @@ public class GeneralConfigManager { private FireworkEffect fireworkEffect; - public boolean ignoreOreGenerators, useBlockProtection, useNewBlockProtection, useBlockProtectionBlockTracker, enableSchedule, PayForRenaming, PayForEnchantingOnAnvil, PayForEachCraft, SignsEnabled, + public boolean ignoreOreGenerators, useBlockProtection, useNewBlockProtection, useNewExploration, useBlockProtectionBlockTracker, enableSchedule, PayForRenaming, PayForEnchantingOnAnvil, + PayForEachCraft, SignsEnabled, SignsColorizeJobName, ShowToplistInScoreboard, useGlobalTimer, useSilkTouchProtection, UseCustomNames, PreventSlimeSplit, PreventMagmaCubeSplit, PreventHopperFillUps, PreventBrewingStandFillUps, informOnPaymentDisable, BrowseUseNewLook, payExploringWhenGliding = false, resetExploringData = false, disablePaymentIfMaxLevelReached, disablePaymentIfRiding, @@ -423,6 +424,12 @@ public class GeneralConfigManager { UseAsWhiteListWorldList = c.get("Optimizations.DisabledWorlds.UseAsWhiteList", false); DisabledWorldsList = c.get("Optimizations.DisabledWorlds.List", Arrays.asList("Example", "Worlds")); CMIList.toLowerCase(DisabledWorldsList); + + if (Version.isCurrentEqualOrHigher(Version.v1_14_R1)) { + c.addComment("Optimizations.Explore.NewMethod", + "Do you want to use new exploration tracking method. Only for 1.14+ servers"); + useNewExploration = c.get("Optimizations.Explore.NewMethod", true); + } 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"); diff --git a/src/main/java/com/gamingmesh/jobs/container/ExploreChunk.java b/src/main/java/com/gamingmesh/jobs/container/ExploreChunk.java index d0df0e49..76fe6f1f 100644 --- a/src/main/java/com/gamingmesh/jobs/container/ExploreChunk.java +++ b/src/main/java/com/gamingmesh/jobs/container/ExploreChunk.java @@ -5,6 +5,7 @@ import java.util.List; import com.gamingmesh.jobs.Jobs; +@Deprecated public class ExploreChunk { private List playerIds = new ArrayList<>(); diff --git a/src/main/java/com/gamingmesh/jobs/container/ExploreRespond.java b/src/main/java/com/gamingmesh/jobs/container/ExploreRespond.java index b55c642c..70104923 100644 --- a/src/main/java/com/gamingmesh/jobs/container/ExploreRespond.java +++ b/src/main/java/com/gamingmesh/jobs/container/ExploreRespond.java @@ -2,9 +2,12 @@ package com.gamingmesh.jobs.container; public class ExploreRespond { - private int count; + private int count = 0; private boolean newChunk = false; + public ExploreRespond() { + } + public ExploreRespond(int count, boolean newChunk) { this.count = count; this.newChunk = newChunk; @@ -17,4 +20,12 @@ public class ExploreRespond { public boolean isNewChunk() { return newChunk; } + + public void setCount(int count) { + this.count = count; + } + + public void setNewChunk(boolean newChunk) { + this.newChunk = newChunk; + } } diff --git a/src/main/java/com/gamingmesh/jobs/dao/JobsDAO.java b/src/main/java/com/gamingmesh/jobs/dao/JobsDAO.java index 99d11815..bcfea717 100644 --- a/src/main/java/com/gamingmesh/jobs/dao/JobsDAO.java +++ b/src/main/java/com/gamingmesh/jobs/dao/JobsDAO.java @@ -2467,7 +2467,7 @@ public abstract class JobsDAO { public void loadBlockProtection() { if (Jobs.getGCManager().useNewBlockProtection) return; - + JobsConnection conn = getConnection(); if (conn == null) return; @@ -2555,6 +2555,9 @@ public abstract class JobsDAO { if (!Jobs.getExploreManager().isExploreEnabled()) return; + if (Jobs.getGCManager().useNewExploration) + return; + JobsConnection conn = getConnection(); if (conn == null) return; @@ -2580,7 +2583,7 @@ public abstract class JobsDAO { int id = jobsWorld == null ? 0 : jobsWorld.getId(); if (id == 0) continue; - + for (Entry region : worlds.getValue().entrySet()) { for (Entry oneChunk : region.getValue().getChunks().entrySet()) { ExploreChunk chunk = oneChunk.getValue(); @@ -2620,6 +2623,9 @@ public abstract class JobsDAO { if (!Jobs.getExploreManager().isExploreEnabled()) return; + if (Jobs.getGCManager().useNewExploration) + return; + JobsConnection conn = getConnection(); if (conn == null) return; @@ -2672,6 +2678,9 @@ public abstract class JobsDAO { if (!Jobs.getExploreManager().isExploreEnabled()) return; + if (Jobs.getGCManager().useNewExploration) + return; + JobsConnection conn = getConnection(); if (conn == null) return; @@ -2723,6 +2732,9 @@ public abstract class JobsDAO { if (!Jobs.getExploreManager().isExploreEnabled()) return false; + if (Jobs.getGCManager().useNewExploration) + return false; + JobsConnection conn = getConnection(); if (conn == null) return false; diff --git a/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java b/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java index 4300470b..4cc43fbd 100644 --- a/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java +++ b/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java @@ -134,6 +134,7 @@ import net.Zrips.CMILib.Items.CMIItemStack; import net.Zrips.CMILib.Items.CMIMC; import net.Zrips.CMILib.Items.CMIMaterial; import net.Zrips.CMILib.Locale.LC; +import net.Zrips.CMILib.Logs.CMIDebug; import net.Zrips.CMILib.Messages.CMIMessages; import net.Zrips.CMILib.Version.Version; import net.Zrips.CMILib.Version.Schedulers.CMIScheduler; @@ -1875,7 +1876,7 @@ public final class JobsPaymentListener implements Listener { @EventHandler(ignoreCancelled = true) public void onExplore(JobsChunkChangeEvent event) { - if (!Jobs.getExploreManager().isExploreEnabled()) + if (!Jobs.getChunkExplorationManager().isExploreEnabled()) return; Player player = event.getPlayer(); @@ -1910,7 +1911,12 @@ public final class JobsPaymentListener implements Listener { if (jPlayer == null) return; - ExploreRespond respond = Jobs.getExploreManager().chunkRespond(jPlayer.getUserId(), event.getNewChunk()); + ExploreRespond respond = null; + + if (Jobs.getGCManager().useNewExploration) + respond = Jobs.getChunkExplorationManager().chunkRespond(jPlayer.getUserId(), event.getNewChunk()); + else + respond = Jobs.getExploreManager().chunkRespond(jPlayer.getUserId(), event.getNewChunk()); if (!respond.isNewChunk()) return; diff --git a/src/main/resources/jobs/explorer.yml b/src/main/resources/jobs/explorer.yml index fb9cc356..2d47147f 100644 --- a/src/main/resources/jobs/explorer.yml +++ b/src/main/resources/jobs/explorer.yml @@ -47,7 +47,20 @@ Explorer: '5': income: 0.1 points: 0.1 - experience: 0.1 + experience: 0.1 + Brush: + 'suspicious_sand': + income: 5 + points: 5 + experience: 5 + 'suspicious_gravel': + income: 6 + points: 6 + experience: 6 + coal: + income: 10 + points: 10 + experience: 10 Kill: Player: income: 7.5