Solved Trident Throw Event

Discussion in 'Spigot Help' started by jacob123, Mar 25, 2021.

  1. How can I cancel it, when a player throws a Trident?
    I 've tried this:
    Code (Java):
    @EventHandler
        public void TridentThrow(ProjectileLaunchEvent event){
            if (event.getEntity().getType() == EntityType.TRIDENT){
                event.setCancelled(true);
                event.getEntity().sendMessage(ChatColor.RED + "Tridents zijn NIET toegestaan!");
            }
        }
     
  2. Strahan

    Benefactor

    The entity in the context of a projectile launch is the projectile not the person who launched it. You need to cast the projectile to its appropriate type then get the person who threw it from that.
     
  3. Can you give an example?
     
  4. Strahan

    Benefactor

    Code (Text):
    ProjectileLaunchEvent {
      if (entity type is not instanceof Trident) return;
     
      Create Trident object from the event.getEntity()
      if (Trident object shooter is not instanceof Player) return;

      Cancel event
      Send message to shooter saying no can do
    }
     
  5. Thx!

    Code (Java):
    @EventHandler
        public void TridentThrow(ProjectileLaunchEvent event){
            if (!(event.getEntity() instanceof Trident)) return;

            if (!(event.getEntity().getShooter() instanceof Player)) return;

            ((Player) event.getEntity().getShooter()).sendMessage(ChatColor.RED + "Tridents zijn NIET toegestaan!");
            event.setCancelled(true);
        }
     
    • Like Like x 2
    • Friendly Friendly x 1