Search in sources :

Example 6 with RegionManager

use of br.net.fabiozumbi12.RedProtect.Bukkit.region.RegionManager in project RedProtect by FabioZumbi12.

the class RedProtect method startLoad.

private void startLoad() throws Exception {
    redProtectUtil = new RedProtectUtil();
    config = new ConfigManager(this.factory);
    lang = new LangManager();
    if (RedProtect.get().getConfigManager().configRoot().purge.regen.enable_whitelist_regen && Sponge.getServer().hasWhitelist()) {
        Sponge.getServer().setHasWhitelist(false);
        RedProtect.get().logger.success("Whitelist disabled!");
    }
    logger.info("Registering commands...");
    commandHandler = new CommandHandler(this);
    logger.info("Registering listeners...");
    Sponge.getGame().getEventManager().registerListeners(container, commandHandler);
    Sponge.getGame().getEventManager().registerListeners(container, new BlockListener());
    Sponge.getGame().getEventManager().registerListeners(container, new GlobalListener());
    Sponge.getGame().getEventManager().registerListeners(container, new PlayerListener());
    Sponge.getGame().getEventManager().registerListeners(container, new EntityListener());
    Sponge.getGame().getEventManager().registerListeners(container, new WorldListener());
    // Register hooks
    this.hooks.registerHooksFirst();
    rm = new RegionManager();
    rm.loadAll();
    RedProtect.get().getUtil().ReadAllDB(rm.getAllRegions());
    rm.saveAll(false);
    if (!config.configRoot().file_type.equalsIgnoreCase("mysql")) {
        AutoSaveHandler();
    }
    logger.info("There are " + rm.getTotalRegionsNum() + " regions on (" + config.configRoot().file_type + ") database!");
    // Register hooks
    this.hooks.registerHooksLast();
    // Load Gui lang file
    guiLang = new LangGuiManager();
}
Also used : RedProtectUtil(br.net.fabiozumbi12.RedProtect.Sponge.helpers.RedProtectUtil) LangManager(br.net.fabiozumbi12.RedProtect.Sponge.config.LangManager) LangGuiManager(br.net.fabiozumbi12.RedProtect.Sponge.config.LangGuiManager) RegionManager(br.net.fabiozumbi12.RedProtect.Sponge.region.RegionManager) CommandHandler(br.net.fabiozumbi12.RedProtect.Sponge.commands.CommandHandler) ConfigManager(br.net.fabiozumbi12.RedProtect.Sponge.config.ConfigManager)

Example 7 with RegionManager

use of br.net.fabiozumbi12.RedProtect.Bukkit.region.RegionManager in project RedProtect by FabioZumbi12.

the class RedProtect method initVars.

private void initVars() throws Exception {
    container = Sponge.getPluginManager().getPlugin("redprotect").get();
    serv = Sponge.getServer();
    cmdService = game.getCommandManager();
    cfgs = new RPConfig();
    RPLang.init();
    WE = checkWE();
    ph = new RPPermHandler();
    rm = new RegionManager();
}
Also used : RPConfig(br.net.fabiozumbi12.RedProtect.Sponge.config.RPConfig)

Example 8 with RegionManager

use of br.net.fabiozumbi12.RedProtect.Bukkit.region.RegionManager in project RedProtect by FabioZumbi12.

the class RedProtectUtil method FilesToSingle.

public int FilesToSingle() {
    int saved = 0;
    for (World w : Sponge.getServer().getWorlds()) {
        File f = new File(RedProtect.get().configDir + File.separator + "data", "data_" + w.getName() + ".conf");
        Set<Region> regions = RedProtect.get().getRegionManager().getRegionsByWorld(w.getName());
        ConfigurationLoader<CommentedConfigurationNode> regionManager = HoconConfigurationLoader.builder().setPath(f.toPath()).build();
        CommentedConfigurationNode fileDB = regionManager.createEmptyNode();
        for (Region r : regions) {
            addProps(fileDB, r);
            saved++;
            File oldf = new File(RedProtect.get().configDir + File.separator + "data", w.getName() + File.separator + r.getName() + ".conf");
            if (oldf.exists()) {
                oldf.delete();
            }
        }
        File oldf = new File(RedProtect.get().configDir + File.separator + "data", w.getName());
        if (oldf.exists()) {
            oldf.delete();
        }
        saveConf(fileDB, regionManager);
    }
    if (RedProtect.get().getConfigManager().configRoot().flat_file.region_per_file) {
        RedProtect.get().getConfigManager().configRoot().flat_file.region_per_file = false;
    }
    RedProtect.get().getConfigManager().save();
    return saved;
}
Also used : CommentedConfigurationNode(ninja.leaping.configurate.commented.CommentedConfigurationNode) Region(br.net.fabiozumbi12.RedProtect.Sponge.Region) PlayerRegion(br.net.fabiozumbi12.RedProtect.Core.region.PlayerRegion) World(org.spongepowered.api.world.World) File(java.io.File)

Example 9 with RegionManager

use of br.net.fabiozumbi12.RedProtect.Bukkit.region.RegionManager 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)

Example 10 with RegionManager

use of br.net.fabiozumbi12.RedProtect.Bukkit.region.RegionManager in project RedProtect by FabioZumbi12.

the class WorldFlatFileRegionManager method load.

private void load(String path) {
    if (!RedProtect.get().getConfigManager().configRoot().file_type.equalsIgnoreCase("mysql")) {
        RedProtect.get().logger.debug(LogLevel.DEFAULT, "Load world " + this.world + ". File type: conf");
        try {
            File tempRegionFile = new File(path);
            if (!tempRegionFile.exists()) {
                tempRegionFile.createNewFile();
            }
            ConfigurationLoader<CommentedConfigurationNode> regionManager = HoconConfigurationLoader.builder().setPath(tempRegionFile.toPath()).build();
            CommentedConfigurationNode region = regionManager.load();
            for (Object key : region.getChildrenMap().keySet()) {
                String rname = key.toString();
                if (!region.getNode(rname).hasMapChildren()) {
                    continue;
                }
                Region newr = loadRegion(region, rname, Sponge.getServer().getWorld(world).get());
                newr.setToSave(false);
                regions.put(rname, newr);
            }
        } catch (IOException e) {
            CoreUtil.printJarVersion();
            e.printStackTrace();
        }
    }
}
Also used : CommentedConfigurationNode(ninja.leaping.configurate.commented.CommentedConfigurationNode) Region(br.net.fabiozumbi12.RedProtect.Sponge.Region) PlayerRegion(br.net.fabiozumbi12.RedProtect.Core.region.PlayerRegion) IOException(java.io.IOException) File(java.io.File)

Aggregations

PlayerRegion (br.net.fabiozumbi12.RedProtect.Core.region.PlayerRegion)6 Region (br.net.fabiozumbi12.RedProtect.Sponge.Region)5 File (java.io.File)5 CommentedConfigurationNode (ninja.leaping.configurate.commented.CommentedConfigurationNode)5 SpigetUpdater (br.net.fabiozumbi12.RedProtect.Bukkit.updater.SpigetUpdater)3 ObjectMappingException (ninja.leaping.configurate.objectmapping.ObjectMappingException)3 CommandHandler (br.net.fabiozumbi12.RedProtect.Bukkit.commands.CommandHandler)2 BlockConfig (br.net.fabiozumbi12.RedProtect.Bukkit.config.BlockConfig)2 ConfigManager (br.net.fabiozumbi12.RedProtect.Bukkit.config.ConfigManager)2 LangGuiManager (br.net.fabiozumbi12.RedProtect.Bukkit.config.LangGuiManager)2 LangManager (br.net.fabiozumbi12.RedProtect.Bukkit.config.LangManager)2 RedProtectUtil (br.net.fabiozumbi12.RedProtect.Bukkit.helpers.RedProtectUtil)2 Metrics (br.net.fabiozumbi12.RedProtect.Bukkit.metrics.Metrics)2 RegionManager (br.net.fabiozumbi12.RedProtect.Bukkit.region.RegionManager)2 CoreUtil (br.net.fabiozumbi12.RedProtect.Core.helpers.CoreUtil)2 RegionManager (br.net.fabiozumbi12.RedProtect.Sponge.region.RegionManager)2 IOException (java.io.IOException)2 java.util (java.util)2 World (org.spongepowered.api.world.World)2 RedProtectAPI (br.net.fabiozumbi12.RedProtect.Bukkit.API.RedProtectAPI)1