Hi, I'm trying to code a zombie survival plugin, and wanted to put in a grenade launcher. The code worked, but I realized I had accidentally named the string "pistol". I went to change it to grenade launcher, changed the command, and exported, but when i tried to run it again, the command gave no console feedback, and didn't give an item as it had with the "pistol" string. No idea what might be causing this. Any help would be great! Broken code: Code: package zombies.items; import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; public class GiveGun implements CommandExecutor{ public GiveGun() { } @Override public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { if (label.equalsIgnoreCase("Grenade Launcher")) { Player player = (Player) sender; ItemStack pisT1 = new ItemStack(Material.IRON_BARDING, 1); ItemMeta meta = pisT1.getItemMeta(); meta.setDisplayName(ChatColor.DARK_RED + "Grenade Launcher"); pisT1.setItemMeta(meta); player.getInventory().addItem(pisT1); return true; } return false; } } Working code: Code: package zombies.items; import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; public class GiveGun implements CommandExecutor{ public GiveGun() { } @Override public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { if (label.equalsIgnoreCase("Pistol")) { Player player = (Player) sender; ItemStack pisT1 = new ItemStack(Material.IRON_BARDING, 1); ItemMeta meta = pisT1.getItemMeta(); meta.setDisplayName(ChatColor.BLUE + "Pistol"); pisT1.setItemMeta(meta); player.getInventory().addItem(pisT1); return true; } return false; } }
@Ghost105 Commands do not support spaces, as all spaces after the first word are considered args. Either change "Grenade Launcher" to "GrenadeLauncher" in both the class and plugin.yml, or better yet, create a new super-command such as "Guns" and use the arguments to give a specific gun type.
I changed the string to GrenadeLauncher and changed the give command to /gren, now it posts the command in the console rather than executing.