Too many return false's?

Discussion in 'Plugin Development' started by dash622, Jun 30, 2016.

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

    dash622


    Code:
    .
    Code:
    package com.dashel.testpxp;
    
    import java.util.logging.Logger;
    
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class PxPTest extends JavaPlugin {
    
        public void onEnable() {
            PluginDescriptionFile pdfFile = getDescription();
            Logger logger = getLogger();
    
            logger.info(pdfFile.getName() + " has been enabled! (V." + pdfFile.getVersion() + ")");
        }
    
        public void onDisable() {
            PluginDescriptionFile pdfFile = getDescription();
            Logger logger = getLogger();
    
            logger.info(pdfFile.getName() + " has been disabled! (V." + pdfFile.getVersion() + ")");
           
            public boolean onCommand(CommandSender sender, Command command,
                    String label, String[] args) {
                if (label.equalsIgnoreCase("pxp")) {
                    if (!(sender instanceof Player)) {
                        sender.sendMessage("Sorry but you do not have permission to use this command!");
                        return false;
                    }
    
                    Player player = (Player) sender;
                    player.sendMessage(ChatColor.BLUE + "PxPCraft Test Command works!!! Good job " + player.getName() + "!");
    
                    return false;
                }
                return false;
        }
    }
    

    Problem:
    . Do I have too many return false's at the end? If so how can I fix that? I was trying to make multiple commands using a new package and class and this guy from a tutorial showed it a different way than what I have on my screen.

    What you can do to recreate the problem:.

    Possible problematic line(s):
    Code:
    return false;
                }
                return false;
        }

    Error message (If any):
    None havent used ingame yet

    What you have tried:
    . Removing the last return false and changing return false above last to return true

    This is my first time making a plugin so some things may be new to me

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

    MCnumi

    Did you learn this from a channel on youtube called "TheBCBroz"?
     
  3. Offline

    bwfcwalshy Retired Staff

    @dash622
    1. Remove the logger
    2. No need to log enable and disable Bukkit does it for you
    3. If you aren't using onDisable remove it
    4. Your command is in your onDisable, you are missing a closing bracket.
    5. Check cmd.getName not label, this gives the ability for aliases
    6. The returns don't matter that much but it is if the command was completed successfully, so you may want to make the one after the send test message to true
    7. Do not learn off TheBCBroz, he teaches bad practices and made the tutorials when he was still learning Java and Bukkit. This does not add up to a good teacher.
     
  4. Offline

    dash622

  5. Offline

    bwfcwalshy Retired Staff

    @dash622 No need to double post and PogoStick29Dev probably has the best YouTube tutorials.
     
  6. Offline

    dash622

    @bwfcwalshy okay thanks! I am kind of new to this coding thingy. Im only 13 so i don't rlly know has good tutorials and who doesnt
     
  7. Offline

    teej107

    Zombie_Striker and bwfcwalshy like this.
Thread Status:
Not open for further replies.

Share This Page