Solved portal blocks how to handle this correctly?

Discussion in 'Plugin Development' started by xize, Apr 23, 2014.

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

    xize

    Hello,

    so I'm trying to make custom portals and it sort of works, but when a player doesn't look to the portal blocks or isn't fully inside the portal blocks itself the player will be teleported to the nether rather than I want to let the player teleport on a other location in the world.

    i've already tried to use getEyeLocation() and it works a bit better but still it isn't enough.

    my event is:
    Code:
         @EventHandler
        public void onEnter(PlayerPortalEvent e) {
            if(e.isCancelled()) {
                return;
            }
            
            e.setCancelled(true);
            
            Block block = e.getFrom().getBlock();
            System.out.print("detected player in portal");
            for(Portal portal : Configuration.getPortalConfig().getPortals().values()) {
                List<Block> blocks = Arrays.asList(portal.getInnerBlocks());
                if(blocks.contains(block)) {
                    System.out.print("detected player in custom portal");
                    e.useTravelAgent(false);
                    if(portal.isLinked()) {
                        Portal linked = portal.getLinkedPortal();
                        e.setTo(linked.getInnerBlocks()[0].getLocation());
                        e.setCancelled(false);
                    } else {
                        e.setCancelled(true);
                    }
                    break;
                }
            }
            e.setCancelled(false);
        }
    
    basicly I'm searching for a better way to detect the player, note that inside the Portal object all the portal blocks are stored which I use to match the block on the players position however this doesn't work always that good.

    thanks for the help:)
     
  2. Offline

    valon750

    xize

    May I suggest a PlayerMoveEvent, then checking for the block the player is currently in?
     
  3. Offline

    xize

    valon750
    that would not be a good idea though since I'm working with Portal blocks in creative it teleports a player instant.

    however ive solved it by using a for each loop on the block faces on the location the player is.

    thanks for the help though:)
     
Thread Status:
Not open for further replies.

Share This Page