Freezing Players

Discussion in 'Plugin Development' started by Ula492, Oct 4, 2015.

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

    Ula492

    So im trying to freeze a player simple as that. But when I do the moveEvent it dosent freeze them. and EventCancel just makes it lag like crazy.


    Code:
          if (cmd.getName().equalsIgnoreCase("Test1"))
                {
                      A.clear();
                      A.add("1");
                    
                    
                      BukkitScheduler sch = Bukkit.getServer().getScheduler();
                      sch.scheduleSyncRepeatingTask(this, new Runnable() {
                    
                      @Override
                      public void run(){
                        
                          Integer i = A.size();
                        
                          if(i == 1){
                            
                                  freeze.add(p.getUniqueId());
                                p.hidePlayer(p);
                                Bukkit.dispatchCommand(p, "spawn");
                              
    
                                p.playSound(p.getLocation(), Sound.CHICKEN_EGG_POP, 1F, 1F);
                                p.sendMessage("§a§lWELCOME TUTORIAL");
                                p.sendMessage("");
                                p.sendMessage("§fHey §6§l" + p.getName() );
                                p.sendMessage("");
                                p.sendMessage("");
                                p.sendMessage("");
                                p.sendMessage("");
                                p.sendMessage("");
                                p.sendMessage("");
                                p.sendMessage("§a§l===================================");
                              
                            
                              A.add("A");
                          }
                          if(i == 2){
                                  freeze.add(p.getUniqueId());
    
                                  p.playSound(p.getLocation(), Sound.CHICKEN_EGG_POP, 1F, 1F);
                                p.sendMessage("§a§lWELCOME TUTORIAL");
                                p.sendMessage("");
                                p.sendMessage("§fHey §6§l" + p.getName());
                                p.sendMessage("");
                                p.sendMessage("§fWelcome to the Hybrid Gaming Network.");
                                p.sendMessage("");
                                p.sendMessage("");
                                p.sendMessage("");
                                p.sendMessage("");
                                p.sendMessage("§a§l===================================");                        
                            
                              A.add("B");
                          }
                        
                          if(i == 3){
                                  freeze.add(p.getUniqueId());
    
                                  p.playSound(p.getLocation(), Sound.CHICKEN_EGG_POP, 1F, 1F);
                                p.sendMessage("§a§lWELCOME TUTORIAL");
                                p.sendMessage("");
                                p.sendMessage("§fHey §6§l" + p.getName());
                                p.sendMessage("");
                                p.sendMessage("§fWelcome to the Hybrid Gaming Network.");
                                p.sendMessage("");
                                p.sendMessage("§fMy name is dave, Ill be your tour guide!");
                                p.sendMessage("");
                                p.sendMessage("");
                                p.sendMessage("§a§l===================================");  
                            
                            
                              A.add("C");
                          }
                        
                          if(1 == 4){
                            
                            
                                p.showPlayer(p);
                                Bukkit.dispatchCommand(p, "spawn");
                                freeze.remove(p.getUniqueId());
                              
                                A.add("D");
                            
                          }
                        
                          if(i == 4){
                            
                              A.clear();
                          }
                        
                      }
                      }, 0, 50);
                }
    Code:
    @EventHandler(priority=EventPriority.NORMAL)
        public void onPlayerMove(PlayerMoveEvent e) {
            Player p = e.getPlayer();
          if (freeze.contains(e.getPlayer().getName())) {
              Location from=e.getFrom();
                Location to=e.getTo();
                double x=Math.floor(from.getX());
                double z=Math.floor(from.getZ());
                if(Math.floor(to.getX())!=x||Math.floor(to.getZ())!=z)
                {
                    x+=.5;
                    z+=.5;
                    e.getPlayer().teleport(new Location(from.getWorld(),x,from.getY(),z,from.getYaw(),from.getPitch()));
                }
              }
          }
     
  2. Offline

    RoboticPlayer

    To cancel movement, just do this:
    Code:
    e.setFrom(e.getTo);
     
  3. Offline

    567legodude

    @Ula492 Have you tried creating a runnable that runs every tick, and constantly teleport them to the location that you want?

    @henderry2019 You did that backwards, it should be:
    Code:
    e.setTo(e.getFrom());
     
  4. Offline

    RoboticPlayer

  5. Offline

    Ula492

  6. Offline

    oceantheskatr

    @Ula492 Show your updated code please.
     
  7. Offline

    Ula492

    Only thing changed was onMoveEvent

    Code:
        @EventHandler(priority=EventPriority.LOW)
        public void onPlayerMove(PlayerMoveEvent e) {
            Player p = e.getPlayer();
          if (freeze.contains(e.getPlayer().getName())) {
              e.setTo(e.getFrom());
              }
     
  8. Offline

    oceantheskatr

    Try setting the priority to high.
     
  9. Offline

    Ula492

    Nothing
     
  10. Offline

    boomboompower

    Did you register the event?
     
  11. Offline

    Ula492

    Yes. and its in the main class
     
  12. Offline

    Scimiguy

    This issue has been going around for a long, long time.

    It's just not practically possible because of the way multiplayer works.

    The client thinks its moving until the server tells it that it's not, so you will always get the jumping around
     
  13. Offline

    mythbusterma

    @Ula492

    As long as "freeze" isn't something stupid, canceling the event doesn't cause any lag.

    Everyone really needs to stop misusing that word, because its not actually lagging your server. The issue you're referring to is actually that the player can still make jerky movements, which is completely different than lag.

    What you're doing right there actually would cause far, far, far more lag than just canceling the event (however, the resource usage is so minimal as to not be worth considering, anyway).

    Set the player's movement speed to a very low number (e.g. 0.0001) and they won't make jerky movements anymore. Note: setting that to zero will crash the player, so don't do that.
     
  14. Offline

    Ula492

    That works! but I can still DoubleJump and Jump walk
     
  15. Offline

    mythbusterma

    @Ula492

    Double jump? Do you have some sort of double jump plugin installed on your server?

    Also, make sure you actually cancel the Events, because those are still PlayerMoveEvents. Perhaps try also cancelling the PlayerTeleportEvent?
     
  16. Offline

    Ula492

    I have my own DoubleJump on a dif class. I Just disabled it cuz i thought it was interfering since it uses the move event

    I stoped the server and stared the server and it fixed it...

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Oct 30, 2015
Thread Status:
Not open for further replies.

Share This Page