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

MojangAPI and textures #102

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open

MojangAPI and textures #102

wants to merge 17 commits into from

Conversation

aakatz3
Copy link
Collaborator

@aakatz3 aakatz3 commented Mar 17, 2021

It would be super nice to have a way to interact with Mojang's web api; and it would also be nice ot have some utility methods for textures

BOTH are in one pr because they interact with each other a bunch, especially in testing

@aakatz3 aakatz3 requested a review from a team as a code owner March 17, 2021 20:47
*/
package com.dumbdogdiner.stickyapi.webapi.mcapi;

class Ping {
Copy link
Contributor

Choose a reason for hiding this comment

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

one class for just two vars? please move these to wherever they are used, thanks!

Copy link
Collaborator

Choose a reason for hiding this comment

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

Very much agree with koda here - what's this used for? Likely for ping status yes, but imo this is slightly overkill.

*/
package com.dumbdogdiner.stickyapi.webapi.namemc;

class Profile {
Copy link
Contributor

Choose a reason for hiding this comment

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

please remove empty classes

*/
package com.dumbdogdiner.stickyapi.webapi.namemc;

class Server {
Copy link
Contributor

Choose a reason for hiding this comment

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

please remove empty classes

@aakatz3
Copy link
Collaborator Author

aakatz3 commented Mar 18, 2021

Re review of irrelevant bits: currently working on pulling these out

@aakatz3 aakatz3 force-pushed the feat/aakatz3/mojangapi branch from 05c3e57 to 8f9a805 Compare March 21, 2021 04:54
@codecov
Copy link

codecov bot commented Mar 21, 2021

Codecov Report

Merging #102 (fa22fff) into master (262edf1) will increase coverage by 0.09%.
The diff coverage is 36.99%.

❗ Current head fa22fff differs from pull request most recent head 46dbdc0. Consider uploading reports for the commit 46dbdc0 to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##           master     #102      +/-   ##
==========================================
+ Coverage   34.72%   34.82%   +0.09%     
==========================================
  Files          63       83      +20     
  Lines        2534     3024     +490     
  Branches      286      332      +46     
==========================================
+ Hits          880     1053     +173     
- Misses       1591     1890     +299     
- Partials       63       81      +18     
Impacted Files Coverage Δ
...diner/stickyapi/bukkit/item/PlayerHeadBuilder.java 0.00% <0.00%> (ø)
...iner/stickyapi/webapi/minecraftheads/Category.java 0.00% <0.00%> (ø)
...iner/stickyapi/webapi/minecraftheads/HeadInfo.java 0.00% <0.00%> (ø)
...r/stickyapi/util/http/HttpConnectionException.java 0.00% <0.00%> (ø)
...umbdogdiner/stickyapi/util/http/HttpException.java 0.00% <0.00%> (ø)
...diner/stickyapi/util/http/HttpStatusException.java 0.00% <0.00%> (ø)
...ogdiner/stickyapi/webapi/misc/BlacklistChecks.java 0.00% <0.00%> (ø)
...m/dumbdogdiner/stickyapi/webapi/namemc/NameMC.java 0.00% <0.00%> (ø)
...gdiner/stickyapi/webapi/namemc/ScrapedProfile.java 0.00% <0.00%> (ø)
.../util/textures/headdatabase/MinecraftHeadsAPI.java 18.75% <18.75%> (ø)
... and 41 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 262edf1...46dbdc0. Read the comment docs.

@aakatz3
Copy link
Collaborator Author

aakatz3 commented Mar 22, 2021

TODO: add caching support to MojangAPI so it can cache things that are just used, maybe even just a 60 second cache, but it helps if a few things are needed at once

Copy link
Collaborator

@kaylendog kaylendog left a comment

Choose a reason for hiding this comment

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

Looks okay - some formatting complaints. Lots of empty classes/seemingly redundant code - are these needed?

@@ -2,6 +2,10 @@ plugins {
id "io.freefair.lombok" version "5.3.0" apply false
id "com.github.hierynomus.license" version "0.15.0" apply false

// root project - intellij

id 'idea'
Copy link
Collaborator

Choose a reason for hiding this comment

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

What is up with all this spacing lul

build.gradle Outdated
@@ -10,6 +14,8 @@ allprojects {
group = "com.dumbdogdiner"
version = "2.2.0"

apply plugin: "idea"

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

javadoc.options.encoding = "UTF-8"
tasks.withType(Javadoc) {
options.addBooleanOption("quiet", true)
options.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.

This doesn't need to be specified if it's in allprojects {}, no?

@@ -28,6 +28,7 @@ dependencies {
These is also an accompanying test at (test src) com.dumbdogdiner.stickyapi.StickyAPITest
*/


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

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

Choose a reason for hiding this comment

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

Why does this existtttt

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Check where it's used

Copy link
Collaborator

@kaylendog kaylendog Mar 23, 2021

Choose a reason for hiding this comment

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

Point still stands? This isn't really something we need

Copy link
Collaborator Author

@aakatz3 aakatz3 Mar 24, 2021

Choose a reason for hiding this comment

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

I think its needed because if any of the methods are called, it will crash, so its for documentation, and can be used with google's errorprone (or that can be used) to make sure they are not called

Copy link
Collaborator

Choose a reason for hiding this comment

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

Okay, but please don't add things unrelated to a PR without asking the rest of the team - for future reference.

Copy link
Contributor

Choose a reason for hiding this comment

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

Would also like to add that if you dont want a specific method to be called, please use the correct modifier for your use case instead of creating annotations that wont prevent the user from executing this method.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

image

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 may be able to do stuff via refactor though

Copy link
Collaborator

Choose a reason for hiding this comment

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

Cloned from previous PR:

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

So yes, would be nice if you can refactor this in a way that doesn't cause this issue.

*/


class AshconResponse {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Internal classes in here are lacking javadoc!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Why do internal data classes need javadoc?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Because we still need to read this code when we're adding to it.

Copy link
Member

Choose a reason for hiding this comment

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

Why do internal data classes need javadoc?

We still need to understand and read the code.



// Double check the occurances of this and whatnot, try to fix, etc.
public class MojangAPI {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Description of class would be nice :3 + javadoc for methods

private static final @NotNull OkHttpClient CLIENT = HttpUtil.getDefaultClientInstance();


protected static final @NotNull HttpUrl COMBINED_API_URL = new HttpUrl.Builder()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would using strings be easier?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No

Copy link
Collaborator

Choose a reason for hiding this comment

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

Why not

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Do you mean using .parse? I'm changing to that. HttpUrl is useful for setting flags

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes

Copy link
Collaborator

Choose a reason for hiding this comment

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

Did you end up changing to .parse?

import java.util.UUID;
import java.util.stream.Collectors;

public class NameMC {
Copy link
Collaborator

Choose a reason for hiding this comment

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

See comments for MojangAPI

import java.util.List;
import java.util.UUID;

class ScrapedProfile {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Javadoc :3

@aakatz3
Copy link
Collaborator Author

aakatz3 commented Mar 23, 2021

Empty classes will either be filled to spec or removed prior to merging. Have to check for duplicate code, I did my best but haven't checked changelog

@jcxldn jcxldn added this to the v3.0 (next) milestone Mar 29, 2021
@jcxldn jcxldn changed the base branch from feat/jcx/major/modules-def to master March 29, 2021 12:04
@kaylendog
Copy link
Collaborator

kaylendog commented Apr 19, 2021

I have no idea what comments from the review I made earlier are valid here, but worth checking some of those. If I get some time tomorrow I will review this too.

@aakatz3
Copy link
Collaborator Author

aakatz3 commented Apr 20, 2021

@SkyezerFox This is the PR that needs review, the other one is for reference only, and is a very old version of the code

@kaylendog
Copy link
Collaborator

Am knows, hence my comment yesterday.

Copy link
Collaborator

@kaylendog kaylendog left a comment

Choose a reason for hiding this comment

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

Some things still valid from the previous PR:

  1. Formatting, but we can fix that with spotless so don't worry.
  2. Pls see comments for a couple of specific things - there are still some unresolved comments above!
  3. thx for working so hard <3
  • friendly neighborhood floofball


import java.io.File;

public class StickyAPIPlugin extends JavaPlugin {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Cloned from the previous review:

Did we ever agree on how we would implement this? Thought for quite a long time it makes much more sense to just pass plugin-specific data about. Do correct me if I'm wrong.

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 don't remember us agreeing, and I also don't remember an easy way to do testing on plugin type functions without making a mocked plugin. please correct me

Copy link
Collaborator

Choose a reason for hiding this comment

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

Okay, can you refactor this out into a separate branch and then we can discuss how it would be implemented from there? Would be highly appreciated <3

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 needed for testing heads, I can refactor but it's a pain due to testing. @Prouser123 thoughts?


implementation("com.squareup.okhttp3:okhttp")
implementation("com.squareup.okhttp3:logging-interceptor")
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.

Cloned from previous PR:
image

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

CommonsValidator also allows us to remove a bunch of the luhn/shortid code we have; I can write a URL regex if necessary.

Copy link
Collaborator

Choose a reason for hiding this comment

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

https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*) here's one :3

Copy link
Collaborator

Choose a reason for hiding this comment

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

Would be very appreciated if you can stick with Preconditions since we can technically 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.

I wrote a special one, and it should be in there, not sure if pushed. Included domain checking

import java.time.Instant;

@UtilityClass
public class BlacklistChecks {
Copy link
Collaborator

Choose a reason for hiding this comment

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

JavaDoc pls <3

Copy link
Collaborator

Choose a reason for hiding this comment

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

For the entire class :3


/**
* Provides the UUID associated with a given username at a given time.
* FIXME: This is currently broken, with an <a href="https://bugs.mojang.com/browse/WEB-3367>open bug report at Mojang</a>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Looks like JavaDoc might complain about this.

Suggested change
* FIXME: This is currently broken, with an <a href="https://bugs.mojang.com/browse/WEB-3367>open bug report at Mojang</a>
* FIXME: This is currently broken, with an <a href="https://bugs.mojang.com/browse/WEB-3367">open bug report at Mojang</a>

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed

Copy link
Collaborator

Choose a reason for hiding this comment

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

Looks broken on my end still. Not included in commit perhaps?

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'm just marking them off as I go so I'm not a dumbwoof

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Because I've been asked to make less commits

Copy link
Collaborator

Choose a reason for hiding this comment

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

Who told you that? Many commits are fine as long as you label them properly :3

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

Choose a reason for hiding this comment

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

Cloned from previous PR:

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

So yes, would be nice if you can refactor this in a way that doesn't cause this issue.

@@ -1,6 +1,6 @@
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.3-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.

From previous PR:

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

@DoNotCall
@Override
@Deprecated
public @NotNull SkullBuilder texture(@NotNull String str) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

See comments on DoNotCall.

public static String getName(int headId) {
if(usePlugin)
return getNamePlugin(headId);
else {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Unnecessary else statement - return breaks out of the method anyway.

@kaylendog
Copy link
Collaborator

kaylendog commented Apr 20, 2021

In regards to your comment here, #56 (comment), that's not the code style we're using. Here's Google's styleguide - must draw attention to the section on immutable variables:

If any of the instance's observable state can change, it is not a constant. Merely intending to never mutate the object is not enough.

Given that this is a HashMap and we're not using Collections.unmodifiableMap here (might be worth doing?), this should be in standard lowerCamelCase. Regardless, think we're going to stick with CONSTANT_CASE for constants anyways.

@kaylendog
Copy link
Collaborator

Formatting complaints can be ignored for now - will be fixed when we get spotless working.

@aakatz3
Copy link
Collaborator Author

aakatz3 commented Apr 21, 2021

@SkyezerFox so, i cant use C style for statics?

@kaylendog
Copy link
Collaborator

@SkyezerFox so, i cant use C style for statics?

It's not specified in the code style we're planning to use, so I wouldn't do it here while we wait to implement it, no.

@aakatz3
Copy link
Collaborator Author

aakatz3 commented Apr 27, 2021

@SkyezerFox so, i cant use C style for statics?

It's not specified in the code style we're planning to use, so I wouldn't do it here while we wait to implement it, no.

Can we discuss adding it to our styleguide? It's nice to identify statics

@kaylendog
Copy link
Collaborator

@SkyezerFox so, i cant use C style for statics?

It's not specified in the code style we're planning to use, so I wouldn't do it here while we wait to implement it, no.

Can we discuss adding it to our styleguide? It's nice to identify statics

We can add it to the next meeting, but pls stick with no C statics until we decide.

@ZachyFoxx ZachyFoxx requested review from kaylendog and kokumaji June 9, 2021 05:02
@ZachyFoxx
Copy link
Member

My god the build process... Anyway, building fails and there are current conflicts. Please resolve these and await the re-requested reviews.

Note to reviewers: When the above requested changes are completed, you will have 7 days to review before this gets merged.

@kokumaji
Copy link
Contributor

kokumaji commented Jun 9, 2021

Only thing I'd like to add (not going to review in detail), but knowing you, there definitely are bits in this PR that are entirely unrelated to MojangAPI and a thing to get heads. If not done already, I'd ask you to remove them from this PR and open a new one with a proper description of what you want changed (although please don't do this now <3)

@kokumaji kokumaji removed their request for review June 9, 2021 05:30
Copy link
Collaborator

@kaylendog kaylendog left a comment

Choose a reason for hiding this comment

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

Mostly good, still a bunch of comments left over from my March review + added some more - pls fix :3

meta = (SkullMeta) head.getItemMeta();
Preconditions.checkNotNull(meta, "Player head must have metadata attached");
// We check this almost immediately after, so it's OK if it's null temporarily
//noinspection ConstantConditions
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can u b careful not to leave editor specific comments around?

/**
* @param playerId the UUID of the player whose head should be generated
*/
public PlayerHeadBuilder(@NotNull UUID playerId) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Bump

@Getter
@NotNull
@VisibleForTesting
private String category = "*";
Copy link
Collaborator

Choose a reason for hiding this comment

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

Bump


profile.setProperty(new ProfileProperty("textures", texture));
meta.setPlayerProfile(profile);
@NotNull ItemStack head = new ItemStack(Material.PLAYER_HEAD, quantity);
Copy link
Collaborator

Choose a reason for hiding this comment

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

No need for @NotNull annotations in code - unless you want to add them, kotlin can't do anything useful with them since they're not externally visible.

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 more for reading and notes, and also because when you auto add them it adds them everywhere

@@ -0,0 +1,75 @@
plugins {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Definitely a need for a consistent quoting/brackets commit here. Are we doing implementation thing or implementation(thing), "" or ''?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ideally, if @Prouser123 agrees, it will be kotlin style syntax. When you cut and paste from different things, you get different syntax.

private static final HeadDatabaseAPI mcheads;

static {
//noinspection ConstantConditions
Copy link
Collaborator

Choose a reason for hiding this comment

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

See above

//noinspection ConstantConditions
if(ServerVersion.isBukkit() && Bukkit.getServer() != null) {
if (Bukkit.getPluginManager().getPlugin("HeadDatabase") == null) {
Bukkit.getLogger().severe("HeadDatabase Plugin was not found!");
Copy link
Collaborator

Choose a reason for hiding this comment

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

Definitely some logic simplifying possible here - you set them null if none of these conditions match?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If we don't have the heads database plugin availible (either because its not installed or because we arent on bukkit) then it goes to fallback


for (int i = 0; i < TEST_REPS; i++) {
HeadThing thing;
//noinspection StatementWithEmptyBody
Copy link
Collaborator

Choose a reason for hiding this comment

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

See above

this(DEFAULT_DOMAIN_REGEX);
}

private UrlValidator(Pattern domain){
Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, this is a private method, but for future devs can you comment on what it does?

import java.time.Instant;

@UtilityClass
public class BlacklistChecks {
Copy link
Collaborator

Choose a reason for hiding this comment

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

For the entire class :3

@kaylendog
Copy link
Collaborator

An additional comment - why is the config package completely empty now?

@kaylendog
Copy link
Collaborator

Might b worth cherry-picking stuff since this PR is chonky af.

Copy link
Collaborator

@kaylendog kaylendog left a comment

Choose a reason for hiding this comment

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

Note on MojangAPI

private static final @NotNull OkHttpClient CLIENT = HttpUtil.getDefaultClientInstance();


protected static final @NotNull HttpUrl COMBINED_API_URL = new HttpUrl.Builder()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Did you end up changing to .parse?

@aakatz3
Copy link
Collaborator Author

aakatz3 commented Jun 9, 2021

Note on MojangAPI

Changing what to .parse?

@aakatz3 aakatz3 force-pushed the feat/aakatz3/mojangapi branch from dd42e0c to bc947a5 Compare June 9, 2021 17:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants