proper formatting
All checks were successful
build / build (push) Successful in 1m23s

This commit is contained in:
2023-06-07 15:07:56 +02:00
parent d98070f7c0
commit 3358404a0f
12 changed files with 562 additions and 387 deletions

View File

@ -1,48 +0,0 @@
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

@ -4,6 +4,8 @@ import net.minecraft.client.MinecraftClient;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.Timer;
import java.util.TimerTask;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
@ -13,39 +15,52 @@ import lel.flummi.skilloverlay.api.records.Profile.Profiles.Member;
import lel.flummi.skilloverlay.config.skilloverlayconfig;
public class PlayerProfile {
public static Member PROFILE;
public static Member PROFILE;
private static Timer timerTask;
private static boolean timerSet;
public static void init() {
String apikey = skilloverlayconfig.get().general.apiKey;
String uuid = MinecraftClient.getInstance().getSession().getUuidOrNull().toString().replace("-", "");
String apiurl = "https://api.hypixel.net/skyblock/profiles?key=" + apikey + "&uuid=" + uuid;
public static void init(Boolean timer) {
if (timer && !timerSet) {
timerTask = new Timer("Timer");
timerTask.scheduleAtFixedRate(new TimerTask() {
public void run() {
PlayerProfile.init(false);
}
}, 1000L, 1000L * 60L);
timerSet = true;
}
if(apikey.length() > 0) {
Profile profile = PlayerProfile.updateProfile(apiurl);
if(profile != null) {
profile.profiles().removeIf(p -> !p.selected());
PROFILE = profile.profiles().get(0).members().get(uuid);
}
else {
System.out.println("leer uff");
}
}
}
String apikey = skilloverlayconfig.get().general.apiKey;
String uuid = MinecraftClient.getInstance().getSession().getUuidOrNull().toString().replace("-", "");
String apiurl = "https://api.hypixel.net/skyblock/profiles?key=" + apikey + "&uuid=" + uuid;
public static Profile updateProfile(String apiurl) {
if(apiurl.length() == 0)
return null;
if (apikey.length() > 0) {
Profile profile = PlayerProfile.updateProfile(apiurl);
if (profile != null) {
profile.profiles().removeIf(p -> !p.selected());
PROFILE = profile.profiles().get(0).members().get(uuid);
} else {
System.out.println("leer uff");
}
}
try {
URL url = new URL(apiurl);
InputStreamReader reader = new InputStreamReader(url.openStream());
Gson gson = new GsonBuilder()
.serializeNulls()
.create();
return gson.fromJson(reader, Profile.class);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
System.out.println("API update! (every minute)");
}
public static Profile updateProfile(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, Profile.class);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}

View File

@ -0,0 +1,47 @@
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 PlayerSkills {
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 = PlayerSkills.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

@ -6,17 +6,15 @@ import java.util.HashMap;
import com.google.gson.annotations.SerializedName;
public record Profile(
boolean success,
List<Profiles> profiles
) {
public record Profiles(
@SerializedName("profile_id") String profileId,
@SerializedName("last_save") long lastSave,
HashMap<String, Member> members,
boolean selected
) {
public record Member(
double experience_skill_farming
){}
}
boolean success,
List<Profiles> profiles) {
public record Profiles(
@SerializedName("profile_id") String profileId,
@SerializedName("last_save") long lastSave,
HashMap<String, Member> members,
boolean selected) {
public record Member(
float experience_skill_farming) {
}
}
}

View File

@ -3,31 +3,32 @@ package lel.flummi.skilloverlay.api.records;
import java.util.HashMap;
import java.util.List;
import lel.flummi.skilloverlay.utils.SkillInfo;
public record Skills(
HashMap<String, Skill> skills
) {
public record Skill(
String name,
int maxLevel,
List<Level> levels
) {
public record Level(
int level,
long totalExpRequired
) {}
HashMap<String, Skill> skills) {
public record Skill(
String name,
int maxLevel,
List<Level> levels) {
public record Level(
int level,
float totalExpRequired) {
}
public int getLevel(double exp) {
int aktLevel = 0;
public SkillInfo getLevel(float 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;
}
for (Level tmp : this.levels()) {
if (exp < tmp.totalExpRequired) {
// int level, float totalXp, float currentXp, float currentXpMax
return new SkillInfo(aktLevel, tmp.totalExpRequired, exp, tmp.totalExpRequired);
}
aktLevel = tmp.level;
}
return 0;
}
}
return null;
}
}
}