From 6f53c39a78360a7912b3694ffbcb96b8118d80f2 Mon Sep 17 00:00:00 2001 From: Lorenz Date: Wed, 24 Aug 2022 09:18:06 +0200 Subject: add fandom /wiki command --- .../java/at/hannibal2/skyhanni/SkyHanniMod.java | 2 ++ .../at/hannibal2/skyhanni/config/Features.java | 4 +++ .../skyhanni/config/features/CommandsFeatures.java | 13 ++++++++ .../skyhanni/features/commands/WikiCommand.kt | 35 ++++++++++++++++++++++ .../java/at/hannibal2/skyhanni/utils/OSUtils.kt | 21 +++++++++++++ 5 files changed, 75 insertions(+) create mode 100644 src/main/java/at/hannibal2/skyhanni/config/features/CommandsFeatures.java create mode 100644 src/main/java/at/hannibal2/skyhanni/features/commands/WikiCommand.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/utils/OSUtils.kt (limited to 'src/main/java') diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java index 843d4b231..81ccc5658 100644 --- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java +++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java @@ -17,6 +17,7 @@ import at.hannibal2.skyhanni.features.chat.ChatFilter; import at.hannibal2.skyhanni.features.chat.ChatManager; import at.hannibal2.skyhanni.features.chat.NewChatFilter; import at.hannibal2.skyhanni.features.chat.PlayerChatFilter; +import at.hannibal2.skyhanni.features.commands.WikiCommand; import at.hannibal2.skyhanni.features.damageindicator.DamageIndicatorManager; import at.hannibal2.skyhanni.features.dungeon.*; import at.hannibal2.skyhanni.features.fishing.SeaCreatureManager; @@ -93,6 +94,7 @@ public class SkyHanniMod { registerEvent(new MinionFeatures()); registerEvent(new RealTime()); registerEvent(new RngMeterInventory()); + registerEvent(new WikiCommand()); Commands.init(); diff --git a/src/main/java/at/hannibal2/skyhanni/config/Features.java b/src/main/java/at/hannibal2/skyhanni/config/Features.java index 75674ca78..e167e9142 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/Features.java +++ b/src/main/java/at/hannibal2/skyhanni/config/Features.java @@ -109,6 +109,10 @@ public class Features { @Category(name = "Misc", desc = "Settings without a category.") public Misc misc = new Misc(); + @Expose + @Category(name = "Commands", desc = "Enable or disable mod commands") + public CommandsFeatures commands = new CommandsFeatures(); + @Expose @Category(name = "Api", desc = "Api Data") public ApiData apiData = new ApiData(); diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/CommandsFeatures.java b/src/main/java/at/hannibal2/skyhanni/config/features/CommandsFeatures.java new file mode 100644 index 000000000..2e1c5ea8f --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/config/features/CommandsFeatures.java @@ -0,0 +1,13 @@ +package at.hannibal2.skyhanni.config.features; + +import at.hannibal2.skyhanni.config.gui.core.config.annotations.ConfigEditorBoolean; +import at.hannibal2.skyhanni.config.gui.core.config.annotations.ConfigOption; +import com.google.gson.annotations.Expose; + +public class CommandsFeatures { + + @Expose + @ConfigOption(name = "Fandom Wiki", desc = "Using §ehypixel-skyblock.fandom.com §7instead of Hypixel wiki") + @ConfigEditorBoolean + public boolean useFandomWiki = false; +} diff --git a/src/main/java/at/hannibal2/skyhanni/features/commands/WikiCommand.kt b/src/main/java/at/hannibal2/skyhanni/features/commands/WikiCommand.kt new file mode 100644 index 000000000..d4769e651 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/commands/WikiCommand.kt @@ -0,0 +1,35 @@ +package at.hannibal2.skyhanni.features.commands + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.events.PacketEvent +import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.OSUtils +import net.minecraft.network.play.client.C01PacketChatMessage +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +class WikiCommand { + + @SubscribeEvent + fun onSendPacket(event: PacketEvent.SendEvent) { + val packet = event.packet + + if (!SkyHanniMod.feature.commands.useFandomWiki) return + + if (packet is C01PacketChatMessage) { + val message = packet.message.lowercase() + if (message == "/wiki") { + event.isCanceled = true + OSUtils.openBrowser("https://hypixel-skyblock.fandom.com/wiki/Hypixel_SkyBlock_Wiki") + LorenzUtils.chat("§e[SkyHanni] Opening the Fandom Wiki..") + } + if (message.startsWith("/wiki ")) { + event.isCanceled = true + val search = packet.message.substring(6) + LorenzUtils.chat("§e[SkyHanni] Searching the Fandom Wiki for §c$search") + + val url = "https://www.google.com/search?q=inurl%3Ahypixel-skyblock.fandom.com $search&hl=en" + OSUtils.openBrowser(url.replace(' ', '+')) + } + } + } +} \ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/utils/OSUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/OSUtils.kt new file mode 100644 index 000000000..5633e7f72 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/utils/OSUtils.kt @@ -0,0 +1,21 @@ +package at.hannibal2.skyhanni.utils + +import java.awt.Desktop +import java.io.IOException +import java.net.URI + +object OSUtils { + + fun openBrowser(url: String) { + if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) { + try { + Desktop.getDesktop().browse(URI(url)) + } catch (e: IOException) { + e.printStackTrace() + LorenzUtils.error("[SkyHanni] Error opening website!") + } + } else { + LorenzUtils.warning("[SkyHanni] Web browser is not supported!") + } + } +} \ No newline at end of file -- cgit