Why type the command and not use the drop button? Moved to plugin requests. EDIT by Moderator: merged posts, please use the edit button instead of double posting.
Why was this moved here? It sounds more like a developer needing some help/advice with the API. He's not requesting a plugin be built for him.. Anyways, here is what you are looking for: Code: ItemStack item = player.getItemInHand().clone(); player.getWorld().dropItemNaturally(player.getLocation(), item); After that you just remove the item from the inventory, then force update the inventory.
Put this in your class and be sure to update the class name to the same as your filename. Code: public class DropCmd implements CommandExecutor { public boolean onCommand(CommandSender cs, Command cmd, String label, String[] args) { if (!cmd.getName().equalsIgnoreCase("drop")) return false; if (!cs.hasPermission("some.permission.node")) { cs.sendMessage("You do not have permission for that command!"); return true; } if (!(cs instanceof Player)) { cs.sendMessage("Only a player can use this command!"); return true; } Player player = (Player) cs; ItemStack item = player.getItemInHand().clone(); player.getWorld().dropItemNaturally(player.getLocation(), item); player.setItemInHand(null); player.updateInventory(); cs.sendMessage("You have dropped " + item.getAmount() + " " + item.getType().toString().toLowerCase() + ".")); return true; } } Then in your onEnable() method in the main class do this: Code: getCommand("drop").setExecutor(new DropCmd()); And dont forget to add the command and permission node to your plugin.yml Code: name: MyPlugin main: me.plugins.MyPlugin version: 1.0 author: BillyGalbreath description: My awesome plugin commands: drop: description: Drop the item in your hand to the ground. usage: /<command> permissions: some.permission.node: description: Allows users to use the /drop command default: false The second is not an error. Its a warning, and can be ignored. As for the first one, it looks like you are putting the code in the wrong spot. I'd have to see the whole file to know whats going on. Player player = (Player) cs; ItemStack item = player.getItemInHand().clone(); player.getWorld().dropItemNaturally(player.getLocation(), item); player.setItemInHand(null); player.updateInventory(); Just remove those two lines I marked out. Code: Player player = (Player) cs; ItemStack item = player.getItemInHand().clone(); if (item.getType().equals(Material.DIRT)) { return; } player.getWorld().dropItemNaturally(player.getLocation(), item); player.setItemInHand(null); player.updateInventory(); You are missing this line above the if statement: Code: ItemStack item = player.getItemInHand().clone(); Here use this ( i added comments so you know what its doing ): Code: Player player = (Player) cs; // get the player ItemStack item = player.getItemInHand().clone(); // get the item in player's hand if (item.getType().equals(Material.AIR) || item.getType().equals(Material.DIRT)) { return; // dont do anything if the player is holding dirt, or nothing at all (air) } //player.getWorld().dropItemNaturally(player.getLocation(), item); // only use this to make the item in hand drop to the ground player.setItemInHand(null); // remove the item from the player's hand player.updateInventory(); // update the player inventory so they see the changes we made Change the return to true. I forgot to put that i the code above. This would be completely separate issue, so make a new thread and someone will help you out with that. I'm starting to doze off here (no sleep for like 3 days now) lol. Have fun ^_^ EDIT by Moderator: merged posts, please use the edit button instead of double posting.
BillyGalbreath This is the code you want to use. Code:java public class DropCommand implements CommandExecutor {@Overridepublic boolean onCommand (CommandSender sender, Command cmd, String commandLabel, String[] args) {if (!(sender instanceof Player)) {System.out.println("You must be a player to do this!")return true;}if (args.length > 0) {player.sendMessage(ChatColor.GRAY + "Usage: /drop");return true;}if (args.length == 0) {if (player.getItemInHand().getType() == Material.AIR) {player.sendMessage(ChatColor.GRAY + "You need to have an item in your hand!");return true;}player.getWorld().dropItemNaturally(player.getLocation(), player.getItemInHand());player.setItemInHand(Material.AIR);player.sendMessage(ChatColor.GRAY + "Item dropped!");return true;} return true;}} EDIT: Also to disable drops use this: Code:java public class PlayerListener implements Listener {@EventHandlerpublic void onPlayerDropItemEvent(PlayerDropItemEvent event) {event.setCancelled(true);} }
elementalgodz11 Why not just disable dropping for some items instead of making the player type a command. The following code makes the player not able to drop there sword. However this could easily be changed to disable dropping of other items. This is untested. Code:java public Material[] blocked = {Material.WOOD_SWORD, Material.STONE_SWORD, Material.IRON_SWORD, Material.GOLD_SWORD, Material.DIAMOND_SWORD}; @EventHandler public void onDrop(PlayerDropItemEvent event) { Player p = event.getPlayer(); for(Material bi : blocked) { if(bi == event.getItemDrop().getItemStack().getType()) { //Check if blocked item event.setCancelled(true); //Stop them from dropping }else { //not blocked //code to remove item } } } elementalgodz11 That's the point. Using my code they can't drop their sword. All other items can be dropped. elementalgodz11 Ok well if it works use it. I just personally think that typing a command to drop an item would be annoying. EDIT by Moderator: merged posts, please use the edit button instead of double posting.