mirror of
				https://github.com/CodeMC/WorldGuardWrapper.git
				synced 2025-10-30 23:02:36 +01:00 
			
		
		
		
	Support flag query by flag name
This commit is contained in:
		
							parent
							
								
									7e0ba6d8e7
								
							
						
					
					
						commit
						ad9ff41b7b
					
				|  | @ -43,6 +43,17 @@ public interface IWorldGuardImplementation { | |||
|      */ | ||||
|     boolean registerStateFlag(@NonNull String flagName, @NonNull Boolean defaultValue); | ||||
| 
 | ||||
|     /** | ||||
|      * Query a flag's value for a given player at a given location. | ||||
|      *  | ||||
|      * @param player   The player | ||||
|      * @param location The location | ||||
|      * @param flagName The name of the flag | ||||
|      * @param type     The type of the flag's value | ||||
|      * @return The flag's value | ||||
|      */ | ||||
|     <T> Optional<T> queryFlag(Player player, @NonNull Location location, @NonNull String flagName, Class<T> type); | ||||
| 
 | ||||
|     /** | ||||
|      * Query a flag's value for a given player at a given location. | ||||
|      *  | ||||
|  | @ -51,7 +62,9 @@ public interface IWorldGuardImplementation { | |||
|      * @param flag     The flag | ||||
|      * @return The flag's value | ||||
|      */ | ||||
|     <T> Optional<T> queryFlag(Player player, @NonNull Location location, @NonNull AbstractFlag<T> flag); | ||||
|     default <T> Optional<T> queryFlag(Player player, @NonNull Location location, @NonNull AbstractFlag<T> flag) { | ||||
|         return queryFlag(player, location, flag.getName(), flag.getType()); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Register a flag to WorldGuard's flag registry. | ||||
|  |  | |||
|  | @ -83,10 +83,10 @@ public class WorldGuardImplementation extends AbstractWorldGuardImplementation { | |||
| 
 | ||||
|     @Override | ||||
|     @SuppressWarnings("unchecked") | ||||
|     public <T> Optional<T> queryFlag(Player player, Location location, AbstractFlag<T> flag) {         | ||||
|         Flag<?> wgFlag = flagRegistry.get(flag.getName()); | ||||
|         Object value = queryValue(player, location, wgFlag).orElse(null); | ||||
|         if (flag.getType().isInstance(value)) { | ||||
|     public <T> Optional<T> queryFlag(Player player, Location location, String flagName, Class<T> type) { | ||||
|         Flag<?> flag = flagRegistry.get(flagName); | ||||
|         Object value = queryValue(player, location, flag).orElse(null); | ||||
|         if (type.isInstance(value)) { | ||||
|             return Optional.of((T) value); | ||||
|         } | ||||
|         return Optional.empty(); | ||||
|  |  | |||
|  | @ -96,10 +96,10 @@ public class WorldGuardImplementation extends AbstractWorldGuardImplementation { | |||
| 
 | ||||
|     @Override | ||||
|     @SuppressWarnings("unchecked") | ||||
|     public <T> Optional<T> queryFlag(Player player, Location location, AbstractFlag<T> flag) {         | ||||
|         Flag<?> wgFlag = flagRegistry.get(flag.getName()); | ||||
|         Object value = queryValue(player, location, wgFlag).orElse(null); | ||||
|         if (flag.getType().isInstance(value)) { | ||||
|     public <T> Optional<T> queryFlag(Player player, Location location, String flagName, Class<T> type) { | ||||
|         Flag<?> flag = flagRegistry.get(flagName); | ||||
|         Object value = queryValue(player, location, flag).orElse(null); | ||||
|         if (type.isInstance(value)) { | ||||
|             return Optional.of((T) value); | ||||
|         } | ||||
|         return Optional.empty(); | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	Block a user