Solved Get the Y level of placed block

Discussion in 'Plugin Development' started by imMrStamper, Apr 22, 2015.

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

    imMrStamper

    in my plugin I'm trying to deny the placement of tnt above Y 40 to prevent grief

    I cant for the life of me get the Altitude check to work. any help?
     
  2. Offline

    Rocoty

    Hey. What have you tried?
     
  3. Offline

    teej107

  4. Offline

    imMrStamper

    Code:
        @EventHandler(priority=EventPriority.HIGH)
          public void onPlayerInteract(BlockPlaceEvent e)
          {
            Block b = e.getBlock();
            Player p = e.getPlayer();
            if ((getConfig().getStringList("belowy40").contains(b.getTypeId() + ":" + b.getData())
                    && b.getY() > 40))
            {
              p.sendMessage("§e[§aBlockHeight§e] §9This Item is only allowed below §eY 40");
              e.setCancelled(true);
     
  5. Offline

    Rocoty

    I dont see anything wrong with that fraction of a method you posted. Would you mind explaining the problem a bit more in detail?
     
  6. Offline

    Agentleader1

    Solution:
    Code:
    Block b = bpe.getBlock();
    if(b.getState().getLocation().getBlockY() >= 40){
      bpe.setCancelled(true);
    }
     
    Last edited: Apr 22, 2015
  7. Offline

    imMrStamper

    its like it doesnt recognize the altitude check at all it doesnt display a message or cancel but if i remove the altitude check it will cancel.


    testing this

    @Agentleader1 blocks all placement

    Code:
        @EventHandler(priority=EventPriority.HIGH)
          public void onPlayerInteract(BlockPlaceEvent e)
          {
            Block b = e.getBlock();
            Player p = e.getPlayer();
            if ((getConfig().getStringList("belowy40").contains(b.getTypeId() + ":" + b.getData())
                    && (b.getState().getLocation().getBlockY() >= 40)))
                
                p.sendMessage("§e[§aBlockHeight§e] §9This Item is only allowed below §eY 40");
                  e.setCancelled(true);
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 12, 2016
  8. Offline

    Agentleader1

    @imMrStamper I'd suggest use:
    Code:
    b.getState().getTypeId() + ":" + b.getState().getData()
    . If that doesn't work, use simple debugging before getting into config with:
    Code:
    if(b.getState().getTypeId() == Whatever the id of tnt is){
        cancel the event;
    }
     
  9. Offline

    imMrStamper

    aha got it thanks everyone for the help
     
  10. Offline

    Agentleader1

  11. Offline

    Konato_K

Thread Status:
Not open for further replies.

Share This Page