Solved Saving Itemstacks into an Array.

Discussion in 'Spigot Plugin Development' started by APDevelopment, Aug 3, 2018.

  1. I am working on a plugin that loads Items from config then I need it to get put into some kind of array or collection that I can then use in a different class to drop the item in the world.

    I am going about this all wrong most likely, let me explain further.

    I have a StringList of items in a config, I have a method that grabs them and converts them into a ItemStack, and Itemstack is a super secret undercover agent as a Object and once its in a list it magically turns into an Object, How would I go about converting it back into a Itemstack that I can drop?
     
  2. So are you having problems when trying to take an ItemStack from a config?
    Suppose you save the item by putting the whole stack inside the config, you take it back by using getConfig#getItemStack(<the path where you saved the ItemStack>).

    Hope this helped. I'm not sure what you are actually asking
     
  3. If you have a list of ItemStack in the configuration, you should just be able to cast it.
     
  4. make an ItemStackUtil class and have 2 public static methods that get an item stack from an string and another than returns a string from an item stack
     
  5. make a config like this:
    Code (YAML):
    0:
      display_name
    : "noodles"
      lore
    : "i liek noodles"
      material
    : minecraft:gold_ingot
    and then get the material path and make an itemstack with that material, and then set the lore as the lore path and name as the name path, etc
     
  6. Why do that when you can just save the ItemStack into the config?

    And your method only saves the some elements of the ItemStack. So you cannot save items with enchantments and attributes (you can but you have to write more codes)
     
  7. because its ugly and if you want to write it straight to config its confusing
     
  8. You got your point. He never mentioned how he saves his config after all
     
  9. I was thinking something like this:
    you save a String to a config that looks like this: DIAMOND_SWORD/YoYoYo/Bite;my;diamond;sword/KNOCKBACK/FIRE_ASPECT

    In your method u can make that string a string[] by splitting it with "/"

    each string contains something like material, display name, lore, enchantments...

    this way you can easily save it
     
    • Funny Funny x 1
    • Optimistic Optimistic x 1
    • Creative Creative x 1
  10. fuk no lol thats just way more effort because you have to get the order right and shit
     
    • Inappropriate Behavior
    no your actually trash

    I easily save locations that way its so f***ing easy kitdu just don't understand bc ur 4 y/o
     
  11. Calm down man. @Fizmo is right that's an ugly way of doing it. Why? It's so confusing for the user to set it up. Instead I would create a Utils class to format and get the item stack. Remember to include all the properties of that item or you may have problems
     
  12. Let's "logically" pro/con @LegendxD method:

    Pros:
    • You write less stuff: Since you don't need to add things like "display name", "lore", "material", you can quickly save an item without typing unnecessary words
    • Save spaces: You write less stuff, you save less stuff! Easy!
    Cons:
    • You need to remember all the placements: You are the developer, of course you're gonna remember the order, but to a normal plugin user, seeing this clump of text means nothing to him. Where is the display name? Where is the lore? How many enchantments can I write in?
    • Confusing: Let's use a book as an example: You want to find the page of a chapter. Where do you find it? A table of content! This method is like cramming in chapters without organising it, or just like people typing a paragraph without using punctuations.
    • Unstable: A missing "/" or ";" will mess up your item, and you will need to find it by looking at lines and lines of saved items. It would be way better to have a list of attributes, organised for reading, and easier to spot mistakes.

    Can I have a friendly rating? XD
     
    • Friendly Friendly x 3
  13. No you really don't understand how easy it is...

    This one class does it all foe you in ONE method
     
  14. If this developer intends to use the plugin just for himself, sure, go right ahead. However, knowing -- logically -- off the top of my head that most development time is spent maintaining a code base, I would have to say going @Fizmo's route is the cleaner, more realistic approach.
     
  15. Think about It this way:

    If you want to save a location it would be like this: WORLD/X/Y/Z/[PITCH]/[YAW] **[ ] means optional**
    Its as easy as this: world/100/54/20/1.34/1.20
    You can write a simple method to turn that string into a location
    the thing is that u can save it as a string list which makes it easy to put in a config
     
  16. You're comparing Location to ItemStack
    Now Compare that, to this:
    Code (YAML):
    type: DIAMOND_HOE
          damage
    : 1559
          meta
    :
            ==
    : ItemMeta
            meta-type
    : UNSPECIFIC
            display-name
    : §r§rTurquoise
            lore
    :
          - §a§a§rSome say that Turquoise is an§b§b§r
            - §a§a§ralluring gemstone that holds bits of Hathor's power§b§b§r
            ItemFlags
    :
          - HIDE_ATTRIBUTES
            - HIDE_UNBREAKABLE
            Unbreakable
    : true
            internal
    : H4sIAAAAAAAAAONiYOBgEHQuLS7Jz/UsSc3V80zxS8xNZRDIy88D0lYlpUWFpfmZxakMANsJsKIqAAAA
    You sure about that?
     
  17. 999% sure

    each one of those descriptions has its own spot (/bla black bla/) and there can be multiple like this /one:two:three/ and they can be left blank if there is non / /
     
  18. Well then, sorry I'm not a genius. I don't have the computing power to search through all elements of an ItemStack as quick as a 6-valued Location. Such mistake when I'm trying to explain stuff to a genius! Why a genius need my explanation when everything is as simple as 1+1 to him!