Пример #1
0
  public void addLimboPlayer(Player player) {
    String name = player.getName().toLowerCase();
    Location loc = player.getLocation();
    int gameMode = player.getGameMode().getValue();
    ItemStack[] arm;
    ItemStack[] inv;
    boolean operator;
    String playerGroup = "";

    if (playerData.doesCacheExist(name)) {
      StoreInventoryEvent event = new StoreInventoryEvent(player, playerData);
      Bukkit.getServer().getPluginManager().callEvent(event);
      if (!event.isCancelled() && event.getInventory() != null && event.getArmor() != null) {
        inv = event.getInventory();
        arm = event.getArmor();
      } else {
        inv = null;
        arm = null;
      }
      playerGroup = playerData.readCache(name).getGroup();
      operator = playerData.readCache(name).getOperator();
    } else {
      StoreInventoryEvent event = new StoreInventoryEvent(player);
      Bukkit.getServer().getPluginManager().callEvent(event);
      if (!event.isCancelled() && event.getInventory() != null && event.getArmor() != null) {
        inv = event.getInventory();
        arm = event.getArmor();
      } else {
        inv = null;
        arm = null;
      }

      if (player.isOp()) {
        operator = true;
      } else {
        operator = false;
      }
    }

    if (Settings.isForceSurvivalModeEnabled) {
      if (Settings.isResetInventoryIfCreative && gameMode != 0) {
        ResetInventoryEvent event = new ResetInventoryEvent(player);
        Bukkit.getServer().getPluginManager().callEvent(event);
        if (!event.isCancelled()) {
          player.sendMessage("Your inventory has been cleaned!");
        }
      }
      gameMode = 0;
    }
    if (player.isDead()) {
      loc = player.getWorld().getSpawnLocation();
      if (plugin.mv != null) {
        try {
          loc =
              plugin
                  .mv
                  .getMVWorldManager()
                  .getMVWorld(player.getWorld().getName())
                  .getSpawnLocation();
        } catch (NullPointerException npe) {
        }
      }
    }
    try {
      if (cache.containsKey(name) && playerGroup.isEmpty()) {
        LimboPlayer groupLimbo = cache.get(name);
        playerGroup = groupLimbo.getGroup();
      }
    } catch (NullPointerException ex) {
    }

    cache.put(
        player.getName().toLowerCase(),
        new LimboPlayer(name, loc, inv, arm, gameMode, operator, playerGroup));
  }
Пример #2
0
    public String performLogin(Player player, String password) {
            
        String name = player.getName().toLowerCase();
        String ip = player.getAddress().getAddress().getHostAddress();
        
        if (PlayerCache.getInstance().isAuthenticated(name)) {
            return m._("logged_in");
           
        }

        if (!database.isAuthAvailable(player.getName().toLowerCase())) {
            return m._("user_unknown");
        }
        
        PlayerAuth pAuth = database.getAuth(name);
            // if Mysql is unavaible
            if(pAuth == null)
                return m._("user_unknown");
            
        String hash = pAuth.getHash();
        

        try {
            if(!passpartu) {
            if (PasswordSecurity.comparePasswordWithHash(password, hash)) {
                PlayerAuth auth = new PlayerAuth(name, hash, ip, new Date().getTime());
            
                database.updateSession(auth);
                PlayerCache.getInstance().addPlayer(auth);
                LimboPlayer limbo = LimboCache.getInstance().getLimboPlayer(name);
                if (limbo != null) {
                    if(Settings.protectInventoryBeforeLogInEnabled) {
                        player.getInventory().setContents(limbo.getInventory());
                        player.getInventory().setArmorContents(limbo.getArmour());
                    }
                    player.setGameMode(GameMode.getByValue(limbo.getGameMode()));
                    player.setOp(limbo.getOperator());
                    /*                  
                     * if (limbo.getOperator()) {
                         System.out.println("player is an operator after login success");
                    }*/
                    utils.addNormal(player, limbo.getGroup());
                    //System.out.println("il gruppo in logincommand "+limbo.getGroup());
                    //
                    // TODO: completly rewrite this part, too much if, else ...
                    // check quit location, check correct spawn, 
                    //
                    World world = player.getWorld();

                        
                    if (Settings.isTeleportToSpawnEnabled && !Settings.isForceSpawnLocOnJoinEnabled) {                  
                                 // This is initial work around for prevent ppl to quit on bukkit bug
                                 // take last quit location from database and subtract y from safe spawn             
                                 // if the error range is smaller then 1, player can come back in his quit location
                                 // otherwise he try to spawn in a unsafe location!
                                
                                 if(Settings.isSaveQuitLocationEnabled && database.getAuth(name).getQuitLocY() != 0) {
                                     Location quitLoc = new Location(player.getWorld(),(double)database.getAuth(name).getQuitLocX()+0.5,(double)database.getAuth(name).getQuitLocY()+1.5,(double)database.getAuth(name).getQuitLocZ()+0.5);
                                     //pre-load chunk before teleport player to quit location
                                     
                                     if(!world.getChunkAt(quitLoc).isLoaded()) {
                                         //System.out.println("Debug chunk insent loaded");
                                         world.getChunkAt(quitLoc).load();
                                     }
                                     player.teleport(quitLoc);
                                     //System.out.println("quit location from db:"+quitLoc);
                                 } else {
                                    //pre-load chunk before teleport player to quit location
                                    if(!world.getChunkAt(limbo.getLoc()).isLoaded())
                                            world.getChunkAt(limbo.getLoc()).load();                                      
                                 player.teleport(limbo.getLoc());
                                 //System.out.println("quit location from bukkit:"+limbo.getLoc());
                                 } 
                    } else {
                        if(Settings.isForceSpawnLocOnJoinEnabled) {
                            player.teleport(player.getWorld().getSpawnLocation());  
                        } else {
                        if ( Settings.isSaveQuitLocationEnabled && database.getAuth(name).getQuitLocY() != 0) {
                          Location quitLoc = new Location(player.getWorld(),(double)database.getAuth(name).getQuitLocX()+0.5,(double)database.getAuth(name).getQuitLocY()+1.5,(double)database.getAuth(name).getQuitLocZ()+0.5);
                          //pre-load chunk before teleport player to quit location
                              if(!world.getChunkAt(quitLoc).isLoaded()) {
                                  //System.out.println("Debug chunk insent loaded");
                                  world.getChunkAt(quitLoc).load(); 
                              }
                          player.teleport(quitLoc);  
                          //System.out.println("quit location from db:"+quitLoc);
                        } else {
                          //pre-load chunk before teleport player to quit location
                              if(!world.getChunkAt(limbo.getLoc()).isLoaded()) {
                                  //System.out.println("Debug chunk insent loaded");
                                  world.getChunkAt(limbo.getLoc()).load();      
                              }
                                player.teleport(limbo.getLoc());
                                //System.out.println("quit location from bukkit:"+limbo.getLoc()); 
                                }  
                        }
                    } 
                player.getServer().getScheduler().cancelTask(limbo.getTimeoutTaskId());
                LimboCache.getInstance().deleteLimboPlayer(name);
                if(playerCache.doesCacheExist(name)) {
                        playerCache.removeCache(name);
                    }   
                }
                
               /*
                *  Little Work Around under Registration Group Switching for admins that
                *  add Registration thru a web Scripts.
                */
                if ( Settings.isPermissionCheckEnabled && AuthMe.permission.playerInGroup(player, Settings.unRegisteredGroup) && !Settings.unRegisteredGroup.isEmpty() ) {
                    AuthMe.permission.playerRemoveGroup(player.getWorld(), player.getName(), Settings.unRegisteredGroup);
                    AuthMe.permission.playerAddGroup(player.getWorld(), player.getName(), Settings.getRegisteredGroup);
                }
                    
                    
                player.sendMessage(m._("login"));
                ConsoleLogger.info(player.getDisplayName() + " logged in!");
                player.saveData();
                
            } else {
                ConsoleLogger.info(player.getDisplayName() + " used the wrong password");
                if (Settings.isKickOnWrongPasswordEnabled) {
                    player.kickPlayer(m._("wrong_pwd"));
                } else {
                    return (m._("wrong_pwd"));
                }
            }
         } else {
            // need for bypass password check if passpartu command is enabled
                PlayerAuth auth = new PlayerAuth(name, hash, ip, new Date().getTime());
                database.updateSession(auth);
                PlayerCache.getInstance().addPlayer(auth);
                LimboPlayer limbo = LimboCache.getInstance().getLimboPlayer(name);
                if (limbo != null) {
                    if(Settings.protectInventoryBeforeLogInEnabled) {
                        player.getInventory().setContents(limbo.getInventory());
                        player.getInventory().setArmorContents(limbo.getArmour());
                    }
                    player.setGameMode(GameMode.getByValue(limbo.getGameMode()));
                    player.setOp(limbo.getOperator());
                    /*                  
                     * if (limbo.getOperator()) {
                         System.out.println("player is an operator after login success");
                    }*/
                    utils.addNormal(player, limbo.getGroup());
                   //System.out.println("il gruppo in logincommand "+limbo.getGroup());
                   //
                   // TODO: completly rewrite this part, too much if, else ...
                   // check quit location, check correct spawn, 
                   //
                    World world = player.getWorld();
                    if (Settings.isTeleportToSpawnEnabled && !Settings.isForceSpawnLocOnJoinEnabled) {                  
                                 // This is initial work around for prevent ppl to quit on bukkit bug
                                 // take last quit location from database and subtract y from safe spawn             
                                 // if the error range is smaller then 1, player can come back in his quit location
                                 // otherwise he try to spawn in a unsafe location!
                                
                                 if(Settings.isSaveQuitLocationEnabled && database.getAuth(name).getQuitLocY() != 0) {
                                     Location quitLoc = new Location(player.getWorld(),(double)database.getAuth(name).getQuitLocX()+0.5,(double)database.getAuth(name).getQuitLocY()+0.5,(double)database.getAuth(name).getQuitLocZ()+0.5);
                                     //pre-load chunk before teleport player to quit location
                                     
                                     if(!world.getChunkAt(quitLoc).isLoaded()) {
                                         //System.out.println("Debug chunk insent loaded");
                                         world.getChunkAt(quitLoc).load();
                                     }
                                     player.teleport(quitLoc);
                                     //System.out.println("quit location from db:"+quitLoc);
                                 } else {
                                    //pre-load chunk before teleport player to quit location
                                    if(!world.getChunkAt(limbo.getLoc()).isLoaded())
                                            world.getChunkAt(limbo.getLoc()).load();                                      
                                 player.teleport(limbo.getLoc());
                                 //System.out.println("quit location from bukkit:"+limbo.getLoc());
                                 } 
                    } else {
                        if(Settings.isForceSpawnLocOnJoinEnabled) {
                            player.teleport(player.getWorld().getSpawnLocation());  
                        } else {
                        if ( Settings.isSaveQuitLocationEnabled && database.getAuth(name).getQuitLocY() != 0) {
                          Location quitLoc = new Location(player.getWorld(),(double)database.getAuth(name).getQuitLocX()+0.5,(double)database.getAuth(name).getQuitLocY()+0.5,(double)database.getAuth(name).getQuitLocZ()+0.5);
                          //pre-load chunk before teleport player to quit location
                              if(!world.getChunkAt(quitLoc).isLoaded()) {
                                  //System.out.println("Debug chunk insent loaded");
                                  world.getChunkAt(quitLoc).load(); 
                              }
                          player.teleport(quitLoc);  
                          //System.out.println("quit location from db:"+quitLoc);
                        } else {
                          //pre-load chunk before teleport player to quit location
                              if(!world.getChunkAt(limbo.getLoc()).isLoaded()) {
                                  //System.out.println("Debug chunk insent loaded");
                                  world.getChunkAt(limbo.getLoc()).load();      
                              }
                                player.teleport(limbo.getLoc());
                                //System.out.println("quit location from bukkit:"+limbo.getLoc()); 
                                }  
                        }
                    } 
                player.getServer().getScheduler().cancelTask(limbo.getTimeoutTaskId());
                LimboCache.getInstance().deleteLimboPlayer(name);
                if(playerCache.doesCacheExist(name)) {
                        playerCache.removeCache(name);
                    }   
                }
                
               /*
                *  Little Work Around under Registration Group Switching for admins that
                *  add Registration thru a web Scripts.
                */
                if ( Settings.isPermissionCheckEnabled && AuthMe.permission.playerInGroup(player, Settings.unRegisteredGroup) && !Settings.unRegisteredGroup.isEmpty() ) {
                    AuthMe.permission.playerRemoveGroup(player.getWorld(), player.getName(), Settings.unRegisteredGroup);
                    AuthMe.permission.playerAddGroup(player.getWorld(), player.getName(), Settings.getRegisteredGroup);
                }
                    
                    
                player.sendMessage(m._("login"));
                ConsoleLogger.info(player.getDisplayName() + " logged in!");
                player.saveData(); 
                this.passpartu = false;
            }                
          
        } catch (NoSuchAlgorithmException ex) {
            ConsoleLogger.showError(ex.getMessage());
            return (m._("error"));
        }
        return "";
	}