2016-03-02 19:28:01 +00:00
|
|
|
package me.totalfreedom.totalfreedommod.command;
|
2013-08-14 13:32:14 +00:00
|
|
|
|
|
|
|
import java.io.BufferedReader;
|
2019-07-31 16:19:23 +00:00
|
|
|
import java.io.FileNotFoundException;
|
2013-08-14 13:32:14 +00:00
|
|
|
import java.io.InputStreamReader;
|
2019-07-31 16:19:23 +00:00
|
|
|
import java.net.HttpURLConnection;
|
2013-08-14 13:32:14 +00:00
|
|
|
import java.net.URL;
|
|
|
|
import java.net.URLConnection;
|
2019-08-02 20:57:42 +00:00
|
|
|
import java.io.IOException;
|
2016-03-06 15:56:15 +00:00
|
|
|
import me.totalfreedom.totalfreedommod.rank.Rank;
|
2015-10-19 17:43:46 +00:00
|
|
|
import me.totalfreedom.totalfreedommod.util.FLog;
|
2019-08-02 20:56:56 +00:00
|
|
|
import me.totalfreedom.totalfreedommod.util.FSync;
|
2013-08-14 13:32:14 +00:00
|
|
|
import org.bukkit.ChatColor;
|
|
|
|
import org.bukkit.command.Command;
|
|
|
|
import org.bukkit.command.CommandSender;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.scheduler.BukkitRunnable;
|
|
|
|
|
2019-07-31 00:31:31 +00:00
|
|
|
@CommandPermissions(level = Rank.OP, source = SourceType.BOTH)
|
2013-08-14 13:32:14 +00:00
|
|
|
@CommandParameters(description = "Validates if a given account is premium.", usage = "/<command> <player>", aliases = "prem")
|
2015-10-19 17:43:46 +00:00
|
|
|
public class Command_premium extends FreedomCommand
|
2013-08-14 13:32:14 +00:00
|
|
|
{
|
2015-11-22 18:26:47 +00:00
|
|
|
|
2013-08-14 13:32:14 +00:00
|
|
|
@Override
|
2015-11-22 18:26:47 +00:00
|
|
|
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
2013-08-14 13:32:14 +00:00
|
|
|
{
|
|
|
|
if (args.length != 1)
|
|
|
|
return false;
|
|
|
|
|
2014-04-26 11:55:24 +00:00
|
|
|
final Player player = getPlayer(args[0]);
|
|
|
|
final String name;
|
2014-05-04 21:03:34 +00:00
|
|
|
|
2014-04-26 11:55:24 +00:00
|
|
|
if (player != null)
|
|
|
|
name = player.getName();
|
|
|
|
else
|
2013-08-14 13:32:14 +00:00
|
|
|
name = args[0];
|
2013-08-18 19:52:32 +00:00
|
|
|
|
2013-08-14 13:32:14 +00:00
|
|
|
new BukkitRunnable()
|
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public void run()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2019-07-31 16:19:23 +00:00
|
|
|
final URL getUrl = new URL("https://api.ashcon.app/mojang/v2/user/" + name);
|
|
|
|
final HttpURLConnection urlConnection = (HttpURLConnection)getUrl.openConnection();
|
|
|
|
urlConnection.setRequestProperty("User-Agent", "");
|
2019-08-02 20:56:56 +00:00
|
|
|
String message = "";
|
|
|
|
/*old code
|
|
|
|
BufferedReader in = new BufferedReader(new InputStreamReader(urlConnection.getInputStream())))
|
|
|
|
//message = (!"PREMIUM".equalsIgnoreCase(in.readLine()) ? ChatColor.RED + "No" : ChatColor.DARK_GREEN + "Yes");
|
|
|
|
*/
|
|
|
|
try
|
2016-10-02 21:05:03 +00:00
|
|
|
{
|
2019-07-31 16:19:23 +00:00
|
|
|
if (urlConnection.getResponseCode() == 200)
|
2019-08-02 20:56:56 +00:00
|
|
|
message = ChatColor.GREEN + "Yes";
|
2019-07-31 16:19:23 +00:00
|
|
|
else
|
2019-08-02 20:56:56 +00:00
|
|
|
message = ChatColor.RED + "No";
|
|
|
|
FSync.playerMsg(sender, "Player " + name + " is premium: " + message);
|
2019-07-31 16:19:23 +00:00
|
|
|
}
|
2019-08-02 20:56:56 +00:00
|
|
|
catch (IOException e)
|
2016-05-12 19:40:39 +00:00
|
|
|
{
|
2019-08-02 20:56:56 +00:00
|
|
|
FSync.playerMsg(sender, ChatColor.RED + "There was an error on trying to connect to the API server");
|
2016-05-12 19:40:39 +00:00
|
|
|
}
|
2019-08-02 20:56:56 +00:00
|
|
|
|
2013-08-14 13:32:14 +00:00
|
|
|
}
|
2019-08-02 20:56:56 +00:00
|
|
|
catch (IOException ex)
|
2013-08-14 13:32:14 +00:00
|
|
|
{
|
2015-10-19 17:43:46 +00:00
|
|
|
FLog.severe(ex);
|
2019-07-31 16:19:23 +00:00
|
|
|
msg("There was an error querying the API server.", ChatColor.RED);
|
2013-08-14 13:32:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}.runTaskAsynchronously(plugin);
|
2013-08-18 19:52:32 +00:00
|
|
|
|
2013-08-14 13:32:14 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|