v0.5.3 - Mined blocks were not converting to dropped resources prior to going into player inventory. i.e. if a prisoner mined a stone they would get a stone block in their inventory instead of a cobblestone. Attempting to fix that here using getDrop() but that returns a list. Attempting to convert that into an Array etc and go from there.
This commit is contained in:
parent
e1dfacfe65
commit
3ddc8217df
|
@ -1,7 +1,6 @@
|
|||
package me.nvus.nvus_prison_setup.Listeners;
|
||||
|
||||
import me.nvus.nvus_prison_setup.PrisonSetup;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
|
@ -9,6 +8,9 @@ import org.bukkit.event.Listener;
|
|||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class BlockListener implements Listener {
|
||||
|
||||
private final PrisonSetup plugin;
|
||||
|
@ -24,14 +26,16 @@ public class BlockListener implements Listener {
|
|||
|
||||
// Check if the player is a prisoner and auto-pickup is enabled
|
||||
if (player.hasPermission("nvus.prisoner") && plugin.getConfigManager().getConfig("config.yml").getBoolean("AutoPickup")) {
|
||||
ItemStack itemStack = new ItemStack(block.getType());
|
||||
if (player.getInventory().addItem(itemStack).isEmpty()) {
|
||||
// Inventory has enough space, remove the dropped item
|
||||
event.setDropItems(false);
|
||||
} else {
|
||||
// Inventory is full, drop the item on the ground
|
||||
block.getWorld().dropItemNaturally(block.getLocation(), itemStack);
|
||||
player.sendMessage("Your inventory is currently full. The resource has been dropped on the ground!");
|
||||
List<ItemStack> drops = Arrays.asList(block.getDrops().toArray(new ItemStack[0]));
|
||||
for (ItemStack drop : drops) {
|
||||
if (player.getInventory().addItem(drop).isEmpty()) {
|
||||
// Inventory has enough space, remove the dropped item
|
||||
event.setDropItems(false);
|
||||
} else {
|
||||
// Inventory is full, drop the item on the ground
|
||||
block.getWorld().dropItemNaturally(block.getLocation(), drop);
|
||||
player.sendMessage("Your inventory is currently full. The resource has been dropped on the ground!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue