Hooking yourself causes server to crash?

Discussion in 'Plugin Development' started by kreashenz, Oct 5, 2013.

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

    kreashenz

    I've been told that a fisherman kit I coded makes the server crash when you hook yourself. I think this may be caused by the hook hitting the player while sneaking and can't pick up who is throwing it, or it's creating a paradox loop somehow.
    There's no way to fix this because there's no FishingHook projectile/entity to cast anything to.
    Also, the ProjectileHitEvent can't pick up the Entity that gets hit, only the entity that gets launched, so I can't check if the projectile launcher is the thing the projectile hits.

    What can be a solution to this?
     
  2. Offline

    Seadragon91

    I am not sure If I understand what you want. Do you want to check if you hit yourself?
    If yes, does PlayerFishEvent not works for you?

    Code:
    @EventHandler
    public void onFishing(PlayerFishEvent event) {
        Player player = event.getPlayer();
        if (event.getState() == PlayerFishEvent.State.CAUGHT_ENTITY) {
            if (event.getCaught().getType() == EntityType.Player) {
                Player caughtPlayer = (Player) event.getCaught();
                if (player.getName().equalsIgnoreCase(caughtPlayer.getName())) {
                    //  yourself
                }
            }
        }
    }
     
Thread Status:
Not open for further replies.

Share This Page