Hey, so I this plugin works in 1.14.4 but not in 1.15.2 but I can't figure out why. Any help would be much appreciated The issue: It's setting the drop to air which is right but it's not adding the item to the players inventory Code (Text): package com.nostalgicprison.minepickup; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.plugin.java.JavaPlugin; public class main extends JavaPlugin implements Listener{ public void onEnable() { getServer().getPluginManager().registerEvents(this, this); } @EventHandler public void onBlockBreak(BlockBreakEvent event) { Player player = (Player) event.getPlayer(); if(WGUtil.canBuild(player, event.getBlock().getLocation())) { for(ItemStack is : event.getBlock().getDrops()) event.getPlayer().getInventory().addItem(is); event.setDropItems(false); } } }
Can you elaborate on details, like for what blocks exactly this doesn't work? I just tried this myself and it works just as expected...
I am on 1.15.2. It works for any block that I tried on. The only difference between your code and my code is that you have that check if the player can build.
Removed the class and changed the code but it's still not working (no errors either) Code (Text): import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.plugin.java.JavaPlugin; public class main extends JavaPlugin implements Listener{ public void onEnable() { getServer().getPluginManager().registerEvents(this, this); } @EventHandler public void onBlockBreak(BlockBreakEvent event) { for(ItemStack is : event.getBlock().getDrops()) event.getPlayer().getInventory().addItem(is); event.setDropItems(false); } }
As @Maxx_Qc said, you should refresh (or update) the player's inventory after you modify it. But also.... If by chance you have set the api-version in the plugin.yml to 1.14, the plugin will fail to load on startup and nothing will work.
Added Code (Text): event.getPlayer().updateInventory(); but still same issue prevails with not adding items to my inventory My plugin.yml Code (Text): name: NostalgicPrison-MinePickUp version: 1.0 main: com.nostalgicprison.minepickup.main author: Instigated api-version: 1.15 description: A NostalgicPrison custom mining Plugin Also, no startup errors or mining errors.
Alright, I will try it, but shouldn't it be working with what's there though? Seems like it should to me
UPDATE: I deleted all other plugins and left this one in and I get this error: https://gyazo.com/2b42a4709913598b0775ea8238e95f85
That just means your code depends on WorldEdit/WorldGuard and since you removed these plugins, the classes cannot be accessed.
WorldGuard/WorldEdit is not longer in my code or in my build path Code (Text): package com.nostalgicprison.minepickup; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.plugin.java.JavaPlugin; public class main extends JavaPlugin implements Listener{ public void onEnable() { getServer().getPluginManager().registerEvents(this, this); } @EventHandler public void onBlockBreak(BlockBreakEvent event) { event.setDropItems(false); for(ItemStack is : event.getBlock().getDrops()) event.getPlayer().getInventory().addItem(is); } } Also, they're not installed on the server either