mirror of
https://github.com/Zrips/Jobs.git
synced 2024-12-30 21:07:48 +01:00
Fix for BP?
This commit is contained in:
parent
fcfd3435ee
commit
eda39ed0d3
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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<World, HashMap<String, HashMap<String, HashMap<Vector, BlockProtection>>>> map =
|
||||
new HashMap<World, HashMap<String, HashMap<String, HashMap<Vector, BlockProtection>>>>();
|
||||
private HashMap<World, HashMap<String, HashMap<String, HashMap<String, BlockProtection>>>> map =
|
||||
new HashMap<World, HashMap<String, HashMap<String, HashMap<String, BlockProtection>>>>();
|
||||
|
||||
public Long timer = 0L;
|
||||
|
||||
public HashMap<World, HashMap<String, HashMap<String, HashMap<Vector, BlockProtection>>>> getMap() {
|
||||
public HashMap<World, HashMap<String, HashMap<String, HashMap<String, BlockProtection>>>> getMap() {
|
||||
return this.map;
|
||||
}
|
||||
|
||||
public int getSize() {
|
||||
int i = 0;
|
||||
for (Entry<World, HashMap<String, HashMap<String, HashMap<Vector, BlockProtection>>>> worlds : map.entrySet()) {
|
||||
for (Entry<String, HashMap<String, HashMap<Vector, BlockProtection>>> regions : worlds.getValue().entrySet()) {
|
||||
for (Entry<String, HashMap<Vector, BlockProtection>> chunks : regions.getValue().entrySet()) {
|
||||
for (Entry<World, HashMap<String, HashMap<String, HashMap<String, BlockProtection>>>> worlds : map.entrySet()) {
|
||||
for (Entry<String, HashMap<String, HashMap<String, BlockProtection>>> regions : worlds.getValue().entrySet()) {
|
||||
for (Entry<String, HashMap<String, BlockProtection>> 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<String, HashMap<String, HashMap<Vector, BlockProtection>>> regions = map.get(loc.getWorld());
|
||||
String v = loc.getBlockX() + ":" + loc.getBlockY() + ":" + loc.getBlockZ();
|
||||
HashMap<String, HashMap<String, HashMap<String, BlockProtection>>> regions = map.get(loc.getWorld());
|
||||
if (regions == null)
|
||||
regions = new HashMap<String, HashMap<String, HashMap<Vector, BlockProtection>>>();
|
||||
regions = new HashMap<String, HashMap<String, HashMap<String, BlockProtection>>>();
|
||||
String region = locToRegion(loc);
|
||||
HashMap<String, HashMap<Vector, BlockProtection>> chunks = regions.get(region);
|
||||
HashMap<String, HashMap<String, BlockProtection>> chunks = regions.get(region);
|
||||
if (chunks == null)
|
||||
chunks = new HashMap<String, HashMap<Vector, BlockProtection>>();
|
||||
chunks = new HashMap<String, HashMap<String, BlockProtection>>();
|
||||
String chunk = locToChunk(loc);
|
||||
HashMap<Vector, BlockProtection> Bpm = chunks.get(chunk);
|
||||
HashMap<String, BlockProtection> Bpm = chunks.get(chunk);
|
||||
if (Bpm == null)
|
||||
Bpm = new HashMap<Vector, BlockProtection>();
|
||||
Bpm = new HashMap<String, BlockProtection>();
|
||||
|
||||
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<String, HashMap<String, HashMap<Vector, BlockProtection>>> world = map.get(loc.getWorld());
|
||||
HashMap<String, HashMap<String, HashMap<String, BlockProtection>>> world = map.get(loc.getWorld());
|
||||
if (world == null)
|
||||
return null;
|
||||
HashMap<String, HashMap<Vector, BlockProtection>> region = world.get(locToRegion(loc));
|
||||
HashMap<String, HashMap<String, BlockProtection>> region = world.get(locToRegion(loc));
|
||||
if (region == null)
|
||||
return null;
|
||||
HashMap<Vector, BlockProtection> chunk = region.get(locToChunk(loc));
|
||||
HashMap<String, BlockProtection> 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<String, HashMap<String, HashMap<Vector, BlockProtection>>> world = map.get(loc.getWorld());
|
||||
HashMap<String, HashMap<String, HashMap<String, BlockProtection>>> world = map.get(loc.getWorld());
|
||||
if (world == null)
|
||||
return null;
|
||||
HashMap<String, HashMap<Vector, BlockProtection>> region = world.get(locToRegion(loc));
|
||||
HashMap<String, HashMap<String, BlockProtection>> region = world.get(locToRegion(loc));
|
||||
if (region == null)
|
||||
return null;
|
||||
HashMap<Vector, BlockProtection> chunk = region.get(locToChunk(loc));
|
||||
HashMap<String, BlockProtection> 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<String, BlockProtection> one : chunk.entrySet()) {
|
||||
Debug.D("g " + one.getKey());
|
||||
}
|
||||
return Bp;
|
||||
}
|
||||
|
||||
|
@ -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");
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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<World, HashMap<String, HashMap<String, HashMap<Vector, BlockProtection>>>> worlds : Jobs.getBpManager().getMap().entrySet()) {
|
||||
for (Entry<String, HashMap<String, HashMap<Vector, BlockProtection>>> regions : worlds.getValue().entrySet()) {
|
||||
for (Entry<String, HashMap<Vector, BlockProtection>> chunks : regions.getValue().entrySet()) {
|
||||
for (Entry<Vector, BlockProtection> block : chunks.getValue().entrySet()) {
|
||||
for (Entry<World, HashMap<String, HashMap<String, HashMap<String, BlockProtection>>>> worlds : Jobs.getBpManager().getMap().entrySet()) {
|
||||
for (Entry<String, HashMap<String, HashMap<String, BlockProtection>>> regions : worlds.getValue().entrySet()) {
|
||||
for (Entry<String, HashMap<String, BlockProtection>> chunks : regions.getValue().entrySet()) {
|
||||
for (Entry<String, BlockProtection> 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();
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user