Advertisement
Guest User

main.class

a guest
Dec 21st, 2015
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 54.94 KB | None | 0 0
  1. package me.leoko.ban;
  2.  
  3. import java.io.File;
  4. import java.io.IOException;
  5. import java.io.InputStream;
  6. import java.io.InputStreamReader;
  7. import java.io.PrintStream;
  8. import java.net.HttpURLConnection;
  9. import java.net.URL;
  10. import java.sql.Connection;
  11. import java.sql.DatabaseMetaData;
  12. import java.sql.DriverManager;
  13. import java.sql.PreparedStatement;
  14. import java.sql.ResultSet;
  15. import java.sql.SQLException;
  16. import java.sql.Statement;
  17. import java.text.ParseException;
  18. import java.text.SimpleDateFormat;
  19. import java.util.ArrayList;
  20. import java.util.Date;
  21. import java.util.HashMap;
  22. import java.util.Iterator;
  23. import java.util.List;
  24. import java.util.Map;
  25. import java.util.Scanner;
  26. import java.util.Set;
  27. import java.util.concurrent.TimeUnit;
  28. import org.bukkit.Bukkit;
  29. import org.bukkit.ChatColor;
  30. import org.bukkit.OfflinePlayer;
  31. import org.bukkit.Server;
  32. import org.bukkit.command.Command;
  33. import org.bukkit.command.CommandSender;
  34. import org.bukkit.configuration.file.FileConfiguration;
  35. import org.bukkit.configuration.file.YamlConfiguration;
  36. import org.bukkit.entity.Player;
  37. import org.bukkit.event.EventHandler;
  38. import org.bukkit.event.EventPriority;
  39. import org.bukkit.event.Listener;
  40. import org.bukkit.event.player.PlayerCommandPreprocessEvent;
  41. import org.bukkit.event.server.ServerCommandEvent;
  42. import org.bukkit.plugin.PluginDescriptionFile;
  43. import org.bukkit.plugin.PluginManager;
  44. import org.bukkit.plugin.java.JavaPlugin;
  45. import org.bukkit.scheduler.BukkitScheduler;
  46. import org.json.simple.JSONObject;
  47. import org.json.simple.parser.JSONParser;
  48.  
  49. public class main
  50. extends JavaPlugin
  51. implements Listener
  52. {
  53. public Events e;
  54. public Map<String, String> ips = new HashMap();
  55. public File confFile = new File(getDataFolder().getPath(), "config.yml");
  56. public FileConfiguration conf;
  57. public File banFile = new File(getDataFolder().getPath(), "bans.yml");
  58. public YamlConfiguration bans = YamlConfiguration.loadConfiguration(this.banFile);
  59. public File playerHistoryFile = new File(getDataFolder().getPath(), "playerHistory.yml");
  60. public YamlConfiguration ph = YamlConfiguration.loadConfiguration(this.playerHistoryFile);
  61. public File ignore = new File(getDataFolder().getPath(), "Ignore.Me");
  62. public Connection myConnT;
  63. public PreparedStatement myStmtT;
  64. public ResultSet myRs;
  65. public PreparedStatement myStmtPH;
  66. public ResultSet myRsPH;
  67. public String pre = "�cAdvancedBan";
  68. public boolean mysql = false;
  69. public boolean DenyNotify = false;
  70. public boolean loading = false;
  71. public boolean useUUID = true;
  72. public List<String> KKL = new ArrayList();
  73. public List<String> BBL = new ArrayList();
  74. public List<String> TTL = new ArrayList();
  75.  
  76. public void onEnable()
  77. {
  78. regEvents();
  79. try
  80. {
  81. if (!this.ignore.exists())
  82. {
  83. this.ignore.mkdirs();
  84. try
  85. {
  86. this.ignore.createNewFile();
  87. }
  88. catch (IOException e)
  89. {
  90. e.printStackTrace();
  91. }
  92. Boolean reachable = Boolean.valueOf(false);
  93. if (Bukkit.getServer().getPort() == 25565) {
  94. reachable = Boolean.valueOf(ping("http://skampscraft-network.de/register/?Plugin=AdvancedBan-V7", 5000));
  95. } else {
  96. reachable = Boolean.valueOf(ping("http://skampscraft-network.de/register/?Plugin=AdvancedBan-V7&PORT=" + Bukkit.getServer().getPort(), 5000));
  97. }
  98. if (reachable.booleanValue()) {
  99. System.out.println("[AdvancedBan] Registered Plugin-Activity >> DONE");
  100. } else {
  101. System.out.println("[AdvancedBan] Registered Plugin-Activity >> FAILED");
  102. }
  103. }
  104. }
  105. catch (Exception exc)
  106. {
  107. System.out.println("[AdvancedBan] Failed to send Stats!\n Contact: Leoko4433@gmail.com \n Error Code: AC3244");
  108. }
  109. try
  110. {
  111. Metrics metrics = new Metrics(this);
  112. metrics.start();
  113. System.out.println("[AdvancedBan] MC-Stats >> Connected");
  114. }
  115. catch (IOException e)
  116. {
  117. System.out.println("[AdvancedBan] Failed to send Stats!\n Contact: Leoko4433@gmail.com \n Error Code: AB344");
  118. }
  119. System.setProperty("file.encoding", "UTF-8");
  120. if (!this.confFile.exists()) {
  121. saveResource("config.yml", false);
  122. }
  123. this.conf = YamlConfiguration.loadConfiguration(this.confFile);
  124.  
  125. this.mysql = this.conf.getBoolean("MySQL.enabled");
  126. this.useUUID = this.conf.getBoolean("UseUUID");
  127. this.DenyNotify = this.conf.getBoolean("DenyNotify");
  128. this.loading = this.conf.getBoolean("LoadingMessage");
  129. this.pre = this.conf.getString("Prefix").replace('&', '�');
  130.  
  131. this.KKL = this.conf.getStringList("KickLayout");
  132. this.BBL = this.conf.getStringList("BanLayout");
  133. this.TTL = this.conf.getStringList("TempbanLayout");
  134. if (this.mysql)
  135. {
  136. try
  137. {
  138. 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"));
  139. DatabaseMetaData md = this.myConnT.getMetaData();
  140. ResultSet rs = md.getTables(null, null, "AdvancedBans", null);
  141. ResultSet rs2 = md.getTables(null, null, "PlayerHistory", null);
  142. if (!rs.next())
  143. {
  144. Statement Stmt = this.myConnT.createStatement();
  145.  
  146. String sql = "CREATE TABLE `AdvancedBans` (`name` TEXT NULL DEFAULT NULL,`reason` TEXT NULL DEFAULT NULL,`until` TEXT NULL DEFAULT NULL)";
  147.  
  148. Stmt.executeUpdate(sql);
  149. }
  150. if (!rs2.next())
  151. {
  152. Statement Stmt = this.myConnT.createStatement();
  153. 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)";
  154.  
  155. Stmt.executeUpdate(sql);
  156. }
  157. this.myStmtT = this.myConnT.prepareStatement("select * from AdvancedBans");
  158. this.myRs = this.myStmtT.executeQuery();
  159. this.myStmtPH = this.myConnT.prepareStatement("select * from PlayerHistory");
  160. this.myRs = this.myStmtPH.executeQuery();
  161. }
  162. catch (Exception exc)
  163. {
  164. this.mysql = false;
  165. exc.printStackTrace();
  166. }
  167. try
  168. {
  169. Bukkit.getScheduler().scheduleAsyncRepeatingTask(this, new Runnable()
  170. {
  171. public void run()
  172. {
  173. try
  174. {
  175. main.this.myConnT.close();
  176. 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"));
  177. main.this.myStmtT = main.this.myConnT.prepareStatement("select * from AdvancedBans");
  178. main.this.myStmtPH = main.this.myConnT.prepareStatement("select * from PlayerHistory");
  179. main.this.myRs = main.this.myStmtT.executeQuery();
  180. main.this.myRsPH = main.this.myStmtPH.executeQuery();
  181. }
  182. catch (SQLException e)
  183. {
  184. main.this.mysql = false;
  185. e.printStackTrace();
  186. }
  187. }
  188. }, 72000L, 72000L);
  189. }
  190. catch (Exception exc)
  191. {
  192. exc.printStackTrace();
  193. }
  194. }
  195. getServer().getPluginManager().registerEvents(this, this);
  196. if (!this.banFile.exists()) {
  197. try
  198. {
  199. this.bans.save(this.banFile);
  200. }
  201. catch (IOException e)
  202. {
  203. e.printStackTrace();
  204. }
  205. }
  206. if (!this.playerHistoryFile.exists()) {
  207. try
  208. {
  209. this.ph.save(this.playerHistoryFile);
  210. }
  211. catch (IOException e)
  212. {
  213. e.printStackTrace();
  214. }
  215. }
  216. 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: " +
  217.  
  218. getDescription().getVersion() +
  219. "\n[=]---------------------------[=]");
  220. }
  221.  
  222. public void onDisable()
  223. {
  224. 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: " +
  225.  
  226. getDescription().getVersion() +
  227. "\n[=]---------------------------[=]");
  228. }
  229.  
  230. public boolean onCommand(final CommandSender sender, Command cmd, String cmdlable, String[] args)
  231. {
  232. Object p = sender;
  233. if (cmd.getName().equalsIgnoreCase("doNothing")) {
  234. return true;
  235. }
  236. if (cmd.getName().equalsIgnoreCase("advancedban"))
  237. {
  238. sendMessage(p, "�7�l�m-=====�r �3�lBanSystem �7�l�m=====-�r ");
  239. sendMessage(p, " �8�lDev �8� �7Leoko");
  240. sendMessage(p, " �8�lStatus �8� �a�oStabel");
  241. sendMessage(p, " �8�lVersion �8� �7" + getDescription().getVersion());
  242. sendMessage(p, " �8�lLicense �8� �7Public");
  243. sendMessage(p, " �8�lMySQL �8� �7" + Boolean.toString(this.mysql));
  244. sendMessage(p, " �8�lPrefix �8� �7" + this.pre);
  245. sendMessage(p, "�7�l�m-===================-�r ");
  246. return true;
  247. }
  248. if ((cmd.getName().equalsIgnoreCase("tempban")) ||
  249. (cmd.getName().equalsIgnoreCase("ban")) ||
  250. (cmd.getName().equalsIgnoreCase("ban-ip")) ||
  251. (cmd.getName().equalsIgnoreCase("kick")) ||
  252. (cmd.getName().equalsIgnoreCase("banip")) ||
  253. (cmd.getName().equalsIgnoreCase("check")) ||
  254. (cmd.getName().equalsIgnoreCase("history")) ||
  255. (cmd.getName().equalsIgnoreCase("unban")) ||
  256. (cmd.getName().equalsIgnoreCase("banlist")))
  257. {
  258. String sArgs = "";
  259. String[] arrayOfString;
  260. int j = (arrayOfString = args).length;
  261. for (int i = 0; i < j; i++)
  262. {
  263. String s = arrayOfString[i];sArgs = sArgs + " " + s;
  264. }
  265. final String sCmd = "/" + cmd.getName() + sArgs;
  266. Bukkit.getScheduler().scheduleAsyncDelayedTask(this, new Runnable()
  267. {
  268. public void run()
  269. {
  270. main.this.runCommand(sCmd, sender);
  271. }
  272. });
  273. return true;
  274. }
  275. return false;
  276. }
  277.  
  278. @EventHandler(priority=EventPriority.HIGHEST)
  279. public void onCommandPlayer(final PlayerCommandPreprocessEvent ev)
  280. {
  281. if (ev.getMessage().startsWith("/pardon"))
  282. {
  283. sendMessage(ev.getPlayer(), this.pre + "�cThe /pardon command is only for VanillaBans use /unban for AdvancedBans");
  284. return;
  285. }
  286. String[] args = ev.getMessage().split(" ");
  287. if ((args[0].equalsIgnoreCase("/ban")) ||
  288. (args[0].equalsIgnoreCase("/tempban")) ||
  289. (args[0].equalsIgnoreCase("/ban-ip")) ||
  290. (args[0].equalsIgnoreCase("/banip")) ||
  291. (args[0].equalsIgnoreCase("/kick")) ||
  292. (args[0].equalsIgnoreCase("/check")) ||
  293. (args[0].equalsIgnoreCase("/history")) ||
  294. (args[0].equalsIgnoreCase("/unban")) ||
  295. (args[0].equalsIgnoreCase("/banlist")))
  296. {
  297. ev.setCancelled(true);
  298. if (this.loading) {
  299. sendMessage(ev.getPlayer(), getMSG("Loading", true));
  300. }
  301. }
  302. Bukkit.getScheduler().scheduleAsyncDelayedTask(this, new Runnable()
  303. {
  304. public void run()
  305. {
  306. main.this.runCommand(ev.getMessage(), ev.getPlayer());
  307. }
  308. });
  309. }
  310.  
  311. @EventHandler(priority=EventPriority.MONITOR)
  312. public void onCommandConsole(final ServerCommandEvent ev)
  313. {
  314. if (ev.getCommand().startsWith("pardon"))
  315. {
  316. sendMessage(ev.getSender(), this.pre + "�cThe /pardon command is only for VanillaBans use /unban for AdvancedBans");
  317. return;
  318. }
  319. final String cmd = ev.getCommand();
  320. Bukkit.getScheduler().scheduleAsyncDelayedTask(this, new Runnable()
  321. {
  322. public void run()
  323. {
  324. main.this.runCommand("/" + cmd, ev.getSender());
  325. }
  326. });
  327. String[] args = ev.getCommand().split(" ");
  328. if ((args[0].equalsIgnoreCase("ban")) ||
  329. (args[0].equalsIgnoreCase("tempban")) ||
  330. (args[0].equalsIgnoreCase("ban-ip")) ||
  331. (args[0].equalsIgnoreCase("banip")) ||
  332. (args[0].equalsIgnoreCase("kick")) ||
  333. (args[0].equalsIgnoreCase("check")) ||
  334. (args[0].equalsIgnoreCase("history")) ||
  335. (args[0].equalsIgnoreCase("unban")) ||
  336. (args[0].equalsIgnoreCase("banlist")))
  337. {
  338. ev.setCommand("doNothing :)");
  339. if (this.loading) {
  340. sendMessage(ev.getSender(), getMSG("Loading", true));
  341. }
  342. }
  343. }
  344.  
  345. public Boolean remBan(String name)
  346. {
  347. name = name.toLowerCase();
  348. if (Bukkit.getOfflinePlayer(name).isBanned()) {
  349. Bukkit.getOfflinePlayer(name).setBanned(false);
  350. }
  351. if ((!isChangedIP(name).booleanValue()) &&
  352. (getUUID(name) != null)) {
  353. name = getUUID(name);
  354. }
  355. if (this.mysql)
  356. {
  357. if (inBanned(name).booleanValue()) {
  358. try
  359. {
  360. String sql = "delete from AdvancedBans where name='" +
  361.  
  362. name + "'";
  363. this.myStmtT.executeUpdate(sql);
  364. }
  365. catch (SQLException e)
  366. {
  367. e.printStackTrace();
  368. }
  369. } else {
  370. return Boolean.valueOf(false);
  371. }
  372. }
  373. else if (this.bans.contains(name))
  374. {
  375. this.bans.set(name, null);
  376. try
  377. {
  378. this.bans.save(this.banFile);
  379. }
  380. catch (IOException e)
  381. {
  382. e.printStackTrace();
  383. }
  384. }
  385. else
  386. {
  387. return Boolean.valueOf(false);
  388. }
  389. return Boolean.valueOf(true);
  390. }
  391.  
  392. public Boolean addBan(String reason, String ending, String name, String by)
  393. {
  394. Boolean b = Boolean.valueOf(true);
  395.  
  396. name = name.toLowerCase();
  397. if (getUUID(name) != null) {
  398. name = getUUID(name);
  399. }
  400. if (reason == null) {
  401. reason = "NoReason";
  402. }
  403. reason = reason + "#BannedBy#" + by;
  404. if (this.mysql)
  405. {
  406. reason = reason.replace('\'', '"').replace(')', ']').replace('(', '[');
  407. try
  408. {
  409. this.myStmtT = this.myConnT.prepareStatement("select * from AdvancedBans");
  410. this.myRs = this.myStmtT.executeQuery();
  411. this.myRs.beforeFirst();
  412. while (this.myRs.next()) {
  413. if (this.myRs.getString("name").equals(name)) {
  414. return Boolean.valueOf(false);
  415. }
  416. }
  417. String sql = "insert into AdvancedBans (name, reason, until) values ('" +
  418.  
  419. name + "','" + reason + "','" + ending + "')";
  420.  
  421. this.myStmtT.executeUpdate(sql);
  422. }
  423. catch (SQLException e)
  424. {
  425. e.printStackTrace();
  426. }
  427. }
  428. if (!this.bans.contains(name))
  429. {
  430. this.bans.createSection(name);
  431. this.bans.set(name + ".reason", reason);
  432. this.bans.set(name + ".ends", ending);
  433. try
  434. {
  435. this.bans.save(this.banFile);
  436. }
  437. catch (IOException e)
  438. {
  439. e.printStackTrace();
  440. }
  441. }
  442. else
  443. {
  444. b = Boolean.valueOf(false);
  445. }
  446. return b;
  447. }
  448.  
  449. public void addHistoryEntry(String name, String reason, String by, Object ending)
  450. {
  451. String uuid = getUUID(name);
  452. if (reason == null) {
  453. reason = "none";
  454. }
  455. SimpleDateFormat ft = new SimpleDateFormat("dd.MM.yyyy-HH:mm:ss");
  456. String now = ft.format(new Date());
  457. if ((ending instanceof Date)) {
  458. ending = ft.format(ending);
  459. }
  460. if (this.mysql)
  461. {
  462. reason = reason.replace('\'', '"').replace(')', ']').replace('(', '[');
  463. try
  464. {
  465. String sql = " INSERT INTO `PlayerHistory` (`uuid`, `name`, `reason`, `by`, `start`, `end`) VALUES ('" +
  466.  
  467. uuid + "','" + name + "','" + reason + "','" + by + "','" + now + "','" + ending + "')";
  468. this.myStmtPH.executeUpdate(sql);
  469. }
  470. catch (SQLException e)
  471. {
  472. e.printStackTrace();
  473. }
  474. }
  475. else
  476. {
  477. List<String> current = new ArrayList();
  478. if (this.ph.contains(uuid)) {
  479. current = this.ph.getStringList(uuid);
  480. }
  481. current.add(uuid + "#SPLIT#" + name + "#SPLIT#" + reason + "#SPLIT#" + by + "#SPLIT#" + now + "#SPLIT#" + ending);
  482. this.ph.set(uuid, current);
  483. try
  484. {
  485. this.ph.save(this.playerHistoryFile);
  486. }
  487. catch (IOException e)
  488. {
  489. e.printStackTrace();
  490. }
  491. }
  492. }
  493.  
  494. public static boolean isNumeric(String str)
  495. {
  496. try
  497. {
  498. double d = Double.parseDouble(str);
  499. }
  500. catch (NumberFormatException nfe)
  501. {
  502. return false;
  503. }
  504. return true;
  505. }
  506.  
  507. public void regEvents()
  508. {
  509. this.e = new Events(this);
  510. }
  511.  
  512. public String getLayout(List<String> ls, String reason, String date, String betw)
  513. {
  514. String s = "";
  515. String by = null;
  516. if (reason.split("#BannedBy#").length > 1) {
  517. by = reason.split("#BannedBy#")[1];
  518. } else {
  519. by = "an Admin";
  520. }
  521. if (reason.startsWith("NoReason")) {
  522. reason = "Connection lost";
  523. } else if (reason.split("#BannedBy#").length > 1) {
  524. reason = reason.split("#BannedBy#")[0];
  525. }
  526. for (String str : ls) {
  527. s = s + str.replaceAll("%OPERATOR%", by).replaceAll("%REMAINING%", betw).replaceAll("%REASON%", reason).replaceAll("%DATE%", date).replaceAll("%PREFIX%", this.pre).replace('&', '�') + "\n";
  528. }
  529. return s;
  530. }
  531.  
  532. public Boolean inBanned(String name)
  533. {
  534. name = name.toLowerCase();
  535. try
  536. {
  537. this.myStmtT = this.myConnT.prepareStatement("select * from AdvancedBans");
  538. this.myRs = this.myStmtT.executeQuery();
  539. this.myRs.beforeFirst();
  540. while (this.myRs.next()) {
  541. if (this.myRs.getString("name").equals(name)) {
  542. return Boolean.valueOf(true);
  543. }
  544. }
  545. }
  546. catch (SQLException e)
  547. {
  548. e.printStackTrace();
  549. }
  550. return Boolean.valueOf(false);
  551. }
  552.  
  553. public Boolean isIP(String ip)
  554. {
  555. if (ip.split("\\.").length != 4) {
  556. return Boolean.valueOf(false);
  557. }
  558. if (!isNumeric(ip.split("\\.")[0])) {
  559. return Boolean.valueOf(false);
  560. }
  561. if (!isNumeric(ip.split("\\.")[1])) {
  562. return Boolean.valueOf(false);
  563. }
  564. if (!isNumeric(ip.split("\\.")[2])) {
  565. return Boolean.valueOf(false);
  566. }
  567. if (!isNumeric(ip.split("\\.")[3])) {
  568. return Boolean.valueOf(false);
  569. }
  570. return Boolean.valueOf(true);
  571. }
  572.  
  573. public Boolean isChangedIP(String ip)
  574. {
  575. if (ip.split("-").length != 4) {
  576. return Boolean.valueOf(false);
  577. }
  578. if (!isNumeric(ip.split("-")[0])) {
  579. return Boolean.valueOf(false);
  580. }
  581. if (!isNumeric(ip.split("-")[1])) {
  582. return Boolean.valueOf(false);
  583. }
  584. if (!isNumeric(ip.split("-")[2])) {
  585. return Boolean.valueOf(false);
  586. }
  587. if (!isNumeric(ip.split("-")[3])) {
  588. return Boolean.valueOf(false);
  589. }
  590. return Boolean.valueOf(true);
  591. }
  592.  
  593. public static boolean ping(String url, int timeout)
  594. {
  595. url = url.replaceFirst("^https", "http");
  596. try
  597. {
  598. HttpURLConnection connection = (HttpURLConnection)new URL(url).openConnection();
  599. connection.setConnectTimeout(timeout);
  600. connection.setReadTimeout(timeout);
  601. connection.setRequestMethod("HEAD");
  602. int responseCode = connection.getResponseCode();
  603. return (200 <= responseCode) && (responseCode <= 399);
  604. }
  605. catch (IOException exception) {}
  606. return false;
  607. }
  608.  
  609. public boolean runCommand(String command, final Object sender)
  610. {
  611. Boolean cancle = Boolean.valueOf(false);
  612. final String[] args = command.split(" ");
  613. if (args.length != 0)
  614. {
  615. if (args[0].equalsIgnoreCase("/unban"))
  616. {
  617. cancle = Boolean.valueOf(true);
  618. if (hasPermission(sender, "ban.unban"))
  619. {
  620. if (args.length == 2)
  621. {
  622. String name = args[1];
  623. if (isIP(name).booleanValue()) {
  624. name = name.replaceAll("\\.", "-");
  625. }
  626. if (remBan(name).booleanValue()) {
  627. sendMessage(sender, getMSG("Unbanned", true).replaceAll("%PLAYER%", args[1]));
  628. } else {
  629. sendMessage(sender, getMSG("NotBanned", true).replaceAll("%PLAYER%", args[1]));
  630. }
  631. }
  632. else
  633. {
  634. sendMessage(sender, getMSG("UsageUnban", true));
  635. }
  636. }
  637. else {
  638. sendMessage(sender, getMSG("NoPerms", true));
  639. }
  640. }
  641. if (args[0].equalsIgnoreCase("/kick"))
  642. {
  643. cancle = Boolean.valueOf(true);
  644. if (hasPermission(sender, "ban.kick"))
  645. {
  646. if (args.length > 1)
  647. {
  648. if (Bukkit.getOfflinePlayer(args[1]).isOnline())
  649. {
  650. if (!Bukkit.getPlayer(args[1]).hasPermission("kick.exempt"))
  651. {
  652. String grund = null;
  653. if (args.length > 2)
  654. {
  655. Integer i = Integer.valueOf(3);
  656. grund = args[2];
  657. while (i.intValue() != args.length)
  658. {
  659. grund = grund + " " + args[i.intValue()];
  660. i = Integer.valueOf(i.intValue() + 1);
  661. }
  662. }
  663. sendMessage(sender, getMSG("Kicked", true).replaceAll("%PLAYER%", args[1]));
  664. if (grund != null) {
  665. sendMessage(sender, getMSG("Reason", false) + grund);
  666. }
  667. Player[] arrayOfPlayer1;
  668. int j = (arrayOfPlayer1 = Bukkit.getOnlinePlayers()).length;
  669. for (int i = 0; i < j; i++)
  670. {
  671. Player op = arrayOfPlayer1[i];
  672. if ((op.hasPermission("kick.notify")) && (!op.equals(sender)))
  673. {
  674. op.sendMessage(getMSG("Kicked", true).replaceAll("%PLAYER%", args[1]));
  675. if (grund != null) {
  676. op.sendMessage(getMSG("Reason", false) + grund);
  677. }
  678. }
  679. }
  680. final String nGrund = grund;
  681. Bukkit.getScheduler().runTask(this, new Runnable()
  682. {
  683. public void run()
  684. {
  685. if (nGrund != null) {
  686. Bukkit.getPlayer(args[1]).kickPlayer(main.this.getLayout(main.this.KKL, nGrund + "#BannedBy#" + main.this.getName(sender), null, null));
  687. } else {
  688. Bukkit.getPlayer(args[1]).kickPlayer(main.this.getLayout(main.this.KKL, "You got kicked#BannedBy#" + main.this.getName(sender), null, null));
  689. }
  690. }
  691. });
  692. addHistoryEntry(args[1], grund, getName(sender), "KICK");
  693. }
  694. else
  695. {
  696. sendMessage(sender, getMSG("KickExempt", true));
  697. }
  698. }
  699. else {
  700. sendMessage(sender, getMSG("NotOnline", true));
  701. }
  702. }
  703. else {
  704. sendMessage(sender, getMSG("UsageKick", true));
  705. }
  706. }
  707. else {
  708. sendMessage(sender, getMSG("NoPerms", true));
  709. }
  710. }
  711. SimpleDateFormat ft;
  712. Integer mon;
  713. Object month;
  714. if (args[0].equalsIgnoreCase("/tempban"))
  715. {
  716. cancle = Boolean.valueOf(true);
  717. if (hasPermission(sender, "ban.tempban"))
  718. {
  719. if (args.length > 3)
  720. {
  721. if ((Bukkit.getOfflinePlayer(args[1]).isOnline()) &&
  722. (Bukkit.getPlayer(args[1]).hasPermission("ban.exempt")))
  723. {
  724. sendMessage(sender, getMSG("BanExempt", true));
  725. return true;
  726. }
  727. if (isNumeric(args[2]))
  728. {
  729. 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")))
  730. {
  731. if (!canTempban(sender, Integer.valueOf(Integer.parseInt(args[2])), args[3].toLowerCase()).booleanValue())
  732. {
  733. sendMessage(sender, getMSG("NoPerms", true));
  734. return true;
  735. }
  736. final Date unbanAt = new Date();
  737. if (args[3].equalsIgnoreCase("S")) {
  738. unbanAt.setSeconds(unbanAt.getSeconds() + Integer.parseInt(args[2]));
  739. }
  740. if (args[3].equalsIgnoreCase("H")) {
  741. unbanAt.setHours(unbanAt.getHours() + Integer.parseInt(args[2]));
  742. }
  743. if (args[3].equalsIgnoreCase("M")) {
  744. unbanAt.setMinutes(unbanAt.getMinutes() + Integer.parseInt(args[2]));
  745. }
  746. if (args[3].equalsIgnoreCase("D")) {
  747. unbanAt.setDate(unbanAt.getDate() + Integer.parseInt(args[2]));
  748. }
  749. if (args[3].equalsIgnoreCase("W")) {
  750. unbanAt.setDate(unbanAt.getDate() + Integer.parseInt(args[2]) * 7);
  751. }
  752. if (args[3].equalsIgnoreCase("Mo")) {
  753. unbanAt.setDate(unbanAt.getDate() + Integer.parseInt(args[2]) * 30);
  754. }
  755. if (args[3].equalsIgnoreCase("Y")) {
  756. unbanAt.setYear(unbanAt.getYear() + Integer.parseInt(args[2]));
  757. }
  758. String grund = null;
  759. if (args.length > 4)
  760. {
  761. Integer i = Integer.valueOf(5);
  762. grund = args[4];
  763. while (i.intValue() != args.length)
  764. {
  765. grund = grund + " " + args[i.intValue()];
  766. i = Integer.valueOf(i.intValue() + 1);
  767. }
  768. }
  769. ft = new SimpleDateFormat("dd.MM.yyyy-HH:mm:ss");
  770. if (addBan(grund, ft.format(unbanAt), args[1], getName(sender)).booleanValue())
  771. {
  772. sendMessage(sender, getMSG("Banned", true).replaceAll("%PLAYER%", args[1]));
  773. if (grund != null) {
  774. sendMessage(sender, getMSG("Reason", false) + grund);
  775. }
  776. mon = Integer.valueOf(unbanAt.getMonth());
  777. month = null;
  778. if (mon.intValue() == 0) {
  779. month = "Jan";
  780. }
  781. if (mon.intValue() == 1) {
  782. month = "Feb";
  783. }
  784. if (mon.intValue() == 2) {
  785. month = "Mar";
  786. }
  787. if (mon.intValue() == 3) {
  788. month = "Apr";
  789. }
  790. if (mon.intValue() == 4) {
  791. month = "May";
  792. }
  793. if (mon.intValue() == 5) {
  794. month = "June";
  795. }
  796. if (mon.intValue() == 6) {
  797. month = "July";
  798. }
  799. if (mon.intValue() == 7) {
  800. month = "Aug";
  801. }
  802. if (mon.intValue() == 8) {
  803. month = "Sept";
  804. }
  805. if (mon.intValue() == 9) {
  806. month = "Oct";
  807. }
  808. if (mon.intValue() == 10) {
  809. month = "Nov";
  810. }
  811. if (mon.intValue() == 11) {
  812. month = "Dec";
  813. }
  814. sendMessage(sender, getMSG("Until", false) + " �7" + unbanAt.getDate() + " " + (String)month + ". at " + unbanAt.getHours() + ":" + unbanAt.getMinutes() + ":" + unbanAt.getSeconds());
  815. Player[] arrayOfPlayer2;
  816. int m = (arrayOfPlayer2 = Bukkit.getOnlinePlayers()).length;
  817. for (int k = 0; k < m; k++)
  818. {
  819. Player op = arrayOfPlayer2[k];
  820. if ((op.hasPermission("ban.notify")) && (!op.equals(sender)) &&
  821. (op != sender))
  822. {
  823. op.sendMessage(getMSG("Banned", true).replaceAll("%PLAYER%", args[1]));
  824. if (grund != null) {
  825. op.sendMessage(getMSG("Reason", false) + grund);
  826. }
  827. op.sendMessage(getMSG("Until", false) + unbanAt.getDate() + " " + (String)month + ". at " + unbanAt.getHours() + ":" + unbanAt.getMinutes() + ":" + unbanAt.getSeconds());
  828. }
  829. }
  830. if (Bukkit.getOfflinePlayer(args[1]).isOnline())
  831. {
  832. final String date = unbanAt.getDate() + "." + (String)month + ". at " + unbanAt.getHours() + ":" + unbanAt.getMinutes() + ":" + unbanAt.getSeconds();
  833. final String nGrund = grund;
  834. Bukkit.getScheduler().runTask(this, new Runnable()
  835. {
  836. public void run()
  837. {
  838. if (nGrund != null) {
  839. 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())));
  840. } else {
  841. 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())));
  842. }
  843. }
  844. });
  845. }
  846. addHistoryEntry(args[1], grund, getName(sender), unbanAt);
  847. }
  848. else
  849. {
  850. sendMessage(sender, getMSG("AlreadyBanned", true).replaceAll("%PLAYER%", args[1]));
  851. }
  852. }
  853. else
  854. {
  855. sendMessage(sender, getMSG("UsageTempBan", true));
  856. }
  857. }
  858. else {
  859. sendMessage(sender, getMSG("UsageTempBan", true));
  860. }
  861. }
  862. else
  863. {
  864. sendMessage(sender, getMSG("UsageTempBan", true));
  865. }
  866. }
  867. else {
  868. sendMessage(sender, getMSG("NoPerms", true));
  869. }
  870. }
  871. if (args[0].equalsIgnoreCase("/ban"))
  872. {
  873. cancle = Boolean.valueOf(true);
  874. if (hasPermission(sender, "ban.ban"))
  875. {
  876. if (args.length > 1)
  877. {
  878. if ((Bukkit.getOfflinePlayer(args[1]).isOnline()) &&
  879. (Bukkit.getPlayer(args[1]).hasPermission("ban.exempt")))
  880. {
  881. sendMessage(sender, getMSG("BanExempt", true));
  882. return true;
  883. }
  884. String grund = null;
  885. if (args.length > 2)
  886. {
  887. Integer i = Integer.valueOf(3);
  888. grund = args[2];
  889. while (i.intValue() != args.length)
  890. {
  891. grund = grund + " " + args[i.intValue()];
  892. i = Integer.valueOf(i.intValue() + 1);
  893. }
  894. }
  895. if (addBan(grund, "never", args[1], getName(sender)).booleanValue())
  896. {
  897. sendMessage(sender, getMSG("Banned", true).replaceAll("%PLAYER%", args[1]));
  898. if (grund != null) {
  899. sendMessage(sender, getMSG("Reason", false) + grund);
  900. }
  901. SimpleDateFormat localSimpleDateFormat2 = (month = Bukkit.getOnlinePlayers()).length;
  902. for (SimpleDateFormat localSimpleDateFormat1 = 0; localSimpleDateFormat1 < localSimpleDateFormat2; localSimpleDateFormat1++)
  903. {
  904. Player op = month[localSimpleDateFormat1];
  905. if ((op.hasPermission("ban.notify")) && (!op.equals(sender)) &&
  906. (op != sender))
  907. {
  908. op.sendMessage(getMSG("Banned", true).replaceAll("%PLAYER%", args[1]));
  909. if (grund != null) {
  910. op.sendMessage(getMSG("Reason", false) + grund);
  911. }
  912. }
  913. }
  914. if (Bukkit.getOfflinePlayer(args[1]).isOnline())
  915. {
  916. final String nGrund = grund;
  917. Bukkit.getScheduler().runTask(this, new Runnable()
  918. {
  919. public void run()
  920. {
  921. if (nGrund != null) {
  922. Bukkit.getPlayer(args[1]).kickPlayer(main.this.getLayout(main.this.BBL, nGrund + "#BannedBy#" + main.this.getName(sender), null, null));
  923. } else {
  924. Bukkit.getPlayer(args[1]).kickPlayer(main.this.getLayout(main.this.BBL, "You got banned#BannedBy#" + main.this.getName(sender), null, null));
  925. }
  926. }
  927. });
  928. }
  929. addHistoryEntry(args[1], grund, getName(sender), "BAN");
  930. }
  931. else
  932. {
  933. sendMessage(sender, getMSG("AlreadyBanned", true).replaceAll("%PLAYER%", args[1]));
  934. }
  935. }
  936. else
  937. {
  938. sendMessage(sender, getMSG("UsageBan", true));
  939. }
  940. }
  941. else {
  942. sendMessage(sender, getMSG("NoPerms", true));
  943. }
  944. }
  945. Object unbanAt;
  946. String str;
  947. if (args[0].equalsIgnoreCase("/banlist"))
  948. {
  949. cancle = Boolean.valueOf(true);
  950.  
  951. List<String> bl = new ArrayList();
  952. List<String> toRem = new ArrayList();
  953. if (this.mysql) {
  954. try
  955. {
  956. this.myStmtT = this.myConnT.prepareStatement("select * from AdvancedBans");
  957. this.myRs = this.myStmtT.executeQuery();
  958. this.myRs.beforeFirst();
  959. while (this.myRs.next()) {
  960. if (!this.myRs.getString("until").equalsIgnoreCase("never"))
  961. {
  962. SimpleDateFormat ft = new SimpleDateFormat("dd.MM.yyyy-HH:mm:ss");
  963. unbanAt = null;
  964. try
  965. {
  966. unbanAt = ft.parse(this.myRs.getString("until"));
  967. }
  968. catch (ParseException e1)
  969. {
  970. e1.printStackTrace();
  971. }
  972. if (((Date)unbanAt).before(new Date())) {
  973. toRem.add(this.myRs.getString("name"));
  974. } else {
  975. bl.add(this.myRs.getString("name") + "-=#=-" + this.myRs.getString("reason") + "-=#=-" + this.myRs.getString("until"));
  976. }
  977. }
  978. else
  979. {
  980. bl.add(this.myRs.getString("name") + "-=#=-" + this.myRs.getString("reason") + "-=#=-" + this.myRs.getString("until"));
  981. }
  982. }
  983. }
  984. catch (SQLException e)
  985. {
  986. e.printStackTrace();
  987. }
  988. } else {
  989. for (unbanAt = this.bans.getKeys(false).iterator(); ((Iterator)unbanAt).hasNext();)
  990. {
  991. String s = (String)((Iterator)unbanAt).next();
  992. if (!this.bans.getString(s + ".ends").equalsIgnoreCase("never"))
  993. {
  994. SimpleDateFormat ft = new SimpleDateFormat("dd.MM.yyyy-HH:mm:ss");
  995. Date unbanAt = null;
  996. try
  997. {
  998. unbanAt = ft.parse(this.bans.getString(s + ".ends"));
  999. }
  1000. catch (ParseException e1)
  1001. {
  1002. ((ParseException)e1).printStackTrace();
  1003. }
  1004. if (unbanAt.before(new Date())) {
  1005. toRem.add(s);
  1006. } else {
  1007. 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()));
  1008. }
  1009. }
  1010. else
  1011. {
  1012. 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()));
  1013. }
  1014. }
  1015. }
  1016. for (unbanAt = toRem.iterator(); ((Iterator)unbanAt).hasNext();)
  1017. {
  1018. String s = (String)((Iterator)unbanAt).next();
  1019. remBan(s);
  1020. }
  1021. toRem.clear();
  1022. String s;
  1023. for (unbanAt = this.conf.getStringList("BanListLayout.Header").iterator(); ((Iterator)unbanAt).hasNext(); sendMessage(sender, s.replace('&', '�'))) {
  1024. s = (String)((Iterator)unbanAt).next();
  1025. }
  1026. for (unbanAt = bl.iterator(); ((Iterator)unbanAt).hasNext();)
  1027. {
  1028. String s = (String)((Iterator)unbanAt).next();
  1029. try
  1030. {
  1031. String name = "";
  1032. if (isChangedIP(s.split("-=#=-")[0]).booleanValue())
  1033. {
  1034. name = s.split("-=#=-")[0].replaceAll("-", "\\.");
  1035. }
  1036. else
  1037. {
  1038. name = s.split("-=#=-")[0];
  1039. if (getNameFromUUID(name) != null) {
  1040. name = getNameFromUUID(name);
  1041. }
  1042. }
  1043. for (e1 = this.conf.getStringList("BanListLayout.Entry").iterator(); ((Iterator)e1).hasNext();)
  1044. {
  1045. str = (String)((Iterator)e1).next();
  1046. sendMessage(sender, str.replaceAll("%NAME%", name)
  1047. .replaceAll("%UNTIL%", s.split("-=#=-")[2])
  1048. .replaceAll("%BY%", s.split("-=#=-")[1].split("#BannedBy#")[1])
  1049. .replaceAll("%REASON%", s.split("-=#=-")[1].split("#BannedBy#")[0])
  1050. .replace('&', '�'));
  1051. }
  1052. }
  1053. catch (IndexOutOfBoundsException localIndexOutOfBoundsException1) {}
  1054. }
  1055. sendMessage(sender, this.conf.getString("BanListLayout.Footer").replaceAll("%NO%", bl.size()).replace('&', '�'));
  1056. }
  1057. Object localObject1;
  1058. if ((args[0].equalsIgnoreCase("/ban-ip")) || (args[0].equalsIgnoreCase("/banip")))
  1059. {
  1060. cancle = Boolean.valueOf(true);
  1061. if (hasPermission(sender, "ban.ipban"))
  1062. {
  1063. if (args.length > 1)
  1064. {
  1065. if ((Bukkit.getOfflinePlayer(args[1]).isOnline()) &&
  1066. (Bukkit.getPlayer(args[1]).hasPermission("ban.exempt")))
  1067. {
  1068. sendMessage(sender, getMSG("BanExempt", true));
  1069. return true;
  1070. }
  1071. String grund = null;
  1072. if (args.length > 2)
  1073. {
  1074. Integer i = Integer.valueOf(3);
  1075. grund = args[2];
  1076. while (i.intValue() != args.length)
  1077. {
  1078. grund = grund + " " + args[i.intValue()];
  1079. i = Integer.valueOf(i.intValue() + 1);
  1080. }
  1081. }
  1082. if ((!isIP(args[1]).booleanValue()) && (!Bukkit.getOfflinePlayer(args[1]).isOnline()) && (!this.ips.containsKey(args[1].toLowerCase())))
  1083. {
  1084. sendMessage(sender, getMSG("NotOnline", true));
  1085. return true;
  1086. }
  1087. String player = args[1];
  1088. if (Bukkit.getOfflinePlayer(args[1]).isOnline()) {
  1089. player = Bukkit.getPlayer(args[1]).getAddress().toString().split("/")[(Bukkit.getPlayer(args[1]).getAddress().toString().split("/").length - 1)].split(":")[0].replaceAll("\\.", "-");
  1090. } else if (isIP(args[1]).booleanValue()) {
  1091. player = player.replaceAll("\\.", "-");
  1092. } else {
  1093. player = ((String)this.ips.get(player.toLowerCase())).replaceAll("\\.", "-");
  1094. }
  1095. if (addBan(grund, "never", player, getName(sender)).booleanValue())
  1096. {
  1097. sendMessage(sender, getMSG("Banned", true).replaceAll("%PLAYER%", args[1]));
  1098. if (grund != null) {
  1099. sendMessage(sender, getMSG("Reason", false) + grund);
  1100. }
  1101. Date localDate1 = (str = Bukkit.getOnlinePlayers()).length;
  1102. for (localObject1 = 0; localObject1 < localDate1; localObject1++)
  1103. {
  1104. Player op = str[localObject1];
  1105. if ((op.hasPermission("ban.notify")) &&
  1106. (op != sender))
  1107. {
  1108. op.sendMessage(getMSG("Banned", true).replaceAll("%PLAYER%", args[1]));
  1109. if (grund != null) {
  1110. op.sendMessage(getMSG("Reason", false) + grund);
  1111. }
  1112. }
  1113. }
  1114. if (Bukkit.getOfflinePlayer(args[1]).isOnline())
  1115. {
  1116. final String nGrund = grund;
  1117. Bukkit.getScheduler().runTask(this, new Runnable()
  1118. {
  1119. public void run()
  1120. {
  1121. if (nGrund != null) {
  1122. Bukkit.getPlayer(args[1]).kickPlayer(main.this.getLayout(main.this.BBL, nGrund + "#BannedBy#" + main.this.getName(sender), null, null));
  1123. } else {
  1124. Bukkit.getPlayer(args[1]).kickPlayer(main.this.getLayout(main.this.BBL, "You got banned#BannedBy#" + main.this.getName(sender), null, null));
  1125. }
  1126. }
  1127. });
  1128. }
  1129. }
  1130. else
  1131. {
  1132. sendMessage(sender, getMSG("AlreadyBanned", true).replaceAll("%PLAYER%", args[1]));
  1133. }
  1134. }
  1135. else
  1136. {
  1137. sendMessage(sender, getMSG("UsageIpBan", true));
  1138. }
  1139. }
  1140. else {
  1141. sendMessage(sender, getMSG("NoPerms", true));
  1142. }
  1143. }
  1144. if (args[0].equalsIgnoreCase("/history"))
  1145. {
  1146. cancle = Boolean.valueOf(true);
  1147. if ((args.length == 1) || (args.length == 2)) {
  1148. sendMessage(sender, getMSG("UsagePlayerHistory", true));
  1149. } else if (args[1].equalsIgnoreCase("get"))
  1150. {
  1151. if (hasPermission(sender, "ban.history.get"))
  1152. {
  1153. List<String> curr = new ArrayList();
  1154. String uuid = getUUID(args[2]);
  1155. if (this.mysql) {
  1156. try
  1157. {
  1158. this.myRsPH = this.myConnT.prepareStatement("select * from PlayerHistory").executeQuery();
  1159. this.myRsPH.beforeFirst();
  1160. while (this.myRsPH.next()) {
  1161. if (this.myRsPH.getString("uuid").equalsIgnoreCase(uuid)) {
  1162. curr.add(uuid + " #SPLIT# " + this.myRsPH.getString("name") +
  1163. " #SPLIT# " + this.myRsPH.getString("reason") +
  1164. " #SPLIT# " + this.myRsPH.getString("by") +
  1165. " #SPLIT# " + this.myRsPH.getString("start") +
  1166. " #SPLIT# " + this.myRsPH.getString("end"));
  1167. }
  1168. }
  1169. }
  1170. catch (SQLException e)
  1171. {
  1172. e.printStackTrace();
  1173. }
  1174. } else if (this.ph.contains(uuid)) {
  1175. curr = this.ph.getStringList(uuid);
  1176. }
  1177. if (curr.isEmpty())
  1178. {
  1179. sendMessage(sender, getMSG("NoPlayerHistory", true));
  1180. }
  1181. else
  1182. {
  1183. sendMessage(sender, "�8");
  1184. sendMessage(sender, "�8");
  1185. sendMessage(sender, getMSG("PlayerHistory", true));
  1186. for (localObject1 = curr.iterator(); ((Iterator)localObject1).hasNext();)
  1187. {
  1188. String s = (String)((Iterator)localObject1).next();
  1189. String[] sl = s.split("#SPLIT#");
  1190. String type = "";
  1191. try
  1192. {
  1193. SimpleDateFormat ft = new SimpleDateFormat("dd.MM.yyyy-HH:mm:ss");
  1194. l = Long.valueOf(ft.parse(sl[5]).getTime() - ft.parse(sl[4]).getTime());
  1195. if (TimeUnit.MILLISECONDS.toHours(((Long)l).longValue()) > 0L) {
  1196. type = "TEMP-BAN [" + TimeUnit.MILLISECONDS.toHours(((Long)l).longValue()) + " h]";
  1197. } else {
  1198. type = "TEMP-BAN [" + TimeUnit.MILLISECONDS.toMinutes(((Long)l).longValue()) + " min]";
  1199. }
  1200. }
  1201. catch (Exception exc)
  1202. {
  1203. type = sl[5];
  1204. }
  1205. sendMessage(sender, "�7");
  1206. for (Object l = this.conf.getStringList("HistoryLayout").iterator(); ((Iterator)l).hasNext();)
  1207. {
  1208. String str = (String)((Iterator)l).next();
  1209. sendMessage(sender, str.replaceAll("%NAME%", sl[1])
  1210. .replaceAll("%DATE%", sl[4])
  1211. .replaceAll("%BY%", sl[3])
  1212. .replaceAll("%TYPE%", type)
  1213. .replaceAll("%REASON%", sl[2]).replace('&', '�'));
  1214. }
  1215. sendMessage(sender, "�7");
  1216. }
  1217. sendMessage(sender, "�8");
  1218. }
  1219. }
  1220. else
  1221. {
  1222. sendMessage(sender, getMSG("NoPerms", true));
  1223. }
  1224. }
  1225. else if (args[1].equalsIgnoreCase("clear"))
  1226. {
  1227. if (hasPermission(sender, "ban.history.clear"))
  1228. {
  1229. String uuid = getUUID(args[2]);
  1230. if (this.mysql)
  1231. {
  1232. try
  1233. {
  1234. this.myConnT.prepareStatement("DELETE FROM PlayerHistory WHERE uuid = '" + uuid + "'").execute();
  1235. }
  1236. catch (SQLException e)
  1237. {
  1238. e.printStackTrace();
  1239. }
  1240. }
  1241. else
  1242. {
  1243. this.ph.set(uuid, null);
  1244. try
  1245. {
  1246. this.ph.save(this.playerHistoryFile);
  1247. }
  1248. catch (IOException e)
  1249. {
  1250. e.printStackTrace();
  1251. }
  1252. }
  1253. sendMessage(sender, getMSG("RemovedPlayerHistory", true).replaceAll("%PLAYER%", args[2]));
  1254. }
  1255. else
  1256. {
  1257. sendMessage(sender, getMSG("NoPerms", true));
  1258. }
  1259. }
  1260. else {
  1261. sendMessage(sender, getMSG("UsagePlayerHistory", true));
  1262. }
  1263. }
  1264. if (args[0].equalsIgnoreCase("/check"))
  1265. {
  1266. cancle = Boolean.valueOf(true);
  1267. if (hasPermission(sender, "ban.check"))
  1268. {
  1269. if (args.length == 1)
  1270. {
  1271. sendMessage(sender, getMSG("UsageCheck", true));
  1272. }
  1273. else
  1274. {
  1275. Boolean banned = Boolean.valueOf(false);
  1276. String name = args[1];
  1277. if (this.mysql)
  1278. {
  1279. if (inBanned(args[1].toLowerCase()).booleanValue())
  1280. {
  1281. banned = Boolean.valueOf(true);
  1282. name = args[1].toLowerCase();
  1283. }
  1284. else if ((getUUID(name) != null) &&
  1285. (inBanned(getUUID(name)).booleanValue()))
  1286. {
  1287. banned = Boolean.valueOf(true);
  1288. name = getUUID(name);
  1289. }
  1290. }
  1291. else if (this.bans.contains(args[1].toLowerCase()))
  1292. {
  1293. banned = Boolean.valueOf(true);
  1294. name = args[1].toLowerCase();
  1295. }
  1296. else if ((getUUID(name) != null) &&
  1297. (this.bans.contains(getUUID(name))))
  1298. {
  1299. banned = Boolean.valueOf(true);
  1300. name = getUUID(name);
  1301. }
  1302. if (banned.booleanValue())
  1303. {
  1304. String reason = null;
  1305. String ending = null;
  1306. if (this.mysql)
  1307. {
  1308. try
  1309. {
  1310. this.myRs = this.myStmtT.executeQuery();
  1311. this.myRs.beforeFirst();
  1312. while (this.myRs.next()) {
  1313. if (this.myRs.getString("name").equals(name))
  1314. {
  1315. reason = this.myRs.getString("reason");
  1316. ending = this.myRs.getString("until");
  1317. }
  1318. }
  1319. }
  1320. catch (SQLException ex)
  1321. {
  1322. ex.printStackTrace();
  1323. }
  1324. }
  1325. else
  1326. {
  1327. reason = this.bans.getString(name + ".reason");
  1328. ending = this.bans.getString(name + ".ends");
  1329. }
  1330. if (ending.equalsIgnoreCase("never"))
  1331. {
  1332. if (!reason.split("#BannedBy#")[0].equalsIgnoreCase("NoReason"))
  1333. {
  1334. sendMessage(sender, getMSG("IsBanned", true).replaceAll("%PLAYER%", args[1]));
  1335. sendMessage(sender, getMSG("EndingIn", false) + "never");
  1336. sendMessage(sender, getMSG("Reason", false) + reason.split("#BannedBy#")[0]);
  1337. sendMessage(sender, getMSG("BannedBy", false) + reason.split("#BannedBy#")[1]);
  1338. }
  1339. else
  1340. {
  1341. sendMessage(sender, getMSG("IsBanned", true).replaceAll("%PLAYER%", args[1]));
  1342. sendMessage(sender, getMSG("EndingIn", false) + "never");
  1343. sendMessage(sender, getMSG("Reason", false) + "none");
  1344. sendMessage(sender, getMSG("BannedBy", false) + reason.split("#BannedBy#")[1]);
  1345. }
  1346. }
  1347. else
  1348. {
  1349. SimpleDateFormat ft = new SimpleDateFormat("dd.MM.yyyy-HH:mm:ss");
  1350. Date unbanAt = null;
  1351. try
  1352. {
  1353. unbanAt = ft.parse(ending);
  1354. }
  1355. catch (ParseException e1)
  1356. {
  1357. e1.printStackTrace();
  1358. }
  1359. if (unbanAt.before(new Date()))
  1360. {
  1361. remBan(name);
  1362. sendMessage(sender, "�aPlayer " + args[1] + " is not banned");
  1363. }
  1364. else if (!reason.split("#BannedBy#")[0].equalsIgnoreCase("NoReason"))
  1365. {
  1366. sendMessage(sender, getMSG("IsBanned", true).replaceAll("%PLAYER%", args[1]));
  1367. sendMessage(sender, getMSG("EndingIn", false) + this.e.caltcBetween(unbanAt, new Date()));
  1368. sendMessage(sender, getMSG("Reason", false) + reason.split("#BannedBy#")[0]);
  1369. sendMessage(sender, getMSG("BannedBy", false) + reason.split("#BannedBy#")[1]);
  1370. }
  1371. else
  1372. {
  1373. sendMessage(sender, getMSG("IsBanned", true).replaceAll("%PLAYER%", args[1]));
  1374. sendMessage(sender, getMSG("EndingIn", false) + this.e.caltcBetween(unbanAt, new Date()));
  1375. sendMessage(sender, getMSG("Reason", false) + "none");
  1376. sendMessage(sender, getMSG("BannedBy", false) + reason.split("#BannedBy#")[1]);
  1377. }
  1378. }
  1379. }
  1380. else
  1381. {
  1382. sendMessage(sender, getMSG("NotBanned", true).replaceAll("%PLAYER%", args[1]));
  1383. }
  1384. }
  1385. }
  1386. else {
  1387. sendMessage(sender, getMSG("NoPerms", true));
  1388. }
  1389. }
  1390. }
  1391. return cancle.booleanValue();
  1392. }
  1393.  
  1394. public void sendMessage(Object target, String msg)
  1395. {
  1396. if ((target instanceof Player)) {
  1397. ((Player)target).sendMessage(msg);
  1398. } else {
  1399. System.out.println(ChatColor.stripColor(msg));
  1400. }
  1401. }
  1402.  
  1403. public String getName(Object target)
  1404. {
  1405. if ((target instanceof Player)) {
  1406. return ((Player)target).getName();
  1407. }
  1408. return "Console";
  1409. }
  1410.  
  1411. public boolean hasPermission(Object target, String perm)
  1412. {
  1413. if ((target instanceof Player))
  1414. {
  1415. if (((Player)target).hasPermission(perm)) {
  1416. return true;
  1417. }
  1418. return false;
  1419. }
  1420. return true;
  1421. }
  1422.  
  1423. public String getUUID(String name)
  1424. {
  1425. if (!this.useUUID) {
  1426. return name;
  1427. }
  1428. try
  1429. {
  1430. URL url = new URL("https://api.mojang.com/users/profiles/minecraft/" + name + "?at=" + new Date().getTime());
  1431. HttpURLConnection request = (HttpURLConnection)url.openConnection();
  1432. request.connect();
  1433.  
  1434. JSONParser jp = new JSONParser();
  1435. JSONObject json = (JSONObject)jp.parse(new InputStreamReader((InputStream)request.getContent()));
  1436. return json.get("id").toString();
  1437. }
  1438. catch (Exception exc) {}
  1439. return null;
  1440. }
  1441.  
  1442. public String getNameFromUUID(String uuid)
  1443. {
  1444. if (!this.useUUID) {
  1445. return uuid;
  1446. }
  1447. try
  1448. {
  1449. String s = new Scanner(new URL("https://api.mojang.com/user/profiles/" + uuid + "/names").openStream(), "UTF-8").useDelimiter("\\A").next();
  1450. s = s.substring(s.lastIndexOf('{'), s.lastIndexOf('}') + 1);
  1451. return ((JSONObject)new JSONParser().parse(s)).get("name").toString();
  1452. }
  1453. catch (Exception e) {}
  1454. return null;
  1455. }
  1456.  
  1457. public Boolean canTempban(Object sender, Integer dur, String type)
  1458. {
  1459. Integer h = Integer.valueOf(0);
  1460. if (hasPermission(sender, "ban.admin")) {
  1461. return Boolean.valueOf(true);
  1462. }
  1463. if (type.equals("s")) {
  1464. return Boolean.valueOf(true);
  1465. }
  1466. if (type.equals("m")) {
  1467. return Boolean.valueOf(true);
  1468. }
  1469. if (type.equals("h")) {
  1470. h = dur;
  1471. }
  1472. if (type.equals("d")) {
  1473. h = Integer.valueOf(dur.intValue() * 24);
  1474. }
  1475. if (type.equals("w")) {
  1476. h = Integer.valueOf(dur.intValue() * 24 * 7);
  1477. }
  1478. if (type.equals("mo")) {
  1479. h = Integer.valueOf(dur.intValue() * 24 * 30);
  1480. }
  1481. if (type.equals("y")) {
  1482. h = Integer.valueOf(dur.intValue() * 24 * 300);
  1483. }
  1484. Integer max = Integer.valueOf(720);
  1485. while (max.intValue() != 0)
  1486. {
  1487. if (hasPermission(sender, "ban.tempban.maxHours." + max)) {
  1488. break;
  1489. }
  1490. max = Integer.valueOf(max.intValue() - 1);
  1491. }
  1492. if (max.intValue() == 0) {
  1493. return Boolean.valueOf(true);
  1494. }
  1495. if (h.intValue() > max.intValue()) {
  1496. return Boolean.valueOf(false);
  1497. }
  1498. return Boolean.valueOf(true);
  1499. }
  1500.  
  1501. public String getMSG(String path, boolean pre)
  1502. {
  1503. String s = null;
  1504. path = "ChatMessages." + path;
  1505. try
  1506. {
  1507. s = this.conf.getString(path);
  1508. }
  1509. catch (Exception exc)
  1510. {
  1511. exc.printStackTrace();
  1512. }
  1513. if (s == null)
  1514. {
  1515. System.out.println("\n \n--===[AdvancdedBan-ERROR]===--\nErrorType: Config-Error\nError: Could not find the message under the path " +
  1516.  
  1517. path.replace('.', '>') +
  1518. "\nReportIt?: No" +
  1519. "\nHELP Skype: Leoko33" +
  1520. "\n--============================--\n ");
  1521. return "�4ERROR! See Console for ErrorLog";
  1522. }
  1523. if (pre) {
  1524. s = this.pre + " " + s;
  1525. }
  1526. return s.replace('&', '�');
  1527. }
  1528. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement