com.sk89q.worldguard.protection.flags.Flag Java Examples

The following examples show how to use com.sk89q.worldguard.protection.flags.Flag. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DependencyManager.java    From NovaGuilds with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void run() throws Exception {
	if(!Config.REGION_WORLDGUARD.getBoolean()) {
		LoggerUtils.info("Skipping WorldGuardFlag Injector. Disabled in config");
		return;
	}

	plugin.getRegionManager().createWorldGuardFlag();
	FieldAccessor<Flag[]> defaultFlagFlagListField = Reflections.getField(DefaultFlag.class, "flagsList", Flag[].class);
	defaultFlagFlagListField.setNotFinal();
	Flag[] array = defaultFlagFlagListField.get(null);
	List<Flag> list = new ArrayList<>();
	Collections.addAll(list, array);
	list.add((StateFlag) RegionManager.WORLDGUARD_FLAG);
	defaultFlagFlagListField.set(list.toArray(new Flag[list.size()]));
	LoggerUtils.info("Successfully injected WorldGuard Flag");
}
 
Example #2
Source File: WorldGuardUtils.java    From WorldGuardExtraFlagsPlugin with MIT License 6 votes vote down vote up
public static <T> FlagValueCalculator createFlagValueCalculator(Player player, World world, Set<ProtectedRegion> regions, Flag<T> flag)
{
	List<ProtectedRegion> checkForRegions = new ArrayList<>();
	for(ProtectedRegion region : regions)
	{
		if (!WorldGuardUtils.hasBypass(player, world, region, flag))
		{
			checkForRegions.add(region);
		}
	}
	
	NormativeOrders.sort(checkForRegions);
	
	ProtectedRegion global = WorldGuardUtils.getCommunicator().getRegionContainer().get(world).getRegion(ProtectedRegion.GLOBAL_REGION);
	if (global != null) //Global region can be null
	{
		if (WorldGuardUtils.hasBypass(player, world, global, flag)) //Lets do like this for now to reduce dublicated code
		{
			global = null;
		}
	}
	
	return new FlagValueCalculator(checkForRegions, global);
}
 
Example #3
Source File: HookWorldGuard_V6_1.java    From CombatLogX with GNU General Public License v3.0 6 votes vote down vote up
public static void registerFlags(Expansion expansion) {
    try {
        Class<?> class_DefaultFlag = DefaultFlag.class;
        Class<?> class_Field = Field.class;

        final Flag<?>[] defaultFlagList = DefaultFlag.flagsList;
        int defaultFlagListLength = defaultFlagList.length;

        Flag<?>[] flagArray = new Flag[defaultFlagListLength + 2];
        System.arraycopy(defaultFlagList, 0, flagArray, 0, defaultFlagListLength);
        flagArray[defaultFlagListLength] = mobCombatFlag;
        flagArray[defaultFlagListLength + 1] = noTaggingFlag;

        Field field_DefaultFlag_flagsList = class_DefaultFlag.getField("flagsList");
        Field field_Field_modifiers = class_Field.getDeclaredField("modifiers");
        field_Field_modifiers.setAccessible(true);
        field_Field_modifiers.setInt(field_DefaultFlag_flagsList, field_DefaultFlag_flagsList.getModifiers() & ~Modifier.FINAL);
        field_DefaultFlag_flagsList.set(null, flagArray);
    } catch(ReflectiveOperationException ex) {
        Logger logger = expansion.getLogger();
        logger.log(Level.WARNING, "An error occurred while trying to register WorldGuard flags.", ex);
    }
}
 
Example #4
Source File: WorldGuardExtraFlagsPlugin.java    From WorldGuardExtraFlagsPlugin with MIT License 6 votes vote down vote up
private Set<Flag<?>> getPluginFlags()
{
	Set<Flag<?>> flags = new HashSet<>();
	
	for (Field field : Flags.class.getFields())
	{
		try
		{
			flags.add((Flag<?>)field.get(null));
		}
		catch (IllegalArgumentException | IllegalAccessException e)
		{
		}
	}
	
	return flags;
}
 
Example #5
Source File: WorldGuardRegionFlagsFeature.java    From AreaShop with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Set a WorldGuard region flag.
 * @param region The WorldGuard region to set
 * @param flag   The flag to set
 * @param value  The value to set the flag to
 * @param <V>    They type of flag to set
 * @throws InvalidFlagFormat When the value of the flag is wrong
 */
private <V> void setFlag(ProtectedRegion region, Flag<V> flag, String value) throws InvalidFlagFormat {
	V current = region.getFlag(flag);
	V next = plugin.getWorldGuardHandler().parseFlagInput(flag, value);

	if(!Objects.equals(current, next)) {
		region.setFlag(flag, next);
	}
}
 
Example #6
Source File: RadiationPlugin.java    From CraftserveRadiation with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private Flag<Boolean> getOrCreateRadiationFlag(FlagRegistry flagRegistry) {
    Objects.requireNonNull(flagRegistry, "flagRegistry");

    Flag<Boolean> flag = (Flag<Boolean>) flagRegistry.get(RADIATION_FLAG.getName());
    if (flag != null) {
        return flag;
    }

    flag = RADIATION_FLAG;
    flagRegistry.register(flag);
    return flag;
}
 
Example #7
Source File: WorldGuardUtils.java    From WorldGuardExtraFlagsPlugin with MIT License 5 votes vote down vote up
public static boolean hasBypass(Player player, World world, ProtectedRegion region, Flag<?> flag)
{
	if (player.hasMetadata("NPC"))
	{
		return true;
	}
	
	//Permission system that supports wildcars is really helpful here :)
	if (player.hasPermission("worldguard.region.bypass." + world.getName() + "." + region.getId() + "." + flag.getName()))
	{
		return true;
	}
	
	return false;
}
 
Example #8
Source File: RegionManager.java    From NovaGuilds with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Checks WorldGuard validity if possible
 *
 * @param selection region selection
 * @return true if valid
 */
private boolean checkWorldGuardValidity(RegionSelection selection) {
	if(!plugin.getDependencyManager().isEnabled(Dependency.WORLDGUARD)) {
		return true;
	}

	WorldGuardPlugin worldGuard = plugin.getDependencyManager().get(Dependency.WORLDGUARD, WorldGuardPlugin.class);
	Area selectionArea = new Area(new Rectangle(
			selection.getCorner(selection.getCorner(0).getBlockX() < selection.getCorner(1).getBlockX() ? 0 : 1).getBlockX(),
			selection.getCorner(selection.getCorner(0).getBlockZ() < selection.getCorner(1).getBlockZ() ? 0 : 1).getBlockZ(),
			selection.getWidth(),
			selection.getLength())
	);

	for(ProtectedRegion region : worldGuard.getRegionManager(selection.getWorld()).getRegions().values()) {
		if(region.getFlag((Flag) RegionManager.WORLDGUARD_FLAG) == StateFlag.State.ALLOW) {
			continue;
		}

		Area regionArea = RegionUtils.toArea(region);

		regionArea.intersect(selectionArea);
		if(!regionArea.isEmpty()) {
			return false;
		}
	}

	return true;
}
 
Example #9
Source File: WorldGuardExtraFlagsPlugin.java    From WorldGuardExtraFlagsPlugin with MIT License 5 votes vote down vote up
private void setupMetrics()
{
	final int bStatsPluginId = 7301;
	
       Metrics metrics = new Metrics(this, bStatsPluginId);
       metrics.addCustomChart(new Metrics.AdvancedPie("flags_count", new Callable<Map<String, Integer>>()
       {
       	private final Set<Flag<?>> flags = WorldGuardExtraFlagsPlugin.this.getPluginFlags();
       	
		@Override
		public Map<String, Integer> call() throws Exception
		{
            Map<Flag<?>, Integer> valueMap = this.flags.stream().collect(Collectors.toMap((v) -> v, (v) -> 0));

            WorldGuardExtraFlagsPlugin.this.getWorldGuardCommunicator().getRegionContainer().getLoaded().forEach((m) ->
            {
            	m.getRegions().values().forEach((r) ->
            	{
            		r.getFlags().keySet().forEach((f) -> 
            		{
            			valueMap.computeIfPresent(f, (k, v) -> v + 1);
            		});
            	});
            });
            
			return valueMap.entrySet().stream().collect(Collectors.toMap((v) -> v.getKey().getName(), (v) -> v.getValue()));
		}
       }));
}
 
Example #10
Source File: WorldGuardHandler5.java    From AreaShop with GNU General Public License v3.0 4 votes vote down vote up
@Override
public <V> V parseFlagInput(Flag<V> flag, String input) throws InvalidFlagFormat {
	return flag.parseInput(WorldGuardPlugin.inst(), null, input);
}
 
Example #11
Source File: CommandHandler.java    From RedProtect with GNU General Public License v3.0 4 votes vote down vote up
private static boolean handleWGRegions() {
    if (!RedProtect.get().hooks.worldguard) {
        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().rm.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().config.configRoot().region_settings.default_leader, RedProtect.get().config.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().config.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().rm.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;
}
 
Example #12
Source File: WorldGuardHandler7_beta_2.java    From AreaShop with GNU General Public License v3.0 4 votes vote down vote up
@Override
public Flag<?> fuzzyMatchFlag(String flagName) {
	return Flags.fuzzyMatchFlag(WorldGuard.getInstance().getFlagRegistry(), flagName);
}
 
Example #13
Source File: WorldGuardHandler7_beta_2.java    From AreaShop with GNU General Public License v3.0 4 votes vote down vote up
@Override
public <V> V parseFlagInput(Flag<V> flag, String input) throws InvalidFlagFormat {
	return flag.parseInput(FlagContext.create().setInput(input).build());
}
 
Example #14
Source File: WorldGuardHandler6.java    From AreaShop with GNU General Public License v3.0 4 votes vote down vote up
@Override
public Flag<?> fuzzyMatchFlag(String flagName) {
	return DefaultFlag.fuzzyMatchFlag(flagName);
}
 
Example #15
Source File: WorldGuardHandler6.java    From AreaShop with GNU General Public License v3.0 4 votes vote down vote up
@Override
public <V> V parseFlagInput(Flag<V> flag, String input) throws InvalidFlagFormat {
	return flag.parseInput(WorldGuardPlugin.inst(), null, input);
}
 
Example #16
Source File: FastAsyncWorldEditWorldGuardHandler.java    From AreaShop with GNU General Public License v3.0 4 votes vote down vote up
@Override
public Flag<?> fuzzyMatchFlag(String flagName) {
	return Flags.fuzzyMatchFlag(WorldGuard.getInstance().getFlagRegistry(), flagName);
}
 
Example #17
Source File: FastAsyncWorldEditWorldGuardHandler.java    From AreaShop with GNU General Public License v3.0 4 votes vote down vote up
@Override
public <V> V parseFlagInput(Flag<V> flag, String input) throws InvalidFlagFormat {
	return flag.parseInput(FlagContext.create().setInput(input).build());
}
 
Example #18
Source File: WorldGuardHandler7_beta_1.java    From AreaShop with GNU General Public License v3.0 4 votes vote down vote up
@Override
public Flag<?> fuzzyMatchFlag(String flagName) {
	return Flags.fuzzyMatchFlag(WorldGuard.getInstance().getFlagRegistry(), flagName);
}
 
Example #19
Source File: WorldGuardHandler7_beta_1.java    From AreaShop with GNU General Public License v3.0 4 votes vote down vote up
@Override
public <V> V parseFlagInput(Flag<V> flag, String input) throws InvalidFlagFormat {
	return flag.parseInput(FlagContext.create().setInput(input).build());
}
 
Example #20
Source File: WorldGuardHandler6_1_3.java    From AreaShop with GNU General Public License v3.0 4 votes vote down vote up
@Override
public Flag<?> fuzzyMatchFlag(String flagName) {
	return DefaultFlag.fuzzyMatchFlag(WorldGuardPlugin.inst().getFlagRegistry(), flagName);
}
 
Example #21
Source File: WorldGuardHandler6_1_3.java    From AreaShop with GNU General Public License v3.0 4 votes vote down vote up
@Override
public <V> V parseFlagInput(Flag<V> flag, String input) throws InvalidFlagFormat {
	return flag.parseInput(FlagContext.create().setInput(input).build());
}
 
Example #22
Source File: WorldGuardHandler5.java    From AreaShop with GNU General Public License v3.0 4 votes vote down vote up
@Override
public Flag<?> fuzzyMatchFlag(String flagName) {
	return DefaultFlag.fuzzyMatchFlag(flagName);
}
 
Example #23
Source File: Radiation.java    From CraftserveRadiation with Apache License 2.0 4 votes vote down vote up
public FlagMatcher(Flag<Boolean> flag) {
    this.flag = Objects.requireNonNull(flag, "flag");
}
 
Example #24
Source File: CustomSetFlag.java    From WorldGuardExtraFlagsPlugin with MIT License 4 votes vote down vote up
public CustomSetFlag(String name, Flag<T> subFlag)
{
	super(name, subFlag);
}
 
Example #25
Source File: WorldGuardSixCommunicator.java    From WorldGuardExtraFlagsPlugin with MIT License 4 votes vote down vote up
@Override
public <T> SetFlag<T> getCustomSetFlag(String name, Flag<T> flag)
{
	return new CustomSetFlag<T>(name, flag);
}
 
Example #26
Source File: CustomSetFlag.java    From WorldGuardExtraFlagsPlugin with MIT License 4 votes vote down vote up
public CustomSetFlag(String name, Flag<T> subFlag)
{
	super(name, subFlag);
}
 
Example #27
Source File: WorldGuardSevenCommunicator.java    From WorldGuardExtraFlagsPlugin with MIT License 4 votes vote down vote up
@Override
public <T> SetFlag<T> getCustomSetFlag(String name, Flag<T> flag)
{
	return new CustomSetFlag<T>(name, flag);
}
 
Example #28
Source File: WorldGuardUtils.java    From WorldGuardExtraFlagsPlugin with MIT License 4 votes vote down vote up
public static <T> Collection<T> queryAllValues(Player player, World world, Set<ProtectedRegion> regions, Flag<T> flag)
{
	return WorldGuardUtils.createFlagValueCalculator(player, world, regions, flag).queryAllValues(WorldGuardUtils.wrapPlayer(player), flag);
}
 
Example #29
Source File: WorldGuardUtils.java    From WorldGuardExtraFlagsPlugin with MIT License 4 votes vote down vote up
@SuppressWarnings({ "unchecked", "rawtypes" })
public static Object queryValueUnchecked(Player player, World world, Set<ProtectedRegion> regions, Flag flag)
{
	return WorldGuardUtils.createFlagValueCalculator(player, world, regions, flag).queryValue(WorldGuardUtils.wrapPlayer(player), flag);
}
 
Example #30
Source File: WorldGuardUtils.java    From WorldGuardExtraFlagsPlugin with MIT License 4 votes vote down vote up
public static <T> T queryValue(Player player, World world, Set<ProtectedRegion> regions, Flag<T> flag)
{
	return WorldGuardUtils.createFlagValueCalculator(player, world, regions, flag).queryValue(WorldGuardUtils.wrapPlayer(player), flag);
}