PlayerToggleSprintEvent Executing, but not stopping sprinting?

Discussion in 'Plugin Development' started by stuntguy3000, Jan 8, 2013.

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

    stuntguy3000

    Hello,

    Here is my PlayerToggleSprintEvent code:

    @EventHandler
    public void noSprint(PlayerToggleSprintEvent event)
    {
    event.setCancelled(true);
    event.getPlayer().sendMessage("Test Message");
    }

    Every time i sprint, i see "Test Message" but i can still sprint and it is not infact canceled :/ Any ideas?
     
  2. Offline

    iZanax

    A time ago I´ve tried the same, with no success, documentation of this event says that it is Cancellable but no effect like u described, U can test the potioneffect below instead of setCancelled, it might work, AFAIK.


    (Untested)
    PHP:
    player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS11));
    // The effect of blindness is that u can't sprint (and blindness).
    // So running players will be stopped and should not notice the blindess,
    // Since it's only 1 tick (50ms)
     
  3. Offline

    Terradominik

    the thing is that it is a ToggleSprintEvent so it fires if you togglesprint (if you cancel it you do equal nothing) so you have to check in the event if the player is spriniting and if yes set it to not sprinting (cancel)
    or you could simply do what iZanax suggested, but in this case i would also do the check if the player is sprinting.
     
  4. Offline

    fireblast709

    player.setSprinting(false);
     
    Vurtix likes this.
Thread Status:
Not open for further replies.

Share This Page