diff options
author | martimavocado <39881008+martimavocado@users.noreply.github.com> | 2024-05-01 18:49:18 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-01 19:49:18 +0200 |
commit | fbfb1f1bc461fed6ccfe480194966e02943f3315 (patch) | |
tree | d766dfe6ecfb4095c897e7b5552c71dbadd15bc8 | |
parent | 7e3f72289763747427e03011a99c22548177e0a3 (diff) | |
download | skyhanni-fbfb1f1bc461fed6ccfe480194966e02943f3315.tar.gz skyhanni-fbfb1f1bc461fed6ccfe480194966e02943f3315.tar.bz2 skyhanni-fbfb1f1bc461fed6ccfe480194966e02943f3315.zip |
Feature: Add Ignored users for Party Commands (#1469)
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Co-authored-by: CalMWolfs <94038482+CalMWolfs@users.noreply.github.com>
5 files changed, 137 insertions, 4 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt b/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt index 5eeb1b6ef..b8a0f2c54 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt +++ b/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt @@ -17,6 +17,7 @@ import at.hannibal2.skyhanni.features.bingo.card.nextstephelper.BingoNextStepHel import at.hannibal2.skyhanni.features.chat.Translator import at.hannibal2.skyhanni.features.combat.endernodetracker.EnderNodeTracker import at.hannibal2.skyhanni.features.combat.ghostcounter.GhostUtil +import at.hannibal2.skyhanni.features.commands.PartyChatCommands import at.hannibal2.skyhanni.features.commands.PartyCommands import at.hannibal2.skyhanni.features.commands.WikiManager import at.hannibal2.skyhanni.features.dungeon.CroesusChestTracker @@ -307,6 +308,10 @@ object Commands { "shlanedetection", "Detect a farming lane in garden" ) { FarmingLaneCreator.commandLaneDetection() } + registerCommand( + "shignore", + "Add/Remove a user from your" + ) { PartyChatCommands.blacklist(it) } } private fun usersBugFix() { diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/misc/PartyCommandsConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/misc/PartyCommandsConfig.java index cee11c99b..7c16b2e13 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/misc/PartyCommandsConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/misc/PartyCommandsConfig.java @@ -46,4 +46,8 @@ public class PartyCommandsConfig { } } + @Expose + @ConfigEditorBoolean + @ConfigOption(name = "Show reminder", desc = "Shows a reminder when an unauthorized player tries to run a command.") + public boolean showIgnoredReminder = true; } diff --git a/src/main/java/at/hannibal2/skyhanni/config/storage/Storage.java b/src/main/java/at/hannibal2/skyhanni/config/storage/Storage.java index 862dfea45..c37ba1dd0 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/storage/Storage.java +++ b/src/main/java/at/hannibal2/skyhanni/config/storage/Storage.java @@ -48,4 +48,6 @@ public class Storage { @Expose public String currentFameRank = "New player"; + @Expose + public List<String> blacklistedUsers = new ArrayList<>(); } diff --git a/src/main/java/at/hannibal2/skyhanni/features/commands/PartyChatCommands.kt b/src/main/java/at/hannibal2/skyhanni/features/commands/PartyChatCommands.kt index aa38f90b8..be986e01d 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/commands/PartyChatCommands.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/commands/PartyChatCommands.kt @@ -7,6 +7,7 @@ import at.hannibal2.skyhanni.data.PartyAPI import at.hannibal2.skyhanni.data.hypixel.chat.event.PartyChatEvent import at.hannibal2.skyhanni.events.TabCompletionEvent import at.hannibal2.skyhanni.utils.ChatUtils +import at.hannibal2.skyhanni.utils.HypixelCommands import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.SimpleTimeMark import net.minecraftforge.fml.common.eventhandler.SubscribeEvent @@ -15,6 +16,7 @@ import kotlin.time.Duration.Companion.seconds object PartyChatCommands { private val config get() = SkyHanniMod.feature.misc.partyCommands + private val storage get() = SkyHanniMod.feature.storage data class PartyChatCommand( val names: List<String>, @@ -32,7 +34,7 @@ object PartyChatCommands { { config.transferCommand }, requiresPartyLead = true, executable = { - ChatUtils.sendCommandToServer("party transfer ${it.cleanedAuthor}") + HypixelCommands.partyTransfer(it.cleanedAuthor) } ), PartyChatCommand( @@ -41,7 +43,7 @@ object PartyChatCommands { requiresPartyLead = true, executable = { lastWarp = SimpleTimeMark.now() - ChatUtils.sendCommandToServer("party warp") + HypixelCommands.partyWarp() } ), PartyChatCommand( @@ -50,7 +52,7 @@ object PartyChatCommands { requiresPartyLead = true, executable = { lastAllInvite = SimpleTimeMark.now() - ChatUtils.sendCommandToServer("party settings allinvite") + HypixelCommands.partyAllInvite() } ), ) @@ -75,6 +77,10 @@ object PartyChatCommands { private val commandPrefixes = ".!?".toSet() + private fun isBlockedUser(name: String): Boolean { + return storage.blacklistedUsers.any { it.equals(name, ignoreCase = true) } + } + @SubscribeEvent fun onPartyCommand(event: PartyChatEvent) { if (event.message.firstOrNull() !in commandPrefixes) return @@ -85,8 +91,21 @@ object PartyChatCommands { if (name == LorenzUtils.getPlayerName()) return if (!command.isEnabled()) return if (command.requiresPartyLead && PartyAPI.partyLeader != LorenzUtils.getPlayerName()) return + if (isBlockedUser(name)) { + if (config.showIgnoredReminder) ChatUtils.clickableChat( + "§cIgnoring chat command from ${event.author}. " + + "Unignore them using /shignore remove <player> or click here!", + onClick = { blacklistModify(event.author) } + ) + return + } if (!isTrustedUser(name)) { - ChatUtils.chat("§cIgnoring chat command from $name. Change your party chat command settings or /friend (best) them.") + if (config.showIgnoredReminder) { + ChatUtils.chat( + "§cIgnoring chat command from $name. " + + "Change your party chat command settings or /friend (best) them." + ) + } return } command.executable(event) @@ -104,4 +123,95 @@ object PartyChatCommands { .map { "$prefix$it" } .forEach(event::addSuggestion) } + + /** + * TODO use a utils function for add/remove/list/clear + * function(args: Array<String>, list: List<String>, listName: String, + * precondition(string): () -> Boolean, onAdd(string), onRemove(string), onList(list)) + */ + fun blacklist(input: Array<String>) { + if (input.size !in 1..2) { + ChatUtils.userError("Usage: /shignore <add/remove/list/clear> <name>") + return + } + when (val firstArg = input[0]) { + "add" -> { + if (input.size != 2) { + ChatUtils.userError("Usage: /shignore <add/remove/list/clear> <name>") + return + } + if (isBlockedUser(input[1])) { + ChatUtils.userError("${input[1]} is already ignored!") + } else blacklistModify(input[1]) + } + + "remove" -> { + if (input.size != 2) { + ChatUtils.userError("Usage: /shignore <add/remove/list/clear> <name>") + return + } + if (!isBlockedUser(input[1])) { + ChatUtils.userError("${input[1]} isn't ignored!") + } else blacklistModify(input[1]) + } + + "list" -> { + if (input.size == 2) { + blacklistView(input[1]) + } else blacklistView() + } + + "clear" -> { + ChatUtils.clickableChat("Are you sure you want to do this? Click here to confirm.", + onClick = { + storage.blacklistedUsers.clear() + ChatUtils.chat("Cleared your ignored players list!") + }) + } + + else -> blacklistModify(firstArg) + } + } + + private fun blacklistModify(player: String) { + if (player !in storage.blacklistedUsers) { + ChatUtils.chat("§cNow ignoring §b$player§e!") + storage.blacklistedUsers.add(player) + return + } + ChatUtils.chat("§aStopped ignoring §b$player§e!") + storage.blacklistedUsers.remove(player) + return + } + + private fun blacklistView() { + val blacklist = storage.blacklistedUsers + if (blacklist.size <= 0) { + ChatUtils.chat("Your ignored players list is empty!") + return + } + var message = "Ignored player list:" + if (blacklist.size > 15) { + message += "\n§e" + blacklist.forEachIndexed { i, it -> + message += it + if (i < blacklist.size - 1) { + message += ", " + } + } + } else { + blacklist.forEach { + message += "\n§e$it" + } + } + ChatUtils.chat(message) + } + + private fun blacklistView(player: String) { + if (isBlockedUser(player)) { + ChatUtils.chat("$player §ais §eignored.") + } else { + ChatUtils.chat("$player §cisn't §eignored.") + } + } } diff --git a/src/main/java/at/hannibal2/skyhanni/utils/HypixelCommands.kt b/src/main/java/at/hannibal2/skyhanni/utils/HypixelCommands.kt index 5507f4b99..1af1a70b8 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/HypixelCommands.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/HypixelCommands.kt @@ -46,6 +46,18 @@ object HypixelCommands { send("togglemusic") } + fun partyWarp() { + send("party warp") + } + + fun partyTransfer(player: String) { + send("party transfer $player") + } + + fun partyAllInvite() { + send("party settings allinvite") + } + private fun send(command: String) { @Suppress("DEPRECATION") // TODO rename function |