Portal problems

Discussion in 'Plugin Development' started by Xhork, Dec 20, 2018.

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

    Xhork

    Hey,

    I'm currently making a plugin and I need to do custom portals, one in world "world" and when a player goes in this portal, he is teleported to the world "cds", BUT when this player takes the portal in X-coords (1 OR 0 OR -1) in the world "cds" he is teleported back to the world "world", but my problem is that when the player takes a portal in world "cds" but in other coords than those mentioned before, nothing is happening. I don't know if i was clear but here is my code :

    Code:
    @EventHandler
        public void onPortalEvent(PlayerPortalEvent e) {
            Player p = e.getPlayer();
            World cds = getServer().getWorld("cds");
            World world = getServer().getWorld("world");
            if(p.getWorld().equals(world)) {
                Location survie = new Location(getServer().getWorld("cds"), 0, 105, 0);
                e.setTo(survie);
            }else if (p.getWorld().equals(cds)) {
                if (e.getFrom().getBlockX() == 1 || e.getFrom().getBlockX() == 0 || e.getFrom().getBlockX() == -1) {
                    Location spawn = new Location(getServer().getWorld("world"), 1758, 14, 34);
                    e.setTo(spawn);
                }
               
            }
        }
    Thank you for reading this thread :)
     
  2. It's a bit confusing to read for me, although that's probably a fault on my end. So to be clear: you're trying to create that whenever someone uses a Nether Portal that is located on either X-coords '1', '0' or '-1' in the world 'cds', they will be teleported back to world 'world'?

    EDIT: And the issue that comes while attempting this, is when someone uses a portal that is not located on either of those X-coords, the Nether Portal just does not function normally anymore?
     
  3. Offline

    Xhork

    Look, here is the code updated to be as clear as possible.


    Code:
    @EventHandler
        public void onPortalEvent(PlayerPortalEvent e) {
            Player p = e.getPlayer();
            World cds = getServer().getWorld("cds");
            World world = getServer().getWorld("world");
            if(p.getWorld().equals(world)) {
                Location survie = new Location(getServer().getWorld("cds"), 0, 105, 0);
                e.setTo(survie);
            }else if (p.getWorld().equals(cds)) {
                if (e.getFrom().getBlockX() > -2 && e.getFrom().getBlockZ() > 13 && e.getFrom().getBlockX() < 3 && e.getFrom().getBlockZ() < 16) {
                    Location spawn = new Location(getServer().getWorld("world"), 1758, 14, 34);
                    e.setTo(spawn);
                }//HERE IF THE PLAYER IS NOT IN THE RIGHT COORDS, HE SHOULD BE TELEPORTED IN THE NETHER, BUT NO :/
               
            }
        }
     
    Last edited: Dec 20, 2018
  4. Offline

    torpkev

    I could be wrong (I frequently am) - but wouldn't the easiest thing to do would just to be cancel the event instead of changing the setTo and then send

    Code:
    e.getPlayer().teleport(spawn);
    
    ?
     
  5. Offline

    ForbiddenSoul

    In your main world "world", there is a nether, when a player steps into the portal they are teleported to the nether. A teleport event is invoked, and your plugin then intercepts this event and teleports the player to "cbs".
    In your "cbs" world, there is no nether, so when a player steps into the portal, no teleportation occurs, no event is invoked, and there is no event to intercept.

    You have to add a nether world to your "cbs" world somehow, so your portals actually teleport the player and your plugin can intercept the event, or find another way of detecting when they have gone into a nether portal other than "onPortalEvent".
     
    Last edited: Dec 28, 2018
    unrealdesign likes this.
Thread Status:
Not open for further replies.

Share This Page