Fully Freeze The Player Without Potions/Runnables

Discussion in 'Resources' started by Ultimate_n00b, Jun 12, 2014.

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

    Ultimate_n00b

    A little tired and don't want to explain it, but basically this will FULLY freeze the player. No zoom (as from using high level zoom), not buggy movement, and he looks perfectly fine from the other players perspectives.

    Code:java
    1.  
    2. public void freeze(Player player) {
    3. Location location = player.getLocation();
    4. try {
    5. PacketPlayOutSpawnEntityLiving spawnPacket = new PacketPlayOutSpawnEntityLiving();
    6. setField(spawnPacket, int.class, 0, 538085);
    7. setField(spawnPacket, int.class, 1, (byte) 65);
    8. setField(spawnPacket, int.class, 2, (int) Math.floor(location.getX() * 32.0D));
    9. setField(spawnPacket, int.class, 3, (int) Math.floor(location.getY() * 32.0D));
    10. setField(spawnPacket, int.class, 4, (int) Math.floor(location.getZ() * 32.0D));
    11. DataWatcher watcher = new DataWatcher(null);
    12. watcher.a(0, (Byte) (byte) 0x20);
    13. setField(spawnPacket, DataWatcher.class, 0, watcher);
    14.  
    15. PacketPlayOutAttachEntity attachPacket = new PacketPlayOutAttachEntity();
    16. setField(attachPacket, int.class, 0, 0);
    17. setField(attachPacket, int.class, 1, player.getEntityId());
    18. setField(attachPacket, int.class, 2, 538085);
    19.  
    20. ((CraftPlayer) player).getHandle().playerConnection.sendPacket(spawnPacket);
    21. ((CraftPlayer) player).getHandle().playerConnection.sendPacket(attachPacket);
    22. } catch (Exception e) {
    23. e.printStackTrace();
    24. }
    25. }
    26.  
    27. public void unfreeze(Player player) {
    28. ((CraftPlayer) player).getHandle().playerConnection.sendPacket(new PacketPlayOutEntityDestroy(538085));
    29. }
    30.  
    31. private void setField(Object object, Class<?> type, int index, Object value) throws NoSuchFieldException, IllegalAccessException {
    32. int i = 0;
    33. for (Field field : object.getClass().getDeclaredFields()) {
    34. if (field.getType().equals(type) && i++ == index) {
    35. field.setAccessible(true);
    36. field.set(object, value);
    37. break;
    38. }
    39. }
    40. }
    41.  

    Also found here.​
    Now just like every freezing method, this has drawbacks. So here's a list of em:​
    • Player appears sitting (only on his screen)
    • Shows "Press shift to stop riding" message
    • Heart thing instead of health bar
    • No gravity (could be good I suppose, it depends on your use)
    Reflection version coming as soon as I figure out why this method isn't being invoked (aka tomorrow).

    Another drawback is that someone can hack/mod their client to ignore the freeze. Not that big of a deal, you could combine this with a runnable or something if you wish.

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

    bigteddy98

    This doesn't work if a player joins later, right?
     
  3. Ultimate_n00b thats nice! thank you!
    bigteddy98 I dont think so because its only for the client, and when relog its disappear... :)
     
  4. Offline

    Ultimate_n00b

    bigteddy98 Yep. If you want them frozen when they log back in, just freeze them again.
     
  5. Offline

    97WaterPolo

    Ultimate_n00b
    Is there a way to get this to work on any entity? More specifically mobs?
     
  6. Offline

    Ultimate_n00b

    This specific way, no. For mobs I'd override the move method or something along those lines. But that's a question for a different thread ;)
     
    97WaterPolo likes this.
  7. Offline

    bigteddy98

    How about using TinyProtocol/ProtocolLib? I think that should work a lot better.
     
    Skyost likes this.
  8. Offline

    Ultimate_n00b

    .. what
     
  9. Offline

    bigteddy98

    I mean like when a player logs in, I think it's better to intercept the packet and modify it, instead of resending a packet after the normal packet has been sent.
     
    Skyost likes this.
  10. Offline

    Ultimate_n00b

    Intercept what packet?
     
  11. Offline

    TheTinySpider

    yourPlayer.setWalkSpeed(0.0f); ?
     
  12. Offline

    Skyost

    I do not know if you understand what you do.
     
  13. Offline

    bigteddy98

    Aah wait, I thought you were sending a PacketPlayOutNamedEntitySpawn, but no. Although I think it's better to make some kind list in which you remember the name and do the "re-freezing' automatically when relogging, this way people don't have to make this mechanism theirselves.
     
  14. Offline

    Ultimate_n00b

    Allows jumping, and zooms in.
    Sure I will, but what server makes a player unable to move before they even do anything?
     
  15. Offline

    Skyost

  16. Offline

    bigteddy98

    When you freeze a player, it probably has a reason. You don't want people to relog to unfreeze, right?
     
  17. Offline

    CaptainBern Retired Staff

    You can also set the ID of the entity, to the player's ID. Like this, it is shorter and works (well, it did last time I checked)
     
  18. Offline

    Ultimate_n00b

    Oh? That's quite interesting. Not a bad idea.
     
    CaptainBern likes this.
Thread Status:
Not open for further replies.

Share This Page