Give the killer of a player a potion effect

Discussion in 'Plugin Development' started by Doodledew, Jun 24, 2013.

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

    Doodledew

    Hi there! I'm fairly new to bukkit, and Java in general.
    I know this is probably easy, but the part I'm struggeling with is:

    It's only specific players that can do this (get the potion effect on kill)
    In my case it's called berserker. So when a player gets the berserker kit they will be added to the arraylist "berserker"

    So I basicly need so that when a berserker kills a player it will get strenght 3 for 10 seconds and blindness and nursea 1 for 5 seconds.

    And the thing is, that players who doesn't have the berserker kit, shall not be able to get those effects when killing another player.

    Thanks! (was this the wrong section maybe? ._.)
    - Doodle
     
  2. Offline

    SyTeck

    Make an event that registers player kills, and then add the correct effectid to the player.
    If you can't figure it out, I can give you the code, but it's best to try on your own to learn.
     
  3. Offline

    toughenough6

    If you add a listener for the PlayerDeathEvent you can get the event.getKiller() and then check if they're in the array (I'd suggest a HashMap instead), and then I'm pretty sure there's a method to give the player a potion effect, if you call player.givePotionEffect or something like that.

    None of these names are confirmed, this is just off the top of my head but that's the basic logic.
     
  4. Offline

    foodyling

    You'll have to register an Event Listener class, here's some pseudocode:
    Code:
    @EventHandler
    public void onPlayerDeath(PlayerDeathEvent event) {
      Player killer = event.getPlayer().getKiller();
      if (killer != null) {
        killer.addPotionEffect(new PotionEffect(PotionEffectType.STRENGTH, 10, 3));
      }
    }
    I believe you can figure out the rest, for reference, http://wiki.bukkit.org/Event_API_Reference
     
  5. Offline

    chasechocolate

    Adding on to what foodyling said, you will also need to check if your ArrayList contains the event.getPlayer()'s name (hopefully you have an ArrayList<String> rather than ArrayList<Player>, saving player instances can cause memory leaks).
     
  6. Offline

    Doodledew

    Thanks guys! :D
     
Thread Status:
Not open for further replies.

Share This Page