This commit is contained in:
parent
fc720a6541
commit
d98070f7c0
48
src/main/java/lel/flummi/skilloverlay/api/ApiSkills.java
Normal file
48
src/main/java/lel/flummi/skilloverlay/api/ApiSkills.java
Normal 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;
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user