-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
68 additions
and
7 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
38 changes: 38 additions & 0 deletions
38
src/main/java/com/mattmx/nametags/config/TextFormatter.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,38 @@ | ||
package com.mattmx.nametags.config; | ||
|
||
import net.kyori.adventure.text.Component; | ||
import net.kyori.adventure.text.minimessage.MiniMessage; | ||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.Arrays; | ||
import java.util.Optional; | ||
import java.util.function.Function; | ||
|
||
public enum TextFormatter { | ||
MINI_MESSAGE( | ||
"minimessage", | ||
(line) -> MiniMessage.miniMessage().deserialize(line) | ||
), | ||
LEGACY( | ||
"legacy", | ||
(line) -> LegacyComponentSerializer.legacyAmpersand().deserialize(line) | ||
) | ||
; | ||
|
||
private final @NotNull String identifier; | ||
private final @NotNull Function<String, Component> formatter; | ||
|
||
TextFormatter(@NotNull String identifier, @NotNull Function<String, Component> formatter) { | ||
this.identifier = identifier; | ||
this.formatter = formatter; | ||
} | ||
|
||
public @NotNull Component format(@NotNull String line) { | ||
return formatter.apply(line); | ||
} | ||
|
||
public static @NotNull Optional<TextFormatter> getById(@NotNull String identifier) { | ||
return Arrays.stream(values()).filter((f) -> f.identifier.equalsIgnoreCase(identifier)).findFirst(); | ||
} | ||
} |
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