Advertisement
Guest User

Untitled

a guest
Jan 21st, 2018
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 37.96 KB | None | 0 0
  1. package me.jmgr2007.Reloader;
  2.  
  3. import org.bukkit.plugin.*;
  4. import org.bukkit.command.*;
  5. import org.bukkit.event.*;
  6. import java.lang.reflect.*;
  7. import org.bukkit.*;
  8. import org.bukkit.permissions.*;
  9. import org.bukkit.entity.*;
  10. import java.util.*;
  11. import java.util.logging.*;
  12. import org.bukkit.configuration.file.*;
  13. import org.bukkit.configuration.*;
  14. import java.io.*;
  15.  
  16. public class Utils
  17. {
  18. private static PluginManager pm;
  19. private static boolean canceled;
  20. public static String canceledPl;
  21. protected static FileConfiguration locale;
  22. protected static File localeFile;
  23. private static Plugin plugin;
  24.  
  25. static {
  26. Utils.pm = Bukkit.getServer().getPluginManager();
  27. Utils.canceledPl = "";
  28. Utils.locale = null;
  29. Utils.localeFile = null;
  30. Utils.plugin = Utils.pm.getPlugin("Reloader");
  31. }
  32.  
  33. public Utils(final String name, final CommandSender sender) {
  34. if (exempt(name)) {
  35. msg(sender, string("exempt", Utils.canceledPl));
  36. }
  37. Utils.canceled = exempt(name);
  38. }
  39.  
  40. public Utils(final String name) {
  41. Utils.canceled = exempt(name);
  42. }
  43.  
  44. public static void load(final String pluginName) {
  45. Plugin[] plugins2;
  46. for (int length = (plugins2 = Utils.pm.getPlugins()).length, i = 0; i < length; ++i) {
  47. final Plugin pl = plugins2[i];
  48. if (pl.getName().toLowerCase().startsWith(pluginName.toLowerCase())) {
  49. Utils.plugin.getLogger().info(string("loaded", pl.getName()));
  50. return;
  51. }
  52. }
  53. String name = "";
  54. final String path = Utils.plugin.getDataFolder().getParent();
  55. final File folder = new File(path);
  56. final ArrayList<File> files = new ArrayList<File>();
  57. final File[] listOfFiles = folder.listFiles();
  58. File[] array;
  59. for (int length2 = (array = listOfFiles).length, j = 0; j < length2; ++j) {
  60. final File compare = array[j];
  61. if (compare.isFile()) {
  62. try {
  63. name = ReloaderListener.plugin.getPluginLoader().getPluginDescription(compare).getName();
  64. }
  65. catch (InvalidDescriptionException e2) {
  66. Utils.plugin.getLogger().info(string("ErrorA", compare.getName()));
  67. }
  68. if (name.toLowerCase().startsWith(pluginName.toLowerCase())) {
  69. files.add(compare);
  70. try {
  71. Utils.pm.loadPlugin(compare);
  72. }
  73. catch (UnknownDependencyException e3) {
  74. Utils.plugin.getLogger().info(string("ErrorC", compare.getName()));
  75. return;
  76. }
  77. catch (InvalidPluginException e4) {
  78. Utils.plugin.getLogger().info(string("ErrorB", compare.getName()));
  79. return;
  80. }
  81. catch (InvalidDescriptionException e2) {
  82. Utils.plugin.getLogger().info(string("ErrorA", compare.getName()));
  83. return;
  84. }
  85. }
  86. }
  87. }
  88. final Plugin[] plugins = Utils.pm.getPlugins();
  89. Plugin[] array2;
  90. for (int length3 = (array2 = plugins).length, k = 0; k < length3; ++k) {
  91. final Plugin pl2 = array2[k];
  92. for (final File compare2 : files) {
  93. try {
  94. if (!pl2.getName().equalsIgnoreCase(ReloaderListener.plugin.getPluginLoader().getPluginDescription(compare2).getName())) {
  95. continue;
  96. }
  97. Utils.pm.enablePlugin(pl2);
  98. }
  99. catch (InvalidDescriptionException e) {
  100. e.printStackTrace();
  101. }
  102. }
  103. }
  104. }
  105.  
  106. public static void load(final String pluginName, final CommandSender sender) {
  107. Plugin[] plugins2;
  108. for (int length = (plugins2 = Utils.pm.getPlugins()).length, i = 0; i < length; ++i) {
  109. final Plugin pl = plugins2[i];
  110. if (pl.getName().toLowerCase().startsWith(pluginName.toLowerCase())) {
  111. msg(sender, pl.getName());
  112. msg(sender, pluginName);
  113. msg(sender, string("loaded", pl.getName()));
  114. return;
  115. }
  116. }
  117. String name = "";
  118. final ArrayList<File> files = new ArrayList<File>();
  119. final File[] listOfFiles = new File(ReloaderListener.plugin.getDataFolder().getParent()).listFiles();
  120. File[] array;
  121. for (int length2 = (array = listOfFiles).length, j = 0; j < length2; ++j) {
  122. final File compare = array[j];
  123. if (compare.isFile() && compare.getName().toLowerCase().endsWith(".jar")) {
  124. try {
  125. name = ReloaderListener.plugin.getPluginLoader().getPluginDescription(compare).getName();
  126. }
  127. catch (InvalidDescriptionException e2) {
  128. msg(sender, string("ErrorA", compare.getName()));
  129. return;
  130. }
  131. if (name.toLowerCase().startsWith(pluginName.toLowerCase())) {
  132. files.add(compare);
  133. try {
  134. Utils.pm.loadPlugin(compare);
  135. }
  136. catch (UnknownDependencyException e3) {
  137. msg(sender, string("ErrorC", compare.getName()));
  138. return;
  139. }
  140. catch (InvalidPluginException e4) {
  141. msg(sender, string("ErrorB", compare.getName()));
  142. return;
  143. }
  144. catch (InvalidDescriptionException e2) {
  145. msg(sender, string("ErrorA", compare.getName()));
  146. return;
  147. }
  148. }
  149. }
  150. }
  151. final Plugin[] plugins = Utils.pm.getPlugins();
  152. Plugin[] array2;
  153. for (int length3 = (array2 = plugins).length, k = 0; k < length3; ++k) {
  154. final Plugin pl2 = array2[k];
  155. for (final File compare2 : files) {
  156. try {
  157. if (!pl2.getName().equalsIgnoreCase(ReloaderListener.plugin.getPluginLoader().getPluginDescription(compare2).getName())) {
  158. continue;
  159. }
  160. Utils.pm.enablePlugin(pl2);
  161. msg(sender, string("load", pl2.getName()));
  162. }
  163. catch (InvalidDescriptionException e) {
  164. e.printStackTrace();
  165. msg(sender, "");
  166. return;
  167. }
  168. }
  169. }
  170. }
  171.  
  172. public static void fload(final String pluginName, final CommandSender sender) {
  173. Plugin[] plugins2;
  174. for (int length = (plugins2 = Utils.pm.getPlugins()).length, i = 0; i < length; ++i) {
  175. final Plugin pl = plugins2[i];
  176. if (pl.getName().toLowerCase().startsWith(pluginName.toLowerCase())) {
  177. msg(sender, string("loaded", pl.getName()));
  178. return;
  179. }
  180. }
  181. String name = "";
  182. final ArrayList<File> files = new ArrayList<File>();
  183. final File[] listOfFiles = new File(ReloaderListener.plugin.getDataFolder().getParent()).listFiles();
  184. File[] array;
  185. for (int length2 = (array = listOfFiles).length, j = 0; j < length2; ++j) {
  186. final File compare = array[j];
  187. if (compare.isFile() && compare.getName().toLowerCase().endsWith(".jar")) {
  188. try {
  189. name = ReloaderListener.plugin.getPluginLoader().getPluginDescription(compare).getName();
  190. }
  191. catch (InvalidDescriptionException e2) {
  192. msg(sender, string("ErrorA", compare.getName()));
  193. return;
  194. }
  195. if (name.toLowerCase().startsWith(pluginName.toLowerCase())) {
  196. files.add(compare);
  197. try {
  198. Utils.pm.loadPlugin(compare);
  199. }
  200. catch (UnknownDependencyException e3) {
  201. msg(sender, string("ErrorC", compare.getName()));
  202. return;
  203. }
  204. catch (InvalidPluginException e4) {
  205. msg(sender, string("ErrorB", compare.getName()));
  206. return;
  207. }
  208. catch (InvalidDescriptionException e2) {
  209. msg(sender, string("ErrorA", compare.getName()));
  210. return;
  211. }
  212. }
  213. }
  214. }
  215. final Plugin[] plugins = Utils.pm.getPlugins();
  216. Plugin[] array2;
  217. for (int length3 = (array2 = plugins).length, k = 0; k < length3; ++k) {
  218. final Plugin pl2 = array2[k];
  219. for (final File compare2 : files) {
  220. try {
  221. if (!pl2.getName().equalsIgnoreCase(Utils.plugin.getPluginLoader().getPluginDescription(compare2).getName())) {
  222. continue;
  223. }
  224. Utils.pm.enablePlugin(pl2);
  225. }
  226. catch (InvalidDescriptionException e) {
  227. e.printStackTrace();
  228. msg(sender, "");
  229. return;
  230. }
  231. }
  232. }
  233. }
  234.  
  235. public static void unload(String pluginName) {
  236. if (Utils.canceled) {
  237. return;
  238. }
  239. pluginName = pluginName.toLowerCase().trim();
  240. final SimplePluginManager spm = (SimplePluginManager)Utils.pm;
  241. SimpleCommandMap commandMap = null;
  242. List<Plugin> plugins = null;
  243. Map<String, Plugin> lookupNames = null;
  244. Map<String, Command> knownCommands = null;
  245. Map<Event, SortedSet<RegisteredListener>> listeners = null;
  246. boolean reloadlisteners = true;
  247. try {
  248. if (spm != null) {
  249. final Field pluginsField = spm.getClass().getDeclaredField("plugins");
  250. pluginsField.setAccessible(true);
  251. plugins = (List<Plugin>)pluginsField.get(spm);
  252. final Field lookupNamesField = spm.getClass().getDeclaredField("lookupNames");
  253. lookupNamesField.setAccessible(true);
  254. lookupNames = (Map<String, Plugin>)lookupNamesField.get(spm);
  255. try {
  256. final Field listenersField = spm.getClass().getDeclaredField("listeners");
  257. listenersField.setAccessible(true);
  258. listeners = (Map<Event, SortedSet<RegisteredListener>>)listenersField.get(spm);
  259. }
  260. catch (Exception e5) {
  261. reloadlisteners = false;
  262. }
  263. final Field commandMapField = spm.getClass().getDeclaredField("commandMap");
  264. commandMapField.setAccessible(true);
  265. commandMap = (SimpleCommandMap)commandMapField.get(spm);
  266. final Field knownCommandsField = commandMap.getClass().getDeclaredField("knownCommands");
  267. knownCommandsField.setAccessible(true);
  268. knownCommands = (Map<String, Command>)knownCommandsField.get(commandMap);
  269. }
  270. }
  271. catch (IllegalArgumentException e) {
  272. e.printStackTrace();
  273. }
  274. catch (NoSuchFieldException e2) {
  275. e2.printStackTrace();
  276. }
  277. catch (SecurityException e3) {
  278. e3.printStackTrace();
  279. }
  280. catch (IllegalAccessException e4) {
  281. e4.printStackTrace();
  282. }
  283. boolean in = false;
  284. Plugin[] plugins2;
  285. for (int length = (plugins2 = Utils.pm.getPlugins()).length, i = 0; i < length; ++i) {
  286. final Plugin pl = plugins2[i];
  287. if (pl.getName().toLowerCase().startsWith(pluginName.toLowerCase())) {
  288. Utils.pm.disablePlugin(pl);
  289. if (plugins != null && plugins.contains(pl)) {
  290. plugins.remove(pl);
  291. }
  292. if (lookupNames != null && lookupNames.containsKey(pl.getName())) {
  293. lookupNames.remove(pl.getName());
  294. }
  295. if (listeners != null && reloadlisteners) {
  296. for (final SortedSet<RegisteredListener> set : listeners.values()) {
  297. final Iterator<RegisteredListener> it = set.iterator();
  298. while (it.hasNext()) {
  299. final RegisteredListener value = it.next();
  300. if (value.getPlugin() == pl) {
  301. it.remove();
  302. }
  303. }
  304. }
  305. }
  306. if (commandMap != null) {
  307. final Iterator<Map.Entry<String, Command>> it2 = knownCommands.entrySet().iterator();
  308. while (it2.hasNext()) {
  309. final Map.Entry<String, Command> entry = it2.next();
  310. if (entry.getValue() instanceof PluginCommand) {
  311. final PluginCommand c = (PluginCommand)entry.getValue();
  312. if (c.getPlugin() != pl) {
  313. continue;
  314. }
  315. c.unregister((CommandMap)commandMap);
  316. it2.remove();
  317. }
  318. }
  319. }
  320. Plugin[] plugins3;
  321. for (int length2 = (plugins3 = Utils.pm.getPlugins()).length, j = 0; j < length2; ++j) {
  322. final Plugin plu = plugins3[j];
  323. if (plu.getDescription().getDepend() != null) {
  324. for (final String depend : plu.getDescription().getDepend()) {
  325. if (depend.equalsIgnoreCase(pl.getName())) {
  326. unload(plu.getName());
  327. }
  328. }
  329. }
  330. }
  331. in = true;
  332. break;
  333. }
  334. }
  335. if (!in) {
  336. Bukkit.getLogger().info(string("ErrorD", pluginName));
  337. }
  338. System.gc();
  339. }
  340.  
  341. public static void unload(String pluginName, final CommandSender sender) {
  342. if (Utils.canceled) {
  343. return;
  344. }
  345. pluginName = pluginName.toLowerCase().trim();
  346. final SimplePluginManager spm = (SimplePluginManager)Utils.pm;
  347. SimpleCommandMap commandMap = null;
  348. List<Plugin> plugins = null;
  349. Map<String, Plugin> lookupNames = null;
  350. Map<String, Command> knownCommands = null;
  351. Map<Event, SortedSet<RegisteredListener>> listeners = null;
  352. boolean reloadlisteners = true;
  353. try {
  354. if (spm != null) {
  355. final Field pluginsField = spm.getClass().getDeclaredField("plugins");
  356. pluginsField.setAccessible(true);
  357. plugins = (List<Plugin>)pluginsField.get(spm);
  358. final Field lookupNamesField = spm.getClass().getDeclaredField("lookupNames");
  359. lookupNamesField.setAccessible(true);
  360. lookupNames = (Map<String, Plugin>)lookupNamesField.get(spm);
  361. try {
  362. final Field listenersField = spm.getClass().getDeclaredField("listeners");
  363. listenersField.setAccessible(true);
  364. listeners = (Map<Event, SortedSet<RegisteredListener>>)listenersField.get(spm);
  365. }
  366. catch (Exception e5) {
  367. reloadlisteners = false;
  368. }
  369. final Field commandMapField = spm.getClass().getDeclaredField("commandMap");
  370. commandMapField.setAccessible(true);
  371. commandMap = (SimpleCommandMap)commandMapField.get(spm);
  372. final Field knownCommandsField = commandMap.getClass().getDeclaredField("knownCommands");
  373. knownCommandsField.setAccessible(true);
  374. knownCommands = (Map<String, Command>)knownCommandsField.get(commandMap);
  375. }
  376. }
  377. catch (IllegalArgumentException e) {
  378. e.printStackTrace();
  379. }
  380. catch (NoSuchFieldException e2) {
  381. e2.printStackTrace();
  382. }
  383. catch (SecurityException e3) {
  384. e3.printStackTrace();
  385. }
  386. catch (IllegalAccessException e4) {
  387. e4.printStackTrace();
  388. }
  389. boolean in = false;
  390. Plugin[] plugins2;
  391. for (int length = (plugins2 = Utils.pm.getPlugins()).length, i = 0; i < length; ++i) {
  392. final Plugin pl = plugins2[i];
  393. if (pl.getName().toLowerCase().startsWith(pluginName.toLowerCase())) {
  394. Utils.pm.disablePlugin(pl);
  395. if (plugins != null && plugins.contains(pl)) {
  396. plugins.remove(pl);
  397. }
  398. if (lookupNames != null && lookupNames.containsKey(pl.getName())) {
  399. lookupNames.remove(pl.getName());
  400. }
  401. if (listeners != null && reloadlisteners) {
  402. for (final SortedSet<RegisteredListener> set : listeners.values()) {
  403. final Iterator<RegisteredListener> it = set.iterator();
  404. while (it.hasNext()) {
  405. final RegisteredListener value = it.next();
  406. if (value.getPlugin() == pl) {
  407. it.remove();
  408. }
  409. }
  410. }
  411. }
  412. if (commandMap != null) {
  413. final Iterator<Map.Entry<String, Command>> it2 = knownCommands.entrySet().iterator();
  414. while (it2.hasNext()) {
  415. final Map.Entry<String, Command> entry = it2.next();
  416. if (entry.getValue() instanceof PluginCommand) {
  417. final PluginCommand c = (PluginCommand)entry.getValue();
  418. if (c.getPlugin() != pl) {
  419. continue;
  420. }
  421. c.unregister((CommandMap)commandMap);
  422. it2.remove();
  423. }
  424. }
  425. }
  426. Plugin[] plugins3;
  427. for (int length2 = (plugins3 = Utils.pm.getPlugins()).length, j = 0; j < length2; ++j) {
  428. final Plugin plu = plugins3[j];
  429. if (plu.getDescription().getDepend() != null) {
  430. for (final String depend : plu.getDescription().getDepend()) {
  431. if (depend.equalsIgnoreCase(pl.getName())) {
  432. unload(plu.getName());
  433. }
  434. }
  435. }
  436. }
  437. in = true;
  438. msg(sender, string("unload", pl.getName()));
  439. break;
  440. }
  441. }
  442. if (!in) {
  443. msg(sender, string("ErrorD", pluginName));
  444. }
  445. System.gc();
  446. }
  447.  
  448. public static void disable(final String plugin) {
  449. if (Utils.canceled) {
  450. return;
  451. }
  452. final Plugin[] plugins = Utils.pm.getPlugins();
  453. Plugin[] array;
  454. for (int length = (array = plugins).length, i = 0; i < length; ++i) {
  455. final Plugin pl = array[i];
  456. if (pl.getName().toLowerCase().startsWith(plugin.toLowerCase())) {
  457. Utils.pm.disablePlugin(pl);
  458. }
  459. }
  460. }
  461.  
  462. public static void disable(final String plugin, final CommandSender sender) {
  463. if (Utils.canceled) {
  464. return;
  465. }
  466. boolean h = false;
  467. final Plugin[] plugins = Utils.pm.getPlugins();
  468. Plugin[] array;
  469. for (int length = (array = plugins).length, i = 0; i < length; ++i) {
  470. final Plugin pl = array[i];
  471. if (pl.getName().toLowerCase().startsWith(plugin.toLowerCase())) {
  472. Utils.pm.disablePlugin(pl);
  473. h = true;
  474. msg(sender, string("disable", pl.getName()));
  475. }
  476. }
  477. if (!h) {
  478. msg(sender, string("disableError", plugin));
  479. }
  480. }
  481.  
  482. public static void hReload() {
  483. Bukkit.reload();
  484. }
  485.  
  486. public static void enable(final String plugin) {
  487. final Plugin[] plugins = Utils.pm.getPlugins();
  488. Plugin[] array;
  489. for (int length = (array = plugins).length, i = 0; i < length; ++i) {
  490. final Plugin pl = array[i];
  491. if (pl.getName().toLowerCase().startsWith(plugin.toLowerCase())) {
  492. Utils.pm.enablePlugin(pl);
  493. }
  494. }
  495. }
  496.  
  497. public static void enable(final String plugin, final CommandSender sender) {
  498. final Plugin[] plugins = Utils.pm.getPlugins();
  499. boolean h = false;
  500. Plugin[] array;
  501. for (int length = (array = plugins).length, i = 0; i < length; ++i) {
  502. final Plugin pl = array[i];
  503. if (pl.getName().toLowerCase().startsWith(plugin.toLowerCase())) {
  504. Utils.pm.enablePlugin(pl);
  505. h = true;
  506. msg(sender, string("enable", pl.getName()));
  507. return;
  508. }
  509. }
  510. if (!h) {
  511. msg(sender, string("enableError", plugin));
  512. }
  513. }
  514.  
  515. public static void use(String plugin, final CommandSender sender) {
  516. Plugin plug = null;
  517. if (plugin.trim() == "") {
  518. plugin = Utils.plugin.getName();
  519. }
  520. final Plugin[] plugins = Utils.pm.getPlugins();
  521. Plugin[] array;
  522. for (int length = (array = plugins).length, k = 0; k < length; ++k) {
  523. final Plugin pl = array[k];
  524. if (pl.getName().toLowerCase().startsWith(plugin.toLowerCase())) {
  525. plug = pl;
  526. }
  527. }
  528. if (plug == null) {
  529. msg(sender, string("notFound", plugin));
  530. return;
  531. }
  532. final ArrayList<String> out = new ArrayList<String>();
  533. final ArrayList<String> parsedCommands = new ArrayList<String>();
  534. final Map commands = plug.getDescription().getCommands();
  535. if (commands != null) {
  536. for (final Map.Entry pluginEntry : commands.entrySet()) {
  537. if (pluginEntry != null) {
  538. parsedCommands.add(pluginEntry.getKey());
  539. }
  540. }
  541. }
  542. if (!parsedCommands.isEmpty()) {
  543. StringBuilder commandsOut = new StringBuilder();
  544. msg(sender, ChatColor.RED + "Commands: ");
  545. for (int i = 0; i < parsedCommands.size(); ++i) {
  546. final String pluginCommand = parsedCommands.get(i);
  547. if (commandsOut.length() + pluginCommand.length() > 55) {
  548. msg(sender, commandsOut.toString());
  549. commandsOut = new StringBuilder();
  550. }
  551. if (parsedCommands.size() >= 10) {
  552. msg(sender, ChatColor.GREEN + parsedCommands.toString().replace("[", "").replace("]", ""));
  553. break;
  554. }
  555. msg(sender, ChatColor.RED + "* " + ChatColor.GREEN + "/" + pluginCommand);
  556. }
  557. out.add(commandsOut.toString());
  558. }
  559. if (plug.getDescription().getPermissions() != null) {
  560. final List<Permission> perms = (List<Permission>)plug.getDescription().getPermissions();
  561. if (perms.size() != 0) {
  562. msg(sender, ChatColor.RED + "Permissions:");
  563. if (perms.size() < 10) {
  564. for (int i = 0; i < perms.size(); ++i) {
  565. msg(sender, ChatColor.RED + "* " + ChatColor.GREEN + perms.get(i).getName());
  566. }
  567. }
  568. else {
  569. String s = perms.get(0).getName();
  570. for (int j = 1; j < perms.size(); ++j) {
  571. s = String.valueOf(s) + ", " + perms.get(j).getName();
  572. }
  573. msg(sender, ChatColor.GREEN + s);
  574. }
  575. }
  576. }
  577. }
  578.  
  579. public static void info(final String plugin, final CommandSender sender) {
  580. Plugin plug = null;
  581. final Plugin[] plugins = Utils.pm.getPlugins();
  582. Plugin[] array;
  583. for (int length = (array = plugins).length, k = 0; k < length; ++k) {
  584. final Plugin pl = array[k];
  585. if (pl.getName().toLowerCase().startsWith(plugin.toLowerCase())) {
  586. plug = pl;
  587. }
  588. }
  589. if (plugin == "") {
  590. plug = Utils.plugin;
  591. }
  592. if (plug == null) {
  593. msg(sender, string("notFound", plugin));
  594. return;
  595. }
  596. if (plugin != null) {
  597. msg(sender, ChatColor.RED + "Plugin info: " + ChatColor.GREEN + plug.getName());
  598. if (plug.getDescription().getAuthors() != null && !plug.getDescription().getAuthors().isEmpty()) {
  599. String author = "";
  600. final List<String> authors = (List<String>)plug.getDescription().getAuthors();
  601. for (int i = 0; i < authors.size(); ++i) {
  602. if (i == 0) {
  603. author = authors.get(i);
  604. }
  605. if (i > 1) {
  606. author = String.valueOf(author) + ", " + authors.get(i);
  607. }
  608. }
  609. msg(sender, ChatColor.RED + "Author(s): " + ChatColor.GREEN + author);
  610. }
  611. if (plug.getDescription().getDescription() != null && !plug.getDescription().getDescription().isEmpty()) {
  612. msg(sender, ChatColor.RED + "Description: " + ChatColor.GREEN + plug.getDescription().getDescription());
  613. }
  614. if (plug.getDescription().getVersion() != null && !plug.getDescription().getVersion().isEmpty()) {
  615. msg(sender, ChatColor.RED + "Version: " + ChatColor.GREEN + plug.getDescription().getVersion());
  616. }
  617. if (plug.getDescription().getWebsite() != null && !plug.getDescription().getWebsite().isEmpty()) {
  618. msg(sender, ChatColor.RED + "Website: " + ChatColor.GREEN + plug.getDescription().getWebsite());
  619. }
  620. if (plug.getDescription().getDepend() != null && !plug.getDescription().getDepend().isEmpty()) {
  621. msg(sender, ChatColor.RED + "Required plugins");
  622. final List<String> depends = (List<String>)plug.getDescription().getDepend();
  623. for (int j = 0; j < depends.size(); ++j) {
  624. msg(sender, ChatColor.RED + "* " + ChatColor.GREEN + depends.get(j));
  625. }
  626. }
  627. if (plug.getDescription().getSoftDepend() != null && !plug.getDescription().getSoftDepend().isEmpty()) {
  628. msg(sender, ChatColor.RED + "Recommended plugins");
  629. final List<String> depends = (List<String>)plug.getDescription().getSoftDepend();
  630. for (int j = 0; j < depends.size(); ++j) {
  631. msg(sender, ChatColor.RED + "* " + ChatColor.GREEN + depends.get(j));
  632. }
  633. }
  634. }
  635. }
  636.  
  637. public static boolean check(final String plugin, final CommandSender sender) {
  638. Plugin plug = null;
  639. final Plugin[] plugins = Utils.pm.getPlugins();
  640. Plugin[] array;
  641. for (int length = (array = plugins).length, i = 0; i < length; ++i) {
  642. final Plugin pl = array[i];
  643. if (pl.getName().toLowerCase().startsWith(plugin.toLowerCase())) {
  644. plug = pl;
  645. }
  646. }
  647. if (plug != null) {
  648. if (plug.isEnabled()) {
  649. msg(sender, string("enabled", plug.getName()));
  650. }
  651. else {
  652. msg(sender, string("disabled", plug.getName()));
  653. }
  654. return true;
  655. }
  656. msg(sender, string("notFound", plugin));
  657. return true;
  658. }
  659.  
  660. public static boolean perm(final CommandSender sender, final String permission) {
  661. if (Utils.pm.getPermission(permission) == null) {
  662. msg(sender, string("permNotFound", permission));
  663. return true;
  664. }
  665. if (sender.hasPermission(permission)) {
  666. msg(sender, string("senderPerm", permission));
  667. }
  668. else {
  669. msg(sender, string("senderNoPerm", permission));
  670. }
  671. return true;
  672. }
  673.  
  674. public static boolean perm(final String player, final CommandSender sender, final String permission) {
  675. if (Utils.pm.getPermission(permission) == null) {
  676. msg(sender, string("permNotFound", permission));
  677. return true;
  678. }
  679. if (Bukkit.getServer().getPlayer(player) != null) {
  680. final Player target = Bukkit.getServer().getPlayer(player);
  681. if (target.hasPermission(permission)) {
  682. msg(sender, string("userPerm", permission).replaceAll("%USER%", player));
  683. }
  684. else {
  685. msg(sender, string("userNoPerm", permission).replaceAll("%USER%", player));
  686. }
  687. }
  688. return true;
  689. }
  690.  
  691. public static boolean list(final CommandSender sender) {
  692. final Plugin[] plugins = Utils.pm.getPlugins();
  693. final ArrayList<String> enabled = new ArrayList<String>();
  694. final ArrayList<String> disabled = new ArrayList<String>();
  695. Plugin[] array;
  696. for (int length = (array = plugins).length, j = 0; j < length; ++j) {
  697. final Plugin pl = array[j];
  698. if (pl.isEnabled()) {
  699. enabled.add(pl.getName());
  700. }
  701. else {
  702. disabled.add(pl.getName());
  703. }
  704. }
  705. Collections.sort(enabled, String.CASE_INSENSITIVE_ORDER);
  706. Collections.sort(disabled, String.CASE_INSENSITIVE_ORDER);
  707. if (plugins.length != 0) {
  708. msg(sender, new StringBuilder().append(ChatColor.GREEN).append(plugins.length).append(" plugins loaded").toString());
  709. }
  710. if (!enabled.isEmpty()) {
  711. msg(sender, ChatColor.GOLD + "Enabled:");
  712. String enable = "";
  713. for (int i = 0; i < enabled.size(); ++i) {
  714. enable = String.valueOf(enable) + ", " + enabled.get(i);
  715. }
  716. enable = enable.replaceFirst(", ", "");
  717. msg(sender, ChatColor.GREEN + enable);
  718. }
  719. if (!disabled.isEmpty()) {
  720. String disable = "";
  721. msg(sender, ChatColor.GOLD + "Disabled:");
  722. for (int i = 0; i < disabled.size(); ++i) {
  723. disable = String.valueOf(disable) + ", " + disabled.get(i);
  724. }
  725. disable = disable.replaceFirst(", ", "");
  726. msg(sender, ChatColor.RED + disable);
  727. }
  728. return true;
  729. }
  730.  
  731. public static boolean vList(final CommandSender sender) {
  732. final Plugin[] plugins = Utils.pm.getPlugins();
  733. final ArrayList<String> enabled = new ArrayList<String>();
  734. final ArrayList<String> disabled = new ArrayList<String>();
  735. Plugin[] array;
  736. for (int length = (array = plugins).length, j = 0; j < length; ++j) {
  737. final Plugin pl = array[j];
  738. if (pl.isEnabled()) {
  739. enabled.add(pl.getName());
  740. }
  741. else {
  742. disabled.add(pl.getName());
  743. }
  744. }
  745. Collections.sort(enabled, String.CASE_INSENSITIVE_ORDER);
  746. Collections.sort(disabled, String.CASE_INSENSITIVE_ORDER);
  747. if (plugins.length != 0) {
  748. msg(sender, new StringBuilder().append(ChatColor.GREEN).append(plugins.length).append(" plugins loaded").toString());
  749. }
  750. if (!enabled.isEmpty()) {
  751. msg(sender, ChatColor.GOLD + "Enabled:");
  752. String enable = "";
  753. for (int i = 0; i < enabled.size(); ++i) {
  754. enable = String.valueOf(enable) + ChatColor.GREEN + ", " + enabled.get(i) + ChatColor.GRAY + " " + Utils.pm.getPlugin((String)enabled.get(i)).getDescription().getVersion();
  755. }
  756. enable = enable.replaceFirst(", ", "");
  757. msg(sender, ChatColor.GREEN + enable);
  758. }
  759. if (!disabled.isEmpty()) {
  760. String disable = "";
  761. msg(sender, ChatColor.GOLD + "Disabled:");
  762. for (int i = 0; i < disabled.size(); ++i) {
  763. disable = String.valueOf(disable) + ", " + disabled.get(i) + ChatColor.GRAY + " " + Utils.pm.getPlugin((String)disabled.get(i)).getDescription().getVersion();
  764. }
  765. disable = disable.replaceFirst(", ", "");
  766. msg(sender, ChatColor.RED + disable);
  767. }
  768. return true;
  769. }
  770.  
  771. public static void msg(final CommandSender sender, final String msg) {
  772. if (sender instanceof Player) {
  773. sender.sendMessage(msg);
  774. }
  775. else {
  776. final Logger log = Bukkit.getServer().getLogger();
  777. log.info(msg);
  778. }
  779. }
  780.  
  781. public static boolean help(final CommandSender sender) {
  782. msg(sender, string("helpHead"));
  783. if (permCheck(sender, "reloader.reload")) {
  784. msg(sender, string("helpReload"));
  785. }
  786. if (permCheck(sender, "reloader.disable")) {
  787. msg(sender, string("helpDisable"));
  788. }
  789. if (permCheck(sender, "reloader.enable")) {
  790. msg(sender, string("helpEnable"));
  791. }
  792. if (permCheck(sender, "reloader.load")) {
  793. msg(sender, string("helpLoad"));
  794. }
  795. if (permCheck(sender, "reloader.unload")) {
  796. msg(sender, string("helpUnload"));
  797. }
  798. if (permCheck(sender, "reloader.check")) {
  799. msg(sender, string("helpCheck"));
  800. }
  801. if (permCheck(sender, "reloader.info")) {
  802. msg(sender, string("helpInfo"));
  803. }
  804. if (permCheck(sender, "reloader.use")) {
  805. msg(sender, string("helpUse"));
  806. }
  807. if (permCheck(sender, "reloader.perm")) {
  808. msg(sender, string("helpPerm"));
  809. }
  810. if (permCheck(sender, "reloader.list")) {
  811. msg(sender, string("helpList"));
  812. }
  813. if (permCheck(sender, "reloader.list")) {
  814. msg(sender, string("helpListV"));
  815. }
  816. if (permCheck(sender, "reloader.config")) {
  817. msg(sender, string("helpConfig"));
  818. }
  819. return true;
  820. }
  821.  
  822. public static boolean exempt(final String name) {
  823. for (final String ex : Utils.plugin.getConfig().getStringList("exempt")) {
  824. if (ex.toLowerCase().startsWith(name.toLowerCase())) {
  825. Utils.canceledPl = ex;
  826. return true;
  827. }
  828. }
  829. return false;
  830. }
  831.  
  832. public static String join(final String[] args) {
  833. String l = "";
  834. for (int i = 1; i < args.length; ++i) {
  835. l = String.valueOf(l) + " " + args[i];
  836. }
  837. l = l.toLowerCase().trim();
  838. return l;
  839. }
  840.  
  841. public static void scheduler() {
  842. if (!Utils.plugin.getConfig().getString("timer.message").isEmpty()) {
  843. Bukkit.getServer().broadcastMessage(Utils.plugin.getConfig().getString("timer.message").replaceAll("&(?=[0-9a-fA-FkKmMoOlLnNrR])", "§"));
  844. }
  845. final Plugin[] plugins = Utils.pm.getPlugins();
  846. if (Utils.plugin.getConfig().getBoolean("timer.all")) {
  847. Plugin[] array;
  848. for (int length = (array = plugins).length, i = 0; i < length; ++i) {
  849. final Plugin pl = array[i];
  850. if (!pl.getName().toLowerCase().startsWith(Utils.plugin.getName().toLowerCase()) && !exempt(pl.getName())) {
  851. unload(pl.getName());
  852. load(pl.getName());
  853. }
  854. }
  855. }
  856. else {
  857. for (final String li : Utils.plugin.getConfig().getStringList("timer.list")) {
  858. Plugin[] plugins2;
  859. for (int length2 = (plugins2 = Utils.pm.getPlugins()).length, j = 0; j < length2; ++j) {
  860. final Plugin pl2 = plugins2[j];
  861. if (pl2.getName().toLowerCase().startsWith(li.toLowerCase()) && !exempt(pl2.getName())) {
  862. unload(pl2.getName());
  863. load(pl2.getName());
  864. }
  865. }
  866. }
  867. }
  868. }
  869.  
  870. public static void localize() {
  871. Utils.plugin.saveResource("locale.yml", true);
  872. Utils.locale = (FileConfiguration)YamlConfiguration.loadConfiguration(Utils.localeFile);
  873. try {
  874. Utils.locale.load(Utils.localeFile);
  875. }
  876. catch (IOException | InvalidConfigurationException ex2) {
  877. final Exception ex;
  878. final Exception e = ex;
  879. e.printStackTrace();
  880. }
  881. Utils.plugin.getServer().broadcastMessage(Utils.locale.getString("test"));
  882. }
  883.  
  884. public static String string(final String s) {
  885. if (Utils.locale.getString(s) != null) {
  886. return Utils.locale.getString(s).replaceAll("&(?=[0-9a-fA-FkKmMoOlLnNrR])", "§");
  887. }
  888. return "";
  889. }
  890.  
  891. public static String string(final String s, final String replac) {
  892. if (Utils.locale.getString(s) != null) {
  893. return Utils.locale.getString(s).replaceAll("&(?=[0-9a-fA-FkKmMoOlLnNrR])", "§").replaceAll("%NAME%", replac);
  894. }
  895. return "";
  896. }
  897.  
  898. public static boolean permCheck(final CommandSender sender, final String perm) {
  899. return sender.hasPermission(perm);
  900. }
  901. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement