get Skills from API
All checks were successful
build / build (push) Successful in 13m17s

This commit is contained in:
Flummi 2023-06-06 01:13:40 +02:00
parent fc720a6541
commit d98070f7c0
Signed by: Flummi
GPG Key ID: AA2AEF822A6F4817
3 changed files with 83 additions and 0 deletions

View File

@ -0,0 +1,48 @@
package lel.flummi.skilloverlay.api;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.HashMap;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import lel.flummi.skilloverlay.api.records.Skills;
import lel.flummi.skilloverlay.api.records.Skills.Skill;
import lel.flummi.skilloverlay.config.skilloverlayconfig;
public class ApiSkills {
public static HashMap<String, Skill> SKILLS;
public static void init() {
String apikey = skilloverlayconfig.get().general.apiKey;
String apiurl = "https://api.hypixel.net/resources/skyblock/skills?key=" + apikey;
if(apikey.length() > 0) {
Skills skills = ApiSkills.updateSkills(apiurl);
if(skills != null) {
SKILLS = skills.skills();
}
else {
System.out.println("leer uff");
}
}
}
public static Skills updateSkills(String apiurl) {
if(apiurl.length() == 0)
return null;
try {
URL url = new URL(apiurl);
InputStreamReader reader = new InputStreamReader(url.openStream());
Gson gson = new GsonBuilder()
.serializeNulls()
.create();
return gson.fromJson(reader, Skills.class);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}

View File

@ -0,0 +1,33 @@
package lel.flummi.skilloverlay.api.records;
import java.util.HashMap;
import java.util.List;
public record Skills(
HashMap<String, Skill> skills
) {
public record Skill(
String name,
int maxLevel,
List<Level> levels
) {
public record Level(
int level,
long totalExpRequired
) {}
public int getLevel(double exp) {
int aktLevel = 0;
for(Level tmp: this.levels()) {
System.out.println((exp > tmp.totalExpRequired) + "; exp: " + exp + "; ter: " + tmp.totalExpRequired);
if(exp < tmp.totalExpRequired) {
return aktLevel;
}
aktLevel = tmp.level;
}
return 0;
}
}
}

View File

@ -4,6 +4,7 @@ import net.fabricmc.api.ModInitializer;
import lel.flummi.skilloverlay.overlays.FarmingOverlay;
import lel.flummi.skilloverlay.api.PlayerProfile;
import lel.flummi.skilloverlay.api.ApiSkills;
import lel.flummi.skilloverlay.config.skilloverlayconfig;
public class skilloverlay implements ModInitializer {
@ -17,6 +18,7 @@ public class skilloverlay implements ModInitializer {
skilloverlayconfig.init();
OVERLAY = new FarmingOverlay();
ApiSkills.init();
PlayerProfile.init();
}
}