diff options
author | Lorenz <lo.scherf@gmail.com> | 2022-07-29 17:04:53 +0200 |
---|---|---|
committer | Lorenz <lo.scherf@gmail.com> | 2022-07-29 17:04:53 +0200 |
commit | c85c3f9d6ab15bb704515d2fb8d3cd1d7c0fc0c8 (patch) | |
tree | 993b216f08e8a88ee5c9fe1e13a649113ffca12f /src/main | |
parent | a1c3ddf8e4aa49ecbbbdd11b637582c6040e66c4 (diff) | |
download | NotEnoughUpdates-c85c3f9d6ab15bb704515d2fb8d3cd1d7c0fc0c8.tar.gz NotEnoughUpdates-c85c3f9d6ab15bb704515d2fb8d3cd1d7c0fc0c8.tar.bz2 NotEnoughUpdates-c85c3f9d6ab15bb704515d2fb8d3cd1d7c0fc0c8.zip |
adding support for minion upgrade chat message
Diffstat (limited to 'src/main')
2 files changed, 63 insertions, 0 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java b/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java index d512e0ac..357760cf 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java @@ -62,6 +62,7 @@ import io.github.moulberry.notenoughupdates.miscgui.SignCalculator; import io.github.moulberry.notenoughupdates.miscgui.TrophyRewardOverlay; import io.github.moulberry.notenoughupdates.miscgui.minionhelper.MinionHelperManager; import io.github.moulberry.notenoughupdates.miscgui.minionhelper.loaders.MinionHelperApiLoader; +import io.github.moulberry.notenoughupdates.miscgui.minionhelper.loaders.MinionHelperChatLoader; import io.github.moulberry.notenoughupdates.miscgui.minionhelper.loaders.MinionHelperInventoryLoader; import io.github.moulberry.notenoughupdates.miscgui.minionhelper.MinionHelperOverlay; import io.github.moulberry.notenoughupdates.miscgui.minionhelper.loaders.MinionHelperRepoLoader; @@ -301,6 +302,7 @@ public class NotEnoughUpdates { MinecraftForge.EVENT_BUS.register(MinionHelperOverlay.getInstance()); MinecraftForge.EVENT_BUS.register(MinionHelperTooltips.getInstance()); MinecraftForge.EVENT_BUS.register(MinionHelperManager.getInstance()); + MinecraftForge.EVENT_BUS.register(MinionHelperChatLoader.getInstance()); MinecraftForge.EVENT_BUS.register(PowerStoneStatsDisplay.getInstance()); MinecraftForge.EVENT_BUS.register(navigation); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/loaders/MinionHelperChatLoader.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/loaders/MinionHelperChatLoader.java new file mode 100644 index 00000000..24688308 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/loaders/MinionHelperChatLoader.java @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2022 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>. + */ + +package io.github.moulberry.notenoughupdates.miscgui.minionhelper.loaders; + +import io.github.moulberry.notenoughupdates.core.util.StringUtils; +import io.github.moulberry.notenoughupdates.miscgui.minionhelper.Minion; +import io.github.moulberry.notenoughupdates.miscgui.minionhelper.MinionHelperManager; +import io.github.moulberry.notenoughupdates.util.Utils; +import net.minecraftforge.client.event.ClientChatReceivedEvent; +import net.minecraftforge.fml.common.eventhandler.EventPriority; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; + +public class MinionHelperChatLoader { + private static MinionHelperChatLoader instance = null; + private final MinionHelperManager manager = MinionHelperManager.getInstance(); + + public static MinionHelperChatLoader getInstance() { + if (instance == null) { + instance = new MinionHelperChatLoader(); + } + return instance; + } + + @SubscribeEvent(priority = EventPriority.LOW, receiveCanceled = true) + public void onChat(ClientChatReceivedEvent event) { + if (event.type != 0) return; + String message = event.message.getFormattedText(); + + try { + if (message.startsWith("§r§aYou crafted a §eTier ") && message.contains("§a! That's a new one!")) { + String text = StringUtils.substringBetween(message, "§eTier ", "§a! That's"); + String rawTier = text.split(" ")[0]; + int tier = Utils.parseRomanNumeral(rawTier); + String name = text.substring(rawTier.length() + 1); + Minion minionByName = manager.getMinionByName(name, tier); + minionByName.setCrafted(true); + } + } catch (Exception e) { + Utils.addChatMessage( + "[NEU] §cMinion Helper failed reading the minion upgrade message. See the logs for more info!"); + e.printStackTrace(); + } + } +} |