{"action":"created","comment":{"url":"https://api.github.com/repos/SpongePowered/SpongeCommon/pulls/comments/30529092","id":30529092,"diff_hunk":"@@ -0,0 +1,122 @@\n+/*\n+ * This file is part of Sponge, 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.common.data.utils.items;\n+\n+import static com.google.common.base.Preconditions.checkNotNull;\n+import static org.spongepowered.common.data.DataTransactionBuilder.fail;\n+import static org.spongepowered.common.data.DataTransactionBuilder.successNoData;\n+\n+import com.google.common.base.Optional;\n+import net.minecraft.init.Items;\n+import net.minecraft.item.ItemStack;\n+import net.minecraft.nbt.NBTTagString;\n+import org.spongepowered.api.data.DataHolder;\n+import org.spongepowered.api.data.DataPriority;\n+import org.spongepowered.api.data.DataTransactionResult;\n+import org.spongepowered.api.data.DataView;\n+import org.spongepowered.api.data.manipulator.item.AuthorData;\n+import org.spongepowered.api.service.persistence.InvalidDataException;\n+import org.spongepowered.api.text.Texts;\n+import org.spongepowered.common.data.SpongeDataProcessor;\n+import org.spongepowered.common.data.manipulators.items.SpongeAuthorData;\n+\n+public class SpongeAuthorProcessor implements SpongeDataProcessor<AuthorData> {\n+\n+    @Override\n+    public Optional<AuthorData> getFrom(DataHolder holder) {\n+        return Optional.absent();\n+    }\n+\n+    @Override\n+    public Optional<AuthorData> fillData(DataHolder holder, AuthorData manipulator, DataPriority priority) {\n+        if (holder instanceof org.spongepowered.api.item.inventory.ItemStack) {\n+            if (((ItemStack) holder).getItem() != Items.writable_book || ((ItemStack) holder).getItem() != Items.written_book) {\n+                return Optional.absent();\n+            }\n+            switch (checkNotNull(priority)) {\n+                case PRE_MERGE:\n+                case DATA_MANIPULATOR:\n+                    return Optional.of(manipulator);\n+                default:\n+                    manipulator.setValue(Texts.of(((ItemStack) holder).getTagCompound().getString(\"author\")));\n+                    return Optional.of(manipulator);\n+            }\n+        }\n+        return Optional.absent();\n+    }\n+\n+    @Override\n+    public DataTransactionResult setData(DataHolder dataHolder, AuthorData manipulator, DataPriority priority) {\n+        if (dataHolder instanceof ItemStack && (((ItemStack) dataHolder).getItem() == Items.writable_book\n+                || ((ItemStack) dataHolder).getItem() == Items.written_book)) {\n+            ((ItemStack) dataHolder).setTagInfo(\"author\", new NBTTagString(Texts.toPlain(manipulator.getValue())));\n+            return successNoData();\n+        }\n+        return fail(manipulator);\n+    }\n+\n+    @Override\n+    public boolean remove(DataHolder dataHolder) {\n+        if (dataHolder instanceof ItemStack && (((ItemStack) dataHolder).getItem() == Items.writable_book\n+                || ((ItemStack) dataHolder).getItem() == Items.written_book)) {\n+            ((ItemStack) dataHolder).setTagInfo(\"author\", new NBTTagString(\"invalid\"));\n+            return true;\n+        }\n+        return false;\n+    }\n+\n+    @Override\n+    public Optional<AuthorData> build(DataView container) throws InvalidDataException {\n+        if (!checkNotNull(container).contains(SpongeAuthorData.AUTHOR)) {\n+            throw new InvalidDataException(\"Missing author to construct an AuthorData.\");\n+        }\n+        final String rawAuthor = container.getString(SpongeAuthorData.AUTHOR).get();\n+        final AuthorData data = create();\n+        data.setValue(Texts.of(rawAuthor));\n+        return Optional.of(data);\n+    }\n+\n+    @Override\n+    public AuthorData create() {\n+        return new SpongeAuthorData();\n+    }\n+\n+    @Override\n+    public Optional<AuthorData> createFrom(DataHolder dataHolder) {\n+        if (!(dataHolder instanceof ItemStack)) {\n+            return Optional.absent();\n+        }\n+        if (!(((ItemStack) dataHolder).getItem() == Items.written_book)) {\n+            return Optional.absent();\n+        }\n+        if (!((ItemStack) dataHolder).hasTagCompound()) {\n+            return Optional.absent();\n+        }\n+        final String rawAuthor = ((ItemStack) dataHolder).getTagCompound().getString(\"author\");\n+        final AuthorData data = create();\n+        data.setValue(Texts.of(rawAuthor));","path":"src/main/java/org/spongepowered/common/data/utils/items/SpongeAuthorProcessor.java","position":119,"original_position":119,"commit_id":"0d816902ae689cfc90e7338ceeaec309636ecf60","original_commit_id":"0d816902ae689cfc90e7338ceeaec309636ecf60","user":{"login":"gabizou","id":1203877,"avatar_url":"https://avatars.githubusercontent.com/u/1203877?v=3","gravatar_id":"","url":"https://api.github.com/users/gabizou","html_url":"https://github.com/gabizou","followers_url":"https://api.github.com/users/gabizou/followers","following_url":"https://api.github.com/users/gabizou/following{/other_user}","gists_url":"https://api.github.com/users/gabizou/gists{/gist_id}","starred_url":"https://api.github.com/users/gabizou/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gabizou/subscriptions","organizations_url":"https://api.github.com/users/gabizou/orgs","repos_url":"https://api.github.com/users/gabizou/repos","events_url":"https://api.github.com/users/gabizou/events{/privacy}","received_events_url":"https://api.github.com/users/gabizou/received_events","type":"User","site_admin":false},"body":"this can be done with fluency:\r\n\r\n```java\r\nreturn Optional.of(create().setValue(Texts.fromLegacy(rawAuthor)));\r\n```\r\n","created_at":"2015-05-18T17:33:12Z","updated_at":"2015-05-18T17:33:12Z","html_url":"https://github.com/SpongePowered/SpongeCommon/pull/38#discussion_r30529092","pull_request_url":"https://api.github.com/repos/SpongePowered/SpongeCommon/pulls/38","_links":{"self":{"href":"https://api.github.com/repos/SpongePowered/SpongeCommon/pulls/comments/30529092"},"html":{"href":"https://github.com/SpongePowered/SpongeCommon/pull/38#discussion_r30529092"},"pull_request":{"href":"https://api.github.com/repos/SpongePowered/SpongeCommon/pulls/38"}}},"pull_request":{"url":"https://api.github.com/repos/SpongePowered/SpongeCommon/pulls/38","id":35606656,"html_url":"https://github.com/SpongePowered/SpongeCommon/pull/38","diff_url":"https://github.com/SpongePowered/SpongeCommon/pull/38.diff","patch_url":"https://github.com/SpongePowered/SpongeCommon/pull/38.patch","issue_url":"https://api.github.com/repos/SpongePowered/SpongeCommon/issues/38","number":38,"state":"open","locked":false,"title":"[WIP] AuthorData implementation and fixes for PagedData","user":{"login":"Grinch","id":963480,"avatar_url":"https://avatars.githubusercontent.com/u/963480?v=3","gravatar_id":"","url":"https://api.github.com/users/Grinch","html_url":"https://github.com/Grinch","followers_url":"https://api.github.com/users/Grinch/followers","following_url":"https://api.github.com/users/Grinch/following{/other_user}","gists_url":"https://api.github.com/users/Grinch/gists{/gist_id}","starred_url":"https://api.github.com/users/Grinch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Grinch/subscriptions","organizations_url":"https://api.github.com/users/Grinch/orgs","repos_url":"https://api.github.com/users/Grinch/repos","events_url":"https://api.github.com/users/Grinch/events{/privacy}","received_events_url":"https://api.github.com/users/Grinch/received_events","type":"User","site_admin":false},"body":"I've also taken the liberty of getting the implementation for\r\ngetManipulators for MixinItemStack. I have verified in my plugin's code\r\nthat I am getting manipulator data when holding a book/tool/sword/armor.\r\n\r\nSigned-off-by: Steven Downer <grinch@outlook.com>","created_at":"2015-05-18T06:52:31Z","updated_at":"2015-05-18T17:33:12Z","closed_at":null,"merged_at":null,"merge_commit_sha":"aed0e4e081a7986cdc0a9bdf688a07cbe0fdc22e","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/SpongePowered/SpongeCommon/pulls/38/commits","review_comments_url":"https://api.github.com/repos/SpongePowered/SpongeCommon/pulls/38/comments","review_comment_url":"https://api.github.com/repos/SpongePowered/SpongeCommon/pulls/comments{/number}","comments_url":"https://api.github.com/repos/SpongePowered/SpongeCommon/issues/38/comments","statuses_url":"https://api.github.com/repos/SpongePowered/SpongeCommon/statuses/0d816902ae689cfc90e7338ceeaec309636ecf60","head":{"label":"Grinch:patch-1","ref":"patch-1","sha":"0d816902ae689cfc90e7338ceeaec309636ecf60","user":{"login":"Grinch","id":963480,"avatar_url":"https://avatars.githubusercontent.com/u/963480?v=3","gravatar_id":"","url":"https://api.github.com/users/Grinch","html_url":"https://github.com/Grinch","followers_url":"https://api.github.com/users/Grinch/followers","following_url":"https://api.github.com/users/Grinch/following{/other_user}","gists_url":"https://api.github.com/users/Grinch/gists{/gist_id}","starred_url":"https://api.github.com/users/Grinch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Grinch/subscriptions","organizations_url":"https://api.github.com/users/Grinch/orgs","repos_url":"https://api.github.com/users/Grinch/repos","events_url":"https://api.github.com/users/Grinch/events{/privacy}","received_events_url":"https://api.github.com/users/Grinch/received_events","type":"User","site_admin":false},"repo":{"id":34674486,"name":"SpongeCommon","full_name":"Grinch/SpongeCommon","owner":{"login":"Grinch","id":963480,"avatar_url":"https://avatars.githubusercontent.com/u/963480?v=3","gravatar_id":"","url":"https://api.github.com/users/Grinch","html_url":"https://github.com/Grinch","followers_url":"https://api.github.com/users/Grinch/followers","following_url":"https://api.github.com/users/Grinch/following{/other_user}","gists_url":"https://api.github.com/users/Grinch/gists{/gist_id}","starred_url":"https://api.github.com/users/Grinch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Grinch/subscriptions","organizations_url":"https://api.github.com/users/Grinch/orgs","repos_url":"https://api.github.com/users/Grinch/repos","events_url":"https://api.github.com/users/Grinch/events{/privacy}","received_events_url":"https://api.github.com/users/Grinch/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Grinch/SpongeCommon","description":"Shared code between Sponge and SpongeVanilla","fork":true,"url":"https://api.github.com/repos/Grinch/SpongeCommon","forks_url":"https://api.github.com/repos/Grinch/SpongeCommon/forks","keys_url":"https://api.github.com/repos/Grinch/SpongeCommon/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Grinch/SpongeCommon/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Grinch/SpongeCommon/teams","hooks_url":"https://api.github.com/repos/Grinch/SpongeCommon/hooks","issue_events_url":"https://api.github.com/repos/Grinch/SpongeCommon/issues/events{/number}","events_url":"https://api.github.com/repos/Grinch/SpongeCommon/events","assignees_url":"https://api.github.com/repos/Grinch/SpongeCommon/assignees{/user}","branches_url":"https://api.github.com/repos/Grinch/SpongeCommon/branches{/branch}","tags_url":"https://api.github.com/repos/Grinch/SpongeCommon/tags","blobs_url":"https://api.github.com/repos/Grinch/SpongeCommon/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Grinch/SpongeCommon/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Grinch/SpongeCommon/git/refs{/sha}","trees_url":"https://api.github.com/repos/Grinch/SpongeCommon/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Grinch/SpongeCommon/statuses/{sha}","languages_url":"https://api.github.com/repos/Grinch/SpongeCommon/languages","stargazers_url":"https://api.github.com/repos/Grinch/SpongeCommon/stargazers","contributors_url":"https://api.github.com/repos/Grinch/SpongeCommon/contributors","subscribers_url":"https://api.github.com/repos/Grinch/SpongeCommon/subscribers","subscription_url":"https://api.github.com/repos/Grinch/SpongeCommon/subscription","commits_url":"https://api.github.com/repos/Grinch/SpongeCommon/commits{/sha}","git_commits_url":"https://api.github.com/repos/Grinch/SpongeCommon/git/commits{/sha}","comments_url":"https://api.github.com/repos/Grinch/SpongeCommon/comments{/number}","issue_comment_url":"https://api.github.com/repos/Grinch/SpongeCommon/issues/comments{/number}","contents_url":"https://api.github.com/repos/Grinch/SpongeCommon/contents/{+path}","compare_url":"https://api.github.com/repos/Grinch/SpongeCommon/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Grinch/SpongeCommon/merges","archive_url":"https://api.github.com/repos/Grinch/SpongeCommon/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Grinch/SpongeCommon/downloads","issues_url":"https://api.github.com/repos/Grinch/SpongeCommon/issues{/number}","pulls_url":"https://api.github.com/repos/Grinch/SpongeCommon/pulls{/number}","milestones_url":"https://api.github.com/repos/Grinch/SpongeCommon/milestones{/number}","notifications_url":"https://api.github.com/repos/Grinch/SpongeCommon/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Grinch/SpongeCommon/labels{/name}","releases_url":"https://api.github.com/repos/Grinch/SpongeCommon/releases{/id}","created_at":"2015-04-27T15:23:35Z","updated_at":"2015-04-27T15:23:36Z","pushed_at":"2015-05-18T17:05:04Z","git_url":"git://github.com/Grinch/SpongeCommon.git","ssh_url":"git@github.com:Grinch/SpongeCommon.git","clone_url":"https://github.com/Grinch/SpongeCommon.git","svn_url":"https://github.com/Grinch/SpongeCommon","homepage":null,"size":636,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"SpongePowered:master","ref":"master","sha":"0ccf74b3f252ecfa13fdcacd67b535cedfd471b2","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":33791453,"name":"SpongeCommon","full_name":"SpongePowered/SpongeCommon","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/SpongeCommon","description":"Shared code between Sponge and SpongeVanilla","fork":false,"url":"https://api.github.com/repos/SpongePowered/SpongeCommon","forks_url":"https://api.github.com/repos/SpongePowered/SpongeCommon/forks","keys_url":"https://api.github.com/repos/SpongePowered/SpongeCommon/keys{/key_id}","collaborators_url":"https://api.github.com/repos/SpongePowered/SpongeCommon/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/SpongePowered/SpongeCommon/teams","hooks_url":"https://api.github.com/repos/SpongePowered/SpongeCommon/hooks","issue_events_url":"https://api.github.com/repos/SpongePowered/SpongeCommon/issues/events{/number}","events_url":"https://api.github.com/repos/SpongePowered/SpongeCommon/events","assignees_url":"https://api.github.com/repos/SpongePowered/SpongeCommon/assignees{/user}","branches_url":"https://api.github.com/repos/SpongePowered/SpongeCommon/branches{/branch}","tags_url":"https://api.github.com/repos/SpongePowered/SpongeCommon/tags","blobs_url":"https://api.github.com/repos/SpongePowered/SpongeCommon/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/SpongePowered/SpongeCommon/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/SpongePowered/SpongeCommon/git/refs{/sha}","trees_url":"https://api.github.com/repos/SpongePowered/SpongeCommon/git/trees{/sha}","statuses_url":"https://api.github.com/repos/SpongePowered/SpongeCommon/statuses/{sha}","languages_url":"https://api.github.com/repos/SpongePowered/SpongeCommon/languages","stargazers_url":"https://api.github.com/repos/SpongePowered/SpongeCommon/stargazers","contributors_url":"https://api.github.com/repos/SpongePowered/SpongeCommon/contributors","subscribers_url":"https://api.github.com/repos/SpongePowered/SpongeCommon/subscribers","subscription_url":"https://api.github.com/repos/SpongePowered/SpongeCommon/subscription","commits_url":"https://api.github.com/repos/SpongePowered/SpongeCommon/commits{/sha}","git_commits_url":"https://api.github.com/repos/SpongePowered/SpongeCommon/git/commits{/sha}","comments_url":"https://api.github.com/repos/SpongePowered/SpongeCommon/comments{/number}","issue_comment_url":"https://api.github.com/repos/SpongePowered/SpongeCommon/issues/comments{/number}","contents_url":"https://api.github.com/repos/SpongePowered/SpongeCommon/contents/{+path}","compare_url":"https://api.github.com/repos/SpongePowered/SpongeCommon/compare/{base}...{head}","merges_url":"https://api.github.com/repos/SpongePowered/SpongeCommon/merges","archive_url":"https://api.github.com/repos/SpongePowered/SpongeCommon/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/SpongePowered/SpongeCommon/downloads","issues_url":"https://api.github.com/repos/SpongePowered/SpongeCommon/issues{/number}","pulls_url":"https://api.github.com/repos/SpongePowered/SpongeCommon/pulls{/number}","milestones_url":"https://api.github.com/repos/SpongePowered/SpongeCommon/milestones{/number}","notifications_url":"https://api.github.com/repos/SpongePowered/SpongeCommon/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/SpongePowered/SpongeCommon/labels{/name}","releases_url":"https://api.github.com/repos/SpongePowered/SpongeCommon/releases{/id}","created_at":"2015-04-11T20:38:48Z","updated_at":"2015-05-17T21:50:55Z","pushed_at":"2015-05-18T17:05:04Z","git_url":"git://github.com/SpongePowered/SpongeCommon.git","ssh_url":"git@github.com:SpongePowered/SpongeCommon.git","clone_url":"https://github.com/SpongePowered/SpongeCommon.git","svn_url":"https://github.com/SpongePowered/SpongeCommon","homepage":null,"size":2418,"stargazers_count":23,"watchers_count":23,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":11,"mirror_url":null,"open_issues_count":22,"forks":11,"open_issues":22,"watchers":23,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/SpongePowered/SpongeCommon/pulls/38"},"html":{"href":"https://github.com/SpongePowered/SpongeCommon/pull/38"},"issue":{"href":"https://api.github.com/repos/SpongePowered/SpongeCommon/issues/38"},"comments":{"href":"https://api.github.com/repos/SpongePowered/SpongeCommon/issues/38/comments"},"review_comments":{"href":"https://api.github.com/repos/SpongePowered/SpongeCommon/pulls/38/comments"},"review_comment":{"href":"https://api.github.com/repos/SpongePowered/SpongeCommon/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/SpongePowered/SpongeCommon/pulls/38/commits"},"statuses":{"href":"https://api.github.com/repos/SpongePowered/SpongeCommon/statuses/0d816902ae689cfc90e7338ceeaec309636ecf60"}}}}