Skip to content

Commit

Permalink
Added unique name check to set name command. (#1713)
Browse files Browse the repository at this point in the history
We were checking for unique names when a faction was created, but not
when it was renamed via the `set name `command. The changes in this PR
add a unique name check to resolve this problem.

This was tested locally on a 1.18.2 spigot server.

closes #1706
  • Loading branch information
dmccoystephenson authored May 7, 2023
1 parent ab66c65 commit adfe5e9
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ class MfFactionSetNameCommand(private val plugin: MedievalFactions) : CommandExe
player.sendMessage("$RED${plugin.language["CommandFactionSetNameNoFactionPermission"]}")
return@Runnable
}
if (factionService.getFaction(name) != null) {
player.sendMessage("$RED${plugin.language["CommandFactionSetNameFactionAlreadyExists"]}")
return@Runnable
}
val updatedFaction = factionService.save(faction.copy(name = name)).onFailure {
player.sendMessage("$RED${plugin.language["CommandFactionSetNameFailedToSaveFaction"]}")
plugin.logger.log(Level.SEVERE, "Failed to save faction: ${it.reason.message}", it.reason.cause)
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/lang/lang_de_DE.properties
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,7 @@ CommandFactionSetNameNameTooLong=Dein Fraktionsname darf nicht l
CommandFactionSetNameNoFactionPermission=Deine Rolle in dieser Fraktion gibt dir nicht die Erlaubnis, ihren Namen zu ändern.
CommandFactionSetNameFailedToSaveFaction=Fraktion konnte nicht gespeichert werden.
CommandFactionSetNameSuccess=Fraktion-Name auf {0} gesetzt.
CommandFactionSetNameFactionAlreadyExists=Eine Fraktion mit diesem Namen existiert bereits.
CommandFactionSetPrefixNotAPlayer=Du hast nicht die Erlaubnis, den Präfix deiner Fraktion zu setzen.
CommandFactionSetPrefixOperationCancelled=Operation abgebrochen.
CommandFactionSetPrefixPrefixPrompt=Gib den neuen Präfix der Fraktion ein oder gib ''{0}'' ein, um abzubrechen.
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/lang/lang_en_GB.properties
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,7 @@ CommandFactionSetNameNameTooLong=You cannot have a faction name longer than {0}
CommandFactionSetNameNoFactionPermission=Your role in this faction does not grant you permission to change its name.
CommandFactionSetNameFailedToSaveFaction=Failed to save faction.
CommandFactionSetNameSuccess=Faction name set to {0}.
CommandFactionSetNameFactionAlreadyExists=A faction by that name already exists.
CommandFactionSetPrefixNotAPlayer=You must be a player in order to set your faction''s prefix
CommandFactionSetPrefixOperationCancelled=Operation cancelled.
CommandFactionSetPrefixPrefixPrompt=Enter the new prefix of the faction, or type ''{0}'' to cancel.
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/lang/lang_en_US.properties
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,7 @@ CommandFactionSetNameNameTooLong=You cannot have a faction name longer than {0}
CommandFactionSetNameNoFactionPermission=Your role in this faction does not grant you permission to change its name.
CommandFactionSetNameFailedToSaveFaction=Failed to save faction.
CommandFactionSetNameSuccess=Faction name set to {0}.
CommandFactionSetNameFactionAlreadyExists=A faction by that name already exists.
CommandFactionSetPrefixNotAPlayer=You must be a player in order to set your faction''s prefix
CommandFactionSetPrefixOperationCancelled=Operation cancelled.
CommandFactionSetPrefixPrefixPrompt=Enter the new prefix of the faction, or type ''{0}'' to cancel.
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/lang/lang_fr_FR.properties
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,7 @@ CommandFactionSetNameNameTooLong=Le nom de votre faction ne peut pas d
CommandFactionSetNameNoFactionPermission=Votre rôle dans cette faction ne vous donne pas le droit de changer son nom.
CommandFactionSetNameFailedToSaveFaction=Échec de l''enregistrement de la faction.
CommandFactionSetNameSuccess=Le nom de la faction est réglé sur {0}.
CommandFactionSetNameFactionAlreadyExists=Une faction de ce nom existe déjà.
CommandFactionSetPrefixNotAPlayer=Vous devez être un joueur pour pouvoir définir le préfixe de votre faction.
CommandFactionSetPrefixOperationCancelled=Opération annulée.
CommandFactionSetPrefixPrefixPrompt=Entrez le nouveau préfixe de la faction, ou tapez ''{0}'' pour annuler.
Expand Down

0 comments on commit adfe5e9

Please sign in to comment.