Skip to content

Commit

Permalink
Clear entityBlockMapper cache after 5 seconds
Browse files Browse the repository at this point in the history
  • Loading branch information
Intelli committed Sep 22, 2023
1 parent 9f3196d commit f76b0d4
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ public void onCreatureSpawn(CreatureSpawnEvent event) {
Map.Entry<String, Object[]> pair = it.next();
String name = pair.getKey();
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);
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();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -904,7 +904,7 @@ else if (event.getHand().equals(EquipmentSlot.OFF_HAND) && offHand != null && en

String relativeBlockKey = world.getName() + "-" + relativeBlockLocation.getBlockX() + "-" + relativeBlockLocation.getBlockY() + "-" + relativeBlockLocation.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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ protected void onProjectileLaunch(ProjectileLaunchEvent event) {
Map.Entry<String, Object[]> pair = it.next();
String name = pair.getKey();
Object[] data = pair.getValue();
ItemStack itemStack = (ItemStack) data[2];
ItemStack itemStack = (ItemStack) data[3];
Material entityMaterial = Util.getEntityMaterial(event.getEntityType());
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);
if (isBow) {
if (itemStack.getType() == Material.CROSSBOW) {
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/net/coreprotect/thread/CacheHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class CacheHandler implements Runnable {
public void run() {
while (ConfigHandler.serverRunning) {
try {
for (int id = 0; id < 7; id++) {
for (int id = 0; id < 8; id++) {
Thread.sleep(1000);
int scanTime = 30;
Map cache = CacheHandler.lookupCache;
Expand Down Expand Up @@ -55,6 +55,10 @@ public void run() {
cache = CacheHandler.entityCache;
scanTime = 3600; // 60 minutes
break;
case 7:
cache = ConfigHandler.entityBlockMapper;
scanTime = 5;
break;
}

int timestamp = (int) (System.currentTimeMillis() / 1000L) - scanTime;
Expand Down

0 comments on commit f76b0d4

Please sign in to comment.