Suggestions for better implementation of OvercastStats
Closed this issue · 8 comments
Hey there, I saw you were using OvercastStats locally to help with the profile parsing in your mod. Over the past several weeks progress has been made and the API now has a remote repository and features that allow you to make async calls.
I highly recommend you add version 1.3 to the project as a remote dependency and take advantage of the new async features, as it doesn't block the main thread and allows you to still run code while the result is being processed.
Be sure to check the readme for the section about implementing callbacks and async usage here, https://github.com/ryanw-se/OvercastStats/.
Thanks for good API.
But I can't use it because I haven't used any API, and Gradle so I don't know how to use API in gradle...
Can you explain me more about setting it?
+Sorry for bad english grammer
@smartsteves You want to navigate to your build.gradle file, which currently looks like this:
buildscript {
repositories {
mavenCentral()
maven {
name = "forge"
url = "http://files.minecraftforge.net/maven"
}
maven {
name = "sonatype"
url = "https://oss.sonatype.org/content/repositories/snapshots/"
}
}
dependencies {
classpath 'net.minecraftforge.gradle:ForgeGradle:1.2-SNAPSHOT'
}
}
and you want to change it to look like this:
buildscript {
repositories {
mavenCentral()
maven {
name = "forge"
url = "http://files.minecraftforge.net/maven"
}
maven {
name = "sonatype"
url = "https://oss.sonatype.org/content/repositories/snapshots/"
}
maven {
name = "repo.ryan-w.me"
url = "http://repo.ryan-w.me/nexus/content/repositories/snapshots/"
}
}
dependencies {
classpath 'net.minecraftforge.gradle:ForgeGradle:1.2-SNAPSHOT'
classpath 'me.ryanw.overcaststats:overcast-scraper:1.3-SNAPSHOT'
}
}
As for actual usage, you'll want to create an instance with the Overcast interface, so you'd want to do the following once you added it as a dependency: java Overcast overcast = new OvercacstStats();
That will allow you to start calling various methods and get information using the overcast variable.
I wrote build.gradle like this, but mod doesn't work because of
java.lang.NoClassDefFoundError: me/ryanw/overcaststats/api/util/Callback
when I make instance which import your api.
plus, compiled jar file doesn't contain api.jar
@smartsteves Simply add another classpath dependency to your build.gradle that adds the API into your project, like this. classpath 'me.ryanw.overcaststats:api:1.3-SNAPSHOT'
I solve that error, but getPlayerByAsync doesn't execute call method....
So I managed to briefly look at what you were doing and wrote up a quick code sample to explain, why that won't work and how you can fix it. Please take a look at, https://gist.github.com/ryanw-se/c49debc21b18696e0339 .
The first thing I noticed is, you aren't creating a new variable called overcast and instantiating the API interfaces, which isn't project breaking, but it isn't recommended and you won't get Javadoc comments. Also, keep in mind the call() function will only fire if the username is valid.
When OvercastStats can't get a players username, it silently fails. Which means that it will let you know in the logs, but it will not call the callback function or throw an exception. I'm assuming this is the case for you, as you are getting the users display name rather than their actual username.
This could lead to problems if the user has a nickname, or has a rank such as (dux or mod star). These would be most likely included in the username and of course would be invalid to the Overcast Network website.
My suggestion would be to print the output of the getDisplayNameString() and see what is going on there, also be sure to check your logs as it a silent exception should be thrown if the username is invalid.
(new OvercastStats()).getPlayerByNameAsync("smartsteve", new Callback() {
@OverRide
public void call(OvercastPlayer result) {
Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("gokfeo"));
firstdata = new StatsData(result.getGlobalStats().getGlobalKills(), result.getGlobalStats().getGlobalDeaths());
}
});
I wrote code like this but it doesn't work....
@smartsteves I can confirm that nothing is broken on my side, I recommend you do some debugging in your code and also take a look at my recommended usage gist. Most of the callback stuff is documented on the wiki, I can see several things you are still doing wrong.
For starters you are still not using the recommended usage (see the recommended gist) and second, your callback does not include the T type OvercastPlayer. You need to have Callback(). This code doesn't even appear to be valid either.
Also make sure that where ever you have the overcast.getPlayerByNameAsync() function, is actually reachable. Try debugging your code and verifying that it is functioning properly and that OvercastStats does actually get called.