List every available PotionEffect(Type)

Discussion in 'Resources' started by Panjab, Aug 15, 2013.

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

    Panjab

    There's an easy way to make a list of all PotionEffectTypes:

    Code:
    public String getPotionEffectTypes() {
        StringBuilder sb = new StringBuilder();
        PotionEffectType[] effects = PotionEffectType.values();
     
        for (PotionEffectType effect : effects) {
            if (sb.length() > 0) {
                sb.append(", ");
            }
     
            if (effect != null) sb.append(effect.getName());    // If you don't want to have the names in CAPSLOCK, easily put a .toLowerCase(); behind
        }
     
        return sb.toString();
    }
    You can remove the variable 'effects' for sure, you just have to put the 'PotionEffectType.values();' into the loop instead of 'effects' ;)

    Enjoy! :)
     
  2. Offline

    flaaghara

    effects is an array.
    Code:
    PotionEffectType effects = PotionEffectType.values();
    should be
    Code:
    PotionEffectType[] effects = PotionEffectType.values();
     
  3. Offline

    Panjab

    You're right. I forgot it, thanks for your information! :)
     
  4. Offline

    xTrollxDudex

    Panjab
    Isn't this like, teaching people java? Each enum should have a values() method, but let me check

    Edit: nvm
     
  5. Offline

    afistofirony

    xTrollxDudex Yep, all enums have the values() method. As its name suggests, it returns an array containing every value in the enum.
     
  6. Offline

    xTrollxDudex

  7. Offline

    Kazzababe

  8. Offline

    xTrollxDudex

Thread Status:
Not open for further replies.

Share This Page