fix: improve performance by fetching materials only once

This commit is contained in:
Sekwah 2024-08-29 18:02:19 +02:00
parent 6a228d8e7d
commit 2a75aca157
2 changed files with 14 additions and 3 deletions

View File

@ -102,9 +102,11 @@ public class Listeners implements Listener {
Location loc = player.getLocation();
Location eyeLoc = player.getEyeLocation();
UUID uuid = player.getUniqueId();
Material block = loc.getBlock().getType();
Material eyeBlock = eyeLoc.getBlock().getType();
for (AdvancedPortal portal : Portal.portals) {
if (!portal.inPortal.contains(uuid)
&& (Portal.locationInPortalTrigger(portal, loc) || Portal.locationInPortalTrigger(portal, eyeLoc))) {
&& (Portal.locationInPortalTrigger(portal, loc, block) || Portal.locationInPortalTrigger(portal, eyeLoc, eyeBlock))) {
portal.inPortal.add(uuid);
}
}

View File

@ -694,14 +694,23 @@ public class Portal {
}
public static boolean inPortalTriggerRegion(Location loc) {
Material block = loc.getBlock().getType();
for (AdvancedPortal portal : Portal.portals)
if (Portal.locationInPortalTrigger(portal, loc))
if (Portal.locationInPortalTrigger(portal, loc, block))
return true;
return false;
}
public static boolean locationInPortalTrigger(AdvancedPortal portal, Location loc, int additionalArea) {
return portal.getTriggers().contains(loc.getBlock().getType()) && locationInPortal(portal, loc, additionalArea);
return locationInPortalTrigger(portal, loc, additionalArea, loc.getBlock().getType());
}
public static boolean locationInPortalTrigger(AdvancedPortal portal, Location loc, int additionalArea, Material type) {
return portal.getTriggers().contains(type) && locationInPortal(portal, loc, additionalArea);
}
public static boolean locationInPortalTrigger(AdvancedPortal portal, Location loc, Material type) {
return locationInPortalTrigger(portal, loc, 0, type);
}
public static boolean locationInPortalTrigger(AdvancedPortal portal, Location loc) {