diff options
author | Lorenz <lo.scherf@gmail.com> | 2022-08-24 09:18:06 +0200 |
---|---|---|
committer | Lorenz <lo.scherf@gmail.com> | 2022-08-24 09:18:06 +0200 |
commit | 6f53c39a78360a7912b3694ffbcb96b8118d80f2 (patch) | |
tree | c98fac1754aebb1554c4e281f9a2a0d0035b1481 /src/main/java | |
parent | 393cdc614d7fbd9c7142a52b3fcef7eb065c99d5 (diff) | |
download | skyhanni-6f53c39a78360a7912b3694ffbcb96b8118d80f2.tar.gz skyhanni-6f53c39a78360a7912b3694ffbcb96b8118d80f2.tar.bz2 skyhanni-6f53c39a78360a7912b3694ffbcb96b8118d80f2.zip |
add fandom /wiki command
Diffstat (limited to 'src/main/java')
5 files changed, 75 insertions, 0 deletions
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 @@ -110,6 +110,10 @@ public class Features { 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 |