Solved Public Booleans getting errors.

Discussion in 'Plugin Development' started by NordisKFail, Apr 30, 2015.

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

    NordisKFail

    Hey, i am making a plugin that makes the server get infinite slots as long as a player got a permissions, i am making a test command, then i need the Public Boolean thingy, but i just get errors in Public Boolean, if you want i may give you my code. :) Of course i HAVE to give it. :p

    Code:
    package me.NordisKFail;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerLoginEvent;
    import org.bukkit.event.player.PlayerLoginEvent.Result;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class PluginMain extends JavaPlugin implements JavaListener {
    
        public void onEnable() {
            getLogger().info(ChatColor.GRAY + "[" + ChatColor.AQUA + "DedicatedSlots" + ChatColor.GRAY + "] " + ChatColor.YELLOW + "Ser ut som om pluginen funker som den skal (DedicatedSlots av NordisKFail)");
            Bukkit.getServer().getPluginManager().registerEvents((Listener) this,     this);
        }
       
        @EventHandler
        public void onPlayerLogin(PlayerLoginEvent e) {
            if (e.getResult() == Result.KICK_FULL && e.getPlayer().hasPermission("dedicateslots.allow")) {
                e.allow();
            }
           
             public boolean onCommand (CommandSender sender, Command cmd, String label, String[] args) {
                Player player = (Player) sender;
           
            if(cmd.getName().equalsIgnoreCase("test")) {
                player.sendMessage(ChatColor.GRAY + "[" + ChatColor.BLUE + "GoliCraft" + ChatColor.GRAY + "] " + ChatColor.YELLOW + "Pluginen funker som den skal" + ChatColor.YELLOW + "!");
                return true;
            }
        }
           
        }
    }
    
    Don't post anything off topic in this post as i want to get to stick to the topic.
     
  2. @NordisKFail Okay, it's quite clear from your code that you are new to both Java and the Bukkit API. Firstly, you have to learn Java before you can make a plugin - trying to learn both at the same time just won't work out and you'll just end up having to come back here to ask questions all the time. I recommend the Oracle tutorials, or a Java book.

    Once you have learned basic Java and are ready to come back to plugins, I recommend you read the plugin tutorial on the Bukkit wiki before trying to make your own plugins.

    Good luck!
     
  3. Offline

    NordisKFail

    @AdamQpzm I know i am new, but you know what they say, you learn of doing things wrong, i really want to learn this, and i am not good at learning just by looking i need to do it myself too, so i am trying my best, sometimes i may come and ask here, but this is the only place that actually helps me out, so if you don't want to help me with my plugin just ignore me, isn't it so easy?

    EDIT: I am always so bored so this is something to do when i am not actually doing something.
     
  4. Offline

    mine-care

    @NordisKFail well the "learn by doing it wrong" has a side effect... it is time consuming :p
    So about your code a few notices:
    Package names should be lowercase (Naming Convention)
    Daf? what is dat?
    Ahh... i see the confusinon! You should implement Listener from org.bukkit.event not JavaListener.
    That casting...
    Usefull resources:
    https://howtoprogramwithjava.com/java-cast/
    http://java.about.com/od/javasyntax/a/nameconventions.htm
    http://wiki.bukkit.org/Plugin_Tutorial
    https://docs.oracle.com/javase/tutorial/java/javaOO/accesscontrol.html


    Lastly Java is considered a requierment for Bukkit (at least the basic knowledge)
    Good luck :D
     
    Last edited: Apr 30, 2015
  5. Offline

    NordisKFail

    As said i want every post to stick with the topic, this helped me a little but i want it to be a little more sticked to the topic. Package does not need to be lowercase, a friend told me to use JavaListener he didn't explain it he just said that i needed to use it! And the Listener isn't the problem altough i tried it out to see if it fixed the main problem but it didn't, i need you to help me with the public boolean, as it's the main problem, i made another plugin (Didn't post here.) and it worked fine, i have compared my other plugin and this plugin and i can't see anything wrong, so someone please help me with the MAIN topic NOT any other stuff, i know everybody tries to help me, but right now i only need everybodys help on the "public boolean" as said
    and
    so PLEEEAASE stay into the MAIN topic and if you don't have something not important to say, just IGNORE my post!
     
  6. Offline

    mine-care

    @NordisKFail
    Wait, i was trying to help you learn a few stuff out of it rather than just throw the solution, since as you said:
    Package name does not have to be lower case indeed function-wise but Java naming conventions are there for a reason and they are mostly followed by devs making code clear to read and easier to understand, The link provided explains in depth.
    Listener would be a problem because registerEvents method accepts a listener and the plugin instance. so providing a class that is not an implementation of list interface would cause a ClassCastException the way it is done in your code.
    As you may have figured in these forums we dont really like spoon feeding people code or generally throwing the easy solution and let people gain nothing out of it.

    So if you want to proceed with your plugin without getting any of what i said so far, fine it is up to you.
    the thing is that you do not specify what you want to use the boolean for, does it refer to Boolean or boolean because in the thread you mention Public Boolean whereas in your latest post you mentioned public boolean, so whitch of those 2 you want help with, because now i can just say
    "Here: public Boolean name; or Here: public boolean name;"
    but do you know how to proceed from here?
    Also about that:
    i really belive that what i mentioned above in my post is pretty important because once you figure how to fix the boolean the other error will apear when you call a command from console you will get a ClassCastExcepton and then another problem will apear when your plugin is enabled again by ClassCastException.

    To sum up please provide the reason you want to use the boolean for, what is the error you get?
     
  7. Offline

    mythbusterma

    @mine-care

    He's talking about the method signature for CommandExecutor#onCommand(...), which is a public method that returns a boolean.

    Unfortunately, he doesn't seem to understand that you can't put a method inside of another method.
     
    mine-care likes this.
  8. Offline

    mine-care

    @mythbusterma oh i see. As you see from the posts above i tried to provide some usefull resources to read and probably be able to create the public boolean variable (i thought it was about creating a public boolean variable so thats why i couldnt get what OP ment :) ).
    Thanks, now i should provide one more link xD
    http://www.tutorialspoint.com/java/java_methods.htm
     
  9. Offline

    NordisKFail

    I don't need help with my knowings of java .etc, i need the answer. :)

    EDIT: @mine-care and @mythbusterma, forgot to tag you guys.
     
  10. Online

    timtower Administrator Administrator Moderator

    @NordisKFail It is your java knowings though.
    Close the onJoin method.
     
  11. Offline

    mine-care

    @NordisKFail Really? it does not look like that :3 and yes the actuall solution was given by @timtower .
     
  12. Offline

    NordisKFail

    Not to be dumb but, that means?
     
  13. Online

    timtower Administrator Administrator Moderator

    @NordisKFail That you open a method while you never close it again.
    Code:java
    1.  
    2. @EventHandler
    3. public void onPlayerLogin(PlayerLoginEvent e) {
    4. if (e.getResult() == Result.KICK_FULL && e.getPlayer().hasPermission("dedicateslots.allow")) {
    5. e.allow();
    6. }
    7.  
    8. public boolean onCommand (CommandSender sender, Command cmd, String label, String[] args) {
    9. Player player = (Player) sender;
    10.  
    11. if(cmd.getName().equalsIgnoreCase("test")) {
    12. player.sendMessage(ChatColor.GRAY + "[" + ChatColor.BLUE + "GoliCraft" + ChatColor.GRAY + "] " + ChatColor.YELLOW + "Pluginen funker som den skal" + ChatColor.YELLOW + "!");
    13. return true;
    14. }
    15. }
    16. }
    17.  

    Notice the indentation that is just wrong.
     
  14. Offline

    NordisKFail

    Ok so what you say is that i need an "public void OnDisable? (I am norwegian, my english is crap!)
    Or am i wrong? If i need where will i put it?

    Or could you just edit it so it is fixed then give it to me? I think that would be more easy so i don't make shit more wrong than it actually is. xP
     
  15. Online

    timtower Administrator Administrator Moderator

    @NordisKFail I never said that you are missing a function.
    You have a function in a function, that just isn't possible.
     
  16. Offline

    teej107

    Just saying that you need a basic Java knowledge to make Bukkit plugins. You lack the basic knowledge. This has nothing to do with Bukkit, and has everything to do with basic Java.
     
    NordisKFail and mine-care like this.
  17. Offline

    NordisKFail

  18. Online

    timtower Administrator Administrator Moderator

    @NordisKFail Just count the spaces, you are declaring a new function before you close the last one.
    This is basic java.
     
  19. Offline

    NordisKFail

    @timtower where do i do that, i don't know what you mean by closing the onJoin method. You might understand that i am trying really hard and i won't give up even the java language has really advanced words that i usually don't use!
     
  20. Online

    timtower Administrator Administrator Moderator

    @NordisKFail You open it with {, but the one that you use to close it "}" is misplaced in your code.
     
  21. Offline

    Koobaczech

    Props to timtower for not pulling a teej107 and pasting a link to learn java. Its nice to see you take your time and explain very simple things like open and closing brackets. Just saying, the world needs more patient people like you!
     
  22. Offline

    NordisKFail

    I see but i can't seem to find it, so i'll just repeat the code. xD I have used maybe 6 hours on this and all i could have done is to recode it in 5-10 mins. @timtower thanks for helping me out (in a way) instead of just saying that i need to study java .etc more, the only reason i couldn't do this was because my english was SOOOO bad. xD But thanks.
    I was all like kinda scared to ask you for more help because i tought you were bored of me. :p You a really good mod and i respect you!

    EDIT: When i mean 6 hours, i mean that i might have used 6 hours on only this post. xD
     
Thread Status:
Not open for further replies.

Share This Page