Solved Check for a certain block?

Discussion in 'Plugin Development' started by PolarCraft, Dec 5, 2013.

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

    PolarCraft

    Like how would you check for a certain block?

    I have the block check but I am checking if the blocks are in the config. If so cancel them from being used.

    Error: The method getBlock() is undefined for the type List<String>

    String m: List<String> m = plugin.getConfig().getStringList("blocks");

    Line: if(m.getBlock().getType().equals(Material.AIR));
     
  2. Offline

    Darq

    I would load the values of the config into a EnumSet one time, and then access .contains(Material.AIR); on that set. Loop through your configured strings, and get each Material with Material.matchMaterial(String material);. I used an EnumSet because it's implemented to handle Enum types in incredibly optimized ways. Much faster than an ArrayList.
     
  3. Offline

    PolarCraft

    Darq Not what i really meant. I am trying to repair only certain items. But I do not want other items to get repaired.
    To be repaired:
    1 - Armor
    2 - Tools
    To not:
    1 - blocks
     
  4. Offline

    Darq

    I need to get better at explaining things in English. Here's some CODE!

    Code:
    EnumSet<Material> repairable = EnumSet.noneOf(Material.class);
    EnumSet<Material> unrepairable = EnumSet.noneOf(Material.class);
     
    void loadConfig() {
        for (String material : config.getStringList("tools")) {
            repairable.add(Material.matchMaterial(material));
        }
        for (String material : config.getStringList("blocks")) {
            unrepairable.add(Material.matchMaterial(material));
        }
    }
     
    boolean isRepairable(Material material) {
        return repairable.contains(material);
    }
     
    boolean isNotRepairable(Material material) {
        return unrepairable.contains(material);
    }
    
    Is this what you wanted? :S

    Oops, that's now how you make a new EnumsSet, editing to fix.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 5, 2016
Thread Status:
Not open for further replies.

Share This Page