How to add players to ArrayList

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

Thread Status:
Not open for further replies.
  1. Hey Guys, I got a problem here and I would like to fix it.
    I want to make my Assassin kit so that only people who do /assassin
    Will get the kit + the ability to right click the suagr and apple to gain benefits.
    I used an ArrayList for this but it is not seeming to work here are my codes:
    Assassin Kit:
    http://pastebin.com/8cDVe2w7
    Assassin Ability:
    http://pastebin.com/8yfi7TUv
    My kits arraylist:
    http://pastebin.com/qwkc4rhR

    Please tell me what I have done wrong and how I should do it.

    ----------------------------------------------------------

    I now got this:

    Assassin Ability:
    http://pastebin.com/m8hebXez

    Assassin Kit:
    http://pastebin.com/fUwXLHi8

    Kits:
    http://gyazo.com/607a85fa7a9e1e3c18c84fff47c3da64
     
    Last edited: Jan 23, 2015
  2. 1) You get any error ?
    Code:java
    1.  
    2. //If you gonna store a player use his UUID instead of using the player
    3. ArrayList<UUID> players = new ArrayList<UUID>();
    4. //Wih this we can add the player to the arraylist
    5. players.add(player.getUniqueId());
    6. //This method is not the best but should work
    7.  

    2)You can create a whole class for this, where you store player profession, etc...
     
  3. Offline

    mythbusterma

    @Eller

    Why is everything static and public? Learn to use instances and stop abusing the static keyword.
    The Java™ Tutorials

    Also, learn to use for-loops and iteration. Debug your code and post results.
     
  4. @mythbusterma
    It keeps telling me to do so, and on tutorials it worked like that but for me it doesn't
    I can follow java tutorials but I don't know if that will help me that much related to Minecraft I'll try it after this is solved and if its not solved ill do it later

    Didn't help anything I'm sorry It keeps telling me add public and add static so I don't know..

    @MaTaMoR_

    It didn't help anything I don't know why

    I now got this:

    Assassin Ability:
    http://pastebin.com/m8hebXez

    Assassin Kit:
    http://pastebin.com/fUwXLHi8

    Kits:
    http://gyazo.com/607a85fa7a9e1e3c18c84fff47c3da64

    EDIT by Timtower: merged posts
     
    Last edited by a moderator: Jan 23, 2015
  5. Offline

    mythbusterma

    @Eller

    You still didn't try debuging it yet. Also, Eclipse provides suggestions that make sense to a computer, not suggestions on program design. That's not it's purpose.
     
  6. @mythbusterma

    I'm not sure how to do that , or do u mean Break points.
    I'm learning Java coding atm now
     
    Last edited: Jan 23, 2015
  7. Online

    timtower Administrator Administrator Moderator

    @Eller Please stop double posting. Use the edit button instead if you want to add information.
     
  8. Offline

    mythbusterma

    @Eller

    I mean add debug statements.
     
  9. @mythbusterma

    I'm not sure how to do that , or do u mean Break points.
    I'm learning Java coding atm now
     
  10. Offline

    TGRHavoc

    @Eller
    The best advice I can give you at the minute is, learn Java and then come back to learning the Bukkit API. It's much more helpful as Bukkit plugins are coded in Java. Learning Java will also allow you to take others suggestions on board including removing your static keywords.

    As for the debug statements @mythbusterma is talking about, add statements that print the values of certain variables so that you can check that they are the correct value.
    Also, in your original post you included an image (http://gyazo.com/607a85fa7a9e1e3c18c84fff47c3da64) from this image I can see that your method "removeKits(PlayerDeathEvent)" isn't going to work. You're telling the Lists to store the users UUID (Player#getUniqueId()) and then you're checking/removing strings (Player#getName())..
     
    Last edited: Jan 23, 2015
    mine-care likes this.
  11. Offline

    CrownedComedian

  12. @CrownedComedian @TGRHavoc @mythbusterma @MaTaMoR_ I have figured it out now, I tried some things I thought it would be a good idea and i fixed it. So I do have another question and it is probably really simple but
    It goes about a healing wand, I want it to give a person full health over 2/3 secs and its a like a splash potion so that you can heal others aswell. This is that I have http://pastebin.com/8xte476Q .
    And I'm wanting to make the Regeneration potion to be giving you Regen 10 or something for 2/3 seconds, is that possible?
     
  13. Offline

    CrownedComedian

    Hmmm. I've been looking into your code. Have you tried using a HashMap<> with playernames(or UUID) of type String as the keys and an ArrayList<> of type String for the values. This will allow you to add kit names to a player's values. When a player performs a command to use that kit, add the kit name to the sender's(in this case the Player's) values. Once a player dies, remove their values.
     
  14. Offline

    TGRHavoc

    @CrownedComedian
    What you're suggesting is to create two Lists to store the players' details and their kit separately? Why not just use a Map to store both key and value together?

    You could just make the method you created a whole lot simpler using the LivingEntity#addPotionEffect() method that takes a PotionEffect as an argument.
     
  15. I just want that the players that are being hit bij the ThrownPotion.class get Regeneration 10 for 2/3 secs
     
  16. Offline

    TGRHavoc

    But, wouldn't using a splash potion also heal the attacker? This seems counter productive. The method I linked you will only be applied to the player that you use it on meaning, that third parties won't also get the effect of the potion.
     
  17. @TGRHavoc
    I know but thats just how it works It's KitPvP there are no teams etc. I dont want to type in /ally ellerqueen and they cant hit each other anymore. I just want the regen 10 splash potion for 2/3 secs long and everyone in range will get the benefits of it ( I also have that soups can heal)
     
    Last edited: Jan 23, 2015
  18. Offline

    mine-care

    @Eller
    A note about your code.... even if its offtopic,
    Code:
                    p.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
                    p.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
                    p.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
                    p.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
                    p.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
                    p.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
                    p.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
                    p.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
                    p.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
                    p.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
                    p.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
                    p.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
                    p.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
                    p.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
                    p.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
                    p.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
                    p.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
                    p.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
                    p.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
                    p.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
                    p.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
                    p.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
                    p.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
                    p.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
                    p.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
                    p.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
                    p.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
                    p.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
                    p.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
                    p.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
                    p.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
                    p.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
                    p.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
                    p.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
                    p.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
                    p.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
                    p.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
    How about
    Code:
    for(int i=0; i<38; i++){
      p.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
    }
    =)
     
    Shortninja66 likes this.
  19. Offline

    1Rogue

    If we're going to be efficient (and future-proofed):

    Code:java
    1. List<ItemStack> notAdded = new ArrayList<>();
    2. ItemStack add = new ItemStack(Material.MUSHROOM_SOUP);
    3. for (int i = 0; i < 38; i++) {
    4. notAdded.addAll(p.getInventory().addItem(add).values());
    5. }
    6. //drop items that could not be added
    7. for (ItemStack i : notAdded) {
    8. p.getWorld().dropItemNaturally(p.getLocation(), i);
    9. }
     
  20. @mine-care
    (Rofl) Thanks you =)
     
  21. Offline

    mine-care

    @1Rogue True, i pointed out the big chunk :p
     
Thread Status:
Not open for further replies.

Share This Page