From ae8bf63c8699861e2d885edb4c8b6545d258a8ce Mon Sep 17 00:00:00 2001 From: sk89q Date: Mon, 18 Aug 2014 03:05:06 -0700 Subject: [PATCH] Remove use of ObjectArrays.concat() in ApplicableRegionSet. --- .../protection/ApplicableRegionSet.java | 3 +- .../protection/FlagValueCalculator.java | 47 +++++++++++++++++++ 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/sk89q/worldguard/protection/ApplicableRegionSet.java b/src/main/java/com/sk89q/worldguard/protection/ApplicableRegionSet.java index 7b9e61cd..5adaa786 100644 --- a/src/main/java/com/sk89q/worldguard/protection/ApplicableRegionSet.java +++ b/src/main/java/com/sk89q/worldguard/protection/ApplicableRegionSet.java @@ -19,7 +19,6 @@ package com.sk89q.worldguard.protection; -import com.google.common.collect.ObjectArrays; import com.sk89q.worldguard.LocalPlayer; import com.sk89q.worldguard.protection.association.RegionAssociable; import com.sk89q.worldguard.protection.flags.DefaultFlag; @@ -121,7 +120,7 @@ public boolean canBuild(LocalPlayer player) { */ public boolean testBuild(RegionAssociable subject, StateFlag... flags) { checkNotNull(subject); - return test(flagValueCalculator.queryState(subject, ObjectArrays.concat(flags, DefaultFlag.BUILD))); + return test(flagValueCalculator.queryState(subject, DefaultFlag.BUILD, flags)); } /** diff --git a/src/main/java/com/sk89q/worldguard/protection/FlagValueCalculator.java b/src/main/java/com/sk89q/worldguard/protection/FlagValueCalculator.java index 91279b27..50b4f57d 100644 --- a/src/main/java/com/sk89q/worldguard/protection/FlagValueCalculator.java +++ b/src/main/java/com/sk89q/worldguard/protection/FlagValueCalculator.java @@ -205,6 +205,53 @@ public State queryState(@Nullable RegionAssociable subject, StateFlag... flags) return value; } + /** + * Get the effective value for a list of state flags. The rules of + * states is observed here; that is, {@code DENY} overrides {@code ALLOW}, + * and {@code ALLOW} overrides {@code NONE}. + * + *

This method is the same as + * {@link #queryState(RegionAssociable, StateFlag...)}.

+ * + * @param subject an optional subject, which would be used to determine the region group to apply + * @param flag a flag to check + * @return a state + */ + @Nullable + public State queryState(@Nullable RegionAssociable subject, StateFlag flag) { + return queryValue(subject, flag); + } + + /** + * Get the effective value for a list of state flags. The rules of + * states is observed here; that is, {@code DENY} overrides {@code ALLOW}, + * and {@code ALLOW} overrides {@code NONE}. + * + *

This method is the same as + * {@link #queryState(RegionAssociable, StateFlag...)} except it allows + * another flag to be added at the beginning of the flag list without + * having to concatenate the vararg array with the first flag.

+ * + * @param subject an optional subject, which would be used to determine the region group to apply + * @param flags a list of flags to check + * @return a state + */ + @Nullable + public State queryState(@Nullable RegionAssociable subject, StateFlag firstFlag, StateFlag... flags) { + State value = queryValue(subject, firstFlag); + + if (value != State.DENY) { + for (StateFlag flag : flags) { + value = StateFlag.combine(value, queryValue(subject, flag)); + if (value == State.DENY) { + break; + } + } + } + + return value; + } + /** * Get the effective value for a flag. If there are multiple values * (for example, if there are multiple regions with the same priority