Not Sure why this isnt working

Discussion in 'Plugin Development' started by xCyclonez, Jul 27, 2017.

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

    xCyclonez

    Code:
    @EventHandler
        public void onPlace(BlockPlaceEvent event) {
            Player p = event.getPlayer();
            Block b = event.getBlockPlaced();
          
            if(b.getType() == Material.IRON_PLATE) {
                if(b.getRelative(BlockFace.DOWN, 1).getType().equals(Material.DIAMOND_BLOCK)) {
                    event.setCancelled(true);
                }
                if(b.getRelative(BlockFace.DOWN, 1).getType().equals(Material.EMERALD_BLOCK)) {
                    event.setCancelled(true);
                }
                if(b.getRelative(BlockFace.DOWN, 1).getType().equals(Material.GOLD_BLOCK)) {
                    event.setCancelled(true);
                }
                if(b.getRelative(BlockFace.DOWN, 1).getType().equals(Material.IRON_BLOCK)) {
                    event.setCancelled(true);
                }
                if(b.getRelative(BlockFace.DOWN, 1).getType().equals(Material.REDSTONE_BLOCK)) {
                    event.setCancelled(true);
                }
                if(b.getRelative(BlockFace.DOWN, 1).getType().equals(Material.COBBLESTONE)) {
                    event.setCancelled(true);
                }
                if(b.getRelative(BlockFace.DOWN, 1).getType().equals(Material.COAL_BLOCK)) {
                    event.setCancelled(true);
                }
                if(b.getRelative(BlockFace.DOWN, 1).getType().equals(Material.PRISMARINE)) {
                    event.setCancelled(true);
                }
            }
     
    Last edited by a moderator: Jul 27, 2017
  2. Offline

    krizzdawg

    More detail please... What are you trying to do? What isn't working?
     
  3. Offline

    xCyclonez

  4. Offline

    Zombie_Striker

    @xCyclonez
    1. Use == for enums.
    2. Are you sure the block below "b" are one of the above?
    3. Instead of doing all these if checks, just create an list of all the materials. Then, in one if statement check if the block's type is inside that list. That should reduce 15+ lines.
    4. Are you sure b is an iron plate? Have you debugged?
     
  5. Offline

    xCyclonez

    Well, I'm pretty sure because in order to run the code, b has to equal an iron plate\
    @Zombie_Striker when the player tries to place the plate on top of one of the blocks it should cancel


    *EDIT*

    The == fixed the problem. Thanks!
     
    Last edited: Jul 27, 2017
  6. Offline

    Machine Maker

    Please mark this thread as Solved if your issue has been resolved.
     
Thread Status:
Not open for further replies.

Share This Page