1
0
mirror of https://github.com/Zrips/Jobs.git synced 2025-01-20 07:01:22 +01:00

Lets store less data in cache for block protection

This commit is contained in:
Zrips 2020-05-06 14:25:17 +03:00
parent 338d306fe7
commit 0d89f170f1
3 changed files with 87 additions and 35 deletions

View File

@ -7,20 +7,18 @@ import java.util.concurrent.ConcurrentHashMap;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.util.Vector;
import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.Jobs;
import com.gamingmesh.jobs.CMILib.CMIMaterial; import com.gamingmesh.jobs.CMILib.CMIMaterial;
import com.gamingmesh.jobs.container.BlockProtection; import com.gamingmesh.jobs.container.BlockProtection;
import com.gamingmesh.jobs.container.DBAction; import com.gamingmesh.jobs.container.DBAction;
import com.gamingmesh.jobs.stuff.Debug;
public class BlockProtectionManager { public class BlockProtectionManager {
private HashMap<World, HashMap<String, HashMap<String, HashMap<String, BlockProtection>>>> map = new HashMap<>(); private HashMap<World, HashMap<String, HashMap<String, HashMap<String, BlockProtection>>>> map = new HashMap<>();
private ConcurrentHashMap<World, ConcurrentHashMap<String, BlockProtection>> tempCache = new ConcurrentHashMap<>(); private ConcurrentHashMap<World, ConcurrentHashMap<String, BlockProtection>> tempCache = new ConcurrentHashMap<>();
public Long timer = 0L;
public HashMap<World, HashMap<String, HashMap<String, HashMap<String, BlockProtection>>>> getMap() { public HashMap<World, HashMap<String, HashMap<String, HashMap<String, BlockProtection>>>> getMap() {
return this.map; return this.map;
} }
@ -71,7 +69,7 @@ public class BlockProtectionManager {
BlockProtection Bp = Bpm.get(v); BlockProtection Bp = Bpm.get(v);
if (Bp == null) if (Bp == null)
Bp = new BlockProtection(DBAction.INSERT, new Vector(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ())); Bp = new BlockProtection(DBAction.INSERT, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
else else
Bp.setAction(DBAction.UPDATE); Bp.setAction(DBAction.UPDATE);
@ -175,8 +173,10 @@ public class BlockProtectionManager {
public Integer getBlockDelayTime(Block block) { public Integer getBlockDelayTime(Block block) {
Integer time = Jobs.getRestrictedBlockManager().restrictedBlocksTimer.get(CMIMaterial.get(block)); Integer time = Jobs.getRestrictedBlockManager().restrictedBlocksTimer.get(CMIMaterial.get(block));
if (time == null && Jobs.getGCManager().useGlobalTimer) if (time == null && Jobs.getGCManager().useGlobalTimer) {
Debug.D("using global " + block.getType());
time = Jobs.getGCManager().globalblocktimer; time = Jobs.getGCManager().globalblocktimer;
}
return time; return time;
} }

View File

@ -4,53 +4,84 @@ import org.bukkit.util.Vector;
public class BlockProtection { public class BlockProtection {
private static long pre = (int) (System.currentTimeMillis() / 10000000000L) * 10000000000L;
private int id; private int id;
private Long time; private Integer time;
private Long recorded; private Integer recorded;
private DBAction action = DBAction.INSERT; private DBAction action;
private Boolean paid = true; private Boolean paid;
private Vector pos; private int x = 0;
private int y = 0;
private int z = 0;
public BlockProtection(Vector pos) { public BlockProtection(Vector pos) {
this.pos = pos; this(DBAction.INSERT, pos);
} }
@Deprecated
public BlockProtection(DBAction action, Vector pos) { public BlockProtection(DBAction action, Vector pos) {
this(action, pos.getBlockX(), pos.getBlockY(), pos.getBlockZ());
}
public BlockProtection(DBAction action, int x, int y, int z) {
this.action = action; this.action = action;
this.pos = pos; if (action == DBAction.NONE)
action = null;
this.x = x;
this.y = y;
this.z = z;
} }
public Long getTime() { public Long getTime() {
return time; return deconvert(time);
}
private static int convert(long time) {
if (time == -1L)
return -1;
return (int) ((time - pre) / 1000L);
}
private static Long deconvert(Integer time) {
return time == null ? -1L : ((time.longValue() * 1000L) + pre);
} }
public void setTime(Long time) { public void setTime(Long time) {
this.time = time; if (time == -1)
this.recorded = System.currentTimeMillis(); this.time = null;
else
this.time = convert(time);
this.recorded = convert(System.currentTimeMillis());
} }
public DBAction getAction() { public DBAction getAction() {
return action; return action == null ? DBAction.NONE : action;
} }
public void setAction(DBAction action) { public void setAction(DBAction action) {
if (action == DBAction.NONE)
action = null;
this.action = action; this.action = action;
} }
public Long getRecorded() { public Long getRecorded() {
return recorded; return deconvert(recorded);
} }
public Boolean isPaid() { public Boolean isPaid() {
return paid; return paid == null ? true : paid;
} }
public void setPaid(Boolean paid) { public void setPaid(Boolean paid) {
this.paid = paid; if (!paid)
this.paid = paid;
else
this.paid = null;
} }
public void setRecorded(Long recorded) { public void setRecorded(Long recorded) {
this.recorded = recorded; this.recorded = convert(recorded);
} }
public int getId() { public int getId() {
@ -61,11 +92,33 @@ public class BlockProtection {
this.id = id; this.id = id;
} }
@Deprecated
public Vector getPos() { public Vector getPos() {
return pos; return new Vector(x, y, z);
} }
@Deprecated
public void setPos(Vector pos) { public void setPos(Vector pos) {
this.pos = pos; x = pos.getBlockX();
y = pos.getBlockY();
z = pos.getBlockZ();
}
public void setPos(int x, int y, int z) {
this.x = x;
this.y = y;
this.z = z;
}
public int getX() {
return x;
}
public int getY() {
return y;
}
public int getZ() {
return z;
} }
} }

View File

@ -1749,12 +1749,12 @@ public abstract class JobsDAO {
long seen = res.getLong(UserTableFields.seen.getCollumn()); long seen = res.getLong(UserTableFields.seen.getCollumn());
Jobs.getPlayerManager().addPlayerToMap(new PlayerInfo( Jobs.getPlayerManager().addPlayerToMap(new PlayerInfo(
res.getString(UserTableFields.username.getCollumn()), res.getString(UserTableFields.username.getCollumn()),
res.getInt("id"), res.getInt("id"),
UUID.fromString(res.getString(UserTableFields.player_uuid.getCollumn())), UUID.fromString(res.getString(UserTableFields.player_uuid.getCollumn())),
seen, seen,
res.getInt(UserTableFields.donequests.getCollumn()), res.getInt(UserTableFields.donequests.getCollumn()),
res.getString(UserTableFields.quests.getCollumn()))); res.getString(UserTableFields.quests.getCollumn())));
} }
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
@ -2201,9 +2201,9 @@ public abstract class JobsDAO {
continue; continue;
insert.setInt(1, worldId); insert.setInt(1, worldId);
insert.setInt(2, block.getValue().getPos().getBlockX()); insert.setInt(2, block.getValue().getX());
insert.setInt(3, block.getValue().getPos().getBlockY()); insert.setInt(3, block.getValue().getY());
insert.setInt(4, block.getValue().getPos().getBlockZ()); insert.setInt(4, block.getValue().getZ());
insert.setLong(5, block.getValue().getRecorded()); insert.setLong(5, block.getValue().getRecorded());
insert.setLong(6, block.getValue().getTime()); insert.setLong(6, block.getValue().getTime());
insert.setString(7, world); insert.setString(7, world);
@ -2267,7 +2267,7 @@ public abstract class JobsDAO {
PreparedStatement prestDel = null; PreparedStatement prestDel = null;
ResultSet res = null; ResultSet res = null;
Jobs.getBpManager().timer = 0L; Long timer = System.currentTimeMillis();
try { try {
Long mark = System.currentTimeMillis() - (Jobs.getGCManager().BlockProtectionDays * 24L * 60L * 60L * 1000L); Long mark = System.currentTimeMillis() - (Jobs.getGCManager().BlockProtectionDays * 24L * 60L * 60L * 1000L);
@ -2308,9 +2308,9 @@ public abstract class JobsDAO {
int z = res.getInt(BlockTableFields.z.getCollumn()); int z = res.getInt(BlockTableFields.z.getCollumn());
long resets = res.getLong(BlockTableFields.resets.getCollumn()); long resets = res.getLong(BlockTableFields.resets.getCollumn());
Location loc = new Location(world, x, y, z); Location loc = new Location(world, x, y, z);
BlockProtection bp = Jobs.getBpManager().addP(loc, resets, true, false); BlockProtection bp = Jobs.getBpManager().addP(loc, resets, true, false);
bp.setId(id); bp.setId(id);
long t = System.currentTimeMillis();
bp.setRecorded(res.getLong(BlockTableFields.recorded.getCollumn())); bp.setRecorded(res.getLong(BlockTableFields.recorded.getCollumn()));
bp.setAction(DBAction.NONE); bp.setAction(DBAction.NONE);
i++; i++;
@ -2320,10 +2320,9 @@ public abstract class JobsDAO {
Jobs.consoleMsg("&6[Jobs] Loading (" + i + ") BP"); Jobs.consoleMsg("&6[Jobs] Loading (" + i + ") BP");
ii = 0; ii = 0;
} }
Jobs.getBpManager().timer += System.currentTimeMillis() - t;
} }
if (i > 0) { if (i > 0) {
Jobs.consoleMsg("&e[Jobs] Loaded " + i + " block protection entries. " + Jobs.getBpManager().timer); Jobs.consoleMsg("&e[Jobs] Loaded " + i + " block protection entries. " + (System.currentTimeMillis() - timer) + "ms");
} }
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();