I'm stuck

Discussion in 'Plugin Development' started by Vistify, May 5, 2019.

  1. Offline

    Vistify

    I'm making a snowball that when you throw it at someone you switch places. This is how far I've gotten.
    Code: https://hastebin.com/iziraqelep.java
    Any suggestions, or help is greatly appreciated. Thank you for your dedication.
     
  2. Online

    timtower Ninja on the waves Moderator

    @Vistify Hi stuck, I am Tim
    /End of bad joke
    You need to use the event that fires when the snowball hits.
    ProjectileHitEvent I believe (name could be different)
    Then you can teleport both players.
    Might need to track the uuid of the snowball though, not sure about that part.
     
  3. Offline

    Vistify

    lol dad jokes. Thanks for the info, I'll give it my best shot.
     
  4. Offline

    KarimAKL

    @Vistify As @timtower said, you need to check the ProjectileHitEvent, then check if 'getHitEntity' is null, if it's not null then check if the entity returned by that method is a player and if so teleport the players, remember the save the two locations in the scope and teleport the players to them instead of directly teleporting the players to eachother, otherwise the second player wouldn't get teleported to a new location.
    To check if the projectile is the snowball you want, you can make a list of type 'Snowball' and then add the snowball to the list when fired in the ProjectileLaunchEvent. (remember to check if it's your snowball before adding it to the list)
     
  5. Offline

    Vistify

    Ok, so I just got home and started working on this again and it doesn't do anything. The event is registered in the main class, and I don't get an error in console. I'm very confused..

    Code Sample: https://pastebin.com/T0Hicrmp

    @KarimAKL @timtower
     
    Last edited: May 5, 2019
  6. Online

    timtower Ninja on the waves Moderator

    @Vistify damagerE instanceof Snowball
    if(!(damagerE instanceof Player)) return;

    They don't go well together.
     
  7. Offline

    KarimAKL

    @Vistify Just a suggestion but instead of naming the entities 'damaged' and 'damager', you could change it to 'victim' and 'attacker', or something like that.
    It's way easier to look for errors etc.
     

Share This Page