1.15.2 MinePickup not working

Discussion in 'Spigot Plugin Development' started by Joshuak52, Feb 6, 2020.

Thread Status:
Not open for further replies.
  1. 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);
            }
         }

    }
     
  2. 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...
     
  3. Are you on 1.15.2 version of Spigot? It works for versions below but not 1.15.2 for some reason
     
  4. 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.
     
  5. 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);
         }
    }
     
     
  6. Refresh inventory
     
  7. 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.
     
  8. 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.
     
  9. You need to update the inventory like 3-10 ticks later
     
  10. Alright, I will try it, but shouldn't it be working with what's there though? Seems like it should to me
     
  11. drives_a_ford

    Moderator

    That just means your code depends on WorldEdit/WorldGuard and since you removed these plugins, the classes cannot be accessed.
     
  12. 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
     
Thread Status:
Not open for further replies.