Iv'e Been developing a plugin for amusement (using eclipse juno) and I've run into some problems. Code:java package me.Kyler.TheCowPlugin; import org.bukkit.entity.Cow;import org.bukkit.plugin.java.JavaPlugin; public class TheCowPlugin extends JavaPlugin{ public void onEnable() { } public void onDisable() { } public boolean onCommand(CommandSender sender, Command cmd, String cl, String[] args) { if (cmd.getname().equalsIgnoreCase("Cow")) { (sender instanceof Player) {//check is the sender is a player Player player = (Player) sender; //cast the sender to a player player.getWorld().spawn(player.getLocation(), Cow.class); //spawn a cow } } On (sender instanceof Player) it says that the lefthand side must be a variable... What does this mean? and it says 'Player cannot be resolved to a type' when I put my mouse over it.
Put an if before the (sender instanceof Player). E.g. Code:java if(sender instanceof Player) { //dostuff}
Code:java package me.Kyler.TheCowPlugin; import org.bukkit.command.Command;import org.bukkit.command.CommandSender;import org.bukkit.entity.Cow;import org.bukkit.entity.Player;import org.bukkit.plugin.java.JavaPlugin; public class TheCowPlugin extends JavaPlugin{public void onEnable(){System.out.println("TCP Enabled");} public void onDisable(){System.out.println("TCP Disabled");} public boolean onCommand(CommandSender sender, Command cmd, String cl, String[] args ){if(cmd.getLabel().equalsIgnoreCase("Cow")) {if(sender instanceof Player) {Player player = (Player) sender;player.getWorld().spawn(player.getLocation(), Cow.class); //Shouldn't it be EntityType.Cow?? Not sure!player.sendMessage("A cow has been spawened at your postition.");} else {sender.sendMessage("Only players can use this command!");}} Syntax error, insert "}" to complete MethodBody
ok Syntax error, insert "}" to complete ClassBody EDIT by Moderator: merged posts, please use the edit button instead of double posting.
Code:java package me.Kyler.TheCowPlugin; import org.bukkit.command.Command;import org.bukkit.command.CommandSender;import org.bukkit.entity.Cow;import org.bukkit.entity.Player;import org.bukkit.plugin.java.JavaPlugin; public class TheCowPlugin extends JavaPlugin{ public void onEnable() { System.out.println("TCP Enabled"); } public void onDisable() { System.out.println("TCP Disabled"); } public boolean onCommand(CommandSender sender, Command cmd, String cl, String[] args ) { if(cmd.getLabel().equalsIgnoreCase("Cow")) { if(sender instanceof Player) { Player player = (Player) sender; player.getWorld().spawn(player.getLocation(), Cow.class); //Shouldn't it be EntityType.Cow?? Not sure! player.sendMessage("A cow has been spawened at your postition."); } //end of player check else { sender.sendMessage("Only players can use this command!"); } //end of else statement } //end of command check return false; } //end of onCommand(...)} //end of class edit: Do you indent at all? That would help you a lot in finding errors like this.... (also using comments like shown above may help as well!)
That's formatting which can make things a bit more confusing unless you configure to your tastes. For example: Code:java System.out.println("This is a very very very long sentence that runs off the side of the program." + "This will be split up to help you read it." + "But this makes newer java coders scratch their heads!"); I know that's a bad example, but the default formatting action can do some weird stuff =P So it's easier to just CTRL+I to properly indent for newer devs.