<commit_before>package de.themoep.inventorygui;

/*
 * Copyright 2017 <NAME> (https://github.com/Phoenix616/)
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the Mozilla Public License as published by
 * the Mozilla Foundation, version 2.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * Mozilla Public License v2.0 for more details.
 *
 * You should have received a copy of the Mozilla Public License v2.0
 * along with this program. If not, see <http://mozilla.org/MPL/2.0/>.
 */

import org.bukkit.ChatColor;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;

public class GuiStorageElement extends GuiElement {
    private final Inventory storage;

    private static final int HOTBAR_OFFSET = 36; // Magic number, slots before the hotbar starts

    public GuiStorageElement(char slotChar, Inventory storage) {
        super(slotChar, null);
        setAction(click -> {
            int index = getSlotIndex(click.getSlot());
            if (index == -1 || index >= storage.getSize()) {
                return true;
            }
            ItemStack storageItem = storage.getItem(index);
            ItemStack slotItem = click.getEvent().getView().getTopInventory().getItem(click.getSlot());
            if (storageItem == null && slotItem != null || storageItem != null && !storageItem.equals(slotItem)) {
                click.getEvent().setCancelled(true);
                click.getGui().draw();
                return false;
            }
            ItemStack movedItem = null;
            switch (click.getEvent().getAction()) {
                case NOTHING:
                case CLONE_STACK:
                    return false;
                case MOVE_TO_OTHER_INVENTORY:
                    if (click.getEvent().getRawSlot() < click.getEvent().getView().getTopInventory().getSize()) {
                        movedItem = null;
                    } else {
                        movedItem = click.getEvent().getCurrentItem();
                    }
                    break;
                case HOTBAR_MOVE_AND_READD:
                case HOTBAR_SWAP:
                    int button = click.getEvent().getHotbarButton();
                    if (button < 0) {
                        return true;
                    }
                    movedItem = click.getEvent().getView().getBottomInventory().getItem(HOTBAR_OFFSET + button).clone();
                    break;
                case PICKUP_ONE:<commit_msg>Bukkit starts counting with the hotbar slots Also prevent possible NPE<commit_after>package de.themoep.inventorygui;

/*
 * Copyright 2017 <NAME> (https://github.com/Phoenix616/)
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the Mozilla Public License as published by
 * the Mozilla Foundation, version 2.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * Mozilla Public License v2.0 for more details.
 *
 * You should have received a copy of the Mozilla Public License v2.0
 * along with this program. If not, see <http://mozilla.org/MPL/2.0/>.
 */

import org.bukkit.ChatColor;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;

public class GuiStorageElement extends GuiElement {
    private final Inventory storage;

    private static final int HOTBAR_OFFSET = 36; // Magic number, slots before the hotbar starts

    public GuiStorageElement(char slotChar, Inventory storage) {
        super(slotChar, null);
        setAction(click -> {
            int index = getSlotIndex(click.getSlot());
            if (index == -1 || index >= storage.getSize()) {
                return true;
            }
            ItemStack storageItem = storage.getItem(index);
            ItemStack slotItem = click.getEvent().getView().getTopInventory().getItem(click.getSlot());
            if (storageItem == null && slotItem != null || storageItem != null && !storageItem.equals(slotItem)) {
                click.getEvent().setCancelled(true);
                click.getGui().draw();
                return false;
            }
            ItemStack movedItem = null;
            switch (click.getEvent().getAction()) {
                case NOTHING:
                case CLONE_STACK:
                    return false;
                case MOVE_TO_OTHER_INVENTORY:
                    if (click.getEvent().getRawSlot() < click.getEvent().getView().getTopInventory().getSize()) {
                        movedItem = null;
                    } else {
                        movedItem = click.getEvent().getCurrentItem();
                    }
                    break;
                case HOTBAR_MOVE_AND_READD:
                case HOTBAR_SWAP:
                    int button = click.getEvent().getHotbarButton();
                    if (button < 0) {
                        return true;
                    }
                    ItemStack hotbarItem = click.getEvent().getView().getBottomInventory().getItem(button);
                    if (hotbarItem != null) {
                        movedItem = hotbarItem.clone();
                    }
                    break;
                case PICKUP_ONE:
{'fraction_non_alphanumeric': 0.0930783242258652, 'fraction_numerical': 0.006557377049180328, 'mean_word_length': 1.9160913436006373, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3138093', 'n_tokens_mistral': 1453, 'n_tokens_neox': 1358, 'n_words': 406}