diff --git a/src/main/java/com/gamingmesh/jobs/Jobs.java b/src/main/java/com/gamingmesh/jobs/Jobs.java index 638c7cae..1273b6a3 100644 --- a/src/main/java/com/gamingmesh/jobs/Jobs.java +++ b/src/main/java/com/gamingmesh/jobs/Jobs.java @@ -846,6 +846,9 @@ public class Jobs extends JavaPlugin { int numjobs = progression.size(); // no job + if (!isBpOk(jPlayer.getPlayer(), info, block, true)) + return; + if (numjobs == 0) { if (noneJob == null) @@ -855,9 +858,6 @@ public class Jobs extends JavaPlugin { if (jobinfo == null) return; - if (!isBpOk(jPlayer, info, block)) - return; - Double income = jobinfo.getIncome(1, numjobs); Double pointAmount = jobinfo.getPoints(1, numjobs); @@ -923,8 +923,6 @@ public class Jobs extends JavaPlugin { if (jobinfo == null) continue; - if (!isBpOk(jPlayer, info, block)) - return; Double income = jobinfo.getIncome(level, numjobs); Double pointAmount = jobinfo.getPoints(level, numjobs); Double expAmount = jobinfo.getExperience(level, numjobs); @@ -1061,36 +1059,61 @@ public class Jobs extends JavaPlugin { } } } - - private static boolean isBpOk(JobsPlayer jPlayer, ActionInfo info, Block block) { - if (block != null && Jobs.getGCManager().useBlockProtection) { - if (info.getType() == ActionType.BREAK || info.getType() == ActionType.PLACE) { - BlockProtection bp = Jobs.getBpManager().getBp(block.getLocation()); - + + private static boolean isBpOk(Player player, ActionInfo info, Block block, boolean inform) { + if ((block != null) && (getGCManager().useBlockProtection)) { + if (info.getType() == ActionType.BREAK) { + BlockProtection bp = getBpManager().getBp(block.getLocation()); if (bp != null) { Long time = bp.getTime(); - if (time == -1) - return false; - - Integer cd = Jobs.getBpManager().getBlockDelayTime(block); - - if (time > System.currentTimeMillis() && bp.isPaid() && bp.getAction() != DBAction.DELETE) { - int sec = Math.round((time - System.currentTimeMillis()) / 1000); - Jobs.getActionBar().send(jPlayer.getPlayer(), - Jobs.getLanguage().getMessage("message.blocktimer", "[time]", sec)); + if (time == -1L) { return false; } - //timer expired + already paid - else if (bp.isPaid()) { - Jobs.getBpManager().remove(block); + Integer cd = getBpManager().getBlockDelayTime(block); + if ((time < System.currentTimeMillis()) && (bp.getAction() != DBAction.DELETE)) { + getBpManager().remove(block); + return true; } + if (((time > System.currentTimeMillis()) || (bp.isPaid().booleanValue())) && (bp.getAction() != DBAction.DELETE)) { + int sec = Math.round((time - System.currentTimeMillis()) / 1000L); + if (inform) { + getActionBar().send(player, getLanguage().getMessage("message.blocktimer", new Object[] { "[time]", Integer.valueOf(sec) })); + } + return false; + } + getBpManager().add(block, cd); + if ((cd == null) && + (getGCManager().useGlobalTimer)) { + getBpManager().add(block, Long.valueOf(System.currentTimeMillis() + getGCManager().globalblocktimer * 1000)); + } + } else if (getGCManager().useGlobalTimer) { + getBpManager().add(block, Long.valueOf(System.currentTimeMillis() + getGCManager().globalblocktimer * 1000)); + } + } else if (info.getType() == ActionType.PLACE) { + BlockProtection bp = getBpManager().getBp(block.getLocation()); + if (bp != null) { + Long time = bp.getTime(); + if (time != -1L) { + if ((time < System.currentTimeMillis()) && (bp.getAction() != DBAction.DELETE)) { + getBpManager().add(block, getBpManager().getBlockDelayTime(block)); + return true; + } + if (((time > System.currentTimeMillis()) || (bp.isPaid().booleanValue())) && (bp.getAction() != DBAction.DELETE)) { + int sec = Math.round((time - System.currentTimeMillis()) / 1000L); - if (cd != null) { - Jobs.getBpManager().add(block, - System.currentTimeMillis() + (Jobs.getGCManager().globalblocktimer * 1000)); - } else { - Jobs.getBpManager().add(block, cd); + Debug.D((time - System.currentTimeMillis()) + " " + bp.isPaid().booleanValue() + bp.getAction()); + + if (inform) { + getActionBar().send(player, getLanguage().getMessage("message.blocktimer", new Object[] { "[time]", Integer.valueOf(sec) })); + } + return false; + } + } else if ((bp.isPaid().booleanValue()) && + (bp.getTime() == -1L) && (getBpManager().getBlockDelayTime(block) != null) && (getBpManager().getBlockDelayTime(block).intValue() == -1)) { + return false; } + } else { + getBpManager().add(block, getBpManager().getBlockDelayTime(block)); } } } diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/bp.java b/src/main/java/com/gamingmesh/jobs/commands/list/bp.java index 06e7e058..538c661e 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/bp.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/bp.java @@ -13,6 +13,7 @@ import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.commands.Cmd; import com.gamingmesh.jobs.commands.JobCommand; import com.gamingmesh.jobs.container.BlockProtection; +import com.gamingmesh.jobs.container.DBAction; public class bp implements Cmd { @@ -39,12 +40,12 @@ public class bp implements Cmd { BlockProtection bp = Jobs.getBpManager().getBp(l); if (bp != null) { Long time = bp.getTime(); -// if (bp.getAction() == DBAction.DELETE) -// continue; -// if (time != -1 && time < System.currentTimeMillis()) { -// Jobs.getBpManager().remove(l); -// continue; -// } + if (bp.getAction() == DBAction.DELETE) + continue; + if (time != -1 && time < System.currentTimeMillis()) { + Jobs.getBpManager().remove(l); + continue; + } changedBlocks.add(l.getBlock()); if (time == -1) player.sendBlockChange(l, Material.STAINED_GLASS, (byte) 15); diff --git a/src/main/java/com/gamingmesh/jobs/config/BlockProtectionManager.java b/src/main/java/com/gamingmesh/jobs/config/BlockProtectionManager.java index 0df49263..8a99c854 100644 --- a/src/main/java/com/gamingmesh/jobs/config/BlockProtectionManager.java +++ b/src/main/java/com/gamingmesh/jobs/config/BlockProtectionManager.java @@ -13,23 +13,24 @@ import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.container.BlockProtection; import com.gamingmesh.jobs.container.DBAction; import com.gamingmesh.jobs.listeners.JobsPaymentListener; +import com.gamingmesh.jobs.stuff.Debug; public class BlockProtectionManager { - private HashMap>>> map = - new HashMap>>>(); + private HashMap>>> map = + new HashMap>>>(); public Long timer = 0L; - public HashMap>>> getMap() { + public HashMap>>> getMap() { return this.map; } public int getSize() { int i = 0; - for (Entry>>> worlds : map.entrySet()) { - for (Entry>> regions : worlds.getValue().entrySet()) { - for (Entry> chunks : regions.getValue().entrySet()) { + for (Entry>>> worlds : map.entrySet()) { + for (Entry>> regions : worlds.getValue().entrySet()) { + for (Entry> chunks : regions.getValue().entrySet()) { i += chunks.getValue().size(); } } @@ -71,23 +72,23 @@ public class BlockProtectionManager { } public BlockProtection add(Location loc, Long time, boolean paid) { - Vector v = new Vector(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()); - HashMap>> regions = map.get(loc.getWorld()); + String v = loc.getBlockX() + ":" + loc.getBlockY() + ":" + loc.getBlockZ(); + HashMap>> regions = map.get(loc.getWorld()); if (regions == null) - regions = new HashMap>>(); + regions = new HashMap>>(); String region = locToRegion(loc); - HashMap> chunks = regions.get(region); + HashMap> chunks = regions.get(region); if (chunks == null) - chunks = new HashMap>(); + chunks = new HashMap>(); String chunk = locToChunk(loc); - HashMap Bpm = chunks.get(chunk); + HashMap Bpm = chunks.get(chunk); if (Bpm == null) - Bpm = new HashMap(); + Bpm = new HashMap(); BlockProtection Bp = Bpm.get(v); if (Bp == null) - Bp = new BlockProtection(DBAction.INSERT); + Bp = new BlockProtection(DBAction.INSERT, new Vector(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ())); else Bp.setAction(DBAction.UPDATE); @@ -105,16 +106,16 @@ public class BlockProtectionManager { } public BlockProtection remove(Location loc) { - HashMap>> world = map.get(loc.getWorld()); + HashMap>> world = map.get(loc.getWorld()); if (world == null) return null; - HashMap> region = world.get(locToRegion(loc)); + HashMap> region = world.get(locToRegion(loc)); if (region == null) return null; - HashMap chunk = region.get(locToChunk(loc)); + HashMap chunk = region.get(locToChunk(loc)); if (chunk == null) return null; - Vector v = new Vector(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()); + String v = loc.getBlockX() + ":" + loc.getBlockY() + ":" + loc.getBlockZ(); BlockProtection bp = chunk.get(v); if (bp != null) bp.setAction(DBAction.DELETE); @@ -133,19 +134,25 @@ public class BlockProtectionManager { } public BlockProtection getBp(Location loc) { - HashMap>> world = map.get(loc.getWorld()); + HashMap>> world = map.get(loc.getWorld()); if (world == null) return null; - HashMap> region = world.get(locToRegion(loc)); + HashMap> region = world.get(locToRegion(loc)); if (region == null) return null; - HashMap chunk = region.get(locToChunk(loc)); + HashMap chunk = region.get(locToChunk(loc)); if (chunk == null) return null; - Vector v = new Vector(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()); + String v = loc.getBlockX() + ":" + loc.getBlockY() + ":" + loc.getBlockZ(); BlockProtection Bp = chunk.get(v); + if (Bp == null) return null; + Debug.D("by " + v); + Debug.D("got " + Bp.getPos().toString()); + for (Entry one : chunk.entrySet()) { + Debug.D("g " + one.getKey()); + } return Bp; } diff --git a/src/main/java/com/gamingmesh/jobs/config/GeneralConfigManager.java b/src/main/java/com/gamingmesh/jobs/config/GeneralConfigManager.java index b3d5c0ef..9d4cd041 100644 --- a/src/main/java/com/gamingmesh/jobs/config/GeneralConfigManager.java +++ b/src/main/java/com/gamingmesh/jobs/config/GeneralConfigManager.java @@ -499,7 +499,7 @@ public class GeneralConfigManager { c.getW().addComment("broadcast.on-level-up.levels", "For what levels you want to broadcast message? Keep it at 0 if you want for all of them"); BroadcastingLevelUpLevels = c.getIntList("broadcast.on-level-up.levels", Arrays.asList(0)); - c.getW().addComment("max-jobs", "Maximum number of jobs a player can join.", "Use 0 for no maximum"); + c.getW().addComment("max-jobs", "Maximum number of jobs a player can join.", "Use 0 for no maximum", "Keep in mind that jobs.max.[amount] will bypass this setting"); maxJobs = c.get("max-jobs", 3); c.getW().addComment("hide-jobs-without-permission", "Hide jobs from player if they lack the permission to join the job"); diff --git a/src/main/java/com/gamingmesh/jobs/container/BlockProtection.java b/src/main/java/com/gamingmesh/jobs/container/BlockProtection.java index e8f0cc17..4a2b743c 100644 --- a/src/main/java/com/gamingmesh/jobs/container/BlockProtection.java +++ b/src/main/java/com/gamingmesh/jobs/container/BlockProtection.java @@ -1,5 +1,7 @@ package com.gamingmesh.jobs.container; +import org.bukkit.util.Vector; + public class BlockProtection { private int id; @@ -7,12 +9,15 @@ public class BlockProtection { private Long recorded; private DBAction action = DBAction.INSERT; private Boolean paid = true; + private Vector pos; - public BlockProtection() { + public BlockProtection(Vector pos) { + this.pos = pos; } - public BlockProtection(DBAction action) { + public BlockProtection(DBAction action, Vector pos) { this.action = action; + this.pos = pos; } public Long getTime() { @@ -55,4 +60,12 @@ public class BlockProtection { public void setId(int id) { this.id = id; } + + public Vector getPos() { + return pos; + } + + public void setPos(Vector pos) { + this.pos = pos; + } } diff --git a/src/main/java/com/gamingmesh/jobs/dao/JobsDAO.java b/src/main/java/com/gamingmesh/jobs/dao/JobsDAO.java index 3b350846..efba12ea 100644 --- a/src/main/java/com/gamingmesh/jobs/dao/JobsDAO.java +++ b/src/main/java/com/gamingmesh/jobs/dao/JobsDAO.java @@ -1133,10 +1133,10 @@ public abstract class JobsDAO { Long mark = System.currentTimeMillis() - (Jobs.getGCManager().BlockProtectionDays * 24L * 60L * 60L * 1000L); ConsoleCommandSender console = Bukkit.getServer().getConsoleSender(); - for (Entry>>> worlds : Jobs.getBpManager().getMap().entrySet()) { - for (Entry>> regions : worlds.getValue().entrySet()) { - for (Entry> chunks : regions.getValue().entrySet()) { - for (Entry block : chunks.getValue().entrySet()) { + for (Entry>>> worlds : Jobs.getBpManager().getMap().entrySet()) { + for (Entry>> regions : worlds.getValue().entrySet()) { + for (Entry> chunks : regions.getValue().entrySet()) { + for (Entry block : chunks.getValue().entrySet()) { if (block.getValue() == null) continue; switch (block.getValue().getAction()) { @@ -1155,9 +1155,9 @@ public abstract class JobsDAO { if (block.getValue().getTime() < current && block.getValue().getTime() != -1) continue; insert.setString(1, worlds.getKey().getName()); - insert.setInt(2, block.getKey().getBlockX()); - insert.setInt(3, block.getKey().getBlockY()); - insert.setInt(4, block.getKey().getBlockZ()); + insert.setInt(2, block.getValue().getPos().getBlockX()); + insert.setInt(3, block.getValue().getPos().getBlockY()); + insert.setInt(4, block.getValue().getPos().getBlockZ()); insert.setLong(5, block.getValue().getRecorded()); insert.setLong(6, block.getValue().getTime()); insert.addBatch(); diff --git a/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java b/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java index 4236b158..b26cbd73 100644 --- a/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java +++ b/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java @@ -333,12 +333,6 @@ public class JobsPaymentListener implements Listener { if (!Jobs.getPermissionHandler().hasWorldPermission(player, player.getLocation().getWorld().getName())) return; - if (Jobs.getGCManager().useBlockProtection) { - BlockProtection bp = Jobs.getBpManager().getBp(block.getLocation()); - if (bp == null || bp.getAction() == DBAction.DELETE) - Jobs.getBpManager().add(block, Jobs.getBpManager().getBlockDelayTime(block), false); - } - JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(player); if (jPlayer == null) return;