mirror of
https://github.com/songoda/UltimateStacker.git
synced 2024-11-08 11:30:38 +01:00
quick fix.
This commit is contained in:
parent
5e995da7bd
commit
544cf08309
@ -58,7 +58,7 @@ public class ItemListeners implements Listener {
|
|||||||
if (amount <= 32) return;
|
if (amount <= 32) return;
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
|
|
||||||
updateInventory(event.getItem(), event.getInventory());
|
Methods.updateInventory(event.getItem(), event.getInventory());
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||||
@ -77,27 +77,7 @@ public class ItemListeners implements Listener {
|
|||||||
instance.isServerVersionAtLeast(ServerVersion.V1_9) ? Sound.ENTITY_ITEM_PICKUP
|
instance.isServerVersionAtLeast(ServerVersion.V1_9) ? Sound.ENTITY_ITEM_PICKUP
|
||||||
: Sound.valueOf("ITEM_PICKUP"), .2f, (float) (1 + Math.random()));
|
: Sound.valueOf("ITEM_PICKUP"), .2f, (float) (1 + Math.random()));
|
||||||
|
|
||||||
updateInventory(event.getItem(), event.getPlayer().getInventory());
|
Methods.updateInventory(event.getItem(), event.getPlayer().getInventory());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateInventory(Item item, Inventory inventory) {
|
|
||||||
int amount = Methods.getActualItemAmount(item);
|
|
||||||
|
|
||||||
while (amount > 0) {
|
|
||||||
int subtract = Math.min(amount, 64);
|
|
||||||
amount -= subtract;
|
|
||||||
ItemStack newItem = item.getItemStack().clone();
|
|
||||||
newItem.setAmount(subtract);
|
|
||||||
Map<Integer, ItemStack> result = inventory.addItem(newItem);
|
|
||||||
if (result.get(0) != null) {
|
|
||||||
amount += result.get(0).getAmount();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (amount <= 0)
|
|
||||||
item.remove();
|
|
||||||
else
|
|
||||||
Methods.updateItemAmount(item, amount);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ import org.bukkit.*;
|
|||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.CreatureSpawner;
|
import org.bukkit.block.CreatureSpawner;
|
||||||
import org.bukkit.entity.*;
|
import org.bukkit.entity.*;
|
||||||
|
import org.bukkit.inventory.Inventory;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.meta.BlockStateMeta;
|
import org.bukkit.inventory.meta.BlockStateMeta;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
@ -24,6 +25,27 @@ import java.util.stream.Collectors;
|
|||||||
|
|
||||||
public class Methods {
|
public class Methods {
|
||||||
|
|
||||||
|
public static void updateInventory(Item item, Inventory inventory) {
|
||||||
|
int amount = Methods.getActualItemAmount(item);
|
||||||
|
|
||||||
|
while (amount > 0) {
|
||||||
|
int subtract = Math.min(amount, 64);
|
||||||
|
amount -= subtract;
|
||||||
|
ItemStack newItem = item.getItemStack().clone();
|
||||||
|
newItem.setAmount(subtract);
|
||||||
|
Map<Integer, ItemStack> result = inventory.addItem(newItem);
|
||||||
|
if (result.get(0) != null) {
|
||||||
|
amount += result.get(0).getAmount();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (amount <= 0)
|
||||||
|
item.remove();
|
||||||
|
else
|
||||||
|
Methods.updateItemAmount(item, amount);
|
||||||
|
}
|
||||||
|
|
||||||
public static void updateItemAmount(Item item, int newAmount) {
|
public static void updateItemAmount(Item item, int newAmount) {
|
||||||
UltimateStacker plugin = UltimateStacker.getInstance();
|
UltimateStacker plugin = UltimateStacker.getInstance();
|
||||||
Material material = item.getItemStack().getType();
|
Material material = item.getItemStack().getType();
|
||||||
|
Loading…
Reference in New Issue
Block a user