Error 1 kit per life

Discussion in 'Plugin Development' started by deathplayes, Feb 15, 2014.

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

    deathplayes

    I tried using 1 kit for life and is not working.

    I just put in my main class:
    Code:
    ArrayList<Player> kit = new ArrayList<Player>();
    Within the class kits I put like this:
    Code:
     if (this.plugin.kit.contains(player))
                      {
                        player.sendMessage("§a[§cMultiKits§a] §eUse apenas 1 kit por vida !");
                        return true;
                      }
                      this.plugin.kit.add(player);
    This was the event that I put to when the player dies:
    Code:
            @EventHandler
            public void onPlayerDeath(PlayerDeathEvent event)
            {
              Player player = event.getEntity();
              if (this.plugin.kit.contains(player)) {
                this.plugin.kit.remove(player);
              }
              this.plugin.kit.remove(player);
            }
    Because giving this error?
    Sorry for my bad english
     
  2. Offline

    DogeDev

    Just make an array list:
    Code:java
    1. ArrayList<Player> alreadyUsed = new ArrayList<Player>();

    When they try to use the kit, check if it contains them:
    Code:java
    1. if(alreadyUsed.contains(player)) {
    2. }

    Then if the player uses the kit, add them:
    Code:java
    1. alreadyUsed.add(player);

    And when they die, remove them:
    Code:java
    1. alreadyUsed.remove(player);
     
  3. Offline

    Jaker232

    NEVER EVER STORE PLAYER IN ANY SORT OF INSTANCE.

    This will cause memory leaks. Rather than using the Player object, store the String that is the player's name.
     
  4. Offline

    DogeDev

    Jaker232 Really? Hm, time to change some stuff up on shotbow ;) Thanks.
     
Thread Status:
Not open for further replies.

Share This Page