diff --git a/docs/commands/admin-commands.md b/docs/commands/admin-commands.md index 1e3b61a3..0bd354c4 100644 --- a/docs/commands/admin-commands.md +++ b/docs/commands/admin-commands.md @@ -87,3 +87,45 @@ Module: power-raids | power | Provide a power value | true | | faction | Provide a faction | true | +## factions bypass + +Permission: factions.bypass + +Usage: `/factions bypass [player]` + +Description: Add or remove a bypass for a player. A bypass only stays until the next server restart + +Module: core + +| Argument | Description | Required | +| --- | --- | --- | +| player | Provide a player for this argument | false | + +## factions force + +Permission: factions.force + +Usage: `/factions force ` + +Description: base.command.force.description + +Module: core + +| Argument | Description | Required | +| --- | --- | --- | + +## factions force join + +Permission: factions.force.join + +Usage: `/factions force join ` + +Description: Force a player to join a faction + +Module: core + +| Argument | Description | Required | +| --- | --- | --- | +| player | Provide a player for this argument | true | +| faction | Provide a faction | true | + diff --git a/docs/commands/index.md b/docs/commands/index.md index 2a251f95..59b577d3 100644 --- a/docs/commands/index.md +++ b/docs/commands/index.md @@ -42,6 +42,9 @@ More details when you click on a command. | [factions zone claim](admin-commands.md#factions-zone-claim) | Mark a claim as property of this zone | core | | [factions power add](admin-commands.md#factions-power-add) | Set the power of a faction | power-raids | | [factions power set](admin-commands.md#factions-power-set) | Set the power of a faction | power-raids | +| [factions bypass](admin-commands.md#factions-bypass) | Add or remove a bypass for a player. A bypass only stays until the next server restart | core | +| [factions force](admin-commands.md#factions-force) | base.command.force.description | core | +| [factions force join](admin-commands.md#factions-force-join) | Force a player to join a faction | core | | [factions rank](permission-management-commands.md#factions-rank) | Access rank commands | core | | [factions rank set](permission-management-commands.md#factions-rank-set) | Set a permission for a rank | core | | [factions rank joinas](permission-management-commands.md#factions-rank-joinas) | Set the rank new members will join with | core | diff --git a/improved-factions-base/src/main/kotlin/io/github/toberocat/improvedfactions/DatabaseConnector.kt b/improved-factions-base/src/main/kotlin/io/github/toberocat/improvedfactions/DatabaseConnector.kt index 0b460a0d..fb71548d 100644 --- a/improved-factions-base/src/main/kotlin/io/github/toberocat/improvedfactions/DatabaseConnector.kt +++ b/improved-factions-base/src/main/kotlin/io/github/toberocat/improvedfactions/DatabaseConnector.kt @@ -101,8 +101,6 @@ class DatabaseConnector(private val plugin: ImprovedFactionsPlugin) { fun createDatabase(): Database { val database = connectDatabase() transaction { - if (config.getBoolean("mysql.verbose", true)) addLogger(StdOutSqlLogger) - SchemaUtils.createMissingTablesAndColumns(FactionUsers) SchemaUtils.createMissingTablesAndColumns(FactionClaims) SchemaUtils.createMissingTablesAndColumns(FactionPermissions) diff --git a/improved-factions-base/src/main/kotlin/io/github/toberocat/improvedfactions/commands/FactionCommandExecutor.kt b/improved-factions-base/src/main/kotlin/io/github/toberocat/improvedfactions/commands/FactionCommandExecutor.kt index 888723c0..bd95cd9d 100644 --- a/improved-factions-base/src/main/kotlin/io/github/toberocat/improvedfactions/commands/FactionCommandExecutor.kt +++ b/improved-factions-base/src/main/kotlin/io/github/toberocat/improvedfactions/commands/FactionCommandExecutor.kt @@ -3,7 +3,8 @@ package io.github.toberocat.improvedfactions.commands import io.github.toberocat.improvedfactions.ImprovedFactionsPlugin import io.github.toberocat.improvedfactions.commands.admin.ByPassCommand import io.github.toberocat.improvedfactions.commands.admin.ReloadCommand -import io.github.toberocat.improvedfactions.commands.admin.ZoneCommandRoute +import io.github.toberocat.improvedfactions.commands.admin.force.ForceCommandRoute +import io.github.toberocat.improvedfactions.commands.admin.zone.ZoneCommandRoute import io.github.toberocat.improvedfactions.commands.claim.ClaimCommand import io.github.toberocat.improvedfactions.commands.claim.FactionMap import io.github.toberocat.improvedfactions.commands.claim.UnclaimCommand @@ -17,14 +18,12 @@ import io.github.toberocat.improvedfactions.commands.manage.IconCommand import io.github.toberocat.improvedfactions.commands.manage.RenameCommand import io.github.toberocat.improvedfactions.commands.member.* import io.github.toberocat.improvedfactions.commands.rank.RankCommandRoute -import io.github.toberocat.improvedfactions.translation.localize import io.github.toberocat.improvedfactions.translation.localizeUnformatted import io.github.toberocat.improvedfactions.translation.sendLocalized import io.github.toberocat.toberocore.command.CommandExecutor import org.bukkit.Bukkit import org.bukkit.entity.Player import java.util.* -import kotlin.reflect.jvm.internal.impl.descriptors.Visibilities.Local /** * Created: 04.08.2023 @@ -67,6 +66,7 @@ class FactionCommandExecutor(plugin: ImprovedFactionsPlugin) { executor.addChild(ReloadCommand(plugin)) executor.addChild(ZoneCommandRoute(plugin)) executor.addChild(ByPassCommand(plugin)) + executor.addChild(ForceCommandRoute(plugin)) plugin.addModuleCommands(executor) diff --git a/improved-factions-base/src/main/kotlin/io/github/toberocat/improvedfactions/commands/admin/force/ForceCommandRoute.kt b/improved-factions-base/src/main/kotlin/io/github/toberocat/improvedfactions/commands/admin/force/ForceCommandRoute.kt new file mode 100644 index 00000000..4c8a40f9 --- /dev/null +++ b/improved-factions-base/src/main/kotlin/io/github/toberocat/improvedfactions/commands/admin/force/ForceCommandRoute.kt @@ -0,0 +1,24 @@ +package io.github.toberocat.improvedfactions.commands.admin.force + +import io.github.toberocat.improvedfactions.ImprovedFactionsPlugin +import io.github.toberocat.improvedfactions.utils.command.CommandCategory +import io.github.toberocat.improvedfactions.utils.command.CommandMeta +import io.github.toberocat.toberocore.command.CommandRoute +import org.bukkit.Bukkit +import org.bukkit.entity.Player + +@CommandMeta( + description = "base.command.force.description", + category = CommandCategory.ADMIN_CATEGORY +) +class ForceCommandRoute(plugin: ImprovedFactionsPlugin) : CommandRoute("force", plugin) { + + init { + addChild(ForceJoinCommand(plugin)) + } + + override fun handle(player: Player, p1: Array): Boolean { + Bukkit.dispatchCommand(player, "factions help category:${CommandCategory.ADMIN_CATEGORY}") + return true + } +} \ No newline at end of file diff --git a/improved-factions-base/src/main/kotlin/io/github/toberocat/improvedfactions/commands/admin/force/ForceJoinCommand.kt b/improved-factions-base/src/main/kotlin/io/github/toberocat/improvedfactions/commands/admin/force/ForceJoinCommand.kt new file mode 100644 index 00000000..395d73eb --- /dev/null +++ b/improved-factions-base/src/main/kotlin/io/github/toberocat/improvedfactions/commands/admin/force/ForceJoinCommand.kt @@ -0,0 +1,72 @@ +package io.github.toberocat.improvedfactions.commands.admin.force + +import io.github.toberocat.improvedfactions.ImprovedFactionsPlugin +import io.github.toberocat.improvedfactions.claims.squareClaimAction +import io.github.toberocat.improvedfactions.factions.Faction +import io.github.toberocat.improvedfactions.ranks.FactionRank +import io.github.toberocat.improvedfactions.ranks.anyRank +import io.github.toberocat.improvedfactions.ranks.listRanks +import io.github.toberocat.improvedfactions.translation.sendLocalized +import io.github.toberocat.improvedfactions.user.factionUser +import io.github.toberocat.improvedfactions.utils.arguments.ClaimRadiusArgument +import io.github.toberocat.improvedfactions.utils.arguments.PlayerArgument +import io.github.toberocat.improvedfactions.utils.arguments.StringArgument +import io.github.toberocat.improvedfactions.utils.arguments.ZoneArgument +import io.github.toberocat.improvedfactions.utils.arguments.entity.FactionArgument +import io.github.toberocat.improvedfactions.utils.arguments.entity.RankArgument +import io.github.toberocat.improvedfactions.utils.command.CommandCategory +import io.github.toberocat.improvedfactions.utils.command.CommandMeta +import io.github.toberocat.improvedfactions.utils.options.* +import io.github.toberocat.improvedfactions.zone.Zone +import io.github.toberocat.toberocore.command.PlayerSubCommand +import io.github.toberocat.toberocore.command.arguments.Argument +import io.github.toberocat.toberocore.command.exceptions.CommandException +import io.github.toberocat.toberocore.command.options.ArgLengthOption +import io.github.toberocat.toberocore.command.options.Options +import org.bukkit.entity.Player +import org.jetbrains.exposed.sql.transactions.transaction + +@CommandMeta( + description = "base.command.force.join.description", + category = CommandCategory.ADMIN_CATEGORY +) +class ForceJoinCommand(private val plugin: ImprovedFactionsPlugin) : PlayerSubCommand("join") { + override fun options(): Options = Options.getFromConfig(plugin, "force.join") { options, _ -> + options + .cmdOpt(PlayerNameOption(0)) + .addFactionNameOption(1) + } + + override fun arguments(): Array> = arrayOf( + PlayerArgument(), + FactionArgument() + ) + + override fun handle(player: Player, args: Array): Boolean { + val parsedArgs = parseArgs(player, args) + val faction = parsedArgs.get(1) ?: return false + val playerToJoin = parsedArgs.get(0) ?: return false + + transaction { + val user = player.factionUser() + if (user.factionId == faction.id.value) { + player.sendLocalized("base.command.force.join.already-member") + return@transaction true + } + + try { + if (user.isInFaction()) { + user.faction()?.leave(player.uniqueId) + } + + faction.join(playerToJoin.uniqueId, faction.defaultRank) + player.sendLocalized("base.command.force.join.success") + playerToJoin.sendLocalized("base.command.force.join.player-joined", mapOf("faction" to faction.name)) + } catch (e: CommandException) { + player.sendLocalized("base.command.force.join.error", e.placeholders) + throw CommandException(e.message, e.placeholders) + } + } + return true + } +} \ No newline at end of file diff --git a/improved-factions-base/src/main/kotlin/io/github/toberocat/improvedfactions/commands/admin/ZoneCommandRoute.kt b/improved-factions-base/src/main/kotlin/io/github/toberocat/improvedfactions/commands/admin/zone/ZoneCommandRoute.kt similarity index 78% rename from improved-factions-base/src/main/kotlin/io/github/toberocat/improvedfactions/commands/admin/ZoneCommandRoute.kt rename to improved-factions-base/src/main/kotlin/io/github/toberocat/improvedfactions/commands/admin/zone/ZoneCommandRoute.kt index 5bed6688..f2e272a8 100644 --- a/improved-factions-base/src/main/kotlin/io/github/toberocat/improvedfactions/commands/admin/ZoneCommandRoute.kt +++ b/improved-factions-base/src/main/kotlin/io/github/toberocat/improvedfactions/commands/admin/zone/ZoneCommandRoute.kt @@ -1,8 +1,6 @@ -package io.github.toberocat.improvedfactions.commands.admin +package io.github.toberocat.improvedfactions.commands.admin.zone import io.github.toberocat.improvedfactions.ImprovedFactionsPlugin -import io.github.toberocat.improvedfactions.commands.admin.zone.ZoneClaimCommand -import io.github.toberocat.improvedfactions.commands.admin.zone.ZoneUnclaimCommand import io.github.toberocat.improvedfactions.utils.command.CommandCategory import io.github.toberocat.improvedfactions.utils.command.CommandMeta import io.github.toberocat.toberocore.command.CommandRoute diff --git a/improved-factions-base/src/main/kotlin/io/github/toberocat/improvedfactions/utils/arguments/StringArgument.kt b/improved-factions-base/src/main/kotlin/io/github/toberocat/improvedfactions/utils/arguments/StringArgument.kt index acfb4389..78f05441 100644 --- a/improved-factions-base/src/main/kotlin/io/github/toberocat/improvedfactions/utils/arguments/StringArgument.kt +++ b/improved-factions-base/src/main/kotlin/io/github/toberocat/improvedfactions/utils/arguments/StringArgument.kt @@ -5,12 +5,13 @@ import org.bukkit.command.CommandSender import org.bukkit.entity.Player open class StringArgument(private val usage: String, - private val descriptionKey: String) : Argument { + private val descriptionKey: String, + private val tabComplete: List = emptyList()) : Argument { override fun parse(player: Player, arg: String): String { return arg } - override fun tab(p0: Player): List = emptyList() + override fun tab(p0: Player): List = tabComplete override fun descriptionKey(): String = descriptionKey diff --git a/improved-factions-base/src/main/resources/languages/messages_en.properties b/improved-factions-base/src/main/resources/languages/messages_en.properties index c31dff24..33000feb 100644 --- a/improved-factions-base/src/main/resources/languages/messages_en.properties +++ b/improved-factions-base/src/main/resources/languages/messages_en.properties @@ -181,4 +181,10 @@ base.exceptions.arg-is-no-player={prefix} Error: The provided argument is n base.commands.bypass.remove-bypass={prefix} You've successfully removed the bypass for this player base.commands.bypass.add-bypass={prefix} You've successfully added the bypass for this player base.commands.bypass.description=Add or remove a bypass for a player. A bypass only stays until the next server restart -base.zone.protected={prefix} This chunk is protected by a zone \ No newline at end of file +base.zone.protected={prefix} This chunk is protected by a zone +base.commands.force.description=Force a player to certain faction-related actions +base.command.force.join.description=Force a player to join a faction +base.command.force.join.success={prefix} You've successfully forced the player to join the faction +base.command.force.join.player-joined={prefix} You've been forced to join the faction {faction} +base.command.force.join.error={prefix} Error: The following error has been encountered when force joining the player: +base.command.force.join.already-member={prefix} Error: The player is already a member of a faction \ No newline at end of file diff --git a/improved-factions-base/src/main/resources/plugin.yml b/improved-factions-base/src/main/resources/plugin.yml index 90589971..ec7aa72d 100644 --- a/improved-factions-base/src/main/resources/plugin.yml +++ b/improved-factions-base/src/main/resources/plugin.yml @@ -75,6 +75,12 @@ permissions: default: true factions.zone: default: op + factions.bypass: + default: op + factions.force: + default: op + factions.force.join: + default: op factions.zone.claim: default: op factions.zone.unclaim: