This commit is contained in:
@ -18,38 +18,30 @@ public class PlayerProfile {
|
||||
public static Member PROFILE;
|
||||
private static Timer timerTask;
|
||||
private static boolean timerSet;
|
||||
private static String apikey;
|
||||
private static String uuid;
|
||||
|
||||
public static void init(Boolean timer) {
|
||||
if (timer && !timerSet) {
|
||||
timerTask = new Timer("Timer");
|
||||
timerTask.scheduleAtFixedRate(new TimerTask() {
|
||||
public void run() {
|
||||
PlayerProfile.init(false);
|
||||
PlayerProfile.updateProfile();
|
||||
}
|
||||
}, 1000L, 1000L * 60L);
|
||||
}, 0, 1000L * 60L * 3);
|
||||
timerSet = true;
|
||||
}
|
||||
|
||||
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;
|
||||
uuid = MinecraftClient.getInstance().getSession().getUuidOrNull().toString().replace("-", "");
|
||||
apikey = skilloverlayconfig.get().general.apiKey;
|
||||
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println("API update! (every minute)");
|
||||
PlayerProfile.updateProfile();
|
||||
}
|
||||
|
||||
public static Profile updateProfile(String apiurl) {
|
||||
public static void updateProfile() {
|
||||
String apiurl = "https://api.hypixel.net/skyblock/profiles?key=" + apikey + "&uuid=" + uuid;
|
||||
if (apiurl.length() == 0)
|
||||
return null;
|
||||
return;
|
||||
|
||||
try {
|
||||
URL url = new URL(apiurl);
|
||||
@ -57,10 +49,16 @@ public class PlayerProfile {
|
||||
Gson gson = new GsonBuilder()
|
||||
.serializeNulls()
|
||||
.create();
|
||||
return gson.fromJson(reader, Profile.class);
|
||||
Profile profile = gson.fromJson(reader, Profile.class);
|
||||
if (profile != null) {
|
||||
profile.profiles().removeIf(p -> !p.selected());
|
||||
PROFILE = profile.profiles().get(0).members().get(uuid);
|
||||
} else {
|
||||
System.out.println("leer uff");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -13,24 +13,18 @@ import lel.flummi.skilloverlay.config.skilloverlayconfig;
|
||||
|
||||
public class PlayerSkills {
|
||||
public static HashMap<String, Skill> SKILLS;
|
||||
private static String apikey;
|
||||
|
||||
public static void init() {
|
||||
String apikey = skilloverlayconfig.get().general.apiKey;
|
||||
String apiurl = "https://api.hypixel.net/resources/skyblock/skills?key=" + apikey;
|
||||
apikey = skilloverlayconfig.get().general.apiKey;
|
||||
|
||||
if (apikey.length() > 0) {
|
||||
Skills skills = PlayerSkills.updateSkills(apiurl);
|
||||
if (skills != null) {
|
||||
SKILLS = skills.skills();
|
||||
} else {
|
||||
System.out.println("leer uff");
|
||||
}
|
||||
}
|
||||
PlayerSkills.updateSkills();
|
||||
}
|
||||
|
||||
public static Skills updateSkills(String apiurl) {
|
||||
public static void updateSkills() {
|
||||
String apiurl = "https://api.hypixel.net/resources/skyblock/skills?key=" + apikey;
|
||||
if (apiurl.length() == 0)
|
||||
return null;
|
||||
return;
|
||||
|
||||
try {
|
||||
URL url = new URL(apiurl);
|
||||
@ -38,10 +32,15 @@ public class PlayerSkills {
|
||||
Gson gson = new GsonBuilder()
|
||||
.serializeNulls()
|
||||
.create();
|
||||
return gson.fromJson(reader, Skills.class);
|
||||
Skills skills = gson.fromJson(reader, Skills.class);
|
||||
if (skills != null) {
|
||||
SKILLS = skills.skills();
|
||||
} else {
|
||||
System.out.println("leer uff");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -17,17 +17,50 @@ public record Skills(
|
||||
}
|
||||
|
||||
public SkillInfo getLevel(float exp) {
|
||||
int aktLevel = 0;
|
||||
LevelObj levelObj = new LevelObj();
|
||||
levelObj.totalXp = exp;
|
||||
levelObj.maxLevel = 60;
|
||||
boolean cumulative = true;
|
||||
|
||||
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);
|
||||
for (int level = 0; level < this.levels().size(); level++) {
|
||||
float levelXp = this.levels().get(level).totalExpRequired;
|
||||
|
||||
if (levelXp > exp) {
|
||||
if (cumulative) {
|
||||
float previous = level > 0 ? this.levels().get(level - 1).totalExpRequired : 0;
|
||||
levelObj.maxXpForLevel = (levelXp - previous);
|
||||
levelObj.level = 1 + level + (exp - levelXp) / levelObj.maxXpForLevel;
|
||||
} else {
|
||||
levelObj.maxXpForLevel = levelXp;
|
||||
levelObj.level = level + exp / levelXp;
|
||||
}
|
||||
|
||||
if (levelObj.level > 60) {
|
||||
levelObj.level = 60;
|
||||
levelObj.maxed = true;
|
||||
}
|
||||
|
||||
return new SkillInfo(levelObj.level, levelObj.totalXp, (levelObj.level % 1) * levelObj.maxXpForLevel, levelObj.maxXpForLevel);
|
||||
}
|
||||
else {
|
||||
if (!cumulative) {
|
||||
exp -= levelXp;
|
||||
}
|
||||
}
|
||||
aktLevel = tmp.level;
|
||||
}
|
||||
|
||||
return null;
|
||||
levelObj.level = Math.min(this.levels().size(), 60);
|
||||
levelObj.maxed = true;
|
||||
|
||||
return new SkillInfo(levelObj.level, levelObj.totalXp, (levelObj.level % 1) * levelObj.maxXpForLevel, levelObj.maxXpForLevel);
|
||||
}
|
||||
|
||||
public static class LevelObj {
|
||||
public float level = 0;
|
||||
public float maxXpForLevel = 0;
|
||||
public boolean maxed = false;
|
||||
public int maxLevel;
|
||||
public float totalXp;
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user