Player drop certain items

Discussion in 'Plugin Development' started by rhunter, Oct 14, 2016.

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

    rhunter

    Hey i'm making a drug plugin and when a cop right clicks a player with a stick, that player is teleported to jail. Now what i'm trying to do is, before he is teleported to jail, I want that player to drop all his drugs so the cop can pick it up.

    Code:
    ItemStack toDrop = sugar,seeds,bread,netherwarts,etc;
    player.getWorld().dropItemNaturally(toDrop);
    
    How would I make the code above something that works? I'm not super familiar with itemstacks and this stuff.

    Heres the code for frisking:
    Code:
    @EventHandler
    
        public void clickWithStick(PlayerInteractEntityEvent event) {
    
            if ((event.getRightClicked() instanceof Player) && (event.getPlayer().getInventory().getItemInMainHand().getType() == Material.STICK)) {
    
                Player player2 = (Player) event.getRightClicked();
    
                Player player1 = event.getPlayer();
    
                if(player1.hasPermission("drugs.cop")){
    
                player1.sendMessage("You frisked " + player2.getName() + ", confiscated their drugs, and sent them to jail for 3 minutes!");
    
                player2.sendMessage(ChatColor.RED + player1.getName() + " frisked you, confiscated your drugs, and sent you to jail for 3 minutes!");
    
                World w = Bukkit.getServer().getWorld(settings.getData().getString("jail." + ".world"));
    
                double x = settings.getData().getDouble("jail." + ".x");
    
                double y = settings.getData().getDouble("jail." + ".y");
    
                double z = settings.getData().getDouble("jail." + ".z");
    
                Location jail = new Location(w,x,y,z);
    
                player2.teleport(jail);
    
                }
    
            }
    
        }
    
     
  2. Offline

    Irantwomiles

    You should make a list of all of the players items, then you loop through it to see whether or not it's a drug or not assuming your using like a item meta to tell what is what, then you drop the items and right after teleprt the player away and remove the items from their inventory
     
  3. Offline

    Zombie_Striker

    @rhunter
    1. For loop through all the players contents.
    2. If the itemstack's type/name/lore is equal to the drugs (DO NOT USE == or equals, as those will not work. Instead, check for the individual values)
    3. If the itemstack is a drug, drop that item and remove it from the player's inventory.
     
Thread Status:
Not open for further replies.

Share This Page