LightLevel not working?

Discussion in 'Plugin Development' started by damo1995, Feb 26, 2012.

Thread Status:
Not open for further replies.
  1. Hello all,

    Im trying to make a plugin that stops the stock bonemeal on grass in the dark plugin by checking the light level of the block the event takes place on.

    my problem is for some reason its not detecting the light level correctley and allways says its below 1 even when in direct sunlight uncovered.

    Heres the script
    Code:
    package me.damo1995.NLGE;
    
    import org.bukkit.block.Block;
    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;
    import org.bukkit.inventory.ItemStack;
    
    public class nlgePlayerListener implements Listener {
    
        @EventHandler
        public void onPlayerInteract(PlayerInteractEvent e){
            Player player = e.getPlayer();
            Block block = e.getClickedBlock();
            ItemStack holding = player.getItemInHand();
            if(e.isCancelled()){ return; }
            if(e.getAction() == Action.RIGHT_CLICK_BLOCK && holding.getType() == org.bukkit.Material.INK_SACK && holding.getDurability() == 15){
                if(block.getLightLevel() < 1){
                    e.setCancelled(true);
                    player.sendMessage("Debug: Light Level Lower then 3, Event Cancled");
                }
                else if (block.getLightLevel() > 1){ 
                    player.sendMessage("Debug: Light level greater then 3, Event continue.");
                    return;
                
                }
                
            }
        }
    
    }
    
    Does anybody know how i can get this to work correctley?

    Thanks
    Damo.
     
  2. Offline

    TopGear93

    Code:
            if(e.getAction() == Action.RIGHT_CLICK_BLOCK && holding.getType() == Material.INK_SACK && holding.getDurability() == 15){
                if(block.getLightLevel() < 1){
                    player.sendMessage("Debug: Light Level Lower then 3, Event Cancled");
                    e.setCancelled(true);
                }else{
    if (block.getLightLevel() > 1){
                    player.sendMessage("Debug: Light level greater then 3, Event continue.");
                    return;
                }
            }
        }
    }
     
  3. Just changing the material type isent going to help, as org.bukkit.Material is just the same as material.materialname
    Just using the class file, But thank you for the start of your help.

    As for the code still does the same, says its less then 3 allthough it should be 1 even when in direct sunlight
     
  4. Offline

    Muddr

    after some testing.. try getting the block above the one you click on.

    Block block = e.getClickedBlock().getRelative(BlockFace.UP);
     
  5. Thanks alot dude!
     
Thread Status:
Not open for further replies.

Share This Page