use of br.net.fabiozumbi12.RedProtect.Sponge.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();
}
use of br.net.fabiozumbi12.RedProtect.Sponge.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();
}
use of br.net.fabiozumbi12.RedProtect.Sponge.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;
}
use of br.net.fabiozumbi12.RedProtect.Sponge.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.");
}
}
use of br.net.fabiozumbi12.RedProtect.Sponge.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();
}
}
}
Aggregations