login plugin help?

Discussion in 'Plugin Development' started by jkctech, Apr 18, 2014.

Thread Status:
Not open for further replies.
  1. Hello,
    im working on a login plugin and i have some issues:
    1. how should i encrypt the passwords of the players and how do i save them the best way?
    2. how do i block certain interactions when not logged in, like walk, breaking /placing blocks and such. (i already have the boolean "isLoggedIn" setup.)

    how do i do these things?
    thanks in advance!
     
  2. Offline

    Onlineids

    1: Dont think there is any need to encrypt them only owner will have access also store it in a database or another config.yml
    2: just get the event check if player isLoggedin if not setCancelled, do this for BlockBreakEvent PlayerMoveEvent PlayerAnimationEvent PlayerInteractEvent ect
     
  3. Offline

    Konkz

    1. http://stackoverflow.com/questions/1205135/how-to-encrypt-string-in-java
    2. Make a HashMap <Player, Boolean> if boolean is false for the player then cancel the following events: BlockBreakEvent, PlayerMoveEvent and BlockPlaceEvent. You can go further and do damage events, but
    seeing you're doing number one you can solve these.

    jkctech

    Onlineids The reason he wants them encrypted is if I go on his server and type in /register <My Password To Everything> then not even he should be able to see it, only you. It's like saying no point in encrypting Bukkit's forum because only the admins have access to it even know 90% of Bukkit's population probably uses same password in two or more instances.
     
  4. Konkz Onlineids is there a way i can do all these events at one time or do i have to mkae seperate evenhandlers?
    still thanks,i think i should not bother about encryption anymore, because just like Onlineids said, there's no much need for it.

    for instance: i have this in the players.yml file:
    Code:
    players:
      jkctech:
        password: minecraft
        email: [email protected]
      otherdude:
        password: otherpass
        email: [email protected]
    how do i get the data?
    i also've put this:
    Code:java
    1. File f = new File("players.yml");

    in the plugin to initialize the player.yml file, do i need to do anything else to get data from the file?

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

    Onlineids

    for password just do getConfig().getString("players." + p.getName() + ".password");
     
  6. thanks, that helped!

    Onlineids But how do i check if the password is set?
    and how do i use another file then the config file?

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

    Onlineids

    well to get the password u have to show me where it is
    and heres the code I use for custom files this one is for a property database:
    You save it with saveData() and get it with Data()
    Code:java
    1.  
    2. public void reloadCustomConfig() {
    3. if (customConfigFile == null) {
    4. customConfigFile = new File(getDataFolder(), "properties.yml");
    5. }
    6. customConfig = YamlConfiguration.loadConfiguration(customConfigFile);
    7.  
    8. // Look for defaults in the jar
    9. InputStream defConfigStream = this.getResource("data.yml");
    10. if (defConfigStream != null) {
    11. YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream);
    12. customConfig.setDefaults(defConfig);
    13. }
    14. }
    15. public FileConfiguration data() {
    16. if (customConfig == null) {
    17. reloadCustomConfig();
    18. }
    19. return customConfig;
    20. }
    21. public void saveData() {
    22. if (customConfig == null || customConfigFile == null) {
    23. return;
    24. }
    25. try {
    26. data().save(customConfigFile);
    27. } catch (IOException ex) {
    28. getLogger().log(Level.SEVERE, "Could not save config to " + customConfigFile, ex);
    29. }
    30. }
     
  8. sorry for asking so much questions but im quite a noob in java XD
    i have this code:
    Code:java
    1. public boolean isLoggedIn(){
    2. List<String> players = getConfig().getStringList("players");
    3. if(players.contains(p.getName())){
    4. p.sendMessage(ChatColor.GOLD+"[JKC-Login] "+ChatColor.DARK_RED+"You need to login!");
    5. return false;
    6. } else {return true;}
    7. return true;
    8. }

    but as you can see, i haven't declared the variable "p".
    i can't seem to get the player, so how do i do this?
    I also have this code:
    Code:java
    1. @EventHandler
    2. public void onPlayerInteract(){
    3. if(!isLoggedIn()){event.setCancelled(true);}
    4.  
    5. }

    but he doesn't seem to recognise the "event" part of event.setCancelled();
    i think this is because it isnt declared as an event.

    thanks in advance!
     
  9. Onlineids Konkz hello guys,
    sorry for asking things again but i'm realy getting confused.
    i don't know how to code my plugin. i have this so far:
    Code:java
    1. package me.jkctech.JKCLogin;
    2.  
    3. import java.io.File;
    4. import java.util.List;
    5.  
    6. import org.bukkit.ChatColor;
    7. import org.bukkit.entity.Player;
    8. import org.bukkit.event.EventHandler;
    9. import org.bukkit.event.Listener;
    10. import org.bukkit.event.player.PlayerInteractEvent;
    11. import org.bukkit.plugin.PluginDescriptionFile;
    12. import org.bukkit.plugin.java.JavaPlugin;
    13.  
    14. public class Main extends JavaPlugin implements Listener{
    15.  
    16. File f = new File("players.yml");
    17.  
    18.  
    19. @Override
    20. public void onEnable(){
    21. PluginDescriptionFile ymlFile = this.getDescription();
    22. this.getLogger().info(ymlFile.getName() + " Version " + ymlFile.getVersion() + " is enabled!");
    23. this.getLogger().info("This plugin is made by jkctech!");
    24. this.getServer().getPluginManager().registerEvents(this, this);
    25. }
    26.  
    27. @Override
    28. public void onDisable(){
    29. PluginDescriptionFile ymlFile = this.getDescription();
    30. this.getLogger().info(ymlFile.getName() + ymlFile.getVersion() + " is now disabled!");
    31. }
    32.  
    33. @EventHandler
    34. public void Interact(PlayerInteractEvent event) {
    35. List<String> players = getConfig().getStringList("players");
    36. final Player p = event.getPlayer();
    37. if(players.contains(p.getName())){event.setCancelled(true);}
    38. p.sendMessage(ChatColor.GOLD+"[JKC-Login] "+ChatColor.DARK_RED+"You need to login!");
    39. }
    40. }


    but i have absolutely no clue of how do this.
    this is the setup in the config file (config.yml):
    Code:
    players:
      jkctech:
        password: minecraft
        email: [email protected]
      otherdude:
        password: otherpass
        email: [email protected]
    i know how to check if the player is in this file. but how do i create that if the player executes this command "/jlogin add <player> <pass> <email>" it adds the player to the config.
    i would really appriciate it if somebody helped me with this.
     
  10. Offline

    Onlineids

    if(getConfig().contains(NAME)){
    //Player is in config
    }else{
    //Player isnt
    }
    and for the command get all the arguments and save it like getConfig().set(p.getName() + ".password") <-- that would be for password
     
  11. Onlineids i get that part but how do i create an array for the players which are logged in?
     
  12. Offline

    Onlineids

    List<Player> playerList = new ArrayList<Player>();
     
  13. Onlineids ok, so this is my whole code at this point:
    Code:java
    1. package me.jkctech.JKCLogin;
    2.  
    3. import java.io.File;
    4.  
    5. import org.bukkit.ChatColor;
    6. import org.bukkit.command.Command;
    7. import org.bukkit.command.CommandSender;
    8. import org.bukkit.entity.Player;
    9. import org.bukkit.event.Listener;
    10. import org.bukkit.plugin.PluginDescriptionFile;
    11. import org.bukkit.plugin.java.JavaPlugin;
    12.  
    13. public class Main extends JavaPlugin implements Listener{
    14.  
    15. File f = new File("players.yml");
    16.  
    17. public void loadConfiguration(){
    18. getConfig().options().copyDefaults(true);
    19. saveConfig();
    20. }
    21.  
    22. @Override
    23. public void onEnable(){
    24. PluginDescriptionFile ymlFile = this.getDescription();
    25. this.getLogger().info(ymlFile.getName() + " Version " + ymlFile.getVersion() + " is enabled!");
    26. this.getLogger().info("This plugin is made by jkctech!");
    27. this.getServer().getPluginManager().registerEvents(this, this);
    28. loadConfiguration();
    29. }
    30.  
    31. @Override
    32. public void onDisable(){
    33. PluginDescriptionFile ymlFile = this.getDescription();
    34. this.getLogger().info(ymlFile.getName() + ymlFile.getVersion() + " is now disabled!");
    35. }
    36.  
    37. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    38. final Player p = (Player) sender;
    39. if(label.equalsIgnoreCase("jlogin") || label.equalsIgnoreCase("jkclogin")){
    40. if(args.length == 4){
    41. if(args[0].equalsIgnoreCase("add")){
    42. getConfig().set("players."+p.getName(), args[1]);
    43. getConfig().set("players."+p.getName() + ".password", args[2]);
    44. getConfig().set("players."+p.getName() + ".email", args[3]);
    45. p.sendMessage(ChatColor.GOLD+"[JKC Login] "+ChatColor.GREEN+"Added "+args[1]+" to the players!");
    46. }
    47. }
    48. }
    49. return true;
    50. }
    51.  
    52. }


    when i execute the command "/jlogin add player pass [email protected]" it saysplayer added to config but it doesnt do anything.
    i get no errors but i think i messed up the code since this is the first time ive been working with configs.
    im using this tutorial at the moment:
    https://forums.bukkit.org/threads/t...ration-api-create-a-yaml-configuration.42775/
    i would realy appriciate it if you helped me ;)
    thanks!
     
  14. Offline

    Onlineids

    If its added to the config what is the problem?
     
  15. Onlineids no it sais it does, but actually it does nothing. can you find whatever i did wrong?
     
  16. Offline

    Onlineids

    add saveConfig()
    after u set the things in the config
     
  17. Onlineids how do i check if a player exists in config, because if i check if it is null, it ouputs an error.
     
  18. Offline

    Onlineids

    if(!(getConfig().getString(PATH)){
    //Doesnt exist
    }else{
    //Does exist
    }
     
  19. Onlineids i get this wierd bug.
    i have this code, which compares the password in the config file with the given argument:
    Code:java
    1. if(label.equalsIgnoreCase("login")){
    2. if(getConfig().getString("players."+p.getName()+".password") == args[0]){
    3. p.sendMessage("OK!");
    4. } else {
    5. p.sendMessage("NOT OK!");
    6. }
    7.  

    but no matter what, it ouputs "NOT OK!", what am i doing wrong?
    ive tried to debug it, to send a message with the given argument and what it sees in the config file.
    they were both the same!
     
Thread Status:
Not open for further replies.

Share This Page