mirror of
https://github.com/BentoBoxWorld/Challenges.git
synced 2024-12-01 06:53:37 +01:00
Added a uniqueId sanitization when creating challenges/levels
This will help fixing issues with spaces, hyphens and accents in non-English languages.
This commit is contained in:
parent
0ae84ec850
commit
db971d81ab
@ -1,6 +1,7 @@
|
|||||||
package world.bentobox.challenges.panel.admin;
|
package world.bentobox.challenges.panel.admin;
|
||||||
|
|
||||||
|
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
@ -252,7 +253,7 @@ public class AdminGUI extends CommonGUI
|
|||||||
clickHandler = (panel, user, clickType, slot) -> {
|
clickHandler = (panel, user, clickType, slot) -> {
|
||||||
|
|
||||||
this.getNewUniqueID(challenge -> {
|
this.getNewUniqueID(challenge -> {
|
||||||
String newName = Utils.getGameMode(this.world) + "_" + challenge;
|
String uniqueId = Utils.getGameMode(this.world) + "_" + challenge;
|
||||||
|
|
||||||
ChallengeTypeGUI.open(user,
|
ChallengeTypeGUI.open(user,
|
||||||
this.addon.getChallengesSettings().getLoreLineLength(),
|
this.addon.getChallengesSettings().getLoreLineLength(),
|
||||||
@ -260,15 +261,15 @@ public class AdminGUI extends CommonGUI
|
|||||||
new EditChallengeGUI(this.addon,
|
new EditChallengeGUI(this.addon,
|
||||||
this.world,
|
this.world,
|
||||||
this.user,
|
this.user,
|
||||||
this.addon.getChallengesManager().createChallenge(newName, type, requirements),
|
this.addon.getChallengesManager().createChallenge(uniqueId, type, requirements),
|
||||||
this.topLabel,
|
this.topLabel,
|
||||||
this.permissionPrefix,
|
this.permissionPrefix,
|
||||||
this).build();
|
this).build();
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
input -> {
|
input -> {
|
||||||
String newName = Utils.getGameMode(this.world) + "_" + input;
|
String uniqueId = Utils.getGameMode(this.world) + "_" + input;
|
||||||
return !this.addon.getChallengesManager().containsChallenge(newName);
|
return !this.addon.getChallengesManager().containsChallenge(uniqueId);
|
||||||
},
|
},
|
||||||
this.user.getTranslation("challenges.gui.questions.admin.unique-id")
|
this.user.getTranslation("challenges.gui.questions.admin.unique-id")
|
||||||
);
|
);
|
||||||
@ -659,7 +660,7 @@ public class AdminGUI extends CommonGUI
|
|||||||
@Override
|
@Override
|
||||||
protected boolean isInputValid(ConversationContext context, String input)
|
protected boolean isInputValid(ConversationContext context, String input)
|
||||||
{
|
{
|
||||||
return stringValidation.apply(input);
|
return stringValidation.apply(sanitizeInput(input));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -679,7 +680,7 @@ public class AdminGUI extends CommonGUI
|
|||||||
protected String getFailedValidationText(ConversationContext context,
|
protected String getFailedValidationText(ConversationContext context,
|
||||||
String invalidInput)
|
String invalidInput)
|
||||||
{
|
{
|
||||||
return user.getTranslation("challenges.errors.unique-id", "[id]", invalidInput);
|
return user.getTranslation("challenges.errors.unique-id", "[id]", sanitizeInput(invalidInput));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -699,7 +700,7 @@ public class AdminGUI extends CommonGUI
|
|||||||
protected Prompt acceptValidatedInput(ConversationContext context, String input)
|
protected Prompt acceptValidatedInput(ConversationContext context, String input)
|
||||||
{
|
{
|
||||||
// Add answer to consumer.
|
// Add answer to consumer.
|
||||||
consumer.accept(input);
|
consumer.accept(sanitizeInput(input));
|
||||||
// End conversation
|
// End conversation
|
||||||
return Prompt.END_OF_CONVERSATION;
|
return Prompt.END_OF_CONVERSATION;
|
||||||
}
|
}
|
||||||
@ -710,4 +711,14 @@ public class AdminGUI extends CommonGUI
|
|||||||
|
|
||||||
conversation.begin();
|
conversation.begin();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sanitizes the provided input.
|
||||||
|
* It replaces spaces and hyphens with underscores and lowercases the input.
|
||||||
|
* @param input input to sanitize
|
||||||
|
* @return sanitized input
|
||||||
|
*/
|
||||||
|
private String sanitizeInput(String input) {
|
||||||
|
return input.toLowerCase(Locale.ENGLISH).replace(" ", "_").replace("-", "_");
|
||||||
|
}
|
||||||
}
|
}
|
@ -507,7 +507,7 @@ challenges:
|
|||||||
|
|
||||||
admin:
|
admin:
|
||||||
number: "Write a number in the chat and press enter."
|
number: "Write a number in the chat and press enter."
|
||||||
unique-id: "Write the object's unique name and press enter."
|
unique-id: "Write the object's unique id and press enter."
|
||||||
challenge-name: "Write the display name in the chat for the current challenge."
|
challenge-name: "Write the display name in the chat for the current challenge."
|
||||||
level-name: "Write the display name in chat for the current level."
|
level-name: "Write the display name in chat for the current level."
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user