Solved Am I using getTotalExperience() or getExpToLevel() right?

Discussion in 'Plugin Development' started by GlacialCreeper, Dec 14, 2014.

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


    I've made a Totems plugin for my private server, and the way it works, is that you can code your own totems (example below).

    Now, I use a PlayerInteractEvent to check for the flint and steel activation. I make it check what blocks are there, and if all goes well, it calls a custom TotemIgniteEvent which takes a player, a location, and a subclass of Totem; in which it'll call certain methods. The Diamond totem (shown above) will turn the glass into a chest, and have some stuff inside, and it should remove the blocks under it.

    Here's the main class:
    package me.camo.totems;
    import me.camo.totems.event.TotemIgniteEvent;
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.World;
    import org.bukkit.block.Block;
    import org.bukkit.block.BlockFace;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.player.PlayerInteractEvent;
    public class TotemMainClass extends JavaPlugin implements Listener {
        public void onEnable(){
            getServer().getPluginManager().registerEvents(this, this);
        public void onPlayerInteract(PlayerInteractEvent event){
            Player player = event.getPlayer();
            World world = player.getWorld();
            if ((event.getAction() == Action.RIGHT_CLICK_BLOCK) && (player.getItemInHand().getType() == Material.FLINT_AND_STEEL)){
                Block block1 = event.getClickedBlock();
                if ((block1.getType() == Material.IRON_BLOCK)
                        && (world.getBlockAt(block1.getX(), block1.getY()-1, block1.getZ()).getType() == Material.GOLD_BLOCK)
                         && (world.getBlockAt(block1.getX(), block1.getY()-2, block1.getZ()).getType() == Material.COAL_BLOCK)
                        && (block1.getRelative(BlockFace.UP).getType() == Material.GLASS)) {
                    if (player.getTotalExperience() >= 2)
                        getServer().getPluginManager().callEvent(new TotemIgniteEvent(player, block1.getLocation(), new TotemDiamonds(this)));
                        player.sendMessage(ChatColor.RED+"You need to be at experience level 2 or greater to activate the "+ChatColor.AQUA+"Diamond Totem!");
    The thing is, everything's fine (the event executes and the chest appears), but it seems to ignore the check on whether the player's experience level is at least 2. I've tried getExpToLevel() too, but I get the same results--it should be executing the else statement since I have less than a level; it calls the event no matter what.

    So how can I solve this? I'd guess that I have enough experience but I google'd a bit and those two methods return your experience in levels.
  2. Offline


    You want player.getLevel().
  3. Offline


    @adam753 *facepalm* wow, I never saw the method..Thanks a bunch! It executes the else correctly now. Now I've gotta fix the blocks not being removed. Could you or anyone else see whats wrong? My code is in this repo.
    And to not sound like I'm trying to be spoonfed, I have looked it over.
  4. Offline


    Well, TotemDiamonds' destroyBlocks() seems fine, so maybe you're not calling it correctly? (I can't see where you're calling it at all.)
  5. Offline


    It's called in the TotemIgniteEvent constructor, which takes a Totem parameter. Also, ignore some classes like TotemType and TotemListener, those aren't being used atm.
    EDIT: ...I'm sorry, I just realized i never put it there. :eek:

    @adam753 Well thanks! I can't test the blocks right now, but I'm sure it'll work! :)

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

Share This Page