Skip to content

Commit

Permalink
add base64 tags for Denizen-For-Bukkit#1852
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Jan 17, 2019
1 parent 0aaf610 commit ec2ca1c
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/main/java/net/aufdemrand/denizencore/objects/Element.java
Expand Up @@ -15,6 +15,7 @@
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.Arrays;
import java.util.Base64;
import java.util.HashMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
Expand Down Expand Up @@ -2243,6 +2244,38 @@ public dObject run(Attribute attribute, dObject object) {
}
});

// <--[tag]
// @attribute <el@element.base64_encode>
// @returns Element
// @group math
// @description
// Encodes the element using Base64 encoding.
// -->
registerTag("base64_encode", new TagRunnable.ObjectForm() {
@Override
public dObject run(Attribute attribute, dObject object) {
String encoded = Base64.getEncoder().encodeToString(((Element) object).element.getBytes());
return new Element(encoded)
.getObjectAttribute(attribute.fulfill(1));
}
});

// <--[tag]
// @attribute <el@element.base64_decode>
// @returns Element
// @group math
// @description
// Decodes the element using Base64 encoding. Must be valid Base64 input.
// -->
registerTag("base64_decode", new TagRunnable.ObjectForm() {
@Override
public dObject run(Attribute attribute, dObject object) {
String decoded = new String(Base64.getDecoder().decode(((Element) object).element));
return new Element(decoded)
.getObjectAttribute(attribute.fulfill(1));
}
});

// <--[tag]
// @attribute <el@element.type>
// @returns Element
Expand Down

0 comments on commit ec2ca1c

Please sign in to comment.