Search in sources :

Example 1 with Handler

use of com.sk89q.worldguard.session.handler.Handler in project WorldGuard by EngineHub.

the class Session method initialize.

/**
 * Initialize the session.
 *
 * @param player The player
 */
public void initialize(LocalPlayer player) {
    RegionQuery query = WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery();
    Location location = player.getLocation();
    ApplicableRegionSet set = query.getApplicableRegions(location);
    lastValid = location;
    lastRegionSet = set.getRegions();
    ConfigurationManager cfg = WorldGuard.getInstance().getPlatform().getGlobalStateManager();
    disableBypass = cfg.disableDefaultBypass;
    if (cfg.announceBypassStatus && player.hasPermission("worldguard.region.toggle-bypass")) {
        player.printInfo(TextComponent.of("You are " + (disableBypass ? "not" : "") + " bypassing region protection. " + "You can toggle this with /rg bypass", TextColor.DARK_PURPLE));
    }
    for (Handler handler : handlers.values()) {
        handler.initialize(player, location, set);
    }
}
Also used : RegionQuery(com.sk89q.worldguard.protection.regions.RegionQuery) Handler(com.sk89q.worldguard.session.handler.Handler) ConfigurationManager(com.sk89q.worldguard.config.ConfigurationManager) Location(com.sk89q.worldedit.util.Location) ApplicableRegionSet(com.sk89q.worldguard.protection.ApplicableRegionSet)

Example 2 with Handler

use of com.sk89q.worldguard.session.handler.Handler in project WorldGuard by EngineHub.

the class Session method tick.

/**
 * Tick the session.
 *
 * @param player The player
 */
public void tick(LocalPlayer player) {
    RegionQuery query = WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery();
    Location location = player.getLocation();
    ApplicableRegionSet set = query.getApplicableRegions(location);
    for (Handler handler : handlers.values()) {
        handler.tick(player, set);
    }
}
Also used : RegionQuery(com.sk89q.worldguard.protection.regions.RegionQuery) Handler(com.sk89q.worldguard.session.handler.Handler) Location(com.sk89q.worldedit.util.Location) ApplicableRegionSet(com.sk89q.worldguard.protection.ApplicableRegionSet)

Example 3 with Handler

use of com.sk89q.worldguard.session.handler.Handler in project WorldGuard by EngineHub.

the class Session method testMoveTo.

/**
 * Test movement to the given location.
 *
 * <p>If a non-null {@link Location} is returned, the player should be
 * at that location instead of where the player has tried to move to.</p>
 *
 * <p>If the {@code moveType} is cancellable
 * ({@link MoveType#isCancellable()}, then the last valid location will
 * be set to the given one.</p>
 *
 * @param player The player
 * @param to The new location
 * @param moveType The type of move
 * @param forced Whether to force a check
 * @return The overridden location, if the location is being overridden
 */
@Nullable
public Location testMoveTo(LocalPlayer player, Location to, MoveType moveType, boolean forced) {
    RegionQuery query = WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery();
    if (!forced && needRefresh.getAndSet(false)) {
        forced = true;
    }
    if (forced || Locations.isDifferentBlock(lastValid, to)) {
        ApplicableRegionSet toSet = query.getApplicableRegions(to);
        for (Handler handler : handlers.values()) {
            if (!handler.testMoveTo(player, lastValid, to, toSet, moveType) && moveType.isCancellable()) {
                return lastValid;
            }
        }
        Set<ProtectedRegion> entered = Sets.difference(toSet.getRegions(), lastRegionSet);
        Set<ProtectedRegion> exited = Sets.difference(lastRegionSet, toSet.getRegions());
        for (Handler handler : handlers.values()) {
            if (!handler.onCrossBoundary(player, lastValid, to, toSet, entered, exited, moveType) && moveType.isCancellable()) {
                return lastValid;
            }
        }
        lastValid = to;
        lastRegionSet = toSet.getRegions();
    }
    return null;
}
Also used : RegionQuery(com.sk89q.worldguard.protection.regions.RegionQuery) ProtectedRegion(com.sk89q.worldguard.protection.regions.ProtectedRegion) Handler(com.sk89q.worldguard.session.handler.Handler) ApplicableRegionSet(com.sk89q.worldguard.protection.ApplicableRegionSet) Nullable(javax.annotation.Nullable)

Aggregations

ApplicableRegionSet (com.sk89q.worldguard.protection.ApplicableRegionSet)3 RegionQuery (com.sk89q.worldguard.protection.regions.RegionQuery)3 Handler (com.sk89q.worldguard.session.handler.Handler)3 Location (com.sk89q.worldedit.util.Location)2 ConfigurationManager (com.sk89q.worldguard.config.ConfigurationManager)1 ProtectedRegion (com.sk89q.worldguard.protection.regions.ProtectedRegion)1 Nullable (javax.annotation.Nullable)1