Skip to content

Commit

Permalink
version 2.9.15
Browse files Browse the repository at this point in the history
adding custom inventory editor
  • Loading branch information
EriolEandur committed Dec 6, 2024
1 parent 81af16a commit d88e3d8
Show file tree
Hide file tree
Showing 14 changed files with 279 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -144,14 +145,19 @@ 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"));
context.setSessionData("type", itemSection.get("type"));
context.setSessionData("cmd", itemSection.get("cmd"));
context.setSessionData("display", itemSection.get("display"));
context.setSessionData("inCategory", itemSection.contains("category"));

Map<String,String> blockData = (Map<String,String>) 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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -79,4 +78,8 @@ public void onSelectBlockstate(PlayerInteractEvent event) {
}
}
}

protected String[] getBlockStateKeys() {
return blockStateKeys;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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'.";
}
}
Original file line number Diff line number Diff line change
@@ -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'";
}
}
Original file line number Diff line number Diff line change
@@ -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'.";
}
}
Original file line number Diff line number Diff line change
@@ -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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,37 +1,47 @@
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
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;
};
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;
}
}
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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();
}
}
Loading

0 comments on commit d88e3d8

Please sign in to comment.