mirror of
https://github.com/Zrips/Jobs.git
synced 2025-03-02 03:01:37 +01:00
Avoiding memory leaks
This commit is contained in:
parent
2bd257b563
commit
b79b8a1e9d
@ -16,6 +16,7 @@ import com.gamingmesh.jobs.container.DBAction;
|
|||||||
|
|
||||||
import net.Zrips.CMILib.Items.CMIMaterial;
|
import net.Zrips.CMILib.Items.CMIMaterial;
|
||||||
import net.Zrips.CMILib.Locale.LC;
|
import net.Zrips.CMILib.Locale.LC;
|
||||||
|
import net.Zrips.CMILib.Logs.CMIDebug;
|
||||||
import net.Zrips.CMILib.Messages.CMIMessages;
|
import net.Zrips.CMILib.Messages.CMIMessages;
|
||||||
import net.Zrips.CMILib.Version.Version;
|
import net.Zrips.CMILib.Version.Version;
|
||||||
|
|
||||||
@ -57,9 +58,8 @@ public class bp implements Cmd {
|
|||||||
changedBlocks.add(l.getBlock());
|
changedBlocks.add(l.getBlock());
|
||||||
|
|
||||||
if (Version.isCurrentEqualOrHigher(Version.v1_15_R1)) {
|
if (Version.isCurrentEqualOrHigher(Version.v1_15_R1)) {
|
||||||
player.sendBlockChange(l, (bp.getAction() == DBAction.DELETE ?
|
player.sendBlockChange(l, (bp.getAction() == DBAction.DELETE ? CMIMaterial.RED_STAINED_GLASS : time == -1 ? CMIMaterial.BLACK_STAINED_GLASS : CMIMaterial.WHITE_STAINED_GLASS)
|
||||||
CMIMaterial.RED_STAINED_GLASS :
|
.getMaterial().createBlockData());
|
||||||
time == -1 ? CMIMaterial.BLACK_STAINED_GLASS : CMIMaterial.WHITE_STAINED_GLASS).getMaterial().createBlockData());
|
|
||||||
} else {
|
} else {
|
||||||
if (bp.getAction() == DBAction.DELETE)
|
if (bp.getAction() == DBAction.DELETE)
|
||||||
player.sendBlockChange(l, CMIMaterial.RED_STAINED_GLASS.getMaterial(), (byte) 14);
|
player.sendBlockChange(l, CMIMaterial.RED_STAINED_GLASS.getMaterial(), (byte) 14);
|
||||||
|
@ -4,6 +4,7 @@ import java.util.HashMap;
|
|||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
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;
|
||||||
@ -15,7 +16,6 @@ import com.gamingmesh.jobs.container.DBAction;
|
|||||||
import net.Zrips.CMILib.Container.CMIBlock;
|
import net.Zrips.CMILib.Container.CMIBlock;
|
||||||
import net.Zrips.CMILib.Container.CMIBlock.Bisect;
|
import net.Zrips.CMILib.Container.CMIBlock.Bisect;
|
||||||
import net.Zrips.CMILib.Items.CMIMaterial;
|
import net.Zrips.CMILib.Items.CMIMaterial;
|
||||||
import net.Zrips.CMILib.Logs.CMIDebug;
|
|
||||||
|
|
||||||
public class BlockProtectionManager {
|
public class BlockProtectionManager {
|
||||||
|
|
||||||
@ -75,6 +75,7 @@ public class BlockProtectionManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public BlockProtection addP(Location loc, Long time, boolean paid, boolean cache) {
|
public BlockProtection addP(Location loc, Long time, boolean paid, boolean cache) {
|
||||||
|
|
||||||
String v = loc.getBlockX() + ":" + loc.getBlockY() + ":" + loc.getBlockZ();
|
String v = loc.getBlockX() + ":" + loc.getBlockY() + ":" + loc.getBlockZ();
|
||||||
|
|
||||||
HashMap<String, HashMap<String, HashMap<String, BlockProtection>>> regions = map.getOrDefault(loc.getWorld(), new HashMap<>());
|
HashMap<String, HashMap<String, HashMap<String, BlockProtection>>> regions = map.getOrDefault(loc.getWorld(), new HashMap<>());
|
||||||
@ -88,16 +89,27 @@ public class BlockProtectionManager {
|
|||||||
|
|
||||||
if (Bp == null)
|
if (Bp == null)
|
||||||
Bp = new BlockProtection(DBAction.INSERT, 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);
|
||||||
|
if (Bp.getSchedId() > -1)
|
||||||
|
Bukkit.getServer().getScheduler().cancelTask(Bp.getSchedId());
|
||||||
|
}
|
||||||
|
|
||||||
Bp.setPaid(paid);
|
Bp.setPaid(paid);
|
||||||
Bp.setTime(time);
|
Bp.setTime(time);
|
||||||
|
|
||||||
|
// If timer is under 2 hours, we can run scheduler to remove it when time comes
|
||||||
|
if ((time - System.currentTimeMillis()) / 1000 < 60 * 60 * 2)
|
||||||
|
Bp.setSchedId(Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Jobs.getInstance(), () -> {
|
||||||
|
remove(loc);
|
||||||
|
}, (time - System.currentTimeMillis()) / 50));
|
||||||
|
|
||||||
Bpm.put(v, Bp);
|
Bpm.put(v, Bp);
|
||||||
chunks.put(chunk, Bpm);
|
chunks.put(chunk, Bpm);
|
||||||
regions.put(region, chunks);
|
regions.put(region, chunks);
|
||||||
map.put(loc.getWorld(), regions);
|
map.put(loc.getWorld(), regions);
|
||||||
if (cache)
|
// Only saving into save cache if timer is higher than 5 minutes
|
||||||
|
if (cache && (time - System.currentTimeMillis()) / 1000 > 60 * 5)
|
||||||
addToCache(loc, Bp);
|
addToCache(loc, Bp);
|
||||||
return Bp;
|
return Bp;
|
||||||
}
|
}
|
||||||
@ -162,6 +174,15 @@ public class BlockProtectionManager {
|
|||||||
BlockProtection bp = chunk.get(v);
|
BlockProtection bp = chunk.get(v);
|
||||||
if (bp != null)
|
if (bp != null)
|
||||||
bp.setAction(DBAction.DELETE);
|
bp.setAction(DBAction.DELETE);
|
||||||
|
if (bp != null && bp.getId() < 0) {
|
||||||
|
chunk.remove(v);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (chunk.isEmpty())
|
||||||
|
region.remove(locToChunk(loc));
|
||||||
|
if (region.isEmpty())
|
||||||
|
world.remove(locToRegion(loc));
|
||||||
|
|
||||||
return bp;
|
return bp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,7 +6,8 @@ public class BlockProtection {
|
|||||||
|
|
||||||
private static long pre = (int) (System.currentTimeMillis() / 10000000000L) * 10000000000L;
|
private static long pre = (int) (System.currentTimeMillis() / 10000000000L) * 10000000000L;
|
||||||
|
|
||||||
private int id;
|
private int id = -1;
|
||||||
|
private int schedId = - 1;
|
||||||
private int time = -1;
|
private int time = -1;
|
||||||
private int recorded = -1;
|
private int recorded = -1;
|
||||||
private DBAction action;
|
private DBAction action;
|
||||||
@ -113,4 +114,12 @@ public class BlockProtection {
|
|||||||
public int getZ() {
|
public int getZ() {
|
||||||
return z;
|
return z;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getSchedId() {
|
||||||
|
return schedId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSchedId(int schedId) {
|
||||||
|
this.schedId = schedId;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user