Solved Check if a string is equal to a material

Discussion in 'Plugin Development' started by ThunderWaffeMC, Apr 28, 2014.

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

    ThunderWaffeMC

    Hi. I'm trying to check if a string is equal to a material but I'm getting an error in eclipse.

    Code:java
    1.  
    2. if(Material.matchMaterial("dirt") != null) {
    3. //it's an item
    4. } else {
    5. //it's not an item
    6. }
    7.  


    Error: The method matchMaterial(String) is undefined for the type Material

    Any ideas?
     
  2. Offline

    Zwander

    Nope, not a clue. Are you sure you don't have an error above it that's making it error? Eclipse does that.
     
  3. Offline

    ThunderWaffeMC

    Well I've also tried:

    Code:java
    1.  
    2. public boolean isMaterial(String string) {
    3. try {
    4. Material material = Material.getMaterial(string);
    5. } catch(Exception e) {
    6. e.printStackTrace();
    7. return false;
    8. }
    9. }
    10.  


    and I get an error on getMaterial() (same error than above). Must be something wrong with the Material class for my version of bukkit.

    Edit: Turned out I had the wrong Material import (minecraft.net import) instead of org.bukkit.Material.
     
  4. Offline

    DrEinsteinium

    AdamQpzm ThunderWaffeMC
    Code:
    String str = "diamond_sword";
    for(Material mat : Material.values())
            if(mat.toString().equalsIgnoreCase(str)
                return mat;
    
     
  5. DrEinsteinium That's one way of doing it, yes. Not at all the way I'd do it, but still.

    But if he's getting that matchMaterial(String) isn't defined for Material, he's probably got a different problem.
     
  6. Offline

    DrEinsteinium


    I just put that because it works with every Enum class :)
     
Thread Status:
Not open for further replies.

Share This Page