Event about change of place.

Discussion in 'Spigot Plugin Development' started by Blizarg, May 11, 2019.

  1. Blizarg

    Blizarg Previously Gitcord

    I know I can sound extremely noob, before telling me to learn java better save your words and your time.

    How can I get the following:

    - That when a player throws a snowball to another player, he exchanges the place with which he throws it.

    Example:
    Player 1 (P1) - Player 2(P2): is in the coordinates 1, 100, 1 and when P1 throws the snowball and hits P2 it will change places with P2.
     
  2. Listen to the Projectile hit events, check to see if the Projectile is an instance of snowball, if so teleport the projectile’s getShooter() to the hit entities() location and vice versa


    Sent from my iPhone using Tapatalk
     
    • Winner Winner x 1
  3. Blizarg

    Blizarg Previously Gitcord

    Would not an example of code be a lot of hassle?
     
  4. That depends on your ability to code really, it’s a reasonably simple event, but you’ll have to setup an entire plugin on the api for it.

    If you can handle that and register an event handler it’s something along the lines of.

    Code (Text):

    @EventHandler
    public void onSnowballHit(ProjectileHitEvent e)
    {
      If(!e.getProjectile() instanceof Snowball)
          Return;   //wasn’t a snowball do nothing

      If(e.getEntity() instanceof Player)
       {
          //a player was hit
          e.getProjectile().getShooter().teleport(e.getEntity().getLocation());   //teleport the shooter to the hit players location.
         
    }


    }

    [\code]

    That should help you figure it out, you’ll have to teleport the hit player to the shooters location.  

    You should store the first player you teleports location in a Location object using getLocation()clone();
    BEFORE you teleport the first player.  It’s important to clone the location because you won’t be able to get it after you teleport the player.


    Sent from my iPhone using Tapatalk
     
  5. This is oftentimes referred to as "spoon-feeding". @dNiym has already given you everything you need to solve this problem. If he gave you the code, it would only encourage you to copy-paste it instead of solving it for yourslf.

    However since you are struggling, I will break it down further for you:

    You can also look at some code in other projects. For example my code-base contains an example of player-swapping from projectileHitEvent insde the PhantomArrow class: https://github.com/SirLich/skill-scheme/tree/slim
     
    • Friendly Friendly x 3
    • Optimistic Optimistic x 1
  6. Blizarg

    Blizarg Previously Gitcord

    code please xd
    ====================
     
    • Optimistic Optimistic x 1
  7. Figure it out... as @SirLich said, spoon-feeding encourages laziness and, ultimately, failure. He and @dNiym have given you MORE than enough information to do this.
     
    • Agree Agree x 1
  8. Strahan

    Benefactor

    It's not that difficult. Return if the entity is not a snowball. Return if the hit entity is null. Return if the shooter isn't a player. Then just clone the shooter's location, teleport the shooter to the target and the target to the cloned location. Easy peasy.
     
    • Agree Agree x 1
    • Funny Funny x 1
  9. Blizarg

    Blizarg Previously Gitcord

    With all the sincerity I am new writing code with the api of spigot and I have no idea, but some code examples could be better, if it is not too much trouble.
     
  10. Honestly, this is as much code as i think most people will give to you, as to not spoon feed. Try doing some testing, change some variables, add in some System.out.println(_) statements, make use of online resources
    and at this point you cant figure it out, well you may need to read up. Sorry friend.
    -Edit, Actually this is more code then is even required
     
  11. Strahan

    Benefactor

    Well, do you have Java experience? If so, everything you need is here. If not, you're putting the cart in front of the horse.
     
  12. Remember he doesn’t want to be told to learn java so don’t waste your time ;)
     
    • Funny Funny x 1
  13. I mean much more and I’ll have written the entire plugin for you, if you would like me to do this I would happily do it if you want to send a couple bucks my way via PayPal.


    Sent from my iPhone using Tapatalk
     
    • Funny Funny x 1
  14. Blizarg

    Blizarg Previously Gitcord

    give me your discord and we negotiate
     
  15. Its at the bottom of every single one of my posts.
     
  16. Are you really asking money for something who can be done in less than 2mn ?
    Like seriously, starting IDE/server take more time than making his request...
     
    • Funny Funny x 1
    • Winner Winner x 1
  17. EWS

    EWS

    The author of the thread wants someone to do the code for him and shows no interest in learning / following the steps to do it... why should anyone do it for free?

    Spoonfeeding will just encourage more of this sort of "help request" appear.
     
    • Agree Agree x 3
  18. Blizarg

    Blizarg Previously Gitcord

    You will accept the money yes or no.
     
  19. He asked me to give him code examples, It was pretty close to copy/paste status short of setting up the listener and plugin main class. So yeah if you come here asking for code help then when it’s given you don’t even try and keep asking for more code, then it becomes a matter of what’s more valuable to you a few bucks or knowledge.


    You are more than welcome to write this plugin for him free of charge if you like.

    Sent from my iPhone using Tapatalk
     
  20. I've never said to spoonfeed him, i'm just saying asking money for something as basic as the op request is ridiculous
     

Share This Page