Hey, I need help with doing..

Discussion in 'Spigot Plugin Development' started by NaJated, May 27, 2015.

  1. Hey, I need help with adding EXP to people.

    I have tried this :
    Code (Text):
            if (e.getEntity() instanceof Zombie || e.getEntity() instanceof Skeleton || e.getEntity() instanceof Spider || e.getEntity() instanceof CaveSpider) {
                e.setDroppedExp(0);
                e.getDrops().clear();
                Player p = e.getEntity().getKiller();
                switch (e.getEntity().getKiller().getLevel()) {
                case 0:
                case 1:
                    e.getEntity().getKiller().setExp((float) (e.getEntity().getKiller().getExp() + 0.2));
                    break;
                default:
                    break;
                }
            }
     
    But I got a weird bug ( https://imgur.com/arcRmDu )

    and then I tried
    Code (Text):
    if (e.getEntity() instanceof Zombie || e.getEntity() instanceof Skeleton || e.getEntity() instanceof Spider || e.getEntity() instanceof CaveSpider) {
        e.setDroppedExp(0);
        e.getDrops().clear();
        Player p = e.getEntity().getKiller();
        switch (e.getEntity().getKiller().getLevel()) {
        case 0:
        case 1:
            if (e.getEntity().getKiller().getExpToLevel() <= 0) {
                e.getEntity().getKiller().setLevel(p.getLevel() + 1);
            }else{
                e.getEntity().getKiller().setExp((float) (e.getEntity().getKiller().getExp() + 0.2));
                break;
            }
        default:
            break;
        }
    }
    to try to counteract this bug but it doesn't work. Thanks!
     
  2. See #setExp() is a float between 0 and 1, which controls the bar. After 1 you should do #setLevel(player#getLevel()+1) and reset their exp. Exp is the bar itself, and level is responsible for the numbers.

    So if you do over 1 you will get a funny result.