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;
|
|
|
|
import java.io.InputStreamReader;
|
|
|
|
import java.net.URL;
|
|
|
|
import java.net.URLConnection;
|
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;
|
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;
|
|
|
|
|
2016-03-06 15:56:15 +00:00
|
|
|
@CommandPermissions(level = Rank.SUPER_ADMIN, 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)
|
2013-08-14 13:32:14 +00:00
|
|
|
{
|
2014-04-26 11:55:24 +00:00
|
|
|
name = player.getName();
|
2013-08-14 13:32:14 +00:00
|
|
|
}
|
2014-04-26 11:55:24 +00:00
|
|
|
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
|
|
|
|
{
|
2016-10-02 21:05:03 +00:00
|
|
|
final URL getUrl = new URL("http://axis.iaero.me/accstatus?username=" + name + "&format=plain");
|
2013-08-14 13:32:14 +00:00
|
|
|
final URLConnection urlConnection = getUrl.openConnection();
|
2016-10-02 21:05:03 +00:00
|
|
|
final String message;
|
|
|
|
try ( // Read the response
|
2018-07-31 06:41:56 +00:00
|
|
|
BufferedReader in = new BufferedReader(new InputStreamReader(urlConnection.getInputStream())))
|
2016-10-02 21:05:03 +00:00
|
|
|
{
|
|
|
|
message = (!"PREMIUM".equalsIgnoreCase(in.readLine()) ? ChatColor.RED + "No" : ChatColor.DARK_GREEN + "Yes");
|
|
|
|
}
|
2013-08-14 13:32:14 +00:00
|
|
|
|
2016-05-12 19:40:39 +00:00
|
|
|
if (!plugin.isEnabled())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-08-14 13:32:14 +00:00
|
|
|
new BukkitRunnable()
|
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public void run()
|
|
|
|
{
|
2016-03-02 19:28:01 +00:00
|
|
|
msg("Player " + name + " is premium: " + message);
|
2013-08-14 13:32:14 +00:00
|
|
|
}
|
|
|
|
}.runTask(plugin);
|
|
|
|
|
|
|
|
}
|
2013-08-14 14:01:42 +00:00
|
|
|
catch (Exception ex)
|
2013-08-14 13:32:14 +00:00
|
|
|
{
|
2015-10-19 17:43:46 +00:00
|
|
|
FLog.severe(ex);
|
2018-07-25 02:44:00 +00:00
|
|
|
msg("There was an error querying the Mojang 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;
|
|
|
|
}
|
|
|
|
}
|