TheCowPlugin

Discussion in 'Plugin Development' started by cheer60823, Jun 23, 2013.

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

    cheer60823

    Iv'e Been developing a plugin for amusement (using eclipse juno) and I've run into some problems.

    Code:java
    1. package me.Kyler.TheCowPlugin;
    2.  
    3. import org.bukkit.entity.Cow;
    4. import org.bukkit.plugin.java.JavaPlugin;
    5.  
    6. public class TheCowPlugin extends JavaPlugin
    7. {
    8. public void onEnable()
    9. {
    10.  
    11. }
    12.  
    13. public void onDisable()
    14. {
    15.  
    16. }
    17.  
    18. public boolean onCommand(CommandSender sender, Command cmd, String cl, String[] args)
    19. {
    20. if (cmd.getname().equalsIgnoreCase("Cow"))
    21. {
    22. (sender instanceof Player) {//check is the sender is a player
    23. Player player = (Player) sender; //cast the sender to a player
    24. player.getWorld().spawn(player.getLocation(), Cow.class); //spawn a cow
    25. }
    26.  
    27.  
    28.  
    29. }
    30.  
    31.  


    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.
     
  2. Offline

    MrJoe223

    Put an if before the (sender instanceof Player).

    E.g.
    Code:java
    1. if(sender instanceof Player) {
    2. //dostuff
    3. }
     
  3. Offline

    Kodfod

    your missing the following in bold:

    if
    (sender instanceof Player) {
     
  4. Offline

    cheer60823

    Code:java
    1. package me.Kyler.TheCowPlugin;
    2.  
    3. import org.bukkit.command.Command;
    4. import org.bukkit.command.CommandSender;
    5. import org.bukkit.entity.Cow;
    6. import org.bukkit.entity.Player;
    7. import org.bukkit.plugin.java.JavaPlugin;
    8.  
    9. public class TheCowPlugin extends JavaPlugin
    10. {
    11. public void onEnable()
    12. {
    13. System.out.println("TCP Enabled");
    14. }
    15.  
    16. public void onDisable()
    17. {
    18. System.out.println("TCP Disabled");
    19. }
    20.  
    21. public boolean onCommand(CommandSender sender, Command cmd, String cl, String[] args )
    22. {
    23. if(cmd.getLabel().equalsIgnoreCase("Cow")) {
    24. if(sender instanceof Player) {
    25. Player player = (Player) sender;
    26. player.getWorld().spawn(player.getLocation(), Cow.class); //Shouldn't it be EntityType.Cow?? Not sure!
    27. player.sendMessage("A cow has been spawened at your postition.");
    28. } else {
    29. sender.sendMessage("Only players can use this command!");
    30. }
    31. }




    Syntax error, insert "}" to complete MethodBody
     
  5. Offline

    Kodfod

    cheer60823 you need one more } at the bottom.
     
    cheer60823 likes this.
  6. Offline

    cheer60823

    ok

    Syntax error, insert "}" to complete ClassBody

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 2, 2016
  7. Offline

    Kodfod

    Code:java
    1. package me.Kyler.TheCowPlugin;
    2.  
    3. import org.bukkit.command.Command;
    4. import org.bukkit.command.CommandSender;
    5. import org.bukkit.entity.Cow;
    6. import org.bukkit.entity.Player;
    7. import org.bukkit.plugin.java.JavaPlugin;
    8.  
    9. public class TheCowPlugin extends JavaPlugin
    10. {
    11. public void onEnable() {
    12. System.out.println("TCP Enabled");
    13. }
    14.  
    15. public void onDisable() {
    16. System.out.println("TCP Disabled");
    17. }
    18.  
    19. public boolean onCommand(CommandSender sender, Command cmd, String cl, String[] args ) {
    20. if(cmd.getLabel().equalsIgnoreCase("Cow")) {
    21. if(sender instanceof Player) {
    22. Player player = (Player) sender;
    23. player.getWorld().spawn(player.getLocation(), Cow.class); //Shouldn't it be EntityType.Cow?? Not sure!
    24. player.sendMessage("A cow has been spawened at your postition.");
    25. } //end of player check
    26. else {
    27. sender.sendMessage("Only players can use this command!");
    28. } //end of else statement
    29. } //end of command check
    30. return false;
    31. } //end of onCommand(...)
    32. } //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!)
     
  8. Offline

    cheer60823

    :D Thanks!
     
  9. Offline

    travja

    Using eclipse, you can do Ctrl+A then Ctrl+I to indent everything to where it should be.
     
  10. Offline

    imaboy321


    or Ctrl + Shift + F
     
  11. Offline

    cheer60823

    F**K YEA IT WORKD THIS IS SO AWESOME THANK YOU SO MUCH!!!!! Kodfod
     
  12. Offline

    Kodfod


    That's formatting which can make things a bit more confusing unless you configure to your tastes.

    For example:
    Code:java
    1. System.out.println("This is a very very very long sentence that runs off the side of the program." +
    2. "This will be split up to help you read it." +
    3. "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.
     
Thread Status:
Not open for further replies.

Share This Page