Vanish setCanPickUpItems

Discussion in 'Plugin Development' started by MaxNatural, Feb 19, 2015.

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

    MaxNatural

    So I am making a vanish plugin and I put player.setCanPickupItems(false); it does not work

    Full code:
    Code:
    package me.max.commands;
    
    import java.util.ArrayList;
    import me.max.MainCore;
    
    import org.bukkit.Bukkit;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Listener;
    
    public class Vanish implements CommandExecutor, Listener{
       
        public Vanish(MainCore mainCore) {
            // TODO Auto-generated constructor stub
        }
        public ArrayList<Player> vanish = new ArrayList<Player>();
    
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
        if(!(sender instanceof Player)) {
            sender.sendMessage("You must be a player");
        }
       
        Player player = (Player) sender;
       
        if(commandLabel.equalsIgnoreCase("v") || commandLabel.equalsIgnoreCase("vanish")) {
            if(!vanish.contains(player)) {
                for (Player online : Bukkit.getOnlinePlayers()) {
                    online.hidePlayer(player);
                   
                }
                vanish.add(player);
           
                player.sendMessage(MainCore.TAG + "You have now vanished");
               
                player.setAllowFlight(true);
                player.setFlying(true);
                player.setCanPickupItems(false);
            } else {
                for (Player online : Bukkit.getOnlinePlayers()) {
                    online.showPlayer(player);
                   
                }
                vanish.remove(player);
                player.setAllowFlight(false);
                player.setFlying(false);
                player.sendMessage(MainCore.TAG + "You are no longer vanished");
            }
           
        }
        return true;
               
       
        }
    
        }
    
    
       
    
     
  2. Offline

    Konato_K

    @MaxNatural The setCanPickUpItems method it's inside LivingEntity, it's used to mobs (like Zombies) to know if they can pick up items or not, it does not work for players.

    You need to listen for PlayerPickupItemEvent and cancel it or make the player not collide with entities.
     
  3. Offline

    MaxNatural

    @Konato_K how would I do that. Sorry i'm a little new
     
  4. Offline

    Arrays

    Create a "PlayerPickupItemEvent" and cancel it.
     
  5. Offline

    Konato_K

  6. just use the PlayerPickupItemEvent and check if the ArrayList "vanish" contains the player
    if so, cancel the event
     
Thread Status:
Not open for further replies.

Share This Page