Skip to content

Commit

Permalink
ActionBarTransformer changes
Browse files Browse the repository at this point in the history
  • Loading branch information
MisterCheezeCake committed Nov 17, 2024
1 parent 29bde20 commit c7e7885
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 38 deletions.
3 changes: 2 additions & 1 deletion OPENSOURCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

SkyBlockTweaks is free and open source software, and it would not be possible without the inspiration, reference, and use of the following open source projects

- [SkyBlocker](https://github.com/SkyblockerMod/Skyblocker) - SkyBlocker Contributors - [License](https://github.com/SkyblockerMod/Skyblocker/blob/master/LICENSE)
- [Skyblocker](https://github.com/SkyblockerMod/Skyblocker) - Skyblocker Contributors - [License](https://github.com/SkyblockerMod/Skyblocker/blob/master/LICENSE)
- [SkyBlockAddons](https://github.com/Fix3dll/SkyblockAddons) - Biscuit, Fix3dll, and SBA Contributors - [License](https://github.com/Fix3dll/SkyblockAddons/blob/main/LICENSE)
- [ChatTriggers](https://github.com/ChatTriggers/ctjs) - Matt, Squagward, and CT Contributors - [License](https://github.com/ChatTriggers/ctjs/blob/main/LICENSE)
- [ESSM](https://github.com/exhq) - exhq and nea89o - [License](https://github.com/exhq/ESSM/blob/main/LICENSE)
- [SkyHanni](https://github.com/hannibal002/SkyHanni) - hannibal002 and SH Contributors - [License](https://github.com/hannibal002/SkyHanni/blob/beta/LICENSE)
- [hm-api](https://github.com/AzureAaron/hm-api) - AzureAaron - [License](https://github.com/AzureAaron/hm-api/blob/master/LICENSE)
- [SkyblockApi](https://github.com/SkyblockAPI/SkyblockAPI) - ThatGravyBoat and Contributors - [License](https://github.com/SkyblockAPI/SkyblockAPI/blob/1.x/LICENSE.txt)



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ public class ActionBarData {
public Integer maxTickers;
@Nullable
public Integer currentTickers;
@Nullable
public String stackSymbol;
@Nullable
public Integer stackAmount;


public String toJson() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,48 +57,45 @@ public class ActionBarTransformer {
public static final String SEPERATOR4 = " ";
public static final String SEPERATOR5 = " ";
public static final String SEPERATOR12 = " ";

private static final Pattern manaAbilityPattern = Pattern.compile("-(\\d+) Mana \\((.+)\\)");
//private static Pattern skillLevelPatern = Pattern.compile("\\+(\\d+\\.?\\d*) (.+) \\((.+)\\)");
private static final Pattern skillLevelPatern = Pattern.compile("\\+([\\d,]+\\.?\\d*) (.+) \\((.+)\\)");
private static final Pattern secretsPattern = Pattern.compile("(\\d+)/(\\d+) Secrets");
private static final Pattern healthPattern = Pattern.compile("(?<current>[\\d,]+)/(?<max>[\\d,]+)❤(?:\\+[\\d,]+.)?(?: {2})?(?<stacks>\\d+)?(?<symbol>.)?");

public static ActionBarData extractDataAndRunTransformation(String actionBarText) {
try {
ActionBarData data = new ActionBarData();
String[] parts = actionBarText.split(SEPERATOR3);
String[] unmodifiedParts = actionBarText.split(SEPERATOR3);
StringBuilder newText = new StringBuilder();
for (String part : parts) {
String unpadded = part.trim();
String segment = TextUtils.removeColorCodes(unpadded);
if (segment.toLowerCase().contains("race")) {
for (String unmodifiedPart : unmodifiedParts) {
String unpadded = unmodifiedPart.trim();
String rawContent = TextUtils.removeColorCodes(unpadded);
if (rawContent.toLowerCase().contains("race")) {
// Races, we do these first because the timer updates an obscene amount
newText.append(unpadded).append(SEPERATOR12);
} else if (segment.contains("❤")) {
// Health
if (segment.contains("+")) {
// Health with a healing wand
String[] health = segment.replaceAll("❤", "").split("\\+")[0].split("/");
data.currentHealth = Float.parseFloat(health[0].replace(",", ""));
data.maxHealth = Float.parseFloat(health[1].replace(",", ""));
if (!SBTConfig.get().actionBarFilters.hideHealth) {
newText.append(SEPERATOR5).append(unpadded);
} else {
newText.append(SEPERATOR5 + TextUtils.SECTION + "c" + "+").append(segment.split("\\+")[1]);
} else if (rawContent.contains("❤")) {
var matcher = healthPattern.matcher(rawContent);
if (matcher.find()) {
data.currentHealth = Float.parseFloat(matcher.group("current").replace(",", ""));
data.maxHealth = Float.parseFloat(matcher.group("max").replace(",", ""));
if (matcher.group("stacks") != null) {
data.stackAmount = Integer.parseInt(matcher.group("stacks"));
}
if (matcher.group("symbol") != null) {
data.stackSymbol = matcher.group("symbol");
}
continue;
}
String[] health = segment.replaceAll("❤", "").split("/");
data.currentHealth = Float.parseFloat(health[0].replace(",", ""));
data.maxHealth = Float.parseFloat(health[1].replace(",", ""));
if (!SBTConfig.get().actionBarFilters.hideHealth) {
newText.append(SEPERATOR5).append(unpadded);
}

} else if (segment.contains("✎")) {
} else if (rawContent.contains("✎")) {
// Mana
// 411/1,221✎ 2ʬ
// 289/1,221✎ Mana
String[] manaParts = segment.split(" ");
String[] manaParts = rawContent.split(" ");
manaParts[0] = manaParts[0].replace("✎", "");
String[] mana = manaParts[0].split("/");
data.currentMana = Float.parseFloat(mana[0].replace(",", ""));
Expand All @@ -111,18 +108,18 @@ public static ActionBarData extractDataAndRunTransformation(String actionBarText
if (!SBTConfig.get().actionBarFilters.hideMana) {
newText.append(SEPERATOR5).append(unpadded);
}
} else if (segment.contains("NOT ENOUGH MANA")) {
} else if (rawContent.contains("NOT ENOUGH MANA")) {
newText.append(SEPERATOR5).append(unpadded);
} else if (segment.contains("❈")) {
} else if (rawContent.contains("❈")) {
// Defense
String defense = segment.split("❈")[0].trim();
String defense = rawContent.split("❈")[0].trim();
data.defense = Integer.parseInt(defense.replace(",", ""));
if (!SBTConfig.get().actionBarFilters.hideDefense) {
newText.append(SEPERATOR5).append(unpadded);
}

} else if (segment.contains("Mana")) {
Matcher matcher = manaAbilityPattern.matcher(segment);
} else if (rawContent.contains("Mana")) {
Matcher matcher = manaAbilityPattern.matcher(rawContent);
if (matcher.find()) {
data.abilityManaCost = Integer.parseInt(matcher.group(1));
data.abilityName = matcher.group(2);
Expand All @@ -133,8 +130,8 @@ public static ActionBarData extractDataAndRunTransformation(String actionBarText
}
newText.append(SEPERATOR5).append(unpadded);

} else if (skillLevelPatern.matcher(segment).matches()) {
Matcher matcher = skillLevelPatern.matcher(segment);
} else if (skillLevelPatern.matcher(rawContent).matches()) {
Matcher matcher = skillLevelPatern.matcher(rawContent);
if (matcher.find() && !matcher.group(2).contains("SkyBlock XP")) {
data.gainedXP = NumberUtils.parseFloatWithKorM(matcher.group(1));
data.skillType = matcher.group(2);
Expand All @@ -153,31 +150,31 @@ public static ActionBarData extractDataAndRunTransformation(String actionBarText
} else {
newText.append(SEPERATOR5).append(unpadded);
}
} else if (segment.contains("Secrets")) {
Matcher matcher = secretsPattern.matcher(segment);
} else if (rawContent.contains("Secrets")) {
Matcher matcher = secretsPattern.matcher(rawContent);
if (matcher.find()) {
data.secretsFound = Integer.parseInt(matcher.group(1));
data.secretsTotal = Integer.parseInt(matcher.group(2));
}
if (!SBTConfig.get().actionBarFilters.hideSecrets) {
newText.append(SEPERATOR5).append(unpadded);
}
} else if (segment.contains("Drill Fuel")) {
} else if (rawContent.contains("Drill Fuel")) {
// Drill Fuel
String[] drillFuel = segment.split(" ")[0].split("/");
String[] drillFuel = rawContent.split(" ")[0].split("/");
data.drillFuel = Integer.parseInt(drillFuel[0].replace(",", ""));
data.maxDrillFuel = NumberUtils.parseIntWithKorM(drillFuel[1]);
if (!SBTConfig.get().actionBarFilters.hideDrill) {
newText.append(SEPERATOR5).append(unpadded);
}
} else if (segment.contains("second") || segment.contains("DPS")) {
} else if (rawContent.contains("second") || rawContent.contains("DPS")) {
// Trial of Fire
newText.append(SEPERATOR3).append(unpadded);
} else if (segment.contains("ⓩ") || segment.contains("Ⓞ")){
} else if (rawContent.contains("ⓩ") || rawContent.contains("Ⓞ")){
// Ornate/Florid: §e§lⓩⓩⓩ§6§lⓄⓄ
// Regular: §a§lⓩ§2§lⓄⓄⓄ
// Foil: §e§lⓄⓄ§7§lⓄⓄ
data.maxTickers = segment.length();
data.maxTickers = rawContent.length();
if (unpadded.contains("§6§l")) {
var split = unpadded.split("§6§l") ;
data.currentTickers = TextUtils.removeColorCodes(split[0]).length();
Expand Down Expand Up @@ -213,7 +210,7 @@ else if (unpadded.contains("§7§l")) {
public static void registerEvents() {
ClientReceiveMessageEvents.MODIFY_GAME.register((message, overlay) -> {
if (!overlay) return message;
// SkyblockTweaks.LOGGER.info("Old: " + message.getString());
SkyblockTweaks.LOGGER.info("Old: " + message.getString());
var data = ActionBarTransformer.extractDataAndRunTransformation(message.getString());
//SkyblockTweaks.LOGGER.info("New: " + data.transformedText);
SkyblockTweaks.DATA.update(data);
Expand Down Expand Up @@ -248,6 +245,9 @@ public static class Config {
@SerialEntry
public boolean hideTickers = false;

@SerialEntry
public boolean hideArmorStacks = false;

public static OptionGroup getGroup(ConfigImpl defaults, ConfigImpl config) {
var health = Option.<Boolean>createBuilder()
.name(key("actionBarFilters.hideHealth"))
Expand Down

0 comments on commit c7e7885

Please sign in to comment.