TotalFreedomMod/src/me/totalfreedom/totalfreedommod/commands/Command_premium.java

74 lines
2.4 KiB
Java
Raw Normal View History

package me.totalfreedom.totalfreedommod.commands;
2013-08-14 13:32:14 +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;
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;
@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")
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;
}
final Player player = getPlayer(args[0]);
final String name;
if (player != null)
2013-08-14 13:32:14 +00:00
{
name = player.getName();
2013-08-14 13:32:14 +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
{
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()
{
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
{
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;
}
}