aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/me/Danker/commands/LobbySkillsCommand.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/me/Danker/commands/LobbySkillsCommand.java')
-rw-r--r--src/main/java/me/Danker/commands/LobbySkillsCommand.java55
1 files changed, 25 insertions, 30 deletions
diff --git a/src/main/java/me/Danker/commands/LobbySkillsCommand.java b/src/main/java/me/Danker/commands/LobbySkillsCommand.java
index 679898d..e5bf98c 100644
--- a/src/main/java/me/Danker/commands/LobbySkillsCommand.java
+++ b/src/main/java/me/Danker/commands/LobbySkillsCommand.java
@@ -1,17 +1,8 @@
package me.Danker.commands;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.LinkedHashMap;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.stream.Collectors;
-
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
-
-import me.Danker.TheMod;
+import me.Danker.DankersSkyblockMod;
import me.Danker.handlers.APIHandler;
import me.Danker.handlers.ConfigHandler;
import me.Danker.utils.Utils;
@@ -24,6 +15,10 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.EnumChatFormatting;
+import java.util.*;
+import java.util.Map.Entry;
+import java.util.stream.Collectors;
+
public class LobbySkillsCommand extends CommandBase {
Thread mainThread = null;
@@ -46,20 +41,20 @@ public class LobbySkillsCommand extends CommandBase {
@Override
public void processCommand(ICommandSender arg0, String[] arg1) throws CommandException {
EntityPlayer playerSP = (EntityPlayer) arg0;
- Map<String, Double> unsortedSAList = new HashMap<String, Double>();
- ArrayList<Double> lobbySkills = new ArrayList<Double>();
+ Map<String, Double> unsortedSAList = new HashMap<>();
+ ArrayList<Double> lobbySkills = new ArrayList<>();
// Check key
String key = ConfigHandler.getString("api", "APIKey");
if (key.equals("")) {
- playerSP.addChatMessage(new ChatComponentText(TheMod.ERROR_COLOUR + "API key not set. Use /setkey."));
+ playerSP.addChatMessage(new ChatComponentText(DankersSkyblockMod.ERROR_COLOUR + "API key not set. Use /setkey."));
return;
}
mainThread = new Thread(() -> {
try {
// Create deep copy of players to prevent passing reference and ConcurrentModificationException
- Collection<NetworkPlayerInfo> players = new ArrayList<NetworkPlayerInfo>(Minecraft.getMinecraft().getNetHandler().getPlayerInfoMap());
- playerSP.addChatMessage(new ChatComponentText(TheMod.MAIN_COLOUR + "Checking skill average of lobby. Estimated time: " + (int) (players.size() * 1.2 + 1) + " seconds."));
+ Collection<NetworkPlayerInfo> players = new ArrayList<>(Minecraft.getMinecraft().getNetHandler().getPlayerInfoMap());
+ playerSP.addChatMessage(new ChatComponentText(DankersSkyblockMod.MAIN_COLOUR + "Checking skill average of lobby. Estimated time: " + (int) (players.size() * 1.2 + 1) + " seconds."));
// Send request every .6 seconds, leaving room for another 20 requests per minute
for (final NetworkPlayerInfo player : players) {
@@ -121,7 +116,7 @@ public class LobbySkillsCommand extends CommandBase {
fishingLevel = (double) Math.round(fishingLevel * 100) / 100;
}
if (latestProfile.has("experience_skill_enchanting")) {
- enchantingLevel = Utils.xpToSkillLevel(latestProfile.get("experience_skill_enchanting").getAsDouble(), 50);
+ enchantingLevel = Utils.xpToSkillLevel(latestProfile.get("experience_skill_enchanting").getAsDouble(), 60);
enchantingLevel = (double) Math.round(enchantingLevel * 100) / 100;
}
if (latestProfile.has("experience_skill_alchemy")) {
@@ -148,25 +143,25 @@ public class LobbySkillsCommand extends CommandBase {
farmingLevel = achievementObject.get("skyblock_harvester").getAsInt();
}
if (achievementObject.has("skyblock_excavator")) {
- miningLevel = achievementObject.get("skyblock_excavator").getAsInt();
+ miningLevel = Math.min(achievementObject.get("skyblock_excavator").getAsInt(), 50);
}
if (achievementObject.has("skyblock_combat")) {
- combatLevel = achievementObject.get("skyblock_combat").getAsInt();
+ combatLevel = Math.min(achievementObject.get("skyblock_combat").getAsInt(), 50);
}
if (achievementObject.has("skyblock_gatherer")) {
- foragingLevel = achievementObject.get("skyblock_gatherer").getAsInt();
+ foragingLevel = Math.min(achievementObject.get("skyblock_gatherer").getAsInt(), 50);
}
if (achievementObject.has("skyblock_angler")) {
- fishingLevel = achievementObject.get("skyblock_angler").getAsInt();
+ fishingLevel = Math.min(achievementObject.get("skyblock_angler").getAsInt(), 50);
}
if (achievementObject.has("skyblock_augmentation")) {
enchantingLevel = achievementObject.get("skyblock_augmentation").getAsInt();
}
if (achievementObject.has("skyblock_concoctor")) {
- alchemyLevel = achievementObject.get("skyblock_concoctor").getAsInt();
+ alchemyLevel = Math.min(achievementObject.get("skyblock_concoctor").getAsInt(), 50);
}
if (achievementObject.has("skyblock_domesticator")) {
- tamingLevel = achievementObject.get("skyblock_domesticator").getAsInt();
+ tamingLevel = Math.min(achievementObject.get("skyblock_domesticator").getAsInt(), 50);
}
}
@@ -182,24 +177,24 @@ public class LobbySkillsCommand extends CommandBase {
.collect(Collectors.toMap(Entry::getKey, Entry::getValue,
(e1, e2) -> e1, LinkedHashMap::new));
- String[] sortedSAListKeys = sortedSAList.keySet().toArray(new String[sortedSAList.keySet().size()]);
+ String[] sortedSAListKeys = sortedSAList.keySet().toArray(new String[0]);
String top3 = "";
for (int i = 0; i < 3 && i < sortedSAListKeys.length; i++) {
- top3 += "\n " + EnumChatFormatting.AQUA + sortedSAListKeys[i] + ": " + TheMod.SKILL_AVERAGE_COLOUR + EnumChatFormatting.BOLD + sortedSAList.get(sortedSAListKeys[i]);
+ top3 += "\n " + EnumChatFormatting.AQUA + sortedSAListKeys[i] + ": " + DankersSkyblockMod.SKILL_AVERAGE_COLOUR + EnumChatFormatting.BOLD + sortedSAList.get(sortedSAListKeys[i]);
}
// Get lobby sa
double lobbySA = 0;
- for (int i = 0; i < lobbySkills.size(); i++) {
- lobbySA += lobbySkills.get(i);
+ for (Double playerSkills : lobbySkills) {
+ lobbySA += playerSkills;
}
lobbySA = (double) Math.round((lobbySA / lobbySkills.size()) * 100) / 100;
// Finally say skill lobby avg and highest SA users
- playerSP.addChatMessage(new ChatComponentText(TheMod.DELIMITER_COLOUR + "" + EnumChatFormatting.BOLD + "-------------------\n" +
- TheMod.TYPE_COLOUR + " Lobby Skill Average: " + TheMod.SKILL_AVERAGE_COLOUR + EnumChatFormatting.BOLD + lobbySA + "\n" +
- TheMod.TYPE_COLOUR + " Highest Skill Averages:" + top3 + "\n" +
- TheMod.DELIMITER_COLOUR + "" + EnumChatFormatting.BOLD + " -------------------"));
+ playerSP.addChatMessage(new ChatComponentText(DankersSkyblockMod.DELIMITER_COLOUR + "" + EnumChatFormatting.BOLD + "-------------------\n" +
+ DankersSkyblockMod.TYPE_COLOUR + " Lobby Skill Average: " + DankersSkyblockMod.SKILL_AVERAGE_COLOUR + EnumChatFormatting.BOLD + lobbySA + "\n" +
+ DankersSkyblockMod.TYPE_COLOUR + " Highest Skill Averages:" + top3 + "\n" +
+ DankersSkyblockMod.DELIMITER_COLOUR + "" + EnumChatFormatting.BOLD + " -------------------"));
} catch (InterruptedException ex) {
System.out.println("Current skill average list: " + unsortedSAList.toString());
Thread.currentThread().interrupt();