Fix item filter for item switching (Fixes #51)

This commit is contained in:
GeorgH93 2019-10-16 19:38:24 +02:00
parent 7229f0f720
commit 6d07050346
No known key found for this signature in database
GPG Key ID: D1630D37F9E4B3C8
2 changed files with 15 additions and 5 deletions

View File

@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>at.pcgamingfreaks</groupId>
<artifactId>Minepacks</artifactId>
<version>2.0.11-RC1</version>
<version>2.0.11-RC2</version>
<scm>
<connection>scm:git:git@github.com:GeorgH93/Minepacks.git</connection>

View File

@ -27,9 +27,11 @@
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.inventory.InventoryAction;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryDragEvent;
import org.bukkit.event.inventory.InventoryMoveItemEvent;
import org.bukkit.inventory.ItemStack;
import java.util.Collection;
import java.util.HashSet;
@ -92,12 +94,20 @@ public void onItemMove(InventoryMoveItemEvent event)
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onItemMove(InventoryClickEvent event)
{
if(event.getInventory().getHolder() instanceof Backpack && event.getCurrentItem() != null && blockedMaterials.contains(new MinecraftMaterial(event.getCurrentItem())))
if(event.getInventory().getHolder() instanceof Backpack)
{
if(event.getClickedInventory() != null && event.getClickedInventory().getHolder() instanceof Backpack) return; // Allow user to move blacklisted items out of the backpack
if(event.getAction() == InventoryAction.HOTBAR_MOVE_AND_READD && event.getHotbarButton() != -1)
{
ItemStack item = event.getWhoClicked().getInventory().getItem(event.getHotbarButton());
if(item != null && blockedMaterials.contains(new MinecraftMaterial(item))) event.setCancelled(true);
}
else if(event.getCurrentItem() != null && blockedMaterials.contains(new MinecraftMaterial(event.getCurrentItem())))
{
if(event.getClickedInventory() != null && event.getClickedInventory().getHolder() instanceof Backpack) return; // Allow user to move blacklisted items out of the backpack
messageNotAllowedInBackpack.send(event.getView().getPlayer(), itemNameResolver.getName(event.getCurrentItem()));
event.setCancelled(true);
messageNotAllowedInBackpack.send(event.getView().getPlayer(), itemNameResolver.getName(event.getCurrentItem()));
event.setCancelled(true);
}
}
}