Hello bukkit community, This my first plugin and first bukkit code attempt, this is just the layout still incomplete.I am trying to make a plugin that despawns all item on the ground like inventory drops and player deaths drops.If any one can tell me whats did I do wrong and tell me how to finish this plugin that would be very much be appreciated. Code: package com.kevin.bukkit; import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.plugin.java.JavaPlugin; public class NoDrop extends JavaPlugin{ @Override public void onEnable(){ getLogger().info("OnEnable as started!"); } @Override public void onDisable(){ getLogger().info("onDisable has started!"); } public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args, boolean PlayerDropItemEvent){ if (cmd.getName().equalsIgnoreCase("nodrop Enabled") && sender instanceof Player){ Player player = (Player)sender; player.sendMessage(ChatColor.GREEN + "NoDrop has been Enabled!"); } else { sender.sendMessage(ChatColor.RED +"Command Can Only Be Used In-Game!"); } } else { if (cmd.getName().equalsIgnoreCase("nodrop Enabled")){ nodropdisabled(sender); } } return false; } public void nodropdisabled(CommandSender sender){ sender.sendMessage("NoDrop has been Disabled!"); } }
CrazyTaco You said you have lots of errors, what are those errors? And I know this is your first attempt at coding a plugin, but what makes you think that sending a message would remove ground drops?
Assist In eclipse it says that Syntax error on token "else", { expected and sender cannot be resolved to a variable. I was hopping someone can help me find the code that makes all drops despawn. Necrodoom how can make I change it so I can do /nodrop enabled in-game?
CrazyTaco Well, why did you try to add an else to a method? It doesnt work that way. Also, read on bukkit wiki on how to write a plugin. If you dont understand it, head to a java tutorial.
CrazyTaco When I started, I also had some trouble with the brackets. Using an IDE helps a lot with them, however it seems like you don't know anything at all about coding (using this syntax, at least). As said, you should start reading/watching some Java tutorials, then head over to the Bukkit wiki and read the big plugin tutorial to get started.
You should create a boolean variable at first. Code:java private boolean dropEnabled; And completly rewrite the onCommand method. Example: Code:java public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { //The command is "/nodrop" if (label.equalsIgnoreCase("nodrop")) { //If the command is without any args (it means the command is just "/nodrop") if (args.length == 0) { //If sender is player if (sender instanceof Player) { Player player = (Player) sender; //Do something here. For example, you can send the list of commands. } //If there's one arg (it means the command is "/nodrop <arg>") } else if (args.length == 1) { //If arg is "enable" (/nodrop enable) if (args[0].equalsIgnoreCase("enable")) { //If sender is player if (sender instanceof Player) { Player player = (Player) sender; //This will set dropEnabled to true (players can't drop anything) dropEnabled = true; player.sendMessage(ChatColor.GREEN + "Enabled!"); } //If arg is "disable" (/nodrop disable) } else if (args[0].equalsIgnoreCase("disable")) { //If sender is player if (sender instanceof Player) { Player player = (Player) sender; //This will set dropEnabled to false (players can drop anything); dropEnabled = false; player.sendMessage(ChatColor.RED + "Disabled"); } } } } return false;} If you want to prevent players from dropping items while dropEnabled is true, you need something like this: Code:java @EventHandlerpublic void onDrop(PlayerDropItemEvent e) { Player p = e.getPlayer(); //If dropEnabled is set to true... if (dropEnabled == true) { //...it will cancel the event and players won't be able to drop anything. e.setCancelled(true); p.sendMessage("You can't do that now!"); }}
i was following a java tut and they added }else{ can help fix my code or give me a link to a good tut on bukkit java on youtube. video I was watching
Btw, don't copy and paste the code. Read it and try to understand. Then make your own based code on what people give you. \\Edit: Oh, you want to remove items on the ground. My mistake. Here's an example: Code:java public void clearItems(World world) { //Check if the world isn't null to prevent exceptions. if (world != null) { //Get list of all entities. List<Entity> entitiesList = world.getEntities(); //List through all entities... for (Entity current : entitiesList) { //...and remove them, if they're item. if (current instanceof Item) { current.remove(); } } }} Then call the method via: Code:java clearItems(world);
yeah thx for all the instructions there so easy to understand BTW where did you learn java/bukkit can you link the video if you can?
Necrodoom I learned basic java for a while but then thought to go to bukkit . @Halginzz Sorry to ask but can you repost the code with some empty places (So I can get more practice) I kinda got cunfused with all the codes that are up. EDIT by Moderator: merged posts, please use the edit button instead of double posting.