Jump to content
Joseph

Herb Snippet

Recommended Posts

So i had this laying around, and i'm not working with herbs anymore so here you go.

 

Some credits to @Kenneh

public enum Herb    {
    GUAM(3, 249, 250, 199, 200),
    MARRENTILL(5, 251, 252, 201, 202),
    TARROMIN(11, 253, 254, 203, 204),
    HARRALANDER(20, 255, 256, 205, 206),
    RANARR(25, 257, 258, 207, 208),
    TOADFLAX(30, 2998, 2999, 3049, 3050),
    IRIT(40, 259, 260, 209, 210),
    AVANTOE(48, 261, 262, 211, 212),
    KWUARM(54, 263, 264, 213, 214),
    SNAPDRAGON(59, 3000, 3001, 3051, 3052),
    CADANTINE(65, 265, 266, 215, 216),
    LANTADYME(67, 2481, 2482, 2485, 2486),
    DWARFWEED(70, 267, 268, 217, 218),
    TORSTOL(75, 269, 270, 219, 220);

    private int idLevel, unnotedCleanId, notedCleanId, unnotedGrimyId, notedGrimyId;

    Herb(int idLevel, int unnotedCleanId, int notedCleanId,  int unnotedGrimyId, int notedGrimyId)    {
        this.idLevel = idLevel;
        this.unnotedCleanId = unnotedCleanId;
        this.notedCleanId = notedCleanId;
        this.unnotedGrimyId = unnotedGrimyId;
        this.notedGrimyId = notedGrimyId;
    }

    public static Herb get(int index)    {
        for (Herb h: values())
            if (index == h.ordinal())
                return h;
        return null;
    }

    public int getUnnotedGrimyId() {
        return unnotedGrimyId;
    }

    public int getIdLevel() {
        return idLevel;
    }

    public int getUnnotedCleanId() {
        return unnotedCleanId;
    }

    public int getNotedCleanId() {
        return notedCleanId;
    }

    public int getNotedGrimyId() {
        return notedGrimyId;
    }

    public String getName() {
        return name().charAt(0) +  name().substring(1).toLowerCase();
    }

    public boolean canIdHerb(int currentLevel)    {
        return currentLevel >= idLevel;
    }
}
Edited by josedpay
Link to comment
Share on other sites

Okay, first before you read the rest of this, I want to say thanks for providing all the IDs.

 

But, you're using an enum wrong.

 

public enum Herb    {
    GUAM(3, 249, 250, 199, 200),
    MARRENTILL(5, 251, 252, 201, 202),
    TARROMIN(11, 253, 254, 203, 204),
    HARRALANDER(20, 255, 256, 205, 206),
    RANARR(25, 257, 258, 207, 208),
    TOADFLAX(30, 2998, 2999, 3049, 3050),
    IRIT(40, 259, 260, 209, 210),
    AVANTOE(48, 261, 262, 211, 212),
    KWUARM(54, 263, 264, 213, 214),
    SNAPDRAGON(59, 3000, 3001, 3051, 3052),
    CADANTINE(65, 265, 266, 215, 216),
    LANTADYME(67, 2481, 2482, 2485, 2486),
    DWARFWEED(70, 267, 268, 217, 218),
    TORSTOL(75, 269, 270, 219, 220);

    private int idLevel, unnotedCleanId, notedCleanId, unnotedGrimyId, notedGrimyId;

    Herb(int idLevel, int unnotedCleanId, int notedCleanId,  int unnotedGrimyId, int notedGrimyId)    {
        this.idLevel = idLevel;
        this.unnotedCleanId = unnotedCleanId;
        this.notedCleanId = notedCleanId;
        this.unnotedGrimyId = unnotedGrimyId;
        this.notedGrimyId = notedGrimyId;
    }

    public static Herb get(int index)    {
        for (Herb h: values())
            if (index == h.ordinal())
                return h;
        return null;
    }

    public int getUnnotedGrimyId() {
        return unnotedGrimyId;
    }

    public int getIdLevel() {
        return idLevel;
    }

    public int getUnnotedCleanId() {
        return unnotedCleanId;
    }

    public int getNotedCleanId() {
        return notedCleanId;
    }

    public int getNotedGrimyId() {
        return notedGrimyId;
    }

    public String getName() {
        return name().charAt(0) +  name().substring(1).toLowerCase();
    }

    public boolean canIdHerb(int currentLevel)    {
        return currentLevel >= idLevel;
    }
}

 

ftfy

Edited by Kenneh
Link to comment
Share on other sites

Why do people always tell me I'm using enum wrong I know exactly what I'm doing -.- the only reason why I have it that way is so, let's say your using a combo box or a list, and they chose a herb from the list. You use getSelectedIndex() (from with or, combo box or list) which returns an int, you use the int that they chose, within the get(int index) which will return the herb the chose. Now you could simply use the other methods that use a herb argument. To return what ever you need, for example name, or ids. You could make an AIO with simply two or three lines of code. Rather Then using a for loop, switch statement, or even a nested if and else statement Which takes up a bunch of lines.

Sorry for the rant, and you didn't fix anything for me you just dumbed it down for everyone else

Edited by josedpay
Link to comment
Share on other sites

Why do people always tell me I'm using enum wrong I know exactly what I'm doing -.- the only reason why I have it that way is so, let's say your using a combo box or a list, and they chose a herb from the list. You use getSelectedIndex() (from with or, combo box or list) which returns an int, you use the int that they chose, within the get(int index) which will return the herb the chose. Now you could simply use the other methods that use a herb argument. To return what ever you need, for example name, or ids. You could make an AIO with simply two or three lines of code. Rather Then using a for loop, switch statement, or even a nested if and else statement Which takes up a bunch of lines.

Sorry for the rant, and you didn't fix anything for me you just dumbed it down for everyone else

he posted a more correct usage of enums.
Link to comment
Share on other sites

Why do people always tell me I'm using enum wrong I know exactly what I'm doing -.- the only reason why I have it that way is so, let's say your using a combo box or a list, and they chose a herb from the list. You use getSelectedIndex() (from with or, combo box or list) which returns an int, you use the int that they chose, within the get(int index) which will return the herb the chose. Now you could simply use the other methods that use a herb argument. To return what ever you need, for example name, or ids. You could make an AIO with simply two or three lines of code. Rather Then using a for loop, switch statement, or even a nested if and else statement Which takes up a bunch of lines.

Sorry for the rant, and you didn't fix anything for me you just dumbed it down for everyone else

 

Comboboxes have getSelectedItem() and getSelectedItemList() though.

Link to comment
Share on other sites

If I'm wrong then I don't now why I brother to help

 

I'm just trying to help. Here's a little example.

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * Created by Kenneth on 3/22/14.
 */
public class HerbGUI extends JFrame {

    public JComboBox<Herb> comboBox = new JComboBox<>(Herb.values());
    public JButton startButton = new JButton("Start");

    public Herb singleHerb;

    public HerbGUI() {
        getContentPane().setLayout(new FlowLayout());
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        getContentPane().add(comboBox);
        getContentPane().add(startButton);

        startButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {

                singleHerb = (Herb) comboBox.getSelectedItem();
                System.out.println(singleHerb.getIdLevel());
                System.out.println(singleHerb.getName());
                System.out.println(singleHerb.getNotedGrimyId());
            }
        });
        pack();
        setVisible(true);
    }


    public static void main(String[] args) {
        new HerbGUI();
    }

}


Edited by Kenneh
Link to comment
Share on other sites

Guest
This topic is now closed to further replies.


  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...