Advertisement
Guest User

Untitled

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