-
Notifications
You must be signed in to change notification settings - Fork 33
Add command to decline vassalization requests #1920
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
Open
Copilot
wants to merge
5
commits into
develop
Choose a base branch
from
copilot/allow-declining-vassalisation-requests
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
92a8c28
Initial plan
Copilot 934efcf
Add decline vassalization command implementation
Copilot 6d5e34a
Translate decline vassalization strings to German, French, and Portug…
Copilot 7976566
Merge branch 'develop' into copilot/allow-declining-vassalisation-req…
dmccoystephenson d4d2250
Fix French language file encoding corruption from merge conflict
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 114 additions & 0 deletions
114
...actionsystem/command/faction/declinevassalization/MfFactionDeclineVassalizationCommand.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| package com.dansplugins.factionsystem.command.faction.declinevassalization | ||
|
|
||
| import com.dansplugins.factionsystem.MedievalFactions | ||
| import com.dansplugins.factionsystem.faction.MfFaction | ||
| import com.dansplugins.factionsystem.player.MfPlayer | ||
| import com.dansplugins.factionsystem.relationship.MfFactionRelationshipType.VASSAL | ||
| import dev.forkhandles.result4k.onFailure | ||
| import org.bukkit.ChatColor.GREEN | ||
| import org.bukkit.ChatColor.RED | ||
| import org.bukkit.command.Command | ||
| import org.bukkit.command.CommandExecutor | ||
| import org.bukkit.command.CommandSender | ||
| import org.bukkit.command.TabCompleter | ||
| import org.bukkit.entity.Player | ||
| import java.util.logging.Level.SEVERE | ||
|
|
||
| class MfFactionDeclineVassalizationCommand(private val plugin: MedievalFactions) : CommandExecutor, TabCompleter { | ||
| override fun onCommand(sender: CommandSender, command: Command, label: String, args: Array<out String>): Boolean { | ||
| if (!sender.hasPermission("mf.declinevassalization")) { | ||
| sender.sendMessage("$RED${plugin.language["CommandFactionDeclineVassalizationNoPermission"]}") | ||
| return true | ||
| } | ||
| if (args.isEmpty()) { | ||
| sender.sendMessage("$RED${plugin.language["CommandFactionDeclineVassalizationUsage"]}") | ||
| return true | ||
| } | ||
| if (sender !is Player) { | ||
| sender.sendMessage("$RED${plugin.language["CommandFactionDeclineVassalizationNotAPlayer"]}") | ||
| return true | ||
| } | ||
| plugin.server.scheduler.runTaskAsynchronously( | ||
| plugin, | ||
| Runnable { | ||
| val playerService = plugin.services.playerService | ||
| val mfPlayer = playerService.getPlayer(sender) | ||
| ?: playerService.save(MfPlayer(plugin, sender)).onFailure { | ||
| sender.sendMessage("$RED${plugin.language["CommandFactionDeclineVassalizationFailedToSavePlayer"]}") | ||
| plugin.logger.log(SEVERE, "Failed to save player: ${it.reason.message}", it.reason.cause) | ||
| return@Runnable | ||
| } | ||
| val factionService = plugin.services.factionService | ||
| val faction = factionService.getFaction(mfPlayer.id) | ||
| if (faction == null) { | ||
| sender.sendMessage("$RED${plugin.language["CommandFactionDeclineVassalizationMustBeInAFaction"]}") | ||
| return@Runnable | ||
| } | ||
| val role = faction.getRole(mfPlayer.id) | ||
| if (role == null || !role.hasPermission(faction, plugin.factionPermissions.swearFealty)) { | ||
| sender.sendMessage("$RED${plugin.language["CommandFactionDeclineVassalizationNoFactionPermission"]}") | ||
| return@Runnable | ||
| } | ||
| val target = factionService.getFaction(args.joinToString(" ")) | ||
| if (target == null) { | ||
| sender.sendMessage("$RED${plugin.language["CommandFactionDeclineVassalizationInvalidTarget"]}") | ||
| return@Runnable | ||
| } | ||
| val factionRelationshipService = plugin.services.factionRelationshipService | ||
| val reverseRelationships = factionRelationshipService.getRelationships(target.id, faction.id) | ||
| val vassalizationRequest = reverseRelationships.firstOrNull { it.type == VASSAL } | ||
| if (vassalizationRequest == null) { | ||
| sender.sendMessage("$RED${plugin.language["CommandFactionDeclineVassalizationNoVassalizationRequest"]}") | ||
| return@Runnable | ||
| } | ||
| factionRelationshipService.delete(vassalizationRequest.id).onFailure { | ||
| sender.sendMessage("$RED${plugin.language["CommandFactionDeclineVassalizationFailedToDeleteRelationship"]}") | ||
| plugin.logger.log(SEVERE, "Failed to delete faction relationship: ${it.reason.message}", it.reason.cause) | ||
| return@Runnable | ||
| } | ||
| sender.sendMessage("$GREEN${plugin.language["CommandFactionDeclineVassalizationSuccess", target.name]}") | ||
| plugin.server.scheduler.runTask( | ||
| plugin, | ||
| Runnable { | ||
| faction.sendMessage( | ||
| plugin.language["FactionVassalizationRequestDeclinedNotificationTitle", target.name], | ||
| plugin.language["FactionVassalizationRequestDeclinedNotificationBody", target.name] | ||
| ) | ||
| target.sendMessage( | ||
| plugin.language["FactionVassalizationRequestRejectedNotificationTitle", faction.name], | ||
| plugin.language["FactionVassalizationRequestRejectedNotificationBody", faction.name] | ||
| ) | ||
| } | ||
| ) | ||
| } | ||
| ) | ||
| return true | ||
| } | ||
|
|
||
| override fun onTabComplete( | ||
| sender: CommandSender, | ||
| command: Command, | ||
| label: String, | ||
| args: Array<out String> | ||
| ): List<String> { | ||
| if (sender !is Player) return emptyList() | ||
| val playerService = plugin.services.playerService | ||
| val mfPlayer = playerService.getPlayer(sender) ?: return emptyList() | ||
| val factionService = plugin.services.factionService | ||
| val faction = factionService.getFaction(mfPlayer.id) ?: return emptyList() | ||
| val factionRelationshipService = plugin.services.factionRelationshipService | ||
| // Find factions that have sent vassalization requests TO this faction | ||
| val factionsWithRequests = factionService.factions.filter { otherFaction -> | ||
| val relationships = factionRelationshipService.getRelationships(otherFaction.id, faction.id) | ||
| relationships.any { it.type == VASSAL } | ||
| } | ||
| return when { | ||
| args.isEmpty() -> factionsWithRequests.map(MfFaction::name) | ||
| args.size == 1 -> | ||
| factionsWithRequests | ||
| .filter { it.name.lowercase().startsWith(args[0].lowercase()) } | ||
| .map(MfFaction::name) | ||
| else -> emptyList() | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.