Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,4 @@ jobs:
with:
name: failed-javadocs-options-file
path: build/tmp/javadoc/javadoc.options

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ hs_err_pid*
.gradle
**/build/
!src/**/build/
**/resources/generated/

# Ignore Gradle GUI config
gradle-app.setting
Expand Down
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
84 changes: 75 additions & 9 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,21 @@ jacoco {
}

group = 'com.dumbdogdiner'

version = '2.1.0'
version = '2.3.0'

// License Plugin Options
license {
header = project.file('LICENSE_HEADER')
ext.year = Calendar.getInstance().get(Calendar.YEAR)
mapping("java", "SLASHSTAR_STYLE")
exclude("**/*.json")
}

tasks.withType(JavaCompile) {
options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation" << "-XDignore.symbol.file"
options.encoding = "UTF-8"
}

// Run the license formatter before compiling the source code.
tasks.compileJava.dependsOn licenseFormatMain, licenseFormatTest

Expand All @@ -39,6 +41,7 @@ configurations {
repositories {
mavenCentral()
jcenter()
google()

maven { url 'https://oss.sonatype.org/content/repositories/snapshots' }
maven { url 'https://papermc.io/repo/repository/maven-public/' }
Expand All @@ -50,17 +53,34 @@ dependencies {

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

implementation 'org.jetbrains:annotations:20.1.0'
implementation 'com.google.code.gson:gson:2.8.6'
implementation 'io.github.classgraph:classgraph:4.8.100'
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

implementation 'com.google.guava:guava:30.1-jre'

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

// Tests - Mocking Suite (eg. mocking Bukkit for tests)
testImplementation("org.mockito:mockito-core:3.7.7")

// Tests - Mocked Bukkit Project (Has some additional features)
testImplementation 'com.github.seeseemelk:MockBukkit-v1.16:0.5.0'
testImplementation 'it.unimi.dsi:fastutil:8.4.4'
}

task downloadTextures(type: Download) {
sourceUrl = 'https://dumbdogdiner.github.io/mc-heads-resource/textures.json'
target = new File('src/main/resources/generated/textures.json')
}

task cleanGenerated(type: Delete){
delete('src/main/resources/generated')
}

test {
Expand All @@ -70,6 +90,7 @@ test {
// 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 @@ -86,15 +107,22 @@ task sources(type: Jar, dependsOn: classes) {
from sourceSets.main.allSource
}

tasks.delombok.shouldRunAfter(sources)
tasks.publish.dependsOn build
tasks.build.shouldRunAfter(clean)
tasks.javadoc.shouldRunAfter(clean)
Copy link
Member

Choose a reason for hiding this comment

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

I'm a little hesitant to have javadoc and build run after clean...

@NotZachery thoughts?

Copy link
Member

Choose a reason for hiding this comment

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

I don't see how this could become an issue so I'm fine by 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.

They are set to run after as should, not forced. This prevents (if you did, say, ./gradlew build clean javadoc it from building then deleting the build.

Copy link
Member

Choose a reason for hiding this comment

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

Ah okay - thanks!

tasks.build.finalizedBy(sources)
tasks.clean.dependsOn(cleanGenerated)
tasks.processResources.dependsOn(downloadTextures)

// Javadoc Fixes
// 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"
delombok {
finalizedBy(javadoc)
print(true)
encoding = "UTF-8"
//verbose(true)
}


// Build Info
Expand Down Expand Up @@ -127,10 +155,35 @@ task processSourceTokens(type: Sync) {
}
// Use the filter task as the input for compileJava
compileJava.source = processSourceTokens.outputs
tasks.publish.dependsOn build, sources

tasks.withType(JavaCompile) {
options.encoding = "UTF-8"
}
tasks.withType(Test) {
systemProperty "file.encoding", "UTF-8"
}

javadoc {
options.addBooleanOption('XDignore.symbol.file', true)
options.addBooleanOption('-frames', true)
options.addBooleanOption('private', true)
test.ignoreFailures true;
options.encoding = 'UTF-8'
dependsOn delombok
}

tasks.publish.dependsOn build, sources
task browseJavadoc {
dependsOn javadoc
doLast {
java.awt.Desktop.desktop.browse new URI(("file:///" << System.getProperty("user.dir").replace('\\','/') << "/build/docs/javadoc/index.html").toString())
}
}

task rebuild {
dependsOn clean
finalizedBy build
}



Expand All @@ -152,3 +205,16 @@ publishing {
}
}
}

class Download extends DefaultTask {
@Input
String sourceUrl

@OutputFile
File target

@TaskAction
void download() {
ant.get(src: sourceUrl, dest: target)
}
}
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.8.2-bin.zip
Copy link
Collaborator

Choose a reason for hiding this comment

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

For future reference: please don't change Gradle versions without asking one of us!

zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
compileJava.options.encoding=UTF-8
27 changes: 20 additions & 7 deletions src/main/java/com/dumbdogdiner/stickyapi/StickyAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@
*/
package com.dumbdogdiner.stickyapi;

import lombok.Getter;
import lombok.Setter;
import org.jetbrains.annotations.NotNull;

import java.io.InputStream;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.logging.Logger;

import lombok.Getter;
import lombok.Setter;

/**
* <h1>StickyAPI</h1> Utility methods, classes and potentially
* code-dupe-annihilating code for DDD plugins.
Expand All @@ -29,7 +31,16 @@ private StickyAPI() {

@Getter
@Setter
private static ExecutorService pool = Executors.newCachedThreadPool();
private static @NotNull 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(@NotNull String resourceName){
return StickyAPI.class.getResourceAsStream(resourceName);
}

// Build Info Start

Expand All @@ -38,8 +49,8 @@ private StickyAPI() {
*
* @since TBA
* @return {@link String} version
*
*/
@SuppressWarnings("JavaDoc")
@Getter
private static final String version = "@BUILDINFO_VERSION";

Expand All @@ -55,6 +66,7 @@ private StickyAPI() {
* @since TBA
* @return {@link String} commit id
*/
@SuppressWarnings("JavaDoc")
@Getter
private static final String commit = "@BUILDINFO_COMMIT@";

Expand All @@ -64,6 +76,7 @@ private StickyAPI() {
* @since TBA
* @return {@link String} branch name
*/
@SuppressWarnings("JavaDoc")
@Getter
private static final String branch = "@BUILDINFO_BRANCH@";

Expand All @@ -80,8 +93,7 @@ private StickyAPI() {
public static Date getTimestamp() {
SimpleDateFormat formatter = new SimpleDateFormat(dateFormat);
try {
Date date = formatter.parse(timestamp);
return date;
return formatter.parse(timestamp);
} catch (ParseException e) {
e.printStackTrace();
return null;
Expand All @@ -106,6 +118,7 @@ public static String getSha() {
* @since TBA
* @return {@link Boolean} isDirty
*/
@SuppressWarnings("ConstantConditions")
public static Boolean getIsDirty() {
return Boolean.parseBoolean(isDirty);
}
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/com/dumbdogdiner/stickyapi/annotation/DoNotCall.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* Copyright (c) 2020-2021 DumbDogDiner <dumbdogdiner.com>. All rights reserved.
* Licensed under the MIT license, see LICENSE for more information...
*/
package com.dumbdogdiner.stickyapi.annotation;

import java.lang.annotation.Documented;


/**
* Do not call a method annotated with this, it will do bad things
*/
@Documented
public @interface DoNotCall {
Copy link
Member

Choose a reason for hiding this comment

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

What is the point of this exactly? If a method shouldn't be called why does it exist.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Would prefer it if we can write things in a way where methods that are strictly internal can't be called externally.


}
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 All @@ -43,7 +43,7 @@ public abstract class AsyncCommand extends Command implements PluginIdentifiable
* @param commandName The name of the command the user will execute
* @param owner The plugin that owns this command.
*/
public AsyncCommand(String commandName, Plugin owner) {
public AsyncCommand(@NotNull String commandName, Plugin owner) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

For future reference: please keep changes unrelated to the branch somewhere else!

super(commandName);
this.owner = owner;
}
Expand All @@ -60,7 +60,7 @@ public AsyncCommand(String commandName, Plugin owner) {
// public abstract int executeCommand(Sender sender, String commandLabel,
// String[] args);

public abstract ExitCode executeCommand(CommandSender sender, String commandLabel, String[] args);
public abstract @NotNull ExitCode executeCommand(CommandSender sender, String commandLabel, String[] args);

/**
* This is a vastly simplified command class. We only check if the plugin is
Expand All @@ -77,17 +77,17 @@ public AsyncCommand(String commandName, Plugin owner) {
* @return {@link ExitCode}
*/
@Override
public final boolean execute(CommandSender sender, String commandLabel, String[] args) {
public final boolean execute(@NotNull CommandSender sender, String commandLabel, String[] args) {
if (!this.owner.isEnabled())
throw new CommandException(String.format("Cannot execute command \"%s\" in plugin %s - plugin is disabled.",
commandLabel, this.owner.getDescription().getFullName()));

AsyncCommand self = this;
FutureTask<Boolean> t = new FutureTask<>(new Callable<Boolean>() {
@NotNull AsyncCommand self = this;
@NotNull FutureTask<Boolean> t = new FutureTask<>(new Callable<Boolean>() {
@Override
public Boolean call() {
public @NotNull Boolean call() {
try {
ExitCode resultingExitCode = self.executeCommand(sender, commandLabel, args);
@NotNull ExitCode resultingExitCode = self.executeCommand(sender, commandLabel, args);

if (resultingExitCode == null) {
throw new IllegalArgumentException("A null exit code was returned");
Expand Down Expand Up @@ -116,7 +116,7 @@ public Boolean call() {
* @return Plugin that owns this command
*/
@Override
public Plugin getPlugin() {
public @NotNull Plugin getPlugin() {
return this.owner;
}

Expand Down Expand Up @@ -181,16 +181,16 @@ public void setTabCompleter(TabCompleter completer) {
*/
@Override
public java.util.@NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias,
String[] args) throws CommandException, IllegalArgumentException {
String @org.jetbrains.annotations.Nullable [] args) throws CommandException, IllegalArgumentException {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Wacky import? If this can be imported as normal, would be appreciated.

if (args == null)
throw new NullPointerException("arguments to tabComplete cannot be null");

List<String> completions = null;
@org.jetbrains.annotations.Nullable List<String> completions = null;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I believe these annotations are for the KLS to help infer things properly - don't think we need them in internal Java code.

try {
if (completer != null)
completions = completer.onTabComplete(sender, this, alias, args);
} catch (Throwable ex) {
StringBuilder message = new StringBuilder();
@NotNull StringBuilder message = new StringBuilder();
message.append("Unhandled exception during tab completion for command '/").append(alias).append(' ');
for (String arg : args)
message.append(arg).append(' ');
Expand All @@ -212,8 +212,8 @@ public void setTabCompleter(TabCompleter completer) {
* @return the human readable name of the class
*/
@Override
public String toString() {
StringBuilder stringBuilder = new StringBuilder(super.toString());
public @NotNull String toString() {
@NotNull StringBuilder stringBuilder = new StringBuilder(super.toString());
stringBuilder.deleteCharAt(stringBuilder.length() - 1);
stringBuilder.append(", ").append(owner.getDescription().getFullName()).append(')');
return stringBuilder.toString();
Expand Down
Loading