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

Added force join command #122

Merged
merged 1 commit into from
May 17, 2024
Merged
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
42 changes: 42 additions & 0 deletions docs/commands/admin-commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <player> <faction>`

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 |

3 changes: 3 additions & 0 deletions docs/commands/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
@@ -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<out String>): Boolean {
Bukkit.dispatchCommand(player, "factions help category:${CommandCategory.ADMIN_CATEGORY}")
return true
}
}
Original file line number Diff line number Diff line change
@@ -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<Argument<*>> = arrayOf(
PlayerArgument(),
FactionArgument()
)

override fun handle(player: Player, args: Array<String>): Boolean {
val parsedArgs = parseArgs(player, args)
val faction = parsedArgs.get<Faction>(1) ?: return false
val playerToJoin = parsedArgs.get<Player>(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
}
}
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> {
private val descriptionKey: String,
private val tabComplete: List<String> = emptyList()) : Argument<String> {
override fun parse(player: Player, arg: String): String {
return arg
}

override fun tab(p0: Player): List<String> = emptyList()
override fun tab(p0: Player): List<String> = tabComplete

override fun descriptionKey(): String = descriptionKey

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,4 +181,10 @@ base.exceptions.arg-is-no-player={prefix} <red>Error: The provided argument is n
base.commands.bypass.remove-bypass={prefix} <green>You've successfully removed the bypass for this player</green>
base.commands.bypass.add-bypass={prefix} <green>You've successfully added the bypass for this player</green>
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} <red>This chunk is protected by a zone</red>
base.zone.protected={prefix} <red>This chunk is protected by a zone</red>
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} <green>You've successfully forced the player to join the faction</green>
base.command.force.join.player-joined={prefix} <green>You've been forced to join the faction <yellow>{faction}</yellow></green>
base.command.force.join.error={prefix} <red>Error: The following error has been encountered when force joining the player:</red>
base.command.force.join.already-member={prefix} <red>Error: The player is already a member of a faction</red>
6 changes: 6 additions & 0 deletions improved-factions-base/src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Loading