mirror of
https://github.com/TotalFreedomMC/TotalFreedomMod.git
synced 2024-11-19 01:40:22 +00:00
Readd Command_premium.java
This commit is contained in:
parent
ec6e8431e3
commit
8ce0defb52
1 changed files with 72 additions and 0 deletions
|
@ -0,0 +1,72 @@
|
|||
package me.StevenLawson.TotalFreedomMod.Commands;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import me.StevenLawson.TotalFreedomMod.TFM_Log;
|
||||
import org.apache.commons.lang.exception.ExceptionUtils;
|
||||
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 = AdminLevel.SUPER, source = SourceType.BOTH)
|
||||
@CommandParameters(description = "Validates if a given account is premium.", usage = "/<command> <player>", aliases = "prem")
|
||||
public class Command_premium extends TFM_Command
|
||||
{
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
if (args.length != 1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
String name;
|
||||
try
|
||||
{
|
||||
name = getPlayer(args[0]).getName();
|
||||
}
|
||||
catch (PlayerNotFoundException e)
|
||||
{
|
||||
name = args[0];
|
||||
}
|
||||
|
||||
final String playername = name;
|
||||
new BukkitRunnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
try
|
||||
{
|
||||
final URL getUrl = new URL("https://minecraft.net/haspaid.jsp?user=" + playername);
|
||||
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 " + playername + " is premium: " + message);
|
||||
}
|
||||
}.runTask(plugin);
|
||||
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
TFM_Log.severe(ExceptionUtils.getStackTrace(e));
|
||||
playerMsg("There was an error querying the mojang server.", ChatColor.RED);
|
||||
}
|
||||
}
|
||||
}.runTaskAsynchronously(plugin);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue