Solved Why doesn't this work?

Discussion in 'Plugin Development' started by evantheis, Jul 3, 2013.

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

    evantheis

    I have this plugin for donators on my server they can do /nightvision and it'll give them nightvision for an unlimited time, but I can do the command in console still. Here is the code.
    Code:java
    1. if (!(sender instanceof Player)) {
    2. sender.sendMessage(ChatColor.AQUA + "You can't have nightvision as console!");
    3. return true;
    4. }


    Shouldn't that work?

    You wouldn't return false because I want it to send a message to the console saying "You can't have night vision in the console!"

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

    messageofdeath

    if(sender instanceof ConsoleCommandSender) ?

    evantheis
    That code worked for me.

    [​IMG]

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

    evantheis

    I get errors no matter what! What are you doing?

    I am in the latest I just updated today.

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

    messageofdeath

  5. Offline

    ELCHILEN0

    Try pasting your entire source for the onCommand method as well as the errors that you are receiving. It is more likely an error with some other part of your code. To expand upon the true/false a bit more, it will not effect the outcome of the method regardless of which one you use; however, returning false will display the usage if set in the plugin.yml for the specified command. I personally always return true and send messages to the user in the error handling for the command but it is up to you to choose what you prefer. The code will end once it hits its first return statement so but remember there can be multiple return statements in the same method but once one gets "hit", the execution stops and continues onto its other tasks.

    As for your error. We cant really help without the errors that occur in the console unless there was an obvious bug. When you are debugging your plugins it often says the line number that the exact error is on and you can debug even further from there. Java in and of itself has a great error/exception system (which contributes to slower performance when compared to different languages) so everything you need to know should be there. If you still cannot figure out the error then feel free to post your source and error and im sure I will be able to help you out! :)
     
  6. Offline

    messageofdeath

    I use the latest dev build of craftbukkit/bukkit and it still worked on my server
     
  7. Offline

    SnipsRevival

    Why would that matter in this case?

    Well perhaps he could post the rest of his code and someone might come up with an alternative conclusion.

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

    ELCHILEN0


    Not to be offensive but your quotes seem a little immature and not helpful. The development environment is not going to matter in this case. Java works the same on both systems and if hes able to start the server then its an issue with the plugin itself. Also no need to spam your "ProTip". I myself use the ChatColor enum instead of § as it is better to support an enum that will always be up to date with different CraftBukkit versions then a String that can change in any update. Using ChatColor ensures that users running two different versions will see the same colors regardless of any changes to the actual CB/Minecraft code itself.
     
  9. Offline

    bob7

    Could you post all of your code?
     
  10. Offline

    evantheis

    I got it all fixed and i'm updating this to solved! Thanks though! It was an easy fix. I also changed everything to a CommandExecutor. Much easier and cleaner code now. Thanks
     
  11. Offline

    SnipsRevival

    evantheis Would you mind posting what you changed? It might be helpful for other people if they ever come across the same problem.
     
  12. Offline

    unforgiven5232

    T3h Cr33p3r
    Sorry for tagging :p but how do you do this symbol? §3
     
  13. Offline

    ZeusAllMighty11

    T3h Cr33p3r Bit of setup? More like a simple copy+paste.

    unforgiven5232 If you are on a keyboard that has a number pad, it's ALT+2+1


    Don't use the section symbol if you plan on sharing your project.
     
Thread Status:
Not open for further replies.

Share This Page