Use generics in the getFlag method

This commit is contained in:
Gabriele C 2018-11-28 13:58:56 +01:00
parent 06eb96b230
commit 74399248f3
9 changed files with 20 additions and 16 deletions

View File

@ -7,7 +7,7 @@
<parent>
<groupId>org.codemc.worldguardwrapper</groupId>
<artifactId>worldguardwrapper-parent</artifactId>
<version>1.1.0-SNAPSHOT</version>
<version>1.1.1-SNAPSHOT</version>
</parent>
<artifactId>worldguardwrapper-api</artifactId>

View File

@ -40,9 +40,10 @@ public interface IWorldGuardImplementation {
* Returns the flag with the given name.
*
* @param name The flag name
* @param type The flag type
* @return The flag, empty if it doesn't exists
*/
Optional<IWrappedFlag<?>> getFlag(@NonNull String name);
<T> Optional<IWrappedFlag<T>> getFlag(String name, Class<T> type);
/**
* Registers a flag to WorldGuard's flag registry.

View File

@ -7,7 +7,7 @@
<parent>
<groupId>org.codemc.worldguardwrapper</groupId>
<artifactId>worldguardwrapper-parent</artifactId>
<version>1.1.0-SNAPSHOT</version>
<version>1.1.1-SNAPSHOT</version>
</parent>
<artifactId>worldguardwrapper-implementation</artifactId>

View File

@ -7,7 +7,7 @@
<parent>
<groupId>org.codemc.worldguardwrapper</groupId>
<artifactId>worldguardwrapper-implementation</artifactId>
<version>1.1.0-SNAPSHOT</version>
<version>1.1.1-SNAPSHOT</version>
</parent>
<artifactId>worldguardwrapper-implementation-v6</artifactId>
@ -18,7 +18,7 @@
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>worldguardwrapper-api</artifactId>
<version>1.1.0-SNAPSHOT</version>
<version>1.1.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>

View File

@ -72,10 +72,12 @@ public class WorldGuardImplementation implements IWorldGuardImplementation {
return queryValue(player, location, wrappedFlag);
}
@SuppressWarnings("unchecked")
@Override
public Optional<IWrappedFlag<?>> getFlag(String name) {
public <T> Optional<IWrappedFlag<T>> getFlag(String name, Class<T> type) {
return Optional.ofNullable(flagRegistry.get(name))
.map(WrappedFlag::new);
.map(flag -> (IWrappedFlag<T>) new WrappedFlag(flag));
}
@SuppressWarnings("unchecked")

View File

@ -7,7 +7,7 @@
<parent>
<groupId>org.codemc.worldguardwrapper</groupId>
<artifactId>worldguardwrapper-implementation</artifactId>
<version>1.1.0-SNAPSHOT</version>
<version>1.1.1-SNAPSHOT</version>
</parent>
<artifactId>worldguardwrapper-implementation-v7</artifactId>
@ -18,7 +18,7 @@
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>worldguardwrapper-api</artifactId>
<version>1.1.0-SNAPSHOT</version>
<version>1.1.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>

View File

@ -76,10 +76,11 @@ public class WorldGuardImplementation implements IWorldGuardImplementation {
return queryValue(player, location, wrappedFlag);
}
@SuppressWarnings("unchecked")
@Override
public Optional<IWrappedFlag<?>> getFlag(String name) {
public <T> Optional<IWrappedFlag<T>> getFlag(String name, Class<T> type) {
return Optional.ofNullable(flagRegistry.get(name))
.map(WrappedFlag::new);
.map(flag -> (IWrappedFlag<T>) new WrappedFlag(flag));
}
@SuppressWarnings("unchecked")

View File

@ -7,7 +7,7 @@
<parent>
<groupId>org.codemc.worldguardwrapper</groupId>
<artifactId>worldguardwrapper-parent</artifactId>
<version>1.1.0-SNAPSHOT</version>
<version>1.1.1-SNAPSHOT</version>
</parent>
<artifactId>worldguardwrapper</artifactId>
@ -18,18 +18,18 @@
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>worldguardwrapper-api</artifactId>
<version>1.1.0-SNAPSHOT</version>
<version>1.1.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>worldguardwrapper-implementation-v6</artifactId>
<version>1.1.0-SNAPSHOT</version>
<version>1.1.1-SNAPSHOT</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>worldguardwrapper-implementation-v7</artifactId>
<version>1.1.0-SNAPSHOT</version>
<version>1.1.1-SNAPSHOT</version>
<scope>runtime</scope>
</dependency>
</dependencies>

View File

@ -6,7 +6,7 @@
<groupId>org.codemc.worldguardwrapper</groupId>
<artifactId>worldguardwrapper-parent</artifactId>
<version>1.1.0-SNAPSHOT</version>
<version>1.1.1-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>