Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package me.leoko.ban;
- import java.io.File;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.InputStreamReader;
- import java.io.PrintStream;
- import java.net.HttpURLConnection;
- import java.net.URL;
- import java.sql.Connection;
- import java.sql.DatabaseMetaData;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- import java.text.ParseException;
- import java.text.SimpleDateFormat;
- import java.util.ArrayList;
- import java.util.Date;
- import java.util.HashMap;
- import java.util.Iterator;
- import java.util.List;
- import java.util.Map;
- import java.util.Scanner;
- import java.util.Set;
- import java.util.concurrent.TimeUnit;
- import org.bukkit.Bukkit;
- import org.bukkit.ChatColor;
- import org.bukkit.OfflinePlayer;
- import org.bukkit.Server;
- import org.bukkit.command.Command;
- import org.bukkit.command.CommandSender;
- import org.bukkit.configuration.file.FileConfiguration;
- import org.bukkit.configuration.file.YamlConfiguration;
- import org.bukkit.entity.Player;
- import org.bukkit.event.EventHandler;
- import org.bukkit.event.EventPriority;
- import org.bukkit.event.Listener;
- import org.bukkit.event.player.PlayerCommandPreprocessEvent;
- import org.bukkit.event.server.ServerCommandEvent;
- import org.bukkit.plugin.PluginDescriptionFile;
- import org.bukkit.plugin.PluginManager;
- import org.bukkit.plugin.java.JavaPlugin;
- import org.bukkit.scheduler.BukkitScheduler;
- import org.json.simple.JSONObject;
- import org.json.simple.parser.JSONParser;
- public class main
- extends JavaPlugin
- implements Listener
- {
- public Events e;
- public Map<String, String> ips = new HashMap();
- public File confFile = new File(getDataFolder().getPath(), "config.yml");
- public FileConfiguration conf;
- public File banFile = new File(getDataFolder().getPath(), "bans.yml");
- public YamlConfiguration bans = YamlConfiguration.loadConfiguration(this.banFile);
- public File playerHistoryFile = new File(getDataFolder().getPath(), "playerHistory.yml");
- public YamlConfiguration ph = YamlConfiguration.loadConfiguration(this.playerHistoryFile);
- public File ignore = new File(getDataFolder().getPath(), "Ignore.Me");
- public Connection myConnT;
- public PreparedStatement myStmtT;
- public ResultSet myRs;
- public PreparedStatement myStmtPH;
- public ResultSet myRsPH;
- public String pre = "�cAdvancedBan";
- public boolean mysql = false;
- public boolean DenyNotify = false;
- public boolean loading = false;
- public boolean useUUID = true;
- public List<String> KKL = new ArrayList();
- public List<String> BBL = new ArrayList();
- public List<String> TTL = new ArrayList();
- public void onEnable()
- {
- regEvents();
- try
- {
- if (!this.ignore.exists())
- {
- this.ignore.mkdirs();
- try
- {
- this.ignore.createNewFile();
- }
- catch (IOException e)
- {
- e.printStackTrace();
- }
- Boolean reachable = Boolean.valueOf(false);
- if (Bukkit.getServer().getPort() == 25565) {
- reachable = Boolean.valueOf(ping("http://skampscraft-network.de/register/?Plugin=AdvancedBan-V7", 5000));
- } else {
- reachable = Boolean.valueOf(ping("http://skampscraft-network.de/register/?Plugin=AdvancedBan-V7&PORT=" + Bukkit.getServer().getPort(), 5000));
- }
- if (reachable.booleanValue()) {
- System.out.println("[AdvancedBan] Registered Plugin-Activity >> DONE");
- } else {
- System.out.println("[AdvancedBan] Registered Plugin-Activity >> FAILED");
- }
- }
- }
- catch (Exception exc)
- {
- System.out.println("[AdvancedBan] Failed to send Stats!\n Contact: Leoko4433@gmail.com \n Error Code: AC3244");
- }
- try
- {
- Metrics metrics = new Metrics(this);
- metrics.start();
- System.out.println("[AdvancedBan] MC-Stats >> Connected");
- }
- catch (IOException e)
- {
- System.out.println("[AdvancedBan] Failed to send Stats!\n Contact: Leoko4433@gmail.com \n Error Code: AB344");
- }
- System.setProperty("file.encoding", "UTF-8");
- if (!this.confFile.exists()) {
- saveResource("config.yml", false);
- }
- this.conf = YamlConfiguration.loadConfiguration(this.confFile);
- this.mysql = this.conf.getBoolean("MySQL.enabled");
- this.useUUID = this.conf.getBoolean("UseUUID");
- this.DenyNotify = this.conf.getBoolean("DenyNotify");
- this.loading = this.conf.getBoolean("LoadingMessage");
- this.pre = this.conf.getString("Prefix").replace('&', '�');
- this.KKL = this.conf.getStringList("KickLayout");
- this.BBL = this.conf.getStringList("BanLayout");
- this.TTL = this.conf.getStringList("TempbanLayout");
- if (this.mysql)
- {
- try
- {
- this.myConnT = DriverManager.getConnection("jdbc:mysql://" + this.conf.getString("MySQL.IP") + ":" + this.conf.getString("MySQL.Port") + "/" + this.conf.getString("MySQL.DB-Name"), this.conf.getString("MySQL.Username"), this.conf.getString("MySQL.Password"));
- DatabaseMetaData md = this.myConnT.getMetaData();
- ResultSet rs = md.getTables(null, null, "AdvancedBans", null);
- ResultSet rs2 = md.getTables(null, null, "PlayerHistory", null);
- if (!rs.next())
- {
- Statement Stmt = this.myConnT.createStatement();
- String sql = "CREATE TABLE `AdvancedBans` (`name` TEXT NULL DEFAULT NULL,`reason` TEXT NULL DEFAULT NULL,`until` TEXT NULL DEFAULT NULL)";
- Stmt.executeUpdate(sql);
- }
- if (!rs2.next())
- {
- Statement Stmt = this.myConnT.createStatement();
- String sql = "CREATE TABLE `PlayerHistory` (`uuid` TEXT NULL DEFAULT NULL,`name` TEXT NULL DEFAULT NULL,`reason` TEXT NULL DEFAULT NULL,`by` TEXT NULL DEFAULT NULL,`start` TEXT NULL DEFAULT NULL,`end` TEXT NULL DEFAULT NULL)";
- Stmt.executeUpdate(sql);
- }
- this.myStmtT = this.myConnT.prepareStatement("select * from AdvancedBans");
- this.myRs = this.myStmtT.executeQuery();
- this.myStmtPH = this.myConnT.prepareStatement("select * from PlayerHistory");
- this.myRs = this.myStmtPH.executeQuery();
- }
- catch (Exception exc)
- {
- this.mysql = false;
- exc.printStackTrace();
- }
- try
- {
- Bukkit.getScheduler().scheduleAsyncRepeatingTask(this, new Runnable()
- {
- public void run()
- {
- try
- {
- main.this.myConnT.close();
- main.this.myConnT = DriverManager.getConnection("jdbc:mysql://" + main.this.conf.getString("MySQL.IP") + ":" + main.this.conf.getString("MySQL.Port") + "/" + main.this.conf.getString("MySQL.DB-Name"), main.this.conf.getString("MySQL.Username"), main.this.conf.getString("MySQL.Password"));
- main.this.myStmtT = main.this.myConnT.prepareStatement("select * from AdvancedBans");
- main.this.myStmtPH = main.this.myConnT.prepareStatement("select * from PlayerHistory");
- main.this.myRs = main.this.myStmtT.executeQuery();
- main.this.myRsPH = main.this.myStmtPH.executeQuery();
- }
- catch (SQLException e)
- {
- main.this.mysql = false;
- e.printStackTrace();
- }
- }
- }, 72000L, 72000L);
- }
- catch (Exception exc)
- {
- exc.printStackTrace();
- }
- }
- getServer().getPluginManager().registerEvents(this, this);
- if (!this.banFile.exists()) {
- try
- {
- this.bans.save(this.banFile);
- }
- catch (IOException e)
- {
- e.printStackTrace();
- }
- }
- if (!this.playerHistoryFile.exists()) {
- try
- {
- this.ph.save(this.playerHistoryFile);
- }
- catch (IOException e)
- {
- e.printStackTrace();
- }
- }
- System.out.println("\n[=]---------------------------[=]\n-= AdvancedBan =-\nDev: Leoko\nStatus: Enabled\nLicense: Public\nLink: http://dev.bukkit.org/bukkit-plugins/advancedban/\nSupport [Skype/Mail]: Leoko33 / Leoko4433@gmail.com\nVersion: " +
- getDescription().getVersion() +
- "\n[=]---------------------------[=]");
- }
- public void onDisable()
- {
- System.out.println("\n[=]---------------------------[=]\n-= AdvancedBan =-\nDev: Leoko\nStatus: Disabled\nLicense: Public\nLink: http://dev.bukkit.org/bukkit-plugins/advancedban/\nSupport [Skype/Mail]: Leoko33 / Leoko4433@gmail.com\nVersion: " +
- getDescription().getVersion() +
- "\n[=]---------------------------[=]");
- }
- public boolean onCommand(final CommandSender sender, Command cmd, String cmdlable, String[] args)
- {
- Object p = sender;
- if (cmd.getName().equalsIgnoreCase("doNothing")) {
- return true;
- }
- if (cmd.getName().equalsIgnoreCase("advancedban"))
- {
- sendMessage(p, "�7�l�m-=====�r �3�lBanSystem �7�l�m=====-�r ");
- sendMessage(p, " �8�lDev �8� �7Leoko");
- sendMessage(p, " �8�lStatus �8� �a�oStabel");
- sendMessage(p, " �8�lVersion �8� �7" + getDescription().getVersion());
- sendMessage(p, " �8�lLicense �8� �7Public");
- sendMessage(p, " �8�lMySQL �8� �7" + Boolean.toString(this.mysql));
- sendMessage(p, " �8�lPrefix �8� �7" + this.pre);
- sendMessage(p, "�7�l�m-===================-�r ");
- return true;
- }
- if ((cmd.getName().equalsIgnoreCase("tempban")) ||
- (cmd.getName().equalsIgnoreCase("ban")) ||
- (cmd.getName().equalsIgnoreCase("ban-ip")) ||
- (cmd.getName().equalsIgnoreCase("kick")) ||
- (cmd.getName().equalsIgnoreCase("banip")) ||
- (cmd.getName().equalsIgnoreCase("check")) ||
- (cmd.getName().equalsIgnoreCase("history")) ||
- (cmd.getName().equalsIgnoreCase("unban")) ||
- (cmd.getName().equalsIgnoreCase("banlist")))
- {
- String sArgs = "";
- String[] arrayOfString;
- int j = (arrayOfString = args).length;
- for (int i = 0; i < j; i++)
- {
- String s = arrayOfString[i];sArgs = sArgs + " " + s;
- }
- final String sCmd = "/" + cmd.getName() + sArgs;
- Bukkit.getScheduler().scheduleAsyncDelayedTask(this, new Runnable()
- {
- public void run()
- {
- main.this.runCommand(sCmd, sender);
- }
- });
- return true;
- }
- return false;
- }
- @EventHandler(priority=EventPriority.HIGHEST)
- public void onCommandPlayer(final PlayerCommandPreprocessEvent ev)
- {
- if (ev.getMessage().startsWith("/pardon"))
- {
- sendMessage(ev.getPlayer(), this.pre + "�cThe /pardon command is only for VanillaBans use /unban for AdvancedBans");
- return;
- }
- String[] args = ev.getMessage().split(" ");
- if ((args[0].equalsIgnoreCase("/ban")) ||
- (args[0].equalsIgnoreCase("/tempban")) ||
- (args[0].equalsIgnoreCase("/ban-ip")) ||
- (args[0].equalsIgnoreCase("/banip")) ||
- (args[0].equalsIgnoreCase("/kick")) ||
- (args[0].equalsIgnoreCase("/check")) ||
- (args[0].equalsIgnoreCase("/history")) ||
- (args[0].equalsIgnoreCase("/unban")) ||
- (args[0].equalsIgnoreCase("/banlist")))
- {
- ev.setCancelled(true);
- if (this.loading) {
- sendMessage(ev.getPlayer(), getMSG("Loading", true));
- }
- }
- Bukkit.getScheduler().scheduleAsyncDelayedTask(this, new Runnable()
- {
- public void run()
- {
- main.this.runCommand(ev.getMessage(), ev.getPlayer());
- }
- });
- }
- @EventHandler(priority=EventPriority.MONITOR)
- public void onCommandConsole(final ServerCommandEvent ev)
- {
- if (ev.getCommand().startsWith("pardon"))
- {
- sendMessage(ev.getSender(), this.pre + "�cThe /pardon command is only for VanillaBans use /unban for AdvancedBans");
- return;
- }
- final String cmd = ev.getCommand();
- Bukkit.getScheduler().scheduleAsyncDelayedTask(this, new Runnable()
- {
- public void run()
- {
- main.this.runCommand("/" + cmd, ev.getSender());
- }
- });
- String[] args = ev.getCommand().split(" ");
- if ((args[0].equalsIgnoreCase("ban")) ||
- (args[0].equalsIgnoreCase("tempban")) ||
- (args[0].equalsIgnoreCase("ban-ip")) ||
- (args[0].equalsIgnoreCase("banip")) ||
- (args[0].equalsIgnoreCase("kick")) ||
- (args[0].equalsIgnoreCase("check")) ||
- (args[0].equalsIgnoreCase("history")) ||
- (args[0].equalsIgnoreCase("unban")) ||
- (args[0].equalsIgnoreCase("banlist")))
- {
- ev.setCommand("doNothing :)");
- if (this.loading) {
- sendMessage(ev.getSender(), getMSG("Loading", true));
- }
- }
- }
- public Boolean remBan(String name)
- {
- name = name.toLowerCase();
- if (Bukkit.getOfflinePlayer(name).isBanned()) {
- Bukkit.getOfflinePlayer(name).setBanned(false);
- }
- if ((!isChangedIP(name).booleanValue()) &&
- (getUUID(name) != null)) {
- name = getUUID(name);
- }
- if (this.mysql)
- {
- if (inBanned(name).booleanValue()) {
- try
- {
- String sql = "delete from AdvancedBans where name='" +
- name + "'";
- this.myStmtT.executeUpdate(sql);
- }
- catch (SQLException e)
- {
- e.printStackTrace();
- }
- } else {
- return Boolean.valueOf(false);
- }
- }
- else if (this.bans.contains(name))
- {
- this.bans.set(name, null);
- try
- {
- this.bans.save(this.banFile);
- }
- catch (IOException e)
- {
- e.printStackTrace();
- }
- }
- else
- {
- return Boolean.valueOf(false);
- }
- return Boolean.valueOf(true);
- }
- public Boolean addBan(String reason, String ending, String name, String by)
- {
- Boolean b = Boolean.valueOf(true);
- name = name.toLowerCase();
- if (getUUID(name) != null) {
- name = getUUID(name);
- }
- if (reason == null) {
- reason = "NoReason";
- }
- reason = reason + "#BannedBy#" + by;
- if (this.mysql)
- {
- reason = reason.replace('\'', '"').replace(')', ']').replace('(', '[');
- try
- {
- this.myStmtT = this.myConnT.prepareStatement("select * from AdvancedBans");
- this.myRs = this.myStmtT.executeQuery();
- this.myRs.beforeFirst();
- while (this.myRs.next()) {
- if (this.myRs.getString("name").equals(name)) {
- return Boolean.valueOf(false);
- }
- }
- String sql = "insert into AdvancedBans (name, reason, until) values ('" +
- name + "','" + reason + "','" + ending + "')";
- this.myStmtT.executeUpdate(sql);
- }
- catch (SQLException e)
- {
- e.printStackTrace();
- }
- }
- if (!this.bans.contains(name))
- {
- this.bans.createSection(name);
- this.bans.set(name + ".reason", reason);
- this.bans.set(name + ".ends", ending);
- try
- {
- this.bans.save(this.banFile);
- }
- catch (IOException e)
- {
- e.printStackTrace();
- }
- }
- else
- {
- b = Boolean.valueOf(false);
- }
- return b;
- }
- public void addHistoryEntry(String name, String reason, String by, Object ending)
- {
- String uuid = getUUID(name);
- if (reason == null) {
- reason = "none";
- }
- SimpleDateFormat ft = new SimpleDateFormat("dd.MM.yyyy-HH:mm:ss");
- String now = ft.format(new Date());
- if ((ending instanceof Date)) {
- ending = ft.format(ending);
- }
- if (this.mysql)
- {
- reason = reason.replace('\'', '"').replace(')', ']').replace('(', '[');
- try
- {
- String sql = " INSERT INTO `PlayerHistory` (`uuid`, `name`, `reason`, `by`, `start`, `end`) VALUES ('" +
- uuid + "','" + name + "','" + reason + "','" + by + "','" + now + "','" + ending + "')";
- this.myStmtPH.executeUpdate(sql);
- }
- catch (SQLException e)
- {
- e.printStackTrace();
- }
- }
- else
- {
- List<String> current = new ArrayList();
- if (this.ph.contains(uuid)) {
- current = this.ph.getStringList(uuid);
- }
- current.add(uuid + "#SPLIT#" + name + "#SPLIT#" + reason + "#SPLIT#" + by + "#SPLIT#" + now + "#SPLIT#" + ending);
- this.ph.set(uuid, current);
- try
- {
- this.ph.save(this.playerHistoryFile);
- }
- catch (IOException e)
- {
- e.printStackTrace();
- }
- }
- }
- public static boolean isNumeric(String str)
- {
- try
- {
- double d = Double.parseDouble(str);
- }
- catch (NumberFormatException nfe)
- {
- return false;
- }
- return true;
- }
- public void regEvents()
- {
- this.e = new Events(this);
- }
- public String getLayout(List<String> ls, String reason, String date, String betw)
- {
- String s = "";
- String by = null;
- if (reason.split("#BannedBy#").length > 1) {
- by = reason.split("#BannedBy#")[1];
- } else {
- by = "an Admin";
- }
- if (reason.startsWith("NoReason")) {
- reason = "Connection lost";
- } else if (reason.split("#BannedBy#").length > 1) {
- reason = reason.split("#BannedBy#")[0];
- }
- for (String str : ls) {
- s = s + str.replaceAll("%OPERATOR%", by).replaceAll("%REMAINING%", betw).replaceAll("%REASON%", reason).replaceAll("%DATE%", date).replaceAll("%PREFIX%", this.pre).replace('&', '�') + "\n";
- }
- return s;
- }
- public Boolean inBanned(String name)
- {
- name = name.toLowerCase();
- try
- {
- this.myStmtT = this.myConnT.prepareStatement("select * from AdvancedBans");
- this.myRs = this.myStmtT.executeQuery();
- this.myRs.beforeFirst();
- while (this.myRs.next()) {
- if (this.myRs.getString("name").equals(name)) {
- return Boolean.valueOf(true);
- }
- }
- }
- catch (SQLException e)
- {
- e.printStackTrace();
- }
- return Boolean.valueOf(false);
- }
- public Boolean isIP(String ip)
- {
- if (ip.split("\\.").length != 4) {
- return Boolean.valueOf(false);
- }
- if (!isNumeric(ip.split("\\.")[0])) {
- return Boolean.valueOf(false);
- }
- if (!isNumeric(ip.split("\\.")[1])) {
- return Boolean.valueOf(false);
- }
- if (!isNumeric(ip.split("\\.")[2])) {
- return Boolean.valueOf(false);
- }
- if (!isNumeric(ip.split("\\.")[3])) {
- return Boolean.valueOf(false);
- }
- return Boolean.valueOf(true);
- }
- public Boolean isChangedIP(String ip)
- {
- if (ip.split("-").length != 4) {
- return Boolean.valueOf(false);
- }
- if (!isNumeric(ip.split("-")[0])) {
- return Boolean.valueOf(false);
- }
- if (!isNumeric(ip.split("-")[1])) {
- return Boolean.valueOf(false);
- }
- if (!isNumeric(ip.split("-")[2])) {
- return Boolean.valueOf(false);
- }
- if (!isNumeric(ip.split("-")[3])) {
- return Boolean.valueOf(false);
- }
- return Boolean.valueOf(true);
- }
- public static boolean ping(String url, int timeout)
- {
- url = url.replaceFirst("^https", "http");
- try
- {
- HttpURLConnection connection = (HttpURLConnection)new URL(url).openConnection();
- connection.setConnectTimeout(timeout);
- connection.setReadTimeout(timeout);
- connection.setRequestMethod("HEAD");
- int responseCode = connection.getResponseCode();
- return (200 <= responseCode) && (responseCode <= 399);
- }
- catch (IOException exception) {}
- return false;
- }
- public boolean runCommand(String command, final Object sender)
- {
- Boolean cancle = Boolean.valueOf(false);
- final String[] args = command.split(" ");
- if (args.length != 0)
- {
- if (args[0].equalsIgnoreCase("/unban"))
- {
- cancle = Boolean.valueOf(true);
- if (hasPermission(sender, "ban.unban"))
- {
- if (args.length == 2)
- {
- String name = args[1];
- if (isIP(name).booleanValue()) {
- name = name.replaceAll("\\.", "-");
- }
- if (remBan(name).booleanValue()) {
- sendMessage(sender, getMSG("Unbanned", true).replaceAll("%PLAYER%", args[1]));
- } else {
- sendMessage(sender, getMSG("NotBanned", true).replaceAll("%PLAYER%", args[1]));
- }
- }
- else
- {
- sendMessage(sender, getMSG("UsageUnban", true));
- }
- }
- else {
- sendMessage(sender, getMSG("NoPerms", true));
- }
- }
- if (args[0].equalsIgnoreCase("/kick"))
- {
- cancle = Boolean.valueOf(true);
- if (hasPermission(sender, "ban.kick"))
- {
- if (args.length > 1)
- {
- if (Bukkit.getOfflinePlayer(args[1]).isOnline())
- {
- if (!Bukkit.getPlayer(args[1]).hasPermission("kick.exempt"))
- {
- String grund = null;
- if (args.length > 2)
- {
- Integer i = Integer.valueOf(3);
- grund = args[2];
- while (i.intValue() != args.length)
- {
- grund = grund + " " + args[i.intValue()];
- i = Integer.valueOf(i.intValue() + 1);
- }
- }
- sendMessage(sender, getMSG("Kicked", true).replaceAll("%PLAYER%", args[1]));
- if (grund != null) {
- sendMessage(sender, getMSG("Reason", false) + grund);
- }
- Player[] arrayOfPlayer1;
- int j = (arrayOfPlayer1 = Bukkit.getOnlinePlayers()).length;
- for (int i = 0; i < j; i++)
- {
- Player op = arrayOfPlayer1[i];
- if ((op.hasPermission("kick.notify")) && (!op.equals(sender)))
- {
- op.sendMessage(getMSG("Kicked", true).replaceAll("%PLAYER%", args[1]));
- if (grund != null) {
- op.sendMessage(getMSG("Reason", false) + grund);
- }
- }
- }
- final String nGrund = grund;
- Bukkit.getScheduler().runTask(this, new Runnable()
- {
- public void run()
- {
- if (nGrund != null) {
- Bukkit.getPlayer(args[1]).kickPlayer(main.this.getLayout(main.this.KKL, nGrund + "#BannedBy#" + main.this.getName(sender), null, null));
- } else {
- Bukkit.getPlayer(args[1]).kickPlayer(main.this.getLayout(main.this.KKL, "You got kicked#BannedBy#" + main.this.getName(sender), null, null));
- }
- }
- });
- addHistoryEntry(args[1], grund, getName(sender), "KICK");
- }
- else
- {
- sendMessage(sender, getMSG("KickExempt", true));
- }
- }
- else {
- sendMessage(sender, getMSG("NotOnline", true));
- }
- }
- else {
- sendMessage(sender, getMSG("UsageKick", true));
- }
- }
- else {
- sendMessage(sender, getMSG("NoPerms", true));
- }
- }
- SimpleDateFormat ft;
- Integer mon;
- Object month;
- if (args[0].equalsIgnoreCase("/tempban"))
- {
- cancle = Boolean.valueOf(true);
- if (hasPermission(sender, "ban.tempban"))
- {
- if (args.length > 3)
- {
- if ((Bukkit.getOfflinePlayer(args[1]).isOnline()) &&
- (Bukkit.getPlayer(args[1]).hasPermission("ban.exempt")))
- {
- sendMessage(sender, getMSG("BanExempt", true));
- return true;
- }
- if (isNumeric(args[2]))
- {
- if ((args[3].equalsIgnoreCase("S")) || (args[3].equalsIgnoreCase("M")) || (args[3].equalsIgnoreCase("H")) || (args[3].equalsIgnoreCase("D")) || (args[3].equalsIgnoreCase("W")) || (args[3].equalsIgnoreCase("Mo")) || (args[3].equalsIgnoreCase("Y")))
- {
- if (!canTempban(sender, Integer.valueOf(Integer.parseInt(args[2])), args[3].toLowerCase()).booleanValue())
- {
- sendMessage(sender, getMSG("NoPerms", true));
- return true;
- }
- final Date unbanAt = new Date();
- if (args[3].equalsIgnoreCase("S")) {
- unbanAt.setSeconds(unbanAt.getSeconds() + Integer.parseInt(args[2]));
- }
- if (args[3].equalsIgnoreCase("H")) {
- unbanAt.setHours(unbanAt.getHours() + Integer.parseInt(args[2]));
- }
- if (args[3].equalsIgnoreCase("M")) {
- unbanAt.setMinutes(unbanAt.getMinutes() + Integer.parseInt(args[2]));
- }
- if (args[3].equalsIgnoreCase("D")) {
- unbanAt.setDate(unbanAt.getDate() + Integer.parseInt(args[2]));
- }
- if (args[3].equalsIgnoreCase("W")) {
- unbanAt.setDate(unbanAt.getDate() + Integer.parseInt(args[2]) * 7);
- }
- if (args[3].equalsIgnoreCase("Mo")) {
- unbanAt.setDate(unbanAt.getDate() + Integer.parseInt(args[2]) * 30);
- }
- if (args[3].equalsIgnoreCase("Y")) {
- unbanAt.setYear(unbanAt.getYear() + Integer.parseInt(args[2]));
- }
- String grund = null;
- if (args.length > 4)
- {
- Integer i = Integer.valueOf(5);
- grund = args[4];
- while (i.intValue() != args.length)
- {
- grund = grund + " " + args[i.intValue()];
- i = Integer.valueOf(i.intValue() + 1);
- }
- }
- ft = new SimpleDateFormat("dd.MM.yyyy-HH:mm:ss");
- if (addBan(grund, ft.format(unbanAt), args[1], getName(sender)).booleanValue())
- {
- sendMessage(sender, getMSG("Banned", true).replaceAll("%PLAYER%", args[1]));
- if (grund != null) {
- sendMessage(sender, getMSG("Reason", false) + grund);
- }
- mon = Integer.valueOf(unbanAt.getMonth());
- month = null;
- if (mon.intValue() == 0) {
- month = "Jan";
- }
- if (mon.intValue() == 1) {
- month = "Feb";
- }
- if (mon.intValue() == 2) {
- month = "Mar";
- }
- if (mon.intValue() == 3) {
- month = "Apr";
- }
- if (mon.intValue() == 4) {
- month = "May";
- }
- if (mon.intValue() == 5) {
- month = "June";
- }
- if (mon.intValue() == 6) {
- month = "July";
- }
- if (mon.intValue() == 7) {
- month = "Aug";
- }
- if (mon.intValue() == 8) {
- month = "Sept";
- }
- if (mon.intValue() == 9) {
- month = "Oct";
- }
- if (mon.intValue() == 10) {
- month = "Nov";
- }
- if (mon.intValue() == 11) {
- month = "Dec";
- }
- sendMessage(sender, getMSG("Until", false) + " �7" + unbanAt.getDate() + " " + (String)month + ". at " + unbanAt.getHours() + ":" + unbanAt.getMinutes() + ":" + unbanAt.getSeconds());
- Player[] arrayOfPlayer2;
- int m = (arrayOfPlayer2 = Bukkit.getOnlinePlayers()).length;
- for (int k = 0; k < m; k++)
- {
- Player op = arrayOfPlayer2[k];
- if ((op.hasPermission("ban.notify")) && (!op.equals(sender)) &&
- (op != sender))
- {
- op.sendMessage(getMSG("Banned", true).replaceAll("%PLAYER%", args[1]));
- if (grund != null) {
- op.sendMessage(getMSG("Reason", false) + grund);
- }
- op.sendMessage(getMSG("Until", false) + unbanAt.getDate() + " " + (String)month + ". at " + unbanAt.getHours() + ":" + unbanAt.getMinutes() + ":" + unbanAt.getSeconds());
- }
- }
- if (Bukkit.getOfflinePlayer(args[1]).isOnline())
- {
- final String date = unbanAt.getDate() + "." + (String)month + ". at " + unbanAt.getHours() + ":" + unbanAt.getMinutes() + ":" + unbanAt.getSeconds();
- final String nGrund = grund;
- Bukkit.getScheduler().runTask(this, new Runnable()
- {
- public void run()
- {
- if (nGrund != null) {
- Bukkit.getPlayer(args[1]).kickPlayer(main.this.getLayout(main.this.TTL, nGrund + "#BannedBy#" + main.this.getName(sender), date, main.this.e.caltcBetween(unbanAt, new Date())));
- } else {
- Bukkit.getPlayer(args[1]).kickPlayer(main.this.getLayout(main.this.TTL, "You got banned temporary#BannedBy#" + main.this.getName(sender), date, main.this.e.caltcBetween(unbanAt, new Date())));
- }
- }
- });
- }
- addHistoryEntry(args[1], grund, getName(sender), unbanAt);
- }
- else
- {
- sendMessage(sender, getMSG("AlreadyBanned", true).replaceAll("%PLAYER%", args[1]));
- }
- }
- else
- {
- sendMessage(sender, getMSG("UsageTempBan", true));
- }
- }
- else {
- sendMessage(sender, getMSG("UsageTempBan", true));
- }
- }
- else
- {
- sendMessage(sender, getMSG("UsageTempBan", true));
- }
- }
- else {
- sendMessage(sender, getMSG("NoPerms", true));
- }
- }
- if (args[0].equalsIgnoreCase("/ban"))
- {
- cancle = Boolean.valueOf(true);
- if (hasPermission(sender, "ban.ban"))
- {
- if (args.length > 1)
- {
- if ((Bukkit.getOfflinePlayer(args[1]).isOnline()) &&
- (Bukkit.getPlayer(args[1]).hasPermission("ban.exempt")))
- {
- sendMessage(sender, getMSG("BanExempt", true));
- return true;
- }
- String grund = null;
- if (args.length > 2)
- {
- Integer i = Integer.valueOf(3);
- grund = args[2];
- while (i.intValue() != args.length)
- {
- grund = grund + " " + args[i.intValue()];
- i = Integer.valueOf(i.intValue() + 1);
- }
- }
- if (addBan(grund, "never", args[1], getName(sender)).booleanValue())
- {
- sendMessage(sender, getMSG("Banned", true).replaceAll("%PLAYER%", args[1]));
- if (grund != null) {
- sendMessage(sender, getMSG("Reason", false) + grund);
- }
- SimpleDateFormat localSimpleDateFormat2 = (month = Bukkit.getOnlinePlayers()).length;
- for (SimpleDateFormat localSimpleDateFormat1 = 0; localSimpleDateFormat1 < localSimpleDateFormat2; localSimpleDateFormat1++)
- {
- Player op = month[localSimpleDateFormat1];
- if ((op.hasPermission("ban.notify")) && (!op.equals(sender)) &&
- (op != sender))
- {
- op.sendMessage(getMSG("Banned", true).replaceAll("%PLAYER%", args[1]));
- if (grund != null) {
- op.sendMessage(getMSG("Reason", false) + grund);
- }
- }
- }
- if (Bukkit.getOfflinePlayer(args[1]).isOnline())
- {
- final String nGrund = grund;
- Bukkit.getScheduler().runTask(this, new Runnable()
- {
- public void run()
- {
- if (nGrund != null) {
- Bukkit.getPlayer(args[1]).kickPlayer(main.this.getLayout(main.this.BBL, nGrund + "#BannedBy#" + main.this.getName(sender), null, null));
- } else {
- Bukkit.getPlayer(args[1]).kickPlayer(main.this.getLayout(main.this.BBL, "You got banned#BannedBy#" + main.this.getName(sender), null, null));
- }
- }
- });
- }
- addHistoryEntry(args[1], grund, getName(sender), "BAN");
- }
- else
- {
- sendMessage(sender, getMSG("AlreadyBanned", true).replaceAll("%PLAYER%", args[1]));
- }
- }
- else
- {
- sendMessage(sender, getMSG("UsageBan", true));
- }
- }
- else {
- sendMessage(sender, getMSG("NoPerms", true));
- }
- }
- Object unbanAt;
- String str;
- if (args[0].equalsIgnoreCase("/banlist"))
- {
- cancle = Boolean.valueOf(true);
- List<String> bl = new ArrayList();
- List<String> toRem = new ArrayList();
- if (this.mysql) {
- try
- {
- this.myStmtT = this.myConnT.prepareStatement("select * from AdvancedBans");
- this.myRs = this.myStmtT.executeQuery();
- this.myRs.beforeFirst();
- while (this.myRs.next()) {
- if (!this.myRs.getString("until").equalsIgnoreCase("never"))
- {
- SimpleDateFormat ft = new SimpleDateFormat("dd.MM.yyyy-HH:mm:ss");
- unbanAt = null;
- try
- {
- unbanAt = ft.parse(this.myRs.getString("until"));
- }
- catch (ParseException e1)
- {
- e1.printStackTrace();
- }
- if (((Date)unbanAt).before(new Date())) {
- toRem.add(this.myRs.getString("name"));
- } else {
- bl.add(this.myRs.getString("name") + "-=#=-" + this.myRs.getString("reason") + "-=#=-" + this.myRs.getString("until"));
- }
- }
- else
- {
- bl.add(this.myRs.getString("name") + "-=#=-" + this.myRs.getString("reason") + "-=#=-" + this.myRs.getString("until"));
- }
- }
- }
- catch (SQLException e)
- {
- e.printStackTrace();
- }
- } else {
- for (unbanAt = this.bans.getKeys(false).iterator(); ((Iterator)unbanAt).hasNext();)
- {
- String s = (String)((Iterator)unbanAt).next();
- if (!this.bans.getString(s + ".ends").equalsIgnoreCase("never"))
- {
- SimpleDateFormat ft = new SimpleDateFormat("dd.MM.yyyy-HH:mm:ss");
- Date unbanAt = null;
- try
- {
- unbanAt = ft.parse(this.bans.getString(s + ".ends"));
- }
- catch (ParseException e1)
- {
- ((ParseException)e1).printStackTrace();
- }
- if (unbanAt.before(new Date())) {
- toRem.add(s);
- } else {
- bl.add(s + "-=#=-" + this.bans.getString(new StringBuilder(String.valueOf(s)).append(".reason").toString()) + "-=#=-" + this.bans.getString(new StringBuilder(String.valueOf(s)).append(".ends").toString()));
- }
- }
- else
- {
- bl.add(s + "-=#=-" + this.bans.getString(new StringBuilder(String.valueOf(s)).append(".reason").toString()) + "-=#=-" + this.bans.getString(new StringBuilder(String.valueOf(s)).append(".ends").toString()));
- }
- }
- }
- for (unbanAt = toRem.iterator(); ((Iterator)unbanAt).hasNext();)
- {
- String s = (String)((Iterator)unbanAt).next();
- remBan(s);
- }
- toRem.clear();
- String s;
- for (unbanAt = this.conf.getStringList("BanListLayout.Header").iterator(); ((Iterator)unbanAt).hasNext(); sendMessage(sender, s.replace('&', '�'))) {
- s = (String)((Iterator)unbanAt).next();
- }
- for (unbanAt = bl.iterator(); ((Iterator)unbanAt).hasNext();)
- {
- String s = (String)((Iterator)unbanAt).next();
- try
- {
- String name = "";
- if (isChangedIP(s.split("-=#=-")[0]).booleanValue())
- {
- name = s.split("-=#=-")[0].replaceAll("-", "\\.");
- }
- else
- {
- name = s.split("-=#=-")[0];
- if (getNameFromUUID(name) != null) {
- name = getNameFromUUID(name);
- }
- }
- for (e1 = this.conf.getStringList("BanListLayout.Entry").iterator(); ((Iterator)e1).hasNext();)
- {
- str = (String)((Iterator)e1).next();
- sendMessage(sender, str.replaceAll("%NAME%", name)
- .replaceAll("%UNTIL%", s.split("-=#=-")[2])
- .replaceAll("%BY%", s.split("-=#=-")[1].split("#BannedBy#")[1])
- .replaceAll("%REASON%", s.split("-=#=-")[1].split("#BannedBy#")[0])
- .replace('&', '�'));
- }
- }
- catch (IndexOutOfBoundsException localIndexOutOfBoundsException1) {}
- }
- sendMessage(sender, this.conf.getString("BanListLayout.Footer").replaceAll("%NO%", bl.size()).replace('&', '�'));
- }
- Object localObject1;
- if ((args[0].equalsIgnoreCase("/ban-ip")) || (args[0].equalsIgnoreCase("/banip")))
- {
- cancle = Boolean.valueOf(true);
- if (hasPermission(sender, "ban.ipban"))
- {
- if (args.length > 1)
- {
- if ((Bukkit.getOfflinePlayer(args[1]).isOnline()) &&
- (Bukkit.getPlayer(args[1]).hasPermission("ban.exempt")))
- {
- sendMessage(sender, getMSG("BanExempt", true));
- return true;
- }
- String grund = null;
- if (args.length > 2)
- {
- Integer i = Integer.valueOf(3);
- grund = args[2];
- while (i.intValue() != args.length)
- {
- grund = grund + " " + args[i.intValue()];
- i = Integer.valueOf(i.intValue() + 1);
- }
- }
- if ((!isIP(args[1]).booleanValue()) && (!Bukkit.getOfflinePlayer(args[1]).isOnline()) && (!this.ips.containsKey(args[1].toLowerCase())))
- {
- sendMessage(sender, getMSG("NotOnline", true));
- return true;
- }
- String player = args[1];
- if (Bukkit.getOfflinePlayer(args[1]).isOnline()) {
- player = Bukkit.getPlayer(args[1]).getAddress().toString().split("/")[(Bukkit.getPlayer(args[1]).getAddress().toString().split("/").length - 1)].split(":")[0].replaceAll("\\.", "-");
- } else if (isIP(args[1]).booleanValue()) {
- player = player.replaceAll("\\.", "-");
- } else {
- player = ((String)this.ips.get(player.toLowerCase())).replaceAll("\\.", "-");
- }
- if (addBan(grund, "never", player, getName(sender)).booleanValue())
- {
- sendMessage(sender, getMSG("Banned", true).replaceAll("%PLAYER%", args[1]));
- if (grund != null) {
- sendMessage(sender, getMSG("Reason", false) + grund);
- }
- Date localDate1 = (str = Bukkit.getOnlinePlayers()).length;
- for (localObject1 = 0; localObject1 < localDate1; localObject1++)
- {
- Player op = str[localObject1];
- if ((op.hasPermission("ban.notify")) &&
- (op != sender))
- {
- op.sendMessage(getMSG("Banned", true).replaceAll("%PLAYER%", args[1]));
- if (grund != null) {
- op.sendMessage(getMSG("Reason", false) + grund);
- }
- }
- }
- if (Bukkit.getOfflinePlayer(args[1]).isOnline())
- {
- final String nGrund = grund;
- Bukkit.getScheduler().runTask(this, new Runnable()
- {
- public void run()
- {
- if (nGrund != null) {
- Bukkit.getPlayer(args[1]).kickPlayer(main.this.getLayout(main.this.BBL, nGrund + "#BannedBy#" + main.this.getName(sender), null, null));
- } else {
- Bukkit.getPlayer(args[1]).kickPlayer(main.this.getLayout(main.this.BBL, "You got banned#BannedBy#" + main.this.getName(sender), null, null));
- }
- }
- });
- }
- }
- else
- {
- sendMessage(sender, getMSG("AlreadyBanned", true).replaceAll("%PLAYER%", args[1]));
- }
- }
- else
- {
- sendMessage(sender, getMSG("UsageIpBan", true));
- }
- }
- else {
- sendMessage(sender, getMSG("NoPerms", true));
- }
- }
- if (args[0].equalsIgnoreCase("/history"))
- {
- cancle = Boolean.valueOf(true);
- if ((args.length == 1) || (args.length == 2)) {
- sendMessage(sender, getMSG("UsagePlayerHistory", true));
- } else if (args[1].equalsIgnoreCase("get"))
- {
- if (hasPermission(sender, "ban.history.get"))
- {
- List<String> curr = new ArrayList();
- String uuid = getUUID(args[2]);
- if (this.mysql) {
- try
- {
- this.myRsPH = this.myConnT.prepareStatement("select * from PlayerHistory").executeQuery();
- this.myRsPH.beforeFirst();
- while (this.myRsPH.next()) {
- if (this.myRsPH.getString("uuid").equalsIgnoreCase(uuid)) {
- curr.add(uuid + " #SPLIT# " + this.myRsPH.getString("name") +
- " #SPLIT# " + this.myRsPH.getString("reason") +
- " #SPLIT# " + this.myRsPH.getString("by") +
- " #SPLIT# " + this.myRsPH.getString("start") +
- " #SPLIT# " + this.myRsPH.getString("end"));
- }
- }
- }
- catch (SQLException e)
- {
- e.printStackTrace();
- }
- } else if (this.ph.contains(uuid)) {
- curr = this.ph.getStringList(uuid);
- }
- if (curr.isEmpty())
- {
- sendMessage(sender, getMSG("NoPlayerHistory", true));
- }
- else
- {
- sendMessage(sender, "�8");
- sendMessage(sender, "�8");
- sendMessage(sender, getMSG("PlayerHistory", true));
- for (localObject1 = curr.iterator(); ((Iterator)localObject1).hasNext();)
- {
- String s = (String)((Iterator)localObject1).next();
- String[] sl = s.split("#SPLIT#");
- String type = "";
- try
- {
- SimpleDateFormat ft = new SimpleDateFormat("dd.MM.yyyy-HH:mm:ss");
- l = Long.valueOf(ft.parse(sl[5]).getTime() - ft.parse(sl[4]).getTime());
- if (TimeUnit.MILLISECONDS.toHours(((Long)l).longValue()) > 0L) {
- type = "TEMP-BAN [" + TimeUnit.MILLISECONDS.toHours(((Long)l).longValue()) + " h]";
- } else {
- type = "TEMP-BAN [" + TimeUnit.MILLISECONDS.toMinutes(((Long)l).longValue()) + " min]";
- }
- }
- catch (Exception exc)
- {
- type = sl[5];
- }
- sendMessage(sender, "�7");
- for (Object l = this.conf.getStringList("HistoryLayout").iterator(); ((Iterator)l).hasNext();)
- {
- String str = (String)((Iterator)l).next();
- sendMessage(sender, str.replaceAll("%NAME%", sl[1])
- .replaceAll("%DATE%", sl[4])
- .replaceAll("%BY%", sl[3])
- .replaceAll("%TYPE%", type)
- .replaceAll("%REASON%", sl[2]).replace('&', '�'));
- }
- sendMessage(sender, "�7");
- }
- sendMessage(sender, "�8");
- }
- }
- else
- {
- sendMessage(sender, getMSG("NoPerms", true));
- }
- }
- else if (args[1].equalsIgnoreCase("clear"))
- {
- if (hasPermission(sender, "ban.history.clear"))
- {
- String uuid = getUUID(args[2]);
- if (this.mysql)
- {
- try
- {
- this.myConnT.prepareStatement("DELETE FROM PlayerHistory WHERE uuid = '" + uuid + "'").execute();
- }
- catch (SQLException e)
- {
- e.printStackTrace();
- }
- }
- else
- {
- this.ph.set(uuid, null);
- try
- {
- this.ph.save(this.playerHistoryFile);
- }
- catch (IOException e)
- {
- e.printStackTrace();
- }
- }
- sendMessage(sender, getMSG("RemovedPlayerHistory", true).replaceAll("%PLAYER%", args[2]));
- }
- else
- {
- sendMessage(sender, getMSG("NoPerms", true));
- }
- }
- else {
- sendMessage(sender, getMSG("UsagePlayerHistory", true));
- }
- }
- if (args[0].equalsIgnoreCase("/check"))
- {
- cancle = Boolean.valueOf(true);
- if (hasPermission(sender, "ban.check"))
- {
- if (args.length == 1)
- {
- sendMessage(sender, getMSG("UsageCheck", true));
- }
- else
- {
- Boolean banned = Boolean.valueOf(false);
- String name = args[1];
- if (this.mysql)
- {
- if (inBanned(args[1].toLowerCase()).booleanValue())
- {
- banned = Boolean.valueOf(true);
- name = args[1].toLowerCase();
- }
- else if ((getUUID(name) != null) &&
- (inBanned(getUUID(name)).booleanValue()))
- {
- banned = Boolean.valueOf(true);
- name = getUUID(name);
- }
- }
- else if (this.bans.contains(args[1].toLowerCase()))
- {
- banned = Boolean.valueOf(true);
- name = args[1].toLowerCase();
- }
- else if ((getUUID(name) != null) &&
- (this.bans.contains(getUUID(name))))
- {
- banned = Boolean.valueOf(true);
- name = getUUID(name);
- }
- if (banned.booleanValue())
- {
- String reason = null;
- String ending = null;
- if (this.mysql)
- {
- try
- {
- this.myRs = this.myStmtT.executeQuery();
- this.myRs.beforeFirst();
- while (this.myRs.next()) {
- if (this.myRs.getString("name").equals(name))
- {
- reason = this.myRs.getString("reason");
- ending = this.myRs.getString("until");
- }
- }
- }
- catch (SQLException ex)
- {
- ex.printStackTrace();
- }
- }
- else
- {
- reason = this.bans.getString(name + ".reason");
- ending = this.bans.getString(name + ".ends");
- }
- if (ending.equalsIgnoreCase("never"))
- {
- if (!reason.split("#BannedBy#")[0].equalsIgnoreCase("NoReason"))
- {
- sendMessage(sender, getMSG("IsBanned", true).replaceAll("%PLAYER%", args[1]));
- sendMessage(sender, getMSG("EndingIn", false) + "never");
- sendMessage(sender, getMSG("Reason", false) + reason.split("#BannedBy#")[0]);
- sendMessage(sender, getMSG("BannedBy", false) + reason.split("#BannedBy#")[1]);
- }
- else
- {
- sendMessage(sender, getMSG("IsBanned", true).replaceAll("%PLAYER%", args[1]));
- sendMessage(sender, getMSG("EndingIn", false) + "never");
- sendMessage(sender, getMSG("Reason", false) + "none");
- sendMessage(sender, getMSG("BannedBy", false) + reason.split("#BannedBy#")[1]);
- }
- }
- else
- {
- SimpleDateFormat ft = new SimpleDateFormat("dd.MM.yyyy-HH:mm:ss");
- Date unbanAt = null;
- try
- {
- unbanAt = ft.parse(ending);
- }
- catch (ParseException e1)
- {
- e1.printStackTrace();
- }
- if (unbanAt.before(new Date()))
- {
- remBan(name);
- sendMessage(sender, "�aPlayer " + args[1] + " is not banned");
- }
- else if (!reason.split("#BannedBy#")[0].equalsIgnoreCase("NoReason"))
- {
- sendMessage(sender, getMSG("IsBanned", true).replaceAll("%PLAYER%", args[1]));
- sendMessage(sender, getMSG("EndingIn", false) + this.e.caltcBetween(unbanAt, new Date()));
- sendMessage(sender, getMSG("Reason", false) + reason.split("#BannedBy#")[0]);
- sendMessage(sender, getMSG("BannedBy", false) + reason.split("#BannedBy#")[1]);
- }
- else
- {
- sendMessage(sender, getMSG("IsBanned", true).replaceAll("%PLAYER%", args[1]));
- sendMessage(sender, getMSG("EndingIn", false) + this.e.caltcBetween(unbanAt, new Date()));
- sendMessage(sender, getMSG("Reason", false) + "none");
- sendMessage(sender, getMSG("BannedBy", false) + reason.split("#BannedBy#")[1]);
- }
- }
- }
- else
- {
- sendMessage(sender, getMSG("NotBanned", true).replaceAll("%PLAYER%", args[1]));
- }
- }
- }
- else {
- sendMessage(sender, getMSG("NoPerms", true));
- }
- }
- }
- return cancle.booleanValue();
- }
- public void sendMessage(Object target, String msg)
- {
- if ((target instanceof Player)) {
- ((Player)target).sendMessage(msg);
- } else {
- System.out.println(ChatColor.stripColor(msg));
- }
- }
- public String getName(Object target)
- {
- if ((target instanceof Player)) {
- return ((Player)target).getName();
- }
- return "Console";
- }
- public boolean hasPermission(Object target, String perm)
- {
- if ((target instanceof Player))
- {
- if (((Player)target).hasPermission(perm)) {
- return true;
- }
- return false;
- }
- return true;
- }
- public String getUUID(String name)
- {
- if (!this.useUUID) {
- return name;
- }
- try
- {
- URL url = new URL("https://api.mojang.com/users/profiles/minecraft/" + name + "?at=" + new Date().getTime());
- HttpURLConnection request = (HttpURLConnection)url.openConnection();
- request.connect();
- JSONParser jp = new JSONParser();
- JSONObject json = (JSONObject)jp.parse(new InputStreamReader((InputStream)request.getContent()));
- return json.get("id").toString();
- }
- catch (Exception exc) {}
- return null;
- }
- public String getNameFromUUID(String uuid)
- {
- if (!this.useUUID) {
- return uuid;
- }
- try
- {
- String s = new Scanner(new URL("https://api.mojang.com/user/profiles/" + uuid + "/names").openStream(), "UTF-8").useDelimiter("\\A").next();
- s = s.substring(s.lastIndexOf('{'), s.lastIndexOf('}') + 1);
- return ((JSONObject)new JSONParser().parse(s)).get("name").toString();
- }
- catch (Exception e) {}
- return null;
- }
- public Boolean canTempban(Object sender, Integer dur, String type)
- {
- Integer h = Integer.valueOf(0);
- if (hasPermission(sender, "ban.admin")) {
- return Boolean.valueOf(true);
- }
- if (type.equals("s")) {
- return Boolean.valueOf(true);
- }
- if (type.equals("m")) {
- return Boolean.valueOf(true);
- }
- if (type.equals("h")) {
- h = dur;
- }
- if (type.equals("d")) {
- h = Integer.valueOf(dur.intValue() * 24);
- }
- if (type.equals("w")) {
- h = Integer.valueOf(dur.intValue() * 24 * 7);
- }
- if (type.equals("mo")) {
- h = Integer.valueOf(dur.intValue() * 24 * 30);
- }
- if (type.equals("y")) {
- h = Integer.valueOf(dur.intValue() * 24 * 300);
- }
- Integer max = Integer.valueOf(720);
- while (max.intValue() != 0)
- {
- if (hasPermission(sender, "ban.tempban.maxHours." + max)) {
- break;
- }
- max = Integer.valueOf(max.intValue() - 1);
- }
- if (max.intValue() == 0) {
- return Boolean.valueOf(true);
- }
- if (h.intValue() > max.intValue()) {
- return Boolean.valueOf(false);
- }
- return Boolean.valueOf(true);
- }
- public String getMSG(String path, boolean pre)
- {
- String s = null;
- path = "ChatMessages." + path;
- try
- {
- s = this.conf.getString(path);
- }
- catch (Exception exc)
- {
- exc.printStackTrace();
- }
- if (s == null)
- {
- System.out.println("\n \n--===[AdvancdedBan-ERROR]===--\nErrorType: Config-Error\nError: Could not find the message under the path " +
- path.replace('.', '>') +
- "\nReportIt?: No" +
- "\nHELP Skype: Leoko33" +
- "\n--============================--\n ");
- return "�4ERROR! See Console for ErrorLog";
- }
- if (pre) {
- s = this.pre + " " + s;
- }
- return s.replace('&', '�');
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement