ArrayList trouble maybe? {HELP}

Discussion in 'Plugin Development' started by Eller, Jan 23, 2015.

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


    So I have been coding myself some nice kits, and decided to make some cooler ones with their own unique Listener everything works and well but now, for some reason I can only choose the kit ones after I reload and after that I can't, but others without Listeners work perfectly, here is my code:
  2. Offline


    Hmmm, could you give us a little more details? What exactly doesn't work, how did you expect it to work? Could you show us more of your code?
  3. Offline


    @WinX64 Hey there thanks for helping me, When I reload or join the server for the 1st time. I can choose the kit Assassin ( Command /assassin ) then after I die and want to choose the Assassin kit again. It doesn't show me anything of the "You already used a kit this life" ( It doesnt have to do that at all) But it does nothing, also when I add a player to an ArrayList I can't remove them other that Reloading the server Here is some coding you might want to see: The Assassin Ability:
    The Assassin kit:

    And the bottom of my Main class ( Where all the kits are located )

    Hope this helps you so you can help me :)
  4. Offline


    Wait, let me see if i got this one correctly. You choose a kit, die, and then cannot choose it again? And you need to reload in order to use it again?
  5. Offline


    @WinX64 Yup thats correctly
  6. Offline


    Also, please use loops when repeating lots of code because there is no need to be spamming:
    p.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
    When a simple loop can do the same.
  7. Offline


    Okay, I see what you mean I had the same problem on my plugin.

    When you reload/stop your server, the array list gets reset and every player that was in the it before the reload/restart gets forgotten. To fix this you need to store players in a config file instead of in an array list. So when you need to see if a player already has the kit, you check in the config file instead of the the array list.

    Please take a look at the Configuration API to see how to do it if you are not familiar with it.
  8. Offline


    @Synapz Please give me some examples , I'm really confused what to do now :/

    @Synapz But I don't like reading full wiki's isnt there a live chat I can talk about it?
  9. Offline


    Okay, I will give you an example and pinpoint where in the wiki you need to read. Config files maybe difficult at first but once you get the hang of it, it is a great tool to store players data and prevent memory leaks.

    Instead of checking an array list with:
    return true;           
    You would do something like:
    //Check the config file path named Kits.assassins
    return true;
    //Add the player to the config
    getConfig.set("Kits.assassins", player.getName())
    The Kits.assassins part shows the path of where it will store the information.
    For an example, if I added a player to the config file named "Steve" the file would look like this:

    That is the same as storing it inside of an array list, but on reload the config file does not get reset and the players stay in the file.

    Its like writing down a shopping list before you go to the store. While you're shopping you will forget what you needed, so you just check back at your shopping list every time so you don't forget it. It's sort of the same way with Java. On reload the server "forgets" all the players and has nothing to look at to remember, config files store the data so it can check back.

    Also, I do strongly recommend reading the full Configuration API because you will need it sooner or later if you continue plugin development, and you should read it sooner than later.
  10. Offline


    @Synapz But I can't read it..... I mean like I seriously dont get 7/8 of what they say Isnt there rlly an easier way, and If doing the config how would you remove them from the conifg?
  11. Offline


    I tried to explain it as best I could, if you don't understand it still don't be lazy there is plenty of well developed tutorials including the one I just linked you. Most people would just give the link and expect you to figure it out, I tried to give you a push forward in the right direction.

    Also, make sure you registered your listener with your "PlayerDeathEvent", try to add a line in it also saying like player.sendMessage("You died")
    To make sure your plugin is even reading the event. If you see the "You died" on your screen when you died it should remove you from the array list instead of having to reload to remove yourself from the array list. If the code isn't reached when you die, it won't remove the player from the array list which is most likely the problem there.
  12. Offline


    @Synapz It doesnt actually work for the normal kits as I mentioned so there is no problem with that. But I really don't know why it doesn't work any more I might have done wrongly

    <Edited by bwfcwalshy: Keep all conversation on the forums.>
  13. Offline


    @Synapz @WinX64 I'm the most stupidest Idiot in the world. It was exporting wrongly..... I found that out a while ago
    Last edited: Jan 25, 2015
Thread Status:
Not open for further replies.

Share This Page