mirror of
https://github.com/Zrips/Jobs.git
synced 2024-11-26 04:25:15 +01:00
Exploration data recording by using persistent data containers
This commit is contained in:
parent
57003dcb01
commit
a945f55104
Binary file not shown.
@ -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,6 +797,7 @@ public final class Jobs extends JavaPlugin {
|
||||
}
|
||||
|
||||
dao.loadBlockProtection();
|
||||
if (!getGCManager().useNewExploration)
|
||||
getExploreManager().load();
|
||||
getCommandManager().fillCommands();
|
||||
getDBManager().getDB().triggerTableIdUpdate();
|
||||
|
@ -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<String, ExploreRegion> exploreRegion = Jobs.getExploreManager().getWorlds().get(player.getWorld().getName());
|
||||
|
||||
if (exploreRegion == null) {
|
||||
List<Integer> 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<Integer> players = chunk.getPlayers();
|
||||
|
||||
for (int i = 0; i < players.size(); i++) {
|
||||
PlayerInfo ji = Jobs.getPlayerManager().getPlayerInfo(players.get(i));
|
||||
if (ji != null)
|
||||
|
@ -28,6 +28,9 @@ public class resetexploreregion implements Cmd {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (Jobs.getGCManager().useNewExploration) {
|
||||
Jobs.getChunkExplorationManager().resetRegion(worldName);
|
||||
} else
|
||||
Jobs.getExploreManager().resetRegion(worldName);
|
||||
Language.sendMessage(sender, "command.resetexploreregion.output.reseted", "%worldname%", worldName);
|
||||
return true;
|
||||
|
@ -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<Integer> 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<Integer> list = container.getListInt(SUBNAME);
|
||||
|
||||
ExploreRespond response = new ExploreRespond();
|
||||
|
||||
if (list == null || !list.contains(playerId)) {
|
||||
if (list == null)
|
||||
list = new ArrayList<Integer>();
|
||||
else
|
||||
list = new ArrayList<Integer>(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.");
|
||||
}
|
||||
}
|
@ -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());
|
||||
|
@ -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<String, Map<String, ExploreRegion>> worlds = new HashMap<>();
|
||||
@ -42,6 +49,31 @@ public class ExploreManager {
|
||||
exploreEnabled = true;
|
||||
}
|
||||
|
||||
public List<Integer> getVisitors(Chunk chunk) {
|
||||
|
||||
Map<String, ExploreRegion> 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;
|
||||
|
@ -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,
|
||||
@ -424,6 +425,12 @@ public class GeneralConfigManager {
|
||||
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");
|
||||
ExploreCompact = c.get("Optimizations.Explore.Compact", true);
|
||||
|
@ -5,6 +5,7 @@ import java.util.List;
|
||||
|
||||
import com.gamingmesh.jobs.Jobs;
|
||||
|
||||
@Deprecated
|
||||
public class ExploreChunk {
|
||||
|
||||
private List<Integer> playerIds = new ArrayList<>();
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -48,6 +48,19 @@ Explorer:
|
||||
income: 0.1
|
||||
points: 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
|
||||
|
Loading…
Reference in New Issue
Block a user