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;
|
package me.nvus.nvus_prison_setup.Listeners;
|
||||||
|
|
||||||
import me.nvus.nvus_prison_setup.PrisonSetup;
|
import me.nvus.nvus_prison_setup.PrisonSetup;
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
|
@ -9,6 +8,9 @@ import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.block.BlockBreakEvent;
|
import org.bukkit.event.block.BlockBreakEvent;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class BlockListener implements Listener {
|
public class BlockListener implements Listener {
|
||||||
|
|
||||||
private final PrisonSetup plugin;
|
private final PrisonSetup plugin;
|
||||||
|
@ -24,15 +26,17 @@ public class BlockListener implements Listener {
|
||||||
|
|
||||||
// Check if the player is a prisoner and auto-pickup is enabled
|
// Check if the player is a prisoner and auto-pickup is enabled
|
||||||
if (player.hasPermission("nvus.prisoner") && plugin.getConfigManager().getConfig("config.yml").getBoolean("AutoPickup")) {
|
if (player.hasPermission("nvus.prisoner") && plugin.getConfigManager().getConfig("config.yml").getBoolean("AutoPickup")) {
|
||||||
ItemStack itemStack = new ItemStack(block.getType());
|
List<ItemStack> drops = Arrays.asList(block.getDrops().toArray(new ItemStack[0]));
|
||||||
if (player.getInventory().addItem(itemStack).isEmpty()) {
|
for (ItemStack drop : drops) {
|
||||||
|
if (player.getInventory().addItem(drop).isEmpty()) {
|
||||||
// Inventory has enough space, remove the dropped item
|
// Inventory has enough space, remove the dropped item
|
||||||
event.setDropItems(false);
|
event.setDropItems(false);
|
||||||
} else {
|
} else {
|
||||||
// Inventory is full, drop the item on the ground
|
// Inventory is full, drop the item on the ground
|
||||||
block.getWorld().dropItemNaturally(block.getLocation(), itemStack);
|
block.getWorld().dropItemNaturally(block.getLocation(), drop);
|
||||||
player.sendMessage("Your inventory is currently full. The resource has been dropped on the ground!");
|
player.sendMessage("Your inventory is currently full. The resource has been dropped on the ground!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue