Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
89 commits
Select commit Hold shift + click to select a range
475a8c2
branch
aakatz3 Dec 6, 2020
5fc3c16
Markdown color parsing
aakatz3 Dec 6, 2020
9d9ea1f
Start Json Renderer
aakatz3 Nov 28, 2020
2b822c6
Add some notes and fix a lot of little bits
aakatz3 Dec 6, 2020
8b3453d
Update gradle
aakatz3 Dec 6, 2020
aa2dbe1
fixup ci
aakatz3 Dec 6, 2020
ba3100d
Implement NodeRenderer, various improvements to MarkdownJsonRenderer
spazzylemons Dec 6, 2020
c81e69c
unbrick javadoc
aakatz3 Dec 6, 2020
8fdc82b
re-add lombok
aakatz3 Dec 6, 2020
14860de
Merge branch 'fixup/ci' into fixup/book-text-utils
aakatz3 Dec 6, 2020
a34ba4c
fix escape in javadoc
aakatz3 Dec 6, 2020
d2ced94
Allow converting json to pages (doesnt check json validity!)
aakatz3 Dec 6, 2020
0b7b3ce
clean imports, clean some code
aakatz3 Dec 6, 2020
a822e67
More BookUtils, create JsonComponent, more fixes to renderer
spazzylemons Dec 6, 2020
8c79712
make RuleBook generate rulebooks
spazzylemons Dec 7, 2020
92c8104
Fix a NoSuchMethodError in BookGenerator
spazzylemons Dec 7, 2020
de2a517
Choose NBTTagString method based on server type
spazzylemons Dec 7, 2020
8753fe5
Expand JsonComponent, change section splitting method to use breaks
spazzylemons Dec 7, 2020
c4b4f55
Add comment
aakatz3 Dec 8, 2020
894944e
Remove NMS and CraftBukkit
spazzylemons Dec 9, 2020
6edb87a
Add Javadocs to book stuff
spazzylemons Dec 9, 2020
59d85cd
Remove RuleBook
spazzylemons Dec 10, 2020
39fae2c
Merge branch 'master' into fixup/book-text-utils
jcxldn Jan 17, 2021
6fcf822
Revert changes that are no longer needed
jcxldn Jan 17, 2021
4b3ab4a
Re-add CommonMark to dependencies
jcxldn Jan 17, 2021
cffd7d7
Run license formatter
jcxldn Jan 17, 2021
eae7442
Remove unused imports
jcxldn Jan 17, 2021
61ef0c0
Merge branch 'master' into fixup/book-text-utils
Jan 21, 2021
01b3b86
Merge remote-tracking branch 'origin/master' into fixup/book-text-utils
aakatz3 Jan 23, 2021
8ca95ea
Ignore vscode workspaces
aakatz3 Jan 23, 2021
cd306cd
Fix a bunch of broken-ness and start tests
aakatz3 Jan 23, 2021
c5a3fa8
Change to switch case
aakatz3 Jan 24, 2021
52d1670
Added some characters manually
aakatz3 Jan 24, 2021
ce6f63b
Use HashMap for characters, remove obsolete TextUtil class
spazzylemons Jan 24, 2021
01ae290
Add mojangles font width data as buildtime dep
jcxldn Jan 24, 2021
3e4e10d
Update BookUtils to use JSON resource, change pixel measurements
spazzylemons Jan 24, 2021
c364e4c
Fix book item generation nbt (hopefully)
aakatz3 Jan 25, 2021
e7fc447
Add some notes and fixes
aakatz3 Jan 27, 2021
572e74e
fix const
aakatz3 Jan 27, 2021
d4c5c80
Finish books, requires in-game testing
aakatz3 Jan 29, 2021
2123e7d
Requested edits
aakatz3 Jan 31, 2021
39f446d
Bump version
aakatz3 Jan 31, 2021
2a4685d
Finish JSON format, update build.gradle, remove commonmark from branch
aakatz3 Feb 1, 2021
ba707be
Spruced up javadoc, annotated utility classes
aakatz3 Feb 1, 2021
091d070
Merge branch 'master' into fixup/book-text-utils
aakatz3 Feb 1, 2021
86226d8
requested fixes
aakatz3 Feb 1, 2021
a6d3a9b
Fix build by removing private constructors where utilityclass is used
jcxldn Feb 1, 2021
0260b3b
Add BookUtil#isCharacterSupported and some tests
jcxldn Feb 1, 2021
10729b0
Add a couple other tests
aakatz3 Feb 2, 2021
439faac
Fixes
aakatz3 Feb 6, 2021
328ac6c
Add tests
aakatz3 Feb 6, 2021
812abb0
minor fixup
aakatz3 Feb 6, 2021
701dd0c
Javadoc fix
aakatz3 Feb 6, 2021
36bcfc0
Merge remote-tracking branch 'origin/master' into fixup/book-text-utils
aakatz3 Feb 11, 2021
ad30a23
Add cool new nbt thingies
aakatz3 Feb 13, 2021
6e68cc1
Additional constructor for NbtCompoundTag
aakatz3 Feb 13, 2021
c722a73
Allow creating NbtListTag with predefined array
aakatz3 Feb 13, 2021
587bba9
Add convenience methods to NbtCompoundTag
aakatz3 Feb 13, 2021
d7b30f9
Merge branch 'feat/string-nbt-helpers' into fixup/book-text-utils
aakatz3 Feb 13, 2021
3b212af
Cleanups
aakatz3 Feb 13, 2021
8e256ac
Finish cleaned version of book stuff
aakatz3 Feb 13, 2021
c08b56d
Add note to comment in copyMCFontExtractor
jcxldn Feb 13, 2021
8600bfc
Move minify TODO to github issue for tracking
jcxldn Feb 13, 2021
3091b88
Merge branch 'master' into fixup/book-text-utils
jcxldn Feb 14, 2021
c0cc8b9
Recreate StringUtil from master
jcxldn Feb 14, 2021
cc9f7d9
replace toSNbt with toNbtString
jcxldn Feb 14, 2021
3ffa5b4
Adjust comments
jcxldn Feb 14, 2021
edb522a
Add browseTests task
jcxldn Feb 14, 2021
16758cd
Don't bump version
jcxldn Feb 14, 2021
699c054
(1st pass) going back to private constructors for now
jcxldn Feb 14, 2021
2b53a39
Try to split annotation changes
jcxldn Feb 14, 2021
afc755a
Split VoidGenerator changes into own pr
jcxldn Feb 14, 2021
1079181
Improved instance naming
jcxldn Feb 14, 2021
e38ba7c
Misc javadoc step changes
jcxldn Feb 14, 2021
29fa23f
Revert StickyAPI.java to master for split
jcxldn Feb 14, 2021
8256966
Split gradle / javadoc changes for after PR merge
jcxldn Feb 14, 2021
c94e280
Add newline to voidgen
jcxldn Feb 14, 2021
7f4f723
Remove unused Gson imports and var
jcxldn Feb 14, 2021
5a0cccf
Remove another unused Gson
jcxldn Feb 14, 2021
86c083e
Merge branch 'master' of https://github.com/DumbDogDiner/StickyAPI in…
jcxldn Feb 14, 2021
503dab5
replace new since annotations with TBA
jcxldn Feb 14, 2021
d7b7dab
Remove empty test class
jcxldn Feb 14, 2021
85d1e5b
Use same javadoc as base StickyAPI.java
jcxldn Feb 14, 2021
d98e139
remove unused imports from mathutil
jcxldn Feb 14, 2021
0f19d7e
Remove unused import from textutil
jcxldn Feb 14, 2021
a1a3d68
(MathUtil/TextUtil): Use constructor instead of utilityclass annotati…
jcxldn Feb 14, 2021
ca18e75
Merge remote-tracking branch 'origin' into fixup/book-text-utils
jcxldn Feb 14, 2021
aa21aa1
(TextUtil): Remove unused var
jcxldn Feb 14, 2021
4003bae
Add basic comments to TextUtil fallback loading
jcxldn Feb 14, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,8 @@ bin
.settings
.classpath
.project
.idea
.idea
*.code-workspace

# Generated resources
src/main/resources/generated/*
36 changes: 31 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,12 @@ license {
header = project.file('LICENSE_HEADER')
ext.year = Calendar.getInstance().get(Calendar.YEAR)
mapping("java", "SLASHSTAR_STYLE")
exclude "**/*.json" // Exclude JSON to keep the font width data valid
}

tasks.withType(JavaCompile) {
options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation" << "-XDignore.symbol.file"
}
// Run the license formatter before compiling the source code.
tasks.compileJava.dependsOn licenseFormatMain, licenseFormatTest

configurations {
jaxDoclet
Expand All @@ -42,9 +41,24 @@ repositories {

maven { url 'https://oss.sonatype.org/content/repositories/snapshots' }
maven { url 'https://papermc.io/repo/repository/maven-public/' }

// Define a Ivy repo for the font width data (that way we don't need another plugin!)
def ddd_mc_font = ivy {
url 'https://dumbdogdiner.github.io/'
patternLayout { artifact '/[module]/[revision]/[classifier].[ext]'}
metadataSources { artifact() }
}
// Only use the Ivy repo for font width data - speeds up dependency resolution
exclusiveContent {
forRepositories(ddd_mc_font)
filter { includeGroup("dumbdogdiner") }
}
}

dependencies {
// Font width data (see above)
compile 'dumbdogdiner:mc-font-extractor:main:mojangles_width_data@json'

compileOnly 'org.projectlombok:lombok:1.18.16'
annotationProcessor 'org.projectlombok:lombok:1.18.16'

Expand Down Expand Up @@ -92,7 +106,6 @@ task sources(type: Jar, dependsOn: classes) {
// Some environments (such as the builder image) do not use UTF-8 as the default encoding!
// This sets UTF-8 as the encoding for the following tasks: delombok, compileJava, compileTestJava and javadoc.
delombok.encoding = "UTF-8"

compileJava.options.encoding = "UTF-8"
compileTestJava.options.encoding = "UTF-8"
javadoc.options.encoding = "UTF-8"
Expand Down Expand Up @@ -129,10 +142,23 @@ task processSourceTokens(type: Sync) {
// Use the filter task as the input for compileJava
compileJava.source = processSourceTokens.outputs


tasks.publish.dependsOn build, sources
// Font Width Info
task copyMCFontExtractor(type: Copy) {
def path = project.configurations.compile.find {it.name.startsWith("mc-font-extractor") }
println path
from file(path)
// into file("src/main/resources")
// - Please keep this comment for future reference.
// - This is how we would do this if we weren't also adding build info (see processSourceTokens)
destinationDir file("src/main/resources/generated/")
rename 'mc-font-extractor-main-mojangles_width_data.json', 'mojangles_width_data.json'
}


// Run the license formatter and font data copier before compiling the source code.
tasks.compileJava.dependsOn licenseFormatMain, licenseFormatTest, copyMCFontExtractor
tasks.build.dependsOn sources
tasks.publish.dependsOn build


publishing {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
/*
* Copyright (c) 2020-2021 DumbDogDiner <dumbdogdiner.com>. All rights reserved.
* Licensed under the MIT license, see LICENSE for more information...
*/
package com.dumbdogdiner.stickyapi.bukkit.item;

import com.dumbdogdiner.stickyapi.common.nbt.NbtCompoundTag;
import com.dumbdogdiner.stickyapi.common.nbt.NbtJsonTag;
import com.dumbdogdiner.stickyapi.common.nbt.NbtListTag;
import com.dumbdogdiner.stickyapi.common.nbt.NbtStringTag;
import com.dumbdogdiner.stickyapi.common.util.TextUtil;
import com.dumbdogdiner.stickyapi.common.util.StringUtil;
import com.google.common.base.Preconditions;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.Accessors;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.VisibleForTesting;

import java.awt.print.Book;
import java.util.Collections;
import java.util.StringJoiner;

/**
* This class allows for easy construction of a writable book, which is unfortunately much
* simpler than a written/signed book, either manually in code, or by loading a JSON object
*
* @since TBA
*/

@SuppressWarnings({"UnusedReturnValue", "unused"})
@Accessors(chain = true)
@NoArgsConstructor
public class BookAndQuillBuilder {
private @NotNull JsonArray pages = new JsonArray();

@Setter
@Getter
private @Nullable String displayName;

private JsonArray lore = new JsonArray();

/**
* Creates a new BookGenerator from a given JsonObject, representing a book, which can
* be obtained in whatever way you want.
*
* @param bookObject A JSON object containing a JsonArray of valid Pages; If a {@link Material#WRITTEN_BOOK} is desired, it must contain a title, author, and optionally, a Generation (an integer with the value of 0, 1, 2, or 3, with 0 being the default)
* @return a {@link BookAndQuillBuilder} with the specified pages; if a title and author are both specified, it will be a {@link Material#WRITTEN_BOOK}, otherwise it will be a {@link Material#WRITABLE_BOOK}
*/
public static @NotNull BookAndQuillBuilder fromJson(@NotNull JsonObject bookObject) {
BookAndQuillBuilder bookBuilder = new BookAndQuillBuilder();
JsonArray pages = bookObject.get("pages").getAsJsonArray();
Preconditions.checkNotNull(pages);
bookBuilder.pages = pages;
if(bookObject.has("lore") && bookObject.get("lore").isJsonArray()){
bookBuilder.lore = bookObject.get("lore").getAsJsonArray();
}
return bookBuilder;
}

/**
* Add some pages to the book. May fail with {@link IllegalStateException} if the book is full or fills up.
*
* @param pages Pages to add
* @return This object, for chaining
*/
public @NotNull BookAndQuillBuilder addPages(String @NotNull ... pages) {
for (String page : pages) {
addPage(page);
}
return this;
}

/**
* Add a page to the book. May fail with {@link IllegalStateException} if the book is full.
*
* @param page The page to add
* @return This object, for chaining
*/
public @NotNull BookAndQuillBuilder addPage(@NotNull String page) {
Preconditions.checkState(!isFull(), "Cannot add page, the book is overfilled!");
pages.add(page);
return this;
}

/**
* Build a book and quill from this generator.
*
* @return an {@link ItemStack} of the book, with pages and all other data
*/
@SuppressWarnings("deprecation")
public @NotNull ItemStack toItemStack() {
Preconditions.checkState(pages.size() > 0, "Cannot generate book with no pages");
Preconditions.checkState(pages.size() < TextUtil.PAGES_PER_BOOK, "Cannot generate book with an invalid number of pages (must be less than " + TextUtil.PAGES_PER_BOOK + ")");
ItemStack stack = new ItemStack(Material.WRITABLE_BOOK, 1);

stack = Bukkit.getUnsafe().modifyItemStack(stack, generateNBT());

return stack;
}

/**
* @return The percentage of pages allowed that are used by this book.
* TODO: Does not account for characters per page or packet size at this time.
*/
public float percentFull() {
return (float) pages.size() / (float) TextUtil.PAGES_PER_BOOK;
}

/**
* TODO: Does not account for characters per page or packet size at this time.
*
* @return True if the book is full.
*/
public boolean isFull() {
return percentFull() >= 1.0f;
}

/**
* Adds a line of lore (formatted JSON text stuffs) to the book
*/
public @NotNull BookAndQuillBuilder addLoreLine(JsonObject lore){
this.lore.add(lore);
return this;
}

public @NotNull BookAndQuillBuilder addLoreLines(JsonObject ... lores){
for(JsonObject lore : lores){
addLoreLine(lore);
}
return this;
}

/**
* Uses a {@link StringJoiner} to convert pages JsonArray to the weird NBT list
*
* @return {@link String} with NBT of the pages
*/
@VisibleForTesting
public @NotNull String generateNBT() {
NbtCompoundTag bookNBT = new NbtCompoundTag();
bookNBT.put("pages", NbtListTag.fromJsonArray(this.pages));
NbtCompoundTag display = new NbtCompoundTag();
if(displayName != null)
display.put("Name", displayName);
if(lore.size() > 0){
display.put("Lore", NbtListTag.fromJsonArrayQuoted(lore));
}
if(!display.isEmpty())
bookNBT.put("display", display);
return bookNBT.toNbtString();
}
}
Loading