[1.7]Player Freeze - Simple to Use Resource

Discussion in 'Resources' started by mrbliss, Jun 20, 2014.

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

    mrbliss

    So i made this a little while ago and today decided that i would release it. It doesn't interact with packets so its easy to update which is why i use this class over my others.

    Code:java
    1. package customitems;
    2.  
    3. import java.util.ArrayList;
    4. import java.util.List;
    5.  
    6. import javax.print.DocFlavor.STRING;
    7.  
    8. import org.bukkit.Bukkit;
    9. import org.bukkit.Location;
    10. import org.bukkit.entity.Player;
    11. import org.bukkit.plugin.Plugin;
    12.  
    13. public class FreezeFactory {
    14.  
    15.  
    16.  
    17. private Main plugin;
    18. private List<String> frozenplayers = new ArrayList<String>();
    19.  
    20. /**
    21. *<pre>
    22. *<u><h1>FreezeFactory</h1></u>
    23. *<p>Made by MrBliss
    24. *
    25. *Funtions:
    26. *freeze(player);
    27. *unfreeze(player);
    28. *isfrozen(player);
    29. *frozenloc(player);
    30. *
    31. *</p>
    32. *</pre>
    33. */
    34. public FreezeFactory(Main plugin) {
    35. this.plugin = plugin;
    36. start();
    37. }
    38. private void start() {
    39. System.out.printf("[FreezeFactory] Started by plugin:"+ plugin.getName());
    40. }
    41. /**
    42. *<pre>
    43. *<u><h1>Freeze</h1></u>
    44. *<p>
    45. *Freeze the player
    46. *
    47. *Use like:
    48. *freeze(player);
    49. *
    50. *</p>
    51. *</pre>
    52. */
    53. public void freeze(Player player) {
    54. Location location = player.getLocation();
    55. String loc = location.toString();
    56. frozenplayers.add(player.getName());
    57. try {
    58. player.setWalkSpeed(0.0f);
    59.  
    60.  
    61. } catch (Exception e) {
    62. e.printStackTrace();
    63. }
    64. }
    65. /**
    66. *<pre>
    67. *<u><h1>UnFreeze</h1></u>
    68. *<p>
    69. *Unfreeze the player
    70. *
    71. *Use like:
    72. *unfreeze(player);
    73. *
    74. *</p>
    75. *</pre>
    76. */
    77. public void unfreeze(Player player) {
    78. Location location = player.getLocation();
    79. String loc = location.toString();
    80. frozenplayers.remove(player.getName());
    81. player.setWalkSpeed(0.2f);
    82.  
    83. }
    84. /**
    85. *<pre>
    86. *<u><h1>IsFrozen</h1></u>
    87. *<p>
    88. *Return if the player is currently frozen
    89. *
    90. *Use like:
    91. *isfrozen(player);
    92. *
    93. *</p>
    94. *</pre>
    95. */
    96. public boolean isfrozen(Player player) {
    97. if(frozenplayers.contains(player.getName())){
    98. return true;
    99. }
    100. }
    101. /**
    102. *<pre>
    103. *<u><h1>Frozenloc</h1></u>
    104. *<p>
    105. *Return location where the frozen player
    106. *is currently <u>not</u> where they were frozen
    107. *
    108. *Use Like:
    109. *frozenloc(player);
    110. *
    111. *</p>
    112. *</pre>
    113. */
    114. public String frozenloc(Player player) {
    115. if(frozenplayers.contains(player.getName())){
    116. String location = player.getLocation().toString();
    117. return location;
    118.  
    119. }
    120.  
    121.  
    122.  
    123. }
    124.  
    125.  
    126. }


    make a new variable like

    Code:java
    1. private FreezeFactory FreezeFactory;


    then add to your on enable

    Code:java
    1. FreezeFactory = new FreezeFactory(this);



    Its got every function described and worked well for me over the past few bukkit versions
     
  2. Offline

    chasechocolate

    Can't they still jump?

    EDIT: isfrozen(player) will always return true.
     
  3. Offline

    Necrodoom

    mrbliss notice the ; at the end of the if.
    Did you actually test if your resource is working as expected before putting this here?

    Soo...
    setWalkSpeed kinda works.

    You can still jump.

    And fly hacks still bypass it.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Feb 9, 2022
  4. Offline

    neol3108

    I'd do something like:
    Code:java
    1. public boolean isFrozen(Player p){
    2. return frozenplayers.contains(p.getName());
    3. }
     
  5. Offline

    filoghost

    It may sound a bit rude, but first learn how to code before making resources...
     
  6. Offline

    mrbliss

    was tired when i posted this after reformatting it and im gona go over it. Also to go over jumping i have a code somewere i use with this to disable that and ill post that or maybe intergrate it later.
     
  7. Offline

    mine-care

    As a lot of people said above, the setwalkspeed fails on jump, instead I recommend using player move event and when player moves teleport him to his location (that makes him unable to move or jump or event turn. As chasechocolate said, your method returns always true, and the set speed method creates a nasty fov event when player is frozen or unfrozen (tested it out thru my plugin ;)
     
    AoH_Ruthless likes this.
  8. Offline

    filoghost

    A better solution: combine walk speed + jump potion lvl. 127 + scheduled repeating task to check the position (because you can still slightly move with that potion, or with a hacked client), to avoid using the move event.
     
  9. Offline

    AoH_Ruthless

    filoghost
    While there can be a lot of overhead associated with the PlayerMoveEvent, I find it easier and rather efficient to follow mine-care 's suggestion. This is because you only need to check if the #getTo() is different from the #getFrom. To avoid checking yaw and pitch, check if each locations block is different. To avoid jumping, check if the y coordinate changes. This is very simple and won't lag the client provided you are not doing about 10 other things in aforementioned event.
     
    samus1221 and mine-care like this.
Thread Status:
Not open for further replies.

Share This Page