From a1fa5a67caebf754a0fcc43168672823ede0db93 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Fri, 4 Jun 2021 01:18:28 +0800 Subject: merge is pain --- .../notenoughupdates/util/XPInformation.java | 52 +++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) (limited to 'src/main/java/io/github/moulberry/notenoughupdates/util/XPInformation.java') diff --git a/src/main/java/io/github/moulberry/notenoughupdates/util/XPInformation.java b/src/main/java/io/github/moulberry/notenoughupdates/util/XPInformation.java index c3535ab4..cde93ddf 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/util/XPInformation.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/util/XPInformation.java @@ -31,9 +31,13 @@ public class XPInformation { } private HashMap skillInfoMap = new HashMap<>(); + public HashMap updateWithPercentage = new HashMap<>(); + + public int correctionCounter = 0; private static Splitter SPACE_SPLITTER = Splitter.on(" ").omitEmptyStrings().trimResults(); private static Pattern SKILL_PATTERN = Pattern.compile("\\+(\\d+(?:,\\d+)*(?:\\.\\d+)?) (.+) \\((\\d+(?:,\\d+)*(?:\\.\\d+)?)/(\\d+(?:,\\d+)*(?:\\.\\d+)?)\\)"); + private static Pattern SKILL_PATTERN_ALT = Pattern.compile("\\+(\\d+(?:,\\d+)*(?:\\.\\d+)?) (.+) \\((\\d\\d?(?:\\.\\d\\d?)?)%\\)"); public HashMap getSkillInfoMap() { return skillInfoMap; @@ -43,7 +47,7 @@ public class XPInformation { return skillInfoMap.get(skillName.toLowerCase()); } - @SubscribeEvent(priority = EventPriority.HIGHEST) + @SubscribeEvent(priority = EventPriority.HIGHEST, receiveCanceled = true) public void onChatReceived(ClientChatReceivedEvent event) { if(event.type == 2) { JsonObject leveling = Constants.LEVELING; @@ -78,8 +82,54 @@ public class XPInformation { } skillInfoMap.put(skillS.toLowerCase(), skillInfo); + return; + } + matcher = SKILL_PATTERN_ALT.matcher(component); + if(matcher.matches()) { + String skillS = matcher.group(2); + String xpPercentageS = matcher.group(3).replace(",",""); + + float xpPercentage = Float.parseFloat(xpPercentageS); + updateWithPercentage.put(skillS.toLowerCase(), xpPercentage); + } + } + } + } + + public void updateLevel(String skill, int level) { + if(updateWithPercentage.containsKey(skill)) { + JsonObject leveling = Constants.LEVELING; + if(leveling == null) return; + + SkillInfo skillInfo = new SkillInfo(); + skillInfo.totalXp = 0; + skillInfo.level = level; + + JsonArray levelingArray = leveling.getAsJsonArray("leveling_xp"); + for(int i=0; i= 10) { + correctionCounter = 0; + skillInfoMap.put(skill.toLowerCase(), skillInfo); + } + + updateWithPercentage.remove(skill); } } -- cgit