Getting potion effects from config

Discussion in 'Plugin Development' started by slater96, Nov 10, 2012.

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

    slater96

    Hey, I'm trying to make an enum for potion effects so that I can check the config for that string for example
    if (plugin.getConfig().getString("Effect").equals(any of the strings in the enum)) {
    // do something
    I've done the enum like this at the moment
    Code:
    public enum PerkEffect {
            DMGRESIST,
            DMGRESISTANCE,
            DAMAGERESIST,
            DAMAGERESISTANCE,
            FASTDIG,
            FASTDIGGING,
            FIRERESIST,
            FIRERESISTANCE,
            HEAL,
            INCREASEDMG,
            INCREASEDAMAGE,
            INVISIBLE,
            INVISIBILITY,
            JUMP,
            NIGHTVISION,
            REGEN,
            REGENERATION,
            SPEED,
            WATERBREATH,
            WATERBREATHING;
           
            private String effect;
           
            PerkEffect (String effect) {
                this.effect = effect;
            }
           
            public String getEffect() {
                return effect;
            }
        }
    However the problem is that the DMGRESIST to WATERBREATHING is red underlined saying the constructor is undefined? Any help please
     
  2. Offline

    thehutch

    you need to put the define the string for the enums

    Example:

    Code:java
    1.  
    2. public enum PerkEffect {
    3. DMGRESIST("DMGERESIST"),
    4. DMGRESISTANCE("DMGERESISTANCE"),
    5. DAMAGERESIST("DAMAGERESIST"),
    6. DAMAGERESISTANCE("DAMAGERESISTANCE"),
    7. FASTDIG("FASTDIG"),
    8. FASTDIGGING("FASTDIGGING"),
    9. FIRERESIST("FIRERESIST"),
    10. FIRERESISTANCE("FIRERESISTANCE"),
    11. HEAL("HEAL"),
    12. INCREASEDMG("INCREASEDMG"),
    13. INCREASEDAMAGE("INCREASEDAMAGE"),
    14. INVISIBLE("INVISIBLE"),
    15. INVISIBILITY("INVISIBILITY"),
    16. JUMP("JUMP"),
    17. NIGHTVISION("NIGHTVISION"),
    18. REGEN("REGEN"),
    19. REGENERATION("REGENERATION"),
    20. SPEED("SPEED"),
    21. WATERBREATH("WATERBREATH"),
    22. WATERBREATHING("WATERBREATHING");
    23.  
    24. private String effect;
    25.  
    26. PerkEffect (String effect) {
    27. this.effect = effect;
    28. }
    29.  
    30. public String getEffect() {
    31. return effect;
    32. }
    33. }
    34. [syntax][/syntax]
     
  3. Offline

    slater96

    Ok thanks that fixed the error. How do I check the config if any of these strings are there like the example i said before, i tried to do PerkEffect.getEffect() but nothing showed up for it.
     
  4. Offline

    Njol

    I suggest a static HashMap<String, PotionEffectType> which you populat with values in a static {} block and then use map.get(input) - if it's null the input is invalid, otherwise you have the correct potion effect type.
    example code:
    Code:
    final static HashMap<String, PotionEffectType> potions = new HashMap<>();
    static {
      potions.put("damage resistance", PotionEffectType.DAMAGE_RESISTANCE);
      potions.put("dmg resist", PotionEffectType.DAMAGE_RESISTANCE);
      //etc.
    }
    
     
    thehutch likes this.
  5. Offline

    thehutch

    Code:java
    1.  
    2. if(plugin.getConfig().getString(path.to.effect).equalsIgnoreCase(PerkEffect.[SIZE=12px][FONT=Consolas][COLOR=#f26100]WATERBREATHING.getEffect()[/COLOR][/FONT][/SIZE])) {
    3. //do stuff
    4. }
    5.  
     
Thread Status:
Not open for further replies.

Share This Page