com.sk89q.worldguard.bukkit.WorldGuardPlugin Java Examples

The following examples show how to use com.sk89q.worldguard.bukkit.WorldGuardPlugin. 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: WorldGuardHandler.java    From Shopkeepers with GNU General Public License v3.0 6 votes vote down vote up
public static boolean isShopAllowed(Player player, Location loc) {
	Plugin plugin = getPlugin();
	if (plugin != null) {
		WorldGuardPlugin wgPlugin = (WorldGuardPlugin) plugin;
		boolean allowShopFlag = wgPlugin.getRegionManager(loc.getWorld()).getApplicableRegions(loc).testState(null, DefaultFlag.ENABLE_SHOP);
		if (Settings.requireWorldGuardAllowShopFlag) {
			// allow shops ONLY in regions with the ENABLE_SHOP flag set:
			return allowShopFlag;
		} else {
			// allow shops in regions where the ENABLE_SHOP flag is set OR the player can build:
			return allowShopFlag || wgPlugin.canBuild(player, loc);
		}
	} else {
		return true;
	}
}
 
Example #2
Source File: BridgeImpl.java    From TabooLib with MIT License 6 votes vote down vote up
public BridgeImpl() {
    if (Bukkit.getPluginManager().getPlugin("Vault") != null) {
        economy = getRegisteredService(Economy.class);
        permission = getRegisteredService(Permission.class);
    }
    if (Bukkit.getPluginManager().getPlugin("WorldGuard") != null) {
        if (!WorldGuardPlugin.inst().getDescription().getVersion().startsWith("7")) {
            try {
                getRegionManager = WorldGuardPlugin.class.getDeclaredMethod("getRegionManager", World.class);
                getRegionManager.setAccessible(true);
            } catch (NoSuchMethodException e) {
                e.printStackTrace();
            }
        }
        worldguard = true;
    }
    placeholder = Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null;
}
 
Example #3
Source File: WorldGuardFilter.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void calculateRegions() {
    TaskManager.IMP.sync(new RunnableVal<Object>() {
        @Override
        public void run(Object value) {
            WorldGuardFilter.this.manager = WorldGuardPlugin.inst().getRegionManager(world);
            for (ProtectedRegion region : manager.getRegions().values()) {
                BlockVector min = region.getMinimumPoint();
                BlockVector max = region.getMaximumPoint();
                if (max.getBlockX() - min.getBlockX() > 1024 || max.getBlockZ() - min.getBlockZ() > 1024) {
                    Fawe.debug("Large or complex region shapes cannot be optimized. Filtering will be slower");
                    large = true;
                    break;
                }
                add(min.toVector2D(), max.toVector2D());
            }
        }
    });
}
 
Example #4
Source File: WorldUtil.java    From SonarPet with GNU General Public License v3.0 5 votes vote down vote up
public static boolean allowRegion(Location location) {
    if (EchoPet.getPlugin().getWorldGuardProvider().isHooked()) {
        WorldGuardPlugin wg = EchoPet.getPlugin().getWorldGuardProvider().getDependency();
        if (wg == null) {
            return true;
        }
        RegionManager regionManager = wg.getRegionManager(location.getWorld());

        if (regionManager == null) {
            return true;
        }

        ApplicableRegionSet set = regionManager.getApplicableRegions(location);

        if (set.size() <= 0) {
            return true;
        }

        boolean result = true;
        boolean hasSet = false;
        boolean def = EchoPet.getPlugin().getMainConfig().getBoolean("worldguard.regions.allowByDefault", true);

        ConfigurationSection cs = EchoPet.getPlugin().getMainConfig().getConfigurationSection("worldguard.regions");
        for (ProtectedRegion region : set) {
            for (String key : cs.getKeys(false)) {
                if (!key.equalsIgnoreCase("allowByDefault") && !key.equalsIgnoreCase("regionEnterCheck")) {
                    if (region.getId().equals(key)) {
                        if (!hasSet) {
                            result = EchoPet.getPlugin().getMainConfig().getBoolean("worldguard.regions." + key, true);
                            hasSet = true;
                        }
                    }
                }
            }
        }

        return hasSet ? result : def;
    }
    return true;
}
 
Example #5
Source File: WorldUtil.java    From EchoPet with GNU General Public License v3.0 5 votes vote down vote up
public static boolean allowRegion(Location location) {
    if (EchoPet.getPlugin().getWorldGuardProvider().isHooked()) {
        WorldGuardPlugin wg = EchoPet.getPlugin().getWorldGuardProvider().getDependency();
        if (wg == null) {
            return true;
        }
        RegionManager regionManager = wg.getRegionManager(location.getWorld());

        if (regionManager == null) {
            return true;
        }

        ApplicableRegionSet set = regionManager.getApplicableRegions(location);

        if (set.size() <= 0) {
            return true;
        }

        boolean result = true;
        boolean hasSet = false;
        boolean def = EchoPet.getPlugin().getMainConfig().getBoolean("worldguard.regions.allowByDefault", true);

        ConfigurationSection cs = EchoPet.getPlugin().getMainConfig().getConfigurationSection("worldguard.regions");
        for (ProtectedRegion region : set) {
            for (String key : cs.getKeys(false)) {
                if (!key.equalsIgnoreCase("allowByDefault") && !key.equalsIgnoreCase("regionEnterCheck")) {
                    if (region.getId().equals(key)) {
                        if (!hasSet) {
                            result = EchoPet.getPlugin().getMainConfig().getBoolean("worldguard.regions." + key, true);
                            hasSet = true;
                        }
                    }
                }
            }
        }

        return hasSet ? result : def;
    }
    return true;
}
 
Example #6
Source File: WorldGuardHook.java    From FunnyGuilds with Apache License 2.0 5 votes vote down vote up
public static void initWorldGuard() {
    WorldGuardHook.worldGuard = WorldGuardPlugin.inst();
    noPointsFlag = new StateFlag("fg-no-points", false);
    
    try {
        ((FlagRegistry) GET_FLAG_REGISTRY.invoke(GET_INSTANCE.invoke(null))).register(noPointsFlag);
    }
    catch (FlagConflictException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
        FunnyGuilds.getInstance().getPluginLogger().error("An error occurred while registering an \"fg-no-points\" worldguard flag", ex);
    }
}
 
Example #7
Source File: WorldGuardHandler.java    From uSkyBlock with GNU General Public License v3.0 5 votes vote down vote up
public static WorldGuardPlatform getWorldGuard() {
    final Plugin plugin = uSkyBlock.getInstance().getServer().getPluginManager().getPlugin("WorldGuard");
    if (!(plugin instanceof WorldGuardPlugin)) {
        return null;
    }
    return WorldGuard.getInstance().getPlatform();
}
 
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: Worldguard.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
private WorldGuardPlugin getWorldGuard() {
    final Plugin plugin = Bukkit.getPluginManager().getPlugin("WorldGuard");

    // WorldGuard may not be loaded
    if ((plugin == null) || !(plugin instanceof WorldGuardPlugin)) {
        return null; // Maybe you want throw an exception instead
    }

    return (WorldGuardPlugin) plugin;
}
 
Example #10
Source File: Radiation.java    From CraftserveRadiation with Apache License 2.0 5 votes vote down vote up
@Override
public boolean test(Player player, RegionContainer regionContainer) {
    Location location = BukkitAdapter.adapt(player.getLocation());
    location = location.setY(Math.max(0, Math.min(255, location.getY())));
    ApplicableRegionSet regions = regionContainer.createQuery().getApplicableRegions(location);

    Boolean value = regions.queryValue(WorldGuardPlugin.inst().wrapPlayer(player), this.flag);
    return value != null && value;
}
 
Example #11
Source File: HookWorldGuard_V6_1.java    From CombatLogX with GNU General Public License v3.0 5 votes vote down vote up
private static ApplicableRegionSet getRegions(Location location) {
    World world = location.getWorld();

    WorldGuardPlugin api = getAPI();
    RegionManager manager = api.getRegionManager(world);
    return manager.getApplicableRegions(location);
}
 
Example #12
Source File: HookWorldGuard_V6_2.java    From CombatLogX with GNU General Public License v3.0 5 votes vote down vote up
private static ApplicableRegionSet getRegions(Location location) {
    World world = location.getWorld();

    WorldGuardPlugin api = getAPI();
    RegionManager manager = api.getRegionManager(world);
    return manager.getApplicableRegions(location);
}
 
Example #13
Source File: WorldGuardSixCommunicator.java    From WorldGuardExtraFlagsPlugin with MIT License 5 votes vote down vote up
@Override
public void onEnable(Plugin plugin) throws Exception
{
	this.sessionManager = new SessionManagerWrapper(WorldGuardPlugin.inst().getSessionManager());
	this.regionContainer = new RegionContainerWrapper();
	
	WorldGuardCommunicator.super.onEnable(plugin);
}
 
Example #14
Source File: BridgeImpl.java    From TabooLib with MIT License 5 votes vote down vote up
private RegionManager worldguardRegionManager(World world) {
    if (WorldGuardPlugin.inst().getDescription().getVersion().startsWith("7")) {
        return WorldGuard.getInstance().getPlatform().getRegionContainer().get(BukkitAdapter.adapt(world));
    } else {
        try {
            return (RegionManager) getRegionManager.invoke(WorldGuardPlugin.inst(), world);
        } catch (Throwable t) {
            t.printStackTrace();
        }
        return null;
    }
}
 
Example #15
Source File: WorldGuard.java    From Modern-LWC with MIT License 5 votes vote down vote up
@Override
public void load(LWC lwc) {
    Plugin plugin = lwc.getPlugin().getServer().getPluginManager()
            .getPlugin("WorldGuard");
    if (plugin != null) {
        if (plugin.getDescription().getAPIVersion() != null) {
            worldGuardPlugin = (WorldGuardPlugin) plugin;
        } else if (configuration.getBoolean("worldguard.enabled", false)) {
            lwc.log("An outdated version of WorldGuard has been detected.");
            lwc.log("Please update it if you wish to use WorldGuard with LWC.");
        }
    }
}
 
Example #16
Source File: Main.java    From ActionHealth with MIT License 5 votes vote down vote up
@Override
public void onEnable() {
    saveDefaultConfig();

    // Register health util
    this.healthUtil = new HealthUtil(this);

    // Load config settings
    configStore = new ConfigStore(this);

    // Create player folder
    File file = new File("plugins/ActionHealth/players/");
    file.mkdirs();

    // Register listeners
    getServer().getPluginManager().registerEvents(new HealthListeners(this), this);
    getServer().getPluginManager().registerEvents(new ActionListener(this, new ActionHelper(this)), this);

    // Register commands
    getCommand("Actionhealth").setExecutor(new HealthCommand(this));

    if (Bukkit.getServer().getPluginManager().isPluginEnabled("WorldGuard")) {
        this.worldGuardPlugin = ((WorldGuardPlugin) getServer().getPluginManager().getPlugin("WorldGuard"));
        this.worldGuardAPI = new WorldGuardAPI(this);
    }

    if (Bukkit.getServer().getPluginManager().isPluginEnabled("mcMMO")) {
        mcMMOEnabled = true;
    }

    if (Bukkit.getServer().getPluginManager().isPluginEnabled("MythicMobs")) {
        mythicMobsEnabled = true;
    }

    if (Bukkit.getServer().getPluginManager().isPluginEnabled("LangUtils")) {
        langUtilsEnabled = true;
    }

    actionTask = new ActionTask(this).runTaskTimer(this, 0, configStore.checkTicks);
}
 
Example #17
Source File: WorldEditFlagHandler.java    From WorldGuardExtraFlagsPlugin with MIT License 5 votes vote down vote up
@Override
public boolean setBlock(Vector location, BaseBlock block) throws WorldEditException
{
	ApplicableRegionSet regions = WorldGuardPlugin.inst().getRegionContainer().get(this.world).getApplicableRegions(location);
	
	State state = WorldGuardUtils.queryState(this.player, this.world, regions.getRegions(), Flags.WORLDEDIT);
	if (state != State.DENY)
	{
		return super.setBlock(location, block);
	}
	
	return false;
}
 
Example #18
Source File: WorldGuard7FAWEHook.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean canBuild_i(final Player p, final Location l) {
    if (p.hasPermission("worldguard.region.bypass." + l.getWorld().getName())) return true;
    RegionQuery query = WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery();
    LocalPlayer player = WorldGuardPlugin.inst().wrapPlayer(p);
    return query.testState(BukkitAdapter.adapt(l), player, Flags.BUILD);
}
 
Example #19
Source File: WorldGuard7Hook.java    From RandomTeleport with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean canBuild(Player player, org.bukkit.Location location) {
    return canBuild(WorldGuardPlugin.inst().wrapPlayer(player), BukkitAdapter.adapt(location));
}
 
Example #20
Source File: WorldGuardIntegration.java    From QuickShop-Reremake with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean canCreateShopHere(@NotNull Player player, @NotNull Location location) {
    LocalPlayer localPlayer = WorldGuardPlugin.inst().wrapPlayer(player);
    com.sk89q.worldedit.util.Location wgLoc = BukkitAdapter.adapt(location);
    boolean canBypass =
            WorldGuard.getInstance()
                    .getPlatform()
                    .getSessionManager()
                    .hasBypass(localPlayer, BukkitAdapter.adapt(location.getWorld()));
    if (canBypass) {
        Util.debugLog(
                "Player "
                        + player.getName()
                        + " bypassing the protection checks, because player have bypass permission in WorldGuard");
        return true;
    }
    RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer();
    RegionQuery query = container.createQuery();
    if (query.getApplicableRegions(wgLoc).getRegions().isEmpty()) {
        return !whiteList;
    }
    for (WorldGuardFlags flag : createFlags) {
        switch (flag) {
            case BUILD:
                if (query.queryState(wgLoc, localPlayer, Flags.BUILD) == StateFlag.State.DENY) {
                    return false;
                }
                break;
            case FLAG:
                if (query.queryState(wgLoc, localPlayer, this.createFlag) == StateFlag.State.DENY) {
                    return false;
                }
                break;
            case CHEST_ACCESS:
                if (query.queryState(wgLoc, localPlayer, Flags.CHEST_ACCESS) == StateFlag.State.DENY) {
                    return false;
                }
                break;
            case INTERACT:
                if (query.queryState(wgLoc, localPlayer, Flags.INTERACT) == StateFlag.State.DENY) {
                    return false;
                }
                break;
        }
    }
    return true;
}
 
Example #21
Source File: WorldGuard7Hook.java    From RandomTeleport with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean canBuild(Player player, World world, int chunkX, int chunkZ) {
    return canBuild(WorldGuardPlugin.inst().wrapPlayer(player), new Location(
            BukkitAdapter.adapt(world), (double) chunkX * 16 + 8, world.getSeaLevel(), (double) chunkZ * 16 + 8)
    );
}
 
Example #22
Source File: WorldGuardHandler5.java    From AreaShop with GNU General Public License v3.0 4 votes vote down vote up
@Override
public RegionManager getRegionManager(World world) {
	return WorldGuardPlugin.inst().getRegionManager(world);
}
 
Example #23
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 #24
Source File: WorldGuardHandler5.java    From AreaShop with GNU General Public License v3.0 4 votes vote down vote up
@Override
public RegionGroup parseFlagGroupInput(RegionGroupFlag flag, String input) throws InvalidFlagFormat {
	return flag.parseInput(WorldGuardPlugin.inst(), null, input);
}
 
Example #25
Source File: WorldGuardHandler6.java    From AreaShop with GNU General Public License v3.0 4 votes vote down vote up
@Override
public RegionManager getRegionManager(World world) {
	return WorldGuardPlugin.inst().getRegionManager(world);
}
 
Example #26
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 #27
Source File: WorldGuardHandler6.java    From AreaShop with GNU General Public License v3.0 4 votes vote down vote up
@Override
public RegionGroup parseFlagGroupInput(RegionGroupFlag flag, String input) throws InvalidFlagFormat {
	return flag.parseInput(WorldGuardPlugin.inst(), null, input);
}
 
Example #28
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 #29
Source File: AreaShop.java    From AreaShop with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Function to get the WorldGuard plugin.
 * @return WorldGuardPlugin
 */
@Override
public WorldGuardPlugin getWorldGuard() {
	return worldGuard;
}
 
Example #30
Source File: Main.java    From ce with GNU Lesser General Public License v3.0 4 votes vote down vote up
public static WorldGuardPlugin getWorldGuard() {
    Plugin worldguard = Bukkit.getServer().getPluginManager().getPlugin("WorldGuard");
    if (worldguard != null && worldguard instanceof WorldGuardPlugin && worldguard.isEnabled())
        return (WorldGuardPlugin) worldguard;
    return null;
}