Listening for Trident Throw

Discussion in 'Spigot Plugin Development' started by hoorigan, Jul 29, 2018.

  1. I'm working on a plugin that needs to listen for tridents being thrown. Or, not thrown, but "used" with Riptide. Is there a special event for this that I'm missing in the Spigot documentation?

    For example, there's the EntityShootBow event, but there isn't an EntityThrowTrident event or anything like that relating to tridents from what I can find.

    If there isn't a special event for this, would PlayerInteractEvent be triggered only when the trident is "released" (release right mouse button) or would any use of the trident (left mouse button click, right mouse button click, right mouse button hold) trigger it?
     
    • Useful Useful x 1
  2. Pretty sure the Trident is a projectile. Therefore, it seems logic that it would run the Projectile events:

    ProjectileHitEvent
    Called when a projectile hits an object
    ProjectileLaunchEvent
    Called when a projectile is launched.

    In both methods, you can get the Entity for the Projectile and check if its EntityType is a TRIDENT.
    Code (Text):
    if(projectile.getEntity().getType == EntityType.TRIDENT)
       // do something
     
    • Agree Agree x 1
    • Winner Winner x 1
    • Informative Informative x 1
  3. Actually, it's an extension of an Arrow, meaning you can use it the same as as you'd use an arrow (ProjectileHitEvent and ProjectileLaunchEvent).
    https://hub.spigotmc.org/javadocs/spigot/org/bukkit/entity/Trident.html
     
  4. Ok, cool. That clears up part of my issue.

    What about when a player "throws" the trident in rain with the Riptide enchantment? It doesn't seem to visibly leave the player's hand. The player simply dashes forward, so I'm not sure if a ProjectileLaunchEvent fires when that happens, or if I want to be listening for PlayerInteractEvent in that particular case.

    Maybe I should explain more specifically what I'm trying to do with my code, instead of asking really vague questions and hoping for detailed answers. ;)

    Under certain conditions, if a player tries to dash using the Riptide enchantment, I want to either cancel that dash or modify the durability of the trident the player is using. Again, there is no visible "launch" of the projectile. The player simply dashes forward and keeps the trident. Do you guys know if the game still counts that as a projectile launch, or if it's something else since a projectile doesn't appear to be launched?
     
  5. An update on what I've figured out so far:

    When the player releases the trident with the Riptide enchantment, it does not register as a ProjectileLaunchEvent. I suspected this would be the case, as no projectile appears to be launched when this happens.
     
  6. I've had an extensive look through the javadocs and its sourcecode, but was unable to find any event relating to this 'riptiding' of the player. :oops:
     
  7. Same. I wonder if it would be worth it to put in a feature request for that. Like bows have EntityShootBow, maybe it would be good for tridents to have EntityThrowTrident, too. Also, just like the "isSwimming" and "isGliding" methods, maybe "isSparklingAndTwirlingWithAGiantDerpyFork" (this is why I don't name things) could be a thing.
     
    • Like Like x 3
    • Funny Funny x 1
    • Winner Winner x 1
  8. Choco

    Moderator

    I like that. It rolls off the tongue quite nicely.
     
    • Like Like x 3
    • Funny Funny x 1
  9. Jokes aside, what would be the best way for me to go about requesting the features I described? I'm fairly new to working with Spigot in any context beyond simply running game servers, so I'm not sure whether it's appropriate to submit a feature request via the issue tracker, nor do I know the best way to describe what I'm asking for. I don't want to be that guy, shoving vague suggestions into random places where they don't belong. XD
     
    • Funny Funny x 1
  10. Choco

    Moderator

    Later today, I will take a look at the trident code and see if there’s anything I can expose in the API for you. Though it would be nice if you created a feature request in the JIRA tracker so I may refer to it :) https://hub.spigotmc.org/jira/
     
    • Useful Useful x 1
    • Friendly Friendly x 1
  11. Or you could just use a playerInteractEvent and see if a trident is in the main hand, but that is just the simple solution ;)
     
  12. The "throwing" happens when you release it, which does not call a PlayerInteractEvent.
     
    • Like Like x 1
  13. Correct. I tried that. PlayerInteractEvent is called when you draw the trident back, not when you release it.

    That would work if I was trying to completely cancel trident use, but that's not the goal.
     
    • Friendly Friendly x 1
  14. Sorry,I havent worked much with tridents
     
  15. Nobody has. :p
     
    • Funny Funny x 3
    • Friendly Friendly x 2
    • Agree Agree x 1
  16. https://hub.spigotmc.org/stash/proj...mits/cab9d86f6ccc8399010c0eac9d7986f55b4d8f23

    For any LivingEntity (Player, monster, etc.)
    Code (Java):
     /**
         * Checks to see if an entity is currently using the Riptide enchantment.
         *
         * @return True if this entity is currently riptiding.
         * @deprecated draft API
         */

        @Deprecated
        public boolean isRiptiding();
    And the added event:
    Code (Java):
    /**
    * This event is fired when the player activates the riptide enchantment, using
    * their trident to propel them through the air.
    * <br>
    * N.B. the riptide action is currently performed client side, so manipulating
    * the player in this event may have undesired effects
    *
    * @deprecated draft API
    */

    @Deprecated
    @Warning(false)
    public class PlayerRiptideEvent extends PlayerEvent { ...
     
  17. Yup! I saw it there last night and am already using it. It's working great so far.

    Many thanks to all involved!
     
    • Friendly Friendly x 1