Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public enum Consumable {
- ATTACK_POTION(Type.COMBAT_POTION, Items.ATTACK_POTION_4, Items.ATTACK_POTION_3, Items.ATTACK_POTION_2, Items.ATTACK_POTION_1) {
- @Override
- public void onConsumption() {
- }
- },
- ;
- private Type type;
- private int[] ids;
- Consumable(Type type, int... ids) {
- this.ids = ids;
- this.type = type;
- }
- public abstract void onConsumption();
- public Item replacement(int id) {
- if (isConsumablePotion(id)) {
- int index = getIds().indexOf(id);
- if (index == getIds().size())
- return new Item(229);
- else
- return new Item(index + 1);
- }
- return new Item(-1);
- }
- public List<Integer> getIds() {
- return Arrays.stream(ids).boxed().collect(Collectors.toList());
- }
- public static Optional<Consumable> get(int id) {
- return Arrays.stream(values()).filter(consumable -> consumable.getIds().contains(id)).findFirst();
- }
- private boolean isConsumablePotion(int id) {
- return Arrays.asList(Type.COMBAT_POTION, Type.RECOVERY_POTION, Type.CURES_OR_ANTI_POTION, Type.SKILL_POTION, Type.WEAPON_POISON_POTION).contains(id);
- }
- public enum Type {
- UNFINISHED_POTION, COMBAT_POTION, RECOVERY_POTION, CURES_OR_ANTI_POTION, SKILL_POTION, WEAPON_POISON_POTION,
- }
- }
Add Comment
Please, Sign In to add comment