Dropping XP

Discussion in 'Plugin Development' started by Mr Washington, Jun 18, 2012.

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

    Mr Washington

    Hello Users,

    I am currently making an Item Donation plugin for my public server that allows users to send items to a configurable drop warp of which they can also drop XP. I can not for the life of me figure out how to drop XP at a given point and would like to know if it is possible and if so, how.

    Thanks Guys :)
     
  2. Offline

    r0306

    Mr Washington
    Well, this is what I would do inside a command executor when they type something like /drop <number of exp>.
    Code:
    public void dropExp(Player player, Integer amt) {
    float totalExp = 1.75 * Math.pow((float) player.getLevel(), 2) + 5.00 * (float) player.getLevel() + player.getExp();
    if (totalExp >= (float) amt) {
    ((ExperienceOrb)world.spawn(player.getLocation().add(1,0,0), ExperienceOrb.class)).setExperience( amt );
    bool check = true;
    float amtLeft = (float) amt;
    for (int i = player.getLevel(); bool check = true && i > -1; i -- ) {
    float remainingExp = 3.5 * (float) (i-1) + 6.75;
    float amtLevel = ((float) amtLeft - 6.75)/3.75;
    if (amtLevel >= 1 && i != 0) {
    player.setLevel(i - 1);
    amtLeft = amtLeft - remainingExp;
    } else {
    if (player.getExp() >= amtLeft()) {
    player.setExp(player.getExp() - (int) amtLeft);
    check == false;
    }
    }
    }
    I'm really sleepy and I've never tested this code out yet so I can't guarantee it to work.
     
    waremanu likes this.
  3. Offline

    Mr Washington

    Ill check it out shortly. Thank you!
     
Thread Status:
Not open for further replies.

Share This Page