Getting EXP Bar

Discussion in 'Plugin Development' started by MyNameIsHariK, Nov 5, 2013.

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

    MyNameIsHariK

    Hey!

    I want to code a plugin for my factions server. Well basically if a player has 1 level of exp I want to set their items with leather armour and a wood sword. How would I do that?

    Thanks for your time,
    Hari
     
  2. Offline

    sd5

    MyNameIsHariK You can get a player's XP level with
    Code:java
    1. player.getLevel()


    The armor can be set by
    Code:java
    1.  
    2. if(player.getLevel() >= 1) {
    3. EntityEquipment equipment = player.getEquipment();
    4. equipment.setBoots(new ItemStack(Material.LEATHER_BOOTS, 1));
    5. equipment.setLeggings(new ItemStack(Material.LEATHER_LEGGINGS, 1));
    6. ...
    7. }


    You can put that in an event or command or whereever :)
     
  3. Offline

    CraftBang

    true what sd5 said but, you're checking if it's equals 1 or higher than 1. He said : has 1 level of exp
    I don't want to hate but just so it won't confuse him.
     
  4. Offline

    MyNameIsHariK

    Dont worry!

    sd5 What kind of event is this?

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

    sd5

    MyNameIsHariK The PlayerExpChangeEvent would be the best, as the name says, it's called every time a player's XP changes.
     
  6. Offline

    MyNameIsHariK

    sd5 How would I make it so when a player dies they keep their EXP bar and they drop 1 level of EXP?
     
  7. Offline

    sd5

    MyNameIsHariK It's simply as that:
    Code:java
    1. @EventHandler
    2. public void onPlayerDeath(PlayerDeathEvent event) {
    3. event.setNewLevel(event.getEntity().getLevel() - 1);
    4. }
     
  8. Offline

    MyNameIsHariK

    sd5 Whats the code for to keep their inventory items like their swords, and armor
     
  9. Offline

    sd5

    MyNameIsHariK Not that easy, you can get the dropped items of a player on his death with the PlayerDeathEvent.getDrops() and then you can add those items to a player's inventory on respawn again
     
  10. Offline

    NathanWolf

    There is also a server setting for that (/gamerule keepInventory true)- unless you want to do something more specific, it seems silly to make your plugin handle that.

    I think you can also technically set this gamerule from your plugin, but that seems like something you should leave up to the server admins to decide!
     
Thread Status:
Not open for further replies.

Share This Page