Skip to content
This repository was archived by the owner on Jul 24, 2021. It is now read-only.

Commit d12115b

Browse files
authored
✨ A player can now add an item by interacting with the inventory. (#11)
* 📄 Update LICENSE year * ✨ A player can now add an item by interacting with the inventory.
1 parent 934d4a0 commit d12115b

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

LICENSE

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,7 @@ state the exclusion of warranty; and each file should have at least
632632
the "copyright" line and a pointer to where the full notice is found.
633633

634634
InventoryAPI is an API to use easily bukkit's inventories
635-
Copyright (C) 2020 BakaAless
635+
Copyright (C) 2021 BakaAless
636636

637637
This program is free software: you can redistribute it and/or modify
638638
it under the terms of the GNU General Public License as published by
@@ -652,7 +652,7 @@ Also add information on how to contact you by electronic and paper mail.
652652
If the program does terminal interaction, make it output a short
653653
notice like this when it starts in an interactive mode:
654654

655-
InventoryAPI Copyright (C) 2020 BakaAless
655+
InventoryAPI Copyright (C) 2021 BakaAless
656656
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657657
This is free software, and you are welcome to redistribute it
658658
under certain conditions; type `show c' for details.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,4 @@ dependencies {
6969

7070
## Licence
7171

72-
<p xmlns:dct="http://purl.org/dc/terms/" xmlns:cc="http://creativecommons.org/ns#" class="license-text"><a rel="cc:attributionURL" property="dct:title" href="https://github.com/BakaAless/InventoryAPI">InventoryAPI</a> by <a rel="cc:attributionURL dct:creator" property="cc:attributionName" href="https://github.com/BakaAless">BakaAless</a> is licensed under <a rel="license" href="https://creativecommons.org/licenses/by-nc-sa/4.0">CC BY-NC-SA 4.0<img style="height:22px!important;margin-left:3px;vertical-align:text-bottom;" src="https://mirrors.creativecommons.org/presskit/icons/cc.svg?ref=chooser-v1" /><img style="height:22px!important;margin-left:3px;vertical-align:text-bottom;" src="https://mirrors.creativecommons.org/presskit/icons/by.svg?ref=chooser-v1" /><img style="height:22px!important;margin-left:3px;vertical-align:text-bottom;" src="https://mirrors.creativecommons.org/presskit/icons/nc.svg?ref=chooser-v1" /><img style="height:22px!important;margin-left:3px;vertical-align:text-bottom;" src="https://mirrors.creativecommons.org/presskit/icons/sa.svg?ref=chooser-v1" /></a></p>
72+
InventoryAPI is under GPL-3.0 License.

src/main/java/fr/bakaaless/inventory/InventoryAPI.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package fr.bakaaless.inventory;
22

3-
import org.bukkit.Bukkit;
3+
import org.bukkit.Material;
44
import org.bukkit.entity.Player;
55
import org.bukkit.event.EventHandler;
66
import org.bukkit.event.HandlerList;
@@ -15,6 +15,7 @@
1515
import java.util.Iterator;
1616
import java.util.List;
1717
import java.util.Optional;
18+
import java.util.concurrent.atomic.AtomicBoolean;
1819
import java.util.function.Consumer;
1920
import java.util.function.Function;
2021
import java.util.logging.Level;
@@ -472,14 +473,22 @@ public void onInteract(final InventoryClickEvent e) {
472473
if (!e.getClickedInventory().equals(this.inventory))
473474
return;
474475
e.setCancelled(this.interactionCancel);
476+
final AtomicBoolean slotRegister = new AtomicBoolean(false);
475477
this.items.forEach(itemAPI -> {
476478
if (e.getSlot() != itemAPI.getSlot())
477479
return;
480+
slotRegister.set(true);
478481
if (e.getCurrentItem() == null)
479482
return;
480483
e.setCancelled(itemAPI.isCancelled());
481484
itemAPI.getConsumer().accept(e);
482485
});
486+
if (!slotRegister.get()) {
487+
if (e.getInventory().getItem(e.getSlot()) == null || e.getInventory().getItem(e.getSlot()).getType() == Material.AIR)
488+
this.clearSlot(e.getSlot());
489+
else
490+
this.addItem(e.getSlot(), e.getInventory().getItem(e.getSlot()), false);
491+
}
483492
}
484493

485494
@EventHandler

0 commit comments

Comments
 (0)