Fix bug that allowed players to move blocked items into the backpack #65

This commit is contained in:
GeorgH93 2020-02-01 15:32:44 +01:00
parent cf32237ae9
commit 27c194c84b
No known key found for this signature in database
GPG Key ID: D1630D37F9E4B3C8
3 changed files with 17 additions and 4 deletions

View File

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

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2019 GeorgH93 * Copyright (C) 2020 GeorgH93
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -96,10 +96,14 @@ public void onItemMove(InventoryClickEvent event)
{ {
if(event.getInventory().getHolder() instanceof Backpack) if(event.getInventory().getHolder() instanceof Backpack)
{ {
if(event.getAction() == InventoryAction.HOTBAR_MOVE_AND_READD && event.getHotbarButton() != -1) if((event.getAction() == InventoryAction.HOTBAR_MOVE_AND_READD || event.getAction() == InventoryAction.HOTBAR_SWAP) && event.getHotbarButton() != -1)
{ {
ItemStack item = event.getWhoClicked().getInventory().getItem(event.getHotbarButton()); ItemStack item = event.getWhoClicked().getInventory().getItem(event.getHotbarButton());
if(item != null && isItemBlocked(item)) event.setCancelled(true); if(item != null && isItemBlocked(item))
{
event.setCancelled(true);
messageNotAllowedInBackpack.send(event.getView().getPlayer(), itemNameResolver.getName(item));
}
} }
else if(event.getCurrentItem() != null && isItemBlocked(event.getCurrentItem())) else if(event.getCurrentItem() != null && isItemBlocked(event.getCurrentItem()))
{ {

View File

@ -146,6 +146,15 @@ else if(event.getAction() == InventoryAction.MOVE_TO_OTHER_INVENTORY)
messageDoNotRemoveItem.send(event.getWhoClicked()); messageDoNotRemoveItem.send(event.getWhoClicked());
} }
} }
else if((event.getAction() == InventoryAction.HOTBAR_MOVE_AND_READD || event.getAction() == InventoryAction.HOTBAR_SWAP) && event.getHotbarButton() != -1)
{
ItemStack item = event.getWhoClicked().getInventory().getItem(event.getHotbarButton());
if(isItemShortcut(item))
{
event.setCancelled(true);
messageDoNotRemoveItem.send(event.getWhoClicked());
}
}
else if(isItemShortcut(event.getCursor()) && !event.getWhoClicked().getInventory().equals(event.getClickedInventory())) else if(isItemShortcut(event.getCursor()) && !event.getWhoClicked().getInventory().equals(event.getClickedInventory()))
{ {
event.setCancelled(true); event.setCancelled(true);