From d88e3d8b053b55b4acac6f5809004d3d2f11cac1 Mon Sep 17 00:00:00 2001 From: EriolEandur Date: Sat, 7 Dec 2024 00:55:58 +0100 Subject: [PATCH] version 2.9.15 adding custom inventory editor --- .../editor/CustomInventoryEditor.java | 8 +++- .../editor/prompt/add/BlockDataPrompt.java | 7 +++- .../editor/prompt/add/BlockTypePrompt.java | 42 ++++++++++++++++--- .../editor/prompt/add/CmdPrompt.java | 35 ++++++++++++++++ .../editor/prompt/add/ColorPrompt.java | 30 +++++++++++++ .../editor/prompt/add/ItemPrompt.java | 19 +++++---- .../prompt/edit/ChangeBlockDataPrompt.java | 25 ++++++++++- .../prompt/edit/ChangeBlockIdPrompt.java | 2 +- .../prompt/edit/ChangeBlockTypePrompt.java | 36 ++++++++++------ .../edit/ChangeCategoryVisiblePrompt.java | 25 ++++++++++- .../editor/prompt/edit/ChangeCmdPrompt.java | 21 ++++++++++ .../editor/prompt/edit/ChangeColorPrompt.java | 21 ++++++++++ .../prompt/edit/ChangeDisplayPrompt.java | 28 ++++++++++++- .../editor/prompt/edit/ChangeItemPrompt.java | 14 ++++++- 14 files changed, 279 insertions(+), 34 deletions(-) create mode 100644 src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/add/CmdPrompt.java create mode 100644 src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/add/ColorPrompt.java create mode 100644 src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/edit/ChangeCmdPrompt.java create mode 100644 src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/edit/ChangeColorPrompt.java diff --git a/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/CustomInventoryEditor.java b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/CustomInventoryEditor.java index 5fe885f..c1e9df0 100644 --- a/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/CustomInventoryEditor.java +++ b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/CustomInventoryEditor.java @@ -135,6 +135,7 @@ public void conversationAbandoned(@NotNull ConversationAbandonedEvent conversati } } + @SuppressWarnings("unchecked") public static void editBlock(Player player, String rpName, String category, CustomInventoryState state, ItemStack inventoryItem) { Conversation conversation = editBlockconversationFactory.buildConversation(player); ConversationContext context = conversation.getContext(); @@ -144,6 +145,7 @@ public static void editBlock(Player player, String rpName, String category, Cust context.setSessionData("id", rpAndId[1]); context.setSessionData("rpName",rpAndId[0]); ConfigurationSection inventoryConfig = getInventoryConfig(rpAndId[0], category); + assert inventoryConfig != null; ConfigurationSection itemSection = inventoryConfig.getConfigurationSection(rpAndId[1]); assert itemSection != null; context.setSessionData("display", itemSection.get("display")); @@ -151,7 +153,11 @@ public static void editBlock(Player player, String rpName, String category, Cust context.setSessionData("cmd", itemSection.get("cmd")); context.setSessionData("display", itemSection.get("display")); context.setSessionData("inCategory", itemSection.contains("category")); - + Map blockData = (Map) context.getSessionData("blockData"); + assert blockData!=null; + itemSection.getKeys(false).stream().filter(key->key.startsWith("blockData")).forEach(key -> { + blockData.put(key.substring(9),itemSection.getString(key)); + }); conversation.begin(); } diff --git a/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/add/BlockDataPrompt.java b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/add/BlockDataPrompt.java index 1926b47..9482a18 100644 --- a/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/add/BlockDataPrompt.java +++ b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/add/BlockDataPrompt.java @@ -32,8 +32,7 @@ public BlockDataPrompt(String... blockStateKeys) { @Override public @NotNull String getPromptText(@NotNull ConversationContext conversationContext) { - return "Make sure you hold in main hand the item you want to add to custom inventory. " + - "Then left-click a block to use for blockData"+blockStateKeys[0]+"."; + return "Left-click a block to use for blockData"+blockStateKeys[0]+"."; } @Override @@ -79,4 +78,8 @@ public void onSelectBlockstate(PlayerInteractEvent event) { } } } + + protected String[] getBlockStateKeys() { + return blockStateKeys; + } } diff --git a/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/add/BlockTypePrompt.java b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/add/BlockTypePrompt.java index ade553e..4af6d7b 100644 --- a/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/add/BlockTypePrompt.java +++ b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/add/BlockTypePrompt.java @@ -6,23 +6,47 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.LinkedHashMap; +import java.util.Arrays; public class BlockTypePrompt extends FixedSetPrompt { public static final String[][] blockData = new String[][]{ {"block", ""}, {"bisected", "Up", "Down"}, - {"four_directions", "North", "West", "South", "East"} + {"four_directions", "North", "West", "South", "East"}, + {"six_faces", "North", "West", "South", "East", "Up", "Down"}, + {"five_faces", "North", "West", "South", "East", "Up"}, + {"three_axis", "X", "Y", "Z"}, + {"branch_twigs",}, + {"branch_horizontal",}, + {"diagonal_connect", "North", "West", "South", "East", "Up" }, + {"block_connect",""}, + {"double_y_block","Upper", "Lower"}, + {"eight_faces", "North", "NorthWest", "West", "SouthWest", "South", "SouthEast", "East", "NorthEast"}, + {"upshift",""}, + {"block_on_water",""}, + {"vanilla"} }; + public BlockTypePrompt() { - super("block", "bisected", "four_directions", "three_axis", "vanilla"); + super(getBlockTypes()); } @Override protected @Nullable Prompt acceptValidatedInput(@NotNull ConversationContext conversationContext, @NotNull String input) { conversationContext.setSessionData("type",input); - return switch(input) { + for (String[] blockDatum : blockData) { + if (input.equalsIgnoreCase(blockDatum[0])) { + String[] blockOrientations = Arrays.copyOfRange(blockDatum, 1, blockDatum.length); + if(blockOrientations.length == 0) { + return new ItemPrompt(); + } else { + return new BlockDataPrompt(blockOrientations); + } + } + } + return END_OF_CONVERSATION; + /*return switch(input) { case "block" -> new BlockDataPrompt(""); case "bisected" -> new BlockDataPrompt("Up", "Down"); case "four_directions" -> new BlockDataPrompt("North", "West", "South", "East"); @@ -33,11 +57,19 @@ public BlockTypePrompt() { case "vanilla" -> new ItemPrompt(); default -> END_OF_CONVERSATION; - }; + };*/ } @Override public @NotNull String getPromptText(@NotNull ConversationContext conversationContext) { return "Which type of block do you want to add? "+formatFixedSet()+" "; } + + public static String[] getBlockTypes() { + String[] result = new String[blockData.length]; + for(int i = 0; i < blockData.length; i++) { + result[i] = blockData[i][0]; + } + return result; + } } diff --git a/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/add/CmdPrompt.java b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/add/CmdPrompt.java new file mode 100644 index 0000000..c622a0d --- /dev/null +++ b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/add/CmdPrompt.java @@ -0,0 +1,35 @@ +package com.mcmiddleearth.architect.specialBlockHandling.customInventories.editor.prompt.add; + +import com.mcmiddleearth.pluginutil.NumericUtil; +import org.bukkit.conversations.ConversationContext; +import org.bukkit.conversations.Prompt; +import org.bukkit.conversations.ValidatingPrompt; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +public class CmdPrompt extends ValidatingPrompt { + + @Override + protected boolean isInputValid(@NotNull ConversationContext conversationContext, @NotNull String input) { + return input.equalsIgnoreCase("!skip") + || NumericUtil.isInt(input) && NumericUtil.getInt(input)>-1; + } + + @Override + protected @Nullable Prompt acceptValidatedInput(@NotNull ConversationContext conversationContext, @NotNull String input) { + if(!input.equalsIgnoreCase("!skip")) { + conversationContext.setSessionData("cmd",NumericUtil.getInt(input)); + } + return new ColorPrompt(); //todo: only for leather + } + + @Override + public @NotNull String getPromptText(@NotNull ConversationContext conversationContext) { + return "Type in a value for custom model data or '!skip'"; //todo prompt current cmd + } + + @Override + protected @Nullable String getFailedValidationText(@NotNull ConversationContext context, @NotNull String invalidInput) { + return "You need to type in a not negative integer or '!skip'."; + } +} diff --git a/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/add/ColorPrompt.java b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/add/ColorPrompt.java new file mode 100644 index 0000000..a6db029 --- /dev/null +++ b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/add/ColorPrompt.java @@ -0,0 +1,30 @@ +package com.mcmiddleearth.architect.specialBlockHandling.customInventories.editor.prompt.add; + +import com.mcmiddleearth.pluginutil.NumericUtil; +import org.bukkit.conversations.ConversationContext; +import org.bukkit.conversations.Prompt; +import org.bukkit.conversations.ValidatingPrompt; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +public class ColorPrompt extends ValidatingPrompt { + + @Override + protected boolean isInputValid(@NotNull ConversationContext conversationContext, @NotNull String input) { + return input.equalsIgnoreCase("!skip") + || NumericUtil.isInt(input) && NumericUtil.getInt(input)>-1; + } + + @Override + protected @Nullable Prompt acceptValidatedInput(@NotNull ConversationContext conversationContext, @NotNull String input) { + if(!input.equalsIgnoreCase("!skip")) { + conversationContext.setSessionData("color", NumericUtil.getInt(input)); + } + return new DisplayPrompt(); + } + + @Override + public @NotNull String getPromptText(@NotNull ConversationContext conversationContext) { + return "Type in a color for leather armor or '!skip'"; + } +} diff --git a/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/add/ItemPrompt.java b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/add/ItemPrompt.java index c648aee..a9b1368 100644 --- a/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/add/ItemPrompt.java +++ b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/add/ItemPrompt.java @@ -1,26 +1,31 @@ package com.mcmiddleearth.architect.specialBlockHandling.customInventories.editor.prompt.add; +import org.bukkit.Material; import org.bukkit.conversations.ConversationContext; import org.bukkit.conversations.FixedSetPrompt; import org.bukkit.conversations.Prompt; +import org.bukkit.conversations.ValidatingPrompt; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -public class ItemPrompt extends FixedSetPrompt { - - public ItemPrompt() { - super("ok"); - } +public class ItemPrompt extends ValidatingPrompt { @Override protected @Nullable Prompt acceptValidatedInput(@NotNull ConversationContext conversationContext, @NotNull String input) { conversationContext.setSessionData("inventoryItem", ((Player)conversationContext.getForWhom()).getInventory().getItemInMainHand()); - return new DisplayPrompt(); + return new CmdPrompt(); + } + + @Override + protected boolean isInputValid(@NotNull ConversationContext context, @NotNull String input) { + return !((Player)context.getForWhom()).getInventory().getItemInMainHand().getType().equals(Material.AIR) + && input.equalsIgnoreCase("ok"); + } @Override public @NotNull String getPromptText(@NotNull ConversationContext conversationContext) { - return "Hold the item you want to add to custom inventory in main hand and type 'ok'"; + return "Hold the item you want to add to custom inventory in main hand and type 'ok'."; } } diff --git a/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/edit/ChangeBlockDataPrompt.java b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/edit/ChangeBlockDataPrompt.java index e0bf077..5955ce0 100644 --- a/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/edit/ChangeBlockDataPrompt.java +++ b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/edit/ChangeBlockDataPrompt.java @@ -1,4 +1,27 @@ package com.mcmiddleearth.architect.specialBlockHandling.customInventories.editor.prompt.edit; -public class ChangeBlockDataPrompt { +import com.mcmiddleearth.architect.specialBlockHandling.customInventories.editor.prompt.add.BlockDataPrompt; +import org.bukkit.conversations.ConversationContext; +import org.jetbrains.annotations.NotNull; + +import java.util.Arrays; + +public class ChangeBlockDataPrompt extends BlockDataPrompt { + + public ChangeBlockDataPrompt(String... blockStateKeys) { + super(blockStateKeys); + } + + @Override + public @NotNull String getPromptText(@NotNull ConversationContext conversationContext) { + return "Current blockData"+getBlockStateKeys()[0]+" is " + +conversationContext.getSessionData(getBlockStateKeys()[0])+". Left-click a block to use for blockData"+getBlockStateKeys()[0]+". Or type !skip!"; + } + + private static String[] getFixedSet(String[] blockstateKeys) { + String[] result = Arrays.copyOf(blockstateKeys, blockstateKeys.length+1); + result[result.length-1] = "!skip"; + return result; + } + } diff --git a/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/edit/ChangeBlockIdPrompt.java b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/edit/ChangeBlockIdPrompt.java index 96a15da..e499fee 100644 --- a/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/edit/ChangeBlockIdPrompt.java +++ b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/edit/ChangeBlockIdPrompt.java @@ -11,7 +11,7 @@ public class ChangeBlockIdPrompt extends ValidatingPrompt { @Override public @NotNull String getPromptText(@NotNull ConversationContext conversationContext) { - return "Type in a new id or '!skip'"; + return "Current item id is "+conversationContext.getSessionData("id")+". Enter a new id or '!skip'."; } @Override diff --git a/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/edit/ChangeBlockTypePrompt.java b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/edit/ChangeBlockTypePrompt.java index c91e58c..0110e3a 100644 --- a/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/edit/ChangeBlockTypePrompt.java +++ b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/edit/ChangeBlockTypePrompt.java @@ -1,17 +1,18 @@ package com.mcmiddleearth.architect.specialBlockHandling.customInventories.editor.prompt.edit; -import com.mcmiddleearth.architect.specialBlockHandling.customInventories.editor.prompt.add.BlockDataPrompt; -import com.mcmiddleearth.architect.specialBlockHandling.customInventories.editor.prompt.add.ItemPrompt; +import com.mcmiddleearth.architect.specialBlockHandling.customInventories.editor.prompt.add.BlockTypePrompt; import org.bukkit.conversations.ConversationContext; import org.bukkit.conversations.FixedSetPrompt; import org.bukkit.conversations.Prompt; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.Arrays; + public class ChangeBlockTypePrompt extends FixedSetPrompt { public ChangeBlockTypePrompt() { - super("block", "bisected", "four_directions", "three_axis", "vanilla", "!skip"); + super(getFixedSet()); } @Override @@ -19,19 +20,28 @@ public ChangeBlockTypePrompt() { if(!input.equalsIgnoreCase("!skip")) { conversationContext.setSessionData("type",input); } - return switch(input) { - case "block" -> new ChangeBlockDataPrompt(""); - case "bisected" -> new ChangeBlockDataPrompt("Up", "Down"); - case "four_directions" -> new ChangeBlockDataPrompt("North", "West", "South", "East"); - case "three_axis" -> new ChangeBlockDataPrompt("X", "Y", "Z"); - case "six_faces" -> new Chan - case "vanilla" -> new ChangeItemPrompt(); - default -> END_OF_CONVERSATION; - }; + for (String[] blockDatum : BlockTypePrompt.blockData) { + if (input.equalsIgnoreCase(blockDatum[0])) { + String[] blockOrientations = Arrays.copyOfRange(blockDatum, 1, blockDatum.length); + if(blockOrientations.length == 0) { + return new ChangeItemPrompt(); + } else { + return new ChangeBlockDataPrompt(blockOrientations); + } + } + } + return END_OF_CONVERSATION; } @Override public @NotNull String getPromptText(@NotNull ConversationContext conversationContext) { - return "Type in a new block type or '!skip'"; + return "Current block type is "+conversationContext.getSessionData("type") + +". Type in a new block type or '!skip' "+formatFixedSet(); + } + + private static String[] getFixedSet() { + String[] result = Arrays.copyOf(BlockTypePrompt.getBlockTypes(), BlockTypePrompt.getBlockTypes().length+1); + result[result.length-1] = "!skip"; + return result; } } diff --git a/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/edit/ChangeCategoryVisiblePrompt.java b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/edit/ChangeCategoryVisiblePrompt.java index 80ac47f..e95c86e 100644 --- a/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/edit/ChangeCategoryVisiblePrompt.java +++ b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/edit/ChangeCategoryVisiblePrompt.java @@ -1,4 +1,27 @@ package com.mcmiddleearth.architect.specialBlockHandling.customInventories.editor.prompt.edit; -public class ChangeCategoryVisiblePrompt { +import org.bukkit.conversations.ConversationContext; +import org.bukkit.conversations.FixedSetPrompt; +import org.bukkit.conversations.Prompt; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +public class ChangeCategoryVisiblePrompt extends FixedSetPrompt { + + public ChangeCategoryVisiblePrompt() { + super("yes", "no", "!skip"); + } + + @Override + protected @Nullable Prompt acceptValidatedInput(@NotNull ConversationContext conversationContext, @NotNull String input) { + if(!input.equalsIgnoreCase("!skip")) { + conversationContext.setSessionData("inCategory", input.equalsIgnoreCase("yes")); + } + return END_OF_CONVERSATION; + } + + @Override + public @NotNull String getPromptText(@NotNull ConversationContext conversationContext) { + return "Should the inventory item be listed directly in the category of it's collection? "+formatFixedSet(); + } } diff --git a/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/edit/ChangeCmdPrompt.java b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/edit/ChangeCmdPrompt.java new file mode 100644 index 0000000..00a5346 --- /dev/null +++ b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/edit/ChangeCmdPrompt.java @@ -0,0 +1,21 @@ +package com.mcmiddleearth.architect.specialBlockHandling.customInventories.editor.prompt.edit; + +import com.mcmiddleearth.architect.specialBlockHandling.customInventories.editor.prompt.add.CmdPrompt; +import org.bukkit.conversations.ConversationContext; +import org.bukkit.conversations.Prompt; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +public class ChangeCmdPrompt extends CmdPrompt { + + @Override + public @NotNull String getPromptText(@NotNull ConversationContext conversationContext) { + return "Current custom model data is "+conversationContext.getSessionData("cmd")+". Type in a new custom model data or '!skip'"; + } + + @Override + protected @Nullable Prompt acceptValidatedInput(@NotNull ConversationContext conversationContext, @NotNull String input) { + super.acceptValidatedInput(conversationContext, input); + return new ChangeColorPrompt(); + } +} diff --git a/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/edit/ChangeColorPrompt.java b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/edit/ChangeColorPrompt.java new file mode 100644 index 0000000..f65a20a --- /dev/null +++ b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/edit/ChangeColorPrompt.java @@ -0,0 +1,21 @@ +package com.mcmiddleearth.architect.specialBlockHandling.customInventories.editor.prompt.edit; + +import com.mcmiddleearth.architect.specialBlockHandling.customInventories.editor.prompt.add.ColorPrompt; +import org.bukkit.conversations.ConversationContext; +import org.bukkit.conversations.Prompt; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +public class ChangeColorPrompt extends ColorPrompt { + + @Override + public @NotNull String getPromptText(@NotNull ConversationContext conversationContext) { + return "Current color is "+conversationContext.getSessionData("color")+". Type in a new color or '!skip'"; + } + + @Override + protected @Nullable Prompt acceptValidatedInput(@NotNull ConversationContext conversationContext, @NotNull String input) { + super.acceptValidatedInput(conversationContext, input); + return new ChangeDisplayPrompt(); + } +} diff --git a/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/edit/ChangeDisplayPrompt.java b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/edit/ChangeDisplayPrompt.java index e424727..44a62e8 100644 --- a/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/edit/ChangeDisplayPrompt.java +++ b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/edit/ChangeDisplayPrompt.java @@ -1,4 +1,30 @@ package com.mcmiddleearth.architect.specialBlockHandling.customInventories.editor.prompt.edit; -public class ChangeDisplayPrompt { +import com.mcmiddleearth.architect.specialBlockHandling.customInventories.CustomInventoryCollectionState; +import com.mcmiddleearth.architect.specialBlockHandling.customInventories.editor.prompt.add.CategoryVisiblePrompt; +import org.bukkit.conversations.ConversationContext; +import org.bukkit.conversations.Prompt; +import org.bukkit.conversations.StringPrompt; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +public class ChangeDisplayPrompt extends StringPrompt { + + @Override + public @NotNull String getPromptText(@NotNull ConversationContext conversationContext) { + return "Current description is "+conversationContext.getSessionData("description") + +". Type in new description for the custom inventory or type '!skip'."; + } + + @Override + public @Nullable Prompt acceptInput(@NotNull ConversationContext conversationContext, @Nullable String input) { + if(input != null && !input.equalsIgnoreCase("!skip")) { + conversationContext.setSessionData("display", input); + } + if(conversationContext.getSessionData("state") instanceof CustomInventoryCollectionState) { + return new ChangeCategoryVisiblePrompt(); + } else { + return END_OF_CONVERSATION; + } + } } diff --git a/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/edit/ChangeItemPrompt.java b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/edit/ChangeItemPrompt.java index 9a03ad0..9d0bcaf 100644 --- a/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/edit/ChangeItemPrompt.java +++ b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/edit/ChangeItemPrompt.java @@ -1,6 +1,7 @@ package com.mcmiddleearth.architect.specialBlockHandling.customInventories.editor.prompt.edit; import com.mcmiddleearth.architect.specialBlockHandling.customInventories.editor.prompt.add.DisplayPrompt; +import org.bukkit.Material; import org.bukkit.conversations.ConversationContext; import org.bukkit.conversations.FixedSetPrompt; import org.bukkit.conversations.Prompt; @@ -16,8 +17,17 @@ public ChangeItemPrompt() { @Override protected @Nullable Prompt acceptValidatedInput(@NotNull ConversationContext conversationContext, @NotNull String input) { - conversationContext.setSessionData("inventoryItem", ((Player)conversationContext.getForWhom()).getInventory().getItemInMainHand()); - return new DisplayPrompt(); + if(!input.equalsIgnoreCase("!skip")) { + conversationContext.setSessionData("inventoryItem", ((Player) conversationContext.getForWhom()).getInventory().getItemInMainHand()); + } + return new ChangeCmdPrompt(); + } + + @Override + protected boolean isInputValid(@NotNull ConversationContext context, @NotNull String input) { + return !((Player)context.getForWhom()).getInventory().getItemInMainHand().getType().equals(Material.AIR) + && super.isInputValid(context, input) + || input.equalsIgnoreCase("!skip"); } @Override