There is a known issue in Spigot when checking the inventory's clicked slot number because of the slot numbering system (picture included)

I fixed this issue by adding an additional fix
if (event.getClickedInventory() == null || event.getClickedInventory().getType() == InventoryType.PLAYER) return;
which checks if the inventory that was clicked was actually the upper part of the UI, otherwise the listener also let's through clicks that were done in the player inventory and act as if they were done in the GUI. But adding this everytime is a bit tedious. Sorry if the explanation is a bit confusing, I can go over certain parts again if you don't understand the problem
There is a known issue in Spigot when checking the inventory's clicked slot number because of the slot numbering system (picture included)

I fixed this issue by adding an additional fix
if (event.getClickedInventory() == null || event.getClickedInventory().getType() == InventoryType.PLAYER) return;which checks if the inventory that was clicked was actually the upper part of the UI, otherwise the listener also let's through clicks that were done in the player inventory and act as if they were done in the GUI. But adding this everytime is a bit tedious. Sorry if the explanation is a bit confusing, I can go over certain parts again if you don't understand the problem