aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/features
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/misc/tabcomplete/PlayerTabComplete.kt76
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/misc/tabcomplete/TabComplete.kt34
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/misc/tabcomplete/WarpTabComplete.kt26
3 files changed, 136 insertions, 0 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/tabcomplete/PlayerTabComplete.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/tabcomplete/PlayerTabComplete.kt
new file mode 100644
index 000000000..c20b64b7f
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/features/misc/tabcomplete/PlayerTabComplete.kt
@@ -0,0 +1,76 @@
+package at.hannibal2.skyhanni.features.misc.tabcomplete
+
+import at.hannibal2.skyhanni.SkyHanniMod
+import at.hannibal2.skyhanni.data.FriendAPI
+import at.hannibal2.skyhanni.data.PartyAPI
+import at.hannibal2.skyhanni.utils.LorenzUtils
+
+object PlayerTabComplete {
+ private val config get() = SkyHanniMod.feature.misc.tabCompleteCommands
+
+ enum class PlayerCategory {
+ PARTY,
+ FRIENDS,
+ ISLAND_PLAYERS,
+ }
+
+ fun handleTabComplete(command: String, originalArray: Array<String>): List<String>? {
+ val commands = mapOf(
+ "p" to listOf(PlayerCategory.PARTY),
+ "party" to listOf(PlayerCategory.PARTY),
+ "pt" to listOf(PlayerCategory.FRIENDS, PlayerCategory.ISLAND_PLAYERS), // /party transfer
+ "f" to listOf(PlayerCategory.FRIENDS),
+ "friend" to listOf(PlayerCategory.FRIENDS),
+
+ "msg" to listOf(),
+ "w" to listOf(),
+ "tell" to listOf(),
+ "boop" to listOf(),
+
+ "visit" to listOf(),
+ "invite" to listOf(),
+ "ah" to listOf(),
+
+ "pv" to listOf(), // NEU's Profile Viewer
+ "shmarkplayer" to listOf(), // SkyHanni's Mark Player
+ )
+ val ignored = commands[command] ?: return null
+
+
+ return buildList {
+
+ if (config.friends) {
+ if (PlayerCategory.FRIENDS !in ignored) {
+ FriendAPI.getAllFriends().filter { it.bestFriend || !config.onlyBestFriends }
+ .forEach { add(it.name) }
+ }
+ }
+
+ if (config.islandPlayers) {
+ if (PlayerCategory.ISLAND_PLAYERS !in ignored) {
+ for (name in originalArray) {
+ if (name != LorenzUtils.getPlayerName()) {
+ add(name)
+ }
+ }
+ }
+ }
+
+ if (config.party) {
+ if (PlayerCategory.PARTY !in ignored) {
+ for (member in PartyAPI.partyMembers) {
+ add(member)
+ }
+ }
+
+ }
+
+ if (config.vipVisits) {
+ if (command == "visit") {
+ add("prtlhub")
+ add("PortalHub")
+ }
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/tabcomplete/TabComplete.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/tabcomplete/TabComplete.kt
new file mode 100644
index 000000000..69d24c4dc
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/features/misc/tabcomplete/TabComplete.kt
@@ -0,0 +1,34 @@
+package at.hannibal2.skyhanni.features.misc.tabcomplete
+
+object TabComplete {
+
+ @JvmStatic
+ fun handleTabComplete(leftOfCursor: String, originalArray: Array<String>): Array<String>? {
+ val splits = leftOfCursor.split(" ")
+ if (splits.size > 1) {
+ var command = splits.first().lowercase()
+ if (command.startsWith("/")) {
+ command = command.substring(1)
+ customTabComplete(command, originalArray)?.let {
+ return buildResponse(splits, it).toTypedArray()
+ }
+ }
+ }
+ return null
+ }
+
+ private fun customTabComplete(command: String, originalArray: Array<String>): List<String>? {
+ WarpTabComplete.handleTabComplete(command)?.let { return it }
+ PlayerTabComplete.handleTabComplete(command, originalArray)?.let { return it }
+
+ return null
+ }
+
+ private fun buildResponse(arguments: List<String>, fullResponse: List<String>): List<String> {
+ if (arguments.size == 2) {
+ val start = arguments[1].lowercase()
+ return fullResponse.filter { it.lowercase().startsWith(start) }
+ }
+ return emptyList()
+ }
+}
diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/tabcomplete/WarpTabComplete.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/tabcomplete/WarpTabComplete.kt
new file mode 100644
index 000000000..cc948c86e
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/features/misc/tabcomplete/WarpTabComplete.kt
@@ -0,0 +1,26 @@
+package at.hannibal2.skyhanni.features.misc.tabcomplete
+
+import at.hannibal2.skyhanni.SkyHanniMod
+import at.hannibal2.skyhanni.events.RepositoryReloadEvent
+import at.hannibal2.skyhanni.utils.LorenzUtils
+import at.hannibal2.skyhanni.utils.jsonobjects.WarpsJson
+import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
+
+object WarpTabComplete {
+ private val config get() = SkyHanniMod.feature.misc.tabCompleteCommands
+ private var warpsJson: WarpsJson? = null
+
+ @SubscribeEvent
+ fun onRepoReload(event: RepositoryReloadEvent) {
+ warpsJson = event.getConstant<WarpsJson>("Warps")
+ }
+
+ fun handleTabComplete(command: String): List<String>? {
+ if (!isEnabled()) return null
+ if (command != "warp") return null
+
+ return warpsJson?.warpCommands
+ }
+
+ fun isEnabled() = LorenzUtils.inSkyBlock && config.warps
+} \ No newline at end of file