Solved How to "Handle Reloads"

Discussion in 'Plugin Development' started by Ambamore2000, Dec 23, 2013.

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

    Ambamore2000

  2. Offline

    ThunderWaffeMC

  3. Offline

    Ambamore2000

    @
    Can you paste a code?
     
  4. Offline

    ThunderWaffeMC

    Code:java
    1.  
    2. @Override
    3. public void onEnable() {
    4. //save hashmap here
    5. }
    6.  


    It's in your main class.
     
  5. Offline

    xTrollxDudex

    Ambamore2000
    ..........................................................................................

    I can only hope this is a joke
     
    Garris0n, DrJava and ThunderWaffeMC like this.
  6. Offline

    Ambamore2000

    This is what I got:
    Code:java
    1. @Override
    2. public void onEnable(){
    3. for (Player player : this.getServer().getOnlinePlayers()) {
    4. playerList.put(player, playerData(player));
    5. }
    6. getLogger().info("Enabled!");
    7. }

    Is it like that?
     
  7. Offline

    ThunderWaffeMC

    Yeah... You should learn the Bukkit API before making plugins: http://wiki.bukkit.org/Plugin_Tutorial
     
  8. Offline

    Ambamore2000

  9. Offline

    ThunderWaffeMC

    But if you had read the tutorial you would have learned about onEnable() and onDisable(). Every plugin needs to have it.
     
  10. Offline

    Ambamore2000

    Also, the problem is, this happened: [​IMG]

    That was the thing I didn't understand. Am I supposed to do something there, or...?

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

    CeramicTitan

    I am a bit confused. It is worried about losing data from a hasmap on reload, so the solution is to store the data into another hashmap?!?! What?

    Oh I understand. The onDisable and on enable methods are run on reload.therefore addinh the appropriate data when the server starts up.
     
  12. Offline

    Ambamore2000

  13. Offline

    CeramicTitan

    Ambamore2000 correct, but if the person doesnt know enough, how do they make the plugin their own way?
     
  14. Offline

    Ambamore2000

  15. Offline

    ThunderWaffeMC

    Ambamore2000 You really have to learn Java. You don't even know how to use imports?
     
  16. Offline

    CeramicTitan

    Ambamore2000 that code is example code and won't actually do what you want.The onDisable and on enable methods are run on reload.therefore adding the appropriate data when the server starts up. The tutorial is merely saying, add your keys and values onEnable as a way to handle reloads and you don't lose your data. Note caches clear on server shutdown.
     
  17. Offline

    Ambamore2000

    ThunderWaffeMC
    I do, but then after that, there are other "errors", so I will just post the code with the errors fixed with the FIRST suggested thing (I am still a beginner in java)

    Code:java
    1. package me.Ambamore2000.Plugin;
    2.  
    3. import org.bukkit.entity.Player;
    4. import org.bukkit.plugin.java.JavaPlugin;
    5.  
    6. public final class Plugin extends JavaPlugin {
    7.  
    8. @Override
    9. public void onEnable(){
    10. getLogger().info("Enabled!");
    11. for (Player player : this.getServer().getOnlinePlayers()) {
    12. Object playerList;
    13. ((Object) playerList).put(player, playerData(player));
    14. }
    15. }
    16.  
    17. private Object playerData(Player player) {
    18. return null;
    19. }
    20.  
    21. @Override
    22. public void onDisable() {
    23. getLogger().info("Disabled!");
    24. }
    25. }
     
  18. Offline

    mrkirby153

    Ambamore2000

    You can have eclipse import your stuff for you by pressing ctrl/cmd + Shift + O. That organized your imports and fixes those errors. Also what are those errors?
     
  19. Offline

    CeramicTitan

    Ambamore2000 please read my comment. It will save you a lot of time and embarrassment.
     
  20. Offline

    Ambamore2000

    mrkirby153
    In playerList.put(player, playerData(player)); The underlined stuff are the "errors".

    __Does anybody have skype, so we can share screen? (I can't talk/hear on my mic)
     
  21. Offline

    mrkirby153

    Ambamore2000

    What does it say when you mouse over the errors? (I take it's your first time taking Eclipse for a spin?)
     
  22. Offline

    CeramicTitan

    Did you see his code? It doesnt make sense... You might be able to fix his code but it won't work.

    Ambamore2000

    If you would just read my comment, you would realise upu are wasting your time.http://forums.bukkit.org/threads/how-to-handle-reloads.210097/#post-2111420
     
  23. Offline

    mrkirby153

  24. Offline

    Ambamore2000

    mrkirby153
    You got skype? Can you add me if you do? --Ambamore is my skype.
     
  25. Offline

    mrkirby153

    Ambamore2000

    Have Skype don't want to use it. It's perfectly fine posting your problems here so people in the future who have the same problem may use it as reference
     
  26. Offline

    Ambamore2000

    mrkirby153
    But, I need to find a way to communicate with you instead of the forums, because I really want to make a plugin (for a server)
     
  27. Offline

    mrkirby153

    Ambamore2000

    Forums. You can post your stuff on the forums. That way you can get more than just me to help. You think you have it bad? You should try writing example code on an iPhone :p
     
  28. Offline

    Ambamore2000

    mrkirby153
    Please? I've been begging people so much now. You're like the 10th person.
     
  29. Offline

    CeramicTitan

    Ambamore2000

    Lmao, I gave you the asnwer, however you chose to ignore my posts
     
  30. Offline

    Ambamore2000

    CeramicTitan
    I don't understand what you are saying.

    CeramicTitan
    I don't get it.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 5, 2016
Thread Status:
Not open for further replies.

Share This Page