Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package io.github.bedwarsrel.BedwarsRel;
- import com.bugsnag.Bugsnag;
- import com.bugsnag.Report;
- import com.bugsnag.callbacks.Callback;
- import com.google.common.collect.ImmutableMap;
- import io.github.bedwarsrel.BedwarsRel.Commands.AddGameCommand;
- import io.github.bedwarsrel.BedwarsRel.Commands.AddHoloCommand;
- import io.github.bedwarsrel.BedwarsRel.Commands.AddTeamCommand;
- import io.github.bedwarsrel.BedwarsRel.Commands.AddTeamJoinCommand;
- import io.github.bedwarsrel.BedwarsRel.Commands.BaseCommand;
- import io.github.bedwarsrel.BedwarsRel.Commands.ClearSpawnerCommand;
- import io.github.bedwarsrel.BedwarsRel.Commands.DebugPasteCommand;
- import io.github.bedwarsrel.BedwarsRel.Commands.GameTimeCommand;
- import io.github.bedwarsrel.BedwarsRel.Commands.HelpCommand;
- import io.github.bedwarsrel.BedwarsRel.Commands.JoinGameCommand;
- import io.github.bedwarsrel.BedwarsRel.Commands.KickCommand;
- import io.github.bedwarsrel.BedwarsRel.Commands.LeaveGameCommand;
- import io.github.bedwarsrel.BedwarsRel.Commands.ListGamesCommand;
- import io.github.bedwarsrel.BedwarsRel.Commands.RegionNameCommand;
- import io.github.bedwarsrel.BedwarsRel.Commands.ReloadCommand;
- import io.github.bedwarsrel.BedwarsRel.Commands.RemoveGameCommand;
- import io.github.bedwarsrel.BedwarsRel.Commands.RemoveHoloCommand;
- import io.github.bedwarsrel.BedwarsRel.Commands.RemoveTeamCommand;
- import io.github.bedwarsrel.BedwarsRel.Commands.SaveGameCommand;
- import io.github.bedwarsrel.BedwarsRel.Commands.SetAutobalanceCommand;
- import io.github.bedwarsrel.BedwarsRel.Commands.SetBedCommand;
- import io.github.bedwarsrel.BedwarsRel.Commands.SetBuilderCommand;
- import io.github.bedwarsrel.BedwarsRel.Commands.SetGameBlockCommand;
- import io.github.bedwarsrel.BedwarsRel.Commands.SetLobbyCommand;
- import io.github.bedwarsrel.BedwarsRel.Commands.SetMainLobbyCommand;
- import io.github.bedwarsrel.BedwarsRel.Commands.SetMinPlayersCommand;
- import io.github.bedwarsrel.BedwarsRel.Commands.SetRegionCommand;
- import io.github.bedwarsrel.BedwarsRel.Commands.SetSpawnCommand;
- import io.github.bedwarsrel.BedwarsRel.Commands.SetSpawnerCommand;
- import io.github.bedwarsrel.BedwarsRel.Commands.SetTargetCommand;
- import io.github.bedwarsrel.BedwarsRel.Commands.StartGameCommand;
- import io.github.bedwarsrel.BedwarsRel.Commands.StatsCommand;
- import io.github.bedwarsrel.BedwarsRel.Commands.StopGameCommand;
- import io.github.bedwarsrel.BedwarsRel.Database.DatabaseManager;
- import io.github.bedwarsrel.BedwarsRel.Game.Game;
- import io.github.bedwarsrel.BedwarsRel.Game.GameManager;
- import io.github.bedwarsrel.BedwarsRel.Game.GameState;
- import io.github.bedwarsrel.BedwarsRel.Game.Region;
- import io.github.bedwarsrel.BedwarsRel.Game.RessourceSpawner;
- import io.github.bedwarsrel.BedwarsRel.Game.Team;
- import io.github.bedwarsrel.BedwarsRel.Listener.BlockListener;
- import io.github.bedwarsrel.BedwarsRel.Listener.ChunkListener;
- import io.github.bedwarsrel.BedwarsRel.Listener.EntityListener;
- import io.github.bedwarsrel.BedwarsRel.Listener.HangingListener;
- import io.github.bedwarsrel.BedwarsRel.Listener.Player19Listener;
- import io.github.bedwarsrel.BedwarsRel.Listener.PlayerListener;
- import io.github.bedwarsrel.BedwarsRel.Listener.PlayerSpigotListener;
- import io.github.bedwarsrel.BedwarsRel.Listener.ServerListener;
- import io.github.bedwarsrel.BedwarsRel.Listener.SignListener;
- import io.github.bedwarsrel.BedwarsRel.Listener.WeatherListener;
- import io.github.bedwarsrel.BedwarsRel.Localization.LocalizationConfig;
- import io.github.bedwarsrel.BedwarsRel.Shop.Specials.SpecialItem;
- import io.github.bedwarsrel.BedwarsRel.Statistics.PlayerStatisticManager;
- import io.github.bedwarsrel.BedwarsRel.Statistics.StorageType;
- import io.github.bedwarsrel.BedwarsRel.Updater.ConfigUpdater;
- import io.github.bedwarsrel.BedwarsRel.Updater.DatabaseUpdater;
- import io.github.bedwarsrel.BedwarsRel.Updater.PluginUpdater;
- import io.github.bedwarsrel.BedwarsRel.Updater.PluginUpdater.UpdateCallback;
- import io.github.bedwarsrel.BedwarsRel.Updater.PluginUpdater.UpdateResult;
- import io.github.bedwarsrel.BedwarsRel.Updater.PluginUpdater.UpdateType;
- import io.github.bedwarsrel.BedwarsRel.Utils.BedwarsCommandExecutor;
- import io.github.bedwarsrel.BedwarsRel.Utils.ChatWriter;
- import io.github.bedwarsrel.BedwarsRel.Utils.SupportData;
- import io.github.bedwarsrel.BedwarsRel.Utils.Utils;
- import java.io.BufferedReader;
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.FileOutputStream;
- import java.io.InputStreamReader;
- import java.io.OutputStreamWriter;
- import java.util.ArrayList;
- import java.util.Iterator;
- import java.util.List;
- import java.util.Map;
- import java.util.Map.Entry;
- import org.bukkit.Bukkit;
- import org.bukkit.ChatColor;
- import org.bukkit.Location;
- import org.bukkit.Material;
- import org.bukkit.Server;
- import org.bukkit.World;
- import org.bukkit.command.ConsoleCommandSender;
- import org.bukkit.command.PluginCommand;
- import org.bukkit.configuration.file.FileConfiguration;
- import org.bukkit.configuration.file.FileConfigurationOptions;
- import org.bukkit.configuration.file.YamlConfiguration;
- import org.bukkit.configuration.serialization.ConfigurationSerialization;
- import org.bukkit.plugin.PluginDescriptionFile;
- import org.bukkit.plugin.PluginManager;
- import org.bukkit.plugin.java.JavaPlugin;
- import org.bukkit.plugin.messaging.Messenger;
- import org.bukkit.scheduler.BukkitRunnable;
- import org.bukkit.scheduler.BukkitScheduler;
- import org.bukkit.scheduler.BukkitTask;
- import org.bukkit.scoreboard.ScoreboardManager;
- import org.mcstats.Metrics;
- public class Main
- extends JavaPlugin
- {
- private static Main instance = null;
- public static int PROJECT_ID = 91743;
- private ArrayList<BaseCommand> commands = new ArrayList();
- private BukkitTask timeTask = null;
- private Package craftbukkit = null;
- private Package minecraft = null;
- private String version = null;
- private LocalizationConfig localization = null;
- private DatabaseManager dbManager = null;
- private BukkitTask updateChecker = null;
- private List<Material> breakableTypes = null;
- private YamlConfiguration shopConfig = null;
- private IHologramInteraction holographicInteraction = null;
- private boolean isSpigot = false;
- private static Boolean locationSerializable = null;
- private PlayerStatisticManager playerStatisticManager = null;
- private ScoreboardManager scoreboardManager = null;
- private GameManager gameManager = null;
- private Bugsnag bugsnag;
- public Bugsnag getBugsnag()
- {
- return this.bugsnag;
- }
- public void onEnable()
- {
- instance = this;
- registerBugsnag();
- registerConfigurationClasses();
- saveDefaultConfig();
- loadConfigInUTF();
- getConfig().options().copyDefaults(true);
- getConfig().options().copyHeader(true);
- this.craftbukkit = getCraftBukkit();
- this.minecraft = getMinecraftPackage();
- this.version = loadVersion();
- ConfigUpdater configUpdater = new ConfigUpdater();
- configUpdater.addConfigs();
- saveConfiguration();
- loadConfigInUTF();
- if (getBooleanConfig("send-error-data", true)) {
- enableBugsnag();
- } else {
- disableBugsnag();
- }
- configUpdater.updateShop();
- loadShop();
- this.isSpigot = getIsSpigot();
- loadDatabase();
- registerCommands();
- registerListener();
- this.gameManager = new GameManager();
- if (getInstance().isBungee()) {
- getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
- }
- loadStatistics();
- this.localization = loadLocalization();
- checkUpdates();
- this.scoreboardManager = Bukkit.getScoreboardManager();
- this.gameManager.loadGames();
- startTimeListener();
- startMetricsIfEnabled();
- if (isHologramsEnabled())
- {
- if (getServer().getPluginManager().isPluginEnabled("HologramAPI")) {
- this.holographicInteraction = new HologramAPIInteraction();
- } else if (getServer().getPluginManager().isPluginEnabled("HolographicDisplays")) {
- this.holographicInteraction = new HolographicDisplaysInteraction();
- }
- this.holographicInteraction.loadHolograms();
- }
- }
- private void registerBugsnag()
- {
- this.bugsnag = new Bugsnag("c23593c1e2f40fc0da36564af1bd00c6");
- this.bugsnag.setAppVersion(SupportData.getPluginVersion());
- this.bugsnag.setProjectPackages(new String[] { "io.github.bedwarsrel" });
- this.bugsnag.setReleaseStage(SupportData.getPluginVersionType());
- }
- private void enableBugsnag()
- {
- this.bugsnag.addCallback(new Callback()
- {
- public void beforeNotify(Report report)
- {
- Boolean shouldBeSent = Boolean.valueOf(false);
- for (StackTraceElement stackTraceElement : report.getException().getStackTrace()) {
- if (stackTraceElement.toString().contains("io.github.bedwarsrel.BedwarsRel"))
- {
- shouldBeSent = Boolean.valueOf(true);
- break;
- }
- }
- if (!shouldBeSent.booleanValue()) {
- report.cancel();
- }
- report.setUserId(SupportData.getIdentifier());
- if (!SupportData.getPluginVersionBuild().equalsIgnoreCase("unknown")) {
- report.addToTab("Server", "Version Build", Main.getInstance().getDescription().getVersion() + " " + SupportData.getPluginVersionBuild());
- }
- report.addToTab("Server", "Version", SupportData.getServerVersion());
- report.addToTab("Server", "Version Bukkit", SupportData.getBukkitVersion());
- report.addToTab("Server", "Server Mode", SupportData.getServerMode());
- report.addToTab("Server", "Plugins", SupportData.getPlugins());
- }
- });
- }
- private void disableBugsnag()
- {
- this.bugsnag.addCallback(new Callback()
- {
- public void beforeNotify(Report report)
- {
- report.cancel();
- }
- });
- }
- public void onDisable()
- {
- stopTimeListener();
- this.gameManager.unloadGames();
- cleanDatabase();
- if ((isHologramsEnabled()) && (this.holographicInteraction != null)) {
- this.holographicInteraction.unloadHolograms();
- }
- }
- public void loadConfigInUTF()
- {
- File configFile = new File(getDataFolder(), "config.yml");
- if (!configFile.exists()) {
- return;
- }
- try
- {
- BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(configFile), "UTF-8"));
- getConfig().load(reader);
- }
- catch (Exception e)
- {
- getInstance().getBugsnag().notify(e);
- e.printStackTrace();
- }
- if (getConfig() == null) {
- return;
- }
- this.breakableTypes = new ArrayList();
- for (String material : getConfig().getStringList("breakable-blocks.list")) {
- if (!material.equalsIgnoreCase("none"))
- {
- Material mat = Utils.parseMaterial(material);
- if ((mat != null) &&
- (!this.breakableTypes.contains(mat))) {
- this.breakableTypes.add(mat);
- }
- }
- }
- }
- public void loadShop()
- {
- File file = new File(getInstance().getDataFolder(), "shop.yml");
- if (!file.exists())
- {
- saveResource("shop.yml", false);
- try
- {
- Thread.sleep(100L);
- }
- catch (InterruptedException e)
- {
- getInstance().getBugsnag().notify(e);
- e.printStackTrace();
- }
- }
- this.shopConfig = new YamlConfiguration();
- try
- {
- BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));
- this.shopConfig.load(reader);
- }
- catch (Exception e)
- {
- getInstance().getBugsnag().notify(e);
- getServer().getConsoleSender().sendMessage(ChatWriter.pluginMessage(ChatColor.RED + "Couldn't load shop! Error in parsing shop!"));
- e.printStackTrace();
- }
- }
- public void dispatchRewardCommands(List<String> commands, Map<String, String> replacements)
- {
- for (String command : commands)
- {
- command = command.trim();
- if (!"".equals(command))
- {
- if ("none".equalsIgnoreCase(command)) {
- break;
- }
- if (command.startsWith("/")) {
- command = command.substring(1);
- }
- for (Map.Entry<String, String> entry : replacements.entrySet()) {
- command = command.replace((CharSequence)entry.getKey(), (CharSequence)entry.getValue());
- }
- getInstance().getServer().dispatchCommand(getInstance().getServer().getConsoleSender(), command);
- }
- }
- }
- public void saveConfiguration()
- {
- File file = new File(getInstance().getDataFolder(), "config.yml");
- try
- {
- file.mkdirs();
- String data = getYamlDump((YamlConfiguration)getConfig());
- FileOutputStream stream = new FileOutputStream(file);
- OutputStreamWriter writer = new OutputStreamWriter(stream, "UTF-8");
- try
- {
- writer.write(data);
- }
- finally
- {
- writer.close();
- stream.close();
- }
- }
- catch (Exception ex)
- {
- getInstance().getBugsnag().notify(ex);
- ex.printStackTrace();
- }
- }
- public Class<?> getVersionRelatedClass(String className)
- {
- try
- {
- return Class.forName("io.github.bedwarsrel.BedwarsRel.Com." + getCurrentVersion() + "." + className);
- }
- catch (Exception ex)
- {
- getInstance().getBugsnag().notify(ex);
- getServer().getConsoleSender().sendMessage(ChatWriter.pluginMessage(ChatColor.RED + "Couldn't find version related class io.github.bedwarsrel.BedwarsRel.Com." + getCurrentVersion() + "." + className));
- }
- return null;
- }
- public String getYamlDump(YamlConfiguration config)
- {
- try
- {
- String fullstring = config.saveToString();
- String endstring = fullstring;
- return Utils.unescape_perl_string(fullstring);
- }
- catch (Exception ex)
- {
- getInstance().getBugsnag().notify(ex);
- ex.printStackTrace();
- }
- return null;
- }
- public boolean isBreakableType(Material type)
- {
- 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)));
- }
- public boolean isMineshafterPresent()
- {
- try
- {
- Class.forName("mineshafter.MineServer");
- return true;
- }
- catch (Exception e) {}
- return false;
- }
- public PlayerStatisticManager getPlayerStatisticManager()
- {
- return this.playerStatisticManager;
- }
- private void checkUpdates()
- {
- try
- {
- if (getBooleanConfig("check-updates", true)) {
- this.updateChecker = new BukkitRunnable()
- {
- public void run()
- {
- final BukkitRunnable task = this;
- PluginUpdater.UpdateCallback callback = new PluginUpdater.UpdateCallback()
- {
- public void onFinish(PluginUpdater updater)
- {
- if (updater.getResult() == PluginUpdater.UpdateResult.SUCCESS) {
- task.cancel();
- }
- }
- };
- new PluginUpdater(Main.getInstance(), Main.PROJECT_ID, Main.getInstance().getFile(), PluginUpdater.UpdateType.DEFAULT, callback, Main.getInstance().getBooleanConfig("update-infos", true));
- }
- }.runTaskTimerAsynchronously(getInstance(), 40L, 36000L);
- }
- }
- catch (Exception ex)
- {
- getInstance().getBugsnag().notify(ex);
- getServer().getConsoleSender().sendMessage(ChatWriter.pluginMessage(ChatColor.RED + "Check for updates not successful: Error!"));
- }
- }
- private LocalizationConfig loadLocalization()
- {
- LocalizationConfig config = new LocalizationConfig();
- config.loadLocale(getConfig().getString("locale"), false);
- return config;
- }
- private void loadStatistics()
- {
- this.playerStatisticManager = new PlayerStatisticManager();
- this.playerStatisticManager.initialize();
- }
- private void loadDatabase()
- {
- if ((!getBooleanConfig("statistics.enabled", false)) || (!"database".equals(getStringConfig("statistics.storage", "yaml")))) {
- return;
- }
- getServer().getConsoleSender().sendMessage(ChatWriter.pluginMessage(ChatColor.GREEN + "Initialize database ..."));
- String host = getStringConfig("database.host", null);
- int port = getIntConfig("database.port", 3306);
- String user = getStringConfig("database.user", null);
- String password = getStringConfig("database.password", null);
- String db = getStringConfig("database.db", null);
- if ((host == null) || (user == null) || (password == null) || (db == null)) {
- return;
- }
- this.dbManager = new DatabaseManager(host, port, user, password, db);
- this.dbManager.initialize();
- getServer().getConsoleSender().sendMessage(ChatWriter.pluginMessage(ChatColor.GREEN + "Update database ..."));
- new DatabaseUpdater().execute();
- getServer().getConsoleSender().sendMessage(ChatWriter.pluginMessage(ChatColor.GREEN + "Done."));
- }
- public StorageType getStatisticStorageType()
- {
- String storage = getStringConfig("statistics.storage", "yaml");
- return StorageType.getByName(storage);
- }
- public boolean statisticsEnabled()
- {
- return getBooleanConfig("statistics.enabled", false);
- }
- private void cleanDatabase()
- {
- if (this.dbManager != null) {
- this.dbManager.cleanUp();
- }
- }
- public DatabaseManager getDatabaseManager()
- {
- return this.dbManager;
- }
- public boolean isSpigot()
- {
- return this.isSpigot;
- }
- private boolean getIsSpigot()
- {
- try
- {
- Package spigotPackage = Package.getPackage("org.spigotmc");
- return spigotPackage != null;
- }
- catch (Exception e)
- {
- getInstance().getBugsnag().notify(e);
- }
- return false;
- }
- public int getIntConfig(String key, int defaultInt)
- {
- FileConfiguration config = getConfig();
- if ((config.contains(key)) && (config.isInt(key))) {
- return config.getInt(key);
- }
- return defaultInt;
- }
- public String getStringConfig(String key, String defaultString)
- {
- FileConfiguration config = getConfig();
- if ((config.contains(key)) && (config.isString(key))) {
- return config.getString(key);
- }
- return defaultString;
- }
- public boolean getBooleanConfig(String key, boolean defaultBool)
- {
- FileConfiguration config = getConfig();
- if ((config.contains(key)) && (config.isBoolean(key))) {
- return config.getBoolean(key);
- }
- return defaultBool;
- }
- public LocalizationConfig getLocalization()
- {
- return this.localization;
- }
- private String loadVersion()
- {
- String packName = Bukkit.getServer().getClass().getPackage().getName();
- return packName.substring(packName.lastIndexOf('.') + 1);
- }
- public String getCurrentVersion()
- {
- return this.version;
- }
- public boolean isBungee()
- {
- return getConfig().getBoolean("bungeecord.enabled");
- }
- public String getBungeeHub()
- {
- if (getConfig().contains("bungeecord.hubserver")) {
- return getConfig().getString("bungeecord.hubserver");
- }
- return null;
- }
- public Package getCraftBukkit()
- {
- try
- {
- if (this.craftbukkit == null) {
- return Package.getPackage("org.bukkit.craftbukkit." + Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3]);
- }
- return this.craftbukkit;
- }
- catch (Exception ex)
- {
- getInstance().getBugsnag().notify(ex);
- getServer().getConsoleSender().sendMessage(ChatWriter.pluginMessage(ChatColor.RED + _l("errors.packagenotfound", ImmutableMap.of("package", "craftbukkit"))));
- }
- return null;
- }
- public Package getMinecraftPackage()
- {
- try
- {
- if (this.minecraft == null) {
- return Package.getPackage("net.minecraft.server." + Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3]);
- }
- return this.minecraft;
- }
- catch (Exception ex)
- {
- getInstance().getBugsnag().notify(ex);
- getServer().getConsoleSender().sendMessage(ChatWriter.pluginMessage(ChatColor.RED + _l("errors.packagenotfound", ImmutableMap.of("package", "minecraft server"))));
- }
- return null;
- }
- public Class getCraftBukkitClass(String classname)
- {
- try
- {
- if (this.craftbukkit == null) {
- this.craftbukkit = getCraftBukkit();
- }
- return Class.forName(this.craftbukkit.getName() + "." + classname);
- }
- catch (Exception ex)
- {
- getInstance().getBugsnag().notify(ex);
- getServer().getConsoleSender().sendMessage(ChatWriter.pluginMessage(ChatColor.RED + _l("errors.classnotfound", ImmutableMap.of("package", "craftbukkit", "class", classname))));
- }
- return null;
- }
- public Class getMinecraftServerClass(String classname)
- {
- try
- {
- if (this.minecraft == null) {
- this.minecraft = getMinecraftPackage();
- }
- return Class.forName(this.minecraft.getName() + "." + classname);
- }
- catch (Exception ex)
- {
- getInstance().getBugsnag().notify(ex);
- getServer().getConsoleSender().sendMessage(ChatWriter.pluginMessage(ChatColor.RED + _l("errors.classnotfound", ImmutableMap.of("package", "minecraft server", "class", classname))));
- }
- return null;
- }
- public boolean metricsEnabled()
- {
- if ((getConfig().contains("plugin-metrics")) && (getConfig().isBoolean("plugin-metrics"))) {
- return getConfig().getBoolean("plugin-metrics");
- }
- return false;
- }
- public void startMetricsIfEnabled()
- {
- if (metricsEnabled()) {
- try
- {
- Metrics metrics = new Metrics(this);
- metrics.start();
- }
- catch (Exception ex)
- {
- getInstance().getBugsnag().notify(ex);
- getServer().getConsoleSender().sendMessage(ChatWriter.pluginMessage(ChatColor.RED + "Metrics are enabled, but couldn't send data!"));
- }
- }
- }
- public String getFallbackLocale()
- {
- return "en_US";
- }
- public boolean allPlayersBackToMainLobby()
- {
- if ((getConfig().contains("endgame.all-players-to-mainlobby")) && (getConfig().isBoolean("endgame.all-players-to-mainlobby"))) {
- return getConfig().getBoolean("endgame.all-players-to-mainlobby");
- }
- return false;
- }
- public List<String> getAllowedCommands()
- {
- FileConfiguration config = getConfig();
- if ((config.contains("allowed-commands")) && (config.isList("allowed-commands"))) {
- return config.getStringList("allowed-commands");
- }
- return new ArrayList();
- }
- public static Main getInstance()
- {
- return instance;
- }
- public ScoreboardManager getScoreboardManager()
- {
- return this.scoreboardManager;
- }
- private void registerListener()
- {
- new WeatherListener();
- new BlockListener();
- new PlayerListener();
- if ((getInstance().getCurrentVersion().startsWith("v1_9")) || (getInstance().getCurrentVersion().startsWith("v1_10")) || (getInstance().getCurrentVersion().startsWith("v1_11"))) {
- new Player19Listener();
- }
- new HangingListener();
- new EntityListener();
- new ServerListener();
- new SignListener();
- new ChunkListener();
- if (isSpigot()) {
- new PlayerSpigotListener();
- }
- SpecialItem.loadSpecials();
- }
- private void registerConfigurationClasses()
- {
- ConfigurationSerialization.registerClass(RessourceSpawner.class, "RessourceSpawner");
- ConfigurationSerialization.registerClass(Team.class, "Team");
- }
- private void registerCommands()
- {
- BedwarsCommandExecutor executor = new BedwarsCommandExecutor(this);
- this.commands.add(new HelpCommand(this));
- this.commands.add(new SetSpawnerCommand(this));
- this.commands.add(new AddGameCommand(this));
- this.commands.add(new StartGameCommand(this));
- this.commands.add(new StopGameCommand(this));
- this.commands.add(new SetRegionCommand(this));
- this.commands.add(new AddTeamCommand(this));
- this.commands.add(new SaveGameCommand(this));
- this.commands.add(new JoinGameCommand(this));
- this.commands.add(new SetSpawnCommand(this));
- this.commands.add(new SetLobbyCommand(this));
- this.commands.add(new LeaveGameCommand(this));
- this.commands.add(new SetTargetCommand(this));
- this.commands.add(new SetBedCommand(this));
- this.commands.add(new ReloadCommand(this));
- this.commands.add(new SetMainLobbyCommand(this));
- this.commands.add(new ListGamesCommand(this));
- this.commands.add(new RegionNameCommand(this));
- this.commands.add(new RemoveTeamCommand(this));
- this.commands.add(new RemoveGameCommand(this));
- this.commands.add(new ClearSpawnerCommand(this));
- this.commands.add(new GameTimeCommand(this));
- this.commands.add(new StatsCommand(this));
- this.commands.add(new SetMinPlayersCommand(this));
- this.commands.add(new SetGameBlockCommand(this));
- this.commands.add(new SetBuilderCommand(this));
- this.commands.add(new SetAutobalanceCommand(this));
- this.commands.add(new KickCommand(this));
- this.commands.add(new AddTeamJoinCommand(this));
- this.commands.add(new AddHoloCommand(this));
- this.commands.add(new RemoveHoloCommand(this));
- this.commands.add(new DebugPasteCommand(this));
- getCommand("bw").setExecutor(executor);
- }
- public ArrayList<BaseCommand> getCommands()
- {
- return this.commands;
- }
- private ArrayList<BaseCommand> filterCommandsByPermission(ArrayList<BaseCommand> commands, String permission)
- {
- Iterator<BaseCommand> it = commands.iterator();
- while (it.hasNext())
- {
- BaseCommand command = (BaseCommand)it.next();
- if (!command.getPermission().equals(permission)) {
- it.remove();
- }
- }
- return commands;
- }
- public ArrayList<BaseCommand> getBaseCommands()
- {
- ArrayList<BaseCommand> commands = (ArrayList)this.commands.clone();
- commands = filterCommandsByPermission(commands, "base");
- return commands;
- }
- public ArrayList<BaseCommand> getSetupCommands()
- {
- ArrayList<BaseCommand> commands = (ArrayList)this.commands.clone();
- commands = filterCommandsByPermission(commands, "setup");
- return commands;
- }
- public ArrayList<BaseCommand> getCommandsByPermission(String permission)
- {
- ArrayList<BaseCommand> commands = (ArrayList)this.commands.clone();
- commands = filterCommandsByPermission(commands, permission);
- return commands;
- }
- public GameManager getGameManager()
- {
- return this.gameManager;
- }
- private void startTimeListener()
- {
- this.timeTask = getServer().getScheduler().runTaskTimer(this, new Runnable()
- {
- public void run()
- {
- for (Game g : Main.getInstance().getGameManager().getGames()) {
- if (g.getState() == GameState.RUNNING) {
- g.getRegion().getWorld().setTime(g.getTime());
- }
- }
- }
- }, 100L, 100L);
- }
- public static String _l(String localeKey, String singularValue, Map<String, String> params)
- {
- if ("1".equals(params.get(singularValue))) {
- return (String)getInstance().getLocalization().get(localeKey + "-one", params);
- }
- return (String)getInstance().getLocalization().get(localeKey, params);
- }
- public static String _l(String localeKey, Map<String, String> params)
- {
- return (String)getInstance().getLocalization().get(localeKey, params);
- }
- public static String _l(String localeKey)
- {
- return (String)getInstance().getLocalization().get(localeKey);
- }
- private void stopTimeListener()
- {
- try
- {
- this.timeTask.cancel();
- }
- catch (Exception ex) {}
- try
- {
- this.updateChecker.cancel();
- }
- catch (Exception ex) {}
- }
- public void reloadLocalization()
- {
- this.localization.loadLocale(getConfig().getString("locale"), false);
- }
- public boolean spectationEnabled()
- {
- if ((getConfig().contains("spectation-enabled")) && (getConfig().isBoolean("spectation-enabled"))) {
- return getConfig().getBoolean("spectation-enabled");
- }
- return true;
- }
- public boolean toMainLobby()
- {
- if (getConfig().contains("endgame.mainlobby-enabled")) {
- return getConfig().getBoolean("endgame.mainlobby-enabled");
- }
- return false;
- }
- public int getMaxLength()
- {
- if ((getConfig().contains("gamelength")) && (getConfig().isInt("gamelength"))) {
- return getConfig().getInt("gamelength") * 60;
- }
- return 3600;
- }
- public Integer getRespawnProtectionTime()
- {
- FileConfiguration config = getConfig();
- if ((config.contains("respawn-protection")) && (config.isInt("respawn-protection"))) {
- return Integer.valueOf(config.getInt("respawn-protection"));
- }
- return Integer.valueOf(0);
- }
- public boolean isLocationSerializable()
- {
- if (locationSerializable == null) {
- try
- {
- Location.class.getMethod("serialize", new Class[0]);
- locationSerializable = Boolean.valueOf(true);
- }
- catch (Exception ex)
- {
- getInstance().getBugsnag().notify(ex);
- locationSerializable = Boolean.valueOf(false);
- }
- }
- return locationSerializable.booleanValue();
- }
- public FileConfiguration getShopConfig()
- {
- return this.shopConfig;
- }
- public boolean isHologramsEnabled()
- {
- return ((getServer().getPluginManager().isPluginEnabled("HologramAPI")) && (getServer().getPluginManager().isPluginEnabled("PacketListenerApi"))) || ((getServer().getPluginManager().isPluginEnabled("HolographicDisplays")) && (getServer().getPluginManager().isPluginEnabled("ProtocolLib")));
- }
- public String getMissingHoloDependency()
- {
- if (!getInstance().isHologramsEnabled())
- {
- String missingHoloDependency = null;
- if ((getServer().getPluginManager().isPluginEnabled("HologramAPI")) || (getServer().getPluginManager().isPluginEnabled("HolographicDisplays")))
- {
- if (getServer().getPluginManager().isPluginEnabled("HologramAPI"))
- {
- missingHoloDependency = "PacketListenerApi";
- return missingHoloDependency;
- }
- if (getServer().getPluginManager().isPluginEnabled("HolographicDisplays"))
- {
- missingHoloDependency = "ProtocolLib";
- return missingHoloDependency;
- }
- }
- else
- {
- missingHoloDependency = "HolographicDisplays and ProtocolLib";
- return missingHoloDependency;
- }
- }
- return null;
- }
- public IHologramInteraction getHolographicInteractor()
- {
- return this.holographicInteraction;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement