How to freeze players without having it look glitchy

Discussion in 'Resources' started by AstramG, May 21, 2013.

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

    AstramG

    Hello, I recently found how to freeze players without just canceling the PlayerMoveEvent. It is actually very simple. I currently do not have any code with you, but I'll just share with you what I've learned. If you give somebody jump boost with an amplifier of 128 they won't be allowed to jump anymore. If you give somebody slowness 6 they won't be able to move at all. However, there is a side effect. The player's FOV will get zoomed in, I'm sure a plugin may be able to fix this however. Also, there is only one glitch as well. Players who jump up and down at the same time when they have both effects on (not moving, and not jumping) will have a jump that is about .1 meters tall and puts you about .1 meters further. You could just play around with this and get something pretty cool. This is also good for bigger servers who hate having bugs in their movement. Thank you.
     
    joserobjr, xxyy98 and hawkfalcon like this.
  2. Offline

    Skyshayde

    Interesting, which effect zooms the FOV in?
     
  3. Offline

    chasechocolate

    The slowness.
     
  4. Offline

    Skyshayde

    Huh, i will have to test next time I have some time
     
  5. Offline

    Ultimate_n00b

    Yeah, I figured the no jump one out when I was making a skill that would give you jump 250. AKA when you jump, you die. But instead it made you not jump... I figured jump 100 was good enough.
     
  6. Offline

    skipperguy12

    Well, I hate to give this away :'( , but this is the code I used in HungerGames to stop players at their pedestals from moving without using event.setCancelled(true) and making it look glitchy:
    Code:
    if (((e.getTo().getX() != e.getFrom().getX()) || (e.getTo().getZ() != e.getFrom().getZ()))) {
                e.setTo(e.getFrom());
                return;
            }
    This is listening to the PlayerMoveEvent of course :p
     
    xxyy98 likes this.
  7. Offline

    user_43347

    Implying it's anything special?
     
    Pew446, TigerHix, Ivan and 1 other person like this.
  8. Offline

    skipperguy12

    nkrecklow
    No, I just dislike giving code from my projects away, but this is something that a lot of people seem to have trouble with.
     
  9. Offline

    AstramG

    Does it work as smooth as the potion version? The potion version restricts movement 100% without latency with the move so you can't move your character at all.
     
  10. Offline

    skipperguy12

    AstramG
    Well, no, but it's not like the cancelled move event where you cannot move your mouse, this restricts going and horizontal direction, and can be modified for y axis too.

    Also, instead of sharply shoving you back into a very glitchy state, this just teleports you back to exactly where you used to be
     
  11. Offline

    AstramG

    Okay yeah I see how it works, since your not checking the Yaw and Pitch which is what most move canceling methods do.
     
  12. Offline

    Burnett1

    Why not just teleport the player to its self when he moves. p.teleport(p.getLocation());
     
  13. Offline

    Lucariatias

    This fires an EntityTeleportEvent, which other plugins may be listening on.
     
  14. Offline

    ZeusAllMighty11


    I'm pretty sure the majority of us know that you can use this, and it's not a 'secret' that you have this code. Infact, I've posted it many times in the past.

    The goal nowadays is to be the LEAST resource intensive. PlayerMoveEvent fires all the time multiple times, so that's out of the question.


    I also figured this way out a while ago too :p
     
    TigerHix, Skyshayde and user_43347 like this.
  15. Offline

    skipperguy12

    TheGreenGamerHD
    Yeah, it's not a secret, I just said that I don't like to give code out, that's all, even if it's already known about.
     
  16. Offline

    DarkBladee12

    AstramG You can also set a players' walk speed to 0 instead of adding slowness effect to the player, so you won't have that zoom effect of the slowness potion ;)
     
    DoctorDark likes this.
  17. Offline

    Skyshayde

    Set a players walk speed? How would that be done? DarkBladee12
     
  18. Offline

    DarkBladee12

    Skyshayde "PLAYER.setWalkSpeed(0.0F);" (Default walk speed is 0.2)
     
  19. Offline

    AstramG

    Oh thank you for that. This means that the only thing left is adding the potioneffect for anti jumping or finding a different way.
     
  20. Offline

    Skyshayde

    If anyone wants, I could write a quick plugin for this.
     
  21. Offline

    AstramG

    Here is something relatively easy to put in your code :p
    Code:
    package me.AstramG.Ice;
     
    import org.bukkit.entity.Player;
    import org.bukkit.potion.PotionEffect;
    import org.bukkit.potion.PotionEffectType;
     
    public class freezeLibrary {
     
        public void freezePlayer(Player player) {
            player.setWalkSpeed(0.0F);
            player.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, 10000, 128));
        }
     
        public void unfreezePlayer(Player player) {
            player.setWalkSpeed(0.2F);
            player.removePotionEffect(PotionEffectType.JUMP);
        }
    }
    
    To use it put it in as a class then reference it in your main plugin by doing this
    Code:
    freezeLibrary freezelib;
    public void onEnable() {
        freezelib = new freezeLibrary();
    }
     
  22. Offline

    Skyshayde

    I just finished one actually, testing it now.
     
  23. Offline

    AstramG

    What's the plugin do?
     
  24. Offline

    kreashenz

    This is one of the most usable and non-buggy ones I've seen. I've used it in a few custom plugins. Good work for spotting it out.
     
  25. Offline

    Skyshayde

    It has a single command, toggling jump 128 and walk speed 0. I am having some trouble actually. Null pointer on the command run, this line

    player.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, Integer.MAX_VALUE, 128));

    I assume I am not making a player object correctly.

    Code:
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    if (cmd.getName().equalsIgnoreCase("freeze")) {
    if (sender.isOp() == true) {
    if (getConfig().getBoolean("freeze." + sender.getName()) == false)
    name = args[0];
    player = getServer().getPlayer("name");
    player.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, Integer.MAX_VALUE, 128));
    player.setWalkSpeed(0.0F);
    getConfig().set("freeze." + sender.getName(), true);
     
    } else {
    if (getConfig().getBoolean("freeze." + sender.getName()) == true) {
    player.setWalkSpeed(0.2F);
    player.removePotionEffect(PotionEffectType.JUMP);
    }
    }
    }
     
    returntrue;
     
    }
    
     
  26. Offline

    AstramG

    Thank you :)

    Cast sender to a player:
    Player player = (Player) sender;
    And you don't need a second if statement because you have an else.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 1, 2016
  27. Offline

    Skyshayde

    I am not freezing the sender, I am freezing the player whos name was sent as an argument, I am going to try something though, think it will fix it.
     
  28. Offline

    AstramG

    Oh I didn't read through it clearly. I'll simply order what you've done wrong below.
    1) name is not defined as a string. Change it to String name = args[0];
    2) Well, you have the variable "name" used as a string instead of referencing the variable "name". Just take out the quotes: player = getServer().getPlayer("name");
    3) Also, define player as a Player class by doing Player player = getServer().getPlayer(name);
    4) You have an if statement after the else which is not needed and it simply says the same thing twice.
    5) Change cmd.getName() to label.equalsIgnoreCase("freeze")
    6) The return statement at the end says returntrue; when it should be return true;
    7) The sender won't always have a name so cast it to a Player and then use player.getName()
    8 [Optional]) It's better to take out the == true when dealing with booleans because it means the same things and just is a bit smaller.
     
  29. Offline

    Skyshayde

    See? This is why I need to program more lol. I did define the variables, just outside of the command stuff.
     
  30. Offline

    AstramG

    It's alright, that's how I started :)
     
Thread Status:
Not open for further replies.

Share This Page