-
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add semi-closing tags to QuickText, add DynamicTextNode
- Loading branch information
Showing
13 changed files
with
236 additions
and
45 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
32 changes: 32 additions & 0 deletions
32
src/main/java/eu/pb4/placeholders/api/node/DynamicTextNode.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,32 @@ | ||
package eu.pb4.placeholders.api.node; | ||
|
||
import eu.pb4.placeholders.api.ParserContext; | ||
import net.minecraft.text.Text; | ||
import net.minecraft.util.Formatting; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.function.Function; | ||
|
||
public record DynamicTextNode(String id, ParserContext.Key<Function<String, Text>> key) implements TextNode { | ||
public static DynamicTextNode of(String id, ParserContext.Key<Function<String, Text>> key) { | ||
return new DynamicTextNode(id, key); | ||
} | ||
|
||
public static ParserContext.Key<Function<String, @Nullable Text>> key(String id) { | ||
return new ParserContext.Key<>("dynamic:" + id, null); | ||
} | ||
|
||
@Override | ||
public Text toText(ParserContext context, boolean removeBackslashes) { | ||
var x = context.get(key); | ||
if (x != null) { | ||
return x.apply(id); | ||
} | ||
return Text.literal("[MISSING CONTEXT FOR " + this.key.key() + "]").formatted(Formatting.ITALIC).withColor(0xFF0000); | ||
} | ||
|
||
@Override | ||
public boolean isDynamic() { | ||
return true; | ||
} | ||
} |
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
Oops, something went wrong.