Solved Command not working D:

Discussion in 'Plugin Development' started by Chintzi, Oct 11, 2014.

?

Am i doing this right?

  1. Yes

    0 vote(s)
    0.0%
  2. Sort of, your just need a little help

    0 vote(s)
    0.0%
  3. Not at all!

    2 vote(s)
    100.0%
Thread Status:
Not open for further replies.
  1. Offline

    Chintzi

    Well im going into plugin designing and i have a lot of ideas and stuff to take care of, but this is slowing me down and i don't know why it is working can someone please help me D:
    Here's the code (I use NetBeans):
    package net.wrightnz.minecraft.skiecraft;
    Code:
    package net.wrightnz.minecraft.skiecraft;
     
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class SkiecraftStats extends JavaPlugin {
     
        Player player;
        public Player Player;
     
        public SkiecraftStats() {
            this.player = (Player);
        }
    //Skiecraft Stats Command, Shows player's statistics such as gamemode, health, food, player name, etc..
     
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
            if (cmd.getName().equalsIgnoreCase("skiecraft")) {
                if (args.length == 1 && args[0].equalsIgnoreCase("stats")) {
            player.sendMessage(player.getName());
                    sender.sendMessage(ChatColor.BLUE + "Stats>");
                    sender.sendMessage(ChatColor.BLUE + "Player:" + ChatColor.AQUA + player.getName());
                    sender.sendMessage(ChatColor.BLUE + "Gamemode:" + ChatColor.AQUA + player.getGameMode());
                    sender.sendMessage(ChatColor.BLUE + "Health:" + ChatColor.AQUA + player.getHealth());
                    sender.sendMessage(ChatColor.BLUE + "Food:" + ChatColor.AQUA + player.getFoodLevel());
                    sender.sendMessage(ChatColor.BLUE + "World:" + ChatColor.AQUA + player.getWorld());
                    sender.sendMessage(ChatColor.BLUE + "Cords:" + ChatColor.AQUA + player.getLocation());
                    sender.sendMessage(ChatColor.BLUE + "Stats>");
                } else {
                    sender.sendMessage(ChatColor.BLUE + "Error>" + ChatColor.GRAY + "Wrong usage, type" + ChatColor.AQUA + "/Skiecraft <command>");
                }
                return true;
            }
            return false;
        }
    }
     
  2. Offline

    Code0

    Just a quick note, you can click the bracket-like icon, select java, insert your code and then hit the "insert" button to make the code more nice and tidy.

    Post Edit: Also, remove your constructor (
    Code:java
    1. public Command_Skiecraft_Stats(){
    2. this.player = (Player);
    3. }

    )

    You also need to tell us where exactly your error is. Chintzi
     
  3. Offline

    pookeythekid

    Chintzi Here's your problem.

    if (args.length == 0 && args[0].equalsIgnoreCase("")

    It's more of a Java problem than a plugin problem. In this statement, you're checking if the arguments are equal to zero, and if args[0] is equal to an empty string. From our English understanding, empty quotes is just the same as nothing. But an empty string is still something to Java. When it checks to see if args[0] equals something--in this case, an empty string--it throws an error because args[0] doesn't exist unless you use arguments in your command. It's looking for args[0]'s value, but the nonexistence of it doesn't do too well with the computer.

    In short, you're confusing your code. Just remove the "&& args[0].equalsIgnoreCase("")", and you should be good.
     
    Code0 likes this.
  4. Offline

    Chintzi

    Alright ill try

    Oh yeah sorry my error is nothing no errors in console no errors in game it just tells me inconsole that i typed the command and in-game is says nothing not a word console logs are here the code is also here its all formatted here so its easier to read :D code

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

    Code0

    I don't fully agree with the "Java Problem" as It does use memory space and therefore exists. But well explained. :)

    Chintzi With the info Pookey gave you, your plugin should work fine.
     
  6. Offline

    JordyPwner

    Registered in main and plugin.yml?
     
  7. Offline

    Chintzi

    Yep ugh why sint my code working ive done everything possible and just to save questions ill tell you when is happening..
    Kk first yes it is registered as skiecraft in plugin.yml and if anyone wants to know the errors I doesnt show any, my guess is it's not the code maybe the file name or the place it is in is effecting it :/

    But if I remove the arg thing it says theres an error, should I post a source code so people can look deeper into this?

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

    Code0

    Yes, you should do that :).
     
  9. Offline

    pookeythekid

    Code0 Say what? By "Java problem" I meant a coding error, not something about how Java works--if the latter is what you meant. And I'm pretty sure that you have to have at least one argument to check if args[0] equals something. It usually throws me an error in my plugins when I accidentally check for a nonexistent argument.
     
  10. Offline

    Code0

    I think we misunderstood each other ;). I thought you meant that Java was wrong and incorrectly coded when it comes to that.
     
  11. Offline

    pookeythekid

    Code0 Ah, okay. Well now we're on the same page. :)
     
  12. Offline

    Chintzi

    Thanks for your help but it turns out it was something different i have 2 commands right now in my plugin and i had extends JavaPlugin for each on and you can only have 1 JavaPlugin in a class so yeah me and my did did some work on it and its all fine :D thanks for your guys help tho, i will send you the files 'n' stuff
     
Thread Status:
Not open for further replies.

Share This Page