Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
api: Implement Resolvers utility class
- Loading branch information
Showing
3 changed files
with
77 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
api/src/main/java/me/dreamerzero/miniplaceholders/api/utils/Resolvers.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package me.dreamerzero.miniplaceholders.api.utils; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
|
||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver; | ||
|
||
/** | ||
* Class of utilities to manage TagResolvers | ||
* @since 1.2.0 | ||
*/ | ||
public final class Resolvers { | ||
private Resolvers() {} | ||
|
||
/** | ||
* Check if the TagResolver is an instance of TagResolver.empty(), | ||
* that is, it will always return null | ||
* @param resolver the resolver to check | ||
* @return true if the TagResolver is the same as TagResolver.empty(), else false | ||
* @since 1.2.0 | ||
*/ | ||
public static boolean isEmpty(final @NotNull TagResolver resolver) { | ||
return resolver == TagResolver.empty(); | ||
} | ||
|
||
/** | ||
* Checks if the TagResolver provided is not a TagResolver.empty() | ||
* @param resolver the resolver to check | ||
* @return false if the TagResolver is the same as TagResolver.empty(), else true | ||
* @since 1.2.0 | ||
* | ||
*/ | ||
public static boolean isNotEmpty(final @NotNull TagResolver resolver) { | ||
return resolver != TagResolver.empty(); | ||
} | ||
|
||
/** | ||
* Applies a TagResolver to a TagResolver.Builder in case it is not a TagResolver.empty() | ||
* @param resolver the resolver to check | ||
* @param builder the resolver that can be added to the builder | ||
* @since 1.2.0 | ||
*/ | ||
public static void applyIfNotEmpty(final @NotNull TagResolver resolver, final @NotNull TagResolver.Builder builder) { | ||
if (isNotEmpty(resolver)) { | ||
builder.resolver(resolver); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters