Please help me with a code

Discussion in 'Plugin Development' started by xristaras40blaums, Dec 13, 2014.

Thread Status:
Not open for further replies.
  1. Hi guys i am a noob begginer at coding and i just tried to make my own bukkit plugin idk what i did wrong please help look

    http://pastebin.com/eL0QQQyM
    if someone knows help :( !
    And please write at the comments the best way to learn bukkit i already learnt java from thenewboston!

    HELP!
     
  2. Offline

    HeadGam3z

  3. Offline

    mythbusterma

  4. Offline

    Skionz

    @xristaras40blaums You aren't checking what command is being sent. You should check before casting which is another thing you should already know considering you already know Java. Look at @mythbusterma 's link
     
  5. Offline

    Tecno_Wizard

  6. Offline

    DeadlyScone

    @mythbusterma is correct. @HeadGam3z is a bit useless in your situation. You learned some basics of java from Buckey and now you neeed to learn about the API you are about to program with.

    The API if you guessed, is bukkit.

    So learn how to make a plugin and get some basic understanding of how to use it.

    For further questions, this will be your friend(bible)
    http://jd.bukkit.org/rb/apidocs/

    Good luck!
     
  7. Offline

    HeadGam3z

    @DeadlyScone False. He's failing to check before casting, failing to use an else if, and failing to return true. This is basic Java knowledge which he has yet to obtain.
     
  8. Offline

    Tecno_Wizard

    I would have to disagree. There is a major difference between java book knowledge and experience knowledge. He has a general understanding of the book knowledge if he actually did watch all of the videos, but you can read or watch as much as you want about it- it's no substitute to experience.

    I'm going to partially spoon feed you- without giving you any code. This is looked down upon in a lot of areas, but as a beginner it's necessary. (Sorry Guys)

    Code:
    package org.teh;
    
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Main extends JavaPlugin{
        public void onEnable(){
         
        }
     
        public void onDisable(){
         
        }
     
        @SuppressWarnings("deprecation")
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
            Player player = (Player) sender;
            if(player.isFlying()){
                player.damage(10);
            }else{
                if(player.isSprinting()){
                    player.kickPlayer(null);
                }
            }
            return false;
         
        }
    
    }
    First, your white spaces are out of control. This is the one and only thing I will fix for you.

    Code:
    package org.teh;
    
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Main extends JavaPlugin{
        public void onEnable(){
        }
     
        public void onDisable(){     
        }
    
        @SuppressWarnings("deprecation")
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
            Player player = (Player) sender;
            if(player.isFlying()){
                player.damage(10);
            }else{
                if(player.isSprinting()){
                    player.kickPlayer(null);
                }
            }
            return false; 
        }
    }
    Okay. Now I have no idea what command was registered to the onCommand in the plugin yml, so for this, i'll pretend it's /foo
    At the moment, when a console calls foo, line 19 of your original WILL throw an error. use an instanceof check to make sure that the sender is a player.(http://www.java2s.com/Tutorial/Java/0060__Operators/TheinstanceofKeyword.htm)

    Also, giving player.kickPlayer null may cause a problem. Find another way to do this.
    Returning false means the command was not handled. You know what to do.
    That's all I have to say.
     
  9. Offline

    All_Fire69

    You don't need a command in your plugin.yml if there aren't any commands..
     
  10. Offline

    mythbusterma

    @All_Fire69

    Erm, you're completely off base....the OP was obviously trying to create a command, and that's exactly what TechnoWizard posted about, and yes, you would need it in a plugin.yml if that was the case.

    There are no obvious EventHandlers anywhere around here, and there certainly weren't any in Tecno's post, and you don't even say what you're talking about when you say "instances," I don't see how Tecno needs to learn Java, frankly.
     
    Tecno_Wizard likes this.
  11. Offline

    Tecno_Wizard

    @All_Fire69
    Nothing you said in either of those posts made any sense whatsoever, and don't try to rebuttal it.
    These are no event handlers in this whatsoever, and using "Instances" literally makes no sense.
     
  12. holy yeaaa! :O i solve it with your help but i deleted some word of the code !

    But i still can't choose which of your way to learn bukkit is good! i am confused right now! Some people say thebcbroz
    some people say that wiki tutorial for bukkit, some people say when i am coding i must use this for help : http://jd.bukkit.org/rb/apidocs/ ! Can a very very good developer tell me how he learnt bukkit? Because i have seen some servers with a lot of people asking for a developer, i want but i am a damn begginer !
     
  13. Offline

    timtower Administrator Administrator Moderator

  14. by trial and error? what you mean!
     
  15. Offline

    timtower Administrator Administrator Moderator

    @xristaras40blaums That you just start making something ( trial ). Then you probably won't succeed at the beginning ( error ) and then you try something else. Keep repeating till happy with the product
     
  16. i am gonna check again the java tutorials! :/

    how did you learn coding? exept learning java! I want u to tell me where you were looking to learn
     
  17. Offline

    timtower Administrator Administrator Moderator

    @xristaras40blaums I looked in my IDE and tried, failed, tried again. And kept repeating.
     
    ChipDev likes this.
  18. please tell me what is IDE :'(
     
  19. Offline

    timtower Administrator Administrator Moderator

  20. but i can't understand how you can think what you must put in the code. THERE'S SO MANY THINGS TO CODE!
    I AM STUCK !
     
  21. Offline

    timtower Administrator Administrator Moderator

    @xristaras40blaums Start with hello world plugins, then listeners, then you keep expanding.
     
  22. hello words? hmm can send me a video for hello word and listeners? plz
     
  23. Offline

    Skionz

    @xristaras40blaums Are you sure you know Java? A hello world is simply a program which somehow prints out "Hello World!" A listener checks when an event happens in a world and then you manipulate that event.
     
  24. i told i am gonna check java again :) look up!

    but it's easy to create a hello word !

    public static void main (String args[]) {}
    System.out.println("Hello word")

    I already know this! but how it can help me?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 29, 2016
    ChipDev and Skionz like this.
  25. Offline

    Skionz

    Dragonphase and ChipDev like this.
  26. Offline

    ChipDev

    Keep all code inside of methods inside of the { }'s!
     
  27. @Skionz if you are a good developer please send me the site/videos that you learnt bukkit! i beg you :(
     
  28. Offline

    Skionz

  29. i know i just wrote {} because i couldn't press space inside them so they can go like this

    public static void main (String args[]) {
    System.out.println("Hello word")
    }

    so you learnt making plugins with http://wiki.bukkit.org/Plugin_Tutorial and whn you want to make a plugin you go at http://jd.bukkit.org ?

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

    Skionz

Thread Status:
Not open for further replies.

Share This Page