Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.climaxcraft.xenfororegister.bungee;
- import com.climaxcraft.xenfororegister.util.Database;
- import java.io.BufferedInputStream;
- import java.io.DataInputStream;
- import java.io.IOException;
- import java.net.HttpURLConnection;
- import java.net.MalformedURLException;
- import java.net.URL;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.util.logging.Logger;
- import java.util.regex.Pattern;
- import net.md_5.bungee.api.ChatColor;
- import net.md_5.bungee.api.CommandSender;
- import net.md_5.bungee.api.ProxyServer;
- import net.md_5.bungee.api.connection.ProxiedPlayer;
- import net.md_5.bungee.api.plugin.Command;
- import net.md_5.bungee.api.scheduler.TaskScheduler;
- import org.bukkit.entity.Player;
- import org.json.JSONException;
- import org.json.JSONObject;
- public class RegisterCommand
- extends Command
- {
- String prefix = "§4§lM.A.D. §8| ";
- protected RegisterCommand()
- {
- super("forum");
- }
- public static boolean isRegistered(ProxiedPlayer p) throws SQLException {
- //User ist in der ForenDB
- String statement = "SELECT COUNT(*) FROM `xf_user` WHERE username = '" + p.getName() + "';";
- ResultSet rs = XenforoRegister.instance.db.executeQueryWithResults(statement);
- if (rs.first()) {
- if (rs.getInt("COUNT(*)") == 1)
- {
- return true;
- } else {
- return false;
- }
- }
- return false;
- }
- public void execute(CommandSender commandSender, final String[] strings)
- {
- try
- {
- if (XenforoRegister.configObj.getString("apiKey").equalsIgnoreCase("xxxxxx"))
- {
- commandSender.sendMessage(ChatColor.DARK_RED + "Configuration for plugin not set up - please refer this message to an administrator.");return;
- }
- }
- catch (JSONException e)
- {
- e.printStackTrace();
- if ((commandSender instanceof ProxiedPlayer))
- {
- final ProxiedPlayer p = (ProxiedPlayer)commandSender;
- if (p.hasPermission("xr.register"))
- {
- if (strings.length == 2) {
- ProxyServer.getInstance().getScheduler().runAsync(XenforoRegister.instance, new Runnable()
- {
- public void run()
- {
- String password = strings[1];
- String email = strings[0];
- String[] emailproviderarray = email.split(Pattern.quote("@"));
- String emailprovider = "*" + emailproviderarray[1];
- try
- {
- if (XenforoRegister.configObj.getBoolean("enforceMaxRegistrations"))
- {
- String statement = "SELECT COUNT(*) FROM `xf_ban_email` WHERE banned_email = '" + emailprovider + "';";
- ResultSet rs = XenforoRegister.instance.db.executeQueryWithResults(statement);
- if ((rs.first()) &&
- (rs.getInt("COUNT(*)") == 1))
- {
- p.sendMessage(RegisterCommand.this.prefix + "§cBitte verwende eine richtige Emailadresse. Keine Trash-EMail!");
- return;
- }
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- try{
- 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"));
- HttpURLConnection conn = (HttpURLConnection)api.openConnection();
- conn.setInstanceFollowRedirects(true);
- DataInputStream result;
- DataInputStream result;
- if (conn.getResponseCode() == 400) {
- result = new DataInputStream(new BufferedInputStream(conn.getErrorStream()));
- } else {
- result = new DataInputStream(new BufferedInputStream(conn.getInputStream()));
- }
- String json = result.readLine();
- if (json == null) {
- p.sendMessage(RegisterCommand.this.prefix + ChatColor.RED + "Das hat nicht geklappt :/ - Bitte an einen Admin wenden!");
- }
- JSONObject obj = new JSONObject(json);
- if (!obj.has("error"))
- {
- p.sendMessage(RegisterCommand.this.prefix + "§6Fertig! §aDu hast dich erfolgreich in unserem Forum registriert. Forum: http://www.mad-gamble.net/forum");
- XenforoRegister.instance.getLogger().info(RegisterCommand.this.prefix + "User " + p.getName() + " has registered on the site.");
- }
- else
- {
- p.sendMessage(RegisterCommand.this.prefix + "§cDu hast dich bereits im Forum registriert!");
- }
- }
- catch (Exception e)
- {
- p.sendMessage(RegisterCommand.this.prefix + "§cDas hat nicht geklappt :/ Bitte an einen Admin wenden!");
- e.printStackTrace();
- }
- }
- });
- } else {
- p.sendMessage(this.prefix + ChatColor.RED + "Verwende: /forum <Email> <Passwort> um dich zu registrieren.");
- }
- }
- else {
- p.sendMessage(this.prefix + ChatColor.RED + "Keine Berechtigung.");
- }
- }
- else
- {
- commandSender.sendMessage(this.prefix + ChatColor.RED + "Dieser Befehl ist nur für Spieler.");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement