generated from Matt-MX/KtPaperPluginTemplate
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from Matt-MX/dev
Dev
- Loading branch information
Showing
10 changed files
with
256 additions
and
35 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
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
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
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
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
48 changes: 48 additions & 0 deletions
48
src/main/java/com/mattmx/nametags/config/ConfigHelper.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,48 @@ | ||
package com.mattmx.nametags.config; | ||
|
||
import me.tofaa.entitylib.meta.display.AbstractDisplayMeta; | ||
import org.bukkit.configuration.ConfigurationSection; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.Arrays; | ||
import java.util.Optional; | ||
import java.util.function.Consumer; | ||
import java.util.function.Function; | ||
|
||
public class ConfigHelper { | ||
|
||
public static <T> @Nullable T takeIfPresent( | ||
@NotNull ConfigurationSection section, | ||
@NotNull String key, | ||
@NotNull Function<String, T> provider, | ||
@NotNull Consumer<T> take | ||
) { | ||
Optional<T> optional = Optional.ofNullable(provider.apply(key)); | ||
|
||
optional.ifPresent(take); | ||
|
||
return optional.orElse(null); | ||
} | ||
|
||
public static <T> @Nullable T takeIfPresentOrElse( | ||
@NotNull ConfigurationSection section, | ||
@NotNull String key, | ||
@NotNull Function<String, T> provider, | ||
@NotNull Consumer<T> take, | ||
@NotNull Runnable orElse | ||
) { | ||
Optional<T> optional = Optional.ofNullable(provider.apply(key)); | ||
|
||
optional.ifPresentOrElse(take, orElse); | ||
|
||
return optional.orElse(null); | ||
} | ||
|
||
public static <T extends Enum<T>> @Nullable T getEnumByNameOrNull(Class<T> enums, @NotNull String name) { | ||
return Arrays.stream(enums.getEnumConstants()) | ||
.filter((e) -> e.name().equalsIgnoreCase(name)) | ||
.findFirst().orElse(null); | ||
} | ||
|
||
} |
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
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
Oops, something went wrong.