Getting or Setting Player Speed

Discussion in 'Plugin Development' started by Steeveeo, Jun 15, 2011.

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


    I've come up with a few ideas for a couple plugins here and there, but the major feature that keeps coming back has to do with making the player move faster or slower while running.

    My questions are simple, but I still cannot find the answer for them: How does one set player speed? And how do you get which direction keys a player is depressing?

    In short, I want to make a "Haste Spell" of sorts, how would I go about doing this?

    EDIT: The title is supposed to say "Getting AND Setting Player Speed", I typo'd it and can't find the button to change it.
  2. Offline


    Been longer than 24 hours without response, does anyone know how to do this?
  3. Offline


    I want something like this too ;D
    If I found somethin, I'll tell you.
  4. Offline


    Would be a cool idea.
  5. Offline


    Side note, it would also be nice to know how to do this for monsters as well, had an idea for a kind of "Frost Touch" spell while toying around in-game today.
  6. Offline


  7. Offline


  8. Offline


    Thanks a lot, I'll look into that and get back to you!

    Well, now, I can make the player go REALLY FAST, but that's about it. I can't seem to figure out how to make the player accelerate with directional keys, since I can't find the command for it, but, if anyone wants to try it, here's the code I came up with. Note, this is hilariously fast, and does not let you jump, and I can't figure out why:

        //Haste Stuffs
        private static double defaultSpeed = 1.8;
        public void onPlayerMove(PlayerMoveEvent event)
            Player player = event.getPlayer();
            //Can this person speed?
                //Unless crouched, speed the hell up
                    //Make sure to only speed up if on solid ground
                    int material = player.getWorld().getBlockAt(player.getLocation().getBlockX(), player.getLocation().getBlockY() - 1, player.getLocation().getBlockZ()).getTypeId();
                    if(material != 0 && material != 8 && material != 9 && material != 10 && material != 11 && material != 30 && material != 65 && material != 88)
                        //Vector dir = player.getLocation().getDirection().multiply(defaultSpeed).setY(0.1);
                        Vector dir = player.getLocation().getDirection().setY(0); //player.getVelocity();
                        Vector veloc = player.getVelocity();
                        dir.setX(Math.max(Math.min((dir.getX() * defaultSpeed)+(veloc.getX()*0.3), 2), -2));
                        dir.setZ(Math.max(Math.min((dir.getZ() * defaultSpeed)+(veloc.getZ()*0.3), 2), -2));
    Anyone know how to get what keys the player is holding? I.e. W, A, S, D, and Jump. The only status thing I could find is "isSneaking()" and that's it.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: May 16, 2016
  9. Offline


    I can imagine that key press events are not passed to the server but only handled at client site. The result is sent to the server. However, it's only a guess, not knowledge.
  10. Offline


    Key Press events are client side, you can't hook into them with Bukkit. Now, I do believe BukkitContrib has some way of handling key-press events...but this requires all users of the plugin to have the client-side BukkitContrib mod.
  11. Offline


    setVelocity() well, does exactly what it says. It instantaneously sets an entity's velocity in the world to the given vector (just ask my falcon punch plugin I made yesterday :cool:), and when this happens to a player, they lose control of movement.

    P.S. I wouldn't make it go too fast if I were you; I've encountered strange, strange problems with doing that to players. But then, it may be the explosion, or the ludicrous amounts of damage.
  12. onPlayerMove()
  13. Offline


    Or you can hook it into Spout, and then your players will only have to download Spoutcraft (a replacement Minecraft client) instead of modifying your minecraft jar. May be a slight inconvenience for your players to download something, but it will enable your plugin to do exactly what you want :)
  14. Offline


    I've looked into that, actually. I was going to use Spout (originally BukkitContrib), but when I got around to testing the environment, I ran into too many problems with it and decided to wait for a couple versions to see if it stops being weird (like ignoring my C key in chat, what the balls kind of error is that?).
  15. Offline


    That post was back when Spout was still under heavy development (with no release) :p
  16. Offline


    lol :p i didnt notice the date XD
Thread Status:
Not open for further replies.

Share This Page