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!
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
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.
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 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.
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.
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 public void reloadCustomConfig() {if (customConfigFile == null) {customConfigFile = new File(getDataFolder(), "properties.yml");}customConfig = YamlConfiguration.loadConfiguration(customConfigFile); // Look for defaults in the jarInputStream defConfigStream = this.getResource("data.yml");if (defConfigStream != null) {YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream);customConfig.setDefaults(defConfig);}}public FileConfiguration data() {if (customConfig == null) {reloadCustomConfig();}return customConfig;}public void saveData() {if (customConfig == null || customConfigFile == null) {return;}try {data().save(customConfigFile);} catch (IOException ex) {getLogger().log(Level.SEVERE, "Could not save config to " + customConfigFile, ex);}}
sorry for asking so much questions but im quite a noob in java XD i have this code: Code:java public boolean isLoggedIn(){ List<String> players = getConfig().getStringList("players"); if(players.contains(p.getName())){ p.sendMessage(ChatColor.GOLD+"[JKC-Login] "+ChatColor.DARK_RED+"You need to login!"); return false; } else {return true;} return true; } 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 @EventHandler public void onPlayerInteract(){ if(!isLoggedIn()){event.setCancelled(true);} } 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!
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 package me.jkctech.JKCLogin; import java.io.File;import java.util.List; import org.bukkit.ChatColor;import org.bukkit.entity.Player;import org.bukkit.event.EventHandler;import org.bukkit.event.Listener;import org.bukkit.event.player.PlayerInteractEvent;import org.bukkit.plugin.PluginDescriptionFile;import org.bukkit.plugin.java.JavaPlugin; public class Main extends JavaPlugin implements Listener{ File f = new File("players.yml"); @Override public void onEnable(){ PluginDescriptionFile ymlFile = this.getDescription(); this.getLogger().info(ymlFile.getName() + " Version " + ymlFile.getVersion() + " is enabled!"); this.getLogger().info("This plugin is made by jkctech!"); this.getServer().getPluginManager().registerEvents(this, this); } @Override public void onDisable(){ PluginDescriptionFile ymlFile = this.getDescription(); this.getLogger().info(ymlFile.getName() + ymlFile.getVersion() + " is now disabled!"); } @EventHandler public void Interact(PlayerInteractEvent event) { List<String> players = getConfig().getStringList("players"); final Player p = event.getPlayer(); if(players.contains(p.getName())){event.setCancelled(true);} p.sendMessage(ChatColor.GOLD+"[JKC-Login] "+ChatColor.DARK_RED+"You need to login!"); }} 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.
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
Onlineids ok, so this is my whole code at this point: Code:java package me.jkctech.JKCLogin; import java.io.File; import org.bukkit.ChatColor;import org.bukkit.command.Command;import org.bukkit.command.CommandSender;import org.bukkit.entity.Player;import org.bukkit.event.Listener;import org.bukkit.plugin.PluginDescriptionFile;import org.bukkit.plugin.java.JavaPlugin; public class Main extends JavaPlugin implements Listener{ File f = new File("players.yml"); public void loadConfiguration(){ getConfig().options().copyDefaults(true); saveConfig(); } @Override public void onEnable(){ PluginDescriptionFile ymlFile = this.getDescription(); this.getLogger().info(ymlFile.getName() + " Version " + ymlFile.getVersion() + " is enabled!"); this.getLogger().info("This plugin is made by jkctech!"); this.getServer().getPluginManager().registerEvents(this, this); loadConfiguration(); } @Override public void onDisable(){ PluginDescriptionFile ymlFile = this.getDescription(); this.getLogger().info(ymlFile.getName() + ymlFile.getVersion() + " is now disabled!"); } public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { final Player p = (Player) sender; if(label.equalsIgnoreCase("jlogin") || label.equalsIgnoreCase("jkclogin")){ if(args.length == 4){ if(args[0].equalsIgnoreCase("add")){ getConfig().set("players."+p.getName(), args[1]); getConfig().set("players."+p.getName() + ".password", args[2]); getConfig().set("players."+p.getName() + ".email", args[3]); p.sendMessage(ChatColor.GOLD+"[JKC Login] "+ChatColor.GREEN+"Added "+args[1]+" to the players!"); } } } return true; } } 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!
Onlineids how do i check if a player exists in config, because if i check if it is null, it ouputs an error.
Onlineids i get this wierd bug. i have this code, which compares the password in the config file with the given argument: Code:java if(label.equalsIgnoreCase("login")){if(getConfig().getString("players."+p.getName()+".password") == args[0]){p.sendMessage("OK!");} else {p.sendMessage("NOT OK!");} 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!