Clear entityBlockMapper cache after 5 seconds

This commit is contained in:
Intelli 2023-09-22 15:51:38 -06:00
parent 9f3196dc97
commit f76b0d45bd
4 changed files with 10 additions and 6 deletions

View File

@ -40,9 +40,9 @@ public final class CreatureSpawnListener extends Queue implements Listener {
Map.Entry<String, Object[]> pair = it.next(); Map.Entry<String, Object[]> pair = it.next();
String name = pair.getKey(); String name = pair.getKey();
Object[] data = pair.getValue(); Object[] data = pair.getValue();
if ((data[0].equals(key) || data[1].equals(key)) && Util.getEntityMaterial(event.getEntityType()) == ((ItemStack) data[2]).getType()) { if ((data[1].equals(key) || data[2].equals(key)) && Util.getEntityMaterial(event.getEntityType()) == ((ItemStack) data[3]).getType()) {
Block gravityLocation = BlockUtil.gravityScan(location, Material.ARMOR_STAND, name); Block gravityLocation = BlockUtil.gravityScan(location, Material.ARMOR_STAND, name);
Queue.queueBlockPlace(name, gravityLocation.getState(), location.getBlock().getType(), location.getBlock().getState(), ((ItemStack) data[2]).getType(), (int) event.getEntity().getLocation().getYaw(), 1, null); Queue.queueBlockPlace(name, gravityLocation.getState(), location.getBlock().getType(), location.getBlock().getState(), ((ItemStack) data[3]).getType(), (int) event.getEntity().getLocation().getYaw(), 1, null);
it.remove(); it.remove();
} }
} }

View File

@ -904,7 +904,7 @@ public final class PlayerInteractListener extends Queue implements Listener {
String relativeBlockKey = world.getName() + "-" + relativeBlockLocation.getBlockX() + "-" + relativeBlockLocation.getBlockY() + "-" + relativeBlockLocation.getBlockZ(); String relativeBlockKey = world.getName() + "-" + relativeBlockLocation.getBlockX() + "-" + relativeBlockLocation.getBlockY() + "-" + relativeBlockLocation.getBlockZ();
String blockKey = world.getName() + "-" + blockLocation.getBlockX() + "-" + blockLocation.getBlockY() + "-" + blockLocation.getBlockZ(); String blockKey = world.getName() + "-" + blockLocation.getBlockX() + "-" + blockLocation.getBlockY() + "-" + blockLocation.getBlockZ();
Object[] keys = new Object[] { relativeBlockKey, blockKey, handItem }; Object[] keys = new Object[] { System.currentTimeMillis(), relativeBlockKey, blockKey, handItem };
ConfigHandler.entityBlockMapper.put(player.getName(), keys); ConfigHandler.entityBlockMapper.put(player.getName(), keys);
} }
} }

View File

@ -68,10 +68,10 @@ public final class ProjectileLaunchListener extends Queue implements Listener {
Map.Entry<String, Object[]> pair = it.next(); Map.Entry<String, Object[]> pair = it.next();
String name = pair.getKey(); String name = pair.getKey();
Object[] data = pair.getValue(); Object[] data = pair.getValue();
ItemStack itemStack = (ItemStack) data[2]; ItemStack itemStack = (ItemStack) data[3];
Material entityMaterial = Util.getEntityMaterial(event.getEntityType()); Material entityMaterial = Util.getEntityMaterial(event.getEntityType());
boolean isBow = BOWS.contains(itemStack.getType()); boolean isBow = BOWS.contains(itemStack.getType());
if ((data[0].equals(key) || data[1].equals(key)) && (entityMaterial == itemStack.getType() || (itemStack.getType() == Material.LINGERING_POTION && entityMaterial == Material.SPLASH_POTION) || isBow)) { if ((data[1].equals(key) || data[2].equals(key)) && (entityMaterial == itemStack.getType() || (itemStack.getType() == Material.LINGERING_POTION && entityMaterial == Material.SPLASH_POTION) || isBow)) {
boolean thrownItem = (itemStack.getType() != Material.FIREWORK_ROCKET && !isBow); boolean thrownItem = (itemStack.getType() != Material.FIREWORK_ROCKET && !isBow);
if (isBow) { if (isBow) {
if (itemStack.getType() == Material.CROSSBOW) { if (itemStack.getType() == Material.CROSSBOW) {

View File

@ -26,7 +26,7 @@ public class CacheHandler implements Runnable {
public void run() { public void run() {
while (ConfigHandler.serverRunning) { while (ConfigHandler.serverRunning) {
try { try {
for (int id = 0; id < 7; id++) { for (int id = 0; id < 8; id++) {
Thread.sleep(1000); Thread.sleep(1000);
int scanTime = 30; int scanTime = 30;
Map cache = CacheHandler.lookupCache; Map cache = CacheHandler.lookupCache;
@ -55,6 +55,10 @@ public class CacheHandler implements Runnable {
cache = CacheHandler.entityCache; cache = CacheHandler.entityCache;
scanTime = 3600; // 60 minutes scanTime = 3600; // 60 minutes
break; break;
case 7:
cache = ConfigHandler.entityBlockMapper;
scanTime = 5;
break;
} }
int timestamp = (int) (System.currentTimeMillis() / 1000L) - scanTime; int timestamp = (int) (System.currentTimeMillis() / 1000L) - scanTime;