mirror of
https://github.com/TotalFreedomMC/PlayerParticles.git
synced 2024-12-28 10:24:15 +00:00
Fixed an issue with WorldGuardWrapper making the region always deny
This commit is contained in:
parent
95121dcc7e
commit
1cc28b323e
1 changed files with 17 additions and 11 deletions
|
@ -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.
|
||||||
|
|
Loading…
Reference in a new issue