How to drop the block that the player is standing on?

Discussion in 'Plugin Development' started by Gabibbo, Jul 14, 2021.

Thread Status:
Not open for further replies.
  1. Offline


    I tried to make a script that converts the block that the player is standing on an then drops it at the player's location, but it's not working, no errors/warnings from the console or the IDE
    package me.gvells.getsteppedblock.listeners;
    import org.bukkit.Bukkit;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.block.Block;
    import org.bukkit.block.BlockFace;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerMoveEvent;
    import org.bukkit.inventory.ItemStack;
    import me.gvells.getsteppedblock.Main;
    public class BlockListener implements Listener{
    private Main plugin;
        public BlockListener(Main plugin) {
            this.plugin = plugin;
            Bukkit.getPluginManager().registerEvents(this, plugin);
        public void moveEvent(PlayerMoveEvent e, Material mats) {
        Player p= e.getPlayer();
        Location ploc = p.getLocation();
        Block block = p.getLocation().getBlock().getRelative(BlockFace.DOWN);
        Material itemblock = block.getType();
            p.getWorld().dropItem(ploc, new ItemStack(itemblock, 1));
    Main file :
    package me.gvells.getsteppedblock;
    import me.gvells.getsteppedblock.listeners.BlockListener;
    public class Main extends JavaPlugin{
        public void onEnable() {
            new BlockListener(this);
    name: YouGetWhatYouWalkOn
    author: Happy Di Piero
    version: 1.0
    api-version: 1.17
    main: me.gvells.getsteppedblock.Main
    Last edited by a moderator: Jul 14, 2021
  2. Online

    timtower Administrator Administrator Moderator

    @Gabibbo You need an @EventHandler, and only the PlayerMoveEvent, not the Material variable
  3. Offline


    Be aware PME fires for any motion, even if said motion doesn't involve actual block traversal - i.e. moving the mouse to turn your head fires it off. Also remember this is global, so it will always happen the way you wrote it. I'd write some sort of check in there to determine if it should be ran. Like if the player has turned the functionality on or not. So my code would open the event then check if the player wants to do this. If not, it returns. Then it'd check if the getFrom() location X/Y/Z matches getTo(), and if so, return. That way you only run it when necessary.
Thread Status:
Not open for further replies.

Share This Page