Solved (URGENT)Need help with Timer

Discussion in 'Plugin Development' started by mrgreen33gamer, May 17, 2014.

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

    xize

    The stacktrace looks incomplete, please show the full stacktrace from your log files in case you use multicraft it shows half complete stacktraces.

    it kinda sounds like your plugin is running in a stackoverflow since the player also disconects.

    however I'm on a phone so I didn't read the whole code.

    -edit-
    also you actually shouldn't use static on these fields.
    instead use constructors or either static factory methods where you instance a whole class as a singleton and only when there is no otherway.

    static is not a encourage way of doing things to make things simple for you, because it could cause really nasty behaviour such when you for example allow multi threading in your plugin and do a call in the seperated thread to this anonymous object which isn't asigned to any class then there is a chance a ClassNoDefoundException throws, this is why I would highly discourage static since it confuses devs very fast and isn't the cleanest way to read code.

    in your main class I don't really see why your ArrayLists should be static, if you could put the plugin through a constructor and only do new ArrayList<String>() in onEnable rather than instancing the ArrayList in the field.
     
  2. Offline

    L33m4n123


    First off all. Hypocrite ;) Second of all. Before you try to trash talk I suggest you looking up what the word means. How does it makes ME a hypocrite if I suggest you learning java? I for my part know Java. Maybe not as much as others on these forums. But I know enough to make at least half decent plugins / code and I don't want more from you. So nope. I am in no way a hypocrite
     
  3. Offline

    Sgt_Tailor

    create and use a playerWrapper class?
     
  4. Offline

    fireblast709

    Ok then, challenge accepted.
    • static instance of main class, could cause memory leaks on reloads.
    • static usage when not needed, discarding the encapsulation principle of OOP.
    • ArrayList<Boolean>, to no end since you cannot see what the boolean is for.
    • unchecked cast to Player, if the console executes the command it would lead to a ClassCastException.
    • As Garris0n mentioned, comparing to the true keyword could be considered unnecessary unboxing (perhaps not the right term, but whatever).
    • Calling .remove(E) after .clear(), if you actually knew how collections worked you would've known that .clear() empties the list, thus rendering any calls to .remove() useless.
    • Why are you adding null to your lists in the first place (since you use .remove(null)).
    • Sending the same message 5 times? Please learn how for-loops work if you want to do repetitive work efficiently.
    • Suppressing an unused warning? Why not just remove the line since you are just executing bytecode to no end.
    So aside your lacking knowledge of OOP, I also see some lacking Java knowledge (referring to things like looping, which is something really basic). That is why I told you to go learn Java. Now you can report me for this all you like, but I doubt any staff member would see this as offensive. That aside, I saw several people telling you the same thing, but you brush them away calling them offensive, while all we do here is trying to help you in the end.
    +1 on discouraging players to use static, but for the wrong reasons :p (NoClassDefException occurs for other reasons). The main reasons are memory leaks and breaking OOP design. (And it is mostly unneeded)
     
    Garris0n, xize and L33m4n123 like this.
  5. Offline

    L33m4n123

    Besides what fireblast709 said

    • nowhere in your onCommand you return true. That means if you propperly set up your command in your plugin.yml you will always see the usage being printed out and thus will never know if something in your command Handling is wrong. And I mean the onCommand can return true for a reason. That you can track down errors in your command Handling. Seeing if the command run sucessfull or not
    • now to your runnables. You have a runnable. Thats good. But you set within the runnable the timer back to 30 and then remove 1 thus it always stays at 29. Thus your if construct does not get called. And your many if countdown == .. look into the usage of switches. they are more efficent. So and due to the issue I said at the beginning with the timer stuck at 29 loadgame2 does not start however
    • in loadgame 2 ingame will be stuck at -29 due to the same issue as above. you set it within the timer thus none of your ifs getting called [and here again. use switch cases]
     
  6. Offline

    mrgreen33gamer

    fireblast709
    * Lacking the knowledge of Java is not supporting the idea of what the topic is about. Your information got me somewhere. But the timer doesn't countdown. First, the boolean is checking the all the players within the isPlaying boolean, which is added whenever a player does: /sg join or /join. I don't get a console error. OOP doesn't have ANYTHING to do with this. This is simply a matter of a Bukkit Countdown System. Whenever I use a:
    Code:
    public static countdown = 20;
    Then it works, but when I use the int in the void,
    Code:
    public void testGame(final int time){
    it doesn't want to respond.

    L33m4n123
    Your runnable information is quite interesting. But it doesn't solve the problem. I thought I had an idea from what I read from your post. But I didn't get the complete spark.

    Since when did I talk trash? I didn't say [1!] curse word in ANY of my sentences. That's talking smart-ass :p.

    Problem is:

    * I am NOT getting an error from the console. Computer server and Mulitcraft server. For some reason. I think it is the:
    Code:
    public void testGame(final int time){
    part. This part I found issues with.

    I can't because I don't know this. The guy that thought he knew everything, obviously, knew what he was talking about, so I asked him to solve it. That's why the Bukkit Forums are for. Right?


    First: Checked....
    Second: ArrayLists are easier than Lists and HashMaps. + They fit the perfect code for checking all the players within the game.
    Third: The reason I have sooo many statics is because other classes use the ArrayLists and Booleans.
    Fourth: I don't disagree. Yet again what I said in the top post.

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

    Rocoty

    No you're wrong. The Bukkit forums is not a place where you go to get your code solved. It is a place where you go to get help with solving your code by yourself. It is a significant difference.
     
    L33m4n123 likes this.
  8. Offline

    mrgreen33gamer

    True dat
     
  9. Offline

    fireblast709

    Java is the language used to write Bukkit plugins. Therefore, lacking the required knowledge to write in the language is a huge pitfall many new developers encounter.
    Java is an Object Oriented language (and guess where the OO in OOP stand for)
    Second: ArrayList extends AbstractList which in turn implements List. Also, there is no way to see for which Player object it is true or false, therefore you should use Maps, not any implementation of List.
    Third aside that it does not fit with the OOP design principles, it is error-prone (especially for people who do not know how to handle statics. Once you use that runnable twice at the same time, you are pretty much done for.
    The reason you aren't getting the errors are either: you didn't execute it from console or rate limiting hides them from the console.

    The reason I keep on "bashing" on your Java is because these issues are caused by misusing static and the Collection framework. Assuming you were referring to me as the guy 'who knew everything', why don't you actual listen to what I am trying to suggest instead of instantly throwing my advice away.
     
    jimuskin likes this.
  10. Offline

    mrgreen33gamer

    Forget this. Closing the topic
     
  11. Offline

    1Rogue Retired Staff


    ...

    Seems pretty contradictory.




    ah yes, the clever ruse. "I know exactly what's wrong! I just want to see if you do".

    People helping you in threads aren't code slaves, they'll offer help to guide you in a proper direction. If your response to that help is to simply be confrontational about it I'm not really surprised that people are deciding that it's not worth their time.
     
    Rocoty and AdamQpzm like this.
  12. Offline

    oscarshi1995

    U should store a list of UUIDs not players
     
  13. Offline

    Rocoty

    oscarshi1995 You should if you don't know what you're doing, yes. That is why newbies around here are encouraged to. But when it comes down to it, there is nothing bad about storing a Player object in memory as long as you make sure to release it when you no longer need it. E.g. when the player logs out.
     
  14. Offline

    mrgreen33gamer

    Okay everyone I have solved the issue. I deleted my old code and created a new one, simplified, and then learn a little bit more about countdowns in the Bukkit Docs and Java Docs and I have solved it!
     
Thread Status:
Not open for further replies.

Share This Page