diff --git a/src/main/java/org/spongepowered/api/data/key/Keys.java b/src/main/java/org/spongepowered/api/data/key/Keys.java index 44e09953a01..e0a1ee7930a 100644 --- a/src/main/java/org/spongepowered/api/data/key/Keys.java +++ b/src/main/java/org/spongepowered/api/data/key/Keys.java @@ -378,6 +378,9 @@ public final class Keys { * Represents the {@link Key} for the content of a * {@link ItemTypes#WRITTEN_BOOK}. * + *

Use {@link Keys#PLAIN_BOOK_PAGES} if you wish to inspect the contents + * of a {@link ItemTypes#WRITABLE_BOOK}.

+ * * @see PagedData#pages() */ public static final Key> BOOK_PAGES = DummyObjectProvider.createExtendedFor(Key.class,"BOOK_PAGES"); @@ -1613,6 +1616,17 @@ public final class Keys { */ public static final Key> PLAYER_CREATED = DummyObjectProvider.createExtendedFor(Key.class,"PLAYER_CREATED"); + /** + * Represents the {@link Key} for the content of a + * {@link ItemTypes#WRITABLE_BOOK}. + * + *

Use {@link Keys#BOOK_PAGES} if you wish to get the contents of a + * {@link ItemTypes#WRITTEN_BOOK}

+ * + * @see PlainPagedData#pages() + */ + public static final Key> PLAIN_BOOK_PAGES = DummyObjectProvider.createExtendedFor(Key.class,"PLAIN_BOOK_PAGES"); + /** * Represents the {@link Key} for representing the {@link PortionType} * of a {@link BlockState}. diff --git a/src/main/java/org/spongepowered/api/data/manipulator/immutable/item/ImmutablePlainPagedData.java b/src/main/java/org/spongepowered/api/data/manipulator/immutable/item/ImmutablePlainPagedData.java new file mode 100644 index 00000000000..6c6f85ee287 --- /dev/null +++ b/src/main/java/org/spongepowered/api/data/manipulator/immutable/item/ImmutablePlainPagedData.java @@ -0,0 +1,54 @@ +/* + * This file is part of SpongeAPI, licensed under the MIT License (MIT). + * + * Copyright (c) SpongePowered + * Copyright (c) contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package org.spongepowered.api.data.manipulator.immutable.item; + +import org.spongepowered.api.data.manipulator.ImmutableDataManipulator; +import org.spongepowered.api.data.manipulator.immutable.ImmutableListData; +import org.spongepowered.api.data.manipulator.mutable.item.PagedData; +import org.spongepowered.api.data.manipulator.mutable.item.PlainPagedData; +import org.spongepowered.api.data.value.immutable.ImmutableListValue; +import org.spongepowered.api.item.ItemTypes; +import org.spongepowered.api.item.inventory.ItemStack; +import org.spongepowered.api.text.Text; + +import java.util.List; + +/** + * An {@link ImmutableDataManipulator} handling the {@link List} of pages of + * {@link Text} for an {@link ItemStack} of type {@link ItemTypes#WRITABLE_BOOK} + * such that the text elements are single pages. + */ +public interface ImmutablePlainPagedData extends ImmutableListData { + + /** + * Gets the {@link ImmutableListValue} for the {@link Text} pages. + * + * @return The immutable list value of text pages + */ + default ImmutableListValue pages() { + return getListValue(); + } + +} diff --git a/src/main/java/org/spongepowered/api/data/manipulator/mutable/item/PagedData.java b/src/main/java/org/spongepowered/api/data/manipulator/mutable/item/PagedData.java index e4cd2aecfc1..dd136ba114d 100644 --- a/src/main/java/org/spongepowered/api/data/manipulator/mutable/item/PagedData.java +++ b/src/main/java/org/spongepowered/api/data/manipulator/mutable/item/PagedData.java @@ -37,7 +37,7 @@ /** * An {@link DataManipulator} handling the {@link List} of pages of - * {@link Text} for an {@link ItemStack} of type {@link ItemTypes#WRITABLE_BOOK} + * {@link Text} for an {@link ItemStack} of type {@link ItemTypes#WRITTEN_BOOK} * such that the text elements are single pages. */ public interface PagedData extends ListData { diff --git a/src/main/java/org/spongepowered/api/data/manipulator/mutable/item/PlainPagedData.java b/src/main/java/org/spongepowered/api/data/manipulator/mutable/item/PlainPagedData.java new file mode 100644 index 00000000000..41b4755aa3b --- /dev/null +++ b/src/main/java/org/spongepowered/api/data/manipulator/mutable/item/PlainPagedData.java @@ -0,0 +1,56 @@ +/* + * This file is part of SpongeAPI, licensed under the MIT License (MIT). + * + * Copyright (c) SpongePowered + * Copyright (c) contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package org.spongepowered.api.data.manipulator.mutable.item; + +import org.spongepowered.api.data.key.Keys; +import org.spongepowered.api.data.manipulator.DataManipulator; +import org.spongepowered.api.data.manipulator.immutable.item.ImmutablePagedData; +import org.spongepowered.api.data.manipulator.immutable.item.ImmutablePlainPagedData; +import org.spongepowered.api.data.manipulator.mutable.ListData; +import org.spongepowered.api.data.value.mutable.ListValue; +import org.spongepowered.api.item.ItemTypes; +import org.spongepowered.api.item.inventory.ItemStack; +import org.spongepowered.api.text.Text; + +import java.util.List; + +/** + * An {@link DataManipulator} handling the {@link List} of pages of + * {@link Text} for an {@link ItemStack} of type {@link ItemTypes#WRITABLE_BOOK} + * such that the text elements are single pages. + */ +public interface PlainPagedData extends ListData { + + /** + * Gets the {@link ListValue} for the {@link Text} pages. + * + * @return The list value of text pages + * @see Keys#PLAIN_BOOK_PAGES + */ + default ListValue pages() { + return getListValue(); + } + +} diff --git a/src/main/java/org/spongepowered/api/util/TypeTokens.java b/src/main/java/org/spongepowered/api/util/TypeTokens.java index 185324fbdc5..089a897b506 100644 --- a/src/main/java/org/spongepowered/api/util/TypeTokens.java +++ b/src/main/java/org/spongepowered/api/util/TypeTokens.java @@ -272,6 +272,8 @@ public final class TypeTokens { public static final TypeToken> LIST_POTION_VALUE_TOKEN = new TypeToken>() {private static final long serialVersionUID = -1;}; + public static final TypeToken> LIST_STRING_VALUE_TOKEN = new TypeToken>() {private static final long serialVersionUID = -1;}; + public static final TypeToken> LIST_TEXT_TOKEN = new TypeToken>() {private static final long serialVersionUID = -1;}; public static final TypeToken> LIST_TEXT_VALUE_TOKEN = new TypeToken>() {private static final long serialVersionUID = -1;};