Fixed an issue with WorldGuardWrapper making the region always deny

This commit is contained in:
Esophose 2022-03-23 12:51:51 -06:00
parent 95121dcc7e
commit 1cc28b323e
No known key found for this signature in database
GPG key ID: DE0E013CAE5C630A

View file

@ -4,7 +4,7 @@ import dev.esophose.playerparticles.manager.ConfigurationManager.Setting;
import java.util.Comparator; import java.util.Comparator;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.Set; import java.util.stream.Collectors;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.codemc.worldguardwrapper.WorldGuardWrapper; import org.codemc.worldguardwrapper.WorldGuardWrapper;
@ -42,24 +42,30 @@ public class WorldGuardHook {
* @param location The location to check * @param location The location to check
* @return true if the location is in an allowed region, otherwise false * @return true if the location is in an allowed region, otherwise false
*/ */
@SuppressWarnings("unchecked")
public static boolean isInAllowedRegion(Location location) { public static boolean isInAllowedRegion(Location location) {
if (!enabled()) if (!enabled())
return true; return true;
Set<IWrappedRegion> regions = worldGuardWrapper.getRegions(location); List<IWrappedRegion> regions = worldGuardWrapper.getRegions(location).stream()
.sorted(Comparator.comparing(IWrappedRegion::getPriority))
.collect(Collectors.toList());
// Get the "player-particles" flag. // Get the "player-particles" flag.
// This will use the region priority to determine which one takes precedence. // This will use the region priority to determine which one takes precedence.
if (flagPlayerParticles != null) { if (flagPlayerParticles != null) {
Optional<WrappedState> flagState = regions.stream() for (IWrappedRegion region : regions) {
.sorted(Comparator.comparingInt(IWrappedRegion::getPriority)) Optional<WrappedState> flagState = region.getFlag(flagPlayerParticles);
.map(region -> region.getFlag(flagPlayerParticles)) if (flagState.isPresent()) {
.filter(Optional::isPresent) Object value = flagState.get();
.map(Optional::get) // Fix a weird mismatch where the type in the compiler does not match the runtime type
.findFirst(); if (value instanceof WrappedState && value == WrappedState.DENY) {
return false;
if (flagState.isPresent()) } else if (value instanceof Optional && ((Optional<WrappedState>) value).get() == WrappedState.DENY) {
return flagState.get() == WrappedState.ALLOW; return false;
}
}
}
} }
// Legacy blocking by region name. // Legacy blocking by region name.