mirror of
https://github.com/songoda/UltimateStacker.git
synced 2024-11-04 17:50:07 +01:00
This commit is contained in:
parent
4d713a5f08
commit
830c49c6f7
@ -398,6 +398,9 @@ public class UltimateStacker extends SongodaPlugin {
|
|||||||
item.removeMetadata("US_AMT", INSTANCE);
|
item.removeMetadata("US_AMT", INSTANCE);
|
||||||
itemStack.setAmount(newAmount);
|
itemStack.setAmount(newAmount);
|
||||||
}
|
}
|
||||||
|
// If amount is 0, Minecraft change the type to AIR
|
||||||
|
if (itemStack.getType() == Material.AIR)
|
||||||
|
return;
|
||||||
item.setItemStack(itemStack);
|
item.setItemStack(itemStack);
|
||||||
|
|
||||||
if ((blacklisted && !Settings.ITEM_HOLOGRAM_BLACKLIST.getBoolean())
|
if ((blacklisted && !Settings.ITEM_HOLOGRAM_BLACKLIST.getBoolean())
|
||||||
@ -419,7 +422,7 @@ public class UltimateStacker extends SongodaPlugin {
|
|||||||
public static int getActualItemAmount(Item item) {
|
public static int getActualItemAmount(Item item) {
|
||||||
ItemStack itemStack = item.getItemStack();
|
ItemStack itemStack = item.getItemStack();
|
||||||
int amount = itemStack.getAmount();
|
int amount = itemStack.getAmount();
|
||||||
if (amount >= (itemStack.getMaxStackSize() / 2) && item.hasMetadata("US_AMT")) {
|
if (/*amount >= (itemStack.getMaxStackSize() / 2) && */item.hasMetadata("US_AMT")) {
|
||||||
return item.getMetadata("US_AMT").get(0).asInt();
|
return item.getMetadata("US_AMT").get(0).asInt();
|
||||||
} else {
|
} else {
|
||||||
return amount;
|
return amount;
|
||||||
|
@ -81,12 +81,18 @@ public class ItemListeners implements Listener {
|
|||||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||||
public void onPickup(PlayerPickupItemEvent event) {
|
public void onPickup(PlayerPickupItemEvent event) {
|
||||||
if (!Settings.STACK_ITEMS.getBoolean()) return;
|
if (!Settings.STACK_ITEMS.getBoolean()) return;
|
||||||
if (event.getItem().getItemStack().getAmount() < (event.getItem().getItemStack().getMaxStackSize() / 2)) return;
|
// Amount here is not the total amount of item (32 if more than 32) but the amount of item the player can retrieve
|
||||||
|
// ie there is x64 diamonds blocks (so 32), the player pick 8 items so the amount is 8 and not 32
|
||||||
|
int amount = UltimateStacker.getActualItemAmount(event.getItem());
|
||||||
|
if (/*event.getItem().getItemStack().getAmount()*/amount < (event.getItem().getItemStack().getMaxStackSize() / 2)) {
|
||||||
|
// Update
|
||||||
|
UltimateStacker.updateItemAmount(event.getItem(), event.getRemaining());
|
||||||
|
return;
|
||||||
|
}
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
|
|
||||||
event.getPlayer().playSound(event.getPlayer().getLocation(), CompatibleSound.ENTITY_ITEM_PICKUP.getSound(), .2f, (float) (1 + Math.random()));
|
event.getPlayer().playSound(event.getPlayer().getLocation(), CompatibleSound.ENTITY_ITEM_PICKUP.getSound(), .2f, (float) (1 + Math.random()));
|
||||||
|
|
||||||
Methods.updateInventory(event.getItem(), event.getPlayer().getInventory());
|
Methods.updateInventory(event.getItem(), event.getPlayer().getInventory());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user