&& Wont work

Discussion in 'Plugin Development' started by camnooten, Jul 8, 2016.

Thread Status:
Not open for further replies.
  1. Problem: Every argument that I try doesn't work. I have done plenty of research on Google and went to a lot of web pages.

    Error: The operator && is undefined for the argument type(s) String, boolean

    What I have done: I have tried to replace && with &, =, ==, I just don't know what to put there.

    Line: 23

    If you could help me that would be great!

    Java Code:

    Code:
    package me._CamPlayzMC_;
    
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
    
    import net.minecraft.server.v1_10_R1.EnumItemSlot.Function;
    
    public class CamCraft extends JavaPlugin {
       
        @Override
        public void onEnable() {
            getLogger().info("CamCraft 1.0 enabled!");
        }
        @Override
        public void onDisable() {
           
        }
       
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args[] ) {
       
        if (cmd.getName().equalsIgnoreCase("hello" && sender instanceof Player )) {
           
            Player player = (Player) sender;
           
            player.sendMessage("Hello, " +player.getName() + "Welcome to the server");
           
            return true;
        }
       
        return false;
      }
    }
       
       
    
     
  2. Offline

    ArsenArsen

    Move the parentheses after the instance of before the &&.

    Hate to say it, but learn java and some general programming before bukkit.
     
    MCnumi likes this.
  3. Offline

    Zombie_Striker

    Bukkit logs your plugins for you. You don't need to log it twice.

    Your plugins shouldf follow the format "me.<name>.<project name>", and should be all lower case.

    If the method does nothing, remove it.

    And as has been said before:
    https://bukkit.org/threads/plugin-dev-sticky-learning-java-where-to-learn.395662/
     


  4. Thank you so much! I plan on doing Java classes online. But thank you so much for the help and im sorry im not good at Java.

    - Cam
     
  5. Offline

    MCKrypto14

    lol why is the args in onCommand defined as a 2 dimensional array?

    it should be
    Code:
    String[] args
    not
    Code:
    String[] args[]
     
    I Al Istannen likes this.
  6. Offline

    MCMastery

    It's combining the Java arrays with C arrays.

    C arrays are defined as
    Code:
    String args[]
    Java arrays are defined as
    Code:
    String[] args
    They both work in Java. (However I did not know you can combine them).
    But use the Java array definition.
     
    Last edited: Jul 10, 2016
    bwfcwalshy and I Al Istannen like this.
  7. Offline

    I Al Istannen

    @MCMastery
    It is actually a 2d array. Just check with your IDE ;)

    But you are complety right with the rest!
     
    MCMastery likes this.
  8. Offline

    Liam Townsley

    Hello!

    Here is the code you can use to allow the &&'s to work.

    Code:
    package me._CamPlayzMC_.CamCraft;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
    import net.minecraft.server.v1_10_R1.EnumItemSlot.Function;
    public class CamCraft extends JavaPlugin {
    
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args ) {
    
        if (cmd.getName().equalsIgnoreCase("hello") && sender instanceof Player ) {
        
            Player player = (Player) sender;
        
            player.sendMessage("Hello, " +player.getName() + "Welcome to the server");
        
            return true;
        }
    
        return false;
      }
    }
    
       
    If you copy this it should work.
     
    Last edited: Jul 10, 2016
  9. @Liam Townsley If your gonna spoon feed might as well fix the other 5 issues
     
Thread Status:
Not open for further replies.

Share This Page