Skip to content

Commit

Permalink
add font tags
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Jun 29, 2020
1 parent d1c81e9 commit b42b7e4
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 18 deletions.
Expand Up @@ -637,6 +637,26 @@ else if (colorName.startsWith("co@")) {
return new ElementTag(colorOut + object.asString() + ChatColor.COLOR_CHAR + "[reset=" + colorOut.substring(1) + "]");
});

// <--[tag]
// @attribute <ElementTag.font[<font>]>
// @returns ElementTag
// @group text manipulation
// @description
// Makes the input text display with the input font name. Equivalent to "<&font[new-font]><ELEMENT_HERE><&font[previous-font]>"
// The default font is "minecraft:default".
//
// Note that font is a magic Denizen tool, and unlike other format codes (like 'bold') does not appear in Spigot's API or the old Minecraft chat system.
// As such, it only works when sent through certain Denizen commands (narrate, announce, etc) or mechanisms (like ItemTag.book).
// This will not be valid anywhere that isn't in the chat bar or a book (titles, items, etc. will not work).
// -->
PropertyParser.<BukkitElementProperties>registerTag("font", (attribute, object) -> {
if (!attribute.hasContext(1)) {
return null;
}
String fontName = attribute.getContext(1);
return new ElementTag(ChatColor.COLOR_CHAR + "[font=" + fontName + "]" + object.asString() + ChatColor.COLOR_CHAR + "[reset=font]");
});

// <--[tag]
// @attribute <ElementTag.rainbow[(<pattern>)]>
// @returns ElementTag
Expand Down
Expand Up @@ -342,7 +342,6 @@ public void adjust(Mechanism mechanism) {
// <ItemTag.potion_effect[<#>].amplifier>
// <ItemTag.potion_effect[<#>].is_ambient>
// <ItemTag.potion_effect[<#>].has_particles>
// <ItemTag.potion_effect[<#>].color>
// <ItemTag.potion_effect[<#>].icon>
// <server.potion_types>
// <server.potion_effect_types>
Expand Down
Expand Up @@ -605,7 +605,7 @@ public void run(ReplaceableTagEvent event) {
// Color can be a color name, color code, hex, or ColorTag... that is: "&color[gold]", "&color[6]", "&color[#AABB00]", and "&color[co@128,64,0]" are all valid.
//
// Note that Full RGB Color is a magic Denizen tool, and unlike other format codes (like 'bold') or the default 16 colors (like 'gold') does not appear in Spigot's API or the old Minecraft chat system.
// This instead generates the special modern Minecraft JSON codes for scoreboard scores through the Denizen message processor.
// This instead generates the special modern Minecraft JSON codes for colors through the Denizen message processor.
// As such, it only works when sent through certain Denizen commands (narrate, announce, etc) or mechanisms (like ItemTag.book).
// This will not be valid anywhere that isn't in the chat bar or a book (titles, items, etc. will not work).
// -->
Expand All @@ -625,7 +625,7 @@ public void run(ReplaceableTagEvent event) {
}
}
else if (colorName.length() == 7 && colorName.startsWith("#")) {
event.setReplacedObject(new ElementTag(net.md_5.bungee.api.ChatColor.COLOR_CHAR + "[color=" + colorName + "]").getObjectAttribute(attribute.fulfill(1)));
event.setReplacedObject(new ElementTag(ChatColor.COLOR_CHAR + "[color=" + colorName + "]").getObjectAttribute(attribute.fulfill(1)));
return;
}
else if (colorName.startsWith("co@")) {
Expand All @@ -634,7 +634,7 @@ else if (colorName.startsWith("co@")) {
while (hex.length() < 6) {
hex = "0" + hex;
}
event.setReplacedObject(new ElementTag(net.md_5.bungee.api.ChatColor.COLOR_CHAR + "[color=#" + hex + "]").getObjectAttribute(attribute.fulfill(1)));
event.setReplacedObject(new ElementTag(ChatColor.COLOR_CHAR + "[color=#" + hex + "]").getObjectAttribute(attribute.fulfill(1)));
}
if (colorOut == null) {
try {
Expand All @@ -650,6 +650,30 @@ else if (colorName.startsWith("co@")) {
}
}, "&color");

// <--[tag]
// @attribute <&font[<font>]>
// @returns ElementTag
// @description
// Returns a chat code that makes the following text display with the specified font.
// The default font is "minecraft:default".
//
// Note that this is a magic Denizen tool, and unlike other format codes (like 'bold') does not appear in Spigot's API or the old Minecraft chat system.
// This instead generates the special modern Minecraft JSON codes for fonts through the Denizen message processor.
// As such, it only works when sent through certain Denizen commands (narrate, announce, etc) or mechanisms (like ItemTag.book).
// This will not be valid anywhere that isn't in the chat bar or a book (titles, items, etc. will not work).
// -->
TagManager.registerTagHandler(new TagRunnable.RootForm() {
@Override
public void run(ReplaceableTagEvent event) {
Attribute attribute = event.getAttributes();
if (!attribute.hasContext(1)) {
return;
}
String fontName = attribute.getContext(1);
event.setReplacedObject(new ElementTag(ChatColor.COLOR_CHAR + "[font=" + fontName + "]").getObjectAttribute(attribute.fulfill(1)));
}
}, "&font");

// <--[tag]
// @attribute <&0>
// @returns ElementTag
Expand Down
Expand Up @@ -250,21 +250,26 @@ else if (innardType.equals("insertion")) {
endBracket = endIndex + "&[/insertion".length();
}
else if (innardType.equals("reset")) {
char subCode = innardBase.get(1).charAt(0);
if (subCode == 'k' || subCode == 'K') {
nextText.setObfuscated(false);
}
else if (subCode == 'l' || subCode == 'L') {
nextText.setBold(false);
}
else if (subCode == 'm' || subCode == 'M') {
nextText.setStrikethrough(false);
}
else if (subCode == 'n' || subCode == 'N') {
nextText.setUnderlined(false);
if (innardBase.get(1).length() == 1) {
char subCode = innardBase.get(1).charAt(0);
if (subCode == 'k' || subCode == 'K') {
nextText.setObfuscated(false);
}
else if (subCode == 'l' || subCode == 'L') {
nextText.setBold(false);
}
else if (subCode == 'm' || subCode == 'M') {
nextText.setStrikethrough(false);
}
else if (subCode == 'n' || subCode == 'N') {
nextText.setUnderlined(false);
}
else if (subCode == 'o' || subCode == 'O') {
nextText.setItalic(false);
}
}
else if (subCode == 'o' || subCode == 'O') {
nextText.setItalic(false);
else if (innardBase.get(1).equals("font")) {
nextText.setFont(doublelasttext.getFont());
}
else {
nextText.setColor(doublelasttext.getColor());
Expand All @@ -279,6 +284,9 @@ else if (colorChar.length() == 7) {
nextText.setColor(ChatColor.of(colorChar));
}
}
else if (innardType.equals("font")) {
nextText.setFont(innardBase.get(1));
}
}
i = endBracket;
started = endBracket + 1;
Expand Down

0 comments on commit b42b7e4

Please sign in to comment.