Cancel Sprinting?

Discussion in 'Plugin Development' started by MineCrypt, Feb 8, 2013.

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

    MineCrypt

    I cant seem to make it stop players from sprinting... Heres my code.
    Code:
    @EventHandler
        public void onPlayerToggleSprint(final PlayerToggleSprintEvent event)
        {
            Player player = event.getPlayer();
                event.setCancelled(true);
     
        }
     
  2. Offline

    Tirelessly

    Try event.getPlayer().setSprinting(false)
     
  3. Offline

    caseif

    You have a final modifier before the event, meaning that the variable is final; in other words, it can't be changed. Remove that modifier and it should work. :D
     
  4. Offline

    MineCrypt

    I got rid of the final, and it still does not work.
     
  5. Offline

    evilmidget38

    AngryNerd Yeah, that's not correct. The final keyword prevents it from being reassigned.

    MineCrypt Are you registering your EventHandler?
     
  6. Offline

    Sagacious_Zed Bukkit Docs

    MineCrypt
    A variable that can't be reassigned has nothing to do with the mutability of the object the variable is pointing to.
     
  7. Offline

    caseif

    Whoops, my bad then...
     
  8. Offline

    MineCrypt

    So does anyone have the code to cancel sprinting?
     
  9. Offline

    Sagacious_Zed Bukkit Docs

    You can't tell a client it can't sprint.
     
  10. Offline

    chasechocolate

    Have you tried what Tirelessly said?
     
  11. Offline

    MineCrypt

    Yea, Didnt work
     
  12. Offline

    Lonesface

    Code:java
    1.  
    2. @EventHandler
    3. public void onPlayerMove(PlayerMoveEvent event) {
    4. Player p = event.getPlayer();
    5. if (p.isSprinting()) {
    6. event.setCancelled(true);
    7. }
    8. }


    This will stop the player's movement when they attempt to sprint.
     
  13. Offline

    llamasaylol

    You sure you're registering the event? Try boradcast something when it's called (outside the ifs) and if you see the broadcast then use Lone's method, the other would be considered broken.
     
Thread Status:
Not open for further replies.

Share This Page