Get material with half the name?

Discussion in 'Plugin Development' started by BetaNyan, Oct 31, 2014.

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

    BetaNyan

    I am creating a Shop plugin and with colors the whole name of the item cant fit on the sign.

    So &b&lYellow_Flower Doesn't fit

    How can I get the material with YELLOW_FLOW, anyway to basically auto-complete it?
     
  2. loop through all materials:
    Code:Java
    1.  
    2. public Material getMaterial(String name){
    3. Material theMaterial = null;
    4. for(Material material : Material.values()) {
    5.  
    6. }
    7. return theMaterial;
    8. }


    get the material name and check if it starts with the String of the sign:
    Code:Java
    1. if(material.name().toLowerCase().startsWith(name.toLowerCase())) {
    2. theMaterial = material;
    3. }

    ^
    |
    inside the for loop


    That should work :D
     
    BetaNyan likes this.
  3. Offline

    BetaNyan

    You da real MVP, Thanks!
     
  4. and to remove the color codes:
    Code:java
    1. ChatColor.stripColor(string);
     
Thread Status:
Not open for further replies.

Share This Page