New requirements
bilwjjsai0093 opened this issue · 1 comments
Please forgive me for using translation software!
But I really need a practical feature, and here's the rough effect
//Convert ItemStack to String
public static String item_to_yml(ItemStack itemStack) {
YamlConfiguration yml = new YamlConfiguration();
yml.set("item", itemStack);
return yml.saveToString();
}
//Convert String to ItemStack
public static ItemStack ymltoitem(String str) {
YamlConfiguration yml = YamlConfiguration.loadConfiguration(file);
ItemStack item;
try {
yml.loadFromString(str);
item = yml.getItemStack("item");
} catch (InvalidConfigurationException ex) {
item = new ItemStack(Material.AIR, 1);
}
return item;
}
When I use id in the recipe file, I can get the ItemStack directly
//New Command
saveItem id //saved player mainhand item in file
☹I hope you understand what I mean, thank you!!!!
public static void getItem(String id){
//After I get the item, I can use it directly in the recipe
File file = new File("plugins/MyIDEA/SavedItems.yml");
YamlConfiguration yaml = YamlConfiguration.loadConfiguration(file);
String item = yaml.getString(id);
ItemStack itemStack = getItemStack(item);
}
public static String getString(ItemStack itemStack){
//add a command /rmsaveitem to save the item
// /rmsaveitem <id> //save player main hand item
YamlConfiguration yaml = new YamlConfiguration();
yaml.set("item", itemStack);
return yaml.saveToString();
}
public static ItemStack getItemStack(String str){
YamlConfiguration yaml = new YamlConfiguration();
try {
yaml.loadFromString(str);
} catch (Exception e) {
e.printStackTrace();
}
return yaml.getItemStack("item");
}