1 |
torben |
1786 |
package dk.thoerup.bukkit.hoeruputils.web; |
2 |
|
|
|
3 |
torben |
3207 |
/* |
4 |
torben |
1786 |
import java.math.BigInteger; |
5 |
|
|
import java.security.MessageDigest; |
6 |
|
|
import java.security.NoSuchAlgorithmException; |
7 |
|
|
|
8 |
|
|
import org.bukkit.command.Command; |
9 |
|
|
import org.bukkit.command.CommandExecutor; |
10 |
|
|
import org.bukkit.command.CommandSender; |
11 |
|
|
import org.bukkit.entity.Player; |
12 |
|
|
import org.bukkit.plugin.Plugin; |
13 |
|
|
|
14 |
torben |
3203 |
import io.ebean.Ebean; |
15 |
|
|
|
16 |
torben |
1786 |
public class WebUserCommand implements CommandExecutor { |
17 |
|
|
|
18 |
|
|
Plugin plugin; |
19 |
|
|
|
20 |
torben |
3203 |
public WebUserCommand(Plugin plugin) { |
21 |
torben |
1786 |
this.plugin = plugin; |
22 |
torben |
3203 |
|
23 |
|
|
Ebean.getDefaultServer().find(WebUser.class).findCount(); |
24 |
|
|
|
25 |
|
|
|
26 |
torben |
1786 |
} |
27 |
|
|
|
28 |
|
|
@Override |
29 |
|
|
public boolean onCommand(CommandSender sender, Command command, |
30 |
|
|
String label, String[] args) { |
31 |
|
|
|
32 |
|
|
if (!(sender instanceof Player)) { |
33 |
|
|
sender.sendMessage("This is not a console command!"); |
34 |
|
|
return true; |
35 |
|
|
} |
36 |
|
|
|
37 |
|
|
if (args.length != 1) { |
38 |
|
|
sender.sendMessage("Usage: /webuser <new_password>"); |
39 |
|
|
return true; |
40 |
|
|
} |
41 |
|
|
|
42 |
|
|
String password = args[0]; |
43 |
|
|
|
44 |
torben |
3203 |
WebUser user = Ebean.getDefaultServer().find(WebUser.class).where() |
45 |
torben |
1786 |
.eq("user", sender.getName()).findUnique(); |
46 |
|
|
if (user == null) { |
47 |
|
|
user = new WebUser(); |
48 |
|
|
user.setUser(sender.getName()); |
49 |
|
|
} |
50 |
|
|
|
51 |
|
|
MessageDigest md5 = null; |
52 |
|
|
try { |
53 |
|
|
md5 = MessageDigest.getInstance("MD5"); |
54 |
|
|
} catch (NoSuchAlgorithmException e) { |
55 |
|
|
e.printStackTrace(); |
56 |
|
|
} |
57 |
|
|
md5.update(password.getBytes(), 0, password.length()); |
58 |
|
|
String pwd = new BigInteger(1,md5.digest()).toString(16); |
59 |
|
|
if (pwd.length() == 31) { |
60 |
|
|
pwd = "0" + pwd; |
61 |
|
|
} |
62 |
|
|
|
63 |
|
|
user.setPassword(pwd); |
64 |
torben |
3203 |
Ebean.getDefaultServer().save(user); |
65 |
torben |
1786 |
|
66 |
|
|
sender.sendMessage("Your web password has been set"); |
67 |
|
|
|
68 |
|
|
return true; |
69 |
|
|
} |
70 |
|
|
|
71 |
torben |
3207 |
}*/ |