2015-10-19 17:43:46 +00:00
|
|
|
package me.totalfreedom.totalfreedommod.commands;
|
2013-08-14 13:32:14 +00:00
|
|
|
|
2015-10-19 17:43:46 +00:00
|
|
|
import me.totalfreedom.totalfreedommod.permission.PlayerRank;
|
2013-08-14 13:32:14 +00:00
|
|
|
import java.io.BufferedReader;
|
|
|
|
import java.io.InputStreamReader;
|
|
|
|
import java.net.URL;
|
|
|
|
import java.net.URLConnection;
|
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;
|
|
|
|
|
2015-10-19 17:43:46 +00:00
|
|
|
@CommandPermissions(level = PlayerRank.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
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
|
|
|
{
|
|
|
|
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
|
|
|
|
{
|
2014-04-26 11:55:24 +00:00
|
|
|
final URL getUrl = new URL("https://minecraft.net/haspaid.jsp?user=" + name);
|
2013-08-14 13:32:14 +00:00
|
|
|
final URLConnection urlConnection = getUrl.openConnection();
|
|
|
|
// Read the response
|
|
|
|
final BufferedReader in = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
|
|
|
|
final String message = ("false".equalsIgnoreCase(in.readLine()) ? ChatColor.RED + "No" : ChatColor.DARK_GREEN + "Yes");
|
|
|
|
in.close();
|
|
|
|
|
|
|
|
new BukkitRunnable()
|
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public void run()
|
|
|
|
{
|
2014-04-26 11:55:24 +00:00
|
|
|
playerMsg("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);
|
2013-08-14 13:32:14 +00:00
|
|
|
playerMsg("There was an error querying the mojang server.", ChatColor.RED);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}.runTaskAsynchronously(plugin);
|
2013-08-18 19:52:32 +00:00
|
|
|
|
2013-08-14 13:32:14 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|