How to set something off if a player has a certain level

Discussion in 'Plugin Development' started by LordFox, May 29, 2014.

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

    LordFox

    ok so im coding a minigame ish thing. But i dont understand how to have the if to set off that. I already have one of which checks the entity to make sure its human.
    Code:java
    1. @EventHandler
    2. public void onDeath(PlayerDeathEvent d){
    3.  
    4. if(d.getEntity().equals(EntityType.PLAYER)){
    5.  
    6. Player a = (Player)d.getEntity();
    7. Player b = (Player)d.getEntity().getKiller();
    8.  
    9.  
    10. }
    11. }
    12. }

    this is what i have atm, im not event sure if i need the player a and b aswell

    bump

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jul 1, 2016
  2. Offline

    Monkey_Swag

    Fix up some stuff. First of all I would make it (PlayerDeathEvent e) but if you want to keep it as d, that's fine. First, do the check like this:
    if(e.getEntity() instanceof Player)
    Now when you cast your players do: Player p = (Player) e.getEntity();
    Player killer = (Player) p.getKiller();

    I just think that labeling things like this will make everything much easier for you. Now, when you say 'level' what do you mean? Like how much xp they have or what? Remember to tag me aswell :)
     
  3. Offline

    LordFox

    @Monkey_Swag I mean like their whole exp levels like in their number, I want it to check the the killer of the player each time someone dies, and when it returns true other stuff happens
     
  4. Offline

    Monkey_Swag

    LordFox ok, just wondering, is there any specific way the killer would get xp in your minigame?
     
  5. Offline

    LordFox

    this is the other class
    Code:java
    1. @EventHandler
    2. public void onDeath(PlayerDeathEvent d){
    3.  
    4. if(d.getEntity().equals(EntityType.PLAYER)){// the problem was here!
    5.  
    6. Player a = (Player)d.getEntity();
    7. Player b = (Player)d.getEntity().getKiller();
    8.  
    9. d.setDeathMessage(ChatColor.BLUE + a.getName() + ChatColor.BLUE + " Was Cut Down By " + ChatColor.BLUE + b.getName() + ChatColor.BLUE +" with " + ChatColor.BLUE + b.getItemInHand());
    10. b.setLevel(b.getLevel() + 1);
    11.  
    12.  
    13. }
    14.  
    15. }
    16.  

    not sure if i should combine the classes and do it D: @Monkey_Swag
     
  6. Offline

    Plo124

    LordFox
    I would recommend checking if .getKiller() != null first, because it would return null if the player wasnt killed.

    To get the exp LEVEL of the player, its player.getLevel()
     
    Monkey_Swag likes this.
  7. Offline

    LordFox

    ik that but how do i get that to check inside a death event if the player has a certain exp level, and i dont know how to make it do certain things when that returns true...........boolean?\
    @Plo124
    @Monkey_Swag

    nvm that was a derp idea

    bump

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

Share This Page