From df9c1b29f0ca35f97e1c74910f6d0e01c2ca6ccb Mon Sep 17 00:00:00 2001 From: Aaron <51387595+AzureAaron@users.noreply.github.com> Date: Tue, 23 Apr 2024 20:18:43 -0400 Subject: Refactor usages of Optional's orElseThrow to getOrThrow Mojang's method is more concise and provides far superior error messages incase the value isn't present (like why it happened) whereas with Optionals its just the standard value not present message. --- .../skyblocker/skyblock/dungeon/secrets/SecretWaypointTest.java | 8 ++++---- .../skyblocker/skyblock/item/ArmorTrimIdSerializationTest.java | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'src/test/java/de/hysky/skyblocker/skyblock') diff --git a/src/test/java/de/hysky/skyblocker/skyblock/dungeon/secrets/SecretWaypointTest.java b/src/test/java/de/hysky/skyblocker/skyblock/dungeon/secrets/SecretWaypointTest.java index 12bfe98b..ef2a9e1b 100644 --- a/src/test/java/de/hysky/skyblocker/skyblock/dungeon/secrets/SecretWaypointTest.java +++ b/src/test/java/de/hysky/skyblocker/skyblock/dungeon/secrets/SecretWaypointTest.java @@ -25,7 +25,7 @@ public class SecretWaypointTest { @Test void testCodecSerialize() { SecretWaypoint waypoint = new SecretWaypoint(0, SecretWaypoint.Category.DEFAULT, "name", new BlockPos(-1, 0, 1)); - JsonElement json = SecretWaypoint.CODEC.encodeStart(JsonOps.INSTANCE, waypoint).result().orElseThrow(); + JsonElement json = SecretWaypoint.CODEC.encodeStart(JsonOps.INSTANCE, waypoint).getOrThrow(); String expectedJson = "{\"secretIndex\":0,\"category\":\"default\",\"name\":\"name\",\"pos\":[-1,0,1]}"; Assertions.assertEquals(expectedJson, json.toString()); @@ -34,7 +34,7 @@ public class SecretWaypointTest { @Test void testCodecDeserialize() { String json = "{\"secretIndex\":0,\"category\":\"default\",\"name\":\"name\",\"pos\":[-1,0,1]}"; - SecretWaypoint waypoint = SecretWaypoint.CODEC.parse(JsonOps.INSTANCE, gson.fromJson(json, JsonElement.class)).result().orElseThrow(); + SecretWaypoint waypoint = SecretWaypoint.CODEC.parse(JsonOps.INSTANCE, gson.fromJson(json, JsonElement.class)).getOrThrow(); SecretWaypoint expectedWaypoint = new SecretWaypoint(0, SecretWaypoint.Category.DEFAULT, "name", new BlockPos(-1, 0, 1)); Assertions.assertEquals(expectedWaypoint, waypoint); @@ -43,7 +43,7 @@ public class SecretWaypointTest { @Test void testListCodecSerialize() { List waypoints = List.of(new SecretWaypoint(0, SecretWaypoint.Category.DEFAULT, "name", new BlockPos(-1, 0, 1)), new SecretWaypoint(1, SecretWaypoint.Category.CHEST, "name", new BlockPos(2, 0, -2))); - JsonElement json = SecretWaypoint.LIST_CODEC.encodeStart(JsonOps.INSTANCE, waypoints).result().orElseThrow(); + JsonElement json = SecretWaypoint.LIST_CODEC.encodeStart(JsonOps.INSTANCE, waypoints).getOrThrow(); String expectedJson = "[{\"secretIndex\":0,\"category\":\"default\",\"name\":\"name\",\"pos\":[-1,0,1]},{\"secretIndex\":1,\"category\":\"chest\",\"name\":\"name\",\"pos\":[2,0,-2]}]"; Assertions.assertEquals(expectedJson, json.toString()); @@ -52,7 +52,7 @@ public class SecretWaypointTest { @Test void testListCodecDeserialize() { String json = "[{\"secretIndex\":0,\"category\":\"default\",\"name\":\"name\",\"pos\":[-1,0,1]},{\"secretIndex\":1,\"category\":\"chest\",\"name\":\"name\",\"pos\":[2,0,-2]}]"; - List waypoints = SecretWaypoint.LIST_CODEC.parse(JsonOps.INSTANCE, gson.fromJson(json, JsonElement.class)).result().orElseThrow(); + List waypoints = SecretWaypoint.LIST_CODEC.parse(JsonOps.INSTANCE, gson.fromJson(json, JsonElement.class)).getOrThrow(); List expectedWaypoints = List.of(new SecretWaypoint(0, SecretWaypoint.Category.DEFAULT, "name", new BlockPos(-1, 0, 1)), new SecretWaypoint(1, SecretWaypoint.Category.CHEST, "name", new BlockPos(2, 0, -2))); Assertions.assertEquals(expectedWaypoints.size(), waypoints.size()); diff --git a/src/test/java/de/hysky/skyblocker/skyblock/item/ArmorTrimIdSerializationTest.java b/src/test/java/de/hysky/skyblocker/skyblock/item/ArmorTrimIdSerializationTest.java index 2709aba4..5c52c3ad 100644 --- a/src/test/java/de/hysky/skyblocker/skyblock/item/ArmorTrimIdSerializationTest.java +++ b/src/test/java/de/hysky/skyblocker/skyblock/item/ArmorTrimIdSerializationTest.java @@ -15,7 +15,7 @@ public class ArmorTrimIdSerializationTest { @Test void serialize() { ArmorTrimId armorTrimId = new ArmorTrimId(new Identifier("material_id"), new Identifier("pattern_id")); - JsonElement json = ArmorTrimId.CODEC.encodeStart(JsonOps.INSTANCE, armorTrimId).result().orElseThrow(); + JsonElement json = ArmorTrimId.CODEC.encodeStart(JsonOps.INSTANCE, armorTrimId).getOrThrow(); String expectedJson = "{\"material\":\"minecraft:material_id\",\"pattern\":\"minecraft:pattern_id\"}"; Assertions.assertEquals(expectedJson, json.toString()); @@ -24,7 +24,7 @@ public class ArmorTrimIdSerializationTest { @Test void deserialize() { String json = "{\"material\":\"minecraft:material_id\",\"pattern\":\"minecraft:pattern_id\"}"; - ArmorTrimId armorTrimId = ArmorTrimId.CODEC.parse(JsonOps.INSTANCE, gson.fromJson(json, JsonElement.class)).result().orElseThrow(); + ArmorTrimId armorTrimId = ArmorTrimId.CODEC.parse(JsonOps.INSTANCE, gson.fromJson(json, JsonElement.class)).getOrThrow(); ArmorTrimId expectedArmorTrimId = new ArmorTrimId(new Identifier("material_id"), new Identifier("pattern_id")); Assertions.assertEquals(expectedArmorTrimId, armorTrimId); -- cgit From 88ff7afb7e6ab60f384e571d378b76f52ed3dfbd Mon Sep 17 00:00:00 2001 From: Aaron <51387595+AzureAaron@users.noreply.github.com> Date: Tue, 30 Apr 2024 17:59:50 -0400 Subject: Make filters ignore formatting codes The formatting codes caused a mess in longer regexes and are fragile if Hypixel changes them or moves fully to Text components. Hypixel also added emblems that display in dark purple and light blue which were obviously incompatible due to the hardcoded formatting codes. --- .../skyblocker/skyblock/filters/AdFilterTest.java | 18 ++++----- .../skyblock/filters/AutopetFilterTest.java | 2 +- .../skyblock/filters/ShowOffFilterTest.java | 47 ++++++++++++++++++++++ 3 files changed, 57 insertions(+), 10 deletions(-) create mode 100644 src/test/java/de/hysky/skyblocker/skyblock/filters/ShowOffFilterTest.java (limited to 'src/test/java/de/hysky/skyblocker/skyblock') diff --git a/src/test/java/de/hysky/skyblocker/skyblock/filters/AdFilterTest.java b/src/test/java/de/hysky/skyblocker/skyblock/filters/AdFilterTest.java index 3eec1cd9..9f788cac 100644 --- a/src/test/java/de/hysky/skyblocker/skyblock/filters/AdFilterTest.java +++ b/src/test/java/de/hysky/skyblocker/skyblock/filters/AdFilterTest.java @@ -15,47 +15,47 @@ class AdFilterTest extends ChatPatternListenerTest { @Test void noRank() { - assertMatches("§8[§a86§8] §7Advertiser§7: advertisement"); + assertMatches("[86] Advertiser: advertisement"); } @Test void vip() { - assertMatches("§8[§b280§8] §a[VIP] Advertiser§f: advertisement"); + assertMatches("[280] [VIP] Advertiser: advertisement"); } @Test void mvp() { - assertMatches("§8[§d256§8] §6§l⚡ §b[MVP§c+§b] Advertiser§f: advertisement"); + assertMatches("[256] ⚡ [MVP+] Advertiser: advertisement"); } @Test void plusPlus() { - assertMatches("§8[§6222§8] §6[MVP§c++§6] Advertiser§f: advertisement"); + assertMatches("[222] [MVP++] Advertiser: advertisement"); } @Test void capturesMessage() { - assertGroup("§8[§c325§8] §b[MVP§c+§b] b2dderr§f: buying prismapump", 2, "buying prismapump"); + assertGroup("[325] [MVP+] b2dderr: buying prismapump", 2, "buying prismapump"); } @Test void simpleAd() { - assertFilters("§8[§e320§8] §b[MVP§c+§b] b2dderr§f: buying prismapump"); + assertFilters("[320] [MVP+] b2dderr: buying prismapump"); } @Test void uppercaseAd() { - assertFilters("§8[§f70§8] §a[VIP] Tecnoisnoob§f: SELLING REJUVENATE 5 Book on ah!"); + assertFilters("[70] [VIP] Tecnoisnoob: SELLING REJUVENATE 5 Book on ah!"); } @Test void characterSpam() { - assertFilters("§8[§9144§8] §a[VIP] Benyyy_§f: Hey, Visit my Island, i spent lots of time to build it! I also made donate room! <<<<<<<<<<<<<<<<<<<"); + assertFilters("[144] [VIP] Benyyy_: Hey, Visit my Island, i spent lots of time to build it! I also made donate room! <<<<<<<<<<<<<<<<<<<"); } @Test void notAd() { - Matcher matcher = listener.pattern.matcher("§8[§6200§8] §a[VIP] NotMatching§f: This message shouldn't match!"); + Matcher matcher = listener.pattern.matcher("[200] [VIP] NotMatching: This message shouldn't match!"); assertTrue(matcher.matches()); assertFalse(listener.onMatch(null, matcher)); } diff --git a/src/test/java/de/hysky/skyblocker/skyblock/filters/AutopetFilterTest.java b/src/test/java/de/hysky/skyblocker/skyblock/filters/AutopetFilterTest.java index 846acbb8..0e578082 100644 --- a/src/test/java/de/hysky/skyblocker/skyblock/filters/AutopetFilterTest.java +++ b/src/test/java/de/hysky/skyblocker/skyblock/filters/AutopetFilterTest.java @@ -10,6 +10,6 @@ class AutopetFilterTest extends ChatPatternListenerTest { @Test void testAutopet() { - assertMatches("§cAutopet §eequipped your §7[Lvl 85] §6Tiger§e! §a§lVIEW RULE"); + assertMatches("Autopet equipped your [Lvl 85] Tiger! VIEW RULE"); } } \ No newline at end of file diff --git a/src/test/java/de/hysky/skyblocker/skyblock/filters/ShowOffFilterTest.java b/src/test/java/de/hysky/skyblocker/skyblock/filters/ShowOffFilterTest.java new file mode 100644 index 00000000..d510274c --- /dev/null +++ b/src/test/java/de/hysky/skyblocker/skyblock/filters/ShowOffFilterTest.java @@ -0,0 +1,47 @@ +package de.hysky.skyblocker.skyblock.filters; + +import org.junit.jupiter.api.Test; + +import de.hysky.skyblocker.utils.chat.ChatPatternListenerTest; + +public class ShowOffFilterTest extends ChatPatternListenerTest { + + public ShowOffFilterTest() { + super(new ShowOffFilter()); + } + + @Test + void holding() { + assertMatches("[290] ⚡ [MVP+] Player is holding [Withered Dark Claymore ✪✪✪✪✪➎]"); + } + + @Test + void wearing() { + assertMatches("[290] ⚡ [MVP+] Player is wearing [Ancient Storm's Chestplate ✪✪✪✪✪➎]"); + } + + @Test + void isFriendsWith() { + assertMatches("[290] [MVP+] Player is friends with a [[Lvl 200] Golden Dragon]"); + } + + @Test + void has() { + assertMatches("[290] ⚡ [MVP+] Player has [Withered Hyperion ✪✪✪✪✪]"); + } + + @Test + void noLevelOrEmblem() { + assertMatches("[MVP+] Player is holding [Mithril Drill SX-R226]"); + } + + @Test + void noRank() { + assertMatches("[290] ⚡ Player is holding [Oak Leaves]"); + } + + @Test + void noLevelOrEmblemOrRank() { + assertMatches("Player is holding [Nether Star]"); + } +} -- cgit From 1eea5cb1cf965bdb0552bdc9615d06a9875aa02e Mon Sep 17 00:00:00 2001 From: Kevinthegreat <92656833+kevinthegreat1@users.noreply.github.com> Date: Wed, 1 May 2024 10:58:20 -0400 Subject: Fix StatusBarTracker --- .../java/de/hysky/skyblocker/skyblock/StatusBarTrackerTest.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'src/test/java/de/hysky/skyblocker/skyblock') diff --git a/src/test/java/de/hysky/skyblocker/skyblock/StatusBarTrackerTest.java b/src/test/java/de/hysky/skyblocker/skyblock/StatusBarTrackerTest.java index c058da5d..9ab4e927 100644 --- a/src/test/java/de/hysky/skyblocker/skyblock/StatusBarTrackerTest.java +++ b/src/test/java/de/hysky/skyblocker/skyblock/StatusBarTrackerTest.java @@ -15,13 +15,12 @@ class StatusBarTrackerTest { void assertStats(int hp, int maxHp, int def, int mana, int maxMana, int overflowMana) { int absorption = 0; - if(hp > maxHp) { - absorption = hp - maxHp; - hp -= absorption; - if(absorption > maxHp) - absorption = maxHp; + if (hp > maxHp) { + absorption = Math.min(hp - maxHp, maxHp); + hp = maxHp; } assertEquals(new StatusBarTracker.Resource(hp, maxHp, absorption), tracker.getHealth()); + assertEquals(def, tracker.getDefense()); assertEquals(new StatusBarTracker.Resource(mana, maxMana, overflowMana), tracker.getMana()); } -- cgit From c36b93a6d1887596fc75759743a29955142e3cc7 Mon Sep 17 00:00:00 2001 From: Aaron <51387595+AzureAaron@users.noreply.github.com> Date: Wed, 1 May 2024 21:33:43 -0400 Subject: Remove formatting codes from a few forgotten classes Fixes Quiz, Threee Weirdos and other solvers --- .../hysky/skyblocker/skyblock/dungeon/puzzle/ThreeWeirdosTest.java | 4 ++-- .../de/hysky/skyblocker/skyblock/dungeon/puzzle/TriviaTest.java | 6 +++--- src/test/java/de/hysky/skyblocker/skyblock/dwarven/FetchurTest.java | 2 +- src/test/java/de/hysky/skyblocker/skyblock/dwarven/PuzzlerTest.java | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) (limited to 'src/test/java/de/hysky/skyblocker/skyblock') diff --git a/src/test/java/de/hysky/skyblocker/skyblock/dungeon/puzzle/ThreeWeirdosTest.java b/src/test/java/de/hysky/skyblocker/skyblock/dungeon/puzzle/ThreeWeirdosTest.java index 22683698..38e795c3 100644 --- a/src/test/java/de/hysky/skyblocker/skyblock/dungeon/puzzle/ThreeWeirdosTest.java +++ b/src/test/java/de/hysky/skyblocker/skyblock/dungeon/puzzle/ThreeWeirdosTest.java @@ -10,10 +10,10 @@ class ThreeWeirdosTest extends ChatPatternListenerTest { @Test void test1() { - assertGroup("§e[NPC] §cBaxter§f: My chest doesn't have the reward. We are all telling the truth.", 1, "Baxter"); + assertGroup("[NPC] Baxter: My chest doesn't have the reward. We are all telling the truth.", 1, "Baxter"); } @Test void test2() { - assertGroup("§e[NPC] §cHope§f: The reward isn't in any of our chests.", 1, "Hope"); + assertGroup("[NPC] Hope: The reward isn't in any of our chests.", 1, "Hope"); } } \ No newline at end of file diff --git a/src/test/java/de/hysky/skyblocker/skyblock/dungeon/puzzle/TriviaTest.java b/src/test/java/de/hysky/skyblocker/skyblock/dungeon/puzzle/TriviaTest.java index 55a59a68..52a7ad8c 100644 --- a/src/test/java/de/hysky/skyblocker/skyblock/dungeon/puzzle/TriviaTest.java +++ b/src/test/java/de/hysky/skyblocker/skyblock/dungeon/puzzle/TriviaTest.java @@ -20,14 +20,14 @@ class TriviaTest extends ChatPatternListenerTest { @Test void answer1() { - assertGroup(" §6 ⓐ §aAnswer 1", 3, "Answer 1"); + assertGroup(" ⓐ Answer 1", 3, "Answer 1"); } @Test void answer2() { - assertGroup(" §6 ⓑ §aAnswer 2", 3, "Answer 2"); + assertGroup(" ⓑ Answer 2", 3, "Answer 2"); } @Test void answer3() { - assertGroup(" §6 ⓒ §aAnswer 3", 3, "Answer 3"); + assertGroup(" ⓒ Answer 3", 3, "Answer 3"); } } \ No newline at end of file diff --git a/src/test/java/de/hysky/skyblocker/skyblock/dwarven/FetchurTest.java b/src/test/java/de/hysky/skyblocker/skyblock/dwarven/FetchurTest.java index 08282972..12a194ee 100644 --- a/src/test/java/de/hysky/skyblocker/skyblock/dwarven/FetchurTest.java +++ b/src/test/java/de/hysky/skyblocker/skyblock/dwarven/FetchurTest.java @@ -10,6 +10,6 @@ class FetchurTest extends ChatPatternListenerTest { @Test public void patternCaptures() { - assertGroup("§e[NPC] Fetchur§f: its a hint", 1, "a hint"); + assertGroup("[NPC] Fetchur: its a hint", 1, "a hint"); } } diff --git a/src/test/java/de/hysky/skyblocker/skyblock/dwarven/PuzzlerTest.java b/src/test/java/de/hysky/skyblocker/skyblock/dwarven/PuzzlerTest.java index 9437a5c9..c32010cf 100644 --- a/src/test/java/de/hysky/skyblocker/skyblock/dwarven/PuzzlerTest.java +++ b/src/test/java/de/hysky/skyblocker/skyblock/dwarven/PuzzlerTest.java @@ -10,6 +10,6 @@ class PuzzlerTest extends ChatPatternListenerTest { @Test void puzzler() { - assertGroup("§e[NPC] §dPuzzler§f: §b◀§d▲§b◀§d▲§d▲§5▶§5▶§b◀§d▲§a▼", 1, "§b◀§d▲§b◀§d▲§d▲§5▶§5▶§b◀§d▲§a▼"); + assertGroup("[NPC] Puzzler: ◀▲◀▲▲▶▶◀▲▼", 1, "◀▲◀▲▲▶▶◀▲▼"); } } \ No newline at end of file -- cgit