Hey guys i need some help basically im trying to make it so when a player clicks the nether star on the ground 2 portals will be placed ontop of each other but for some reason its not working , it works with other blocks just not portals. Here is my code Code: @EventHandler public void onCreatePortal(PlayerInteractEvent e) { Player p = e.getPlayer(); if (wsp.containsKey(p.getName())) return; if (e.getAction() == Action.LEFT_CLICK_BLOCK) { if (p.getItemInHand().getType() == Material.NETHER_STAR) { Block clik = e.getClickedBlock(); if (clik.getLocation().add(0, 1, 0).getBlock().getType() == Material.AIR) clik.getLocation().add(0, 1, 0).getBlock() .setType(Material.PORTAL); else return; if (clik.getLocation().add(0, 2, 0).getBlock().getType() == Material.AIR) clik.getLocation().add(0, 2, 0).getBlock() .setType(Material.PORTAL); }
I know why: The portal block dissappears when it gets updated. Try to cancel the BlockPhysicsEvent if the block is portal
Did you debug? Does your event fire? And @FisheyLP , Canceling that event could break normal nether portals. A better idea would be to surround the nether Portal with obsidian, making a smaller portal.
@Zombie_Striker It does fire since it works with other blocks, like i changed portal to stone and it worked but i think its breaking when another portal block is placed over it @FisheyLP im going to try canceling the event to see if it works i was looking around in bukkit looking for help and i found this " When creating multiple portals via /setblock x y z portal that are placed adjacent to each other, they get removed. (probably because they act like a BUD and get removed if they aren't connected to obsidian) Wouldn't this also apply to portals being placed by a Bukkit plugin?" @FisheyLP Thanks dude! your method worked For people that want to fix their portals here is what i used Code: @EventHandler public void onBlockPhysics(BlockPhysicsEvent event) { if (event.isCancelled()) { return; } if (event.getBlock().getType() == Material.PORTAL) { event.setCancelled(true); } if (event.getChangedType() == Material.PORTAL) { event.setCancelled(true); } } } EDIT by Moderator: merged posts, please use the edit button instead of double posting.
@dsdevil or just Code:java @EventHandlerpublic void onBlockChange(BlockPhysicsEvent e) {if (!e.isCancelled() && e.getBlock().getType() == Material.PORTAL && e.getChangedType() == Material.PORTAL)e.setCanceclled(true);}