Search in sources :

Example 1 with WorldGuard

use of com.sk89q.worldguard.WorldGuard in project WorldGuard by EngineHub.

the class WorldGuardPlugin method onEnable.

/**
 * Called on plugin enable.
 */
@Override
public void onEnable() {
    // Catch bad things being done by naughty plugins that include WorldGuard's classes
    ClassSourceValidator verifier = new ClassSourceValidator(this);
    verifier.reportMismatches(ImmutableList.of(WorldGuard.class, ProtectedRegion.class, Flag.class));
    configureLogger();
    // Need to create the plugins/WorldGuard folder
    getDataFolder().mkdirs();
    PermissionsResolverManager.initialize(this);
    // Initialise WorldGuard
    WorldGuard.getInstance().setPlatform(platform = new BukkitWorldGuardPlatform());
    WorldGuard.getInstance().setup();
    BukkitSessionManager sessionManager = (BukkitSessionManager) platform.getSessionManager();
    // Set the proper command injector
    commands.setInjector(new SimpleInjector(WorldGuard.getInstance()));
    // Register command classes
    final CommandsManagerRegistration reg = new CommandsManagerRegistration(this, commands);
    reg.register(ToggleCommands.class);
    reg.register(ProtectionCommands.class);
    getServer().getScheduler().scheduleSyncDelayedTask(this, () -> {
        if (!platform.getGlobalStateManager().hasCommandBookGodMode()) {
            reg.register(GeneralCommands.class);
        }
    }, 0L);
    getServer().getScheduler().scheduleSyncRepeatingTask(this, sessionManager, BukkitSessionManager.RUN_DELAY, BukkitSessionManager.RUN_DELAY);
    // Register events
    getServer().getPluginManager().registerEvents(sessionManager, this);
    (new WorldGuardPlayerListener(this)).registerEvents();
    (new WorldGuardBlockListener(this)).registerEvents();
    (new WorldGuardEntityListener(this)).registerEvents();
    (new WorldGuardWeatherListener(this)).registerEvents();
    (new WorldGuardVehicleListener(this)).registerEvents();
    (new WorldGuardServerListener(this)).registerEvents();
    (new WorldGuardHangingListener(this)).registerEvents();
    // Modules
    (playerMoveListener = new PlayerMoveListener(this)).registerEvents();
    (new BlacklistListener(this)).registerEvents();
    (new ChestProtectionListener(this)).registerEvents();
    (new RegionProtectionListener(this)).registerEvents();
    (new RegionFlagsListener(this)).registerEvents();
    (new WorldRulesListener(this)).registerEvents();
    (new BlockedPotionsListener(this)).registerEvents();
    (new EventAbstractionListener(this)).registerEvents();
    (new PlayerModesListener(this)).registerEvents();
    (new BuildPermissionListener(this)).registerEvents();
    (new InvincibilityListener(this)).registerEvents();
    if ("true".equalsIgnoreCase(System.getProperty("worldguard.debug.listener"))) {
        (new DebuggingListener(this, WorldGuard.logger)).registerEvents();
    }
    platform.getGlobalStateManager().updateCommandBookGodMode();
    if (getServer().getPluginManager().isPluginEnabled("CommandBook")) {
        getServer().getPluginManager().registerEvents(new WorldGuardCommandBookListener(this), this);
    }
    // handle worlds separately to initialize already loaded worlds
    WorldGuardWorldListener worldListener = (new WorldGuardWorldListener(this));
    for (World world : getServer().getWorlds()) {
        worldListener.initWorld(world);
    }
    worldListener.registerEvents();
    Bukkit.getScheduler().runTask(this, () -> {
        for (Player player : Bukkit.getServer().getOnlinePlayers()) {
            ProcessPlayerEvent event = new ProcessPlayerEvent(player);
            Events.fire(event);
        }
    });
    ((SimpleFlagRegistry) WorldGuard.getInstance().getFlagRegistry()).setInitialized(true);
    // Enable metrics
    // bStats plugin id
    final Metrics metrics = new Metrics(this, BSTATS_PLUGIN_ID);
    if (platform.getGlobalStateManager().extraStats) {
        setupCustomCharts(metrics);
    }
}
Also used : PlayerModesListener(com.sk89q.worldguard.bukkit.listener.PlayerModesListener) ProcessPlayerEvent(com.sk89q.worldguard.bukkit.event.player.ProcessPlayerEvent) BlacklistListener(com.sk89q.worldguard.bukkit.listener.BlacklistListener) EventAbstractionListener(com.sk89q.worldguard.bukkit.listener.EventAbstractionListener) WorldGuardEntityListener(com.sk89q.worldguard.bukkit.listener.WorldGuardEntityListener) World(org.bukkit.World) SimpleFlagRegistry(com.sk89q.worldguard.protection.flags.registry.SimpleFlagRegistry) Metrics(org.bstats.bukkit.Metrics) RegionProtectionListener(com.sk89q.worldguard.bukkit.listener.RegionProtectionListener) BukkitSessionManager(com.sk89q.worldguard.bukkit.session.BukkitSessionManager) DebuggingListener(com.sk89q.worldguard.bukkit.listener.DebuggingListener) ProtectedRegion(com.sk89q.worldguard.protection.regions.ProtectedRegion) PlayerMoveListener(com.sk89q.worldguard.bukkit.listener.PlayerMoveListener) WorldGuardWeatherListener(com.sk89q.worldguard.bukkit.listener.WorldGuardWeatherListener) WorldGuard(com.sk89q.worldguard.WorldGuard) WorldGuardWorldListener(com.sk89q.worldguard.bukkit.listener.WorldGuardWorldListener) Player(org.bukkit.entity.Player) OfflinePlayer(org.bukkit.OfflinePlayer) LocalPlayer(com.sk89q.worldguard.LocalPlayer) CommandsManagerRegistration(com.sk89q.bukkit.util.CommandsManagerRegistration) ClassSourceValidator(com.sk89q.worldguard.bukkit.util.ClassSourceValidator) BlockedPotionsListener(com.sk89q.worldguard.bukkit.listener.BlockedPotionsListener) ChestProtectionListener(com.sk89q.worldguard.bukkit.listener.ChestProtectionListener) RegionFlagsListener(com.sk89q.worldguard.bukkit.listener.RegionFlagsListener) BuildPermissionListener(com.sk89q.worldguard.bukkit.listener.BuildPermissionListener) Flag(com.sk89q.worldguard.protection.flags.Flag) WorldRulesListener(com.sk89q.worldguard.bukkit.listener.WorldRulesListener) SimpleInjector(com.sk89q.minecraft.util.commands.SimpleInjector) WorldGuardHangingListener(com.sk89q.worldguard.bukkit.listener.WorldGuardHangingListener) WorldGuardBlockListener(com.sk89q.worldguard.bukkit.listener.WorldGuardBlockListener) WorldGuardPlayerListener(com.sk89q.worldguard.bukkit.listener.WorldGuardPlayerListener) WorldGuardCommandBookListener(com.sk89q.worldguard.bukkit.listener.WorldGuardCommandBookListener) WorldGuardVehicleListener(com.sk89q.worldguard.bukkit.listener.WorldGuardVehicleListener) WorldGuardServerListener(com.sk89q.worldguard.bukkit.listener.WorldGuardServerListener) InvincibilityListener(com.sk89q.worldguard.bukkit.listener.InvincibilityListener)

Example 2 with WorldGuard

use of com.sk89q.worldguard.WorldGuard in project SilkSpawners by timbru31.

the class SilkUtil method canBuildHere.

/**
 * Checks if a player can build here (WorldGuard).
 *
 * @param player the player
 * @param location the location to check
 * @return the result, true or false
 */
public boolean canBuildHere(final Player player, final Location location) {
    if (wg == null) {
        return true;
    }
    try {
        final WorldGuard instance = WorldGuard.getInstance();
        final RegionContainer regionContainer = instance.getPlatform().getRegionContainer();
        final RegionQuery query = regionContainer.createQuery();
        return query.testBuild(BukkitAdapter.adapt(location), wg.wrapPlayer(player), Flags.BUILD);
    } catch (@SuppressWarnings("unused") Exception | NoClassDefFoundError e) {
        try {
            return (boolean) wg.getClass().getDeclaredMethod("canBuild", Player.class, Location.class).invoke(wg, player, location);
        } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e1) {
            e1.printStackTrace();
        }
        return false;
    }
}
Also used : Player(org.bukkit.entity.Player) RegionContainer(com.sk89q.worldguard.protection.regions.RegionContainer) RegionQuery(com.sk89q.worldguard.protection.regions.RegionQuery) InvocationTargetException(java.lang.reflect.InvocationTargetException) WorldGuard(com.sk89q.worldguard.WorldGuard) Location(org.bukkit.Location)

Aggregations

WorldGuard (com.sk89q.worldguard.WorldGuard)2 Player (org.bukkit.entity.Player)2 CommandsManagerRegistration (com.sk89q.bukkit.util.CommandsManagerRegistration)1 SimpleInjector (com.sk89q.minecraft.util.commands.SimpleInjector)1 LocalPlayer (com.sk89q.worldguard.LocalPlayer)1 ProcessPlayerEvent (com.sk89q.worldguard.bukkit.event.player.ProcessPlayerEvent)1 BlacklistListener (com.sk89q.worldguard.bukkit.listener.BlacklistListener)1 BlockedPotionsListener (com.sk89q.worldguard.bukkit.listener.BlockedPotionsListener)1 BuildPermissionListener (com.sk89q.worldguard.bukkit.listener.BuildPermissionListener)1 ChestProtectionListener (com.sk89q.worldguard.bukkit.listener.ChestProtectionListener)1 DebuggingListener (com.sk89q.worldguard.bukkit.listener.DebuggingListener)1 EventAbstractionListener (com.sk89q.worldguard.bukkit.listener.EventAbstractionListener)1 InvincibilityListener (com.sk89q.worldguard.bukkit.listener.InvincibilityListener)1 PlayerModesListener (com.sk89q.worldguard.bukkit.listener.PlayerModesListener)1 PlayerMoveListener (com.sk89q.worldguard.bukkit.listener.PlayerMoveListener)1 RegionFlagsListener (com.sk89q.worldguard.bukkit.listener.RegionFlagsListener)1 RegionProtectionListener (com.sk89q.worldguard.bukkit.listener.RegionProtectionListener)1 WorldGuardBlockListener (com.sk89q.worldguard.bukkit.listener.WorldGuardBlockListener)1 WorldGuardCommandBookListener (com.sk89q.worldguard.bukkit.listener.WorldGuardCommandBookListener)1 WorldGuardEntityListener (com.sk89q.worldguard.bukkit.listener.WorldGuardEntityListener)1