diff --git a/src/main/java/com/sk89q/worldguard/LocalPlayer.java b/src/main/java/com/sk89q/worldguard/LocalPlayer.java index b1964aa9..585acd2f 100644 --- a/src/main/java/com/sk89q/worldguard/LocalPlayer.java +++ b/src/main/java/com/sk89q/worldguard/LocalPlayer.java @@ -20,10 +20,13 @@ package com.sk89q.worldguard; import com.sk89q.worldedit.Vector; +import com.sk89q.worldguard.domains.Association; +import com.sk89q.worldguard.protection.association.RegionAssociable; +import com.sk89q.worldguard.protection.regions.ProtectedRegion; import java.util.UUID; -public abstract class LocalPlayer { +public abstract class LocalPlayer implements RegionAssociable { /** * Get this player's name. @@ -89,7 +92,18 @@ public abstract class LocalPlayer { * @return Whether this player has {@code perm} */ public abstract boolean hasPermission(String perm); - + + @Override + public Association getAssociation(ProtectedRegion region) { + if (region.isOwner(this)) { + return Association.OWNER; + } else if (region.isMember(this)) { + return Association.MEMBER; + } else { + return Association.NON_MEMBER; + } + } + @Override public boolean equals(Object obj) { return obj instanceof LocalPlayer && ((LocalPlayer) obj).getName().equals(getName()); diff --git a/src/main/java/com/sk89q/worldguard/bukkit/RegionQuery.java b/src/main/java/com/sk89q/worldguard/bukkit/RegionQuery.java index 5fafb41a..904a1a10 100644 --- a/src/main/java/com/sk89q/worldguard/bukkit/RegionQuery.java +++ b/src/main/java/com/sk89q/worldguard/bukkit/RegionQuery.java @@ -22,6 +22,7 @@ import com.sk89q.worldguard.LocalPlayer; import com.sk89q.worldguard.protection.ApplicableRegionSet; import com.sk89q.worldguard.protection.GlobalRegionManager; +import com.sk89q.worldguard.protection.association.RegionAssociable; import com.sk89q.worldguard.protection.flags.DefaultFlag; import com.sk89q.worldguard.protection.flags.Flag; import com.sk89q.worldguard.protection.flags.StateFlag; @@ -108,26 +109,46 @@ public ApplicableRegionSet getApplicableRegions(Location location) { * @param player the player * @param flags zero or more flags * @return true if permission is granted - * @see ApplicableRegionSet#testBuild(LocalPlayer, StateFlag...) + * @see ApplicableRegionSet#testBuild(RegionAssociable, StateFlag...) */ public boolean testBuild(Location location, Player player, StateFlag... flags) { checkNotNull(location); checkNotNull(player); - checkNotNull(flags); World world = location.getWorld(); - WorldConfiguration worldConfig = config.get(world); - - if (!worldConfig.useRegions) { - return true; - } if (player.hasPermission("worldguard.region.bypass." + world.getName())) { return true; } LocalPlayer localPlayer = plugin.wrapPlayer(player); - return getApplicableRegions(location).testBuild(localPlayer, flags); + return testBuild(location, localPlayer, flags); + } + + /** + * Test whether the given flags evaluate to {@code ALLOW}, implicitly also + * considering the {@link DefaultFlag#BUILD} flag. + * + *
This method is equivalent to calling + * {@link #testState(Location, Player, StateFlag...)} with + * {@code flags} plus the {@code BUILD} flag.
+ * + * @param location the location + * @param subject the subject + * @param flags zero or more flags + * @return true if permission is granted + * @see ApplicableRegionSet#testBuild(RegionAssociable, StateFlag...) + */ + public boolean testBuild(Location location, RegionAssociable subject, StateFlag... flags) { + checkNotNull(location); + checkNotNull(subject); + checkNotNull(flags); + + World world = location.getWorld(); + WorldConfiguration worldConfig = config.get(world); + + return !worldConfig.useRegions || getApplicableRegions(location).testBuild(subject, flags); + } /** @@ -144,7 +165,7 @@ public boolean testBuild(Location location, Player player, StateFlag... flags) { * @param player an optional player, which would be used to determine the region group to apply * @param flag the flag * @return true if the result was {@code ALLOW} - * @see ApplicableRegionSet#queryValue(LocalPlayer, Flag) + * @see ApplicableRegionSet#queryValue(RegionAssociable, Flag) */ public boolean testState(Location location, @Nullable Player player, StateFlag... flag) { return StateFlag.test(queryState(location, player, flag)); @@ -165,7 +186,7 @@ public boolean testState(Location location, @Nullable Player player, StateFlag.. * @param player an optional player, which would be used to determine the region groups that apply * @param flags a list of flags to check * @return a state - * @see ApplicableRegionSet#queryState(LocalPlayer, StateFlag...) + * @see ApplicableRegionSet#queryState(RegionAssociable, StateFlag...) */ @Nullable public State queryState(Location location, @Nullable Player player, StateFlag... flags) { @@ -195,7 +216,7 @@ public State queryState(Location location, @Nullable Player player, StateFlag... * @param player an optional player, which would be used to determine the region group to apply * @param flag the flag * @return a value, which could be {@code null} - * @see ApplicableRegionSet#queryValue(LocalPlayer, Flag) + * @see ApplicableRegionSet#queryValue(RegionAssociable, Flag) */ @Nullable publicIf there are several relevant flags (i.e. in addition to * {@code BUILD}, such as {@link DefaultFlag#SLEEP} when the target * object is a bed), then - * {@link #testBuild(LocalPlayer, StateFlag...)} should be used.
+ * {@link #testBuild(RegionAssociable, StateFlag...)} should be used. * * @param player the player to check * @return true if permitted - * @deprecated use {@link #testBuild(LocalPlayer, StateFlag...)} + * @deprecated use {@link #testBuild(RegionAssociable, StateFlag...)} */ @Deprecated public boolean canBuild(LocalPlayer player) { @@ -105,36 +107,36 @@ public boolean canBuild(LocalPlayer player) { * considering the {@link DefaultFlag#BUILD} flag. * *This method is equivalent to calling - * {@link #testState(LocalPlayer, StateFlag...)} with {@code flags} plus + * {@link #testState(RegionAssociable, StateFlag...)} with {@code flags} plus * the {@code BUILD} flag.
* - * @param player the player + * @param subject the subject * @param flags zero or more flags * @return true if permission is granted - * @see #queryState(LocalPlayer, StateFlag...) + * @see #queryState(RegionAssociable, StateFlag...) */ - public boolean testBuild(LocalPlayer player, StateFlag... flags) { - checkNotNull(player); - return test(flagValueCalculator.queryState(player, ObjectArrays.concat(flags, DefaultFlag.BUILD))); + public boolean testBuild(RegionAssociable subject, StateFlag... flags) { + checkNotNull(subject); + return test(flagValueCalculator.queryState(subject, ObjectArrays.concat(flags, DefaultFlag.BUILD))); } /** * Test whether the (effective) value for a list of state flags equals * {@code ALLOW}. * - *{@code player} can be non-null to satisfy region group requirements, + *
{@code subject} can be non-null to satisfy region group requirements, * otherwise it will be assumed that the caller that is not a member of any * regions. (Flags on a region can be changed so that they only apply - * to certain users.) The player argument is required if the + * to certain users.) The subject argument is required if the * {@link DefaultFlag#BUILD} flag is in the list of flags.
* - * @param player an optional player, which would be used to determine the region groups that apply + * @param subject an optional subject, which would be used to determine the region groups that apply * @param flags a list of flags to check * @return true if the result was {@code ALLOW} - * @see #queryState(LocalPlayer, StateFlag...) + * @see #queryState(RegionAssociable, StateFlag...) */ - public boolean testState(@Nullable LocalPlayer player, StateFlag... flags) { - return test(flagValueCalculator.queryState(player, flags)); + public boolean testState(@Nullable RegionAssociable subject, StateFlag... flags) { + return test(flagValueCalculator.queryState(subject, flags)); } /** @@ -142,19 +144,19 @@ public boolean testState(@Nullable LocalPlayer player, StateFlag... flags) { * states is observed here; that is, {@code DENY} overrides {@code ALLOW}, * and {@code ALLOW} overrides {@code NONE}. One flag may override another. * - *{@code player} can be non-null to satisfy region group requirements, + *
{@code subject} can be non-null to satisfy region group requirements, * otherwise it will be assumed that the caller that is not a member of any * regions. (Flags on a region can be changed so that they only apply - * to certain users.) The player argument is required if the + * to certain users.) The subject argument is required if the * {@link DefaultFlag#BUILD} flag is in the list of flags.
* - * @param player an optional player, which would be used to determine the region groups that apply + * @param subject an optional subject, which would be used to determine the region groups that apply * @param flags a list of flags to check * @return a state */ @Nullable - public State queryState(@Nullable LocalPlayer player, StateFlag... flags) { - return flagValueCalculator.queryState(player, flags); + public State queryState(@Nullable RegionAssociable subject, StateFlag... flags) { + return flagValueCalculator.queryState(subject, flags); } /** @@ -169,19 +171,19 @@ public State queryState(@Nullable LocalPlayer player, StateFlag... flags) { * type of flag that actually has a strategy for picking a value is the * {@link StateFlag}. * - *{@code player} can be non-null to satisfy region group requirements, + *
{@code subject} can be non-null to satisfy region group requirements, * otherwise it will be assumed that the caller that is not a member of any * regions. (Flags on a region can be changed so that they only apply - * to certain users.) The player argument is required if the + * to certain users.) The subject argument is required if the * {@link DefaultFlag#BUILD} flag is the flag being queried.
* - * @param player an optional player, which would be used to determine the region group to apply + * @param subject an optional subject, which would be used to determine the region group to apply * @param flag the flag * @return a value, which could be {@code null} */ @Nullable - public{@code player} can be non-null to satisfy region group requirements, + *
{@code subject} can be non-null to satisfy region group requirements, * otherwise it will be assumed that the caller that is not a member of any * regions. (Flags on a region can be changed so that they only apply - * to certain users.) The player argument is required if the + * to certain users.) The subject argument is required if the * {@link DefaultFlag#BUILD} flag is the flag being queried.
* - * @param player an optional player, which would be used to determine the region group to apply + * @param subject an optional subject, which would be used to determine the region group to apply * @param flag the flag * @return a collection of values */ - publicA region is "counted" if it doesn't have the
@@ -97,20 +97,20 @@ private Iterable This method is mostly for internal use. It's not particularly
* useful. A player can be provided that is used to determine whether the value
+ * A subject can be provided that is used to determine whether the value
* of a flag on a particular region should be used. For example, if a
* flag's region group is set to {@link RegionGroup#MEMBERS} and the given
- * player is not a member, then the region would be skipped when
- * querying that flag. If {@code null} is provided for the player, then
+ * subject is not a member, then the region would be skipped when
+ * querying that flag. If {@code null} is provided for the subject, then
* only flags that use {@link RegionGroup#ALL},
* {@link RegionGroup#NON_MEMBERS}, etc. will apply.
A player can be provided that is used to determine whether the value + *
A subject can be provided that is used to determine whether the value * of a flag on a particular region should be used. For example, if a * flag's region group is set to {@link RegionGroup#MEMBERS} and the given - * player is not a member, then the region would be skipped when - * querying that flag. If {@code null} is provided for the player, then + * subject is not a member, then the region would be skipped when + * querying that flag. If {@code null} is provided for the subject, then * only flags that use {@link RegionGroup#ALL}, * {@link RegionGroup#NON_MEMBERS}, etc. will apply.
* - * @param player an optional player, which would be used to determine the region group to apply + * @param subject an optional subject, which would be used to determine the region group to apply * @param flag the flag * @return a value, which could be {@code null} */ @Nullable - publicA player can be provided that is used to determine whether the value + *
A subject can be provided that is used to determine whether the value * of a flag on a particular region should be used. For example, if a * flag's region group is set to {@link RegionGroup#MEMBERS} and the given - * player is not a member, then the region would be skipped when - * querying that flag. If {@code null} is provided for the player, then + * subject is not a member, then the region would be skipped when + * querying that flag. If {@code null} is provided for the subject, then * only flags that use {@link RegionGroup#ALL}, * {@link RegionGroup#NON_MEMBERS}, etc. will apply.
* - * @param player an optional player, which would be used to determine the region group to apply + * @param subject an optional subject, which would be used to determine the region group to apply * @param flag the flag * @return a collection of values */ @SuppressWarnings("unchecked") - public