diff options
author | Linnea Gräf <nea@nea.moe> | 2024-04-13 08:13:55 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-13 08:13:55 +0200 |
commit | 961b5a839d5092b5edda37ffc645cf5a2c67a8ba (patch) | |
tree | eca12602722c9d9632c73caacd235600d5d17d1d /src/main/java/at | |
parent | 0a9c63b5f5f0ff9eca991c93f12afa2ae03cf3ae (diff) | |
download | skyhanni-961b5a839d5092b5edda37ffc645cf5a2c67a8ba.tar.gz skyhanni-961b5a839d5092b5edda37ffc645cf5a2c67a8ba.tar.bz2 skyhanni-961b5a839d5092b5edda37ffc645cf5a2c67a8ba.zip |
Add party chat commands (#1433)
Diffstat (limited to 'src/main/java/at')
6 files changed, 189 insertions, 7 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt index eab267a4d..b55b037b0 100644 --- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt +++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt @@ -92,6 +92,7 @@ import at.hannibal2.skyhanni.features.combat.mobs.AreaMiniBossFeatures import at.hannibal2.skyhanni.features.combat.mobs.AshfangMinisNametagHider import at.hannibal2.skyhanni.features.combat.mobs.MobHighlight import at.hannibal2.skyhanni.features.combat.mobs.SpawnTimers +import at.hannibal2.skyhanni.features.commands.PartyChatCommands import at.hannibal2.skyhanni.features.commands.PartyCommands import at.hannibal2.skyhanni.features.commands.SendCoordinatedCommand import at.hannibal2.skyhanni.features.commands.ViewRecipeCommand @@ -586,6 +587,7 @@ class SkyHanniMod { loadModule(WarpIsCommand()) loadModule(ViewRecipeCommand) loadModule(PartyCommands) + loadModule(PartyChatCommands) loadModule(SummoningMobManager()) loadModule(SkyblockXPInChat()) loadModule(AreaMiniBossFeatures()) diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/misc/MiscConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/misc/MiscConfig.java index f4e5fd032..915430ea7 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/misc/MiscConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/misc/MiscConfig.java @@ -29,6 +29,10 @@ public class MiscConfig { public CommandsConfig commands = new CommandsConfig(); @Expose + @Category(name = "Party Commands", desc = "Enable or disable party commands.") + public PartyCommandsConfig partyCommands = new PartyCommandsConfig(); + + @Expose @Category(name = "Minions", desc = "The minions on your private island.") public MinionsConfig minions = new MinionsConfig(); 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 new file mode 100644 index 000000000..fb28b6544 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/config/features/misc/PartyCommandsConfig.java @@ -0,0 +1,44 @@ +package at.hannibal2.skyhanni.config.features.misc; + +import com.google.gson.annotations.Expose; +import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorBoolean; +import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorDropdown; +import io.github.notenoughupdates.moulconfig.annotations.ConfigOption; +import org.jetbrains.annotations.NotNull; + +public class PartyCommandsConfig { + + @Expose + @ConfigEditorDropdown + @ConfigOption(name = "Party Command Trust Level", desc = "Choose who can run party chat commands.") + public @NotNull TrustedUser defaultRequiredTrustLevel = TrustedUser.FRIENDS; + + @Expose + @ConfigEditorBoolean + @ConfigOption(name = "Party Transfer", desc = "Automatically transfer the party to people who type §b!ptme") + public boolean transferCommand = false; + + @Expose + @ConfigEditorBoolean + @ConfigOption(name = "Party Warp", desc = "Automatically warp the party if someone types §b!warp") + public boolean warpCommand = false; + + public enum TrustedUser { + BEST_FRIENDS("Best Friends"), + FRIENDS("Friends"), + ANYONE("Everyone"), + NO_ONE("No One"), + ; + final String label; + + TrustedUser(String label) { + this.label = label; + } + + @Override + public String toString() { + return label; + } + } + +} diff --git a/src/main/java/at/hannibal2/skyhanni/data/PartyAPI.kt b/src/main/java/at/hannibal2/skyhanni/data/PartyAPI.kt index acc30ee44..44a778292 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/PartyAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/PartyAPI.kt @@ -1,6 +1,7 @@ package at.hannibal2.skyhanni.data import at.hannibal2.skyhanni.events.LorenzChatEvent +import at.hannibal2.skyhanni.events.PartyChatEvent import at.hannibal2.skyhanni.utils.ChatUtils import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.OSUtils @@ -44,9 +45,13 @@ object PartyAPI { "others.disconnect", "(?<name>.*) §ewas removed from your party because they disconnected\\." ) - private val transferPattern by patternGroup.pattern( - "others.transfer", - "The party was transferred to .* because (?<name>.*) left" + private val transferOnLeavePattern by patternGroup.pattern( + "others.transfer.leave", + "The party was transferred to (?<newowner>.*) because (?<name>.*) left" + ) + private val transferVoluntaryPattern by patternGroup.pattern( + "others.transfer.voluntary", + "The party was transferred to (?<newowner>.*) by .*" ) private val disbandedPattern by patternGroup.pattern( "others.disband", @@ -61,8 +66,8 @@ object PartyAPI { "§6Party Members \\(\\d+\\)" ) private val partyMemberListPattern by patternGroup.pattern( - "members.list", - "Party (?:Leader|Moderators|Members): (?<names>.*)" + "members.list.withkind", + "Party (?<kind>Leader|Moderators|Members): (?<names>.*)" ) private val kuudraFinderJoinPattern by patternGroup.pattern( "kuudrafinder.join", @@ -73,8 +78,20 @@ object PartyAPI { "§dParty Finder §f> (?<name>.*?) §ejoined the dungeon group! \\(§[a-fA-F0-9].* Level \\d+§[a-fA-F0-9]\\)" ) + /** + * REGEX-TEST: §9Party §8> §b§l⚛ §b[MVP§f+§b] Dankbarkeit§f: §rx: -190, y: 5, z: -163 + * REGEX-TEST: §9Party §8> §6⚔ §6[MVP§3++§6] RealBacklight§f: §r!warp + * REGEX-TEST: §9Party §8> §b[MVP§3+§b] Eisengolem§f: §r!pt + */ + private val partyChatMessagePattern by patternGroup.pattern( + "chat.message", + "§9Party §8> (?<name>[^:]*): §r(?<message>.*)" + ) + val partyMembers = mutableListOf<String>() + var partyLeader: String? = null + fun listMembers() { val size = partyMembers.size if (size == 0) { @@ -83,7 +100,11 @@ object PartyAPI { } ChatUtils.chat("Tracked party members §7($size) §f:", prefixColor = "§a") for (member in partyMembers) { - ChatUtils.chat(" §a- §7$member", false) + ChatUtils.chat(" §a- §7$member" + if (partyLeader == member) " §a(Leader)" else "", false) + } + + if (partyLeader == LorenzUtils.getPlayerName()) { + ChatUtils.chat("§aYou are leader") } if (Random.nextDouble() < 0.1) { @@ -96,13 +117,24 @@ object PartyAPI { fun onChat(event: LorenzChatEvent) { val message = event.message.trimWhiteSpace().removeResets() + partyChatMessagePattern.matchMatcher(event.message) { + val name = group("name").cleanPlayerName() + val message = group("message") + addPlayer(name) + PartyChatEvent(name, message, event).postAndCatch() + } + // new member joined youJoinedPartyPattern.matchMatcher(message) { val name = group("name").cleanPlayerName() + partyLeader = name addPlayer(name) } othersJoinedPartyPattern.matchMatcher(message) { val name = group("name").cleanPlayerName() + if (partyMembers.isEmpty()) { + partyLeader = LorenzUtils.getPlayerName() + } addPlayer(name) } othersInThePartyPattern.matchMatcher(message) { @@ -136,23 +168,30 @@ object PartyAPI { val name = group("name").cleanPlayerName() partyMembers.remove(name) } - transferPattern.matchMatcher(message.removeColor()) { + transferOnLeavePattern.matchMatcher(message.removeColor()) { val name = group("name").cleanPlayerName() + partyLeader = group("newowner").cleanPlayerName() partyMembers.remove(name) } + transferVoluntaryPattern.matchMatcher(message.removeColor()) { + partyLeader = group("newowner").cleanPlayerName() + } // party disbanded disbandedPattern.matchMatcher(message) { partyMembers.clear() + partyLeader = null } kickedPattern.matchMatcher(message) { partyMembers.clear() + partyLeader = null } if (message == "§eYou left the party." || message == "§cThe party was disbanded because all invites expired and the party was empty." || message == "§cYou are not currently in a party." ) { partyMembers.clear() + partyLeader = null } // party list @@ -161,9 +200,14 @@ object PartyAPI { } partyMemberListPattern.matchMatcher(message.removeColor()) { + val kind = group("kind") + val isPartyLeader = kind == "Leader" for (name in group("names").split(" ● ")) { val playerName = name.replace(" ●", "").cleanPlayerName() addPlayer(playerName) + if (isPartyLeader) { + partyLeader = playerName + } } } } diff --git a/src/main/java/at/hannibal2/skyhanni/events/PartyChatEvent.kt b/src/main/java/at/hannibal2/skyhanni/events/PartyChatEvent.kt new file mode 100644 index 000000000..76630583e --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/events/PartyChatEvent.kt @@ -0,0 +1,7 @@ +package at.hannibal2.skyhanni.events + +data class PartyChatEvent( + val author: String, + val text: String, + val trigger: LorenzChatEvent, +) : LorenzEvent() diff --git a/src/main/java/at/hannibal2/skyhanni/features/commands/PartyChatCommands.kt b/src/main/java/at/hannibal2/skyhanni/features/commands/PartyChatCommands.kt new file mode 100644 index 000000000..6b0e7df53 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/commands/PartyChatCommands.kt @@ -0,0 +1,81 @@ +package at.hannibal2.skyhanni.features.commands + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.config.features.misc.PartyCommandsConfig +import at.hannibal2.skyhanni.data.FriendAPI +import at.hannibal2.skyhanni.data.PartyAPI +import at.hannibal2.skyhanni.events.PartyChatEvent +import at.hannibal2.skyhanni.utils.ChatUtils +import at.hannibal2.skyhanni.utils.LorenzUtils +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +object PartyChatCommands { + + data class PartyChatCommand( + val names: List<String>, + val isEnabled: () -> Boolean, + val requiresPartyLead: Boolean, + val executable: (PartyChatEvent) -> Unit, + ) + + private fun useConfig() = SkyHanniMod.feature.misc.partyCommands + val allPartyCommands = listOf( + PartyChatCommand( + listOf("pt", "ptme", "transfer"), + { useConfig().transferCommand }, + requiresPartyLead = true, + executable = { + ChatUtils.sendCommandToServer("party transfer ${it.author}") + } + ), + PartyChatCommand( + listOf("pw", "warp", "warpus"), + { useConfig().warpCommand }, + requiresPartyLead = true, + executable = { + ChatUtils.sendCommandToServer("party warp") + } + ), + ) + + val indexedPartyChatCommands = buildMap { + for (command in allPartyCommands) { + for (name in command.names) { + put(name.lowercase(), command) + } + } + } + + + fun isTrustedUser(name: String): Boolean { + val friend = FriendAPI.getAllFriends().find { it.name == name } + return when (useConfig().defaultRequiredTrustLevel) { + PartyCommandsConfig.TrustedUser.FRIENDS -> friend != null + PartyCommandsConfig.TrustedUser.BEST_FRIENDS -> friend?.bestFriend == true + PartyCommandsConfig.TrustedUser.ANYONE -> true + PartyCommandsConfig.TrustedUser.NO_ONE -> false + } + } + + private val commandBeginChars = ".!?".toSet() + + @SubscribeEvent + fun onPartyCommand(event: PartyChatEvent) { + if (event.text.firstOrNull() !in commandBeginChars) + return + val commandLabel = event.text.substring(1).substringBefore(' ') + val command = indexedPartyChatCommands[commandLabel.lowercase()] ?: return + if (event.author == LorenzUtils.getPlayerName()) { + return + } + if (!command.isEnabled()) return + if (command.requiresPartyLead && PartyAPI.partyLeader != LorenzUtils.getPlayerName()) { + return + } + if (!isTrustedUser(event.author)) { + ChatUtils.chat("§cIgnoring chat command from ${event.author}. Change your party chat command settings or /friend (best) them.") + return + } + command.executable(event) + } +} |