Solved Can't set a player's passenger

Discussion in 'Plugin Development' started by Maxx_Qc, Nov 19, 2015.

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

    Maxx_Qc

    Hi I'm trying to make a player1 to ride player2 when player2 right click on player1.
    When player2 right click on player1, it gives me a nullpointerexception and I can't figure it out.
    Code:
    @EventHandler
        public void onPlayerRightClick(PlayerInteractEntityEvent e) {
            Entity ent = e.getRightClicked();
            Player p = e.getPlayer();
            if(ent instanceof Player) {
                Player entPlayer = (Player) ent;
                String entName = entPlayer.getName();
       NullPointerException  ->if(p.getItemInHand().getItemMeta().getDisplayName().equals(getRopeName())) {
                    if(frozenPlayers.contains(entName)) {
                        p.sendMessage(colorize("&cVous avez démenotté: &5" + entName));
                        entPlayer.sendMessage(colorize("&aVous avez été démenotté!"));
                        entPlayer.setWalkSpeed(0.2F);
                        frozenPlayers.remove(entName);
                        return;
                    }
                    p.sendMessage(colorize("&aCe joueur est maintenant attaché: &5" + entName));
                    entPlayer.sendMessage(colorize("&cVous êtes maintenant menotté!"));
                    entPlayer.setWalkSpeed(0.0F);
                    frozenPlayers.add(entName);
                } else {
                    if(frozenPlayers.contains(entName))
                        p.setPassenger(entPlayer);
                }
            }
        }
    getRopeName() returns "&cRope" which isn't equals to null.
    Thank you for helping me!
     
  2. Offline

    Mrs. bwfctower

    @Maxx_Qc
    a) The player isn't holding anything
    b) The item the player is holding doesn't have itemmeta
    c) The display name of the item isn't set
     
    Maxx_Qc and Xerox262 like this.
  3. Offline

    Maxx_Qc

    Okay I got it, I needed to check if the player have something in his hand.
    Another problem:
    I can a force a player to stay in a vehicle?
    VehicleExitEvent doesn't work...
     
  4. Offline

    Xerox262

    I had the same problem while making a similar plugin, long story short it's EntityDismountEvent you want to look for, not Vehicle
     
  5. Offline

    Maxx_Qc

    @Xerox262 Man, this event doesn't even exist!
    I also have another problem, when the player2 is on player1, player1 can see almost nothing.
    Is there a way to put player2 higher so player1 can see?
    Thank you!
     
  6. Offline

    Xerox262

    Woops, apparently the EntityDismountEvent is a org.spigotmc event. And if you need to mount the player higher then just add a buffer, put an invisible entity between them.
     
  7. Offline

    Maxx_Qc

    @Xerox262 What entity would you sugget me to put between the two?
     
  8. Offline

    Xerox262

    Maybe a wither skull
     
  9. Offline

    Maxx_Qc

    @Xerox262 How can I make it not visible?
     
  10. Offline

    Xerox262

    Apparently it would take packets to make it invisible, you could do that or you could use a bat and give it a invisible potion effect however the bat will still make noise.
     
  11. Offline

    Maxx_Qc

    @Xerox262 Can't I use an arrow or enderpearl?
     
  12. Offline

    Xerox262

    Since they're not actual living entities they do not have the ability to add a potion effect, you could use them, but again you would have to use packets to hide it from the player.
     
  13. Offline

    Maxx_Qc

    @Xerox262 I never used packets before, it scares me
     
    Last edited: Nov 19, 2015
  14. Offline

    mcdorli

    .....
    Then why you use a knife? That is also scary.
     
  15. Offline

    Maxx_Qc

    @mcdorli What are you talking about?
     
Thread Status:
Not open for further replies.

Share This Page