Solved Prevent players from getting stuck

Discussion in 'Plugin Development' started by Ruptur, Jun 29, 2015.

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

    Ruptur

    Hey, thank you for taking time to read this.
    I have a little problem i cannot fix and need help with.
    I have a basic border i dont want players to cross, but somehow they keep getting stuck in the border.
    So i came up with a solution which was great at first. It basically threw players backwards when on the border.
    Code:
    
            IListener.Listen move = new IListener.Listen(PlayerMoveEvent.class) {
    
                @Override
                public void onEvent(Event event) {
                    if (event instanceof PlayerMoveEvent) {
                        PlayerMoveEvent e = (PlayerMoveEvent) event;
    
                        if (!arena.getCuboid().withinCuboid(e.getTo())) {
                            Player player = e.getPlayer();
    
                            player.setVelocity(player.getLocation().getDirection().setY(0).multiply(-0.2));
                            e.setTo(e.getFrom());
    
                            if (duel.isEnded()) {
                                this.cancel();
                                DuelIt.listener.unregister(this);
                            }
                        }
                    }
                }
            };
    
    
    Although this works the way i wanted it to i soon realised that when you enter the border from an angle you get stuck again. How can i prevent this?
     
  2. if you're using 1.8 send blockchange of a barrier block when the player is near 2-3 blocks
     
  3. Offline

    Zombie_Striker

    @Ruptur
    Why are you using the Event event instead of PlayerMoveEvent directly? Also, why not just add a method to teleport the player to another location if they are stuck?
     
  4. Offline

    Ruptur

  5. Offline

    Zombie_Striker

    @Ruptur
    Well, how do you? If you can tell that a player can get stuck, why cant the server?
     
  6. Offline

    Ruptur

    @Zombie_Striker
    I know the player gets stuck because i went ingame to test it out. Once glitched into the border i get rebounded back then rebounded opposite ways but the movement is minute.
     
  7. Offline

    Tecno_Wizard

    @Ruptur, which direction are you throwing them? directly horizontal? You'll have to add a vertical vector too.
     
  8. Offline

    Ruptur

    @Tecno_Wizard
    I throw them horizontal, although it throw throw them up a bit.
     
  9. Offline

    Tecno_Wizard

    @Ruptur, put a direct vertical acceleration in it.
     
  10. Offline

    Ruptur

    Thanks for your all tips.
    I have solved this issue but reducing the amount the players are bounced back by.

    From
    Code:java
    1.  
    2. player.setVelocity(player.getLocation().getDirection().setY(0).multiply(-2));
    3.  

    To
    Code:java
    1.  
    2. player.setVelocity(player.getLocation().getDirection().setY(0).multiply(-0.2));
    3.  
     
Thread Status:
Not open for further replies.

Share This Page