vendredi 20 mars 2020

over reliance on one arrayList

public class InventorySetDAO{
    public LinkedList<CustomInventory> inventories = new LinkedList<>();           
}

I am developing plugin that add/delete data in arraylist. and There's too much reference on the arrayList from other class.

Class InventoryItemModifier:

public class InventoryItemModifier {
InventorySetDAO inventorySetDAO;

public InventoryItemModifier(InventorySetDAO inventorySetDAO){
    this.inventorySetDAO = inventorySetDAO;
}

public void addItem(ItemStack itemStack, ClickAction click, RequiredItems requiredItems) {
    Bukkit.getPluginManager().callEvent(new ItemAddedEvent());

    inventorySetDAO.getLastInventory().addItem(itemStack, click, requiredItems);
}

public void removeItem(ItemStack itemStack){
    Bukkit.getPluginManager().callEvent(new ItemRemovedEvent());

    inventorySetDAO.getLastInventory().removeItem(itemStack);
}

}

Class InventoryPlayerAccessor:

public class InventoryPlayerAccessor {
InventorySetDAO inventorySetDAO;

public boolean openPage(Player player) {
    if (!inventories.isEmpty()) {
        inventories.get(0).openInventory(player);
        return true;
    }
    return false;
}

public boolean openPage(Player player, int index) {
    if (!inventories.isEmpty()) {
        if (index >= 0 && index < inventories.size()) {
            inventories.get(index).openInventory(player);
            return true;
        }
    }
    return false;
}

}

I want to reduce these classes' reliance on the arrayList, so I tried to seperate them into multiple classes, but it doesn't seem to solve this problem.

Aucun commentaire:

Enregistrer un commentaire