Advertisement
Guest User

Untitled

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