Util Auto Downloading Plugins Through Plugins

Discussion in 'Resources' started by Gingerbreadman, Dec 22, 2014.

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

    Gingerbreadman

    [Util Removed]
     
    Last edited: Dec 24, 2014
    ChipDev and Skionz like this.
  2. Offline

    AdamQpzm

    @Gingerbreadman
    1. Bare in mind that doing this will have your plugin rejected from BukkitDev for obvious reasons.
    2. Why a public time field? Encapsulate that field!
    3. Don't do if(boolean==false), do if(!boolean)
    4. Why are you creating a "b" variable that you only ever set to true and only ever use once?
     
    Skyost likes this.
  3. Offline

    Gingerbreadman

    @AdamQpzm The boolean is used to set Downloaded in the config to true, making the util not constantly repeat
     
  4. Offline

    AdamQpzm

    Skyost likes this.
  5. Offline

    Gingerbreadman

    @AdamQpzm true, I will change that (I was not thinking straight yesterday (I was doing this at 2am))
     
  6. Offline

    DJSkepter

    @Gingerbreadman Correct me if I am wrong, but will this not cause a bit of lag if the plugin file is pretty big? What you should do, is make sure that the server reloads after the file has downloaded (So probably put it in one of those finally sections).
     
  7. Offline

    Gingerbreadman

    @DJSkepter Its actually already has a reload function
     
  8. Offline

    AdamQpzm

    @Gingerbreadman Looking at it again, I notice you download the file in the main thread. That's a bad idea.

    @Gingerbreadman Downloading a file over the primary thread? Of course it's bad! Why wouldn't that be bad?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 28, 2016
    Skyost likes this.
  9. Online

    timtower Moderator Moderator

    @Gingerbreadman Resource is a section, in that already. For further reference: top right corner, thread tools, edit thread.
     
  10. Offline

    Gingerbreadman

    @AdamQpzm Its not like I am downloading a huge file, plugins download fast
     
  11. Offline

    Assist

    @Gingerbreadman
    But you freeze the main thread for the duration of the download.
     
    AdamQpzm likes this.
  12. Offline

    AdamQpzm

    @Gingerbreadman It's still bad standard to force the main thread into network I/O operations. What if there's a large latency for the place you're accessing? What if the plugin is large? What if the server (either yours or the one your connecting to) is having slow connection issues?

    Two things to bare in mind: 1) The server freezes while you're doing all of this (I see @Assist ninja'd me on this point) and 2) You're releasing this as a resource. Excuses such as "I'm not downloading a large plugin" are unacceptable. Just because you aren't, doesn't mean others wouldn't want to. You need to consider others needs when trying to release something to them.
     
    Skyost likes this.
  13. Offline

    Gingerbreadman

    @AdamQpzm Yes your correct (I will update the util), but when I was talking about huge files I meant very huge (Over 100mb)

    @Skionz thanks xD

    Now its a thread, and I added a time variable for the reload (needed if plugin is very big)

    EDIT by Timtower: merged posts

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Nov 27, 2017
  14. Offline

    Skionz

    ChipDev likes this.
  15. Online

    timtower Moderator Moderator

    @Gingerbreadman Well, when download is running on the main thread then the server waits, so the reload will also wait till the download finishes.
     
  16. Offline

    Gingerbreadman

    @timtower Its not on a main thread anymore
     
  17. Offline

    AdamQpzm

    @Gingerbreadman Yes it is. Your constructor calls the download method, and you're still instantiating it in the main thread.
     
  18. Offline

    Gingerbreadman

  19. Offline

    xTrollxDudex

    @Gingerbreadman
    You're using the (Thread) constructor? Why not just start DownloadUtil? If the download takes longer than usual, you will have issues with reloading the server.
     
    Skyost and teej107 like this.
  20. Offline

    teej107

    Code:
    if(true == true == true == true == true == false == true == false)
    {
                      
    }
    Redundant redundancy FTW!
     
    xTrollxDudex, Skyost and Skionz like this.
  21. Offline

    Skyost

    @Gingerbreadman Stop being rude ! Your code has some bad practices, this is why @AdamQpzm is trying to correct you.
     
    AdamQpzm likes this.
  22. Offline

    Gingerbreadman

    @Skyost its my personal choice to do if(boolean == false) instead of if(!boolean)

    @xTrollxDudex That's why I added the time variable into the constructor

    @teej107 Redundant?
    Without it, the server will keep downloading the plugin and reloading xD

    <merged by Eyamaz, please use the edit button in the future.>
     
    Last edited by a moderator: Dec 22, 2014
  23. Offline

    teej107

    @Gingerbreadman No not that. boolean == boolean is redundant. boolean == boolean makes another boolean. You could just do boolean or !boolean.
     
  24. Offline

    Gingerbreadman

    @teej107 like I said just a personal choice xD
     
  25. Offline

    RingOfStorms

    If you want your public resources to be taken at all seriously you need to code it to the proper java conventions. I don't want to be terribly rude, but no one cares about your personal choice. If you want to code in your own world then keep it that way, don't release something and then not accept the ridicule it deserves.

    That being said, there is no reason to re-direct every single piece of advice that is being given to you, you should take it and improve the code that you've released for other people to use. When people like you are stubborn and think their way is best and someone else who is still learning reads your code, they too learn the horrible practices that you've learned and it becomes a never ending circle of bad code.
     
  26. Offline

    Gingerbreadman

    @RingOfStorms Its not a horrible practice, is just not necessary
    (Code changed for readability)
     
    Last edited: Dec 22, 2014
  27. Offline

    xTrollxDudex

    @Gingerbreadman
    It doesn't work that way. The download time will vary, the "set" delayed time will never work unless you allow the download to complete before planning anything.
    1. The download can take more time if the server's connection isn't good
    2. I/O time can be affected by server load
    3. URL can be removed, in that case, the download will never finish, and the server reloads for no reason

    There are better ways to do this. First of all, you should implement a timeout, and second, use a latch.

    Timeouts are relatively simple, you can just use a check to System.currentTimeMillis() from an observation thread. The extra thread may be necessary because if you place it inside the loop, your download will encounter slowdown from time check overhead. If it timesout, return from the thread and continue.

    Second, using java.util.concurrent.CountDownLatch with a single permit (or Semaphore with 0 permits, increment and block on take) can be used to check thread continuation. If the operation does not timeout and completes, count down and await for response to reload.
     
    Skyost, Avygeil and AdamQpzm like this.
  28. Offline

    Gingerbreadman

    @xTrollxDudex Thank you for the advice, I will be redoing this util tomorrow when I have the time xD

    EDIT: Of course I knew that the download wont download in the time you present xD
     
    Last edited: Dec 22, 2014
  29. Offline

    ChipDev

    Does this really help?
     
    Gingerbreadman likes this.
  30. Offline

    teej107

    help with what?
     
Thread Status:
Not open for further replies.

Share This Page