From f328733453937e2c3934660b7a49b40227be5254 Mon Sep 17 00:00:00 2001 From: J10a1n15 <45315647+j10a1n15@users.noreply.github.com> Date: Thu, 12 Sep 2024 17:52:51 +0200 Subject: [PATCH] use new event system Signed-off-by: J10a1n15 <45315647+j10a1n15@users.noreply.github.com> --- .../dungeons/party/PartyFriendManager.java | 4 +- .../party/partymanager/PartyManager.java | 44 +++++++------ .../economy/minioncalculator/MinionData.java | 4 +- .../minecraft/MixinPlayerControllerMP.java | 3 +- .../partlysaneskies/PartlySaneSkies.kt | 9 ++- .../api/WaypointRenderPipeline.kt | 40 ++++++++++++ .../partlysaneskies/api/events/PSSEvent.kt | 4 +- .../partlysaneskies/config/Keybinds.kt | 2 +- .../partlysaneskies/data/cache/PetData.kt | 6 +- .../data/pssdata/PublicDataManager.kt | 2 +- .../data/skyblockdata/SkyblockDataManager.kt | 6 +- .../partlysaneskies/events/EventManager.kt | 58 +++++------------- .../events/SubscribePSSEvent.kt | 10 --- .../events/data/LoadPublicDataEvent.kt | 26 +------- .../events/minecraft/PSSChatEvent.kt | 21 +++---- .../events/minecraft/TablistUpdateEvent.kt | 16 +---- .../minecraft/player/PlayerBreakBlockEvent.kt | 25 +------- .../minecraft/render/RenderWaypointEvent.kt | 61 +++---------------- .../skyblock/dungeons/DungeonEndEvent.kt | 23 +++---- .../skyblock/dungeons/DungeonStartEvent.kt | 21 +------ .../events/skyblock/mining/MinesEvent.kt | 23 +------ .../features/debug/DebugKey.kt | 6 +- .../features/dungeons/AutoGG.kt | 13 ++-- .../features/dungeons/ItemRefill.kt | 6 +- .../features/dungeons/PlayerRating.kt | 10 +-- .../features/dungeons/RequiredSecretsFound.kt | 8 +-- .../features/dungeons/TerminalWaypoints.kt | 8 +-- .../features/dungeons/WatcherReady.kt | 4 +- .../farming/MathematicalHoeRightClicks.kt | 6 +- .../features/farming/WrongToolCropWarning.kt | 9 ++- .../features/farming/garden/CompostValue.kt | 4 +- .../farming/garden/CropMilestoneWebhook.kt | 4 +- .../features/farming/garden/SkymartValue.kt | 4 +- .../foraging/TreecapitatorCooldown.kt | 4 +- .../features/gui/hud/DropBannerDisplay.kt | 6 +- .../features/information/WikiArticleOpener.kt | 4 +- .../features/mining/PickaxeWarning.kt | 33 +++++----- .../mining/crystalhollows/WormWarning.kt | 4 +- .../gemstonewaypoints/GemstoneData.kt | 4 +- .../GemstoneWaypointRender.kt | 4 +- .../mining/events/MiningEventNotifier.kt | 15 ++++- .../features/skills/BestiaryLevelUpWebhook.kt | 4 +- .../skills/BestiaryMilestoneWebhook.kt | 4 +- .../features/skills/PetLevelUpWebhook.kt | 4 +- .../features/skills/SkillUpgradeWebhook.kt | 4 +- .../partlysaneskies/utils/HypixelUtils.kt | 4 +- 46 files changed, 225 insertions(+), 359 deletions(-) create mode 100644 src/main/kotlin/me/partlysanestudios/partlysaneskies/api/WaypointRenderPipeline.kt delete mode 100644 src/main/kotlin/me/partlysanestudios/partlysaneskies/events/SubscribePSSEvent.kt diff --git a/src/main/java/me/partlysanestudios/partlysaneskies/features/dungeons/party/PartyFriendManager.java b/src/main/java/me/partlysanestudios/partlysaneskies/features/dungeons/party/PartyFriendManager.java index b484a959d..dad68ea95 100644 --- a/src/main/java/me/partlysanestudios/partlysaneskies/features/dungeons/party/PartyFriendManager.java +++ b/src/main/java/me/partlysanestudios/partlysaneskies/features/dungeons/party/PartyFriendManager.java @@ -6,8 +6,8 @@ package me.partlysanestudios.partlysaneskies.features.dungeons.party; import me.partlysanestudios.partlysaneskies.PartlySaneSkies; +import me.partlysanestudios.partlysaneskies.api.events.PSSEvent; import me.partlysanestudios.partlysaneskies.commands.PSSCommand; -import me.partlysanestudios.partlysaneskies.events.SubscribePSSEvent; import me.partlysanestudios.partlysaneskies.events.minecraft.PSSChatEvent; import me.partlysanestudios.partlysaneskies.utils.StringUtils; @@ -57,7 +57,7 @@ public static void partyAll() { } } - @SubscribePSSEvent + @PSSEvent.Subscribe public void onChat(PSSChatEvent event) { if (!isWaitingForMembers) { return; diff --git a/src/main/java/me/partlysanestudios/partlysaneskies/features/dungeons/party/partymanager/PartyManager.java b/src/main/java/me/partlysanestudios/partlysaneskies/features/dungeons/party/partymanager/PartyManager.java index b31a1adcf..48cfbfde1 100644 --- a/src/main/java/me/partlysanestudios/partlysaneskies/features/dungeons/party/partymanager/PartyManager.java +++ b/src/main/java/me/partlysanestudios/partlysaneskies/features/dungeons/party/partymanager/PartyManager.java @@ -6,13 +6,11 @@ package me.partlysanestudios.partlysaneskies.features.dungeons.party.partymanager; import me.partlysanestudios.partlysaneskies.PartlySaneSkies; +import me.partlysanestudios.partlysaneskies.api.events.PSSEvent; import me.partlysanestudios.partlysaneskies.commands.PSSCommand; -import me.partlysanestudios.partlysaneskies.events.SubscribePSSEvent; import me.partlysanestudios.partlysaneskies.events.minecraft.PSSChatEvent; import me.partlysanestudios.partlysaneskies.utils.ChatUtils; import me.partlysanestudios.partlysaneskies.utils.StringUtils; -import net.minecraftforge.client.event.ClientChatReceivedEvent; -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import java.io.IOException; import java.net.MalformedURLException; @@ -165,7 +163,7 @@ public static void reparty(List partyMembers) { } } - @SubscribePSSEvent + @PSSEvent.Subscribe public void onChatMemberJoin(PSSChatEvent event) { if (!PartlySaneSkies.Companion.getConfig().getGetDataOnJoin()) { return; @@ -192,20 +190,20 @@ public void onChatMemberJoin(PSSChatEvent event) { } // Upon chat message receives, it will check to see if it is the party list - @SubscribeEvent - public void getMembers(ClientChatReceivedEvent event) { + @PSSEvent.Subscribe + public void getMembers(PSSChatEvent event) { // If it's not waiting for party members, it returns if (!isWaitingForMembers) { return; } // If the message says "leader" - if (event.message.getUnformattedText().startsWith("Party Leader: ")) { + if (event.getComponent().getUnformattedText().startsWith("Party Leader: ")) { // Hides the message - event.setCanceled(true); + event.cancel(); // Gets the message contents - String text = event.message.getUnformattedText(); + String text = event.getComponent().getUnformattedText(); // Removes the header text = text.replace("Party Leader: ", ""); // Processes the list @@ -213,10 +211,10 @@ public void getMembers(ClientChatReceivedEvent event) { } // If the message says "Party Moderators: " - else if (event.message.getUnformattedText().startsWith("Party Moderators: ")) { + else if (event.getComponent().getUnformattedText().startsWith("Party Moderators: ")) { // Hides the message - event.setCanceled(true); - String text = event.message.getUnformattedText(); + event.cancel(); + String text = event.getComponent().getUnformattedText(); // Removes the header text = text.replace("Party Moderators: ", ""); @@ -224,12 +222,12 @@ else if (event.message.getUnformattedText().startsWith("Party Moderators: ")) { } // If the message says "Party Members: " - else if (event.message.getUnformattedText().startsWith("Party Members: ")) { + else if (event.getComponent().getUnformattedText().startsWith("Party Members: ")) { // Hides the message - event.setCanceled(true); + event.cancel(); // Gets the message contents - String text = event.message.getUnformattedText(); + String text = event.getComponent().getUnformattedText(); // Removes the header text = text.replace("Party Members: ", ""); // Processes the list @@ -237,15 +235,15 @@ else if (event.message.getUnformattedText().startsWith("Party Members: ")) { } // Hides the beginning of the "Party Members" list - else if (event.message.getUnformattedText().startsWith("Party Members (")) { - event.setCanceled(true); + else if (event.getComponent().getUnformattedText().startsWith("Party Members (")) { + event.cancel(); } // Detects the closing line ----- // when all the members have been listed and the bar appears, its end of the message - else if (isMembersListed && event.message.getUnformattedText().startsWith("-----------------------------------------------------")) { + else if (isMembersListed && event.getComponent().getUnformattedText().startsWith("-----------------------------------------------------")) { // Hides the message - event.setCanceled(true); + event.cancel(); // Resets isMembersListed = false; isWaitingForMembers = false; @@ -254,14 +252,14 @@ else if (isMembersListed && event.message.getUnformattedText().startsWith("----- } // Hides the --------------------- - else if (event.message.getUnformattedText().startsWith("-----------------------------------------------------")) { - event.setCanceled(true); + else if (event.getComponent().getUnformattedText().startsWith("-----------------------------------------------------")) { + event.cancel(); } // If the player is not in the party - else if (event.message.getUnformattedText().startsWith("You are not currently in a party.")) { + else if (event.getComponent().getUnformattedText().startsWith("You are not currently in a party.")) { // Hides message - event.setCanceled(true); + event.cancel(); // Sends an error message ChatUtils.INSTANCE.sendClientMessage(("§9§m-----------------------------------------------------\n " + "§r§cError: Could not run Party Manager." + diff --git a/src/main/java/me/partlysanestudios/partlysaneskies/features/economy/minioncalculator/MinionData.java b/src/main/java/me/partlysanestudios/partlysaneskies/features/economy/minioncalculator/MinionData.java index a2c454469..86e23449b 100644 --- a/src/main/java/me/partlysanestudios/partlysaneskies/features/economy/minioncalculator/MinionData.java +++ b/src/main/java/me/partlysanestudios/partlysaneskies/features/economy/minioncalculator/MinionData.java @@ -8,9 +8,9 @@ import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParser; +import me.partlysanestudios.partlysaneskies.api.events.PSSEvent; import me.partlysanestudios.partlysaneskies.data.pssdata.PublicDataManager; import me.partlysanestudios.partlysaneskies.data.skyblockdata.SkyblockDataManager; -import me.partlysanestudios.partlysaneskies.events.SubscribePSSEvent; import me.partlysanestudios.partlysaneskies.events.data.LoadPublicDataEvent; import me.partlysanestudios.partlysaneskies.utils.MathUtils; import me.partlysanestudios.partlysaneskies.utils.StringUtils; @@ -81,7 +81,7 @@ public static LinkedHashMap sortMap(HashMap map) } // Runs after the request - @SubscribePSSEvent + @PSSEvent.Subscribe public void init(LoadPublicDataEvent event) { String str = PublicDataManager.INSTANCE.getFile(MINIONS_DATA_URL); // Creates a json object from the request response diff --git a/src/main/java/me/partlysanestudios/partlysaneskies/mixin/minecraft/MixinPlayerControllerMP.java b/src/main/java/me/partlysanestudios/partlysaneskies/mixin/minecraft/MixinPlayerControllerMP.java index cbce57368..f71ee1e2c 100644 --- a/src/main/java/me/partlysanestudios/partlysaneskies/mixin/minecraft/MixinPlayerControllerMP.java +++ b/src/main/java/me/partlysanestudios/partlysaneskies/mixin/minecraft/MixinPlayerControllerMP.java @@ -6,6 +6,7 @@ package me.partlysanestudios.partlysaneskies.mixin.minecraft; import me.partlysanestudios.partlysaneskies.events.minecraft.player.PlayerBreakBlockEvent; +import me.partlysanestudios.partlysaneskies.utils.geometry.vectors.Point3d; import net.minecraft.client.multiplayer.PlayerControllerMP; import net.minecraft.util.BlockPos; import net.minecraft.util.EnumFacing; @@ -19,6 +20,6 @@ public class MixinPlayerControllerMP { @Inject(method = "onPlayerDestroyBlock", at = @At("HEAD")) private void onPlayerDestroyBlock(BlockPos pos, EnumFacing side, CallbackInfoReturnable cir) { - PlayerBreakBlockEvent.Companion.onPlayerBreakBlock$Partly_Sane_Skies(pos, side); + new PlayerBreakBlockEvent(Point3d.Companion.toPoint3d(pos), side).post(); } } diff --git a/src/main/kotlin/me/partlysanestudios/partlysaneskies/PartlySaneSkies.kt b/src/main/kotlin/me/partlysanestudios/partlysaneskies/PartlySaneSkies.kt index 2f8e5a5be..932113eed 100644 --- a/src/main/kotlin/me/partlysanestudios/partlysaneskies/PartlySaneSkies.kt +++ b/src/main/kotlin/me/partlysanestudios/partlysaneskies/PartlySaneSkies.kt @@ -20,6 +20,7 @@ package me.partlysanestudios.partlysaneskies import com.google.gson.JsonObject import com.google.gson.JsonParser +import me.partlysanestudios.partlysaneskies.api.events.PSSEvent import me.partlysanestudios.partlysaneskies.api.events.PSSEvents import me.partlysanestudios.partlysaneskies.config.Keybinds import me.partlysanestudios.partlysaneskies.config.OneConfigScreen @@ -34,7 +35,6 @@ import me.partlysanestudios.partlysaneskies.data.cache.VisitorLogbookData import me.partlysanestudios.partlysaneskies.data.pssdata.PublicDataManager import me.partlysanestudios.partlysaneskies.data.skyblockdata.SkyblockDataManager import me.partlysanestudios.partlysaneskies.events.EventManager -import me.partlysanestudios.partlysaneskies.events.SubscribePSSEvent import me.partlysanestudios.partlysaneskies.events.data.LoadPublicDataEvent import me.partlysanestudios.partlysaneskies.features.chat.ChatAlertsManager import me.partlysanestudios.partlysaneskies.features.chat.ChatManager @@ -352,7 +352,7 @@ class PartlySaneSkies { } catch (e: IOException) { e.printStackTrace() } - LoadPublicDataEvent.onDataLoad() + LoadPublicDataEvent().post() // Loads user player data for PartyManager Thread( @@ -379,7 +379,6 @@ class PartlySaneSkies { private fun registerEvent(obj: Any) { runCatching { EVENT_BUS.register(obj) }.onFailure { it.printStackTrace() } - runCatching { EventManager.register(obj) }.onFailure { it.printStackTrace() } runCatching { PSSEvents.register(obj) }.onFailure { it.printStackTrace() } } @@ -401,7 +400,7 @@ class PartlySaneSkies { EventManager.tick() } - @SubscribePSSEvent + @PSSEvent.Subscribe fun loadMainMenuJson(event: LoadPublicDataEvent) { val data = PublicDataManager.getFile("main_menu.json") val jsonObj = JsonParser().parse(data).asJsonObject @@ -454,7 +453,7 @@ class PartlySaneSkies { } @SubscribeEvent - fun onClientConnectedToServer(event: ClientConnectedToServerEvent?) { + fun onClientConnectedToServer(event: ClientConnectedToServerEvent) { if (DOGFOOD) { Thread { try { diff --git a/src/main/kotlin/me/partlysanestudios/partlysaneskies/api/WaypointRenderPipeline.kt b/src/main/kotlin/me/partlysanestudios/partlysaneskies/api/WaypointRenderPipeline.kt new file mode 100644 index 000000000..a0e123607 --- /dev/null +++ b/src/main/kotlin/me/partlysanestudios/partlysaneskies/api/WaypointRenderPipeline.kt @@ -0,0 +1,40 @@ +// +// Written by Su386. +// See LICENSE for copyright and license notices. +// + +package me.partlysanestudios.partlysaneskies.api + +import me.partlysanestudios.partlysaneskies.render.waypoint.Waypoint +import me.partlysanestudios.partlysaneskies.utils.geometry.vectors.Point3d.Companion.toPoint3d +import net.minecraft.client.Minecraft + +class WaypointRenderPipeline { + private val waypointsToRender = ArrayList() + + /** + * Adds a waypoint to the render pipeline + * + * @param waypoint the waypoint to be rendered + */ + fun add(waypoint: Waypoint) { + waypointsToRender.add(waypoint) + } + + // Written partially by j10a1n15 + /** + * Renders all the waypoints in the pipeline + * + * @param partialTicks the amount of partial ticks since the last frame that rendered + */ + internal fun renderAll(partialTicks: Float) { + val mc = Minecraft.getMinecraft() + + for (waypoint in waypointsToRender) { + val waypointPos = waypoint.position.toPoint3d() + val distance = waypointPos.distanceToPlayer() + + waypoint.render(distance) + } + } +} diff --git a/src/main/kotlin/me/partlysanestudios/partlysaneskies/api/events/PSSEvent.kt b/src/main/kotlin/me/partlysanestudios/partlysaneskies/api/events/PSSEvent.kt index 4b8befe4b..4978f6ae5 100644 --- a/src/main/kotlin/me/partlysanestudios/partlysaneskies/api/events/PSSEvent.kt +++ b/src/main/kotlin/me/partlysanestudios/partlysaneskies/api/events/PSSEvent.kt @@ -10,12 +10,12 @@ abstract class PSSEvent protected constructor() { var isCancelled = false private set - fun post() { + open fun post(): Boolean { PSSEvents.post(this) + return isCancelled } interface Cancellable { - fun cancel() { (this as PSSEvent).isCancelled = true } diff --git a/src/main/kotlin/me/partlysanestudios/partlysaneskies/config/Keybinds.kt b/src/main/kotlin/me/partlysanestudios/partlysaneskies/config/Keybinds.kt index 225e6b89f..44236e713 100644 --- a/src/main/kotlin/me/partlysanestudios/partlysaneskies/config/Keybinds.kt +++ b/src/main/kotlin/me/partlysanestudios/partlysaneskies/config/Keybinds.kt @@ -62,7 +62,7 @@ object Keybinds { } @SubscribeEvent - fun checkKeyBinds(event: InputEvent.KeyInputEvent?) { + fun checkKeyBinds(event: InputEvent.KeyInputEvent) { if (OneConfigScreen.debugKeybind.isActive()) { onDebugKeyPress() } diff --git a/src/main/kotlin/me/partlysanestudios/partlysaneskies/data/cache/PetData.kt b/src/main/kotlin/me/partlysanestudios/partlysaneskies/data/cache/PetData.kt index 3e269c62a..81578cf4c 100644 --- a/src/main/kotlin/me/partlysanestudios/partlysaneskies/data/cache/PetData.kt +++ b/src/main/kotlin/me/partlysanestudios/partlysaneskies/data/cache/PetData.kt @@ -9,9 +9,9 @@ import com.google.gson.Gson import com.google.gson.GsonBuilder import com.google.gson.annotations.Expose import me.partlysanestudios.partlysaneskies.PartlySaneSkies +import me.partlysanestudios.partlysaneskies.api.events.PSSEvent import me.partlysanestudios.partlysaneskies.data.skyblockdata.Rarity import me.partlysanestudios.partlysaneskies.data.skyblockdata.Rarity.Companion.getRarityFromColorCode -import me.partlysanestudios.partlysaneskies.events.SubscribePSSEvent import me.partlysanestudios.partlysaneskies.events.minecraft.PSSChatEvent import me.partlysanestudios.partlysaneskies.events.minecraft.TablistUpdateEvent import me.partlysanestudios.partlysaneskies.utils.MathUtils @@ -107,7 +107,7 @@ object PetData { */ fun getCurrentPetRarity() = petDataJson?.currentPetRarity ?: Rarity.UNKNOWN - @SubscribePSSEvent + @PSSEvent.Subscribe fun onChat(event: PSSChatEvent) { // Parse despawn message if (event.component.unformattedText.startsWith("You despawned your")) { @@ -163,7 +163,7 @@ object PetData { } } - @SubscribePSSEvent + @PSSEvent.Subscribe fun parsePetFromTablist(event: TablistUpdateEvent) { val pet = event.list.nextAfter("§e§lPet:")?.removeResets()?.trim() ?: return diff --git a/src/main/kotlin/me/partlysanestudios/partlysaneskies/data/pssdata/PublicDataManager.kt b/src/main/kotlin/me/partlysanestudios/partlysaneskies/data/pssdata/PublicDataManager.kt index eb0877945..7957c4cb3 100644 --- a/src/main/kotlin/me/partlysanestudios/partlysaneskies/data/pssdata/PublicDataManager.kt +++ b/src/main/kotlin/me/partlysanestudios/partlysaneskies/data/pssdata/PublicDataManager.kt @@ -110,7 +110,7 @@ object PublicDataManager { ) fileCache.clear() sendClientMessage(chatcomponent) - LoadPublicDataEvent.onDataLoad() + LoadPublicDataEvent().post() }.register() } diff --git a/src/main/kotlin/me/partlysanestudios/partlysaneskies/data/skyblockdata/SkyblockDataManager.kt b/src/main/kotlin/me/partlysanestudios/partlysaneskies/data/skyblockdata/SkyblockDataManager.kt index c1f83656c..5af428dba 100644 --- a/src/main/kotlin/me/partlysanestudios/partlysaneskies/data/skyblockdata/SkyblockDataManager.kt +++ b/src/main/kotlin/me/partlysanestudios/partlysaneskies/data/skyblockdata/SkyblockDataManager.kt @@ -8,20 +8,20 @@ package me.partlysanestudios.partlysaneskies.data.skyblockdata import com.google.gson.JsonParser import me.partlysanestudios.partlysaneskies.PartlySaneSkies.Companion.config import me.partlysanestudios.partlysaneskies.PartlySaneSkies.Companion.time +import me.partlysanestudios.partlysaneskies.api.events.PSSEvent import me.partlysanestudios.partlysaneskies.data.api.GetRequest import me.partlysanestudios.partlysaneskies.data.api.Request import me.partlysanestudios.partlysaneskies.data.api.RequestRunnable import me.partlysanestudios.partlysaneskies.data.api.RequestsManager.newRequest import me.partlysanestudios.partlysaneskies.data.pssdata.PublicDataManager.getFile -import me.partlysanestudios.partlysaneskies.events.SubscribePSSEvent import me.partlysanestudios.partlysaneskies.events.data.LoadPublicDataEvent import me.partlysanestudios.partlysaneskies.utils.StringUtils.removeColorCodes import java.io.IOException import java.net.MalformedURLException object SkyblockDataManager { - @SubscribePSSEvent - fun onDataLoad(event: LoadPublicDataEvent?) { + @PSSEvent.Subscribe + fun onDataLoad(event: LoadPublicDataEvent) { try { initBitValues() } catch (e: IOException) { diff --git a/src/main/kotlin/me/partlysanestudios/partlysaneskies/events/EventManager.kt b/src/main/kotlin/me/partlysanestudios/partlysaneskies/events/EventManager.kt index 87b374f33..20f6d523a 100644 --- a/src/main/kotlin/me/partlysanestudios/partlysaneskies/events/EventManager.kt +++ b/src/main/kotlin/me/partlysanestudios/partlysaneskies/events/EventManager.kt @@ -5,83 +5,55 @@ package me.partlysanestudios.partlysaneskies.events +import me.partlysanestudios.partlysaneskies.api.WaypointRenderPipeline +import me.partlysanestudios.partlysaneskies.api.events.PSSEvent +import me.partlysanestudios.partlysaneskies.data.skyblockdata.IslandType import me.partlysanestudios.partlysaneskies.events.minecraft.PSSChatEvent import me.partlysanestudios.partlysaneskies.events.minecraft.TablistUpdateEvent import me.partlysanestudios.partlysaneskies.events.minecraft.render.RenderWaypointEvent import me.partlysanestudios.partlysaneskies.events.skyblock.dungeons.DungeonEndEvent import me.partlysanestudios.partlysaneskies.events.skyblock.dungeons.DungeonStartEvent -import me.partlysanestudios.partlysaneskies.events.skyblock.mining.MinesEvent import me.partlysanestudios.partlysaneskies.utils.MinecraftUtils -import me.partlysanestudios.partlysaneskies.utils.SystemUtils.log import net.minecraftforge.client.event.ClientChatReceivedEvent import net.minecraftforge.client.event.RenderWorldLastEvent import net.minecraftforge.fml.common.eventhandler.EventPriority import net.minecraftforge.fml.common.eventhandler.SubscribeEvent -import org.apache.logging.log4j.Level -import kotlin.reflect.KClass -import kotlin.reflect.KFunction -import kotlin.reflect.full.hasAnnotation -import kotlin.reflect.full.memberFunctions object EventManager { private var oldTablist = emptyList() - internal val registeredFunctions = HashMap, ArrayList>() - - fun register(obj: Any) { - val kClass = obj::class // get the class - for (function in kClass.memberFunctions) { // for each function in the class - if (!function.hasAnnotation()) { // if the functions are not annotated, continue - continue - } - - val functionParameters = function.parameters - if (functionParameters.size != 2) { // if there is not only 1 parameter (param 1 is always the instance parameter - log( - Level.WARN, - "Unable to add ${function.name} due to incorrect number of function parameters (${functionParameters.size}", - ) - continue - } - val paramClass = functionParameters[1].type.classifier as? KClass<*> ?: continue - - if (!registeredFunctions.containsKey(paramClass)) { - registeredFunctions[paramClass] = ArrayList() - } - registeredFunctions[paramClass]?.add(EventFunction(obj, function)) // adds the function to a list to call - log(Level.INFO, "Registered ${function.name} from ${obj.javaClass.name} in PSS events") - } - } - fun tick() { val tablist = MinecraftUtils.getTabList() if (tablist != oldTablist) { - TablistUpdateEvent.onUpdate(registeredFunctions[TablistUpdateEvent::class] ?: ArrayList(), tablist) + TablistUpdateEvent(tablist).post() oldTablist = tablist } } @SubscribeEvent fun onScreenRender(event: RenderWorldLastEvent) { - RenderWaypointEvent.onEventCall(event.partialTicks, registeredFunctions[RenderWaypointEvent::class] ?: ArrayList()) + RenderWaypointEvent(WaypointRenderPipeline(), event.partialTicks).post() } @SubscribeEvent(priority = EventPriority.HIGHEST) fun onChatReceivedEvent(event: ClientChatReceivedEvent) { if (event.type.toInt() != 0) return - PSSChatEvent.onMessageReceived(registeredFunctions[PSSChatEvent::class] ?: ArrayList(), event.message) + if (PSSChatEvent(event.message.formattedText, event.message).post()) { + event.isCanceled = true + } } - @SubscribePSSEvent + @PSSEvent.Subscribe fun onChat(event: PSSChatEvent) { val message = event.message - DungeonStartEvent.onMessageReceived(registeredFunctions[DungeonStartEvent::class] ?: ArrayList(), message) - DungeonEndEvent.onMessageReceived(registeredFunctions[DungeonEndEvent::class] ?: ArrayList(), message) - MinesEvent.onMessageReceived(registeredFunctions[MinesEvent::class] ?: ArrayList(), message) + if (message.contains("Starting in 1 second.") && IslandType.CATACOMBS.onIsland()) { + DungeonStartEvent().post() + } + if (message.contains("§r§c☠ §r§eDefeated §r")) { + DungeonEndEvent().post() + } } - - internal class EventFunction(val obj: Any, val function: KFunction<*>) } diff --git a/src/main/kotlin/me/partlysanestudios/partlysaneskies/events/SubscribePSSEvent.kt b/src/main/kotlin/me/partlysanestudios/partlysaneskies/events/SubscribePSSEvent.kt deleted file mode 100644 index 0fd52b712..000000000 --- a/src/main/kotlin/me/partlysanestudios/partlysaneskies/events/SubscribePSSEvent.kt +++ /dev/null @@ -1,10 +0,0 @@ -// -// Written by Su386. -// See LICENSE for copyright and license notices. -// - -package me.partlysanestudios.partlysaneskies.events - -@Retention(AnnotationRetention.RUNTIME) -@Target(AnnotationTarget.FUNCTION) -annotation class SubscribePSSEvent diff --git a/src/main/kotlin/me/partlysanestudios/partlysaneskies/events/data/LoadPublicDataEvent.kt b/src/main/kotlin/me/partlysanestudios/partlysaneskies/events/data/LoadPublicDataEvent.kt index 0de34ffbc..d5e6bbfc6 100644 --- a/src/main/kotlin/me/partlysanestudios/partlysaneskies/events/data/LoadPublicDataEvent.kt +++ b/src/main/kotlin/me/partlysanestudios/partlysaneskies/events/data/LoadPublicDataEvent.kt @@ -5,28 +5,6 @@ package me.partlysanestudios.partlysaneskies.events.data -import me.partlysanestudios.partlysaneskies.events.EventManager -import me.partlysanestudios.partlysaneskies.utils.SystemUtils -import org.apache.logging.log4j.Level +import me.partlysanestudios.partlysaneskies.api.events.PSSEvent -class LoadPublicDataEvent { - companion object { - private fun callEvent(functions: List) { - Thread { - for (function in functions) { - try { - SystemUtils.log(Level.INFO, "Loading ${function.obj.javaClass.name} ${function.function.name}") - val event = LoadPublicDataEvent() - function.function.call(function.obj, event) - } catch (e: Exception) { - e.printStackTrace() - } - } - }.start() - } - - internal fun onDataLoad() { - callEvent(EventManager.registeredFunctions[LoadPublicDataEvent::class] ?: ArrayList()) - } - } -} +class LoadPublicDataEvent : PSSEvent() diff --git a/src/main/kotlin/me/partlysanestudios/partlysaneskies/events/minecraft/PSSChatEvent.kt b/src/main/kotlin/me/partlysanestudios/partlysaneskies/events/minecraft/PSSChatEvent.kt index e12db855f..760ed8aa4 100644 --- a/src/main/kotlin/me/partlysanestudios/partlysaneskies/events/minecraft/PSSChatEvent.kt +++ b/src/main/kotlin/me/partlysanestudios/partlysaneskies/events/minecraft/PSSChatEvent.kt @@ -1,18 +1,11 @@ +// +// Written by J10a1n15. +// See LICENSE for copyright and license notices. +// + package me.partlysanestudios.partlysaneskies.events.minecraft -import me.partlysanestudios.partlysaneskies.events.EventManager +import me.partlysanestudios.partlysaneskies.api.events.PSSEvent import net.minecraft.util.IChatComponent -class PSSChatEvent(val message: String, val component: IChatComponent) { - companion object { - internal fun onMessageReceived(functionList: List, component: IChatComponent) { - functionList.forEach { - try { - it.function.call(it.obj, PSSChatEvent(component.formattedText, component)) - } catch (exception: Exception) { - exception.printStackTrace() - } - } - } - } -} +class PSSChatEvent(val message: String, val component: IChatComponent) : PSSEvent(), PSSEvent.Cancellable diff --git a/src/main/kotlin/me/partlysanestudios/partlysaneskies/events/minecraft/TablistUpdateEvent.kt b/src/main/kotlin/me/partlysanestudios/partlysaneskies/events/minecraft/TablistUpdateEvent.kt index fa4442fce..b8222c219 100644 --- a/src/main/kotlin/me/partlysanestudios/partlysaneskies/events/minecraft/TablistUpdateEvent.kt +++ b/src/main/kotlin/me/partlysanestudios/partlysaneskies/events/minecraft/TablistUpdateEvent.kt @@ -1,17 +1,5 @@ package me.partlysanestudios.partlysaneskies.events.minecraft -import me.partlysanestudios.partlysaneskies.events.EventManager +import me.partlysanestudios.partlysaneskies.api.events.PSSEvent -class TablistUpdateEvent(val list: List) { - companion object { - internal fun onUpdate(functionList: List, list: List) { - functionList.forEach { - try { - it.function.call(it.obj, TablistUpdateEvent(list)) - } catch (exception: Exception) { - exception.printStackTrace() - } - } - } - } -} +class TablistUpdateEvent(val list: List) : PSSEvent() diff --git a/src/main/kotlin/me/partlysanestudios/partlysaneskies/events/minecraft/player/PlayerBreakBlockEvent.kt b/src/main/kotlin/me/partlysanestudios/partlysaneskies/events/minecraft/player/PlayerBreakBlockEvent.kt index 022589bb3..e6646f33c 100644 --- a/src/main/kotlin/me/partlysanestudios/partlysaneskies/events/minecraft/player/PlayerBreakBlockEvent.kt +++ b/src/main/kotlin/me/partlysanestudios/partlysaneskies/events/minecraft/player/PlayerBreakBlockEvent.kt @@ -5,29 +5,8 @@ package me.partlysanestudios.partlysaneskies.events.minecraft.player -import me.partlysanestudios.partlysaneskies.events.EventManager +import me.partlysanestudios.partlysaneskies.api.events.PSSEvent import me.partlysanestudios.partlysaneskies.utils.geometry.vectors.Point3d -import me.partlysanestudios.partlysaneskies.utils.geometry.vectors.Point3d.Companion.toPoint3d -import net.minecraft.util.BlockPos import net.minecraft.util.EnumFacing -class PlayerBreakBlockEvent(val point: Point3d, val side: EnumFacing) { - companion object { - private fun callEvent(functions: List, pos: BlockPos, side: EnumFacing) { - for (function in functions) { - try { - val event = PlayerBreakBlockEvent(pos.toPoint3d(), side) - function.function.call(function.obj, event) - } catch (exception: Exception) { - exception.printStackTrace() - } - } - } - - // Called from the mixin because writing this code in java is about 50 times harder - // that's called a hook - internal fun onPlayerBreakBlock(blockPos: BlockPos, side: EnumFacing) { - callEvent(EventManager.registeredFunctions[PlayerBreakBlockEvent::class] ?: return, blockPos, side) - } - } -} +class PlayerBreakBlockEvent(val point: Point3d, val side: EnumFacing) : PSSEvent() diff --git a/src/main/kotlin/me/partlysanestudios/partlysaneskies/events/minecraft/render/RenderWaypointEvent.kt b/src/main/kotlin/me/partlysanestudios/partlysaneskies/events/minecraft/render/RenderWaypointEvent.kt index 309158837..22cc46106 100644 --- a/src/main/kotlin/me/partlysanestudios/partlysaneskies/events/minecraft/render/RenderWaypointEvent.kt +++ b/src/main/kotlin/me/partlysanestudios/partlysaneskies/events/minecraft/render/RenderWaypointEvent.kt @@ -5,57 +5,14 @@ package me.partlysanestudios.partlysaneskies.events.minecraft.render -import me.partlysanestudios.partlysaneskies.events.EventManager -import me.partlysanestudios.partlysaneskies.render.waypoint.Waypoint -import me.partlysanestudios.partlysaneskies.utils.geometry.vectors.Point3d.Companion.toPoint3d -import net.minecraft.client.Minecraft - -class RenderWaypointEvent(val pipeline: WaypointRenderPipeline) { - companion object { - internal fun onEventCall(partialTicks: Float, functions: List) { - val pipeline = WaypointRenderPipeline() - - for (function in functions) { - val event = RenderWaypointEvent(pipeline) - try { - function.function.call(function.obj, event) - } catch (exception: Exception) { - exception.printStackTrace() - } - } - - pipeline.renderAll(partialTicks) - } - } - - class WaypointRenderPipeline { - private val waypointsToRender = ArrayList() - - /** - * Adds a waypoint to the render pipeline - * - * @param waypoint the waypoint to be rendered - */ - fun add(waypoint: Waypoint) { - waypointsToRender.add(waypoint) - } - - // Written partially by j10a1n15 - - /** - * Renders all the waypoints in the pipeline - * - * @param partialTicks the amount of partial ticks since the last frame that rendered - */ - internal fun renderAll(partialTicks: Float) { - val mc = Minecraft.getMinecraft() - - for (waypoint in waypointsToRender) { - val waypointPos = waypoint.position.toPoint3d() - val distance = waypointPos.distanceToPlayer() - - waypoint.render(distance) - } - } +import me.partlysanestudios.partlysaneskies.api.WaypointRenderPipeline +import me.partlysanestudios.partlysaneskies.api.events.PSSEvent + +class RenderWaypointEvent(val pipeline: WaypointRenderPipeline, private val partialTicks: Float) : PSSEvent() { + override fun post(): Boolean { + super.post() + pipeline.renderAll(partialTicks) + return isCancelled } } + diff --git a/src/main/kotlin/me/partlysanestudios/partlysaneskies/events/skyblock/dungeons/DungeonEndEvent.kt b/src/main/kotlin/me/partlysanestudios/partlysaneskies/events/skyblock/dungeons/DungeonEndEvent.kt index cf213ccf5..9ae4cb378 100644 --- a/src/main/kotlin/me/partlysanestudios/partlysaneskies/events/skyblock/dungeons/DungeonEndEvent.kt +++ b/src/main/kotlin/me/partlysanestudios/partlysaneskies/events/skyblock/dungeons/DungeonEndEvent.kt @@ -1,19 +1,10 @@ +// +// Written by Su386. +// See LICENSE for copyright and license notices. +// + package me.partlysanestudios.partlysaneskies.events.skyblock.dungeons -import me.partlysanestudios.partlysaneskies.events.EventManager +import me.partlysanestudios.partlysaneskies.api.events.PSSEvent -class DungeonEndEvent { - companion object { - internal fun onMessageReceived(functionList: List, formattedMessage: String) { - if (formattedMessage.contains("§r§c☠ §r§eDefeated §r")) { - for (function in functionList) { - try { - function.function.call(function.obj, DungeonEndEvent()) - } catch (exception: Exception) { - exception.printStackTrace() - } - } - } - } - } -} +class DungeonEndEvent : PSSEvent() diff --git a/src/main/kotlin/me/partlysanestudios/partlysaneskies/events/skyblock/dungeons/DungeonStartEvent.kt b/src/main/kotlin/me/partlysanestudios/partlysaneskies/events/skyblock/dungeons/DungeonStartEvent.kt index 75ffee5c8..5b29d7967 100644 --- a/src/main/kotlin/me/partlysanestudios/partlysaneskies/events/skyblock/dungeons/DungeonStartEvent.kt +++ b/src/main/kotlin/me/partlysanestudios/partlysaneskies/events/skyblock/dungeons/DungeonStartEvent.kt @@ -5,23 +5,6 @@ package me.partlysanestudios.partlysaneskies.events.skyblock.dungeons -import me.partlysanestudios.partlysaneskies.data.skyblockdata.IslandType -import me.partlysanestudios.partlysaneskies.events.EventManager -import me.partlysanestudios.partlysaneskies.utils.StringUtils.removeColorCodes +import me.partlysanestudios.partlysaneskies.api.events.PSSEvent -class DungeonStartEvent { - companion object { - internal fun onMessageReceived(functionList: List, formattedMessage: String) { - val message = formattedMessage.removeColorCodes() - if (message.contains("Starting in 1 second.") && IslandType.CATACOMBS.onIsland()) { - for (function in functionList) { - try { - function.function.call(function.obj, DungeonStartEvent()) - } catch (exception: Exception) { - exception.printStackTrace() - } - } - } - } - } -} +class DungeonStartEvent : PSSEvent() diff --git a/src/main/kotlin/me/partlysanestudios/partlysaneskies/events/skyblock/mining/MinesEvent.kt b/src/main/kotlin/me/partlysanestudios/partlysaneskies/events/skyblock/mining/MinesEvent.kt index 171902cfc..9e8502613 100644 --- a/src/main/kotlin/me/partlysanestudios/partlysaneskies/events/skyblock/mining/MinesEvent.kt +++ b/src/main/kotlin/me/partlysanestudios/partlysaneskies/events/skyblock/mining/MinesEvent.kt @@ -6,26 +6,7 @@ package me.partlysanestudios.partlysaneskies.events.skyblock.mining -import me.partlysanestudios.partlysaneskies.events.EventManager +import me.partlysanestudios.partlysaneskies.api.events.PSSEvent import me.partlysanestudios.partlysaneskies.features.mining.events.MiningEvent -import me.partlysanestudios.partlysaneskies.utils.HypixelUtils.inAdvancedMiningIsland -class MinesEvent(val miningEvent: MiningEvent) { - companion object { - internal fun onMessageReceived(functionList: List, formattedMessage: String) { - if (!inAdvancedMiningIsland()) return - - MiningEvent.entries - .firstOrNull { it.triggeredEvent(formattedMessage) } - ?.let { event -> - for (function in functionList) { - try { - function.function.call(function.obj, MinesEvent(event)) - } catch (e: Exception) { - e.printStackTrace() - } - } - } - } - } -} +class MinesEvent(val miningEvent: MiningEvent) : PSSEvent() diff --git a/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/debug/DebugKey.kt b/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/debug/DebugKey.kt index 71053fed9..3b25a6789 100644 --- a/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/debug/DebugKey.kt +++ b/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/debug/DebugKey.kt @@ -12,9 +12,9 @@ import gg.essential.universal.UResolution import me.partlysanestudios.partlysaneskies.PartlySaneSkies.Companion.config import me.partlysanestudios.partlysaneskies.PartlySaneSkies.Companion.minecraft import me.partlysanestudios.partlysaneskies.PartlySaneSkies.Companion.time +import me.partlysanestudios.partlysaneskies.api.events.PSSEvent import me.partlysanestudios.partlysaneskies.data.cache.StatsData import me.partlysanestudios.partlysaneskies.data.skyblockdata.Rarity -import me.partlysanestudios.partlysaneskies.events.SubscribePSSEvent import me.partlysanestudios.partlysaneskies.events.minecraft.PSSChatEvent import me.partlysanestudios.partlysaneskies.events.minecraft.render.RenderWaypointEvent import me.partlysanestudios.partlysaneskies.features.dungeons.PlayerRating @@ -148,7 +148,7 @@ object DebugKey { } // Runs chat analyzer for debug mode - @SubscribePSSEvent + @PSSEvent.Subscribe fun onChat(event: PSSChatEvent) { if (isDebugMode() && config.debugChatAnalyser) { log(Level.INFO, event.message) @@ -158,7 +158,7 @@ object DebugKey { private var waypointPoint = Point3d(0.0, 0.0, 0.0) - @SubscribePSSEvent + @PSSEvent.Subscribe fun onWaypointRender(event: RenderWaypointEvent) { if (isDebugMode() && config.debugSpawnWaypoint) { event.pipeline.add(Waypoint("Debug Waypoint", waypointPoint.toBlockPosInt())) diff --git a/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/dungeons/AutoGG.kt b/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/dungeons/AutoGG.kt index 88b336b98..fb7ea37bf 100644 --- a/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/dungeons/AutoGG.kt +++ b/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/dungeons/AutoGG.kt @@ -6,22 +6,23 @@ package me.partlysanestudios.partlysaneskies.features.dungeons import me.partlysanestudios.partlysaneskies.PartlySaneSkies -import me.partlysanestudios.partlysaneskies.events.SubscribePSSEvent +import me.partlysanestudios.partlysaneskies.api.events.PSSEvent import me.partlysanestudios.partlysaneskies.events.minecraft.PSSChatEvent import java.util.regex.Matcher import java.util.regex.Pattern object AutoGG { - @SubscribePSSEvent + @PSSEvent.Subscribe fun onChat(event: PSSChatEvent) { if (!PartlySaneSkies.config.autoGgEnabled) { return } if (event.message.contains("§r§fTeam Score:")) { - Thread({ - Thread.sleep((PartlySaneSkies.config.autoGGCooldown * 1000).toLong()) - val input = event.component.unformattedText - val regex = "\\((.*?)\\)" + Thread( + { + Thread.sleep((PartlySaneSkies.config.autoGGCooldown * 1000).toLong()) + val input = event.component.unformattedText + val regex = "\\((.*?)\\)" val pattern: Pattern = Pattern.compile(regex) val matcher: Matcher = pattern.matcher(input) diff --git a/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/dungeons/ItemRefill.kt b/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/dungeons/ItemRefill.kt index cb7010f97..98d4e0c4e 100644 --- a/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/dungeons/ItemRefill.kt +++ b/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/dungeons/ItemRefill.kt @@ -7,9 +7,9 @@ package me.partlysanestudios.partlysaneskies.features.dungeons import me.partlysanestudios.partlysaneskies.PartlySaneSkies import me.partlysanestudios.partlysaneskies.PartlySaneSkies.Companion.config +import me.partlysanestudios.partlysaneskies.api.events.PSSEvent import me.partlysanestudios.partlysaneskies.commands.PSSCommand import me.partlysanestudios.partlysaneskies.data.skyblockdata.SkyblockDataManager -import me.partlysanestudios.partlysaneskies.events.SubscribePSSEvent import me.partlysanestudios.partlysaneskies.events.skyblock.dungeons.DungeonStartEvent import me.partlysanestudios.partlysaneskies.utils.ChatUtils import me.partlysanestudios.partlysaneskies.utils.MinecraftUtils.countItemInInventory @@ -18,7 +18,7 @@ import net.minecraftforge.fml.common.gameevent.InputEvent import java.util.Locale object ItemRefill { - @SubscribePSSEvent + @PSSEvent.Subscribe fun onDungeonStart(event: DungeonStartEvent) { if (!config.autoItemRefill) return runItemRefil() @@ -37,7 +37,7 @@ object ItemRefill { } @SubscribeEvent - fun checkKeyBinds(event: InputEvent.KeyInputEvent?) { + fun checkKeyBinds(event: InputEvent.KeyInputEvent) { if (config.itemRefillKeybind.isActive()) { runItemRefil() } diff --git a/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/dungeons/PlayerRating.kt b/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/dungeons/PlayerRating.kt index 7ff9a13a9..7f0640684 100644 --- a/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/dungeons/PlayerRating.kt +++ b/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/dungeons/PlayerRating.kt @@ -9,10 +9,10 @@ import com.google.gson.JsonParser import me.partlysanestudios.partlysaneskies.PartlySaneSkies.Companion.RANK_NAMES import me.partlysanestudios.partlysaneskies.PartlySaneSkies.Companion.config import me.partlysanestudios.partlysaneskies.PartlySaneSkies.Companion.minecraft +import me.partlysanestudios.partlysaneskies.api.events.PSSEvent import me.partlysanestudios.partlysaneskies.commands.PSSCommand import me.partlysanestudios.partlysaneskies.data.pssdata.PublicDataManager.getFile import me.partlysanestudios.partlysaneskies.data.skyblockdata.IslandType -import me.partlysanestudios.partlysaneskies.events.SubscribePSSEvent import me.partlysanestudios.partlysaneskies.events.data.LoadPublicDataEvent import me.partlysanestudios.partlysaneskies.events.minecraft.PSSChatEvent import me.partlysanestudios.partlysaneskies.events.skyblock.dungeons.DungeonEndEvent @@ -40,7 +40,7 @@ object PlayerRating { private var lastMessage = "" - @SubscribePSSEvent + @PSSEvent.Subscribe fun initPatterns(event: LoadPublicDataEvent) { currentPlayer = minecraft.session.username val str = getFile("constants/dungeon_player_rate_regex_strings.json") @@ -176,7 +176,7 @@ object PlayerRating { ) { reprintLastScore() }.register() } - @SubscribePSSEvent + @PSSEvent.Subscribe fun onDungeonStart(event: DungeonStartEvent) { if (!(config.dungeonPlayerBreakdown || config.dungeonSnitcher)) { return @@ -184,7 +184,7 @@ object PlayerRating { reset() } - @SubscribePSSEvent + @PSSEvent.Subscribe fun onDungeonEnd(event: DungeonEndEvent) { if (!(config.dungeonPlayerBreakdown || config.dungeonSnitcher)) { return @@ -225,7 +225,7 @@ object PlayerRating { reset() } - @SubscribePSSEvent + @PSSEvent.Subscribe fun onChatEvent(event: PSSChatEvent) { if (!(config.dungeonPlayerBreakdown || config.dungeonSnitcher)) { return diff --git a/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/dungeons/RequiredSecretsFound.kt b/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/dungeons/RequiredSecretsFound.kt index 3f891ea52..173e7e2be 100644 --- a/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/dungeons/RequiredSecretsFound.kt +++ b/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/dungeons/RequiredSecretsFound.kt @@ -7,8 +7,8 @@ package me.partlysanestudios.partlysaneskies.features.dungeons import me.partlysanestudios.partlysaneskies.PartlySaneSkies.Companion.config import me.partlysanestudios.partlysaneskies.PartlySaneSkies.Companion.minecraft +import me.partlysanestudios.partlysaneskies.api.events.PSSEvent import me.partlysanestudios.partlysaneskies.data.skyblockdata.IslandType -import me.partlysanestudios.partlysaneskies.events.SubscribePSSEvent import me.partlysanestudios.partlysaneskies.events.minecraft.TablistUpdateEvent import me.partlysanestudios.partlysaneskies.events.skyblock.dungeons.DungeonStartEvent import me.partlysanestudios.partlysaneskies.render.gui.hud.BannerRenderer.renderNewBanner @@ -21,12 +21,12 @@ import net.minecraft.util.ResourceLocation object RequiredSecretsFound { private var alreadySendThisRun = false - @SubscribePSSEvent - fun onDungeonStart(event: DungeonStartEvent?) { + @PSSEvent.Subscribe + fun onDungeonStart(event: DungeonStartEvent) { alreadySendThisRun = false } - @SubscribePSSEvent + @PSSEvent.Subscribe fun onTablistUpdate(event: TablistUpdateEvent) { if (!isSkyblock()) return if (!IslandType.CATACOMBS.onIsland()) return diff --git a/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/dungeons/TerminalWaypoints.kt b/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/dungeons/TerminalWaypoints.kt index 0e983648c..d811b2135 100644 --- a/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/dungeons/TerminalWaypoints.kt +++ b/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/dungeons/TerminalWaypoints.kt @@ -6,8 +6,8 @@ package me.partlysanestudios.partlysaneskies.features.dungeons import me.partlysanestudios.partlysaneskies.PartlySaneSkies.Companion.config +import me.partlysanestudios.partlysaneskies.api.events.PSSEvent import me.partlysanestudios.partlysaneskies.data.skyblockdata.IslandType -import me.partlysanestudios.partlysaneskies.events.SubscribePSSEvent import me.partlysanestudios.partlysaneskies.events.minecraft.render.RenderWaypointEvent import me.partlysanestudios.partlysaneskies.events.skyblock.dungeons.DungeonStartEvent import me.partlysanestudios.partlysaneskies.features.debug.DebugKey @@ -37,7 +37,7 @@ object TerminalWaypoints { log(INFO, cachedPuzzles.toString()) } - @SubscribePSSEvent + @PSSEvent.Subscribe fun onWaypointRender(event: RenderWaypointEvent) { if (!config.terminalWaypoints) { return @@ -85,8 +85,8 @@ object TerminalWaypoints { } } - @SubscribePSSEvent - fun onDungeonStart(event: DungeonStartEvent) { // Yes I wrote the entire event system just so that I wouldn't have to call a chat event here + @PSSEvent.Subscribe + fun onDungeonStart(event: DungeonStartEvent) { for (terminal in cachedPuzzles) { terminal.active = false } diff --git a/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/dungeons/WatcherReady.kt b/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/dungeons/WatcherReady.kt index 4f447cccd..9b617b5a4 100644 --- a/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/dungeons/WatcherReady.kt +++ b/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/dungeons/WatcherReady.kt @@ -7,7 +7,7 @@ package me.partlysanestudios.partlysaneskies.features.dungeons import me.partlysanestudios.partlysaneskies.PartlySaneSkies.Companion.config import me.partlysanestudios.partlysaneskies.PartlySaneSkies.Companion.minecraft -import me.partlysanestudios.partlysaneskies.events.SubscribePSSEvent +import me.partlysanestudios.partlysaneskies.api.events.PSSEvent import me.partlysanestudios.partlysaneskies.events.minecraft.PSSChatEvent import me.partlysanestudios.partlysaneskies.render.gui.hud.BannerRenderer.renderNewBanner import me.partlysanestudios.partlysaneskies.render.gui.hud.PSSBanner @@ -16,7 +16,7 @@ import net.minecraft.util.ResourceLocation object WatcherReady { - @SubscribePSSEvent + @PSSEvent.Subscribe fun onChat(event: PSSChatEvent) { if (event.component.unformattedText.startsWith("[BOSS] The Watcher: That will be enough for now.")) { if (config.watcherReadyBanner) { diff --git a/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/farming/MathematicalHoeRightClicks.kt b/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/farming/MathematicalHoeRightClicks.kt index 7f8c1bee9..a77a28b04 100644 --- a/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/farming/MathematicalHoeRightClicks.kt +++ b/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/farming/MathematicalHoeRightClicks.kt @@ -9,9 +9,9 @@ import me.partlysanestudios.partlysaneskies.PartlySaneSkies import me.partlysanestudios.partlysaneskies.PartlySaneSkies.Companion.config import me.partlysanestudios.partlysaneskies.PartlySaneSkies.Companion.minecraft import me.partlysanestudios.partlysaneskies.PartlySaneSkies.Companion.time +import me.partlysanestudios.partlysaneskies.api.events.PSSEvent import me.partlysanestudios.partlysaneskies.commands.PSSCommand import me.partlysanestudios.partlysaneskies.data.pssdata.PublicDataManager.getFile -import me.partlysanestudios.partlysaneskies.events.SubscribePSSEvent import me.partlysanestudios.partlysaneskies.events.data.LoadPublicDataEvent import me.partlysanestudios.partlysaneskies.utils.HypixelUtils.getItemId import me.partlysanestudios.partlysaneskies.utils.MathUtils.onCooldown @@ -26,8 +26,8 @@ object MathematicalHoeRightClicks { var lastAllowHoeRightClickTime: Long = 0 private val hoes = ArrayList() - @SubscribePSSEvent - fun loadHoes(event: LoadPublicDataEvent?) { + @PSSEvent.Subscribe + fun loadHoes(event: LoadPublicDataEvent) { val str = getFile("constants/mathematical_hoes.json") val array = JsonParser().parse(str).getAsJsonObject()["hoes"].getAsJsonArray() hoes.clear() diff --git a/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/farming/WrongToolCropWarning.kt b/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/farming/WrongToolCropWarning.kt index e42b5daab..0f530dfb5 100644 --- a/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/farming/WrongToolCropWarning.kt +++ b/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/farming/WrongToolCropWarning.kt @@ -10,9 +10,9 @@ import com.google.gson.JsonParser import me.partlysanestudios.partlysaneskies.PartlySaneSkies.Companion.config import me.partlysanestudios.partlysaneskies.PartlySaneSkies.Companion.minecraft import me.partlysanestudios.partlysaneskies.PartlySaneSkies.Companion.time +import me.partlysanestudios.partlysaneskies.api.events.PSSEvent import me.partlysanestudios.partlysaneskies.data.pssdata.PublicDataManager import me.partlysanestudios.partlysaneskies.data.skyblockdata.IslandType -import me.partlysanestudios.partlysaneskies.events.SubscribePSSEvent import me.partlysanestudios.partlysaneskies.events.data.LoadPublicDataEvent import me.partlysanestudios.partlysaneskies.events.minecraft.player.PlayerBreakBlockEvent import me.partlysanestudios.partlysaneskies.render.gui.hud.BannerRenderer.renderNewBanner @@ -28,7 +28,7 @@ import net.minecraft.util.ResourceLocation object WrongToolCropWarning { private var lastWarnTime = -1L - @SubscribePSSEvent + @PSSEvent.Subscribe fun onBlockBreak(event: PlayerBreakBlockEvent) { if (!config.wrongToolForCropEnabled) return if (onCooldown(lastWarnTime, (config.wrongToolForCropCooldown * 1000).toLong())) return @@ -99,10 +99,9 @@ object WrongToolCropWarning { internal object CropToolData { var jsonObject = JsonObject() - @SubscribePSSEvent + @PSSEvent.Subscribe fun loadData(event: LoadPublicDataEvent) { - jsonObject = - JsonParser().parse(PublicDataManager.getFile("constants/crop_tools.json")).asJsonObject ?: JsonObject() + jsonObject = JsonParser().parse(PublicDataManager.getFile("constants/crop_tools.json")).asJsonObject ?: JsonObject() } fun serializeCrop(cropUnlocalizedName: String, cropObject: JsonObject): Crop = diff --git a/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/farming/garden/CompostValue.kt b/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/farming/garden/CompostValue.kt index 966e0f9e5..019e9a044 100644 --- a/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/farming/garden/CompostValue.kt +++ b/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/farming/garden/CompostValue.kt @@ -16,9 +16,9 @@ import gg.essential.elementa.dsl.constraint import gg.essential.elementa.dsl.percent import me.partlysanestudios.partlysaneskies.PartlySaneSkies.Companion.config import me.partlysanestudios.partlysaneskies.PartlySaneSkies.Companion.minecraft +import me.partlysanestudios.partlysaneskies.api.events.PSSEvent import me.partlysanestudios.partlysaneskies.data.pssdata.PublicDataManager import me.partlysanestudios.partlysaneskies.data.skyblockdata.SkyblockDataManager.getItem -import me.partlysanestudios.partlysaneskies.events.SubscribePSSEvent import me.partlysanestudios.partlysaneskies.events.data.LoadPublicDataEvent import me.partlysanestudios.partlysaneskies.features.gui.SidePanel import me.partlysanestudios.partlysaneskies.render.gui.constraints.ScaledPixelConstraint.Companion.scaledPixels @@ -115,7 +115,7 @@ object CompostValue : SidePanel() { return true } - @SubscribePSSEvent + @PSSEvent.Subscribe fun loadCompostValues(event: LoadPublicDataEvent) { val data = PublicDataManager.getFile("constants/organic_matter.json") val obj = JsonParser().parse(data).asJsonObject diff --git a/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/farming/garden/CropMilestoneWebhook.kt b/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/farming/garden/CropMilestoneWebhook.kt index 3445dec3f..266c2dd35 100644 --- a/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/farming/garden/CropMilestoneWebhook.kt +++ b/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/farming/garden/CropMilestoneWebhook.kt @@ -8,9 +8,9 @@ package me.partlysanestudios.partlysaneskies.features.farming.garden import gg.essential.elementa.constraints.CenterConstraint import gg.essential.elementa.dsl.percent import me.partlysanestudios.partlysaneskies.PartlySaneSkies +import me.partlysanestudios.partlysaneskies.api.events.PSSEvent import me.partlysanestudios.partlysaneskies.config.psconfig.Toggle import me.partlysanestudios.partlysaneskies.config.psconfig.Toggle.Companion.asBoolean -import me.partlysanestudios.partlysaneskies.events.SubscribePSSEvent import me.partlysanestudios.partlysaneskies.events.minecraft.PSSChatEvent import me.partlysanestudios.partlysaneskies.features.discord.webhooks.EmbedData import me.partlysanestudios.partlysaneskies.features.discord.webhooks.EmbedField @@ -48,7 +48,7 @@ object CropMilestoneWebhook : Webhook() { val regex = "§lGARDEN MILESTONE §3(\\w+[\\s\\w+]*) §8(\\w+)➜§3(\\w+)".toRegex() - @SubscribePSSEvent + @PSSEvent.Subscribe fun onChatMessage(event: PSSChatEvent) { if (!enabled) return diff --git a/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/farming/garden/SkymartValue.kt b/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/farming/garden/SkymartValue.kt index b03031a17..f5918936f 100644 --- a/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/farming/garden/SkymartValue.kt +++ b/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/farming/garden/SkymartValue.kt @@ -16,10 +16,10 @@ import gg.essential.elementa.dsl.constraint import gg.essential.elementa.dsl.percent import me.partlysanestudios.partlysaneskies.PartlySaneSkies.Companion.config import me.partlysanestudios.partlysaneskies.PartlySaneSkies.Companion.minecraft +import me.partlysanestudios.partlysaneskies.api.events.PSSEvent import me.partlysanestudios.partlysaneskies.data.pssdata.PublicDataManager.getFile import me.partlysanestudios.partlysaneskies.data.skyblockdata.SkyblockDataManager.getItem import me.partlysanestudios.partlysaneskies.data.skyblockdata.SkyblockItem -import me.partlysanestudios.partlysaneskies.events.SubscribePSSEvent import me.partlysanestudios.partlysaneskies.events.data.LoadPublicDataEvent import me.partlysanestudios.partlysaneskies.features.gui.SidePanel import me.partlysanestudios.partlysaneskies.render.gui.constraints.ScaledPixelConstraint.Companion.scaledPixels @@ -83,7 +83,7 @@ object SkymartValue : SidePanel() { textComponent.setText(textString) } - @SubscribePSSEvent + @PSSEvent.Subscribe fun initCopperValues(event: LoadPublicDataEvent) { val str = getFile("constants/skymart_copper.json") val skymartObject = JsonParser().parse(str).getAsJsonObject().getAsJsonObject("skymart") diff --git a/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/foraging/TreecapitatorCooldown.kt b/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/foraging/TreecapitatorCooldown.kt index e7ab6536a..448f37de0 100644 --- a/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/foraging/TreecapitatorCooldown.kt +++ b/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/foraging/TreecapitatorCooldown.kt @@ -6,9 +6,9 @@ package me.partlysanestudios.partlysaneskies.features.foraging import me.partlysanestudios.partlysaneskies.PartlySaneSkies +import me.partlysanestudios.partlysaneskies.api.events.PSSEvent import me.partlysanestudios.partlysaneskies.data.cache.PetData import me.partlysanestudios.partlysaneskies.data.skyblockdata.Rarity -import me.partlysanestudios.partlysaneskies.events.SubscribePSSEvent import me.partlysanestudios.partlysaneskies.events.minecraft.player.PlayerBreakBlockEvent import me.partlysanestudios.partlysaneskies.render.gui.hud.cooldown.Cooldown import me.partlysanestudios.partlysaneskies.render.gui.hud.cooldown.CooldownManager @@ -85,7 +85,7 @@ object TreecapitatorCooldown : Cooldown() { return treecapitatorAxe ?: ItemStack(Items.golden_axe) } - @SubscribePSSEvent + @PSSEvent.Subscribe fun checkForCooldown(event: PlayerBreakBlockEvent) { if (!PartlySaneSkies.config.treecapCooldown) { return diff --git a/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/gui/hud/DropBannerDisplay.kt b/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/gui/hud/DropBannerDisplay.kt index 1d02e44c7..27664d514 100644 --- a/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/gui/hud/DropBannerDisplay.kt +++ b/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/gui/hud/DropBannerDisplay.kt @@ -17,13 +17,13 @@ import gg.essential.universal.UMatrixStack import me.partlysanestudios.partlysaneskies.PartlySaneSkies.Companion.config import me.partlysanestudios.partlysaneskies.PartlySaneSkies.Companion.minecraft import me.partlysanestudios.partlysaneskies.PartlySaneSkies.Companion.time +import me.partlysanestudios.partlysaneskies.api.events.PSSEvent import me.partlysanestudios.partlysaneskies.data.skyblockdata.Rarity import me.partlysanestudios.partlysaneskies.data.skyblockdata.Rarity.Companion.getRarityFromColorCode -import me.partlysanestudios.partlysaneskies.features.items.rngdrop.RareDropGUIManager.isAllowedDrop -import me.partlysanestudios.partlysaneskies.events.SubscribePSSEvent import me.partlysanestudios.partlysaneskies.events.minecraft.PSSChatEvent import me.partlysanestudios.partlysaneskies.features.items.rngdrop.Drop import me.partlysanestudios.partlysaneskies.features.items.rngdrop.DropWebhook +import me.partlysanestudios.partlysaneskies.features.items.rngdrop.RareDropGUIManager.isAllowedDrop import me.partlysanestudios.partlysaneskies.render.gui.constraints.TextScaledPixelConstraint.Companion.textScaledPixels import me.partlysanestudios.partlysaneskies.utils.MathUtils.onCooldown import me.partlysanestudios.partlysaneskies.utils.StringUtils.colorCodeToColor @@ -68,7 +68,7 @@ object DropBannerDisplay { y = PixelConstraint(topText.getBottom() + window.getHeight() * TEXT_SPACING_FACTOR) } childOf window - @SubscribePSSEvent + @PSSEvent.Subscribe fun onChatMessage(event: PSSChatEvent) { val formattedMessage = event.message diff --git a/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/information/WikiArticleOpener.kt b/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/information/WikiArticleOpener.kt index ae266ac1a..a7d2efe01 100644 --- a/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/information/WikiArticleOpener.kt +++ b/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/information/WikiArticleOpener.kt @@ -7,7 +7,7 @@ package me.partlysanestudios.partlysaneskies.features.information import me.partlysanestudios.partlysaneskies.PartlySaneSkies.Companion.config import me.partlysanestudios.partlysaneskies.PartlySaneSkies.Companion.minecraft -import me.partlysanestudios.partlysaneskies.events.SubscribePSSEvent +import me.partlysanestudios.partlysaneskies.api.events.PSSEvent import me.partlysanestudios.partlysaneskies.events.minecraft.PSSChatEvent import me.partlysanestudios.partlysaneskies.features.economy.auctionhousemenu.AuctionHouseGui import me.partlysanestudios.partlysaneskies.utils.HypixelUtils.getItemId @@ -20,7 +20,7 @@ import net.minecraft.item.ItemStack object WikiArticleOpener { private var isWaitingForArticle = false - @SubscribePSSEvent + @PSSEvent.Subscribe fun onChat(e: PSSChatEvent) { if (!isWaitingForArticle) { return diff --git a/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/mining/PickaxeWarning.kt b/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/mining/PickaxeWarning.kt index c1c45a838..48590ea72 100644 --- a/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/mining/PickaxeWarning.kt +++ b/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/mining/PickaxeWarning.kt @@ -7,18 +7,19 @@ package me.partlysanestudios.partlysaneskies.features.mining import me.partlysanestudios.partlysaneskies.PartlySaneSkies.Companion.config import me.partlysanestudios.partlysaneskies.PartlySaneSkies.Companion.minecraft +import me.partlysanestudios.partlysaneskies.api.events.PSSEvent import me.partlysanestudios.partlysaneskies.data.skyblockdata.IslandType import me.partlysanestudios.partlysaneskies.data.skyblockdata.IslandType.Companion.onIslands +import me.partlysanestudios.partlysaneskies.events.minecraft.PSSChatEvent import me.partlysanestudios.partlysaneskies.render.gui.hud.BannerRenderer.renderNewBanner import me.partlysanestudios.partlysaneskies.render.gui.hud.PSSBanner import me.partlysanestudios.partlysaneskies.utils.MinecraftUtils.getCurrentlyHoldingItem import me.partlysanestudios.partlysaneskies.utils.MinecraftUtils.getLore import me.partlysanestudios.partlysaneskies.utils.MinecraftUtils.isListOfStringsInLore import me.partlysanestudios.partlysaneskies.utils.StringUtils.getMatcher -import me.partlysanestudios.partlysaneskies.utils.StringUtils.removeColorCodes -import net.minecraftforge.client.event.ClientChatReceivedEvent +import net.minecraft.client.audio.PositionedSoundRecord +import net.minecraft.util.ResourceLocation import net.minecraftforge.event.entity.player.PlayerInteractEvent -import net.minecraftforge.fml.common.eventhandler.EventPriority import net.minecraftforge.fml.common.eventhandler.SubscribeEvent object PickaxeWarning { @@ -33,10 +34,10 @@ object PickaxeWarning { "Gemstone Infusion", ) - @SubscribeEvent(priority = EventPriority.HIGHEST) - fun onChat(event: ClientChatReceivedEvent) { + @PSSEvent.Subscribe + fun onChat(event: PSSChatEvent) { if (config.onlyGiveWarningOnMiningIsland && !onIslands(IslandType.DWARVEN_MINES, IslandType.CRYSTAL_HOLLOWS)) return - val message = event.message.formattedText.removeColorCodes() + val message = event.component.unformattedText pattern.getMatcher(message) { if (group("ability") !in pickaxeAbilities) return@getMatcher @@ -52,16 +53,20 @@ object PickaxeWarning { ) } if (config.pickaxeAbilityReadySound) { - minecraft.thePlayer.playSound( - if (config.pickaxeAbilityReadySiren) { - "partlysaneskies:airraidsiren" - } else { - "partlysaneskies:bell" - }, - 100f, 1f, + minecraft.soundHandler.playSound( + PositionedSoundRecord.create( + ResourceLocation( + "partlysaneskies", + if (config.pickaxeAbilityReadySiren) { + "airraidsiren" + } else { + "bell" + }, + ), + ), ) } - if (config.hideReadyMessageFromChat) event.setCanceled(true) + if (config.hideReadyMessageFromChat) event.cancel() } } diff --git a/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/mining/crystalhollows/WormWarning.kt b/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/mining/crystalhollows/WormWarning.kt index 9546b5b1d..0037561f8 100644 --- a/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/mining/crystalhollows/WormWarning.kt +++ b/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/mining/crystalhollows/WormWarning.kt @@ -8,7 +8,7 @@ package me.partlysanestudios.partlysaneskies.features.mining.crystalhollows import me.partlysanestudios.partlysaneskies.PartlySaneSkies.Companion.config import me.partlysanestudios.partlysaneskies.PartlySaneSkies.Companion.minecraft import me.partlysanestudios.partlysaneskies.PartlySaneSkies.Companion.time -import me.partlysanestudios.partlysaneskies.events.SubscribePSSEvent +import me.partlysanestudios.partlysaneskies.api.events.PSSEvent import me.partlysanestudios.partlysaneskies.events.minecraft.PSSChatEvent import me.partlysanestudios.partlysaneskies.render.gui.hud.BannerRenderer.renderNewBanner import me.partlysanestudios.partlysaneskies.render.gui.hud.PSSBanner @@ -17,7 +17,7 @@ object WormWarning { private var wormWarningString = "" private var wormWarningBannerTime: Long = 0 - @SubscribePSSEvent + @PSSEvent.Subscribe fun onChat(event: PSSChatEvent) { if (event.component.unformattedText.startsWith("You hear the sound of something approaching...")) { if (config.wormWarningBanner) { diff --git a/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/mining/crystalhollows/gemstonewaypoints/GemstoneData.kt b/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/mining/crystalhollows/gemstonewaypoints/GemstoneData.kt index f44bfc059..762e283e3 100644 --- a/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/mining/crystalhollows/gemstonewaypoints/GemstoneData.kt +++ b/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/mining/crystalhollows/gemstonewaypoints/GemstoneData.kt @@ -8,8 +8,8 @@ package me.partlysanestudios.partlysaneskies.features.mining.crystalhollows.gems import com.google.gson.JsonObject import com.google.gson.JsonParser import me.partlysanestudios.partlysaneskies.PartlySaneSkies.Companion.time +import me.partlysanestudios.partlysaneskies.api.events.PSSEvent import me.partlysanestudios.partlysaneskies.data.pssdata.PublicDataManager -import me.partlysanestudios.partlysaneskies.events.SubscribePSSEvent import me.partlysanestudios.partlysaneskies.events.data.LoadPublicDataEvent import me.partlysanestudios.partlysaneskies.utils.SystemUtils.log import me.partlysanestudios.partlysaneskies.utils.geometry.vectors.Point2d @@ -34,7 +34,7 @@ object GemstoneData { map[chunk]?.get(gemstone.type)?.add(gemstone) } - @SubscribePSSEvent + @PSSEvent.Subscribe fun loadJsonData(event: LoadPublicDataEvent) { Thread( { diff --git a/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/mining/crystalhollows/gemstonewaypoints/GemstoneWaypointRender.kt b/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/mining/crystalhollows/gemstonewaypoints/GemstoneWaypointRender.kt index 9dafa9dc6..2eb8ddf79 100644 --- a/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/mining/crystalhollows/gemstonewaypoints/GemstoneWaypointRender.kt +++ b/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/mining/crystalhollows/gemstonewaypoints/GemstoneWaypointRender.kt @@ -6,8 +6,8 @@ package me.partlysanestudios.partlysaneskies.features.mining.crystalhollows.gemstonewaypoints import me.partlysanestudios.partlysaneskies.PartlySaneSkies.Companion.config +import me.partlysanestudios.partlysaneskies.api.events.PSSEvent import me.partlysanestudios.partlysaneskies.data.skyblockdata.IslandType -import me.partlysanestudios.partlysaneskies.events.SubscribePSSEvent import me.partlysanestudios.partlysaneskies.events.minecraft.render.RenderWaypointEvent import me.partlysanestudios.partlysaneskies.render.waypoint.Waypoint import me.partlysanestudios.partlysaneskies.utils.ImageUtils.applyOpacity @@ -16,7 +16,7 @@ import me.partlysanestudios.partlysaneskies.utils.geometry.vectors.Point3d import java.awt.Color object GemstoneWaypointRender { - @SubscribePSSEvent + @PSSEvent.Subscribe fun onWaypointRenderEvent(event: RenderWaypointEvent) { if (!config.renderGemstoneWaypoints) { return diff --git a/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/mining/events/MiningEventNotifier.kt b/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/mining/events/MiningEventNotifier.kt index 9392105a8..609a607a0 100644 --- a/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/mining/events/MiningEventNotifier.kt +++ b/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/mining/events/MiningEventNotifier.kt @@ -7,17 +7,19 @@ package me.partlysanestudios.partlysaneskies.features.mining.events import me.partlysanestudios.partlysaneskies.PartlySaneSkies.Companion.config import me.partlysanestudios.partlysaneskies.PartlySaneSkies.Companion.minecraft -import me.partlysanestudios.partlysaneskies.events.SubscribePSSEvent +import me.partlysanestudios.partlysaneskies.api.events.PSSEvent +import me.partlysanestudios.partlysaneskies.events.minecraft.PSSChatEvent import me.partlysanestudios.partlysaneskies.events.skyblock.mining.MinesEvent import me.partlysanestudios.partlysaneskies.render.gui.hud.BannerRenderer.renderNewBanner import me.partlysanestudios.partlysaneskies.render.gui.hud.PSSBanner import me.partlysanestudios.partlysaneskies.system.SystemNotification.showNotification +import me.partlysanestudios.partlysaneskies.utils.HypixelUtils.inAdvancedMiningIsland import me.partlysanestudios.partlysaneskies.utils.StringUtils.removeColorCodes import org.lwjgl.opengl.Display object MiningEventNotifier { - @SubscribePSSEvent + @PSSEvent.Subscribe fun onMiningEvent(event: MinesEvent) { if (!config.miningEventsToggle) return @@ -32,4 +34,13 @@ object MiningEventNotifier { renderNewBanner(PSSBanner(text, (config.miningEventBannerTime * 1000).toLong(), 4f)) } } + + @PSSEvent.Subscribe + fun onChat(event: PSSChatEvent) { + if (!inAdvancedMiningIsland()) return + + MiningEvent.entries + .firstOrNull { it.triggeredEvent(event.message) } + ?.let { MinesEvent(it).post() } + } } diff --git a/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/skills/BestiaryLevelUpWebhook.kt b/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/skills/BestiaryLevelUpWebhook.kt index e3e7562b6..f884b094a 100644 --- a/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/skills/BestiaryLevelUpWebhook.kt +++ b/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/skills/BestiaryLevelUpWebhook.kt @@ -8,9 +8,9 @@ package me.partlysanestudios.partlysaneskies.features.skills import gg.essential.elementa.constraints.CenterConstraint import gg.essential.elementa.dsl.percent import me.partlysanestudios.partlysaneskies.PartlySaneSkies +import me.partlysanestudios.partlysaneskies.api.events.PSSEvent import me.partlysanestudios.partlysaneskies.config.psconfig.Toggle import me.partlysanestudios.partlysaneskies.config.psconfig.Toggle.Companion.asBoolean -import me.partlysanestudios.partlysaneskies.events.SubscribePSSEvent import me.partlysanestudios.partlysaneskies.events.minecraft.PSSChatEvent import me.partlysanestudios.partlysaneskies.features.discord.webhooks.EmbedData import me.partlysanestudios.partlysaneskies.features.discord.webhooks.EmbedField @@ -48,7 +48,7 @@ object BestiaryLevelUpWebhook : Webhook() { private val regex = "§b(§.)(\\w+[\\s\\w+]*) §7§8(\\w+) §8➡§b §b(\\w+)".toRegex() - @SubscribePSSEvent + @PSSEvent.Subscribe fun onChatMessage(event: PSSChatEvent) { if (!enabled) return val message = event.message diff --git a/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/skills/BestiaryMilestoneWebhook.kt b/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/skills/BestiaryMilestoneWebhook.kt index e7e8a8646..8c3bd4390 100644 --- a/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/skills/BestiaryMilestoneWebhook.kt +++ b/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/skills/BestiaryMilestoneWebhook.kt @@ -8,9 +8,9 @@ package me.partlysanestudios.partlysaneskies.features.skills import gg.essential.elementa.constraints.CenterConstraint import gg.essential.elementa.dsl.percent import me.partlysanestudios.partlysaneskies.PartlySaneSkies +import me.partlysanestudios.partlysaneskies.api.events.PSSEvent import me.partlysanestudios.partlysaneskies.config.psconfig.Toggle import me.partlysanestudios.partlysaneskies.config.psconfig.Toggle.Companion.asBoolean -import me.partlysanestudios.partlysaneskies.events.SubscribePSSEvent import me.partlysanestudios.partlysaneskies.events.minecraft.PSSChatEvent import me.partlysanestudios.partlysaneskies.features.discord.webhooks.EmbedData import me.partlysanestudios.partlysaneskies.features.discord.webhooks.EmbedField @@ -50,7 +50,7 @@ object BestiaryMilestoneWebhook : Webhook() { private val regex = "§8(\\w+)➡§e(\\w+)".toRegex() - @SubscribePSSEvent + @PSSEvent.Subscribe fun onChatMessage(event: PSSChatEvent) { if (!enabled) return diff --git a/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/skills/PetLevelUpWebhook.kt b/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/skills/PetLevelUpWebhook.kt index 8aa830915..177c6f505 100644 --- a/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/skills/PetLevelUpWebhook.kt +++ b/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/skills/PetLevelUpWebhook.kt @@ -8,11 +8,11 @@ package me.partlysanestudios.partlysaneskies.features.skills import gg.essential.elementa.constraints.CenterConstraint import gg.essential.elementa.dsl.percent import me.partlysanestudios.partlysaneskies.PartlySaneSkies +import me.partlysanestudios.partlysaneskies.api.events.PSSEvent import me.partlysanestudios.partlysaneskies.config.psconfig.Toggle import me.partlysanestudios.partlysaneskies.config.psconfig.Toggle.Companion.asBoolean import me.partlysanestudios.partlysaneskies.data.skyblockdata.Rarity import me.partlysanestudios.partlysaneskies.data.skyblockdata.Rarity.Companion.getRarityFromColorCode -import me.partlysanestudios.partlysaneskies.events.SubscribePSSEvent import me.partlysanestudios.partlysaneskies.events.minecraft.PSSChatEvent import me.partlysanestudios.partlysaneskies.features.discord.webhooks.EmbedData import me.partlysanestudios.partlysaneskies.features.discord.webhooks.EmbedField @@ -65,7 +65,7 @@ object PetLevelUpWebhook : Webhook() { private val regex = "§r§aYour §r(§.)((\\w+(\\s\\w+)*)( ✦)?) §r§aleveled up to level §r§9(\\d+)§r§a!§r".toRegex() - @SubscribePSSEvent + @PSSEvent.Subscribe fun onChatMessage(event: PSSChatEvent) { if (!enabled) return diff --git a/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/skills/SkillUpgradeWebhook.kt b/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/skills/SkillUpgradeWebhook.kt index 7e730a3fe..3767a4f40 100644 --- a/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/skills/SkillUpgradeWebhook.kt +++ b/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/skills/SkillUpgradeWebhook.kt @@ -8,9 +8,9 @@ package me.partlysanestudios.partlysaneskies.features.skills import gg.essential.elementa.constraints.CenterConstraint import gg.essential.elementa.dsl.percent import me.partlysanestudios.partlysaneskies.PartlySaneSkies +import me.partlysanestudios.partlysaneskies.api.events.PSSEvent import me.partlysanestudios.partlysaneskies.config.psconfig.Toggle import me.partlysanestudios.partlysaneskies.config.psconfig.Toggle.Companion.asBoolean -import me.partlysanestudios.partlysaneskies.events.SubscribePSSEvent import me.partlysanestudios.partlysaneskies.events.minecraft.PSSChatEvent import me.partlysanestudios.partlysaneskies.features.discord.webhooks.EmbedData import me.partlysanestudios.partlysaneskies.features.discord.webhooks.EmbedField @@ -49,7 +49,7 @@ object SkillUpgradeWebhook : Webhook() { val regex = "SKILL LEVEL UP (\\w+) (\\w+)➜(\\w+)".toRegex() - @SubscribePSSEvent + @PSSEvent.Subscribe fun onChatMessage(event: PSSChatEvent ) { if (!enabled) return diff --git a/src/main/kotlin/me/partlysanestudios/partlysaneskies/utils/HypixelUtils.kt b/src/main/kotlin/me/partlysanestudios/partlysaneskies/utils/HypixelUtils.kt index a118aab65..31a8e0d3f 100644 --- a/src/main/kotlin/me/partlysanestudios/partlysaneskies/utils/HypixelUtils.kt +++ b/src/main/kotlin/me/partlysanestudios/partlysaneskies/utils/HypixelUtils.kt @@ -6,8 +6,8 @@ package me.partlysanestudios.partlysaneskies.utils import me.partlysanestudios.partlysaneskies.PartlySaneSkies +import me.partlysanestudios.partlysaneskies.api.events.PSSEvent import me.partlysanestudios.partlysaneskies.data.skyblockdata.IslandType -import me.partlysanestudios.partlysaneskies.events.SubscribePSSEvent import me.partlysanestudios.partlysaneskies.events.minecraft.TablistUpdateEvent import me.partlysanestudios.partlysaneskies.utils.StringUtils.removeColorCodes import me.partlysanestudios.partlysaneskies.utils.StringUtils.stripLeading @@ -142,7 +142,7 @@ object HypixelUtils { fun inAdvancedMiningIsland() = IslandType.onIslands(IslandType.DWARVEN_MINES, IslandType.CRYSTAL_HOLLOWS, IslandType.MINESHAFT) - @SubscribePSSEvent + @PSSEvent.Subscribe fun onTablistUpdate(event: TablistUpdateEvent) { currentIsland = event.list .map { it.removeColorCodes().trim() }