From e94664201abb099589fffbcb2e8ec079b1838a69 Mon Sep 17 00:00:00 2001 From: EriolEandur Date: Wed, 4 Dec 2024 22:12:20 +0100 Subject: [PATCH 1/5] version 2.9.15 adding custom inventory editor --- pom.xml | 2 +- .../architect/ArchitectPlugin.java | 4 +- .../mcmiddleearth/architect/Permission.java | 1 + .../customInventories/CustomInventory.java | 20 +++++ .../CustomInventoryCollectionState.java | 4 + .../CustomInventoryState.java | 4 + .../editor/CustomInventoryEditor.java | 77 +++++++++++++++++++ .../editor/prompt/BlockDataPrompt.java | 70 +++++++++++++++++ .../editor/prompt/BlockIdPrompt.java | 28 +++++++ .../editor/prompt/BlockTypePrompt.java | 31 ++++++++ .../editor/prompt/DisplayPrompt.java | 21 +++++ .../data/SpecialBlockInventoryData.java | 2 +- 12 files changed, 261 insertions(+), 3 deletions(-) create mode 100644 src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/CustomInventoryEditor.java create mode 100644 src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/BlockDataPrompt.java create mode 100644 src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/BlockIdPrompt.java create mode 100644 src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/BlockTypePrompt.java create mode 100644 src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/DisplayPrompt.java diff --git a/pom.xml b/pom.xml index afb785b..58e9a5f 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ 4.0.0 com.mcmiddleearth MCME-Architect - 2.9.14 + 2.9.15-snapshot jar UTF-8 diff --git a/src/main/java/com/mcmiddleearth/architect/ArchitectPlugin.java b/src/main/java/com/mcmiddleearth/architect/ArchitectPlugin.java index 088a337..49f2804 100644 --- a/src/main/java/com/mcmiddleearth/architect/ArchitectPlugin.java +++ b/src/main/java/com/mcmiddleearth/architect/ArchitectPlugin.java @@ -32,6 +32,7 @@ import com.mcmiddleearth.architect.specialBlockHandling.command.GetCommand; import com.mcmiddleearth.architect.specialBlockHandling.command.InvCommand; import com.mcmiddleearth.architect.specialBlockHandling.command.SwitchStickCommand; +import com.mcmiddleearth.architect.specialBlockHandling.customInventories.editor.CustomInventoryEditor; import com.mcmiddleearth.architect.specialBlockHandling.data.*; import com.mcmiddleearth.architect.specialBlockHandling.itemBlock.ItemBlockCommand; import com.mcmiddleearth.architect.specialBlockHandling.itemBlock.ItemBlockListener; @@ -146,7 +147,8 @@ public void onEnable() { setCommandExecutor("switchstick", new SwitchStickCommand()); //setCommandExecutor("speed", new SpeedCommand()); // setCommandExecutor("newafkk", new NewAfkCommand()); - + + CustomInventoryEditor.init(this); rpSwitchTask = new RPSwitchTask().runTaskTimer(this, 500, 20); ItemBlockManager.startEntityGlowTask(); diff --git a/src/main/java/com/mcmiddleearth/architect/Permission.java b/src/main/java/com/mcmiddleearth/architect/Permission.java index cb45f9c..ae9640c 100644 --- a/src/main/java/com/mcmiddleearth/architect/Permission.java +++ b/src/main/java/com/mcmiddleearth/architect/Permission.java @@ -63,6 +63,7 @@ public enum Permission { INV_COMMAND ("architect.inventory"), INV_OTHER ("architect.inventory.other"), INV_SAVE ("architect.inventory.save"), + INV_EDIT ("architect.inventory.edit"), INV_RELOAD_COMMAND ("architect.inventory.reload"), INVENTORY_OPEN ("architect.inventory.open"), NO_PHYSICS_LIST ("architect.noPhysicsList.view"), diff --git a/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/CustomInventory.java b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/CustomInventory.java index 4d9431a..14a3d4d 100644 --- a/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/CustomInventory.java +++ b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/CustomInventory.java @@ -22,9 +22,13 @@ */ import com.mcmiddleearth.architect.ArchitectPlugin; +import com.mcmiddleearth.architect.Permission; +import com.mcmiddleearth.architect.serverResoucePack.RpManager; +import com.mcmiddleearth.architect.specialBlockHandling.customInventories.editor.CustomInventoryEditor; import com.mcmiddleearth.architect.specialBlockHandling.data.SpecialBlockInventoryData; import com.mcmiddleearth.architect.specialBlockHandling.data.SpecialHeadInventoryData; import com.mcmiddleearth.architect.specialBlockHandling.data.SpecialItemInventoryData; +import com.mcmiddleearth.architect.specialBlockHandling.specialBlocks.SpecialBlock; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.entity.Player; @@ -339,6 +343,22 @@ void onCategoryChange(final InventoryClickEvent event) { } } } + + @EventHandler(priority = EventPriority.HIGHEST) + void onInventoryEdit(final InventoryClickEvent event) { + if (openInventories.containsKey(event.getInventory())) { //.getTitle.equals(name)) { + if (event.getWhoClicked() instanceof Player player + && player.hasPermission(Permission.INV_EDIT.getPermissionNode()) + && event.getRawSlot() >= CATEGORY_SLOTS + && event.getCurrentItem() == null) {//items.size()/9+1)*9 + CustomInventoryState state = openInventories.get(event.getInventory()); + String category = state.categoryNames[state.currentCategory]; + String rpName = RpManager.getCurrentRpName(state.getPlayer()); + event.getInventory().close(); + CustomInventoryEditor.addBlock(player, rpName, category, state); + } + } + } @EventHandler(priority=EventPriority.MONITOR, ignoreCancelled=true) void onClose(final InventoryCloseEvent event) { diff --git a/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/CustomInventoryCollectionState.java b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/CustomInventoryCollectionState.java index ed75f94..19df8a9 100644 --- a/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/CustomInventoryCollectionState.java +++ b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/CustomInventoryCollectionState.java @@ -212,4 +212,8 @@ public boolean isDirectGet() { public void setDirectGet(boolean directGet) { this.directGet = directGet; } + + public SpecialBlock getBaseBlock() { + return baseBlock; + } } \ No newline at end of file diff --git a/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/CustomInventoryState.java b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/CustomInventoryState.java index fb7ecc3..262d6f2 100644 --- a/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/CustomInventoryState.java +++ b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/CustomInventoryState.java @@ -281,4 +281,8 @@ public static ItemStack newPagingItem(Material material, int cmd, String display } public abstract boolean usesSubcategories(); + + public Player getPlayer() { + return player; + } } \ No newline at end of file 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 new file mode 100644 index 0000000..8b37ece --- /dev/null +++ b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/CustomInventoryEditor.java @@ -0,0 +1,77 @@ +package com.mcmiddleearth.architect.specialBlockHandling.customInventories.editor; + +import com.mcmiddleearth.architect.specialBlockHandling.customInventories.CustomInventoryState; +import com.mcmiddleearth.architect.specialBlockHandling.customInventories.editor.prompt.BlockIdPrompt; +import com.mcmiddleearth.architect.specialBlockHandling.customInventories.editor.prompt.BlockTypePrompt; +import com.mcmiddleearth.architect.specialBlockHandling.data.SpecialBlockInventoryData; +import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.configuration.InvalidConfigurationException; +import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.conversations.*; +import org.bukkit.entity.Player; +import org.bukkit.plugin.Plugin; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.io.File; +import java.io.IOException; +import java.util.HashMap; +import java.util.Locale; +import java.util.Map; +import java.util.Objects; + +public class CustomInventoryEditor { + + private static ConversationFactory addBlockconversationFactory; + + public static void init(Plugin plugin) { + Map sessionData = new HashMap<>(); + sessionData.put("blockData", new HashMap()); + addBlockconversationFactory = new ConversationFactory(plugin) + .withModality(false) + .withEscapeSequence("!cancel") + .withTimeout(120) + .withLocalEcho(true) + .withPrefix(conversationContext -> "[Inventory Editor] ") + .withInitialSessionData(sessionData) + .addConversationAbandonedListener(new AddBlockExecutor()) + .withFirstPrompt(new BlockIdPrompt()); + } + + public static void addBlock(Player player, String rpName, String category, CustomInventoryState state) { + Conversation conversation = addBlockconversationFactory.buildConversation(player); + ConversationContext context = conversation.getContext(); + context.setSessionData("rpName",rpName); + context.setSessionData("category", category); + context.setSessionData("state", state); + conversation.begin(); + } + + public static class AddBlockExecutor implements ConversationAbandonedListener { + @Override + public void conversationAbandoned(@NotNull ConversationAbandonedEvent conversationAbandonedEvent) { + if(conversationAbandonedEvent.gracefulExit()) { + ConversationContext context = conversationAbandonedEvent.getContext(); + File rpFolder = new File(SpecialBlockInventoryData.configFolder, + (String) Objects.requireNonNull(context.getSessionData("rpName"))); + File categoryFile = new File(rpFolder, context.getSessionData("category")+".yml"); + if(categoryFile.exists()) { + YamlConfiguration config = new YamlConfiguration(); + try { + config.load(categoryFile); + ConfigurationSection items = config.getConfigurationSection("Items"); + assert items != null; + ConfigurationSection newSection = items.createSection((String) Objects.requireNonNull(context + .getSessionData("id"))); + newSection.set("display", context.getSessionData("display")); + newSection.set("type", Objects.requireNonNull(context.getSessionData("type")).toString() + .toUpperCase()); + + } catch (IOException | InvalidConfigurationException e) { + e.printStackTrace(); + } + } + } + } + } +} diff --git a/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/BlockDataPrompt.java b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/BlockDataPrompt.java new file mode 100644 index 0000000..5608e08 --- /dev/null +++ b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/BlockDataPrompt.java @@ -0,0 +1,70 @@ +package com.mcmiddleearth.architect.specialBlockHandling.customInventories.editor.prompt; + +import org.bukkit.Bukkit; +import org.bukkit.block.Block; +import org.bukkit.conversations.ConversationContext; +import org.bukkit.conversations.Prompt; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.block.Action; +import org.bukkit.event.player.PlayerInteractEvent; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.Arrays; +import java.util.Map; +import java.util.Objects; + +public class BlockDataPrompt implements Prompt, Listener { + + private boolean done = false; + + private boolean listenerRegistered = false; + + private ConversationContext conversationContext; + + private final String[] blockStateKeys; + + public BlockDataPrompt(String... blockStateKeys) { + this.blockStateKeys = blockStateKeys; + } + + @Override + public @NotNull String getPromptText(@NotNull ConversationContext conversationContext) { + return "Left-click a block for blockData"+blockStateKeys[0]+"."; + } + + @Override + public boolean blocksForInput(@NotNull ConversationContext conversationContext) { + if(!listenerRegistered) { + this.conversationContext = conversationContext; + Bukkit.getPluginManager().registerEvents(this, Objects.requireNonNull(conversationContext.getPlugin())); + listenerRegistered = true; + } + return !done; + } + + @Override + public @Nullable Prompt acceptInput(@NotNull ConversationContext conversationContext, @Nullable String input) { + if(blockStateKeys.length>1) { + return new BlockDataPrompt(Arrays.copyOfRange(blockStateKeys,1,blockStateKeys.length)); + } else { + return new DisplayPrompt(); + } + } + + @EventHandler(priority = EventPriority.LOWEST) + public void onSelectBlockstate(PlayerInteractEvent event) { + if(event.getAction().equals(Action.LEFT_CLICK_BLOCK) + && event.hasItem()) { + Block block = event.getClickedBlock(); + if(block != null) { + ((Map) Objects.requireNonNull(conversationContext.getSessionData("blockData"))) + .put(blockStateKeys[0], block.getBlockData().getAsString()); + conversationContext.setSessionData("inventoryItem", event.getItem()); + done = true; + } + } + } +} diff --git a/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/BlockIdPrompt.java b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/BlockIdPrompt.java new file mode 100644 index 0000000..067be23 --- /dev/null +++ b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/BlockIdPrompt.java @@ -0,0 +1,28 @@ +package com.mcmiddleearth.architect.specialBlockHandling.customInventories.editor.prompt; + +import com.mcmiddleearth.architect.specialBlockHandling.data.SpecialBlockInventoryData; +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 BlockIdPrompt extends ValidatingPrompt { + + @Override + public @NotNull String getPromptText(@NotNull ConversationContext conversationContext) { + return "Type in an unique ID for the new block!"; + } + + @Override + protected boolean isInputValid(@NotNull ConversationContext conversationContext, @NotNull String input) { + return SpecialBlockInventoryData.getSpecialBlock(conversationContext.getSessionData("rpName")+"/"+input) + == null; + } + + @Override + protected @Nullable Prompt acceptValidatedInput(@NotNull ConversationContext conversationContext, @NotNull String input) { + conversationContext.setSessionData("id", input); + return new BlockTypePrompt(); + } +} diff --git a/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/BlockTypePrompt.java b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/BlockTypePrompt.java new file mode 100644 index 0000000..5722727 --- /dev/null +++ b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/BlockTypePrompt.java @@ -0,0 +1,31 @@ +package com.mcmiddleearth.architect.specialBlockHandling.customInventories.editor.prompt; + +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 BlockTypePrompt extends FixedSetPrompt { + + public BlockTypePrompt() { + super("block", "bisected", "four_directions", "three_axis", "vanilla"); + } + + @Override + protected @Nullable Prompt acceptValidatedInput(@NotNull ConversationContext conversationContext, @NotNull String input) { + conversationContext.setSessionData("type",input); + return switch(input) { + case "block" -> new BlockDataPrompt(""); + case "bisected" -> new BlockDataPrompt("Up", "Down"); + case "four_directions" -> new BlockDataPrompt("North", "West", "South", "East"); + case "three_axis" -> new BlockDataPrompt("X", "Y", "Z"); + default -> END_OF_CONVERSATION; + }; + } + + @Override + public @NotNull String getPromptText(@NotNull ConversationContext conversationContext) { + return "Which type of block do you want to add? "+formatFixedSet()+" "; + } +} diff --git a/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/DisplayPrompt.java b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/DisplayPrompt.java new file mode 100644 index 0000000..1273674 --- /dev/null +++ b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/DisplayPrompt.java @@ -0,0 +1,21 @@ +package com.mcmiddleearth.architect.specialBlockHandling.customInventories.editor.prompt; + +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 DisplayPrompt extends StringPrompt { + + @Override + public @NotNull String getPromptText(@NotNull ConversationContext conversationContext) { + return "Enter a block description for the custom inventory:"; + } + + @Override + public @Nullable Prompt acceptInput(@NotNull ConversationContext conversationContext, @Nullable String input) { + conversationContext.setSessionData("display", input); + return END_OF_CONVERSATION; + } +} diff --git a/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/data/SpecialBlockInventoryData.java b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/data/SpecialBlockInventoryData.java index 82d2d72..18b8e12 100644 --- a/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/data/SpecialBlockInventoryData.java +++ b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/data/SpecialBlockInventoryData.java @@ -62,7 +62,7 @@ public class SpecialBlockInventoryData { private static final String configLocator = "inventories"; - private static final File configFolder = new File(ArchitectPlugin.getPluginInstance() + public static final File configFolder = new File(ArchitectPlugin.getPluginInstance() .getDataFolder(),configLocator+"/block"); static { From e3ed7882ef78f564c577994e7c8a1292bfac5f17 Mon Sep 17 00:00:00 2001 From: EriolEandur Date: Thu, 5 Dec 2024 00:34:37 +0100 Subject: [PATCH 2/5] version 2.9.15 adding custom inventory editor --- .../editor/CustomInventoryEditor.java | 18 +++++++++++++ .../editor/prompt/CategoryVisiblePrompt.java | 25 +++++++++++++++++++ .../editor/prompt/DisplayPrompt.java | 7 +++++- 3 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/CategoryVisiblePrompt.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 8b37ece..9f5eba3 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 @@ -9,6 +9,8 @@ import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.conversations.*; import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.plugin.Plugin; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -44,6 +46,7 @@ public static void addBlock(Player player, String rpName, String category, Custo context.setSessionData("rpName",rpName); context.setSessionData("category", category); context.setSessionData("state", state); + context.setSessionData("inCategory", true); conversation.begin(); } @@ -66,7 +69,22 @@ public void conversationAbandoned(@NotNull ConversationAbandonedEvent conversati newSection.set("display", context.getSessionData("display")); newSection.set("type", Objects.requireNonNull(context.getSessionData("type")).toString() .toUpperCase()); + ItemStack item = (ItemStack) context.getSessionData("inventoryItem"); + assert item != null; + ItemMeta meta = item.getItemMeta(); + newSection.set("itemMaterial", item.getType().name()); + newSection.set("cmd", meta.getCustomModelData()); + if((Boolean) context.getSessionData("inCategory")) { + newSection.set("category",context.getSessionData("category")); + } + Map blockData = (Map) context.getSessionData("blockData"); + assert blockData != null; + for(Map.Entry entry: blockData.entrySet()) { + newSection.set(entry.getKey(), entry.getValue()); + } + config.save(categoryFile); + SpecialBlockInventoryData.loadInventories(); } catch (IOException | InvalidConfigurationException e) { e.printStackTrace(); } diff --git a/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/CategoryVisiblePrompt.java b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/CategoryVisiblePrompt.java new file mode 100644 index 0000000..9c0eae5 --- /dev/null +++ b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/CategoryVisiblePrompt.java @@ -0,0 +1,25 @@ +package com.mcmiddleearth.architect.specialBlockHandling.customInventories.editor.prompt; + +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 CategoryVisiblePrompt extends FixedSetPrompt { + + public CategoryVisiblePrompt() { + super("yes", "no"); + } + + @Override + public @NotNull String getPromptText(@NotNull ConversationContext conversationContext) { + return "Should the new inventory item be listed directly in the category of it's collection. "+formatFixedSet(); + } + + @Override + protected @Nullable Prompt acceptValidatedInput(@NotNull ConversationContext conversationContext, @NotNull String input) { + conversationContext.setSessionData("inCategory", input.equalsIgnoreCase("yes")); + return END_OF_CONVERSATION; + } +} diff --git a/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/DisplayPrompt.java b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/DisplayPrompt.java index 1273674..7b33b96 100644 --- a/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/DisplayPrompt.java +++ b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/DisplayPrompt.java @@ -1,5 +1,6 @@ package com.mcmiddleearth.architect.specialBlockHandling.customInventories.editor.prompt; +import com.mcmiddleearth.architect.specialBlockHandling.customInventories.CustomInventoryCollectionState; import org.bukkit.conversations.ConversationContext; import org.bukkit.conversations.Prompt; import org.bukkit.conversations.StringPrompt; @@ -16,6 +17,10 @@ public class DisplayPrompt extends StringPrompt { @Override public @Nullable Prompt acceptInput(@NotNull ConversationContext conversationContext, @Nullable String input) { conversationContext.setSessionData("display", input); - return END_OF_CONVERSATION; + if(conversationContext.getSessionData("state") instanceof CustomInventoryCollectionState) { + return new CategoryVisiblePrompt(); + } else { + return END_OF_CONVERSATION; + } } } From 81af16ad4e7e2b542cf7cfd39aca0221089c0c7c Mon Sep 17 00:00:00 2001 From: EriolEandur Date: Fri, 6 Dec 2024 00:00:17 +0100 Subject: [PATCH 3/5] version 2.9.15 adding custom inventory editor --- .../customInventories/CustomInventory.java | 10 +- .../editor/CustomInventoryEditor.java | 207 ++++++++++++++++-- .../prompt/{ => add}/BlockDataPrompt.java | 38 ++-- .../prompt/{ => add}/BlockIdPrompt.java | 2 +- .../prompt/{ => add}/BlockTypePrompt.java | 14 +- .../{ => add}/CategoryVisiblePrompt.java | 2 +- .../prompt/{ => add}/DisplayPrompt.java | 2 +- .../editor/prompt/add/ItemPrompt.java | 26 +++ .../prompt/edit/ChangeBlockDataPrompt.java | 4 + .../prompt/edit/ChangeBlockIdPrompt.java | 30 +++ .../prompt/edit/ChangeBlockTypePrompt.java | 37 ++++ .../edit/ChangeCategoryVisiblePrompt.java | 4 + .../prompt/edit/ChangeDisplayPrompt.java | 4 + .../editor/prompt/edit/ChangeItemPrompt.java | 27 +++ .../editor/prompt/edit/EditPrompt.java | 29 +++ src/main/resources/plugin.yml | 8 +- 16 files changed, 409 insertions(+), 35 deletions(-) rename src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/{ => add}/BlockDataPrompt.java (56%) rename src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/{ => add}/BlockIdPrompt.java (97%) rename src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/{ => add}/BlockTypePrompt.java (71%) rename src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/{ => add}/CategoryVisiblePrompt.java (96%) rename src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/{ => add}/DisplayPrompt.java (97%) create mode 100644 src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/add/ItemPrompt.java create mode 100644 src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/edit/ChangeBlockDataPrompt.java create mode 100644 src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/edit/ChangeBlockIdPrompt.java create mode 100644 src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/edit/ChangeBlockTypePrompt.java create mode 100644 src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/edit/ChangeCategoryVisiblePrompt.java create mode 100644 src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/edit/ChangeDisplayPrompt.java create mode 100644 src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/edit/ChangeItemPrompt.java create mode 100644 src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/edit/EditPrompt.java diff --git a/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/CustomInventory.java b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/CustomInventory.java index 14a3d4d..c36b236 100644 --- a/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/CustomInventory.java +++ b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/CustomInventory.java @@ -350,12 +350,18 @@ void onInventoryEdit(final InventoryClickEvent event) { if (event.getWhoClicked() instanceof Player player && player.hasPermission(Permission.INV_EDIT.getPermissionNode()) && event.getRawSlot() >= CATEGORY_SLOTS - && event.getCurrentItem() == null) {//items.size()/9+1)*9 + && event.getRawSlot() < event.getInventory().getSize() + && event.isRightClick() + && event.isShiftClick()) {//items.size()/9+1)*9 CustomInventoryState state = openInventories.get(event.getInventory()); String category = state.categoryNames[state.currentCategory]; String rpName = RpManager.getCurrentRpName(state.getPlayer()); event.getInventory().close(); - CustomInventoryEditor.addBlock(player, rpName, category, state); + if(event.getCurrentItem() == null) { + CustomInventoryEditor.addBlock(player, rpName, category, state, event.getRawSlot()); + } else { + CustomInventoryEditor.editBlock(player, rpName, category, state, event.getCurrentItem()); + } } } } 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 9f5eba3..5fe885f 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 @@ -1,9 +1,14 @@ package com.mcmiddleearth.architect.specialBlockHandling.customInventories.editor; +import com.mcmiddleearth.architect.PluginData; +import com.mcmiddleearth.architect.specialBlockHandling.customInventories.CustomInventory; +import com.mcmiddleearth.architect.specialBlockHandling.customInventories.CustomInventoryCollectionState; import com.mcmiddleearth.architect.specialBlockHandling.customInventories.CustomInventoryState; -import com.mcmiddleearth.architect.specialBlockHandling.customInventories.editor.prompt.BlockIdPrompt; -import com.mcmiddleearth.architect.specialBlockHandling.customInventories.editor.prompt.BlockTypePrompt; +import com.mcmiddleearth.architect.specialBlockHandling.customInventories.editor.prompt.add.BlockIdPrompt; +import com.mcmiddleearth.architect.specialBlockHandling.customInventories.editor.prompt.edit.EditPrompt; import com.mcmiddleearth.architect.specialBlockHandling.data.SpecialBlockInventoryData; +import com.mcmiddleearth.architect.specialBlockHandling.specialBlocks.SpecialBlock; +import org.bukkit.ChatColor; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.InvalidConfigurationException; import org.bukkit.configuration.file.YamlConfiguration; @@ -13,18 +18,18 @@ import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.plugin.Plugin; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import java.io.File; import java.io.IOException; import java.util.HashMap; -import java.util.Locale; import java.util.Map; import java.util.Objects; +import java.util.logging.Logger; public class CustomInventoryEditor { private static ConversationFactory addBlockconversationFactory; + private static ConversationFactory editBlockconversationFactory; public static void init(Plugin plugin) { Map sessionData = new HashMap<>(); @@ -33,39 +38,52 @@ public static void init(Plugin plugin) { .withModality(false) .withEscapeSequence("!cancel") .withTimeout(120) - .withLocalEcho(true) - .withPrefix(conversationContext -> "[Inventory Editor] ") + .withLocalEcho(false) + .withPrefix(conversationContext -> ChatColor.AQUA+"[Inventory Editor] ") .withInitialSessionData(sessionData) .addConversationAbandonedListener(new AddBlockExecutor()) .withFirstPrompt(new BlockIdPrompt()); + editBlockconversationFactory = new ConversationFactory(plugin) + .withModality(false) + .withEscapeSequence("!cancel") + .withTimeout(120) + .withLocalEcho(false) + .withPrefix(conversationContext -> ChatColor.AQUA+"[Inventory Editor] ") + .withInitialSessionData(sessionData) + .addConversationAbandonedListener(new EditBlockExecutor()) + .withFirstPrompt(new EditPrompt()); } - public static void addBlock(Player player, String rpName, String category, CustomInventoryState state) { + public static void addBlock(Player player, String rpName, String category, CustomInventoryState state, int slot) { Conversation conversation = addBlockconversationFactory.buildConversation(player); ConversationContext context = conversation.getContext(); context.setSessionData("rpName",rpName); context.setSessionData("category", category); context.setSessionData("state", state); context.setSessionData("inCategory", true); + context.setSessionData("slot", slot); conversation.begin(); } + @SuppressWarnings("unchecked") public static class AddBlockExecutor implements ConversationAbandonedListener { @Override public void conversationAbandoned(@NotNull ConversationAbandonedEvent conversationAbandonedEvent) { + Player player = (Player) conversationAbandonedEvent.getContext().getForWhom(); if(conversationAbandonedEvent.gracefulExit()) { ConversationContext context = conversationAbandonedEvent.getContext(); - File rpFolder = new File(SpecialBlockInventoryData.configFolder, - (String) Objects.requireNonNull(context.getSessionData("rpName"))); - File categoryFile = new File(rpFolder, context.getSessionData("category")+".yml"); + String rpName = (String) Objects.requireNonNull(context.getSessionData("rpName")); + File rpFolder = new File(SpecialBlockInventoryData.configFolder,rpName); + String category = (String) context.getSessionData("category"); assert category != null; + File categoryFile = new File(rpFolder, category.toLowerCase()+".yml"); if(categoryFile.exists()) { YamlConfiguration config = new YamlConfiguration(); try { config.load(categoryFile); ConfigurationSection items = config.getConfigurationSection("Items"); assert items != null; - ConfigurationSection newSection = items.createSection((String) Objects.requireNonNull(context - .getSessionData("id"))); + String blockId = (String) Objects.requireNonNull(context.getSessionData("id")); + ConfigurationSection newSection = items.createSection(blockId); newSection.set("display", context.getSessionData("display")); newSection.set("type", Objects.requireNonNull(context.getSessionData("type")).toString() .toUpperCase()); @@ -74,22 +92,183 @@ public void conversationAbandoned(@NotNull ConversationAbandonedEvent conversati ItemMeta meta = item.getItemMeta(); newSection.set("itemMaterial", item.getType().name()); newSection.set("cmd", meta.getCustomModelData()); - if((Boolean) context.getSessionData("inCategory")) { + Object inCategory = context.getSessionData("inCategory"); assert inCategory != null; + if((Boolean) inCategory) { newSection.set("category",context.getSessionData("category")); } + if(context.getSessionData("state") instanceof CustomInventoryCollectionState collection) { + SpecialBlock baseBlock = collection.getBaseBlock(); + String baseId = baseBlock.getId().substring(baseBlock.getId().indexOf("/")+1); +Logger.getGlobal().info("BaseId: "+baseId); + Object slot = context.getSessionData("slot"); assert slot != null; + String locator = getLocator((Integer) slot); + ConfigurationSection baseSection = items.getConfigurationSection(baseId); assert baseSection != null; + ConfigurationSection collectionSection = baseSection.getConfigurationSection("collection"); + assert collectionSection != null; + collectionSection.set(locator, blockId); + } + Map blockData = (Map) context.getSessionData("blockData"); + assert blockData != null; + for(Map.Entry entry: blockData.entrySet()) { + newSection.set("blockData"+entry.getKey(), entry.getValue()); + } + config.save(categoryFile); + PluginData.getMessageUtil().sendInfoMessage(player, "New block "+blockId + +" added to file "+rpName+"/"+categoryFile.getName()+" Reloading inventories..."); + SpecialBlockInventoryData.loadInventories(); + PluginData.getMessageUtil().sendInfoMessage(player, "Inventory reload done!"); + } catch (IOException | InvalidConfigurationException e) { + PluginData.getMessageUtil().sendErrorMessage(player, "Internal error" + + " while saving new custom inventory block."); + e.printStackTrace(); + } + } else { + PluginData.getMessageUtil().sendErrorMessage(player, + "Can't save new block. Inventory config file not found: " + +rpName+"/"+categoryFile.getName()); + Logger.getGlobal().warning("Not found! "+categoryFile); + } + } else { + PluginData.getMessageUtil().sendErrorMessage(player, "Custom inventory editor conversation cancelled."); + } + } + } + + public static void editBlock(Player player, String rpName, String category, CustomInventoryState state, ItemStack inventoryItem) { + Conversation conversation = editBlockconversationFactory.buildConversation(player); + ConversationContext context = conversation.getContext(); + context.setSessionData("category", category); + context.setSessionData("state", state); + String[] rpAndId = SpecialBlockInventoryData.getSpecialBlockId(inventoryItem).split("/"); + context.setSessionData("id", rpAndId[1]); + context.setSessionData("rpName",rpAndId[0]); + ConfigurationSection inventoryConfig = getInventoryConfig(rpAndId[0], category); + ConfigurationSection itemSection = inventoryConfig.getConfigurationSection(rpAndId[1]); + assert itemSection != null; + context.setSessionData("display", itemSection.get("display")); + context.setSessionData("type", itemSection.get("type")); + context.setSessionData("cmd", itemSection.get("cmd")); + context.setSessionData("display", itemSection.get("display")); + context.setSessionData("inCategory", itemSection.contains("category")); + + conversation.begin(); + } + + @SuppressWarnings("unchecked") + public static class EditBlockExecutor implements ConversationAbandonedListener { + @Override + public void conversationAbandoned(@NotNull ConversationAbandonedEvent conversationAbandonedEvent) { + Player player = (Player) conversationAbandonedEvent.getContext().getForWhom(); + if(conversationAbandonedEvent.gracefulExit()) { + ConversationContext context = conversationAbandonedEvent.getContext(); + String rpName = (String) Objects.requireNonNull(context.getSessionData("rpName")); + File rpFolder = new File(SpecialBlockInventoryData.configFolder,rpName); + String category = (String) context.getSessionData("category"); assert category != null; + File categoryFile = new File(rpFolder, category.toLowerCase()+".yml"); + if(categoryFile.exists()) { + YamlConfiguration config = new YamlConfiguration(); + try { + config.load(categoryFile); + ConfigurationSection items = config.getConfigurationSection("Items"); + assert items != null; + String blockId = (String) Objects.requireNonNull(context.getSessionData("id")); + ConfigurationSection newSection = items.createSection(blockId); + newSection.set("display", context.getSessionData("display")); + newSection.set("type", Objects.requireNonNull(context.getSessionData("type")).toString() + .toUpperCase()); + ItemStack item = (ItemStack) context.getSessionData("inventoryItem"); + assert item != null; + ItemMeta meta = item.getItemMeta(); + newSection.set("itemMaterial", item.getType().name()); + newSection.set("cmd", meta.getCustomModelData()); + Object inCategory = context.getSessionData("inCategory"); assert inCategory != null; + if((Boolean) inCategory) { + newSection.set("category",context.getSessionData("category")); + } + if(context.getSessionData("state") instanceof CustomInventoryCollectionState collection) { + SpecialBlock baseBlock = collection.getBaseBlock(); + String baseId = baseBlock.getId().substring(baseBlock.getId().indexOf("/")+1); + Logger.getGlobal().info("BaseId: "+baseId); + Object slot = context.getSessionData("slot"); assert slot != null; + String locator = getLocator((Integer) slot); + ConfigurationSection baseSection = items.getConfigurationSection(baseId); assert baseSection != null; + ConfigurationSection collectionSection = baseSection.getConfigurationSection("collection"); + assert collectionSection != null; + collectionSection.set(locator, blockId); + } + Map blockData = (Map) context.getSessionData("blockData"); assert blockData != null; for(Map.Entry entry: blockData.entrySet()) { - newSection.set(entry.getKey(), entry.getValue()); + newSection.set("blockData"+entry.getKey(), entry.getValue()); } config.save(categoryFile); + PluginData.getMessageUtil().sendInfoMessage(player, "New block "+blockId + +" added to file "+rpName+"/"+categoryFile.getName()+" Reloading inventories..."); SpecialBlockInventoryData.loadInventories(); + PluginData.getMessageUtil().sendInfoMessage(player, "Inventory reload done!"); } catch (IOException | InvalidConfigurationException e) { + PluginData.getMessageUtil().sendErrorMessage(player, "Internal error" + + " while saving new custom inventory block."); e.printStackTrace(); } + } else { + PluginData.getMessageUtil().sendErrorMessage(player, + "Can't save new block. Inventory config file not found: " + +rpName+"/"+categoryFile.getName()); + Logger.getGlobal().warning("Not found! "+categoryFile); } + } else { + PluginData.getMessageUtil().sendErrorMessage(player, "Custom inventory editor conversation cancelled."); + } + } + } + + private static String getLocator(int slot) { + slot = slot - CustomInventory.CATEGORY_SLOTS; + char letter; + int number; + if(slot % 9 < 5) { + letter = switch (slot / 9) { + case 0 -> 'A'; + case 1 -> 'B'; + case 2 -> 'C'; + case 3 -> 'D'; + case 4 -> 'E'; + default -> 'X'; + }; + number = 4 - slot % 9; + } else { + letter = switch (slot / 9) { + case 0 -> 'F'; + case 1 -> 'G'; + case 2 -> 'H'; + case 3 -> 'I'; + case 4 -> 'J'; + default -> 'X'; + }; + number = slot % 9 - 4; + } + return ""+letter+number; + } + + private static ConfigurationSection getInventoryConfig(String rpName, String category) { + File rpFolder = new File(SpecialBlockInventoryData.configFolder, rpName); + File categoryFile = new File(rpFolder, category.toLowerCase() + ".yml"); + if (categoryFile.exists()) { + YamlConfiguration config = new YamlConfiguration(); + try { + config.load(categoryFile); + return config.getConfigurationSection("Items"); + } catch (IOException | InvalidConfigurationException e) { + Logger.getGlobal().warning("Error while reading inventory config! " + categoryFile); + e.printStackTrace(); + return null; } + } else { + Logger.getGlobal().warning("Not found! " + categoryFile); + return null; } } } diff --git a/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/BlockDataPrompt.java b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/add/BlockDataPrompt.java similarity index 56% rename from src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/BlockDataPrompt.java rename to src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/add/BlockDataPrompt.java index 5608e08..1926b47 100644 --- a/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/BlockDataPrompt.java +++ b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/add/BlockDataPrompt.java @@ -1,11 +1,13 @@ -package com.mcmiddleearth.architect.specialBlockHandling.customInventories.editor.prompt; +package com.mcmiddleearth.architect.specialBlockHandling.customInventories.editor.prompt.add; import org.bukkit.Bukkit; import org.bukkit.block.Block; import org.bukkit.conversations.ConversationContext; import org.bukkit.conversations.Prompt; +import org.bukkit.conversations.ValidatingPrompt; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; +import org.bukkit.event.HandlerList; import org.bukkit.event.Listener; import org.bukkit.event.block.Action; import org.bukkit.event.player.PlayerInteractEvent; @@ -15,11 +17,9 @@ import java.util.Arrays; import java.util.Map; import java.util.Objects; +import java.util.logging.Logger; -public class BlockDataPrompt implements Prompt, Listener { - - private boolean done = false; - +public class BlockDataPrompt extends ValidatingPrompt implements Listener { private boolean listenerRegistered = false; private ConversationContext conversationContext; @@ -32,7 +32,8 @@ public BlockDataPrompt(String... blockStateKeys) { @Override public @NotNull String getPromptText(@NotNull ConversationContext conversationContext) { - return "Left-click a block for blockData"+blockStateKeys[0]+"."; + 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]+"."; } @Override @@ -42,28 +43,39 @@ public boolean blocksForInput(@NotNull ConversationContext conversationContext) Bukkit.getPluginManager().registerEvents(this, Objects.requireNonNull(conversationContext.getPlugin())); listenerRegistered = true; } - return !done; +Logger.getGlobal().info("blocksForInput: "+true); + return true; + } + + @Override + protected boolean isInputValid(@NotNull ConversationContext conversationContext, @NotNull String input) { + return input.equals("__d0nE__"); } @Override - public @Nullable Prompt acceptInput(@NotNull ConversationContext conversationContext, @Nullable String input) { + protected @Nullable Prompt acceptValidatedInput(@NotNull ConversationContext conversationContext, @NotNull String input) { if(blockStateKeys.length>1) { return new BlockDataPrompt(Arrays.copyOfRange(blockStateKeys,1,blockStateKeys.length)); } else { - return new DisplayPrompt(); + return new ItemPrompt(); } } + @SuppressWarnings("unchecked") @EventHandler(priority = EventPriority.LOWEST) public void onSelectBlockstate(PlayerInteractEvent event) { +Logger.getGlobal().info("onSelectBlockstate"); if(event.getAction().equals(Action.LEFT_CLICK_BLOCK) && event.hasItem()) { Block block = event.getClickedBlock(); +Logger.getGlobal().info("Block: "+block); if(block != null) { - ((Map) Objects.requireNonNull(conversationContext.getSessionData("blockData"))) - .put(blockStateKeys[0], block.getBlockData().getAsString()); - conversationContext.setSessionData("inventoryItem", event.getItem()); - done = true; +Logger.getGlobal().info("BlockData: "+block.getBlockData()); + Map blockDatas = (Map) Objects.requireNonNull(conversationContext.getSessionData("blockData")); + blockDatas.put(blockStateKeys[0], block.getBlockData().getAsString()); + HandlerList.unregisterAll(this); + event.setCancelled(true); + conversationContext.getForWhom().acceptConversationInput("__d0nE__"); } } } diff --git a/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/BlockIdPrompt.java b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/add/BlockIdPrompt.java similarity index 97% rename from src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/BlockIdPrompt.java rename to src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/add/BlockIdPrompt.java index 067be23..f7a9bb3 100644 --- a/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/BlockIdPrompt.java +++ b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/add/BlockIdPrompt.java @@ -1,4 +1,4 @@ -package com.mcmiddleearth.architect.specialBlockHandling.customInventories.editor.prompt; +package com.mcmiddleearth.architect.specialBlockHandling.customInventories.editor.prompt.add; import com.mcmiddleearth.architect.specialBlockHandling.data.SpecialBlockInventoryData; import org.bukkit.conversations.ConversationContext; diff --git a/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/BlockTypePrompt.java b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/add/BlockTypePrompt.java similarity index 71% rename from src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/BlockTypePrompt.java rename to src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/add/BlockTypePrompt.java index 5722727..ade553e 100644 --- a/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/BlockTypePrompt.java +++ b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/add/BlockTypePrompt.java @@ -1,4 +1,4 @@ -package com.mcmiddleearth.architect.specialBlockHandling.customInventories.editor.prompt; +package com.mcmiddleearth.architect.specialBlockHandling.customInventories.editor.prompt.add; import org.bukkit.conversations.ConversationContext; import org.bukkit.conversations.FixedSetPrompt; @@ -6,8 +6,15 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.LinkedHashMap; + public class BlockTypePrompt extends FixedSetPrompt { + public static final String[][] blockData = new String[][]{ + {"block", ""}, + {"bisected", "Up", "Down"}, + {"four_directions", "North", "West", "South", "East"} + }; public BlockTypePrompt() { super("block", "bisected", "four_directions", "three_axis", "vanilla"); } @@ -20,6 +27,11 @@ public BlockTypePrompt() { case "bisected" -> new BlockDataPrompt("Up", "Down"); case "four_directions" -> new BlockDataPrompt("North", "West", "South", "East"); case "three_axis" -> new BlockDataPrompt("X", "Y", "Z"); + case "six_faces" -> new BlockDataPrompt("North", "West", "South", "East", "Up", "Down"); + case "branch_twigs" -> ; + case "branch_horizontal" -> + + case "vanilla" -> new ItemPrompt(); default -> END_OF_CONVERSATION; }; } diff --git a/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/CategoryVisiblePrompt.java b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/add/CategoryVisiblePrompt.java similarity index 96% rename from src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/CategoryVisiblePrompt.java rename to src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/add/CategoryVisiblePrompt.java index 9c0eae5..4d42e30 100644 --- a/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/CategoryVisiblePrompt.java +++ b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/add/CategoryVisiblePrompt.java @@ -1,4 +1,4 @@ -package com.mcmiddleearth.architect.specialBlockHandling.customInventories.editor.prompt; +package com.mcmiddleearth.architect.specialBlockHandling.customInventories.editor.prompt.add; import org.bukkit.conversations.ConversationContext; import org.bukkit.conversations.FixedSetPrompt; diff --git a/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/DisplayPrompt.java b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/add/DisplayPrompt.java similarity index 97% rename from src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/DisplayPrompt.java rename to src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/add/DisplayPrompt.java index 7b33b96..f3e00c8 100644 --- a/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/DisplayPrompt.java +++ b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/add/DisplayPrompt.java @@ -1,4 +1,4 @@ -package com.mcmiddleearth.architect.specialBlockHandling.customInventories.editor.prompt; +package com.mcmiddleearth.architect.specialBlockHandling.customInventories.editor.prompt.add; import com.mcmiddleearth.architect.specialBlockHandling.customInventories.CustomInventoryCollectionState; import org.bukkit.conversations.ConversationContext; 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 new file mode 100644 index 0000000..c648aee --- /dev/null +++ b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/add/ItemPrompt.java @@ -0,0 +1,26 @@ +package com.mcmiddleearth.architect.specialBlockHandling.customInventories.editor.prompt.add; + +import org.bukkit.conversations.ConversationContext; +import org.bukkit.conversations.FixedSetPrompt; +import org.bukkit.conversations.Prompt; +import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +public class ItemPrompt extends FixedSetPrompt { + + public ItemPrompt() { + super("ok"); + } + + @Override + protected @Nullable Prompt acceptValidatedInput(@NotNull ConversationContext conversationContext, @NotNull String input) { + conversationContext.setSessionData("inventoryItem", ((Player)conversationContext.getForWhom()).getInventory().getItemInMainHand()); + return new DisplayPrompt(); + } + + @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'"; + } +} 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 new file mode 100644 index 0000000..e0bf077 --- /dev/null +++ b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/edit/ChangeBlockDataPrompt.java @@ -0,0 +1,4 @@ +package com.mcmiddleearth.architect.specialBlockHandling.customInventories.editor.prompt.edit; + +public class ChangeBlockDataPrompt { +} 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 new file mode 100644 index 0000000..96a15da --- /dev/null +++ b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/edit/ChangeBlockIdPrompt.java @@ -0,0 +1,30 @@ +package com.mcmiddleearth.architect.specialBlockHandling.customInventories.editor.prompt.edit; + +import com.mcmiddleearth.architect.specialBlockHandling.data.SpecialBlockInventoryData; +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 ChangeBlockIdPrompt extends ValidatingPrompt { + + @Override + public @NotNull String getPromptText(@NotNull ConversationContext conversationContext) { + return "Type in a new id or '!skip'"; + } + + @Override + protected boolean isInputValid(@NotNull ConversationContext conversationContext, @NotNull String input) { + return SpecialBlockInventoryData.getSpecialBlock(conversationContext.getSessionData("rpName")+"/"+input) + == null; + } + + @Override + public @Nullable Prompt acceptValidatedInput(@NotNull ConversationContext conversationContext, @NotNull String input) { + if(!input.equalsIgnoreCase("!skip")) { + conversationContext.setSessionData("id",input); + } + return new ChangeBlockTypePrompt(); + } +} 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 new file mode 100644 index 0000000..c91e58c --- /dev/null +++ b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/edit/ChangeBlockTypePrompt.java @@ -0,0 +1,37 @@ +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 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 ChangeBlockTypePrompt extends FixedSetPrompt { + + public ChangeBlockTypePrompt() { + super("block", "bisected", "four_directions", "three_axis", "vanilla", "!skip"); + } + + @Override + protected @Nullable Prompt acceptValidatedInput(@NotNull ConversationContext conversationContext, @NotNull String input) { + 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; + }; + } + + @Override + public @NotNull String getPromptText(@NotNull ConversationContext conversationContext) { + return "Type in a new block type or '!skip'"; + } +} 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 new file mode 100644 index 0000000..80ac47f --- /dev/null +++ b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/edit/ChangeCategoryVisiblePrompt.java @@ -0,0 +1,4 @@ +package com.mcmiddleearth.architect.specialBlockHandling.customInventories.editor.prompt.edit; + +public class ChangeCategoryVisiblePrompt { +} 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 new file mode 100644 index 0000000..e424727 --- /dev/null +++ b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/edit/ChangeDisplayPrompt.java @@ -0,0 +1,4 @@ +package com.mcmiddleearth.architect.specialBlockHandling.customInventories.editor.prompt.edit; + +public class ChangeDisplayPrompt { +} 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 new file mode 100644 index 0000000..9a03ad0 --- /dev/null +++ b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/edit/ChangeItemPrompt.java @@ -0,0 +1,27 @@ +package com.mcmiddleearth.architect.specialBlockHandling.customInventories.editor.prompt.edit; + +import com.mcmiddleearth.architect.specialBlockHandling.customInventories.editor.prompt.add.DisplayPrompt; +import org.bukkit.conversations.ConversationContext; +import org.bukkit.conversations.FixedSetPrompt; +import org.bukkit.conversations.Prompt; +import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +public class ChangeItemPrompt extends FixedSetPrompt { + + public ChangeItemPrompt() { + super("ok", "!skip"); + } + + @Override + protected @Nullable Prompt acceptValidatedInput(@NotNull ConversationContext conversationContext, @NotNull String input) { + conversationContext.setSessionData("inventoryItem", ((Player)conversationContext.getForWhom()).getInventory().getItemInMainHand()); + return new DisplayPrompt(); + } + + @Override + public @NotNull String getPromptText(@NotNull ConversationContext conversationContext) { + return "To change the inventory item hold in main hand a new item and type 'ok'. To not change type '!skip'"; + } +} diff --git a/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/edit/EditPrompt.java b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/edit/EditPrompt.java new file mode 100644 index 0000000..d3430cc --- /dev/null +++ b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/edit/EditPrompt.java @@ -0,0 +1,29 @@ +package com.mcmiddleearth.architect.specialBlockHandling.customInventories.editor.prompt.edit; + +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 EditPrompt extends FixedSetPrompt { + + public EditPrompt() { + super("edit", "delete", "none"); + } + + @Override + protected @Nullable Prompt acceptValidatedInput(@NotNull ConversationContext conversationContext, @NotNull String input) { + conversationContext.setSessionData("action",input); + if(input.equalsIgnoreCase("edit")) { + return new ChangeBlockIdPrompt(); + } else { + return END_OF_CONVERSATION; + } + } + + @Override + public @NotNull String getPromptText(@NotNull ConversationContext conversationContext) { + return "What do you want to do with inventory entry "+conversationContext.getSessionData("id")+"? "+formatFixedSet(); + } +} diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 2740e2f..0ff5137 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -119,6 +119,7 @@ permissions: architect.bannerEditor.delete: true architect.inventory.reload: true architect.inventory.other: true + archtiect.inventory.edit: true architect.get.other: true architect.weather: true archtiect.resourcePackAdmin: true @@ -396,8 +397,11 @@ permissions: descriptions: Allows to check item NBTs default: op architect.inventory.ignoreProtection: - descriptions: Allows to edit inventory content without build permission - default: op + descriptions: Allows to edit inventory content without build permission + default: op + architect.inventory.edit: + descriptions: Allows to edit custom inventory + default: op architect.viewdistance: descriptions: Allows to change client view distance default: op \ No newline at end of file From d88e3d8b053b55b4acac6f5809004d3d2f11cac1 Mon Sep 17 00:00:00 2001 From: EriolEandur Date: Sat, 7 Dec 2024 00:55:58 +0100 Subject: [PATCH 4/5] 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 From 0be7d590583f70fa698947fc2b1a4a7ab133268b Mon Sep 17 00:00:00 2001 From: EriolEandur Date: Sun, 8 Dec 2024 01:06:09 +0100 Subject: [PATCH 5/5] version 2.9.15 added custom inventory editor --- pom.xml | 2 +- .../serverResoucePack/RpManager.java | 5 + .../RpPluginMessageListener.java | 4 +- .../customInventories/CustomInventory.java | 2 +- .../CustomInventoryCategory.java | 6 +- .../CustomInventoryCollectionState.java | 1 + .../customInventories/SearchInventory.java | 9 +- .../editor/CustomInventoryEditor.java | 195 +++++++----------- .../editor/prompt/add/BlockDataPrompt.java | 33 ++- .../editor/prompt/add/BlockIdPrompt.java | 7 +- .../editor/prompt/add/BlockTypePrompt.java | 21 +- .../prompt/add/CategoryVisiblePrompt.java | 9 + .../editor/prompt/add/CmdPrompt.java | 12 +- .../editor/prompt/add/ColorPrompt.java | 7 +- .../editor/prompt/add/DisplayPrompt.java | 2 +- .../editor/prompt/add/ItemPrompt.java | 26 ++- .../prompt/edit/ChangeBlockDataPrompt.java | 29 ++- .../prompt/edit/ChangeBlockIdPrompt.java | 11 +- .../prompt/edit/ChangeBlockTypePrompt.java | 5 +- .../edit/ChangeCategoryVisiblePrompt.java | 12 +- .../editor/prompt/edit/ChangeCmdPrompt.java | 13 +- .../editor/prompt/edit/ChangeColorPrompt.java | 5 - .../prompt/edit/ChangeDisplayPrompt.java | 7 +- .../editor/prompt/edit/ChangeItemPrompt.java | 17 +- .../editor/prompt/edit/ChangeSlotPrompt.java | 35 ++++ .../editor/prompt/edit/EditPrompt.java | 9 +- src/main/resources/plugin.yml | 2 +- 27 files changed, 289 insertions(+), 197 deletions(-) create mode 100644 src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/edit/ChangeSlotPrompt.java diff --git a/pom.xml b/pom.xml index 58e9a5f..9733dd3 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ 4.0.0 com.mcmiddleearth MCME-Architect - 2.9.15-snapshot + 2.9.15 jar UTF-8 diff --git a/src/main/java/com/mcmiddleearth/architect/serverResoucePack/RpManager.java b/src/main/java/com/mcmiddleearth/architect/serverResoucePack/RpManager.java index 28ac4bb..41162b1 100644 --- a/src/main/java/com/mcmiddleearth/architect/serverResoucePack/RpManager.java +++ b/src/main/java/com/mcmiddleearth/architect/serverResoucePack/RpManager.java @@ -29,6 +29,7 @@ import com.mcmiddleearth.connect.log.Log; import com.mcmiddleearth.util.DevUtil; import com.mcmiddleearth.util.ResourceUtil; +import com.viaversion.viaversion.api.Via; import org.bukkit.Location; import org.bukkit.command.CommandSender; import org.bukkit.configuration.ConfigurationSection; @@ -213,6 +214,9 @@ private static ConfigurationSection getConfigSection(String rp, Player player) { RpPlayerData data; if (player != null) { data = getPlayerData(player); + if(data.getProtocolVersion()==0) { + data.setProtocolVersion(Via.getAPI().getPlayerProtocolVersion(player.getUniqueId()).getVersion()); + } } else { data = new RpPlayerData(); } @@ -344,6 +348,7 @@ public static boolean setRp(String rpName, Player player, boolean force) { RpPlayerData data = getPlayerData(player); if(url!=null && data!=null && !url.equals("") && (force || !url.equals(data.getCurrentRpUrl()))) { data.setCurrentRpUrl(url); +//Logger.getGlobal().info("Sending to "+player.getName()+"("+getPlayerData(player).getProtocolVersion()+") RP: "+url); player.setResourcePack(url, getSHA(rpName, player)); savePlayerData(player); return true; diff --git a/src/main/java/com/mcmiddleearth/architect/serverResoucePack/RpPluginMessageListener.java b/src/main/java/com/mcmiddleearth/architect/serverResoucePack/RpPluginMessageListener.java index 2082a4c..af6abd2 100644 --- a/src/main/java/com/mcmiddleearth/architect/serverResoucePack/RpPluginMessageListener.java +++ b/src/main/java/com/mcmiddleearth/architect/serverResoucePack/RpPluginMessageListener.java @@ -16,8 +16,8 @@ public class RpPluginMessageListener implements PluginMessageListener { public void onPluginMessageReceived(@NotNull String channel, @NotNull Player player, byte[] bytes) { //Logger.getGlobal().info("Sodium client detected: "+player.getName()); -Logger.getGlobal().info("Received message from player " + player.getName() + " on channel " - + channel + " with data " + Arrays.toString(bytes)); +//Logger.getGlobal().info("Received message from player " + player.getName() + " on channel " +// + channel + " with data " + Arrays.toString(bytes)); try (var dataStream = new DataInputStream(new ByteArrayInputStream(bytes))) { int stringLength = readVarInt(dataStream); String jsonString = new String(dataStream.readNBytes(stringLength)); diff --git a/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/CustomInventory.java b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/CustomInventory.java index c36b236..b2d2749 100644 --- a/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/CustomInventory.java +++ b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/CustomInventory.java @@ -360,7 +360,7 @@ void onInventoryEdit(final InventoryClickEvent event) { if(event.getCurrentItem() == null) { CustomInventoryEditor.addBlock(player, rpName, category, state, event.getRawSlot()); } else { - CustomInventoryEditor.editBlock(player, rpName, category, state, event.getCurrentItem()); + CustomInventoryEditor.editBlock(player, category, state, event.getRawSlot(), event.getCurrentItem()); } } } diff --git a/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/CustomInventoryCategory.java b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/CustomInventoryCategory.java index cbcc511..f8c2897 100644 --- a/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/CustomInventoryCategory.java +++ b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/CustomInventoryCategory.java @@ -21,6 +21,7 @@ import org.bukkit.inventory.ItemStack; import java.util.*; +import java.util.logging.Logger; /** * @@ -85,7 +86,10 @@ public boolean isVisible(Player player) { } public ItemStack getItem(String id) { - return items.stream().filter(item -> SpecialBlockInventoryData.getSpecialBlockId(item).equals(id)).findAny().orElse(null); + return items.stream().filter(item -> { + String blockId = SpecialBlockInventoryData.getSpecialBlockId(item); + return blockId != null && blockId.equals(id); + }).findAny().orElse(null); } public boolean isPublic() { diff --git a/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/CustomInventoryCollectionState.java b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/CustomInventoryCollectionState.java index 19df8a9..d9ccd54 100644 --- a/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/CustomInventoryCollectionState.java +++ b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/CustomInventoryCollectionState.java @@ -28,6 +28,7 @@ import org.bukkit.inventory.meta.ItemMeta; import java.util.*; +import java.util.logging.Logger; /** * diff --git a/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/SearchInventory.java b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/SearchInventory.java index 8992aa3..048fa89 100644 --- a/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/SearchInventory.java +++ b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/SearchInventory.java @@ -222,7 +222,14 @@ public boolean isEmpty() { public ItemStack getItem(String id) { //Logger.getGlobal().info("search getItem: "+id); - return items.stream().filter(item -> item.getItemMeta().getLore().get(1).equals(id)).findFirst().orElse(null); + return items.stream().filter(item -> { + if(item.hasItemMeta() && item.getItemMeta().hasLore()) { + return item.getItemMeta().getLore().get(1).equals(id); +// } else { +// Logger.getGlobal().warning("Invalid item in search inventory: "+item); + } + return false; + }).findFirst().orElse(null); } public Set getRecipeKeys() { 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 c1e9df0..4ffecdb 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 @@ -15,7 +15,6 @@ import org.bukkit.conversations.*; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.plugin.Plugin; import org.jetbrains.annotations.NotNull; @@ -28,116 +27,46 @@ public class CustomInventoryEditor { - private static ConversationFactory addBlockconversationFactory; - private static ConversationFactory editBlockconversationFactory; + private static ConversationFactory addBlockConversationFactory; + private static ConversationFactory editBlockConversationFactory; public static void init(Plugin plugin) { Map sessionData = new HashMap<>(); sessionData.put("blockData", new HashMap()); - addBlockconversationFactory = new ConversationFactory(plugin) + addBlockConversationFactory = new ConversationFactory(plugin) .withModality(false) .withEscapeSequence("!cancel") - .withTimeout(120) - .withLocalEcho(false) + .withTimeout(300) + .withLocalEcho(true) .withPrefix(conversationContext -> ChatColor.AQUA+"[Inventory Editor] ") .withInitialSessionData(sessionData) - .addConversationAbandonedListener(new AddBlockExecutor()) + .addConversationAbandonedListener(new EditExecutor()) .withFirstPrompt(new BlockIdPrompt()); - editBlockconversationFactory = new ConversationFactory(plugin) + editBlockConversationFactory = new ConversationFactory(plugin) .withModality(false) .withEscapeSequence("!cancel") - .withTimeout(120) - .withLocalEcho(false) + .withTimeout(300) + .withLocalEcho(true) .withPrefix(conversationContext -> ChatColor.AQUA+"[Inventory Editor] ") .withInitialSessionData(sessionData) - .addConversationAbandonedListener(new EditBlockExecutor()) + .addConversationAbandonedListener(new EditExecutor()) .withFirstPrompt(new EditPrompt()); } public static void addBlock(Player player, String rpName, String category, CustomInventoryState state, int slot) { - Conversation conversation = addBlockconversationFactory.buildConversation(player); + Conversation conversation = addBlockConversationFactory.buildConversation(player); ConversationContext context = conversation.getContext(); context.setSessionData("rpName",rpName); context.setSessionData("category", category); context.setSessionData("state", state); context.setSessionData("inCategory", true); - context.setSessionData("slot", slot); + context.setSessionData("slot", getLocator(slot)); conversation.begin(); } @SuppressWarnings("unchecked") - public static class AddBlockExecutor implements ConversationAbandonedListener { - @Override - public void conversationAbandoned(@NotNull ConversationAbandonedEvent conversationAbandonedEvent) { - Player player = (Player) conversationAbandonedEvent.getContext().getForWhom(); - if(conversationAbandonedEvent.gracefulExit()) { - ConversationContext context = conversationAbandonedEvent.getContext(); - String rpName = (String) Objects.requireNonNull(context.getSessionData("rpName")); - File rpFolder = new File(SpecialBlockInventoryData.configFolder,rpName); - String category = (String) context.getSessionData("category"); assert category != null; - File categoryFile = new File(rpFolder, category.toLowerCase()+".yml"); - if(categoryFile.exists()) { - YamlConfiguration config = new YamlConfiguration(); - try { - config.load(categoryFile); - ConfigurationSection items = config.getConfigurationSection("Items"); - assert items != null; - String blockId = (String) Objects.requireNonNull(context.getSessionData("id")); - ConfigurationSection newSection = items.createSection(blockId); - newSection.set("display", context.getSessionData("display")); - newSection.set("type", Objects.requireNonNull(context.getSessionData("type")).toString() - .toUpperCase()); - ItemStack item = (ItemStack) context.getSessionData("inventoryItem"); - assert item != null; - ItemMeta meta = item.getItemMeta(); - newSection.set("itemMaterial", item.getType().name()); - newSection.set("cmd", meta.getCustomModelData()); - Object inCategory = context.getSessionData("inCategory"); assert inCategory != null; - if((Boolean) inCategory) { - newSection.set("category",context.getSessionData("category")); - } - if(context.getSessionData("state") instanceof CustomInventoryCollectionState collection) { - SpecialBlock baseBlock = collection.getBaseBlock(); - String baseId = baseBlock.getId().substring(baseBlock.getId().indexOf("/")+1); -Logger.getGlobal().info("BaseId: "+baseId); - Object slot = context.getSessionData("slot"); assert slot != null; - String locator = getLocator((Integer) slot); - ConfigurationSection baseSection = items.getConfigurationSection(baseId); assert baseSection != null; - ConfigurationSection collectionSection = baseSection.getConfigurationSection("collection"); - assert collectionSection != null; - collectionSection.set(locator, blockId); - } - - Map blockData = (Map) context.getSessionData("blockData"); - assert blockData != null; - for(Map.Entry entry: blockData.entrySet()) { - newSection.set("blockData"+entry.getKey(), entry.getValue()); - } - config.save(categoryFile); - PluginData.getMessageUtil().sendInfoMessage(player, "New block "+blockId - +" added to file "+rpName+"/"+categoryFile.getName()+" Reloading inventories..."); - SpecialBlockInventoryData.loadInventories(); - PluginData.getMessageUtil().sendInfoMessage(player, "Inventory reload done!"); - } catch (IOException | InvalidConfigurationException e) { - PluginData.getMessageUtil().sendErrorMessage(player, "Internal error" + - " while saving new custom inventory block."); - e.printStackTrace(); - } - } else { - PluginData.getMessageUtil().sendErrorMessage(player, - "Can't save new block. Inventory config file not found: " - +rpName+"/"+categoryFile.getName()); - Logger.getGlobal().warning("Not found! "+categoryFile); - } - } else { - PluginData.getMessageUtil().sendErrorMessage(player, "Custom inventory editor conversation cancelled."); - } - } - } - - @SuppressWarnings("unchecked") - public static void editBlock(Player player, String rpName, String category, CustomInventoryState state, ItemStack inventoryItem) { - Conversation conversation = editBlockconversationFactory.buildConversation(player); + public static void editBlock(Player player, String category, CustomInventoryState state, int slot, ItemStack inventoryItem) { + Conversation conversation = editBlockConversationFactory.buildConversation(player); ConversationContext context = conversation.getContext(); context.setSessionData("category", category); context.setSessionData("state", state); @@ -150,9 +79,15 @@ public static void editBlock(Player player, String rpName, String category, Cust assert itemSection != null; context.setSessionData("display", itemSection.get("display")); context.setSessionData("type", itemSection.get("type")); - context.setSessionData("cmd", itemSection.get("cmd")); - context.setSessionData("display", itemSection.get("display")); + context.setSessionData("itemMaterial", itemSection.get("itemMaterial")); + if(itemSection.contains("cmd")) { + context.setSessionData("cmd", itemSection.get("cmd")); + } + if(itemSection.contains("color")) { + context.setSessionData("color", itemSection.get("color")); + } context.setSessionData("inCategory", itemSection.contains("category")); + context.setSessionData("slot", getLocator(slot)); Map blockData = (Map) context.getSessionData("blockData"); assert blockData!=null; itemSection.getKeys(false).stream().filter(key->key.startsWith("blockData")).forEach(key -> { @@ -162,7 +97,7 @@ public static void editBlock(Player player, String rpName, String category, Cust } @SuppressWarnings("unchecked") - public static class EditBlockExecutor implements ConversationAbandonedListener { + public static class EditExecutor implements ConversationAbandonedListener { @Override public void conversationAbandoned(@NotNull ConversationAbandonedEvent conversationAbandonedEvent) { Player player = (Player) conversationAbandonedEvent.getContext().getForWhom(); @@ -178,50 +113,70 @@ public void conversationAbandoned(@NotNull ConversationAbandonedEvent conversati config.load(categoryFile); ConfigurationSection items = config.getConfigurationSection("Items"); assert items != null; - String blockId = (String) Objects.requireNonNull(context.getSessionData("id")); - ConfigurationSection newSection = items.createSection(blockId); - newSection.set("display", context.getSessionData("display")); - newSection.set("type", Objects.requireNonNull(context.getSessionData("type")).toString() - .toUpperCase()); - ItemStack item = (ItemStack) context.getSessionData("inventoryItem"); - assert item != null; - ItemMeta meta = item.getItemMeta(); - newSection.set("itemMaterial", item.getType().name()); - newSection.set("cmd", meta.getCustomModelData()); - Object inCategory = context.getSessionData("inCategory"); assert inCategory != null; - if((Boolean) inCategory) { - newSection.set("category",context.getSessionData("category")); - } - if(context.getSessionData("state") instanceof CustomInventoryCollectionState collection) { - SpecialBlock baseBlock = collection.getBaseBlock(); - String baseId = baseBlock.getId().substring(baseBlock.getId().indexOf("/")+1); - Logger.getGlobal().info("BaseId: "+baseId); - Object slot = context.getSessionData("slot"); assert slot != null; - String locator = getLocator((Integer) slot); - ConfigurationSection baseSection = items.getConfigurationSection(baseId); assert baseSection != null; - ConfigurationSection collectionSection = baseSection.getConfigurationSection("collection"); - assert collectionSection != null; - collectionSection.set(locator, blockId); + if(context.getSessionData("oldId")!=null) { + String oldId = (String) Objects.requireNonNull(context.getSessionData("oldId")); + if(items.contains(oldId)) { + items.set(oldId, null); + } } + String blockId = (String) Objects.requireNonNull(context.getSessionData("id")); + if("delete".equalsIgnoreCase((String) context.getSessionData("action"))) { + items.set(blockId, null); + } else { + ConfigurationSection newSection = items.createSection(blockId); + newSection.set("display", context.getSessionData("display")); + newSection.set("type", Objects.requireNonNull(context.getSessionData("type")).toString() + .toUpperCase()); + newSection.set("itemMaterial", context.getSessionData("itemMaterial")); + if ((context.getSessionData("cmd") != null)) { + newSection.set("cmd", context.getSessionData("cmd")); + } + if ((context.getSessionData("color") != null)) { + newSection.set("color", context.getSessionData("color")); + } + Object inCategory = context.getSessionData("inCategory"); + assert inCategory != null; + if ((Boolean) inCategory) { + newSection.set("category", context.getSessionData("category")); + } + if (context.getSessionData("state") instanceof CustomInventoryCollectionState collection) { + SpecialBlock baseBlock = collection.getBaseBlock(); + String baseId = baseBlock.getId().substring(baseBlock.getId().indexOf("/") + 1); + Logger.getGlobal().info("BaseId: " + baseId); + ConfigurationSection baseSection = items.getConfigurationSection(baseId); + assert baseSection != null; + ConfigurationSection collectionSection = baseSection.getConfigurationSection("collection"); + assert collectionSection != null; + String slot = (String) context.getSessionData("slot"); + assert slot != null; + if (context.getSessionData("oldSlot") != null) { + String oldSlot = (String) context.getSessionData("oldSlot"); + assert oldSlot != null; + String otherBlockId = collectionSection.getString(slot); + collectionSection.set(oldSlot, otherBlockId); + } + collectionSection.set(slot, blockId); + } - Map blockData = (Map) context.getSessionData("blockData"); - assert blockData != null; - for(Map.Entry entry: blockData.entrySet()) { - newSection.set("blockData"+entry.getKey(), entry.getValue()); + Map blockData = (Map) context.getSessionData("blockData"); + assert blockData != null; + for (Map.Entry entry : blockData.entrySet()) { + newSection.set("blockData" + entry.getKey(), entry.getValue()); + } } config.save(categoryFile); - PluginData.getMessageUtil().sendInfoMessage(player, "New block "+blockId - +" added to file "+rpName+"/"+categoryFile.getName()+" Reloading inventories..."); + PluginData.getMessageUtil().sendInfoMessage(player, "Custom inventory item saved to file " + +rpName+"/"+categoryFile.getName()+" Reloading inventories..."); SpecialBlockInventoryData.loadInventories(); PluginData.getMessageUtil().sendInfoMessage(player, "Inventory reload done!"); } catch (IOException | InvalidConfigurationException e) { PluginData.getMessageUtil().sendErrorMessage(player, "Internal error" + - " while saving new custom inventory block."); + " while saving custom inventory."); e.printStackTrace(); } } else { PluginData.getMessageUtil().sendErrorMessage(player, - "Can't save new block. Inventory config file not found: " + "Can't save custom inventory. Inventory config file not found: " +rpName+"/"+categoryFile.getName()); Logger.getGlobal().warning("Not found! "+categoryFile); } 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 9482a18..c79d77d 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 @@ -1,6 +1,8 @@ package com.mcmiddleearth.architect.specialBlockHandling.customInventories.editor.prompt.add; +import com.mcmiddleearth.architect.ArchitectPlugin; import org.bukkit.Bukkit; +import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.conversations.ConversationContext; import org.bukkit.conversations.Prompt; @@ -11,6 +13,7 @@ import org.bukkit.event.Listener; import org.bukkit.event.block.Action; import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.inventory.EquipmentSlot; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -32,7 +35,12 @@ public BlockDataPrompt(String... blockStateKeys) { @Override public @NotNull String getPromptText(@NotNull ConversationContext conversationContext) { - return "Left-click a block to use for blockData"+blockStateKeys[0]+"."; + return "Left-click a block to use for blockData"+blockStateKeys[0]+". You may also type in valid block data."; + } + + @Override + protected @Nullable String getFailedValidationText(@NotNull ConversationContext context, @NotNull String invalidInput) { + return "You need to left-click a block or type in valid block data!"; } @Override @@ -42,17 +50,24 @@ public boolean blocksForInput(@NotNull ConversationContext conversationContext) Bukkit.getPluginManager().registerEvents(this, Objects.requireNonNull(conversationContext.getPlugin())); listenerRegistered = true; } -Logger.getGlobal().info("blocksForInput: "+true); return true; } @Override protected boolean isInputValid(@NotNull ConversationContext conversationContext, @NotNull String input) { - return input.equals("__d0nE__"); + try { + Bukkit.createBlockData(input); + return true; + } catch(IllegalArgumentException ignore){} + return false; } @Override + @SuppressWarnings("unchecked") protected @Nullable Prompt acceptValidatedInput(@NotNull ConversationContext conversationContext, @NotNull String input) { + HandlerList.unregisterAll(this); + Map blockDatas = (Map) Objects.requireNonNull(conversationContext.getSessionData("blockData")); + blockDatas.put(blockStateKeys[0], input); if(blockStateKeys.length>1) { return new BlockDataPrompt(Arrays.copyOfRange(blockStateKeys,1,blockStateKeys.length)); } else { @@ -60,21 +75,21 @@ protected boolean isInputValid(@NotNull ConversationContext conversationContext, } } - @SuppressWarnings("unchecked") @EventHandler(priority = EventPriority.LOWEST) public void onSelectBlockstate(PlayerInteractEvent event) { Logger.getGlobal().info("onSelectBlockstate"); - if(event.getAction().equals(Action.LEFT_CLICK_BLOCK) - && event.hasItem()) { + if(event.getPlayer().equals(conversationContext.getForWhom()) && event.getAction().equals(Action.LEFT_CLICK_BLOCK) + && event.getHand()!=null && event.getHand().equals(EquipmentSlot.HAND) + && event.getPlayer().getInventory().getItemInMainHand().getType().equals(Material.PRISMARINE_SHARD)) { Block block = event.getClickedBlock(); Logger.getGlobal().info("Block: "+block); if(block != null) { Logger.getGlobal().info("BlockData: "+block.getBlockData()); - Map blockDatas = (Map) Objects.requireNonNull(conversationContext.getSessionData("blockData")); - blockDatas.put(blockStateKeys[0], block.getBlockData().getAsString()); HandlerList.unregisterAll(this); event.setCancelled(true); - conversationContext.getForWhom().acceptConversationInput("__d0nE__"); + Bukkit.getScheduler().runTaskLater(ArchitectPlugin.getPluginInstance(),()-> { + conversationContext.getForWhom().acceptConversationInput(block.getBlockData().getAsString()); + }, 3); } } } diff --git a/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/add/BlockIdPrompt.java b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/add/BlockIdPrompt.java index f7a9bb3..2fba69d 100644 --- a/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/add/BlockIdPrompt.java +++ b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/add/BlockIdPrompt.java @@ -11,7 +11,12 @@ public class BlockIdPrompt extends ValidatingPrompt { @Override public @NotNull String getPromptText(@NotNull ConversationContext conversationContext) { - return "Type in an unique ID for the new block!"; + return "Type in an unique ID for the new item! You may '!cancel' at any point of the conversation."; + } + + @Override + protected @Nullable String getFailedValidationText(@NotNull ConversationContext context, @NotNull String invalidInput) { + return "You need to type in an item id that doesn't exist yet."; } @Override 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 4af6d7b..5968751 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 @@ -32,6 +32,10 @@ public BlockTypePrompt() { super(getBlockTypes()); } + protected BlockTypePrompt(@NotNull String... fixedSet) { + super(fixedSet); + } + @Override protected @Nullable Prompt acceptValidatedInput(@NotNull ConversationContext conversationContext, @NotNull String input) { conversationContext.setSessionData("type",input); @@ -46,18 +50,6 @@ public BlockTypePrompt() { } } 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"); - case "three_axis" -> new BlockDataPrompt("X", "Y", "Z"); - case "six_faces" -> new BlockDataPrompt("North", "West", "South", "East", "Up", "Down"); - case "branch_twigs" -> ; - case "branch_horizontal" -> - - case "vanilla" -> new ItemPrompt(); - default -> END_OF_CONVERSATION; - };*/ } @Override @@ -65,6 +57,11 @@ public BlockTypePrompt() { return "Which type of block do you want to add? "+formatFixedSet()+" "; } + @Override + protected @Nullable String getFailedValidationText(@NotNull ConversationContext context, @NotNull String invalidInput) { + return "Not all block types are supported. You need to type in one of the listed block types."; + } + public static String[] getBlockTypes() { String[] result = new String[blockData.length]; for(int i = 0; i < blockData.length; i++) { diff --git a/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/add/CategoryVisiblePrompt.java b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/add/CategoryVisiblePrompt.java index 4d42e30..fb9883c 100644 --- a/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/add/CategoryVisiblePrompt.java +++ b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/add/CategoryVisiblePrompt.java @@ -12,11 +12,20 @@ public CategoryVisiblePrompt() { super("yes", "no"); } + protected CategoryVisiblePrompt(@NotNull String... fixedSet) { + super(fixedSet); + } + @Override public @NotNull String getPromptText(@NotNull ConversationContext conversationContext) { return "Should the new inventory item be listed directly in the category of it's collection. "+formatFixedSet(); } + @Override + protected @Nullable String getFailedValidationText(@NotNull ConversationContext context, @NotNull String invalidInput) { + return "If you type in 'no' the item will be available only by a block collection."; + } + @Override protected @Nullable Prompt acceptValidatedInput(@NotNull ConversationContext conversationContext, @NotNull String input) { conversationContext.setSessionData("inCategory", input.equalsIgnoreCase("yes")); 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 index c622a0d..8de75b9 100644 --- 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 @@ -1,5 +1,6 @@ package com.mcmiddleearth.architect.specialBlockHandling.customInventories.editor.prompt.add; +import com.mcmiddleearth.architect.specialBlockHandling.customInventories.editor.prompt.edit.ChangeColorPrompt; import com.mcmiddleearth.pluginutil.NumericUtil; import org.bukkit.conversations.ConversationContext; import org.bukkit.conversations.Prompt; @@ -7,6 +8,8 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.Objects; + public class CmdPrompt extends ValidatingPrompt { @Override @@ -20,12 +23,17 @@ protected boolean isInputValid(@NotNull ConversationContext conversationContext, if(!input.equalsIgnoreCase("!skip")) { conversationContext.setSessionData("cmd",NumericUtil.getInt(input)); } - return new ColorPrompt(); //todo: only for leather + if(((String) Objects.requireNonNull(conversationContext.getSessionData("itemMaterial"))).startsWith("LEATHER")) { + return new ColorPrompt(); + } else { + return new DisplayPrompt(); + } } @Override public @NotNull String getPromptText(@NotNull ConversationContext conversationContext) { - return "Type in a value for custom model data or '!skip'"; //todo prompt current cmd + return "Current custom model data is "+conversationContext.getSessionData("cmd") + +". Type in a new custom model data or '!skip'"; } @Override 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 index a6db029..3a24bdd 100644 --- 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 @@ -25,6 +25,11 @@ protected boolean isInputValid(@NotNull ConversationContext conversationContext, @Override public @NotNull String getPromptText(@NotNull ConversationContext conversationContext) { - return "Type in a color for leather armor or '!skip'"; + return "Current color is "+conversationContext.getSessionData("color")+". Type in a new color or '!skip'"; + } + + @Override + protected @Nullable String getFailedValidationText(@NotNull ConversationContext context, @NotNull String invalidInput) { + return "You need to type in a valid rgb color code."; } } diff --git a/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/add/DisplayPrompt.java b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/add/DisplayPrompt.java index f3e00c8..763287e 100644 --- a/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/add/DisplayPrompt.java +++ b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/add/DisplayPrompt.java @@ -11,7 +11,7 @@ public class DisplayPrompt extends StringPrompt { @Override public @NotNull String getPromptText(@NotNull ConversationContext conversationContext) { - return "Enter a block description for the custom inventory:"; + return "Enter a description for the custom inventory:"; } @Override 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 a9b1368..8546f03 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 @@ -4,23 +4,40 @@ 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.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.LeatherArmorMeta; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -public class ItemPrompt extends ValidatingPrompt { +public class ItemPrompt extends FixedSetPrompt { + + public ItemPrompt() { + super("ok"); + } + + protected ItemPrompt(String... fixedSet) { + super(fixedSet); + } @Override protected @Nullable Prompt acceptValidatedInput(@NotNull ConversationContext conversationContext, @NotNull String input) { - conversationContext.setSessionData("inventoryItem", ((Player)conversationContext.getForWhom()).getInventory().getItemInMainHand()); + ItemStack item = ((Player)conversationContext.getForWhom()).getInventory().getItemInMainHand(); + conversationContext.setSessionData("itemMaterial", item.getType().name()); + if(item.hasItemMeta() && item.getItemMeta().hasCustomModelData()) { + conversationContext.setSessionData("cmd", item.getItemMeta().getCustomModelData()); + } + if(item.getType().name().startsWith("LEATHER")) { + LeatherArmorMeta meta = (LeatherArmorMeta) item.getItemMeta(); + conversationContext.setSessionData("color", meta.getColor().asRGB()); + } 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"); + && super.isInputValid(context, input); } @@ -28,4 +45,5 @@ protected boolean isInputValid(@NotNull ConversationContext context, @NotNull St public @NotNull String getPromptText(@NotNull ConversationContext conversationContext) { 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 5955ce0..0eaaaf9 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 @@ -2,9 +2,12 @@ import com.mcmiddleearth.architect.specialBlockHandling.customInventories.editor.prompt.add.BlockDataPrompt; import org.bukkit.conversations.ConversationContext; +import org.bukkit.conversations.Prompt; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.Arrays; +import java.util.Map; public class ChangeBlockDataPrompt extends BlockDataPrompt { @@ -13,15 +16,31 @@ public ChangeBlockDataPrompt(String... blockStateKeys) { } @Override + @SuppressWarnings("unchecked") public @NotNull String getPromptText(@NotNull ConversationContext conversationContext) { + Map blockData = (Map) conversationContext.getSessionData("blockData"); + assert blockData != null; return "Current blockData"+getBlockStateKeys()[0]+" is " - +conversationContext.getSessionData(getBlockStateKeys()[0])+". Left-click a block to use for blockData"+getBlockStateKeys()[0]+". Or type !skip!"; + +blockData.get(getBlockStateKeys()[0])+". Left-click a block to use for blockData"+getBlockStateKeys()[0] + +". Or type '!skip'. You may also type in valid block data."; } - private static String[] getFixedSet(String[] blockstateKeys) { - String[] result = Arrays.copyOf(blockstateKeys, blockstateKeys.length+1); - result[result.length-1] = "!skip"; - return result; + @Override + protected boolean isInputValid(@NotNull ConversationContext conversationContext, @NotNull String input) { + return input.equalsIgnoreCase("!skip") || super.isInputValid(conversationContext, input); } + @Override + protected @Nullable Prompt acceptValidatedInput(@NotNull ConversationContext conversationContext, @NotNull String input) { + if (!input.equalsIgnoreCase("!skip")) { + super.acceptValidatedInput(conversationContext, input); + } + if(getBlockStateKeys().length>1) { + return new ChangeBlockDataPrompt(Arrays.copyOfRange(getBlockStateKeys(),1,getBlockStateKeys().length)); + } else { + return new ChangeItemPrompt(); + } + } + + } 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 e499fee..0006dc6 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 @@ -1,28 +1,23 @@ package com.mcmiddleearth.architect.specialBlockHandling.customInventories.editor.prompt.edit; +import com.mcmiddleearth.architect.specialBlockHandling.customInventories.editor.prompt.add.BlockIdPrompt; import com.mcmiddleearth.architect.specialBlockHandling.data.SpecialBlockInventoryData; 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 ChangeBlockIdPrompt extends ValidatingPrompt { +public class ChangeBlockIdPrompt extends BlockIdPrompt { @Override public @NotNull String getPromptText(@NotNull ConversationContext conversationContext) { return "Current item id is "+conversationContext.getSessionData("id")+". Enter a new id or '!skip'."; } - @Override - protected boolean isInputValid(@NotNull ConversationContext conversationContext, @NotNull String input) { - return SpecialBlockInventoryData.getSpecialBlock(conversationContext.getSessionData("rpName")+"/"+input) - == null; - } - @Override public @Nullable Prompt acceptValidatedInput(@NotNull ConversationContext conversationContext, @NotNull String input) { if(!input.equalsIgnoreCase("!skip")) { + conversationContext.setSessionData("oldId", conversationContext.getSessionData("id")); conversationContext.setSessionData("id",input); } return new ChangeBlockTypePrompt(); 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 0110e3a..a5218bb 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 @@ -9,7 +9,7 @@ import java.util.Arrays; -public class ChangeBlockTypePrompt extends FixedSetPrompt { +public class ChangeBlockTypePrompt extends BlockTypePrompt { public ChangeBlockTypePrompt() { super(getFixedSet()); @@ -20,8 +20,9 @@ public ChangeBlockTypePrompt() { if(!input.equalsIgnoreCase("!skip")) { conversationContext.setSessionData("type",input); } + String type = (String) conversationContext.getSessionData("type"); assert type != null; for (String[] blockDatum : BlockTypePrompt.blockData) { - if (input.equalsIgnoreCase(blockDatum[0])) { + if (type.equalsIgnoreCase(blockDatum[0])) { String[] blockOrientations = Arrays.copyOfRange(blockDatum, 1, blockDatum.length); if(blockOrientations.length == 0) { return new ChangeItemPrompt(); 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 e95c86e..c9ad960 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,15 +1,15 @@ package com.mcmiddleearth.architect.specialBlockHandling.customInventories.editor.prompt.edit; +import com.mcmiddleearth.architect.specialBlockHandling.customInventories.editor.prompt.add.CategoryVisiblePrompt; 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 class ChangeCategoryVisiblePrompt extends CategoryVisiblePrompt { public ChangeCategoryVisiblePrompt() { - super("yes", "no", "!skip"); + super(getFixedSet()); } @Override @@ -17,11 +17,15 @@ public ChangeCategoryVisiblePrompt() { if(!input.equalsIgnoreCase("!skip")) { conversationContext.setSessionData("inCategory", input.equalsIgnoreCase("yes")); } - return END_OF_CONVERSATION; + return new ChangeSlotPrompt(); } @Override public @NotNull String getPromptText(@NotNull ConversationContext conversationContext) { return "Should the inventory item be listed directly in the category of it's collection? "+formatFixedSet(); } + + private static String[] getFixedSet() { + return new String[]{"yes", "no", "!skip"}; + } } 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 index 00a5346..2c1f1b0 100644 --- 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 @@ -6,16 +6,17 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -public class ChangeCmdPrompt extends CmdPrompt { +import java.util.Objects; - @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'"; - } +public class ChangeCmdPrompt extends CmdPrompt { @Override protected @Nullable Prompt acceptValidatedInput(@NotNull ConversationContext conversationContext, @NotNull String input) { super.acceptValidatedInput(conversationContext, input); - return new ChangeColorPrompt(); + if(((String) Objects.requireNonNull(conversationContext.getSessionData("itemMaterial"))).startsWith("LEATHER")) { + return new ChangeColorPrompt(); + } else { + return new ChangeDisplayPrompt(); + } } } 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 index f65a20a..b5bc016 100644 --- 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 @@ -8,11 +8,6 @@ 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); 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 44a62e8..6ce93fa 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,18 +1,17 @@ package com.mcmiddleearth.architect.specialBlockHandling.customInventories.editor.prompt.edit; import com.mcmiddleearth.architect.specialBlockHandling.customInventories.CustomInventoryCollectionState; -import com.mcmiddleearth.architect.specialBlockHandling.customInventories.editor.prompt.add.CategoryVisiblePrompt; +import com.mcmiddleearth.architect.specialBlockHandling.customInventories.editor.prompt.add.DisplayPrompt; 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 { +public class ChangeDisplayPrompt extends DisplayPrompt { @Override public @NotNull String getPromptText(@NotNull ConversationContext conversationContext) { - return "Current description is "+conversationContext.getSessionData("description") + return "Current description is "+conversationContext.getSessionData("display") +". Type in new description for the custom inventory or type '!skip'."; } 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 9d0bcaf..61354d5 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,15 +1,16 @@ package com.mcmiddleearth.architect.specialBlockHandling.customInventories.editor.prompt.edit; -import com.mcmiddleearth.architect.specialBlockHandling.customInventories.editor.prompt.add.DisplayPrompt; +import com.mcmiddleearth.architect.specialBlockHandling.customInventories.editor.prompt.add.ItemPrompt; import org.bukkit.Material; import org.bukkit.conversations.ConversationContext; -import org.bukkit.conversations.FixedSetPrompt; import org.bukkit.conversations.Prompt; import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.LeatherArmorMeta; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -public class ChangeItemPrompt extends FixedSetPrompt { +public class ChangeItemPrompt extends ItemPrompt { public ChangeItemPrompt() { super("ok", "!skip"); @@ -18,7 +19,15 @@ public ChangeItemPrompt() { @Override protected @Nullable Prompt acceptValidatedInput(@NotNull ConversationContext conversationContext, @NotNull String input) { if(!input.equalsIgnoreCase("!skip")) { - conversationContext.setSessionData("inventoryItem", ((Player) conversationContext.getForWhom()).getInventory().getItemInMainHand()); + ItemStack item = ((Player)conversationContext.getForWhom()).getInventory().getItemInMainHand(); + conversationContext.setSessionData("itemMaterial", item.getType()); + if(item.hasItemMeta() && item.getItemMeta().hasCustomModelData()) { + conversationContext.setSessionData("cmd", item.getItemMeta().getCustomModelData()); + } + if(item.getType().name().startsWith("LEATHER")) { + LeatherArmorMeta meta = (LeatherArmorMeta) item.getItemMeta(); + conversationContext.setSessionData("color", meta.getColor().asRGB()); + } } return new ChangeCmdPrompt(); } diff --git a/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/edit/ChangeSlotPrompt.java b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/edit/ChangeSlotPrompt.java new file mode 100644 index 0000000..33820ab --- /dev/null +++ b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/edit/ChangeSlotPrompt.java @@ -0,0 +1,35 @@ +package com.mcmiddleearth.architect.specialBlockHandling.customInventories.editor.prompt.edit; + +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 ChangeSlotPrompt extends FixedSetPrompt { + + public ChangeSlotPrompt() { + super("A0", "A1", "A4", "B2", "B4", "C2", "C4", "D2", "D4", "E0", "E1", "E4", + "F1", "F4", "G2", "G4", "H2", "H4", "I2", "I4", "J1", "J4", "!skip"); + } + + @Override + protected @Nullable Prompt acceptValidatedInput(@NotNull ConversationContext conversationContext, @NotNull String input) { + if(!input.equalsIgnoreCase("!skip")) { + conversationContext.setSessionData("oldSlot", conversationContext.getSessionData("slot")); + conversationContext.setSessionData("slot", input); + } + return END_OF_CONVERSATION; + } + + @Override + public @NotNull String getPromptText(@NotNull ConversationContext conversationContext) { + return "Current item slot is "+conversationContext.getSessionData("slot") + +". Type in a new slot for the inventory item or '!skip'. "+formatFixedSet(); + } + + @Override + protected @Nullable String getFailedValidationText(@NotNull ConversationContext context, @NotNull String invalidInput) { + return "You need to type in a slot label or '!skip'."; + } +} diff --git a/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/edit/EditPrompt.java b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/edit/EditPrompt.java index d3430cc..d934dd8 100644 --- a/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/edit/EditPrompt.java +++ b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/customInventories/editor/prompt/edit/EditPrompt.java @@ -9,7 +9,7 @@ public class EditPrompt extends FixedSetPrompt { public EditPrompt() { - super("edit", "delete", "none"); + super("edit", "delete"); } @Override @@ -24,6 +24,11 @@ public EditPrompt() { @Override public @NotNull String getPromptText(@NotNull ConversationContext conversationContext) { - return "What do you want to do with inventory entry "+conversationContext.getSessionData("id")+"? "+formatFixedSet(); + return "What do you want to do with inventory item "+conversationContext.getSessionData("id")+"? "+formatFixedSet(); + } + + @Override + protected @Nullable String getFailedValidationText(@NotNull ConversationContext context, @NotNull String invalidInput) { + return "You need to type in 'edit' or 'delete'. Or you may '!cancel' at any point of the conversation."; } } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 0ff5137..d87ca2a 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -119,7 +119,7 @@ permissions: architect.bannerEditor.delete: true architect.inventory.reload: true architect.inventory.other: true - archtiect.inventory.edit: true + architect.inventory.edit: true architect.get.other: true architect.weather: true archtiect.resourcePackAdmin: true