Getting Item ID's with colons from config issue

Discussion in 'Plugin Development' started by OTF Catastrophe, Jul 26, 2016.

Thread Status:
Not open for further replies.
  1. Offline

    OTF Catastrophe

    Alright so I've been working on trying to find out how to get values from config from a string. I've come to the conclusion that any integer values without colons in them are usable, but as soon as I try to use the item ID of, let's say a stained clay block, it won't work. I thought possibly putting the integer in two apostrophes would make it so it could read it no matter what data is attached to the number. Does anyone know how to get block ID's from a config string that has colons in it? (Example: 159:14 is Red Stained Clay)

    Code: (To look for the block the player is standing on)
    Code:
    if (loc.subtract(0.0D, 1.0D, 0.0D).getBlock().getType() == Material.matchMaterial(config.getString("Modifications.checkpointItem.itemID")))
    {
    // Other stuff
    Config Section:

    Code:
    Modifications:
      checkpointItem:
        itemID: (ID HERE)
     
  2. Offline

    ArsenArsen

    matchMaterial matches a name. You need to loop and check for the ID (the thing before colon) then check its data.
    Material does not hold data, youll have to check the durability seperatly.
     
  3. Offline

    OTF Catastrophe

    I forgot to ask if anyone was willing to give me the uh, less smart answer since I'm not 100% familiar with the language. Any chance you could possibly spoon feed me a little? If not that's totally fine, any help is appreciated ^-^ Thank you for your response
     
  4. Offline

    ArsenArsen

    Well I forgot my spoon (not on accident) but:

    String s;
    String[] split = s.split(Pattern.quote(":"))
    int id = parseInt(split index 0)
    int durability = parseInt(split index 1)

    In your brand new getFromId(string id) method
    for every Material in array that is Material.values()
    If Material.getId()1 == id then return that material
    Outside of the loop return false

    Then if blocks type is getFromId of id and blocks states toItemStacks get durability is durability then you have yourself a match.

    1 getId is deprecated

    By the way, learn java. Saves time. Alot of it. Saying from experience.
    Not saying you don't know it, I have no idea to be honest, but for everyone reading this in the future, please do.
     
    Last edited: Jul 26, 2016
  5. Offline

    OTF Catastrophe

    Instead of just blatantly saying I have no clue how to fully go about this, I've decided to try some stuff out and see if I'm at least doing something semi right. Here my unfinished attempt at a "brand new getFromId":

    Code:
        public static final int getFromId(String s)
        {
    
            String[] split = s.split(Pattern.quote(":"));
           
            int id = Integer.parseInt(split[0]);
            int durability = Integer.parseInt(split[1]);
           
            if (Material.getId() == id)
            {
               
                //TO-DO
               
            }
           
            return id;
    
        }
    Two things, any chance you could help me out a little bit more? And also, am I even close aha? I genuinely feel like I'm getting somewhere I just can't seem to piece it together in my mind the correct way to go about it.
     
  6. Offline

    ArsenArsen

    @OTF Catastrophe you are getting there, but may I suggest loop through Material.values, and compare the id's, if they are the same make a new itemstack with that material and durability and return it.

    I'm on my phone buut
    for(Material material : Material.values) {...
     
  7. @OTF Catastrophe Remove the pattern stuff just have the string ":", also surround your parses with a try catch (NumberFormatException) so you know if it's invalid and can handle it.
     
  8. Offline

    OTF Catastrophe

    If i had to compare the id's of each of the blocks with durability after it, would I have to point out every single block to test for in the code? Or is there a shorter way to check all the blocks with durability?
     
Thread Status:
Not open for further replies.

Share This Page