Search in sources :

Example 1 with WorldGuardHelper

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

the class CommandHandler method handleWGRegions.

private static boolean handleWGRegions() {
    if (!RedProtect.get().hooks.checkWG()) {
        return false;
    }
    WorldGuardHelper helper = RedProtect.get().hooks.worldGuardHelper;
    List<RegionManager> loaded = helper.getLoaded();
    if (loaded.isEmpty())
        return false;
    int i = 0;
    for (RegionManager rm : loaded) {
        if (rm.getRegions().isEmpty())
            continue;
        String w = rm.getName();
        for (Map.Entry<String, ProtectedRegion> pr : rm.getRegions().entrySet()) {
            if (!pr.getValue().getType().equals(RegionType.CUBOID))
                continue;
            if (RedProtect.get().getRegionManager().getRegion(pr.getKey(), w) != null)
                continue;
            Set<PlayerRegion> leaders;
            Set<PlayerRegion> members;
            if (!pr.getValue().getOwners().getUniqueIds().isEmpty())
                leaders = pr.getValue().getOwners().getUniqueIds().stream().filter(p -> Bukkit.getPlayer(p) != null).map(o -> new PlayerRegion(o.toString(), Bukkit.getPlayer(o).getName())).collect(Collectors.toSet());
            else
                leaders = pr.getValue().getOwners().getPlayers().stream().map(o -> new PlayerRegion(o, o)).collect(Collectors.toSet());
            if (!pr.getValue().getMembers().getUniqueIds().isEmpty())
                members = pr.getValue().getMembers().getUniqueIds().stream().filter(p -> Bukkit.getPlayer(p) != null).map(o -> new PlayerRegion(o.toString(), Bukkit.getPlayer(o).getName())).collect(Collectors.toSet());
            else
                members = pr.getValue().getMembers().getPlayers().stream().map(o -> new PlayerRegion(o, o)).collect(Collectors.toSet());
            if (leaders.isEmpty()) {
                if (members.isEmpty())
                    leaders.add(new PlayerRegion(RedProtect.get().getConfigManager().configRoot().region_settings.default_leader, RedProtect.get().getConfigManager().configRoot().region_settings.default_leader));
                else
                    leaders.addAll(members);
            }
            Location min = helper.getMinimumPoint(pr.getValue(), Bukkit.getWorld(w));
            Location max = helper.getMaximumPoint(pr.getValue(), Bukkit.getWorld(w));
            Region r = new Region(pr.getKey(), new HashSet<>(), members, leaders, min, max, RedProtect.get().getConfigManager().getDefFlagsValues(), "", pr.getValue().getPriority(), w, RedProtect.get().getUtil().dateNow(), 0, null, true, true);
            for (Map.Entry<Flag<?>, Object> flag : pr.getValue().getFlags().entrySet()) {
                if (r.flagExists(flag.getKey().getName()) && RedProtect.get().getUtil().parseObject(flag.getValue().toString()) != null) {
                    r.setFlag(Bukkit.getConsoleSender(), flag.getKey().getName(), RedProtect.get().getUtil().parseObject(flag.getValue().toString()));
                }
            }
            RedProtect.get().getRegionManager().add(r, w);
            RedProtect.get().logger.warning("Region converted and named to " + r.getName());
            i++;
        }
        RedProtect.get().logger.success(i + " WorldGuard regions imported for world " + w);
    }
    return i > 0;
}
Also used : PlayerRegion(br.net.fabiozumbi12.RedProtect.Core.region.PlayerRegion) PlayerRegion(br.net.fabiozumbi12.RedProtect.Core.region.PlayerRegion) java.util(java.util) ProtectedRegion(com.sk89q.worldguard.protection.regions.ProtectedRegion) Array(java.lang.reflect.Array) CommandHandlers(br.net.fabiozumbi12.RedProtect.Bukkit.commands.CommandHandlers) TabCompleter(org.bukkit.command.TabCompleter) WorldGuardHelper(br.net.fabiozumbi12.RedProtect.Bukkit.helpers.WorldGuardHelper) SimpleDateFormat(java.text.SimpleDateFormat) Player(org.bukkit.entity.Player) CoreUtil(br.net.fabiozumbi12.RedProtect.Core.helpers.CoreUtil) org.bukkit(org.bukkit) EventHandler(org.bukkit.event.EventHandler) PlayerCommandPreprocessEvent(org.bukkit.event.player.PlayerCommandPreprocessEvent) Region(br.net.fabiozumbi12.RedProtect.Bukkit.Region) ParseException(java.text.ParseException) RegionManager(com.sk89q.worldguard.protection.managers.RegionManager) Replacer(br.net.fabiozumbi12.RedProtect.Core.helpers.Replacer) Listener(org.bukkit.event.Listener) PlayerHandlers(br.net.fabiozumbi12.RedProtect.Bukkit.commands.SubCommands.PlayerHandlers) CommandSender(org.bukkit.command.CommandSender) MojangUUIDs(br.net.fabiozumbi12.RedProtect.Bukkit.helpers.MojangUUIDs) SpigetUpdater(br.net.fabiozumbi12.RedProtect.Bukkit.updater.SpigetUpdater) RegionType(com.sk89q.worldguard.protection.regions.RegionType) RedProtect(br.net.fabiozumbi12.RedProtect.Bukkit.RedProtect) WEHook(br.net.fabiozumbi12.RedProtect.Bukkit.hooks.WEHook) Flag(com.sk89q.worldguard.protection.flags.Flag) CommandExecutor(org.bukkit.command.CommandExecutor) Collectors(java.util.stream.Collectors) RegionHandlers(br.net.fabiozumbi12.RedProtect.Bukkit.commands.SubCommands.RegionHandlers) ItemStack(org.bukkit.inventory.ItemStack) TimeUnit(java.util.concurrent.TimeUnit) LiteChunk(me.ellbristow.mychunk.LiteChunk) MyChunkChunk(me.ellbristow.mychunk.MyChunkChunk) Command(org.bukkit.command.Command) UltimateFancy(br.net.fabiozumbi12.UltimateFancy.UltimateFancy) WorldGuardHelper(br.net.fabiozumbi12.RedProtect.Bukkit.helpers.WorldGuardHelper) Flag(com.sk89q.worldguard.protection.flags.Flag) ProtectedRegion(com.sk89q.worldguard.protection.regions.ProtectedRegion) RegionManager(com.sk89q.worldguard.protection.managers.RegionManager) PlayerRegion(br.net.fabiozumbi12.RedProtect.Core.region.PlayerRegion) ProtectedRegion(com.sk89q.worldguard.protection.regions.ProtectedRegion) Region(br.net.fabiozumbi12.RedProtect.Bukkit.Region)

Example 2 with WorldGuardHelper

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

the class HooksManager method registerHooksFirst.

public void registerHooksFirst() {
    try {
        boolean translationApi = checkTAPI();
        boolean infernalMobs = checkIMobs();
        boolean fac = checkFac();
        boolean placeHolderAPI = checkPHAPI();
        boolean mcMMO = checkMcMMo();
        boolean skillAPI = checkSkillAPI();
        if (checkSF4()) {
            RedProtect.get().getServer().getPluginManager().registerEvents(new SlimefunHook(), RedProtect.get());
            RedProtect.get().logger.info("Slimefun found. Hooked.");
        }
        if (checkVault()) {
            // Economy
            RegisteredServiceProvider<Economy> rsp = RedProtect.get().getServer().getServicesManager().getRegistration(Economy.class);
            if (rsp != null) {
                RedProtect.get().economy = rsp.getProvider();
                RedProtect.get().logger.info("Vault Economy found. Hooked.");
            } else {
                RedProtect.get().logger.warning("Could not initialize Vault Economy hook.");
            }
            // Permissions
            RegisteredServiceProvider<Permission> perm = RedProtect.get().getServer().getServicesManager().getRegistration(Permission.class);
            if (perm != null) {
                RedProtect.get().permission = perm.getProvider();
                RedProtect.get().logger.info("Vault Permissions found. Hooked.");
            } else {
                RedProtect.get().logger.warning("Could not initialize Vault Permissions hook.");
            }
        }
        if (infernalMobs) {
            try {
                RedProtect.get().getServer().getPluginManager().registerEvents(new InfernalMobsHook(), RedProtect.get());
                RedProtect.get().logger.info("InfernalMobs found. Hooked.");
            } catch (Exception ex) {
                RedProtect.get().logger.warning("Your InfernalMobs version is NOT compatible and has no API. Look for FabioZumbi12's version on Github!");
            }
        }
        if (checkPvPm()) {
            RedProtect.get().logger.info("PvPManager found. Hooked.");
        }
        if (checkEss()) {
            pless = (Essentials) Bukkit.getPluginManager().getPlugin("Essentials");
            RedProtect.get().logger.info("Essentials found. Hooked.");
        }
        if (checkWe()) {
            RedProtect.get().logger.info("WorldEdit found. Hooked.");
        }
        if (checkWG()) {
            RedProtect rp = RedProtect.get();
            if (rp.bukkitVersion >= 1130) {
                worldGuardHelper = (WorldGuardHelper) Class.forName("br.net.fabiozumbi12.RedProtect.Bukkit.helpers.WorldGuardHelperLatest").newInstance();
            } else {
                worldGuardHelper = (WorldGuardHelper) Class.forName("br.net.fabiozumbi12.RedProtect.Bukkit.helpers.WorldGuardHelper112").newInstance();
            }
            rp.logger.info("WorldGuard version " + worldGuardHelper.getWorldGuardMajorVersion() + " found. Hooked.");
        }
        if (checkAB()) {
            RedProtect.get().logger.info("ActionBarAPI found. Hooked.");
        }
        if (checkBM()) {
            RedProtect.get().logger.info("BossbarAPI found. Hooked.");
        }
        if (checkMyPet()) {
            RedProtect.get().getServer().getPluginManager().registerEvents(new MyPetHook(), RedProtect.get());
            RedProtect.get().logger.info("MyPet found. Hooked.");
        }
        if (mcMMO) {
            RedProtect.get().getServer().getPluginManager().registerEvents(new McMMOHook(), RedProtect.get());
            RedProtect.get().logger.info("mcMMo found. Hooked.");
        }
        if (skillAPI) {
            RedProtect.get().getServer().getPluginManager().registerEvents(new SkillAPIHook(), RedProtect.get());
            RedProtect.get().logger.info("SkillAPI found. Hooked.");
        }
        if (checkMyChunk()) {
            RedProtect.get().logger.success("MyChunk found. Ready to convert!");
            RedProtect.get().logger.warning("Use '/rp mychunkconvert' to start MyChunk conversion (This may cause lag during conversion)");
        }
        if (checkMagicCarpet()) {
            RedProtect.get().logger.info("MagicCarpet found. Hooked.");
        }
        if (checkSC()) {
            clanManager = SimpleClans.getInstance().getClanManager();
            RedProtect.get().logger.info("SimpleClans found. Hooked.");
        }
        if (placeHolderAPI) {
            new PAPIHook().register();
            RedProtect.get().logger.info("PlaceHolderAPI found. Hooked and registered some chat placeholders.");
        }
        if (fac) {
            RedProtect.get().getServer().getPluginManager().registerEvents(new FactionsHook(), RedProtect.get());
            RedProtect.get().logger.info("Factions found. Hooked.");
        }
        if (translationApi) {
            this.transAPI = new TransAPI();
            RedProtect.get().logger.info("TranslationAPI found. Hooked.");
        }
    } catch (Exception e) {
        CoreUtil.printJarVersion();
        e.printStackTrace();
    }
}
Also used : Economy(net.milkbowl.vault.economy.Economy) RedProtect(br.net.fabiozumbi12.RedProtect.Bukkit.RedProtect) Permission(net.milkbowl.vault.permission.Permission)

Aggregations

RedProtect (br.net.fabiozumbi12.RedProtect.Bukkit.RedProtect)2 Region (br.net.fabiozumbi12.RedProtect.Bukkit.Region)1 CommandHandlers (br.net.fabiozumbi12.RedProtect.Bukkit.commands.CommandHandlers)1 PlayerHandlers (br.net.fabiozumbi12.RedProtect.Bukkit.commands.SubCommands.PlayerHandlers)1 RegionHandlers (br.net.fabiozumbi12.RedProtect.Bukkit.commands.SubCommands.RegionHandlers)1 MojangUUIDs (br.net.fabiozumbi12.RedProtect.Bukkit.helpers.MojangUUIDs)1 WorldGuardHelper (br.net.fabiozumbi12.RedProtect.Bukkit.helpers.WorldGuardHelper)1 WEHook (br.net.fabiozumbi12.RedProtect.Bukkit.hooks.WEHook)1 SpigetUpdater (br.net.fabiozumbi12.RedProtect.Bukkit.updater.SpigetUpdater)1 CoreUtil (br.net.fabiozumbi12.RedProtect.Core.helpers.CoreUtil)1 Replacer (br.net.fabiozumbi12.RedProtect.Core.helpers.Replacer)1 PlayerRegion (br.net.fabiozumbi12.RedProtect.Core.region.PlayerRegion)1 UltimateFancy (br.net.fabiozumbi12.UltimateFancy.UltimateFancy)1 Flag (com.sk89q.worldguard.protection.flags.Flag)1 RegionManager (com.sk89q.worldguard.protection.managers.RegionManager)1 ProtectedRegion (com.sk89q.worldguard.protection.regions.ProtectedRegion)1 RegionType (com.sk89q.worldguard.protection.regions.RegionType)1 Array (java.lang.reflect.Array)1 ParseException (java.text.ParseException)1 SimpleDateFormat (java.text.SimpleDateFormat)1