feat: implemented conversations for name/skin change
This commit is contained in:
parent
b908e0562f
commit
2c7ee30ad2
1 changed files with 41 additions and 24 deletions
|
@ -8,7 +8,6 @@ import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import xyz.ineanto.nicko.Nicko;
|
import xyz.ineanto.nicko.Nicko;
|
||||||
import xyz.ineanto.nicko.gui.prompt.Prompt;
|
import xyz.ineanto.nicko.gui.prompt.Prompt;
|
||||||
import xyz.ineanto.nicko.language.PlayerLanguage;
|
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
@ -19,7 +18,6 @@ public class ConversationPrompt extends Prompt {
|
||||||
private final Player player;
|
private final Player player;
|
||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
private String skin;
|
|
||||||
|
|
||||||
public ConversationPrompt(Player player) {
|
public ConversationPrompt(Player player) {
|
||||||
super(player);
|
super(player);
|
||||||
|
@ -30,15 +28,26 @@ public class ConversationPrompt extends Prompt {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void displayNameThenSkinPrompt() {
|
public void displayNameThenSkinPrompt() {
|
||||||
|
conversationFactory
|
||||||
|
.thatExcludesNonPlayersWithMessage("Player only")
|
||||||
|
.withTimeout(30)
|
||||||
|
.withModality(false)
|
||||||
|
.withFirstPrompt(new ChangeNameConversation())
|
||||||
|
.withEscapeSequence("EXIT")
|
||||||
|
.withInitialSessionData(Map.of(identifier, true, identifier + "-both", true))
|
||||||
|
.withLocalEcho(false)
|
||||||
|
.buildConversation(player)
|
||||||
|
.begin();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void displaySkinPrompt() {
|
public void displaySkinPrompt() {
|
||||||
conversationFactory
|
conversationFactory
|
||||||
.thatExcludesNonPlayersWithMessage("Player only")
|
.thatExcludesNonPlayersWithMessage("Player only")
|
||||||
|
.withModality(false)
|
||||||
.withTimeout(30)
|
.withTimeout(30)
|
||||||
.withFirstPrompt(new ChangeAppearanceConversation(player, playerLanguage))
|
.withFirstPrompt(new ChangeSkinConversation())
|
||||||
.withInitialSessionData(Map.of(identifier, true, identifier + "-skin", true))
|
.withEscapeSequence("EXIT")
|
||||||
.withLocalEcho(false)
|
.withLocalEcho(false)
|
||||||
.buildConversation(player)
|
.buildConversation(player)
|
||||||
.begin();
|
.begin();
|
||||||
|
@ -46,37 +55,45 @@ public class ConversationPrompt extends Prompt {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void displayNamePrompt() {
|
public void displayNamePrompt() {
|
||||||
|
conversationFactory
|
||||||
|
.thatExcludesNonPlayersWithMessage("Player only")
|
||||||
|
.withModality(false)
|
||||||
|
.withTimeout(30)
|
||||||
|
.withFirstPrompt(new ChangeNameConversation())
|
||||||
|
.withEscapeSequence("EXIT")
|
||||||
|
.withLocalEcho(false)
|
||||||
|
.buildConversation(player)
|
||||||
|
.begin();
|
||||||
}
|
}
|
||||||
|
|
||||||
private class ChangeAppearanceConversation extends StringPrompt {
|
private class ChangeNameConversation extends StringPrompt {
|
||||||
private final Player player;
|
|
||||||
private final PlayerLanguage playerLanguage;
|
|
||||||
|
|
||||||
public ChangeAppearanceConversation(Player player, PlayerLanguage playerLanguage) {
|
|
||||||
this.player = player;
|
|
||||||
this.playerLanguage = playerLanguage;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull String getPromptText(@NotNull ConversationContext context) {
|
public @NotNull String getPromptText(@NotNull ConversationContext context) {
|
||||||
|
|
||||||
if (Objects.equals(context.getSessionData(identifier + "-skin"), true)) {
|
|
||||||
// If changing skin
|
|
||||||
return "Enter your new skin";
|
|
||||||
}
|
|
||||||
|
|
||||||
return "Enter your new name";
|
return "Enter your new name";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Nullable org.bukkit.conversations.Prompt acceptInput(@NotNull ConversationContext context, @Nullable String input) {
|
public @Nullable org.bukkit.conversations.Prompt acceptInput(@NotNull ConversationContext context, @Nullable String input) {
|
||||||
if (Objects.equals(context.getSessionData(identifier + "-skin"), true)) {
|
if (Objects.equals(context.getSessionData(identifier + "-both"), true)) {
|
||||||
skin = input;
|
name = input;
|
||||||
update(null, skin, true);
|
return new ChangeSkinConversation();
|
||||||
return END_OF_CONVERSATION;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
update(input, null, false);
|
||||||
|
return END_OF_CONVERSATION;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private class ChangeSkinConversation extends StringPrompt {
|
||||||
|
@Override
|
||||||
|
public @NotNull String getPromptText(@NotNull ConversationContext context) {
|
||||||
|
return "Enter your new skin";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @Nullable org.bukkit.conversations.Prompt acceptInput(@NotNull ConversationContext context, @Nullable String input) {
|
||||||
|
update(name != null ? name : null, input, true);
|
||||||
|
name = null;
|
||||||
return END_OF_CONVERSATION;
|
return END_OF_CONVERSATION;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue