Untitled

mail@pastecode.io avatar
unknown
java
12 days ago
1.7 kB
3
Indexable
Never
package com.trexmine.bedwars.database.content;

import com.trexmine.bedwars.menu.ItemType;
import lombok.Getter;

import java.util.Arrays;

@Getter
public final class QuickbuyData {

    private final int[] base = new int[21];
    private final int[] changes = new int[21];
    private final int[] changesReversed = new int[ItemType.values().length];

    private boolean modified, temporary;

    public QuickbuyData() {
        Arrays.fill(changesReversed, -1);
    }

    public QuickbuyData defaults() {
        for (int i = 0; i < ItemType.DEFAULTS.size(); i++) {
            register(i, ItemType.DEFAULTS.get(i));
        }
        return this;
    }

    public QuickbuyData temporary() {
        temporary = true;
        return this;
    }

    public void register(int slot, int id) {
        base[slot] = id;
        changes[slot] = id;
        changesReversed[id ] = slot;
    }

    public int getId(int slot) {
        return changes[slot];
    }

    public int getSlot(int id) {
        return changesReversed[id];
    }

    public ItemType getHolder(int slot) {
        return ItemType.byId(changes[slot]);
    }

    public void set(int slot, ItemType value) {
        set(slot, value.ordinal());
    }

    public void set(int slot, int id) {
        if (changes[slot] != id) {
            modified = true;
            changes[slot] = id;
            changesReversed[id] = slot;
        }
    }

    public QuickbuyData applyChanges(QuickbuyData data) {
        return applyChanges(data.getChanges());
    }

    public QuickbuyData applyChanges(int[] newChanges) {
        for (int i = 0; i < newChanges.length; i++) {
            set(i, newChanges[i]);
        }
        return this;
    }
}
Leave a Comment