Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add chatmessage parameter #246

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion docs/parameters.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,13 @@ Negative Allowed - `No`
Multiple Allowed - `No`
Example - `rolledback:true`

This parameter allows you to filter by rollback state. If true, then it will only show results that have already been rolled back. If false, then it will only show results that have not been rolled back.
This parameter allows you to filter by rollback state. If true, then it will only show results that have already been rolled back. If false, then it will only show results that have not been rolled back.

### Chat Message
Key - `chatmessage:`
Value - `true` or `false`
Negative Allowed - `No`
Multiple Allowed - `No`
Example - `chatmessage:true`

This parameter allows to sent data as chat message. If true, then it will also send a chat message when using networking. If false, then it will only send using networking.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ data class ActionSearchParams(
val before: Instant?,
val after: Instant?,
val rolledBack: Boolean?,
val chatMessage: Boolean?,
var actions: MutableSet<Negatable<String>>?,
var objects: MutableSet<Negatable<Identifier>>?,
var sourceNames: MutableSet<Negatable<String>>?,
Expand All @@ -22,14 +23,15 @@ data class ActionSearchParams(
builder.before,
builder.after,
builder.rolledBack,
builder.chatMessage,
builder.actions,
builder.objects,
builder.sourceNames,
builder.sourcePlayerIds,
builder.worlds
)

fun isEmpty() = listOf(bounds, before, after, actions, objects, sourceNames, sourcePlayerIds, worlds, rolledBack).all { it == null }
fun isEmpty() = listOf(bounds, before, after, actions, objects, sourceNames, sourcePlayerIds, worlds, rolledBack, chatMessage).all { it == null }

companion object {
inline fun build(block: Builder.() -> Unit) = Builder().apply(block).build()
Expand All @@ -40,6 +42,7 @@ data class ActionSearchParams(
var before: Instant? = null
var after: Instant? = null
var rolledBack: Boolean? = null
var chatMessage: Boolean? = null
var actions: MutableSet<Negatable<String>>? = null
var objects: MutableSet<Negatable<Identifier>>? = null
var sourceNames: MutableSet<Negatable<String>>? = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.github.quiltservertools.ledger.commands.arguments

import com.github.quiltservertools.ledger.actionutils.ActionSearchParams
import com.github.quiltservertools.ledger.commands.parameters.ActionParameter
import com.github.quiltservertools.ledger.commands.parameters.ChatmessageParameter
import com.github.quiltservertools.ledger.commands.parameters.DimensionParameter
import com.github.quiltservertools.ledger.commands.parameters.ObjectParameter
import com.github.quiltservertools.ledger.commands.parameters.RangeParameter
Expand Down Expand Up @@ -41,6 +42,7 @@ object SearchParamArgument {
paramSuggesters["before"] = Parameter(TimeParameter())
paramSuggesters["after"] = Parameter(TimeParameter())
paramSuggesters["rolledback"] = Parameter(RollbackStatusParameter())
paramSuggesters["chatmessage"] = Parameter(ChatmessageParameter())
}

fun argument(name: String): RequiredArgumentBuilder<ServerCommandSource, String> {
Expand Down Expand Up @@ -173,6 +175,10 @@ object SearchParamArgument {
val rolledBack = value as Boolean
builder.rolledBack = rolledBack
}
"chatmessage" -> {
val chatMessage = value as Boolean
builder.chatMessage = chatMessage
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.github.quiltservertools.ledger.commands.parameters

import com.mojang.brigadier.StringReader
import com.mojang.brigadier.arguments.BoolArgumentType
import com.mojang.brigadier.context.CommandContext
import com.mojang.brigadier.exceptions.CommandSyntaxException
import com.mojang.brigadier.suggestion.Suggestions
import com.mojang.brigadier.suggestion.SuggestionsBuilder
import net.minecraft.server.command.ServerCommandSource
import java.util.concurrent.CompletableFuture

class ChatmessageParameter : SimpleParameter<Boolean>() {
override fun parse(stringReader: StringReader): Boolean = try {
BoolArgumentType.bool().parse(stringReader)
} catch (e: CommandSyntaxException) {
stringReader.readString()
false // TODO Maybe rework parser to alert errors and not require a default value
}

override fun getSuggestions(
context: CommandContext<ServerCommandSource>,
builder: SuggestionsBuilder
): CompletableFuture<Suggestions> = BoolArgumentType.bool().listSuggestions(context, builder)
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ object MessageUtils {
for (n in results.page..results.pages) {
val networkResults = DatabaseManager.searchActions(results.searchParams, n)
networkResults.actions.forEach {
if (results.searchParams.chatMessage) {
actionType -> source.sendFeedback({ actionType.getMessage() }, false)
}
val packet = ActionPacket()
packet.populate(it)
ServerPlayNetworking.send(source.player, packet.channel, packet.buf)
Expand Down
Loading