block server creating portal but allow teleports

Discussion in 'Plugin Development' started by Scorpionvssub, Aug 24, 2016.

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

    Scorpionvssub

    Title pretty much says it all but...

    Im trying to create a plugin for my faction server that will allow players to create a portal and use it, while disallowing the server to create a portal in the overworld

    Code:
        @EventHandler
        public void onPortalCreate(PlayerPortalEvent e) {
            boolean travelAgent = e.getPortalTravelAgent().getCanCreatePortal();
            if (travelAgent) {
                Location loc = e.getTo();
                if (!loc.getWorld().getName().equalsIgnoreCase("world_nether")) {
                    e.setCancelled(true);
                    TravelAgent search = e.getPortalTravelAgent().setSearchRadius(500);
                }
            }
        }
    This is what i currently have.

    This bit of code functions for nether world and does what vanilla mc does for nether portals in the nether, however currently while in overworld it blocks creation of a "new" portal, it also blocks traveling.

    Players can travel to the nether normally that all works. Its going back thats being a son of a gun lol

    I tried just teleporting the player but they end up 25+ blocks upin the air...and that is deadly :p
     
    Last edited: Aug 24, 2016
  2. Offline

    Qwertyness_

    I'm not sure if I'm understanding you entirely, but if you are just trying to control portal creation, wouldn't a PortalCreateEvent be better? You can get the world from the Block objects in PortalCreateEvent#getBlocks() and cancel if it's in the overworld. There is also a CreateReason enum that has a field called OBC_DESTINATION that is present in that event when the portal is created for player teleportation. Then just add any extra logic you need to make exceptions.
     
    Last edited: Aug 26, 2016
Thread Status:
Not open for further replies.

Share This Page