Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PlainPagedData #1899

Merged
merged 1 commit into from Oct 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/main/java/org/spongepowered/api/data/key/Keys.java
Expand Up @@ -378,6 +378,9 @@ public final class Keys {
* Represents the {@link Key} for the content of a
* {@link ItemTypes#WRITTEN_BOOK}.
*
* <p>Use {@link Keys#PLAIN_BOOK_PAGES} if you wish to inspect the contents
* of a {@link ItemTypes#WRITABLE_BOOK}.</p>
*
* @see PagedData#pages()
*/
public static final Key<ListValue<Text>> BOOK_PAGES = DummyObjectProvider.createExtendedFor(Key.class,"BOOK_PAGES");
Expand Down Expand Up @@ -1613,6 +1616,17 @@ public final class Keys {
*/
public static final Key<Value<Boolean>> PLAYER_CREATED = DummyObjectProvider.createExtendedFor(Key.class,"PLAYER_CREATED");

/**
* Represents the {@link Key} for the content of a
* {@link ItemTypes#WRITABLE_BOOK}.
*
* <p>Use {@link Keys#BOOK_PAGES} if you wish to get the contents of a
* {@link ItemTypes#WRITTEN_BOOK}</p>
*
* @see PlainPagedData#pages()
*/
public static final Key<ListValue<String>> PLAIN_BOOK_PAGES = DummyObjectProvider.createExtendedFor(Key.class,"PLAIN_BOOK_PAGES");

/**
* Represents the {@link Key} for representing the {@link PortionType}
* of a {@link BlockState}.
Expand Down
@@ -0,0 +1,54 @@
/*
* This file is part of SpongeAPI, licensed under the MIT License (MIT).
*
* Copyright (c) SpongePowered <https://www.spongepowered.org>
* 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<String, ImmutablePlainPagedData, PlainPagedData> {

/**
* Gets the {@link ImmutableListValue} for the {@link Text} pages.
*
* @return The immutable list value of text pages
*/
default ImmutableListValue<String> pages() {
return getListValue();
}

}
Expand Up @@ -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<Text, PagedData, ImmutablePagedData> {
Expand Down
@@ -0,0 +1,56 @@
/*
* This file is part of SpongeAPI, licensed under the MIT License (MIT).
*
* Copyright (c) SpongePowered <https://www.spongepowered.org>
* 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<String, PlainPagedData, ImmutablePlainPagedData> {

/**
* Gets the {@link ListValue} for the {@link Text} pages.
*
* @return The list value of text pages
* @see Keys#PLAIN_BOOK_PAGES
*/
default ListValue<String> pages() {
return getListValue();
}

}
2 changes: 2 additions & 0 deletions src/main/java/org/spongepowered/api/util/TypeTokens.java
Expand Up @@ -272,6 +272,8 @@ public final class TypeTokens {

public static final TypeToken<ListValue<PotionEffect>> LIST_POTION_VALUE_TOKEN = new TypeToken<ListValue<PotionEffect>>() {private static final long serialVersionUID = -1;};

public static final TypeToken<ListValue<String>> LIST_STRING_VALUE_TOKEN = new TypeToken<ListValue<String>>() {private static final long serialVersionUID = -1;};

public static final TypeToken<List<Text>> LIST_TEXT_TOKEN = new TypeToken<List<Text>>() {private static final long serialVersionUID = -1;};

public static final TypeToken<ListValue<Text>> LIST_TEXT_VALUE_TOKEN = new TypeToken<ListValue<Text>>() {private static final long serialVersionUID = -1;};
Expand Down