Advertisement
Guest User

Untitled

a guest
Jul 9th, 2016
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.56 KB | None | 0 0
  1. package com.climaxcraft.xenfororegister.bungee;
  2.  
  3. import java.sql.ResultSet;
  4. import java.sql.SQLException;
  5.  
  6. import net.md_5.bungee.api.ChatColor;
  7. import net.md_5.bungee.api.CommandSender;
  8. import net.md_5.bungee.api.connection.ProxiedPlayer;
  9. import net.md_5.bungee.api.plugin.Command;
  10.  
  11. public class RegisterCommand extends Command {
  12.  
  13. String prefix = "§4§lM.A.D. §8| ";
  14.  
  15. protected RegisterCommand() {
  16. super("forum");
  17. }
  18.  
  19. public static boolean isRegistered(ProxiedPlayer p) throws SQLException {
  20. // User ist in der ForenDB
  21. String statement = "SELECT COUNT(*) FROM `xf_user` WHERE username = '" + p.getName() + "';";
  22. ResultSet rs = XenforoRegister.instance.db.executeQueryWithResults(statement);
  23. if (rs.first()) {
  24. if (rs.getInt("COUNT(*)") == 1) {
  25. return true;
  26. } else {
  27. return false;
  28. }
  29. }
  30. return false;
  31. }
  32.  
  33. @SuppressWarnings("deprecation")
  34. public void execute(CommandSender commandSender, final String[] strings) {
  35. try {
  36. if (XenforoRegister.configObj.getString("apiKey").equalsIgnoreCase("xxxxxx")) {
  37. commandSender.sendMessage(ChatColor.DARK_RED
  38. + "Configuration for plugin not set up - please refer this message to an administrator.");
  39. return;
  40. }
  41. } catch (Exception e3) {
  42. e3.printStackTrace();
  43. if ((commandSender instanceof ProxiedPlayer)) {
  44. final ProxiedPlayer p = (ProxiedPlayer) commandSender;
  45. if (p.hasPermission("xr.register")) {
  46. if (strings.length == 2) {
  47. ProxyServer.getInstance().getScheduler().runAsync(XenforoRegister.instance, new Runnable() {
  48. public void run() {
  49. String password = strings[1];
  50. String email = strings[0];
  51. String[] emailproviderarray = email.split(Pattern.quote("@"));
  52. String emailprovider = "*" + emailproviderarray[1];
  53. try {
  54. if (XenforoRegister.configObj.getBoolean("enforceMaxRegistrations")) {
  55. String statement = "SELECT COUNT(*) FROM `xf_ban_email` WHERE banned_email = '"
  56. + emailprovider + "';";
  57. ResultSet rs = XenforoRegister.instance.db.executeQueryWithResults(statement);
  58. if ((rs.first()) && (rs.getInt("COUNT(*)") == 1)) {
  59. p.sendMessage(RegisterCommand.this.prefix
  60. + "§cBitte verwende eine richtige Emailadresse. Keine Trash-EMail!");
  61. return;
  62. }
  63. }
  64. } catch (Exception e) {
  65. e.printStackTrace();
  66. }
  67. try {
  68. URL api = new URL(XenforoRegister.configObj.getString("apiLoc")
  69. + "?action=register&hash=" + XenforoRegister.configObj.getString("apiKey")
  70. + "&username=" + p.getName() + "&password=" + password + "&email=" + email
  71. + "&user_state="
  72. + XenforoRegister.configObj.getString("default_user_state"));
  73. HttpURLConnection conn = (HttpURLConnection) api.openConnection();
  74. conn.setInstanceFollowRedirects(true);
  75. DataInputStream result;
  76. DataInputStream result;
  77. if (conn.getResponseCode() == 400) {
  78. result = new DataInputStream(new BufferedInputStream(conn.getErrorStream()));
  79. } else {
  80. result = new DataInputStream(new BufferedInputStream(conn.getInputStream()));
  81. }
  82. String json = result.readLine();
  83. if (json == null) {
  84. p.sendMessage(RegisterCommand.this.prefix + ChatColor.RED
  85. + "Das hat nicht geklappt :/ - Bitte an einen Admin wenden!");
  86. }
  87. JSONObject obj = new JSONObject(json);
  88. if (!obj.has("error")) {
  89. p.sendMessage(RegisterCommand.this.prefix
  90. + "§6Fertig! §aDu hast dich erfolgreich in unserem Forum registriert. Forum: http://www.mad-gamble.net/forum");
  91.  
  92. XenforoRegister.instance.getLogger().info(RegisterCommand.this.prefix + "User "
  93. + p.getName() + " has registered on the site.");
  94. } else {
  95. p.sendMessage(RegisterCommand.this.prefix
  96. + "§cDu hast dich bereits im Forum registriert!");
  97. }
  98. } catch (Exception e) {
  99. p.sendMessage(RegisterCommand.this.prefix
  100. + "§cDas hat nicht geklappt :/ Bitte an einen Admin wenden!");
  101. e.printStackTrace();
  102. }
  103. }
  104. });
  105. } else {
  106. p.sendMessage(this.prefix + ChatColor.RED
  107. + "Verwende: /forum <Email> <Passwort> um dich zu registrieren.");
  108. }
  109. } else {
  110. p.sendMessage(this.prefix + ChatColor.RED + "Keine Berechtigung.");
  111. }
  112. } else {
  113. commandSender.sendMessage(this.prefix + ChatColor.RED + "Dieser Befehl ist nur für Spieler.");
  114. }
  115. }
  116. }
  117. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement