Can I do that anyway faster?

Discussion in 'Spigot Plugin Development' started by zozidalom, Jun 11, 2016.

  1. I am collecting ALL sounds to my bukkit plugin but there are a lot of them :D
    I would need them this way:
    if (main.getConfig().getBoolean("BLOCK_GRAVEL_STEP") == true) {
    p.playSound(loc, Sound.BLOCK_GRAVEL_STEP, volume, volume);
    }if (main.getConfig().getBoolean("BLOCK_IRON_DOOR_CLOSE") == true) {
    p.playSound(loc, Sound.BLOCK_IRON_DOOR_CLOSE, volume, volume);
    }if (main.getConfig().getBoolean("BLOCK_IRON_DOOR_OPEN") == true) {
    p.playSound(loc, Sound.BLOCK_IRON_DOOR_OPEN, volume, volume);
    }if (main.getConfig().getBoolean("BLOCK_IRON_TRAPDOOR_CLOSE") == true) {
    p.playSound(loc, Sound.BLOCK_IRON_TRAPDOOR_CLOSE, volume, volume);
    }if (main.getConfig().getBoolean("BLOCK_IRON_DOOR_OPEN") == true) {
    p.playSound(loc, Sound.BLOCK_IRON_TRAPDOOR_OPEN, volume, volume);
    Any ideas how to do that faster?
  2. First of all, instead of doing this:

    Code (Text):
    if (boolean == true) {
    you should be doing this:

    Code (Text):
    if (boolean) {
    or if you want to check if it's false:

    Code (Text):
    if (!boolean) {
    As for your question on how to make it faster, could you maybe show your config first?
  3. you can use Sound.values() and toString() to iterate over it.
  4. Sound#valueOf(String)

    Also, if(true) is the same as if(true == true).
    The == is redundant.

    Same as:
    Code (Java):
    boolean x = true;
    boolean y = true;
    if (x == y) // aka if (true == true). Just if (x) or if (true)