Portal Help

Discussion in 'Plugin Development' started by dsdevil, Mar 15, 2015.

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

    dsdevil

    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);
    
        }
     
  2. maybe wsp doesn't contains the player?
     
  3. Offline

    dsdevil

    @FisheyLP It does since other blocks work just not the portal blocks
     
  4. I know why: The portal block dissappears when it gets updated. Try to cancel the BlockPhysicsEvent if the block is portal
     
  5. Offline

    Zombie_Striker

    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.
     
  6. Offline

    dsdevil

    @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.
     
    Last edited by a moderator: Jun 13, 2016
  7. @dsdevil or just
    Code:java
    1. @EventHandler
    2. public void onBlockChange(BlockPhysicsEvent e) {
    3. if (!e.isCancelled() && e.getBlock().getType() == Material.PORTAL && e.getChangedType() == Material.PORTAL)
    4. e.setCanceclled(true);
    5. }
    :p
     
Thread Status:
Not open for further replies.

Share This Page