@Clybzotik You need to check the material type of the Block. Either do a switch case or a bunch of if checks to find out which door the block is. Note that the material type does not store for whether it is the top block or bottom block, in case you were looking for that (you would need to get the block's state for that)
PHP: @EventHandler public void click(PlayerInteractEvent pie) { Player p = pie.getPlayer(); Action a = pie.getAction(); Block b = pie.getClickedBlock(); if(a != Action.RIGHT_CLICK_BLOCK) return; if((b.getType().equals(Material.ACACIA_DOOR) || (b.getType().equals(Material.BIRCH_DOOR)) || (b.getType().equals(Material.DARK_OAK_DOOR)) || (b.getType().equals(Material.IRON_DOOR)) || (b.getType().equals(Material.JUNGLE_DOOR)) || (b.getType().equals(Material.SPRUCE_DOOR)) || (b.getType().equals(Material.WOODEN_DOOR)))){ if((b.getState() instanceof Door)) { Door d = (Door) b; d.setOpen(true); } } } Im added this if-s, but doors don`t open and any errors on a Console
@Clybzotik You should have variables with one character names. It will make reading the code and adding onto the code later more confusing than it needs to be. Use == when comparing enum values (i.e when comparing Material types) If you don't need to check for specific types, just check if the block has a BlockState and if the state is an instanceof Door. This will mean you won't need to check the material type.
@Zombie_Striker PHP: if(block.getState() == null) return; if((block.getState() instanceof Door)) { Door d = (Door) block; d.setOpen(true); } Im added this check, and delete check of the material type, its true? (Sorry for my English)
@Clybzotik The only issue is the "d". You're checking if the state is equal to the door in the first line (which is correct), but then you are casting the block, not the state, to a Door. You need to cast the block's state to a door.
@Zombie_Striker PHP: if(!(pie.getAction() == Action.RIGHT_CLICK_BLOCK)) return; Block block = pie.getClickedBlock(); if(block.getState() == null) return; if((block.getState() instanceof Door)) { Door d = (Door) block.getState(); d.setOpen(d.isOpen()); } } I did what you said but the door does not open
It is not opening because you set the door state to 'closed' due d.isOpen() returns false when its closed. So change that to true like d.setOpen(true); to make it open and d.setOpen(false) to close it.
@Clybzotik By setting the state equal to whether the door is open, you are not changing anything. If the door is open (isOpen==true), then you are setting it so the door stays open (since it would be the same as setOpen(true)). If it is closes, isOpen==false, so you would be setting it so it stays closed (setOpen(false)). What you want to do is Invert the boolean. Use d.setOpen( ! d.isOpen) to invert the boolean ( The ! symbol turns true values to false, and false to true.)
Here's my code, what I doing wrong? PHP: @EventHandler public void click(PlayerInteractEvent pie) { if(!(pie.getAction() == Action.RIGHT_CLICK_BLOCK)) return; Block block = pie.getClickedBlock(); if(block.getState() == null) return; if((block.getState() instanceof Door)) { Door d = (Door) block.getState(); d.setOpen(!d.isOpen()); } } When I click on the iron door nothing happens.
@Clybzotik Try sending a player a message if the state is an instanceof door. Also try sending a message if the state is null. Doing this will show the following: If you only see the message when the state is null, then you know that iron doors somehow don't have states. If you only see the door message, you know that setOpen method does not work, and you may need to report the problem to spigot/update your server. If you don't see any messages, that means the state is not a door, but the state exists, and you will need to check what the state is actually an instanceof (do this by sending a player a message, but use the state.toString() to see what it is)