Adding two ints not doing anything

So the problem is, when I say ovrxp = ovrxp + xp, it never stacks and just resets every kill. A fix to this and an explanation to why this doesn't work would be much appreciated.

@EventHandler
public void onDeath(EntityDeathEvent e) {

    Player player = (Player) e.getEntity().getKiller();
    Skeleton s = (Skeleton) e.getEntity();

    int ovrlvl = 1;
    int ovrxp = 0;

    Random random = new Random();
    int xp = random.nextInt(30) + 21;

    if (ovrlvl == 1 && ovrxp >= 200) {
        player.sendMessage(ChatColor.GREEN + "You are now level two!");
        player.playSound(player.getLocation(), Sound.LEVEL_UP, 1.0F, 0.0F);
        ovrlvl = 2;
    }
    if (ovrlvl == 2 && ovrxp >= 400) {
        player.sendMessage(ChatColor.GREEN + "You are now level three!");
        player.playSound(player.getLocation(), Sound.LEVEL_UP, 1.0F, 0.0F);
        ovrlvl = 3;
    }

    ovrxp = ovrxp + xp;

    if (s.getCustomName() == "Undead Recruit") {
        if (ovrlvl == 1) {
            player.sendMessage(ChatColor.GREEN + "" + ovrxp + "/200");
        }
        if (ovrlvl == 2) {
            player.sendMessage(ChatColor.GREEN + "" + ovrxp + "/400");
        }
    }
}
}
Jon Skeet
people
quotationmark

You've declared ovrxp as a local variable - it's initialized each time onDeath is called.

If you want the value to persist between multiple calls to the method, you'll need to make the variable a field (part of the object itself). Assuming the method is always called on the same object, and on the same thread, just making it an instance field should be fine.

people

See more on this question at Stackoverflow