Skip to content
Draft
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
5972a00
Initial work on heads (cherrypick + new!)
aakatz3 Dec 17, 2020
b8a5bf6
Beta of the mojang api stuff
aakatz3 Dec 20, 2020
8dae48a
Bump classgraph from 4.8.92 to 4.8.98
dependabot-preview[bot] Dec 24, 2020
7d74d10
Merge branch 'master' into feat/heads-mojangapi-users
aakatz3 Dec 25, 2020
3db73ff
Merge remote-tracking branch 'origin/master' into feat/heads-mojangap…
aakatz3 Dec 25, 2020
004fbf0
Fixed the stupidity of textures as enums and wrote some fun stuff
aakatz3 Dec 26, 2020
b014f6b
force gradle to uff-8
aakatz3 Dec 26, 2020
329515f
Test the enums so coverage isnt mad
aakatz3 Dec 26, 2020
ab69d97
more api work before changing pc
aakatz3 Dec 28, 2020
67a9c4b
More tests, use MHF, Start skullbuilder refactor
aakatz3 Dec 29, 2020
680655b
Allow generating frames for javadoc
aakatz3 Dec 30, 2020
8c113ec
Test updates (mocked bukkit); javadoc frames
aakatz3 Dec 30, 2020
ac010e4
typo
aakatz3 Dec 30, 2020
0b15f04
More test work
aakatz3 Dec 30, 2020
b6f0496
Add javadoc to ci
aakatz3 Dec 30, 2020
6d4bcec
javadoc
aakatz3 Dec 31, 2020
c4a023e
update licence, start on zach comments
aakatz3 Jan 2, 2021
0fb226b
Minor refactor, javadoc
aakatz3 Jan 4, 2021
c44992f
Refactor Texture validation to it's own class
aakatz3 Jan 4, 2021
b278a81
Bump mockito-core from 3.6.28 to 3.7.0
dependabot-preview[bot] Jan 5, 2021
8c6b7b5
Little more work before back to phone for a while?
aakatz3 Jan 5, 2021
786590d
try to fix docs
aakatz3 Jan 6, 2021
cacaefb
Finish javadoc
aakatz3 Jan 9, 2021
ade9f94
Merge branch 'master' into dependabot/gradle/io.github.classgraph-cla…
aakatz3 Jan 9, 2021
223a6f9
Merge remote-tracking branch 'origin/dependabot/gradle/org.mockito-mo…
aakatz3 Jan 9, 2021
84c0b3b
Merge remote-tracking branch 'origin/dependabot/gradle/io.github.clas…
aakatz3 Jan 9, 2021
6b4316f
Add mocked bukkit stuff, remove extra old enums
aakatz3 Jan 9, 2021
42b1739
PlayerSelector & better math util
kokumaji Jan 11, 2021
d16c439
Merge remote-tracking branch 'origin/yeen-cherrypick' into feat/heads…
aakatz3 Jan 11, 2021
3aaa25b
Add lots of javadoc
aakatz3 Jan 11, 2021
6fc4385
Infer Nullity
aakatz3 Jan 11, 2021
263164b
Prepare for new tests, add docs
aakatz3 Jan 16, 2021
26c8415
Bug fixups
aakatz3 Jan 22, 2021
614816b
javadoc 1
aakatz3 Jan 29, 2021
e6a97e1
Merge master
aakatz3 Jan 31, 2021
94683c6
Fix licence after merge
aakatz3 Feb 2, 2021
aa23150
Change how textures are implemented to a json we generate
aakatz3 Feb 8, 2021
7f2cab7
Cleanup
aakatz3 Feb 8, 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
22 changes: 22 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,25 @@ jobs:
run: chmod +x gradlew
- name: Run the license formatter checker
run: ./gradlew licenseMain licenseTest
docs-test:
runs-on: ubuntu-latest
container:
image: jcxldn/openjdk-alpine:11-jdk
steps:
- uses: actions/checkout@v2
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Generate javadocs
run: ./gradlew javadoc
- name: Save docs artifact
uses: actions/upload-artifact@v2
with:
name: javadocs
path: build/docs/*
- name: Save failed javadocs options
if: ${{ failure() }}
uses: actions/upload-artifact@v2
with:
name: javadocs-opts
path: build/tmp/javadoc/javadoc.options

2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ This project is open for all developers for contribution, so it's important we e

- No pushing to master without opening a pull request (The only exceptions are small hotfixes, any new features or such MUST go in a new branch)
- Must be backwards compatible down to Java 11
- Javadoc your code according to google's [Javadoc guidlines](https://google.github.io/styleguide/javaguide.html#s7-javadoc)
- Javadoc your code according to Google's [Javadoc guidlines](https://google.github.io/styleguide/javaguide.html#s7-javadoc)

## Pull Requests

Expand Down
42 changes: 34 additions & 8 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ plugins {
id "com.github.hierynomus.license" version "0.15.0"
}



jacoco {
// Use JaCoCo 0.8.6 for (experimental) support for Java 15 class files.
toolVersion = "0.8.6"
Expand All @@ -25,6 +27,10 @@ license {
tasks.withType(JavaCompile) {
options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation" << "-XDignore.symbol.file"
}

javadoc{
options.addBooleanOption("-frames", true)
}
// Run the license formatter before compiling the source code.
tasks.compileJava.dependsOn licenseFormatMain, licenseFormatTest

Expand All @@ -48,30 +54,37 @@ dependencies {

compileOnly 'com.destroystokyo.paper:paper-api:1.16.4-R0.1-SNAPSHOT'
compileOnly 'net.md-5:bungeecord-api:1.16-R0.4-SNAPSHOT'

implementation 'org.jetbrains:annotations:20.1.0'
implementation 'com.google.code.gson:gson:2.8.6'
implementation 'io.github.classgraph:classgraph:4.8.92'
implementation 'com.github.seancfoley:ipaddress:5.3.3'
implementation 'com.squareup.okhttp3:okhttp:4.9.0'
implementation 'commons-validator:commons-validator:1.7'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use Guava's preconditions rather than shading in deps to StickyAPI.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please explain

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See the JavaDocs for preconditions. This is included in both bukkit and bungee so will work at runtime. No need to shade in extra dependencies.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless you're intending to use this for a completely different reason.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Validator is used primarily to check url formatting for validity, and determine if a URL is validly formatted (and I think it also checks if it's resolvable). There are a couple other ways I plan to use it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can also theoretically call the minimize() function to reduce jar size

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Validator is used primarily to check url formatting for validity, and determine if a URL is validly formatted (and I think it also checks if it's resolvable). There are a couple other ways I plan to use it.

Google preconditions does thissssss - just include a URL regex.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can also theoretically call the minimize() function to reduce jar size

This has side effects, we've already tried it.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we even need to validate the URL ourselves? OkHttp should throw an exception when unable to parse a URL, and if we don't want to use OkHttp, a regular expression will do for URL validity

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could also probably test URL validity by attempting to construct a URL object using the string and seeing if a MalformedURLException is thrown


// JUnit 5 Testing
testImplementation("org.junit.jupiter:junit-jupiter-api:5.7.0")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.7.0")
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.0'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.0'

// Mocking
testImplementation("org.powermock:powermock-module-junit4:2.0.9")
testImplementation("org.powermock:powermock-api-mockito2:2.0.9")
testImplementation("org.powermock:powermock-module-junit4-rule:2.0.9")
testImplementation("org.powermock:powermock-classloading-xstream:2.0.9")
testImplementation("org.mockito:mockito-core:3.6.28")
testImplementation 'org.powermock:powermock-module-junit4:2.0.9'
testImplementation 'org.powermock:powermock-api-mockito2:2.0.9'
testImplementation 'org.powermock:powermock-module-junit4-rule:2.0.9'
testImplementation 'org.powermock:powermock-classloading-xstream:2.0.9'
testImplementation 'org.mockito:mockito-core:3.6.28'
testImplementation 'com.github.seeseemelk:MockBukkit-v1.16:0.5.0'
testImplementation 'it.unimi.dsi:fastutil:8.4.4'
}


test {
useJUnitPlatform()
testLogging {
events "passed", "skipped", "failed"
// Show System.out for code ran by tests
showStandardStreams = true
}
//ignoreFailures = true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this line if it's commented.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its there for testing. I will try to fold into a new task

finalizedBy jacocoTestReport // report is always generated after tests run
}

Expand All @@ -88,9 +101,22 @@ task sources(type: Jar, dependsOn: classes) {
from sourceSets.main.allSource
}

tasks.delombok.shouldRunAfter(sources)


tasks.publish.dependsOn build, sources
tasks.publish.dependsOn build

tasks.javadoc.dependsOn delombok
javadoc {
options.addBooleanOption('XDignore.symbol.file', true)
options.addBooleanOption('-frames', true)
}
tasks.build.finalizedBy(sources)

task rebuild {}
tasks.rebuild.dependsOn build, clean
tasks.build.shouldRunAfter(clean)
tasks.javadoc.shouldRunAfter(clean)



Expand Down
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
systemProp.file.encoding=utf-8
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
systemProp.file.encoding=utf-8
systemProp.file.encoding=utf-8

3 changes: 1 addition & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
compileJava.options.encoding=UTF-8
12 changes: 12 additions & 0 deletions src/main/java/com/dumbdogdiner/stickyapi/StickyAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/
package com.dumbdogdiner.stickyapi;

import java.io.InputStream;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.logging.Logger;
Expand All @@ -25,4 +26,15 @@ public class StickyAPI {
@Getter
@Setter
private static ExecutorService pool = Executors.newCachedThreadPool();

/**
* Provides a wrapper for {@link java.lang.Class#getResourceAsStream(String)} (String)}
* @param resourceName The resource to get
* @return an {@link InputStream} to that resource
*/
public static InputStream getResourceAsStream(String resourceName){
return StickyAPI.class.getResourceAsStream(resourceName);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? Also, where are the annotations?


private StickyAPI() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
*
* @deprecated Use
* {@link com.dumbdogdiner.stickyapi.bukkit.command.BukkitCommandBuilder}
* as this will be removed in the next release
* as this will be removed in a future release
*/
@Deprecated
public abstract class AsyncCommand extends Command implements PluginIdentifiableCommand {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
* Enum based exit codes for StickyAPI command classes.
*
* @deprecated use {@link com.dumbdogdiner.stickyapi.common.command.ExitCode} as
* this will be removed in the next release
* @see {@link com.dumbdogdiner.stickyapi.common.command.ExitCode}
* this will be removed in a future release
* @see com.dumbdogdiner.stickyapi.common.command.ExitCode
*/
@Deprecated
public enum ExitCode {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@
/**
* A class for generating empty void worlds
*/
@SuppressWarnings("unused")
public class VoidGenerator extends ChunkGenerator {

@Override
public ChunkData generateChunkData(@NotNull World world, Random random, int x, int z, BiomeGrid biome) {
public @NotNull ChunkData generateChunkData(@NotNull World world, @NotNull Random random, int x, int z, @NotNull BiomeGrid biome) {
return createChunkData(world);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/*
* Copyright (c) 2020 DumbDogDiner <dumbdogdiner.com>. All rights reserved.
* Licensed under the MIT license, see LICENSE for more information...
*/
package com.dumbdogdiner.stickyapi.bukkit.item.generator;

import com.destroystokyo.paper.profile.PlayerProfile;
import com.destroystokyo.paper.profile.ProfileProperty;
import com.dumbdogdiner.stickyapi.bukkit.user.StickyUserBukkit;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.SkullMeta;
import com.google.gson.Gson;

import java.net.URL;
import java.util.Base64;
import java.util.UUID;

public class PlayerHeadGenerator {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PlayerHeadBuilder?

private SkullMeta meta = (SkullMeta) (new ItemStack(Material.PLAYER_HEAD, 1)).getItemMeta();

PlayerProfile ownerProfile;

public PlayerHeadGenerator(UUID playerId){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public PlayerHeadGenerator(UUID playerId){
public PlayerHeadGenerator(@NotNull UUID playerId) {

Use annotations please, this is for Kotlin support.

meta.setOwningPlayer(Bukkit.getOfflinePlayer(playerId));
ownerProfile = Bukkit.getServer().createProfile(playerId);
}

public PlayerHeadGenerator(Player player){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public PlayerHeadGenerator(Player player){
public PlayerHeadGenerator(@NotNull Player player) {

this(Bukkit.getOfflinePlayer(player.getUniqueId()));
}

public PlayerHeadGenerator(StickyUserBukkit player){
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There must be a better way to do this aside from implementing an API-specific user.

meta.setOwningPlayer(player.getAsBukkitPlayer());
ownerProfile = player.getAsBukkitPlayer().getPlayerProfile();
}

public PlayerHeadGenerator(OfflinePlayer player){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public PlayerHeadGenerator(OfflinePlayer player){
public PlayerHeadGenerator(@NotNull OfflinePlayer player) {

meta.setOwningPlayer(player);
ownerProfile = Bukkit.createProfile(player.getUniqueId());
}

public PlayerHeadGenerator(ItemStack head){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public PlayerHeadGenerator(ItemStack head){
public PlayerHeadGenerator(@NotNull ItemStack head) {

if(head.getType() != Material.PLAYER_HEAD && head.getType() != Material.PLAYER_WALL_HEAD)
throw new IllegalArgumentException("head must be a player head or player wall head");
meta = (SkullMeta) head.getItemMeta();
meta.getPlayerProfile();
if(!ownerProfile.hasTextures()){
if(!ownerProfile.complete()){
throw new IllegalArgumentException("Invalid player profile attached to the head, with no UUID or textures!");
}
}
}


public void setTexture(URL textureURL){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public void setTexture(URL textureURL){
public void setTexture(@NotNull URL textureURL) {

// {"textures":{"SKIN":{"url":"http://textures.minecraft.net/texture/63d621100fea5883922e78bb448056448c983e3f97841948a2da747d6b08b8ab"}}}
class textures {
SKIN skn;
public textures(String url){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public textures(String url){
public textures(@NotNull String url) {

skn = new SKIN(url);
}
class SKIN{
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
class SKIN{
class SKIN {

String url;
public SKIN(String s){
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public SKIN(String s){
public SKIN(String s) {

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public SKIN(String s){
public SKIN(@NotNull String s) {

url = s;
}
}
}

setTexture(new String(Base64.getEncoder().encode(new Gson().toJson(new textures(textureURL.toString())).getBytes())));
}

/**
* Set the texture with a pre-encoded string
* @param texture Base64 string of the json of texture location
*/
public void setTexture(String texture){
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public void setTexture(String texture){
public void setTexture(String texture) {

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public void setTexture(String texture){
public void setTexture(@NotNull String texture) {

ownerProfile.setProperty(new ProfileProperty("texture", texture));
meta.setPlayerProfile(ownerProfile);
}

public ItemStack getHead(){
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public ItemStack getHead(){
public ItemStack getHead() {

return getHead(1);
}

public ItemStack getHead(int amount){
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public ItemStack getHead(int amount){
public ItemStack getHead(int amount) {

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public ItemStack getHead(int amount){
public ItemStack getHead(@NotNull int amount) {

ItemStack head = new ItemStack(Material.PLAYER_HEAD, amount);
head.setItemMeta(meta);
return null;
}

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

import com.destroystokyo.paper.profile.PlayerProfile;
import com.destroystokyo.paper.profile.ProfileProperty;
import com.dumbdogdiner.stickyapi.common.util.textures.TextureHelper;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.SkullMeta;

import java.util.UUID;


public class SkullBuilder {
@Getter
private String filter = "*";
@Getter
private int quantity = 1;
@Getter
private String head;
@Accessors(fluent = true, chain = true)
@Setter @Getter
private String name;


public SkullBuilder() {

}

public SkullBuilder filter(String group) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public SkullBuilder filter(String group) {
public SkullBuilder filter(@NotNull String group) {

if (TextureHelper.getCategories().contains(group.toUpperCase())) {
filter = group.toUpperCase();
}
return this;
}

public SkullBuilder head(String head) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public SkullBuilder head(String head) {
public SkullBuilder head(@NotNull String head) {

head = head.toUpperCase();
if (TextureHelper.getTexture(filter, head) != null) {
this.head = head;
}
return this;
}

public SkullBuilder quantity(int i) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public SkullBuilder quantity(int i) {
public SkullBuilder quantity(@NotNull int i) {

if (i >= 0 && i <= 64) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Throw error if stack is over 64 or under 0?

this.quantity = i;
}
return this;
}

public ItemStack build() {
SkullMeta meta = (SkullMeta) (new ItemStack(Material.PLAYER_HEAD, 1)).getItemMeta();
PlayerProfile profile = Bukkit.createProfile(new UUID(0, 0), null);

profile.setName(TextureHelper.asQualifiedName(filter, head));
if(name != null){
meta.setDisplayName(name);
} else {
meta.setDisplayName(StringUtils.capitalize(head));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid using Apache's StringUtils as we have our own, just for consistency.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought that was ours, oops. I'll use that, and if it doesnt have what I need I'll use inheritance

}

profile.setProperty(new ProfileProperty("texture", TextureHelper.getTexture(filter, head)));
ItemStack head = new ItemStack(Material.PLAYER_HEAD, quantity);
head.setItemMeta(meta);
return head;
}
}
Loading