Solved Player can’t drop the item from the creative

Discussion in 'Plugin Development' started by GRENKA, Jul 15, 2021.

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

    GRENKA

    My problem:
    When I right-click, I am given a creative. I press "E" to enter the inventory and I can take things from the creative to my inventory, BUT I cannot hover over the item and click "Q" to throw it away, nothing happens. Wish the items were thrown away.

    Code:
    package plugin.grenka.plugin;
    
    import org.bukkit.GameMode;
    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.player.*;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.plugin.java.JavaPlugin;
    
    
    import static java.lang.Thread.sleep;
    
    public final class Plugin extends JavaPlugin implements Listener {
        boolean ibb = true;
    
    
    
        @Override
        public void onEnable() {
            // Plugin startup logic
            System.out.println("The plugin is starting up.");
            getServer().getPluginManager().registerEvents(this, this);
    
        }
        @EventHandler
        public void onPlayer(PlayerInteractEvent event) throws InterruptedException {
            Player player = event.getPlayer();
            Action action = event.getAction();
    
            if (action.equals(Action.RIGHT_CLICK_AIR) || action.equals(Action.RIGHT_CLICK_BLOCK)) {
                if (player.getItemInHand().getType() == Material.TRIDENT) {
                    player.getInventory().getItemInMainHand().setAmount(player.getInventory().getItemInMainHand().getAmount() - 1);
                    player.updateInventory();
                    player.setGameMode(GameMode.CREATIVE);
                    sleep(2000);
                    player.setGameMode(GameMode.SURVIVAL);
    
    
    
                }
            }
        }
    
    
        @EventHandler
        public void PlayerAdvancementDone(PlayerAdvancementDoneEvent event){
            Player player = event.getPlayer();
            player.getInventory().addItem(new ItemStack(Material.TRIDENT, 1));
        }
    }
    
    
    If I turn on the creative myself, then that's okay, if the plugin turns it on, I can't. And all what i do in creative - everything rolls back. I think problem with "sleep"...

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jul 16, 2021
  2. Online

    timtower Administrator Administrator Moderator

    @GRENKA Yeah, sleep is your code is bad.
     
  3. Offline

    GRENKA

    I change to

    Code:
    Bukkit.getScheduler().runTaskLater(this, () -> {
                        player.setGameMode(GameMode.SURVIVAL);
                    }, 40L);
     
Thread Status:
Not open for further replies.

Share This Page