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);
}
}
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);
}
}
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;
}
Aggregations