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
|
|
|
|
{
|
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();
|
|
|
|
|
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);
|
2016-03-02 19:28:01 +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;
|
|
|
|
}
|
|
|
|
}
|