Search in sources :

Example 1 with VersionHelper

use of br.net.fabiozumbi12.RedProtect.Bukkit.helpers.VersionHelper in project RedProtect by FabioZumbi12.

the class RedProtect method startLoad.

private void startLoad() throws Exception {
    redProtectUtil = new RedProtectUtil(this);
    config = new ConfigManager();
    lang = new LangManager();
    blockConfig = new BlockConfig();
    if (config.configRoot().purge.regen.enable_whitelist_regen && Bukkit.getServer().hasWhitelist()) {
        Bukkit.getServer().setWhitelist(false);
        RedProtect.get().logger.success("Whitelist disabled!");
    }
    logger.info("Registering commands...");
    cmdHandler = new CommandHandler(this);
    logger.info("Registering listeners...");
    getServer().getPluginManager().registerEvents(cmdHandler, this);
    getServer().getPluginManager().registerEvents(new GlobalListener(), this);
    getServer().getPluginManager().registerEvents(new BlockListener(), this);
    getServer().getPluginManager().registerEvents(new PlayerListener(), this);
    getServer().getPluginManager().registerEvents(new EntityListener(), this);
    getServer().getPluginManager().registerEvents(new WorldListener(), this);
    // Register hooks
    hooks.registerHooksFirst();
    rm = new RegionManager();
    rm.loadAll();
    redProtectUtil.ReadAllDB(rm.getAllRegions());
    rm.saveAll(false);
    if (!config.configRoot().file_type.equalsIgnoreCase("mysql")) {
        startAutoSave();
    }
    logger.info("There are " + rm.getTotalRegionsNum() + " regions on (" + config.configRoot().file_type + ") database!");
    // Register hooks
    hooks.registerHooksLast();
    // Load Gui lang file
    guiLang = new LangGuiManager();
    // Update Manager
    if (updater != null) {
        Bukkit.getScheduler().cancelTask(updater.getTaskId());
        updater = null;
    }
    if (config.configRoot().update.enable) {
        updater = new SpigetUpdater(this);
        updater.setCurrentJarFile(this.getFile().getName());
        updater.hourlyUpdateCheck(getServer().getConsoleSender(), config.configRoot().update.enable, false);
    }
    bukkitVersion = getBukkitVersion();
    logger.debug(LogLevel.DEFAULT, "Version String: " + bukkitVersion);
    if (bukkitVersion >= 180) {
        getServer().getPluginManager().registerEvents(new Compat18(), this);
    }
    if (bukkitVersion >= 190) {
        getServer().getPluginManager().registerEvents(new Compat19(), this);
    }
    if (bukkitVersion >= 1110) {
        getServer().getPluginManager().registerEvents(new Compat111(), this);
    }
    if (bukkitVersion >= 1140) {
        getServer().getPluginManager().registerEvents(new Compat114(), this);
    }
    if (bukkitVersion <= 189) {
        rpvHelper = (VersionHelper) Class.forName("br.net.fabiozumbi12.RedProtect.Bukkit.helpers.VersionHelper18").newInstance();
    }
    if (bukkitVersion >= 190) {
        rpvHelper = (VersionHelper) Class.forName("br.net.fabiozumbi12.RedProtect.Bukkit.helpers.VersionHelper112").newInstance();
    }
    if (bukkitVersion >= 1130) {
        rpvHelper = (VersionHelper) Class.forName("br.net.fabiozumbi12.RedProtect.Bukkit.helpers.VersionHelper113").newInstance();
    }
    if (bukkitVersion >= 1140) {
        rpvHelper = (VersionHelper) Class.forName("br.net.fabiozumbi12.RedProtect.Bukkit.helpers.VersionHelperLatest").newInstance();
    }
    // Register as listener
    getServer().getPluginManager().registerEvents(rpvHelper, this);
    // Print helper version
    logger.info("Helper version: " + rpvHelper.getVersion());
    // Load gui items for Minecraft version
    config.setGuiRoot(rpvHelper.setGuiItems(config.guiRoot()));
    // Load mob permissions
    modListener = new ModListener(this);
    // Metrics
    try {
        Metrics metrics = new Metrics(this);
        metrics.addCustomChart(new Metrics.SingleLineChart("server_regions", () -> rm.getAllRegions().size()));
        if (metrics.isEnabled())
            logger.info("Metrics enabled! See our stats here: https://bstats.org/plugin/bukkit/RedProtect");
    } catch (Exception ex) {
        logger.info("Metrics not enabled due errors: " + ex.getLocalizedMessage());
    }
}
Also used : LangManager(br.net.fabiozumbi12.RedProtect.Bukkit.config.LangManager) CommandHandler(br.net.fabiozumbi12.RedProtect.Bukkit.commands.CommandHandler) SpigetUpdater(br.net.fabiozumbi12.RedProtect.Bukkit.updater.SpigetUpdater) ConfigManager(br.net.fabiozumbi12.RedProtect.Bukkit.config.ConfigManager) ObjectMappingException(ninja.leaping.configurate.objectmapping.ObjectMappingException) RedProtectUtil(br.net.fabiozumbi12.RedProtect.Bukkit.helpers.RedProtectUtil) Metrics(br.net.fabiozumbi12.RedProtect.Bukkit.metrics.Metrics) LangGuiManager(br.net.fabiozumbi12.RedProtect.Bukkit.config.LangGuiManager) RegionManager(br.net.fabiozumbi12.RedProtect.Bukkit.region.RegionManager) BlockConfig(br.net.fabiozumbi12.RedProtect.Bukkit.config.BlockConfig)

Example 2 with VersionHelper

use of br.net.fabiozumbi12.RedProtect.Bukkit.helpers.VersionHelper in project RedProtect by FabioZumbi12.

the class RedProtect method onServerStart.

@Listener
public void onServerStart(GameStartedServerEvent event) {
    try {
        String v = Sponge.getGame().getPlatform().getContainer(Component.API).getVersion().orElse("0");
        instance = this;
        commandManager = Sponge.getGame().getCommandManager();
        ph = new PermissionHandler();
        rm = new RegionManager();
        // Init schematic
        schematic = new RPSchematics();
        // Init config, lang, listeners and flags
        startLoad();
        if (v.startsWith("7")) {
            rpvHelper = (VersionHelper) Class.forName("br.net.fabiozumbi12.RedProtect.Sponge.VersionHelper7").newInstance();
            Sponge.getGame().getEventManager().registerListeners(container, Class.forName("br.net.fabiozumbi12.RedProtect.Sponge.listeners.RPBlockListener7").newInstance());
        } else /*else if (v.startsWith("8")) {
                Sponge.getGame().getEventManager().registerListeners(container, Class.forName("br.net.fabiozumbi12.RedProtect.Sponge.listeners.RPBlockListener8").newInstance());
                rpvHelper = (VersionHelper) Class.forName("br.net.fabiozumbi12.RedProtect.Sponge.VersionHelper8").newInstance();
            }*/
        {
            Sponge.getGame().getEventManager().registerListeners(container, Class.forName("br.net.fabiozumbi12.RedProtect.Sponge.listeners.BlockListenerCompat56").newInstance());
            rpvHelper = (VersionHelper) Class.forName("br.net.fabiozumbi12.RedProtect.Sponge.helpers.VersionHelper56").newInstance();
        }
        logger.info("Loading API...");
        this.redProtectAPI = new RedProtectAPI();
        logger.info("API Loaded!");
        logger.info("Sponge version: " + v);
        logger.clear("\n" + "&4 _   _  _  &c _   _   _  _ _  _  _ _ _  __\n" + "&4|_| |_ | \\ &c|_| |_| | |  |  |_ |   |    / \n" + "&4| \\ |_ |_/ &c|   | \\ |_|  |  |_ |_  |   /\n" + "&a¯ Redprotect " + container.getVersion().get() + " enabled\n" + "");
    } catch (Exception e) {
        CoreUtil.printJarVersion();
        e.printStackTrace();
        Sponge.getGame().getServer().setHasWhitelist(true);
        Sponge.getGame().getServer().getOnlinePlayers().forEach(Player::kick);
        logger.severe("Error enabling RedProtect, plugin will shut down.");
        logger.severe("Due to an error in RedProtect loading, the whitelist has been turned on and every player has been kicked.");
        logger.severe("DO NOT LET ANYONE ENTER before fixing the problem, otherwise you risk losing protected regions.");
    }
}
Also used : RedProtectAPI(br.net.fabiozumbi12.RedProtect.Sponge.API.RedProtectAPI) PermissionHandler(br.net.fabiozumbi12.RedProtect.Sponge.helpers.PermissionHandler) RPSchematics(br.net.fabiozumbi12.RedProtect.Sponge.schematics.RPSchematics) RegionManager(br.net.fabiozumbi12.RedProtect.Sponge.region.RegionManager) ObjectMappingException(ninja.leaping.configurate.objectmapping.ObjectMappingException) Listener(org.spongepowered.api.event.Listener)

Aggregations

ObjectMappingException (ninja.leaping.configurate.objectmapping.ObjectMappingException)2 CommandHandler (br.net.fabiozumbi12.RedProtect.Bukkit.commands.CommandHandler)1 BlockConfig (br.net.fabiozumbi12.RedProtect.Bukkit.config.BlockConfig)1 ConfigManager (br.net.fabiozumbi12.RedProtect.Bukkit.config.ConfigManager)1 LangGuiManager (br.net.fabiozumbi12.RedProtect.Bukkit.config.LangGuiManager)1 LangManager (br.net.fabiozumbi12.RedProtect.Bukkit.config.LangManager)1 RedProtectUtil (br.net.fabiozumbi12.RedProtect.Bukkit.helpers.RedProtectUtil)1 Metrics (br.net.fabiozumbi12.RedProtect.Bukkit.metrics.Metrics)1 RegionManager (br.net.fabiozumbi12.RedProtect.Bukkit.region.RegionManager)1 SpigetUpdater (br.net.fabiozumbi12.RedProtect.Bukkit.updater.SpigetUpdater)1 RedProtectAPI (br.net.fabiozumbi12.RedProtect.Sponge.API.RedProtectAPI)1 PermissionHandler (br.net.fabiozumbi12.RedProtect.Sponge.helpers.PermissionHandler)1 RegionManager (br.net.fabiozumbi12.RedProtect.Sponge.region.RegionManager)1 RPSchematics (br.net.fabiozumbi12.RedProtect.Sponge.schematics.RPSchematics)1 Listener (org.spongepowered.api.event.Listener)1