{"action":"created","comment":{"url":"https://api.github.com/repos/SpongePowered/SpongeAPI/pulls/comments/53273418","id":53273418,"diff_hunk":"@@ -0,0 +1,473 @@\n+/*\n+ * This file is part of SpongeAPI, licensed under the MIT License (MIT).\n+ *\n+ * Copyright (c) SpongePowered <https://www.spongepowered.org>\n+ * Copyright (c) contributors\n+ *\n+ * Permission is hereby granted, free of charge, to any person obtaining a copy\n+ * of this software and associated documentation files (the \"Software\"), to deal\n+ * in the Software without restriction, including without limitation the rights\n+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n+ * copies of the Software, and to permit persons to whom the Software is\n+ * furnished to do so, subject to the following conditions:\n+ *\n+ * The above copyright notice and this permission notice shall be included in\n+ * all copies or substantial portions of the Software.\n+ *\n+ * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n+ * THE SOFTWARE.\n+ */\n+package org.spongepowered.api.text;\n+\n+import static com.google.common.base.Preconditions.checkNotNull;\n+\n+import com.google.common.base.Objects;\n+import com.google.common.collect.ImmutableBiMap;\n+import com.google.common.collect.ImmutableList;\n+import com.google.common.reflect.TypeToken;\n+import ninja.leaping.configurate.objectmapping.Setting;\n+import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable;\n+import ninja.leaping.configurate.objectmapping.serialize.TypeSerializers;\n+import org.spongepowered.api.text.format.TextColor;\n+import org.spongepowered.api.text.format.TextFormat;\n+import org.spongepowered.api.text.format.TextStyle;\n+import org.spongepowered.api.text.serializer.TextTemplateConfigSerializer;\n+\n+import java.util.ArrayList;\n+import java.util.Collections;\n+import java.util.HashMap;\n+import java.util.List;\n+import java.util.Map;\n+import java.util.Optional;\n+\n+import javax.annotation.Nullable;\n+\n+/**\n+ * Represents a re-usable template that produces a formatted\n+ * {@link Text.Builder}. Elements will be appended to the result builder in the\n+ * order that they are specified in {@link #of(Object...)}.\n+ */\n+public class TextTemplate implements TextRepresentable {\n+\n+    static {\n+        TypeSerializers.getDefaultSerializers().registerType(TypeToken.of(TextTemplate.class), new TextTemplateConfigSerializer());\n+    }\n+\n+    /**\n+     * Default \"open\" String for how arguments are contained within the template.\n+     */\n+    public static final String DEFAULT_OPEN_ARG = \"{\";\n+\n+    /**\n+     * Default \"close\" String for how arguments are contained within the template.\n+     */\n+    public static final String DEFAULT_CLOSE_ARG = \"}\";\n+\n+    /**\n+     * Empty representation of a {@link TextTemplate}. This is returned if the\n+     * array supplied to {@link #of(Object...)} is empty.\n+     */\n+    public static final TextTemplate EMPTY = new TextTemplate(DEFAULT_OPEN_ARG, DEFAULT_CLOSE_ARG, new Object[]{});\n+\n+    protected final List<Object> elements = new ArrayList<>();\n+    protected final Map<String, Arg> arguments = new HashMap<>();\n+    protected final String openArg, closeArg;\n+\n+    protected TextTemplate(String openArg, String closeArg, Object[] elements) {\n+        this.openArg = openArg;\n+        this.closeArg = closeArg;\n+        for (Object element : elements) {\n+            if (element instanceof Arg.Builder) {\n+                element = ((Arg.Builder) element).build();\n+            }\n+            this.elements.add(element);\n+            if (element instanceof Arg) {\n+                // check for non-equal duplicate argument\n+                Arg newArg = (Arg) element;\n+                newArg.openArg = this.openArg;\n+                newArg.closeArg = this.closeArg;\n+                Arg oldArg = this.arguments.get(newArg.name);\n+                if (oldArg != null && !oldArg.equals(newArg)) {\n+                    throw new TextTemplateArgumentException(\"Tried to supply an unequal argument with a duplicate name \\\"\"\n+                            + newArg.name + \"\\\" to TextTemplate.\");\n+                }\n+                arguments.put(newArg.name, newArg);\n+            }\n+        }\n+    }\n+\n+    /**\n+     * Returns the elements contained in this TextTemplate.\n+     *\n+     * @return The elements within the template\n+     */\n+    public List<Object> getElements() {\n+        return ImmutableList.copyOf(this.elements);\n+    }\n+\n+    /**\n+     * Returns the arguments contained within the TextTemplate.\n+     *\n+     * @return The arguments within this TextTemplate\n+     */\n+    public Map<String, Arg> getArguments() {\n+        return ImmutableBiMap.copyOf(this.arguments);","path":"src/main/java/org/spongepowered/api/text/TextTemplate.java","position":119,"original_position":119,"commit_id":"41f86f4f2e636030931126d16a4743e3093406b9","original_commit_id":"d6b23f3dc6a8ad1279c71301acfe1282d2adcec4","user":{"login":"kashike","id":5474071,"avatar_url":"https://avatars.githubusercontent.com/u/5474071?v=3","gravatar_id":"","url":"https://api.github.com/users/kashike","html_url":"https://github.com/kashike","followers_url":"https://api.github.com/users/kashike/followers","following_url":"https://api.github.com/users/kashike/following{/other_user}","gists_url":"https://api.github.com/users/kashike/gists{/gist_id}","starred_url":"https://api.github.com/users/kashike/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kashike/subscriptions","organizations_url":"https://api.github.com/users/kashike/orgs","repos_url":"https://api.github.com/users/kashike/repos","events_url":"https://api.github.com/users/kashike/events{/privacy}","received_events_url":"https://api.github.com/users/kashike/received_events","type":"User","site_admin":false},"body":"...what? The original is not a `BiMap`. I assume you meant `ImmutableMap.copyOf(this.arguments)`?","created_at":"2016-02-18T05:33:58Z","updated_at":"2016-02-18T05:33:58Z","html_url":"https://github.com/SpongePowered/SpongeAPI/pull/1079#discussion_r53273418","pull_request_url":"https://api.github.com/repos/SpongePowered/SpongeAPI/pulls/1079","_links":{"self":{"href":"https://api.github.com/repos/SpongePowered/SpongeAPI/pulls/comments/53273418"},"html":{"href":"https://github.com/SpongePowered/SpongeAPI/pull/1079#discussion_r53273418"},"pull_request":{"href":"https://api.github.com/repos/SpongePowered/SpongeAPI/pulls/1079"}}},"pull_request":{"url":"https://api.github.com/repos/SpongePowered/SpongeAPI/pulls/1079","id":59548171,"html_url":"https://github.com/SpongePowered/SpongeAPI/pull/1079","diff_url":"https://github.com/SpongePowered/SpongeAPI/pull/1079.diff","patch_url":"https://github.com/SpongePowered/SpongeAPI/pull/1079.patch","issue_url":"https://api.github.com/repos/SpongePowered/SpongeAPI/issues/1079","number":1079,"state":"open","locked":false,"title":"[WIP] TextTemplates","user":{"login":"windy1","id":755713,"avatar_url":"https://avatars.githubusercontent.com/u/755713?v=3","gravatar_id":"","url":"https://api.github.com/users/windy1","html_url":"https://github.com/windy1","followers_url":"https://api.github.com/users/windy1/followers","following_url":"https://api.github.com/users/windy1/following{/other_user}","gists_url":"https://api.github.com/users/windy1/gists{/gist_id}","starred_url":"https://api.github.com/users/windy1/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/windy1/subscriptions","organizations_url":"https://api.github.com/users/windy1/orgs","repos_url":"https://api.github.com/users/windy1/repos","events_url":"https://api.github.com/users/windy1/events{/privacy}","received_events_url":"https://api.github.com/users/windy1/received_events","type":"User","site_admin":false},"body":"# Example\r\n\r\n```java\r\nimport static org.spongepowered.api.text.template.TextTemplate.*;\r\n\r\nTextTemplate template = of(\r\n    TextColors.BLUE, \"Hello, \", arg(\"playerName\"), \"!\"\r\n);\r\n\r\nvoid onPlayerJoin() {\r\n    player.sendMessage(template, ImmutableMap.of(\"player\", Text.of(player.getName()));\r\n}\r\n```\r\n\r\n## Serialized\r\n\r\n```hocon\r\ntemplate {\r\n    arguments {\r\n        playerName {\r\n            optional=false\r\n        }\r\n    }\r\n    content {\r\n        color=blue\r\n        extra=[\r\n            \"Hello, \",\r\n            \"{playerName}\",\r\n            \"!\"\r\n        ]\r\n        text=\"\"\r\n    }\r\n}\r\n```\r\n\r\nSigned-off-by: Walker Crouse <walkercrouse@hotmail.com>","created_at":"2016-02-16T20:20:51Z","updated_at":"2016-02-18T05:33:58Z","closed_at":null,"merged_at":null,"merge_commit_sha":"b0083e94c604438dc66b41cb9c1db1dcec6616b1","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/SpongePowered/SpongeAPI/pulls/1079/commits","review_comments_url":"https://api.github.com/repos/SpongePowered/SpongeAPI/pulls/1079/comments","review_comment_url":"https://api.github.com/repos/SpongePowered/SpongeAPI/pulls/comments{/number}","comments_url":"https://api.github.com/repos/SpongePowered/SpongeAPI/issues/1079/comments","statuses_url":"https://api.github.com/repos/SpongePowered/SpongeAPI/statuses/41f86f4f2e636030931126d16a4743e3093406b9","head":{"label":"SpongePowered:feature/text-template","ref":"feature/text-template","sha":"41f86f4f2e636030931126d16a4743e3093406b9","user":{"login":"SpongePowered","id":8683473,"avatar_url":"https://avatars.githubusercontent.com/u/8683473?v=3","gravatar_id":"","url":"https://api.github.com/users/SpongePowered","html_url":"https://github.com/SpongePowered","followers_url":"https://api.github.com/users/SpongePowered/followers","following_url":"https://api.github.com/users/SpongePowered/following{/other_user}","gists_url":"https://api.github.com/users/SpongePowered/gists{/gist_id}","starred_url":"https://api.github.com/users/SpongePowered/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SpongePowered/subscriptions","organizations_url":"https://api.github.com/users/SpongePowered/orgs","repos_url":"https://api.github.com/users/SpongePowered/repos","events_url":"https://api.github.com/users/SpongePowered/events{/privacy}","received_events_url":"https://api.github.com/users/SpongePowered/received_events","type":"Organization","site_admin":false},"repo":{"id":23770421,"name":"SpongeAPI","full_name":"SpongePowered/SpongeAPI","owner":{"login":"SpongePowered","id":8683473,"avatar_url":"https://avatars.githubusercontent.com/u/8683473?v=3","gravatar_id":"","url":"https://api.github.com/users/SpongePowered","html_url":"https://github.com/SpongePowered","followers_url":"https://api.github.com/users/SpongePowered/followers","following_url":"https://api.github.com/users/SpongePowered/following{/other_user}","gists_url":"https://api.github.com/users/SpongePowered/gists{/gist_id}","starred_url":"https://api.github.com/users/SpongePowered/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SpongePowered/subscriptions","organizations_url":"https://api.github.com/users/SpongePowered/orgs","repos_url":"https://api.github.com/users/SpongePowered/repos","events_url":"https://api.github.com/users/SpongePowered/events{/privacy}","received_events_url":"https://api.github.com/users/SpongePowered/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/SpongePowered/SpongeAPI","description":"A Minecraft plugin API","fork":false,"url":"https://api.github.com/repos/SpongePowered/SpongeAPI","forks_url":"https://api.github.com/repos/SpongePowered/SpongeAPI/forks","keys_url":"https://api.github.com/repos/SpongePowered/SpongeAPI/keys{/key_id}","collaborators_url":"https://api.github.com/repos/SpongePowered/SpongeAPI/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/SpongePowered/SpongeAPI/teams","hooks_url":"https://api.github.com/repos/SpongePowered/SpongeAPI/hooks","issue_events_url":"https://api.github.com/repos/SpongePowered/SpongeAPI/issues/events{/number}","events_url":"https://api.github.com/repos/SpongePowered/SpongeAPI/events","assignees_url":"https://api.github.com/repos/SpongePowered/SpongeAPI/assignees{/user}","branches_url":"https://api.github.com/repos/SpongePowered/SpongeAPI/branches{/branch}","tags_url":"https://api.github.com/repos/SpongePowered/SpongeAPI/tags","blobs_url":"https://api.github.com/repos/SpongePowered/SpongeAPI/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/SpongePowered/SpongeAPI/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/SpongePowered/SpongeAPI/git/refs{/sha}","trees_url":"https://api.github.com/repos/SpongePowered/SpongeAPI/git/trees{/sha}","statuses_url":"https://api.github.com/repos/SpongePowered/SpongeAPI/statuses/{sha}","languages_url":"https://api.github.com/repos/SpongePowered/SpongeAPI/languages","stargazers_url":"https://api.github.com/repos/SpongePowered/SpongeAPI/stargazers","contributors_url":"https://api.github.com/repos/SpongePowered/SpongeAPI/contributors","subscribers_url":"https://api.github.com/repos/SpongePowered/SpongeAPI/subscribers","subscription_url":"https://api.github.com/repos/SpongePowered/SpongeAPI/subscription","commits_url":"https://api.github.com/repos/SpongePowered/SpongeAPI/commits{/sha}","git_commits_url":"https://api.github.com/repos/SpongePowered/SpongeAPI/git/commits{/sha}","comments_url":"https://api.github.com/repos/SpongePowered/SpongeAPI/comments{/number}","issue_comment_url":"https://api.github.com/repos/SpongePowered/SpongeAPI/issues/comments{/number}","contents_url":"https://api.github.com/repos/SpongePowered/SpongeAPI/contents/{+path}","compare_url":"https://api.github.com/repos/SpongePowered/SpongeAPI/compare/{base}...{head}","merges_url":"https://api.github.com/repos/SpongePowered/SpongeAPI/merges","archive_url":"https://api.github.com/repos/SpongePowered/SpongeAPI/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/SpongePowered/SpongeAPI/downloads","issues_url":"https://api.github.com/repos/SpongePowered/SpongeAPI/issues{/number}","pulls_url":"https://api.github.com/repos/SpongePowered/SpongeAPI/pulls{/number}","milestones_url":"https://api.github.com/repos/SpongePowered/SpongeAPI/milestones{/number}","notifications_url":"https://api.github.com/repos/SpongePowered/SpongeAPI/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/SpongePowered/SpongeAPI/labels{/name}","releases_url":"https://api.github.com/repos/SpongePowered/SpongeAPI/releases{/id}","deployments_url":"https://api.github.com/repos/SpongePowered/SpongeAPI/deployments","created_at":"2014-09-07T20:39:25Z","updated_at":"2016-02-17T15:34:50Z","pushed_at":"2016-02-18T05:33:55Z","git_url":"git://github.com/SpongePowered/SpongeAPI.git","ssh_url":"git@github.com:SpongePowered/SpongeAPI.git","clone_url":"https://github.com/SpongePowered/SpongeAPI.git","svn_url":"https://github.com/SpongePowered/SpongeAPI","homepage":"http://www.spongepowered.org/","size":21086,"stargazers_count":840,"watchers_count":840,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":346,"mirror_url":null,"open_issues_count":120,"forks":346,"open_issues":120,"watchers":840,"default_branch":"master"}},"base":{"label":"SpongePowered:master","ref":"master","sha":"ecd761a70219e467dea47a09fc310e8238e9911f","user":{"login":"SpongePowered","id":8683473,"avatar_url":"https://avatars.githubusercontent.com/u/8683473?v=3","gravatar_id":"","url":"https://api.github.com/users/SpongePowered","html_url":"https://github.com/SpongePowered","followers_url":"https://api.github.com/users/SpongePowered/followers","following_url":"https://api.github.com/users/SpongePowered/following{/other_user}","gists_url":"https://api.github.com/users/SpongePowered/gists{/gist_id}","starred_url":"https://api.github.com/users/SpongePowered/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SpongePowered/subscriptions","organizations_url":"https://api.github.com/users/SpongePowered/orgs","repos_url":"https://api.github.com/users/SpongePowered/repos","events_url":"https://api.github.com/users/SpongePowered/events{/privacy}","received_events_url":"https://api.github.com/users/SpongePowered/received_events","type":"Organization","site_admin":false},"repo":{"id":23770421,"name":"SpongeAPI","full_name":"SpongePowered/SpongeAPI","owner":{"login":"SpongePowered","id":8683473,"avatar_url":"https://avatars.githubusercontent.com/u/8683473?v=3","gravatar_id":"","url":"https://api.github.com/users/SpongePowered","html_url":"https://github.com/SpongePowered","followers_url":"https://api.github.com/users/SpongePowered/followers","following_url":"https://api.github.com/users/SpongePowered/following{/other_user}","gists_url":"https://api.github.com/users/SpongePowered/gists{/gist_id}","starred_url":"https://api.github.com/users/SpongePowered/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SpongePowered/subscriptions","organizations_url":"https://api.github.com/users/SpongePowered/orgs","repos_url":"https://api.github.com/users/SpongePowered/repos","events_url":"https://api.github.com/users/SpongePowered/events{/privacy}","received_events_url":"https://api.github.com/users/SpongePowered/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/SpongePowered/SpongeAPI","description":"A Minecraft plugin API","fork":false,"url":"https://api.github.com/repos/SpongePowered/SpongeAPI","forks_url":"https://api.github.com/repos/SpongePowered/SpongeAPI/forks","keys_url":"https://api.github.com/repos/SpongePowered/SpongeAPI/keys{/key_id}","collaborators_url":"https://api.github.com/repos/SpongePowered/SpongeAPI/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/SpongePowered/SpongeAPI/teams","hooks_url":"https://api.github.com/repos/SpongePowered/SpongeAPI/hooks","issue_events_url":"https://api.github.com/repos/SpongePowered/SpongeAPI/issues/events{/number}","events_url":"https://api.github.com/repos/SpongePowered/SpongeAPI/events","assignees_url":"https://api.github.com/repos/SpongePowered/SpongeAPI/assignees{/user}","branches_url":"https://api.github.com/repos/SpongePowered/SpongeAPI/branches{/branch}","tags_url":"https://api.github.com/repos/SpongePowered/SpongeAPI/tags","blobs_url":"https://api.github.com/repos/SpongePowered/SpongeAPI/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/SpongePowered/SpongeAPI/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/SpongePowered/SpongeAPI/git/refs{/sha}","trees_url":"https://api.github.com/repos/SpongePowered/SpongeAPI/git/trees{/sha}","statuses_url":"https://api.github.com/repos/SpongePowered/SpongeAPI/statuses/{sha}","languages_url":"https://api.github.com/repos/SpongePowered/SpongeAPI/languages","stargazers_url":"https://api.github.com/repos/SpongePowered/SpongeAPI/stargazers","contributors_url":"https://api.github.com/repos/SpongePowered/SpongeAPI/contributors","subscribers_url":"https://api.github.com/repos/SpongePowered/SpongeAPI/subscribers","subscription_url":"https://api.github.com/repos/SpongePowered/SpongeAPI/subscription","commits_url":"https://api.github.com/repos/SpongePowered/SpongeAPI/commits{/sha}","git_commits_url":"https://api.github.com/repos/SpongePowered/SpongeAPI/git/commits{/sha}","comments_url":"https://api.github.com/repos/SpongePowered/SpongeAPI/comments{/number}","issue_comment_url":"https://api.github.com/repos/SpongePowered/SpongeAPI/issues/comments{/number}","contents_url":"https://api.github.com/repos/SpongePowered/SpongeAPI/contents/{+path}","compare_url":"https://api.github.com/repos/SpongePowered/SpongeAPI/compare/{base}...{head}","merges_url":"https://api.github.com/repos/SpongePowered/SpongeAPI/merges","archive_url":"https://api.github.com/repos/SpongePowered/SpongeAPI/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/SpongePowered/SpongeAPI/downloads","issues_url":"https://api.github.com/repos/SpongePowered/SpongeAPI/issues{/number}","pulls_url":"https://api.github.com/repos/SpongePowered/SpongeAPI/pulls{/number}","milestones_url":"https://api.github.com/repos/SpongePowered/SpongeAPI/milestones{/number}","notifications_url":"https://api.github.com/repos/SpongePowered/SpongeAPI/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/SpongePowered/SpongeAPI/labels{/name}","releases_url":"https://api.github.com/repos/SpongePowered/SpongeAPI/releases{/id}","deployments_url":"https://api.github.com/repos/SpongePowered/SpongeAPI/deployments","created_at":"2014-09-07T20:39:25Z","updated_at":"2016-02-17T15:34:50Z","pushed_at":"2016-02-18T05:33:55Z","git_url":"git://github.com/SpongePowered/SpongeAPI.git","ssh_url":"git@github.com:SpongePowered/SpongeAPI.git","clone_url":"https://github.com/SpongePowered/SpongeAPI.git","svn_url":"https://github.com/SpongePowered/SpongeAPI","homepage":"http://www.spongepowered.org/","size":21086,"stargazers_count":840,"watchers_count":840,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":346,"mirror_url":null,"open_issues_count":120,"forks":346,"open_issues":120,"watchers":840,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/SpongePowered/SpongeAPI/pulls/1079"},"html":{"href":"https://github.com/SpongePowered/SpongeAPI/pull/1079"},"issue":{"href":"https://api.github.com/repos/SpongePowered/SpongeAPI/issues/1079"},"comments":{"href":"https://api.github.com/repos/SpongePowered/SpongeAPI/issues/1079/comments"},"review_comments":{"href":"https://api.github.com/repos/SpongePowered/SpongeAPI/pulls/1079/comments"},"review_comment":{"href":"https://api.github.com/repos/SpongePowered/SpongeAPI/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/SpongePowered/SpongeAPI/pulls/1079/commits"},"statuses":{"href":"https://api.github.com/repos/SpongePowered/SpongeAPI/statuses/41f86f4f2e636030931126d16a4743e3093406b9"}}}}