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

Implement warning and post-clear command hooks #2

Open
wants to merge 3 commits into
base: main
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
18 changes: 18 additions & 0 deletions src/main/java/com/pokeskies/skiesclear/ClearTask.kt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ class ClearTask(
}

}
if (clearConfig.commands.clear.isNotEmpty()) {
for (command in clearConfig.commands.clear) {
if (server.commands.performPrefixedCommand(server.createCommandSourceStack(), command) == 0) {
Utils.printError("The post-clearing command \"$command\" failed to execute")
break
}
}
}
if (broadcast && (clearConfig.messages.clear.isNotEmpty() || clearConfig.sounds.clear != null)) {
for (player in server.playerList.players) {
for (line in clearConfig.messages.clear) {
Expand All @@ -69,6 +77,7 @@ class ClearTask(
}
}
}

return totalCleared.get()
}

Expand Down Expand Up @@ -99,6 +108,15 @@ class ClearTask(
)
}
}
val warningCommands: List<String>? = clearConfig.commands.warnings[timer.toString()]
if (warningCommands != null) {
for (command in warningCommands) {
if (server.commands.performPrefixedCommand(server.createCommandSourceStack(), command) == 0) {
Utils.printError("The ${timer}s warning command \"$command\" failed to execute")
break
}
}
}
if (timer-- <= 0) {
resetTimer()
runClear(server, true)
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/com/pokeskies/skiesclear/config/ClearConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class ClearConfig(
val messages: Messages = Messages(),
val sounds: Sounds = Sounds(),
val clearables: Clearables? = null,
val commands: Commands = Commands(),
) {
class Messages(
@JsonAdapter(FlexibleListAdaptorFactory::class)
Expand Down Expand Up @@ -56,6 +57,16 @@ class ClearConfig(
}
}

class Commands(
@JsonAdapter(FlexibleListAdaptorFactory::class)
val clear: List<String> = emptyList(),
val warnings: Map<String, List<String>> = emptyMap(),
) {
override fun toString(): String {
return "Commands(clear=$clear, warnings=$warnings)"
}
}

override fun toString(): String {
return "ClearConfig(enabled=$enabled, interval=$interval, dimensions=$dimensions, messages=$messages, sounds=$sounds, clearables=$clearables)"
}
Expand Down
10 changes: 10 additions & 0 deletions src/main/resources/assets/skiesclear/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@
}
}
},
"commands": {
"clear": [
],
"warnings": {
"10": [
],
"5": [
]
}
},
"clearables": {
"items": {
"enabled": true,
Expand Down