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 dump command for better debugging #40

Open
wants to merge 5 commits into
base: refactor/0.4-old
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
1 change: 1 addition & 0 deletions anvil-api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ version = rootProject.apiVersion
dependencies {
api bson
api configurate_core
api(gson)
api(guice + ":" + guice_version)
api hikari
api jedis
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,11 @@ public static Map<String, Key<?>> getAll(String nameSpace) {
.sensitive()
.build();

public static final Key<String> DUMP_PERMISSION =
Key.builder(TypeTokens.STRING)
.name("DUMP_PERMISSION")
.fallback("anvil.admin.dump")
.build();
public static final Key<String> PLUGINS_PERMISSION =
Key.builder(TypeTokens.STRING)
.name("PLUGINS_PERMISSION")
Expand Down Expand Up @@ -345,6 +350,7 @@ public static Map<String, Key<?>> getAll(String nameSpace) {
.register(REDIS_USE_AUTH);

startRegistration("anvil")
.register(DUMP_PERMISSION)
.register(PLUGINS_PERMISSION)
.register(REGEDIT_PERMISSION)
.register(RELOAD_PERMISSION)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Anvil - AnvilPowered
* Copyright (C) 2020-2021
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package org.anvilpowered.anvil.api.util

import org.anvilpowered.anvil.api.Environment

interface InfoDumpService<TCommandSource> {

/**
* Publishes the registry data for all loaded environments to anvil servers
*
* @param source User to send the URL to
*/
suspend fun publishInfo(source: TCommandSource)

/**
* Publishes the registry data for all specific environments to anvil servers
*
* @param source User to send the URL to
* @param environments Environments to query registry data from
*/
suspend fun publishInfo(source: TCommandSource, vararg environments: Environment)
}
16 changes: 13 additions & 3 deletions anvil-bungee/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,26 @@ dependencies {
implementation javasisst
implementation(kotlin_reflect + ":" + kotlin_version)
implementation(kotlin_stdlib + ":" + kotlin_version)
implementation(kotlin_stdlib7 + ":" + kotlin_version)
implementation(kotlin_stdlib8 + ":" + kotlin_version)
implementation(kotlinx_coroutines)
implementation(kotlinx_coroutines_core)
implementation(kotlinx_coroutines_jvm)
implementation(kotlinx_serialization)
implementation(ktor_cio)
implementation(ktor_core)
implementation(ktor_http)
implementation(ktor_http_jvm)
implementation(ktor_network)
implementation(ktor_network_jvm)
implementation(ktor_utils)
implementation(kyori_api)
implementation(kyori_bungee_serializer)
implementation(kyori_examination)
implementation(kyori_key)
implementation(kyori_legacy_serializer)
implementation(kyori_gson_serializer)
implementation(kyori_plain_serializer)
implementation kotlinx_coroutines
implementation kotlinx_serialization
implementation microutils_logging
implementation mongo_java_driver
implementation typesafe_config
Expand Down Expand Up @@ -59,7 +69,7 @@ shadowJar {
include dependency(kotlin_reflect)
include dependency(kotlin_stdlib)
include dependency(kotlin_stdlib8)
include dependency(kotlinx_coroutines)
include dependency(kotlinx_coroutines_core)
include dependency(kotlinx_serialization)
include dependency(kyori_api)
include dependency(kyori_examination)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.anvilpowered.anvil.bungee.command

import com.google.inject.Inject
import kotlinx.coroutines.runBlocking
import net.md_5.bungee.api.CommandSender
import net.md_5.bungee.api.ProxyServer
import net.md_5.bungee.api.plugin.Command
Expand All @@ -39,7 +40,9 @@ class BungeeSimpleCommandService : CommonSimpleCommandService<CommandSender>() {
) : Command(primaryAlias, null, *otherAliases) {
override fun execute(source: CommandSender, context: Array<String>) {
if (delegate.canExecute(source)) {
delegate.execute(source, context)
runBlocking {
delegate.execute(source, context)
}
} else {
source.sendNoPermission()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import org.anvilpowered.anvil.api.command.CommandExecuteService
import org.anvilpowered.anvil.api.misc.bind
import org.anvilpowered.anvil.api.misc.to
import org.anvilpowered.anvil.api.server.LocationService
import org.anvilpowered.anvil.api.util.InfoDumpService
import org.anvilpowered.anvil.api.util.KickService
import org.anvilpowered.anvil.api.util.PermissionService
import org.anvilpowered.anvil.api.util.TextService
Expand All @@ -37,6 +38,7 @@ import org.anvilpowered.anvil.bungee.util.BungeeUserService
import org.anvilpowered.anvil.common.PlatformImpl
import org.anvilpowered.anvil.common.module.JavaUtilLoggingAdapter
import org.anvilpowered.anvil.common.module.PlatformModule
import org.anvilpowered.anvil.common.util.CommonInfoDumpService
import org.anvilpowered.anvil.common.util.CommonTextService
import org.anvilpowered.anvil.common.util.SendTextService

Expand All @@ -53,6 +55,8 @@ class ApiBungeeModule : PlatformModule(
with(binder()) {
bind<CommandExecuteService>().to<BungeeCommandExecuteService>()
bind<KickService>().to<BungeeKickService>()
bind<InfoDumpService<CommandSender>>().to<CommonInfoDumpService<CommandSender>>()
bind<InfoDumpService<*>>().to<CommonInfoDumpService<CommandSender>>()
bind<LocationService>().to<BungeeLocationService>()
bind<PermissionService>().to<BungeePermissionService>()
bind<SendTextService<CommandSender>>().to<BungeeSendTextService>()
Expand Down
2 changes: 2 additions & 0 deletions anvil-common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ dependencies {
api("net.kyori:adventure-text-serializer-legacy:4.5.0")
api("net.kyori:adventure-text-serializer-plain:4.5.0")
api(configurate_hocon)
api(ktor_core)
api(ktor_cio)
api(kotlin_reflect + ":" + kotlin_version)
api(kotlin_stdlib + ":" + kotlin_version)
api(kotlin_stdlib8 + ":" + kotlin_version)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import org.anvilpowered.anvil.common.command.regedit.CommonRegistryEditCommandNo

class CommonAnvilCommandNode<TUser, TPlayer, TCommandSource> @Inject constructor(
private val commandService: SimpleCommandService<TCommandSource>,
private val dumpCommand: CommonAnvilDumpCommand<TCommandSource>,
private val pluginsCommand: CommonAnvilPluginsCommand<TCommandSource>,
private val reloadCommand: CommonAnvilReloadCommand<TCommandSource>,
private val callbackCommand: CommonCallbackCommand<TCommandSource>,
Expand All @@ -44,6 +45,7 @@ class CommonAnvilCommandNode<TUser, TPlayer, TCommandSource> @Inject constructor
}

val CALLBACK_ALIAS = listOf("callback")
val DUMP_ALIAS = listOf("dump")
val HELP_ALIAS = listOf("help")
val PLUGINS_ALIAS = listOf("plugins")
val RELOAD_ALIAS = listOf("reload")
Expand Down Expand Up @@ -71,6 +73,7 @@ class CommonAnvilCommandNode<TUser, TPlayer, TCommandSource> @Inject constructor
private fun loadCommands() {
val subCommands = listOf(
commandService.mapTerminal(HELP_ALIAS, commandService.generateHelp { anvilMapping.subCommands }),
commandService.mapTerminal(DUMP_ALIAS, dumpCommand),
commandService.mapTerminal(PLUGINS_ALIAS, pluginsCommand),
regeditNode.regeditMapping,
commandService.mapTerminal(RELOAD_ALIAS, reloadCommand),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*
* Anvil - AnvilPowered
* Copyright (C) 2020
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see https://www.gnu.org/licenses/.
*/

package org.anvilpowered.anvil.common.command

import com.google.inject.Inject
import java.util.Optional
import java.util.stream.Collectors
import kotlinx.coroutines.runBlocking
import org.anvilpowered.anvil.api.Anvil
import org.anvilpowered.anvil.api.Environment
import org.anvilpowered.anvil.api.command.SimpleCommand
import org.anvilpowered.anvil.api.misc.Named
import org.anvilpowered.anvil.api.util.InfoDumpService
import org.anvilpowered.anvil.api.util.TextService

class CommonAnvilDumpCommand<TCommandSource> : SimpleCommand<TCommandSource> {

@Inject
private lateinit var dumpService: InfoDumpService<TCommandSource>

@Inject
private lateinit var textService: TextService<TCommandSource>

override fun execute(source: TCommandSource, context: Array<String>) {
if (context.isEmpty()) {
textService.builder()
.appendPrefix()
.red().append("Plugin is required if '--all' is not set")
.sendTo(source)
return
}
if ("-a" == context[0] || "--all" == context[0]) {
runBlocking {
dumpService.publishInfo(source)
}
return
} else {
runBlocking {
dumpDirect(source, context)
}
}
}

override fun suggest(source: TCommandSource, context: Array<String>): List<String> {
val suggestions = Anvil.getEnvironmentManager()
.environments.values.stream()
.map(Named::name)
.sorted().collect(Collectors.toList())
suggestions.add("--all")
return suggestions
}

private suspend fun dumpDirect(source: TCommandSource, plugins: Array<String>): Boolean {
val optionalEnvironments: MutableList<Optional<Environment>> = mutableListOf()
for (environment in Anvil.getEnvironmentManager().environments.values) {
if (plugins.contains(environment.name)) {
optionalEnvironments.add(Optional.of(environment))
}
}
if (optionalEnvironments.isEmpty()) {
textService.builder()
.appendPrefix()
.red().append("Could not find plugin(s) ")
.gold().append(plugins.joinToString(separator = " "))
.sendTo(source)
return false
}
val environments: MutableList<Environment> = mutableListOf()
for (env in optionalEnvironments) {
environments.add(env.get())
}
dumpService.publishInfo(source, *environments.toTypedArray())
return true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ abstract class CommonModule<TCommandSource>(private val configDir: String) : Api
.to<CommonXodusCoreMemberRepository>()
bind<CoreMemberRepository<EntityId, PersistentEntityStore>>()
.to<CommonXodusCoreMemberRepository>()

bind<CoreMemberManager>().to<CommonCoreMemberManager>()

withMongoDB()
Expand Down
Loading