Advertisement
Guest User

Untitled

a guest
Jan 21st, 2017
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 30.91 KB | None | 0 0
  1. package io.github.bedwarsrel.BedwarsRel;
  2.  
  3. import com.bugsnag.Bugsnag;
  4. import com.bugsnag.Report;
  5. import com.bugsnag.callbacks.Callback;
  6. import com.google.common.collect.ImmutableMap;
  7. import io.github.bedwarsrel.BedwarsRel.Commands.AddGameCommand;
  8. import io.github.bedwarsrel.BedwarsRel.Commands.AddHoloCommand;
  9. import io.github.bedwarsrel.BedwarsRel.Commands.AddTeamCommand;
  10. import io.github.bedwarsrel.BedwarsRel.Commands.AddTeamJoinCommand;
  11. import io.github.bedwarsrel.BedwarsRel.Commands.BaseCommand;
  12. import io.github.bedwarsrel.BedwarsRel.Commands.ClearSpawnerCommand;
  13. import io.github.bedwarsrel.BedwarsRel.Commands.DebugPasteCommand;
  14. import io.github.bedwarsrel.BedwarsRel.Commands.GameTimeCommand;
  15. import io.github.bedwarsrel.BedwarsRel.Commands.HelpCommand;
  16. import io.github.bedwarsrel.BedwarsRel.Commands.JoinGameCommand;
  17. import io.github.bedwarsrel.BedwarsRel.Commands.KickCommand;
  18. import io.github.bedwarsrel.BedwarsRel.Commands.LeaveGameCommand;
  19. import io.github.bedwarsrel.BedwarsRel.Commands.ListGamesCommand;
  20. import io.github.bedwarsrel.BedwarsRel.Commands.RegionNameCommand;
  21. import io.github.bedwarsrel.BedwarsRel.Commands.ReloadCommand;
  22. import io.github.bedwarsrel.BedwarsRel.Commands.RemoveGameCommand;
  23. import io.github.bedwarsrel.BedwarsRel.Commands.RemoveHoloCommand;
  24. import io.github.bedwarsrel.BedwarsRel.Commands.RemoveTeamCommand;
  25. import io.github.bedwarsrel.BedwarsRel.Commands.SaveGameCommand;
  26. import io.github.bedwarsrel.BedwarsRel.Commands.SetAutobalanceCommand;
  27. import io.github.bedwarsrel.BedwarsRel.Commands.SetBedCommand;
  28. import io.github.bedwarsrel.BedwarsRel.Commands.SetBuilderCommand;
  29. import io.github.bedwarsrel.BedwarsRel.Commands.SetGameBlockCommand;
  30. import io.github.bedwarsrel.BedwarsRel.Commands.SetLobbyCommand;
  31. import io.github.bedwarsrel.BedwarsRel.Commands.SetMainLobbyCommand;
  32. import io.github.bedwarsrel.BedwarsRel.Commands.SetMinPlayersCommand;
  33. import io.github.bedwarsrel.BedwarsRel.Commands.SetRegionCommand;
  34. import io.github.bedwarsrel.BedwarsRel.Commands.SetSpawnCommand;
  35. import io.github.bedwarsrel.BedwarsRel.Commands.SetSpawnerCommand;
  36. import io.github.bedwarsrel.BedwarsRel.Commands.SetTargetCommand;
  37. import io.github.bedwarsrel.BedwarsRel.Commands.StartGameCommand;
  38. import io.github.bedwarsrel.BedwarsRel.Commands.StatsCommand;
  39. import io.github.bedwarsrel.BedwarsRel.Commands.StopGameCommand;
  40. import io.github.bedwarsrel.BedwarsRel.Database.DatabaseManager;
  41. import io.github.bedwarsrel.BedwarsRel.Game.Game;
  42. import io.github.bedwarsrel.BedwarsRel.Game.GameManager;
  43. import io.github.bedwarsrel.BedwarsRel.Game.GameState;
  44. import io.github.bedwarsrel.BedwarsRel.Game.Region;
  45. import io.github.bedwarsrel.BedwarsRel.Game.RessourceSpawner;
  46. import io.github.bedwarsrel.BedwarsRel.Game.Team;
  47. import io.github.bedwarsrel.BedwarsRel.Listener.BlockListener;
  48. import io.github.bedwarsrel.BedwarsRel.Listener.ChunkListener;
  49. import io.github.bedwarsrel.BedwarsRel.Listener.EntityListener;
  50. import io.github.bedwarsrel.BedwarsRel.Listener.HangingListener;
  51. import io.github.bedwarsrel.BedwarsRel.Listener.Player19Listener;
  52. import io.github.bedwarsrel.BedwarsRel.Listener.PlayerListener;
  53. import io.github.bedwarsrel.BedwarsRel.Listener.PlayerSpigotListener;
  54. import io.github.bedwarsrel.BedwarsRel.Listener.ServerListener;
  55. import io.github.bedwarsrel.BedwarsRel.Listener.SignListener;
  56. import io.github.bedwarsrel.BedwarsRel.Listener.WeatherListener;
  57. import io.github.bedwarsrel.BedwarsRel.Localization.LocalizationConfig;
  58. import io.github.bedwarsrel.BedwarsRel.Shop.Specials.SpecialItem;
  59. import io.github.bedwarsrel.BedwarsRel.Statistics.PlayerStatisticManager;
  60. import io.github.bedwarsrel.BedwarsRel.Statistics.StorageType;
  61. import io.github.bedwarsrel.BedwarsRel.Updater.ConfigUpdater;
  62. import io.github.bedwarsrel.BedwarsRel.Updater.DatabaseUpdater;
  63. import io.github.bedwarsrel.BedwarsRel.Updater.PluginUpdater;
  64. import io.github.bedwarsrel.BedwarsRel.Updater.PluginUpdater.UpdateCallback;
  65. import io.github.bedwarsrel.BedwarsRel.Updater.PluginUpdater.UpdateResult;
  66. import io.github.bedwarsrel.BedwarsRel.Updater.PluginUpdater.UpdateType;
  67. import io.github.bedwarsrel.BedwarsRel.Utils.BedwarsCommandExecutor;
  68. import io.github.bedwarsrel.BedwarsRel.Utils.ChatWriter;
  69. import io.github.bedwarsrel.BedwarsRel.Utils.SupportData;
  70. import io.github.bedwarsrel.BedwarsRel.Utils.Utils;
  71. import java.io.BufferedReader;
  72. import java.io.File;
  73. import java.io.FileInputStream;
  74. import java.io.FileOutputStream;
  75. import java.io.InputStreamReader;
  76. import java.io.OutputStreamWriter;
  77. import java.util.ArrayList;
  78. import java.util.Iterator;
  79. import java.util.List;
  80. import java.util.Map;
  81. import java.util.Map.Entry;
  82. import org.bukkit.Bukkit;
  83. import org.bukkit.ChatColor;
  84. import org.bukkit.Location;
  85. import org.bukkit.Material;
  86. import org.bukkit.Server;
  87. import org.bukkit.World;
  88. import org.bukkit.command.ConsoleCommandSender;
  89. import org.bukkit.command.PluginCommand;
  90. import org.bukkit.configuration.file.FileConfiguration;
  91. import org.bukkit.configuration.file.FileConfigurationOptions;
  92. import org.bukkit.configuration.file.YamlConfiguration;
  93. import org.bukkit.configuration.serialization.ConfigurationSerialization;
  94. import org.bukkit.plugin.PluginDescriptionFile;
  95. import org.bukkit.plugin.PluginManager;
  96. import org.bukkit.plugin.java.JavaPlugin;
  97. import org.bukkit.plugin.messaging.Messenger;
  98. import org.bukkit.scheduler.BukkitRunnable;
  99. import org.bukkit.scheduler.BukkitScheduler;
  100. import org.bukkit.scheduler.BukkitTask;
  101. import org.bukkit.scoreboard.ScoreboardManager;
  102. import org.mcstats.Metrics;
  103.  
  104. public class Main
  105. extends JavaPlugin
  106. {
  107. private static Main instance = null;
  108. public static int PROJECT_ID = 91743;
  109. private ArrayList<BaseCommand> commands = new ArrayList();
  110. private BukkitTask timeTask = null;
  111. private Package craftbukkit = null;
  112. private Package minecraft = null;
  113. private String version = null;
  114. private LocalizationConfig localization = null;
  115. private DatabaseManager dbManager = null;
  116. private BukkitTask updateChecker = null;
  117. private List<Material> breakableTypes = null;
  118. private YamlConfiguration shopConfig = null;
  119. private IHologramInteraction holographicInteraction = null;
  120. private boolean isSpigot = false;
  121. private static Boolean locationSerializable = null;
  122. private PlayerStatisticManager playerStatisticManager = null;
  123. private ScoreboardManager scoreboardManager = null;
  124. private GameManager gameManager = null;
  125. private Bugsnag bugsnag;
  126.  
  127. public Bugsnag getBugsnag()
  128. {
  129. return this.bugsnag;
  130. }
  131.  
  132. public void onEnable()
  133. {
  134. instance = this;
  135.  
  136. registerBugsnag();
  137.  
  138. registerConfigurationClasses();
  139.  
  140. saveDefaultConfig();
  141. loadConfigInUTF();
  142.  
  143. getConfig().options().copyDefaults(true);
  144. getConfig().options().copyHeader(true);
  145.  
  146. this.craftbukkit = getCraftBukkit();
  147. this.minecraft = getMinecraftPackage();
  148. this.version = loadVersion();
  149.  
  150. ConfigUpdater configUpdater = new ConfigUpdater();
  151. configUpdater.addConfigs();
  152. saveConfiguration();
  153. loadConfigInUTF();
  154. if (getBooleanConfig("send-error-data", true)) {
  155. enableBugsnag();
  156. } else {
  157. disableBugsnag();
  158. }
  159. configUpdater.updateShop();
  160. loadShop();
  161.  
  162. this.isSpigot = getIsSpigot();
  163. loadDatabase();
  164.  
  165. registerCommands();
  166. registerListener();
  167.  
  168. this.gameManager = new GameManager();
  169. if (getInstance().isBungee()) {
  170. getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
  171. }
  172. loadStatistics();
  173. this.localization = loadLocalization();
  174.  
  175. checkUpdates();
  176.  
  177. this.scoreboardManager = Bukkit.getScoreboardManager();
  178. this.gameManager.loadGames();
  179. startTimeListener();
  180. startMetricsIfEnabled();
  181. if (isHologramsEnabled())
  182. {
  183. if (getServer().getPluginManager().isPluginEnabled("HologramAPI")) {
  184. this.holographicInteraction = new HologramAPIInteraction();
  185. } else if (getServer().getPluginManager().isPluginEnabled("HolographicDisplays")) {
  186. this.holographicInteraction = new HolographicDisplaysInteraction();
  187. }
  188. this.holographicInteraction.loadHolograms();
  189. }
  190. }
  191.  
  192. private void registerBugsnag()
  193. {
  194. this.bugsnag = new Bugsnag("c23593c1e2f40fc0da36564af1bd00c6");
  195. this.bugsnag.setAppVersion(SupportData.getPluginVersion());
  196. this.bugsnag.setProjectPackages(new String[] { "io.github.bedwarsrel" });
  197. this.bugsnag.setReleaseStage(SupportData.getPluginVersionType());
  198. }
  199.  
  200. private void enableBugsnag()
  201. {
  202. this.bugsnag.addCallback(new Callback()
  203. {
  204. public void beforeNotify(Report report)
  205. {
  206. Boolean shouldBeSent = Boolean.valueOf(false);
  207. for (StackTraceElement stackTraceElement : report.getException().getStackTrace()) {
  208. if (stackTraceElement.toString().contains("io.github.bedwarsrel.BedwarsRel"))
  209. {
  210. shouldBeSent = Boolean.valueOf(true);
  211. break;
  212. }
  213. }
  214. if (!shouldBeSent.booleanValue()) {
  215. report.cancel();
  216. }
  217. report.setUserId(SupportData.getIdentifier());
  218. if (!SupportData.getPluginVersionBuild().equalsIgnoreCase("unknown")) {
  219. report.addToTab("Server", "Version Build", Main.getInstance().getDescription().getVersion() + " " + SupportData.getPluginVersionBuild());
  220. }
  221. report.addToTab("Server", "Version", SupportData.getServerVersion());
  222. report.addToTab("Server", "Version Bukkit", SupportData.getBukkitVersion());
  223. report.addToTab("Server", "Server Mode", SupportData.getServerMode());
  224. report.addToTab("Server", "Plugins", SupportData.getPlugins());
  225. }
  226. });
  227. }
  228.  
  229. private void disableBugsnag()
  230. {
  231. this.bugsnag.addCallback(new Callback()
  232. {
  233. public void beforeNotify(Report report)
  234. {
  235. report.cancel();
  236. }
  237. });
  238. }
  239.  
  240. public void onDisable()
  241. {
  242. stopTimeListener();
  243. this.gameManager.unloadGames();
  244. cleanDatabase();
  245. if ((isHologramsEnabled()) && (this.holographicInteraction != null)) {
  246. this.holographicInteraction.unloadHolograms();
  247. }
  248. }
  249.  
  250. public void loadConfigInUTF()
  251. {
  252. File configFile = new File(getDataFolder(), "config.yml");
  253. if (!configFile.exists()) {
  254. return;
  255. }
  256. try
  257. {
  258. BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(configFile), "UTF-8"));
  259.  
  260. getConfig().load(reader);
  261. }
  262. catch (Exception e)
  263. {
  264. getInstance().getBugsnag().notify(e);
  265. e.printStackTrace();
  266. }
  267. if (getConfig() == null) {
  268. return;
  269. }
  270. this.breakableTypes = new ArrayList();
  271. for (String material : getConfig().getStringList("breakable-blocks.list")) {
  272. if (!material.equalsIgnoreCase("none"))
  273. {
  274. Material mat = Utils.parseMaterial(material);
  275. if ((mat != null) &&
  276.  
  277. (!this.breakableTypes.contains(mat))) {
  278. this.breakableTypes.add(mat);
  279. }
  280. }
  281. }
  282. }
  283.  
  284. public void loadShop()
  285. {
  286. File file = new File(getInstance().getDataFolder(), "shop.yml");
  287. if (!file.exists())
  288. {
  289. saveResource("shop.yml", false);
  290. try
  291. {
  292. Thread.sleep(100L);
  293. }
  294. catch (InterruptedException e)
  295. {
  296. getInstance().getBugsnag().notify(e);
  297. e.printStackTrace();
  298. }
  299. }
  300. this.shopConfig = new YamlConfiguration();
  301. try
  302. {
  303. BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));
  304.  
  305. this.shopConfig.load(reader);
  306. }
  307. catch (Exception e)
  308. {
  309. getInstance().getBugsnag().notify(e);
  310. getServer().getConsoleSender().sendMessage(ChatWriter.pluginMessage(ChatColor.RED + "Couldn't load shop! Error in parsing shop!"));
  311.  
  312. e.printStackTrace();
  313. }
  314. }
  315.  
  316. public void dispatchRewardCommands(List<String> commands, Map<String, String> replacements)
  317. {
  318. for (String command : commands)
  319. {
  320. command = command.trim();
  321. if (!"".equals(command))
  322. {
  323. if ("none".equalsIgnoreCase(command)) {
  324. break;
  325. }
  326. if (command.startsWith("/")) {
  327. command = command.substring(1);
  328. }
  329. for (Map.Entry<String, String> entry : replacements.entrySet()) {
  330. command = command.replace((CharSequence)entry.getKey(), (CharSequence)entry.getValue());
  331. }
  332. getInstance().getServer().dispatchCommand(getInstance().getServer().getConsoleSender(), command);
  333. }
  334. }
  335. }
  336.  
  337. public void saveConfiguration()
  338. {
  339. File file = new File(getInstance().getDataFolder(), "config.yml");
  340. try
  341. {
  342. file.mkdirs();
  343.  
  344. String data = getYamlDump((YamlConfiguration)getConfig());
  345.  
  346. FileOutputStream stream = new FileOutputStream(file);
  347. OutputStreamWriter writer = new OutputStreamWriter(stream, "UTF-8");
  348. try
  349. {
  350. writer.write(data);
  351. }
  352. finally
  353. {
  354. writer.close();
  355. stream.close();
  356. }
  357. }
  358. catch (Exception ex)
  359. {
  360. getInstance().getBugsnag().notify(ex);
  361. ex.printStackTrace();
  362. }
  363. }
  364.  
  365. public Class<?> getVersionRelatedClass(String className)
  366. {
  367. try
  368. {
  369. return Class.forName("io.github.bedwarsrel.BedwarsRel.Com." + getCurrentVersion() + "." + className);
  370. }
  371. catch (Exception ex)
  372. {
  373. getInstance().getBugsnag().notify(ex);
  374. getServer().getConsoleSender().sendMessage(ChatWriter.pluginMessage(ChatColor.RED + "Couldn't find version related class io.github.bedwarsrel.BedwarsRel.Com." + getCurrentVersion() + "." + className));
  375. }
  376. return null;
  377. }
  378.  
  379. public String getYamlDump(YamlConfiguration config)
  380. {
  381. try
  382. {
  383. String fullstring = config.saveToString();
  384. String endstring = fullstring;
  385. return Utils.unescape_perl_string(fullstring);
  386. }
  387. catch (Exception ex)
  388. {
  389. getInstance().getBugsnag().notify(ex);
  390. ex.printStackTrace();
  391. }
  392. return null;
  393. }
  394.  
  395. public boolean isBreakableType(Material type)
  396. {
  397. return ((getInstance().getConfig().getBoolean("breakable-blocks.use-as-blacklist")) && (!this.breakableTypes.contains(type))) || ((!getInstance().getConfig().getBoolean("breakable-blocks.use-as-blacklist")) && (this.breakableTypes.contains(type)));
  398. }
  399.  
  400. public boolean isMineshafterPresent()
  401. {
  402. try
  403. {
  404. Class.forName("mineshafter.MineServer");
  405. return true;
  406. }
  407. catch (Exception e) {}
  408. return false;
  409. }
  410.  
  411. public PlayerStatisticManager getPlayerStatisticManager()
  412. {
  413. return this.playerStatisticManager;
  414. }
  415.  
  416. private void checkUpdates()
  417. {
  418. try
  419. {
  420. if (getBooleanConfig("check-updates", true)) {
  421. this.updateChecker = new BukkitRunnable()
  422. {
  423. public void run()
  424. {
  425. final BukkitRunnable task = this;
  426. PluginUpdater.UpdateCallback callback = new PluginUpdater.UpdateCallback()
  427. {
  428. public void onFinish(PluginUpdater updater)
  429. {
  430. if (updater.getResult() == PluginUpdater.UpdateResult.SUCCESS) {
  431. task.cancel();
  432. }
  433. }
  434. };
  435. new PluginUpdater(Main.getInstance(), Main.PROJECT_ID, Main.getInstance().getFile(), PluginUpdater.UpdateType.DEFAULT, callback, Main.getInstance().getBooleanConfig("update-infos", true));
  436. }
  437. }.runTaskTimerAsynchronously(getInstance(), 40L, 36000L);
  438. }
  439. }
  440. catch (Exception ex)
  441. {
  442. getInstance().getBugsnag().notify(ex);
  443. getServer().getConsoleSender().sendMessage(ChatWriter.pluginMessage(ChatColor.RED + "Check for updates not successful: Error!"));
  444. }
  445. }
  446.  
  447. private LocalizationConfig loadLocalization()
  448. {
  449. LocalizationConfig config = new LocalizationConfig();
  450. config.loadLocale(getConfig().getString("locale"), false);
  451. return config;
  452. }
  453.  
  454. private void loadStatistics()
  455. {
  456. this.playerStatisticManager = new PlayerStatisticManager();
  457. this.playerStatisticManager.initialize();
  458. }
  459.  
  460. private void loadDatabase()
  461. {
  462. if ((!getBooleanConfig("statistics.enabled", false)) || (!"database".equals(getStringConfig("statistics.storage", "yaml")))) {
  463. return;
  464. }
  465. getServer().getConsoleSender().sendMessage(ChatWriter.pluginMessage(ChatColor.GREEN + "Initialize database ..."));
  466.  
  467. String host = getStringConfig("database.host", null);
  468. int port = getIntConfig("database.port", 3306);
  469. String user = getStringConfig("database.user", null);
  470. String password = getStringConfig("database.password", null);
  471. String db = getStringConfig("database.db", null);
  472. if ((host == null) || (user == null) || (password == null) || (db == null)) {
  473. return;
  474. }
  475. this.dbManager = new DatabaseManager(host, port, user, password, db);
  476. this.dbManager.initialize();
  477.  
  478. getServer().getConsoleSender().sendMessage(ChatWriter.pluginMessage(ChatColor.GREEN + "Update database ..."));
  479.  
  480. new DatabaseUpdater().execute();
  481.  
  482. getServer().getConsoleSender().sendMessage(ChatWriter.pluginMessage(ChatColor.GREEN + "Done."));
  483. }
  484.  
  485. public StorageType getStatisticStorageType()
  486. {
  487. String storage = getStringConfig("statistics.storage", "yaml");
  488. return StorageType.getByName(storage);
  489. }
  490.  
  491. public boolean statisticsEnabled()
  492. {
  493. return getBooleanConfig("statistics.enabled", false);
  494. }
  495.  
  496. private void cleanDatabase()
  497. {
  498. if (this.dbManager != null) {
  499. this.dbManager.cleanUp();
  500. }
  501. }
  502.  
  503. public DatabaseManager getDatabaseManager()
  504. {
  505. return this.dbManager;
  506. }
  507.  
  508. public boolean isSpigot()
  509. {
  510. return this.isSpigot;
  511. }
  512.  
  513. private boolean getIsSpigot()
  514. {
  515. try
  516. {
  517. Package spigotPackage = Package.getPackage("org.spigotmc");
  518. return spigotPackage != null;
  519. }
  520. catch (Exception e)
  521. {
  522. getInstance().getBugsnag().notify(e);
  523. }
  524. return false;
  525. }
  526.  
  527. public int getIntConfig(String key, int defaultInt)
  528. {
  529. FileConfiguration config = getConfig();
  530. if ((config.contains(key)) && (config.isInt(key))) {
  531. return config.getInt(key);
  532. }
  533. return defaultInt;
  534. }
  535.  
  536. public String getStringConfig(String key, String defaultString)
  537. {
  538. FileConfiguration config = getConfig();
  539. if ((config.contains(key)) && (config.isString(key))) {
  540. return config.getString(key);
  541. }
  542. return defaultString;
  543. }
  544.  
  545. public boolean getBooleanConfig(String key, boolean defaultBool)
  546. {
  547. FileConfiguration config = getConfig();
  548. if ((config.contains(key)) && (config.isBoolean(key))) {
  549. return config.getBoolean(key);
  550. }
  551. return defaultBool;
  552. }
  553.  
  554. public LocalizationConfig getLocalization()
  555. {
  556. return this.localization;
  557. }
  558.  
  559. private String loadVersion()
  560. {
  561. String packName = Bukkit.getServer().getClass().getPackage().getName();
  562. return packName.substring(packName.lastIndexOf('.') + 1);
  563. }
  564.  
  565. public String getCurrentVersion()
  566. {
  567. return this.version;
  568. }
  569.  
  570. public boolean isBungee()
  571. {
  572. return getConfig().getBoolean("bungeecord.enabled");
  573. }
  574.  
  575. public String getBungeeHub()
  576. {
  577. if (getConfig().contains("bungeecord.hubserver")) {
  578. return getConfig().getString("bungeecord.hubserver");
  579. }
  580. return null;
  581. }
  582.  
  583. public Package getCraftBukkit()
  584. {
  585. try
  586. {
  587. if (this.craftbukkit == null) {
  588. return Package.getPackage("org.bukkit.craftbukkit." + Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3]);
  589. }
  590. return this.craftbukkit;
  591. }
  592. catch (Exception ex)
  593. {
  594. getInstance().getBugsnag().notify(ex);
  595. getServer().getConsoleSender().sendMessage(ChatWriter.pluginMessage(ChatColor.RED + _l("errors.packagenotfound", ImmutableMap.of("package", "craftbukkit"))));
  596. }
  597. return null;
  598. }
  599.  
  600. public Package getMinecraftPackage()
  601. {
  602. try
  603. {
  604. if (this.minecraft == null) {
  605. return Package.getPackage("net.minecraft.server." + Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3]);
  606. }
  607. return this.minecraft;
  608. }
  609. catch (Exception ex)
  610. {
  611. getInstance().getBugsnag().notify(ex);
  612. getServer().getConsoleSender().sendMessage(ChatWriter.pluginMessage(ChatColor.RED + _l("errors.packagenotfound", ImmutableMap.of("package", "minecraft server"))));
  613. }
  614. return null;
  615. }
  616.  
  617. public Class getCraftBukkitClass(String classname)
  618. {
  619. try
  620. {
  621. if (this.craftbukkit == null) {
  622. this.craftbukkit = getCraftBukkit();
  623. }
  624. return Class.forName(this.craftbukkit.getName() + "." + classname);
  625. }
  626. catch (Exception ex)
  627. {
  628. getInstance().getBugsnag().notify(ex);
  629. getServer().getConsoleSender().sendMessage(ChatWriter.pluginMessage(ChatColor.RED + _l("errors.classnotfound", ImmutableMap.of("package", "craftbukkit", "class", classname))));
  630. }
  631. return null;
  632. }
  633.  
  634. public Class getMinecraftServerClass(String classname)
  635. {
  636. try
  637. {
  638. if (this.minecraft == null) {
  639. this.minecraft = getMinecraftPackage();
  640. }
  641. return Class.forName(this.minecraft.getName() + "." + classname);
  642. }
  643. catch (Exception ex)
  644. {
  645. getInstance().getBugsnag().notify(ex);
  646. getServer().getConsoleSender().sendMessage(ChatWriter.pluginMessage(ChatColor.RED + _l("errors.classnotfound", ImmutableMap.of("package", "minecraft server", "class", classname))));
  647. }
  648. return null;
  649. }
  650.  
  651. public boolean metricsEnabled()
  652. {
  653. if ((getConfig().contains("plugin-metrics")) && (getConfig().isBoolean("plugin-metrics"))) {
  654. return getConfig().getBoolean("plugin-metrics");
  655. }
  656. return false;
  657. }
  658.  
  659. public void startMetricsIfEnabled()
  660. {
  661. if (metricsEnabled()) {
  662. try
  663. {
  664. Metrics metrics = new Metrics(this);
  665. metrics.start();
  666. }
  667. catch (Exception ex)
  668. {
  669. getInstance().getBugsnag().notify(ex);
  670. getServer().getConsoleSender().sendMessage(ChatWriter.pluginMessage(ChatColor.RED + "Metrics are enabled, but couldn't send data!"));
  671. }
  672. }
  673. }
  674.  
  675. public String getFallbackLocale()
  676. {
  677. return "en_US";
  678. }
  679.  
  680. public boolean allPlayersBackToMainLobby()
  681. {
  682. if ((getConfig().contains("endgame.all-players-to-mainlobby")) && (getConfig().isBoolean("endgame.all-players-to-mainlobby"))) {
  683. return getConfig().getBoolean("endgame.all-players-to-mainlobby");
  684. }
  685. return false;
  686. }
  687.  
  688. public List<String> getAllowedCommands()
  689. {
  690. FileConfiguration config = getConfig();
  691. if ((config.contains("allowed-commands")) && (config.isList("allowed-commands"))) {
  692. return config.getStringList("allowed-commands");
  693. }
  694. return new ArrayList();
  695. }
  696.  
  697. public static Main getInstance()
  698. {
  699. return instance;
  700. }
  701.  
  702. public ScoreboardManager getScoreboardManager()
  703. {
  704. return this.scoreboardManager;
  705. }
  706.  
  707. private void registerListener()
  708. {
  709. new WeatherListener();
  710. new BlockListener();
  711. new PlayerListener();
  712. if ((getInstance().getCurrentVersion().startsWith("v1_9")) || (getInstance().getCurrentVersion().startsWith("v1_10")) || (getInstance().getCurrentVersion().startsWith("v1_11"))) {
  713. new Player19Listener();
  714. }
  715. new HangingListener();
  716. new EntityListener();
  717. new ServerListener();
  718. new SignListener();
  719. new ChunkListener();
  720. if (isSpigot()) {
  721. new PlayerSpigotListener();
  722. }
  723. SpecialItem.loadSpecials();
  724. }
  725.  
  726. private void registerConfigurationClasses()
  727. {
  728. ConfigurationSerialization.registerClass(RessourceSpawner.class, "RessourceSpawner");
  729. ConfigurationSerialization.registerClass(Team.class, "Team");
  730. }
  731.  
  732. private void registerCommands()
  733. {
  734. BedwarsCommandExecutor executor = new BedwarsCommandExecutor(this);
  735.  
  736. this.commands.add(new HelpCommand(this));
  737. this.commands.add(new SetSpawnerCommand(this));
  738. this.commands.add(new AddGameCommand(this));
  739. this.commands.add(new StartGameCommand(this));
  740. this.commands.add(new StopGameCommand(this));
  741. this.commands.add(new SetRegionCommand(this));
  742. this.commands.add(new AddTeamCommand(this));
  743. this.commands.add(new SaveGameCommand(this));
  744. this.commands.add(new JoinGameCommand(this));
  745. this.commands.add(new SetSpawnCommand(this));
  746. this.commands.add(new SetLobbyCommand(this));
  747. this.commands.add(new LeaveGameCommand(this));
  748. this.commands.add(new SetTargetCommand(this));
  749. this.commands.add(new SetBedCommand(this));
  750. this.commands.add(new ReloadCommand(this));
  751. this.commands.add(new SetMainLobbyCommand(this));
  752. this.commands.add(new ListGamesCommand(this));
  753. this.commands.add(new RegionNameCommand(this));
  754. this.commands.add(new RemoveTeamCommand(this));
  755. this.commands.add(new RemoveGameCommand(this));
  756. this.commands.add(new ClearSpawnerCommand(this));
  757. this.commands.add(new GameTimeCommand(this));
  758. this.commands.add(new StatsCommand(this));
  759. this.commands.add(new SetMinPlayersCommand(this));
  760. this.commands.add(new SetGameBlockCommand(this));
  761. this.commands.add(new SetBuilderCommand(this));
  762. this.commands.add(new SetAutobalanceCommand(this));
  763. this.commands.add(new KickCommand(this));
  764. this.commands.add(new AddTeamJoinCommand(this));
  765. this.commands.add(new AddHoloCommand(this));
  766. this.commands.add(new RemoveHoloCommand(this));
  767. this.commands.add(new DebugPasteCommand(this));
  768.  
  769. getCommand("bw").setExecutor(executor);
  770. }
  771.  
  772. public ArrayList<BaseCommand> getCommands()
  773. {
  774. return this.commands;
  775. }
  776.  
  777. private ArrayList<BaseCommand> filterCommandsByPermission(ArrayList<BaseCommand> commands, String permission)
  778. {
  779. Iterator<BaseCommand> it = commands.iterator();
  780. while (it.hasNext())
  781. {
  782. BaseCommand command = (BaseCommand)it.next();
  783. if (!command.getPermission().equals(permission)) {
  784. it.remove();
  785. }
  786. }
  787. return commands;
  788. }
  789.  
  790. public ArrayList<BaseCommand> getBaseCommands()
  791. {
  792. ArrayList<BaseCommand> commands = (ArrayList)this.commands.clone();
  793. commands = filterCommandsByPermission(commands, "base");
  794.  
  795. return commands;
  796. }
  797.  
  798. public ArrayList<BaseCommand> getSetupCommands()
  799. {
  800. ArrayList<BaseCommand> commands = (ArrayList)this.commands.clone();
  801. commands = filterCommandsByPermission(commands, "setup");
  802.  
  803. return commands;
  804. }
  805.  
  806. public ArrayList<BaseCommand> getCommandsByPermission(String permission)
  807. {
  808. ArrayList<BaseCommand> commands = (ArrayList)this.commands.clone();
  809. commands = filterCommandsByPermission(commands, permission);
  810.  
  811. return commands;
  812. }
  813.  
  814. public GameManager getGameManager()
  815. {
  816. return this.gameManager;
  817. }
  818.  
  819. private void startTimeListener()
  820. {
  821. this.timeTask = getServer().getScheduler().runTaskTimer(this, new Runnable()
  822. {
  823. public void run()
  824. {
  825. for (Game g : Main.getInstance().getGameManager().getGames()) {
  826. if (g.getState() == GameState.RUNNING) {
  827. g.getRegion().getWorld().setTime(g.getTime());
  828. }
  829. }
  830. }
  831. }, 100L, 100L);
  832. }
  833.  
  834. public static String _l(String localeKey, String singularValue, Map<String, String> params)
  835. {
  836. if ("1".equals(params.get(singularValue))) {
  837. return (String)getInstance().getLocalization().get(localeKey + "-one", params);
  838. }
  839. return (String)getInstance().getLocalization().get(localeKey, params);
  840. }
  841.  
  842. public static String _l(String localeKey, Map<String, String> params)
  843. {
  844. return (String)getInstance().getLocalization().get(localeKey, params);
  845. }
  846.  
  847. public static String _l(String localeKey)
  848. {
  849. return (String)getInstance().getLocalization().get(localeKey);
  850. }
  851.  
  852. private void stopTimeListener()
  853. {
  854. try
  855. {
  856. this.timeTask.cancel();
  857. }
  858. catch (Exception ex) {}
  859. try
  860. {
  861. this.updateChecker.cancel();
  862. }
  863. catch (Exception ex) {}
  864. }
  865.  
  866. public void reloadLocalization()
  867. {
  868. this.localization.loadLocale(getConfig().getString("locale"), false);
  869. }
  870.  
  871. public boolean spectationEnabled()
  872. {
  873. if ((getConfig().contains("spectation-enabled")) && (getConfig().isBoolean("spectation-enabled"))) {
  874. return getConfig().getBoolean("spectation-enabled");
  875. }
  876. return true;
  877. }
  878.  
  879. public boolean toMainLobby()
  880. {
  881. if (getConfig().contains("endgame.mainlobby-enabled")) {
  882. return getConfig().getBoolean("endgame.mainlobby-enabled");
  883. }
  884. return false;
  885. }
  886.  
  887. public int getMaxLength()
  888. {
  889. if ((getConfig().contains("gamelength")) && (getConfig().isInt("gamelength"))) {
  890. return getConfig().getInt("gamelength") * 60;
  891. }
  892. return 3600;
  893. }
  894.  
  895. public Integer getRespawnProtectionTime()
  896. {
  897. FileConfiguration config = getConfig();
  898. if ((config.contains("respawn-protection")) && (config.isInt("respawn-protection"))) {
  899. return Integer.valueOf(config.getInt("respawn-protection"));
  900. }
  901. return Integer.valueOf(0);
  902. }
  903.  
  904. public boolean isLocationSerializable()
  905. {
  906. if (locationSerializable == null) {
  907. try
  908. {
  909. Location.class.getMethod("serialize", new Class[0]);
  910. locationSerializable = Boolean.valueOf(true);
  911. }
  912. catch (Exception ex)
  913. {
  914. getInstance().getBugsnag().notify(ex);
  915. locationSerializable = Boolean.valueOf(false);
  916. }
  917. }
  918. return locationSerializable.booleanValue();
  919. }
  920.  
  921. public FileConfiguration getShopConfig()
  922. {
  923. return this.shopConfig;
  924. }
  925.  
  926. public boolean isHologramsEnabled()
  927. {
  928. return ((getServer().getPluginManager().isPluginEnabled("HologramAPI")) && (getServer().getPluginManager().isPluginEnabled("PacketListenerApi"))) || ((getServer().getPluginManager().isPluginEnabled("HolographicDisplays")) && (getServer().getPluginManager().isPluginEnabled("ProtocolLib")));
  929. }
  930.  
  931. public String getMissingHoloDependency()
  932. {
  933. if (!getInstance().isHologramsEnabled())
  934. {
  935. String missingHoloDependency = null;
  936. if ((getServer().getPluginManager().isPluginEnabled("HologramAPI")) || (getServer().getPluginManager().isPluginEnabled("HolographicDisplays")))
  937. {
  938. if (getServer().getPluginManager().isPluginEnabled("HologramAPI"))
  939. {
  940. missingHoloDependency = "PacketListenerApi";
  941. return missingHoloDependency;
  942. }
  943. if (getServer().getPluginManager().isPluginEnabled("HolographicDisplays"))
  944. {
  945. missingHoloDependency = "ProtocolLib";
  946. return missingHoloDependency;
  947. }
  948. }
  949. else
  950. {
  951. missingHoloDependency = "HolographicDisplays and ProtocolLib";
  952. return missingHoloDependency;
  953. }
  954. }
  955. return null;
  956. }
  957.  
  958. public IHologramInteraction getHolographicInteractor()
  959. {
  960. return this.holographicInteraction;
  961. }
  962. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement