use of com.fastasyncworldedit.core.regions.FaweMaskManager in project FastAsyncWorldEdit by IntellectualSites.
the class FaweBukkit method getMaskManagers.
/**
* A mask manager handles region restrictions e.g., PlotSquared plots / WorldGuard regions
*/
@Override
public Collection<FaweMaskManager> getMaskManagers() {
final Plugin worldguardPlugin = Bukkit.getServer().getPluginManager().getPlugin("WorldGuard");
final ArrayList<FaweMaskManager> managers = new ArrayList<>();
if (worldguardPlugin != null && worldguardPlugin.isEnabled()) {
try {
managers.add(new WorldGuardFeature(worldguardPlugin));
LOGGER.info("Attempting to use plugin 'WorldGuard'");
} catch (Throwable ignored) {
}
}
final Plugin townyPlugin = Bukkit.getServer().getPluginManager().getPlugin("Towny");
if (townyPlugin != null && townyPlugin.isEnabled()) {
try {
managers.add(new TownyFeature(townyPlugin));
LOGGER.info("Attempting to use plugin 'Towny'");
} catch (Throwable ignored) {
}
}
final Plugin residencePlugin = Bukkit.getServer().getPluginManager().getPlugin("Residence");
if (residencePlugin != null && residencePlugin.isEnabled()) {
try {
managers.add(new ResidenceFeature(residencePlugin, this));
LOGGER.info("Attempting to use plugin 'Residence'");
} catch (Throwable ignored) {
}
}
final Plugin griefpreventionPlugin = Bukkit.getServer().getPluginManager().getPlugin("GriefPrevention");
if (griefpreventionPlugin != null && griefpreventionPlugin.isEnabled()) {
try {
managers.add(new GriefPreventionFeature(griefpreventionPlugin));
LOGGER.info("Attempting to use plugin 'GriefPrevention'");
} catch (Throwable ignored) {
}
}
final Plugin griefdefenderPlugin = Bukkit.getServer().getPluginManager().getPlugin("GriefDefender");
if (griefdefenderPlugin != null && griefdefenderPlugin.isEnabled()) {
try {
managers.add(new GriefDefenderFeature(griefdefenderPlugin));
LOGGER.info("Attempting to use plugin 'GriefDefender'");
} catch (Throwable ignored) {
}
}
return managers;
}
use of com.fastasyncworldedit.core.regions.FaweMaskManager in project FastAsyncWorldEdit by IntellectualSites.
the class WEManager method getMask.
/**
* Get a player's mask.
*
* @param player Player to get mask of
* @param type Mask type; whether to check if the player is an owner of a member of the regions
* @param isWhitelist If searching for whitelist or blacklist regions. True if whitelist
* @return array of allowed regions if whitelist, else of disallowed regions.
*/
public Region[] getMask(Player player, FaweMaskManager.MaskType type, final boolean isWhitelist) {
if (!Settings.settings().REGION_RESTRICTIONS || player.hasPermission("fawe.bypass") || player.hasPermission("fawe.bypass.regions")) {
return new Region[] { RegionWrapper.GLOBAL() };
}
Location loc = player.getLocation();
String world = player.getWorld().getName();
if (!world.equals(player.getMeta("lastMaskWorld"))) {
player.deleteMeta("lastMaskWorld");
player.deleteMeta("lastMask");
}
player.setMeta("lastMaskWorld", world);
Set<FaweMask> masks = player.getMeta("lastMask");
Set<Region> backupRegions = new HashSet<>();
Set<Region> regions = new HashSet<>();
if (masks == null || !isWhitelist) {
masks = new HashSet<>();
} else {
synchronized (masks) {
boolean removed = false;
if (!masks.isEmpty()) {
Iterator<FaweMask> iterator = masks.iterator();
while (iterator.hasNext()) {
FaweMask mask = iterator.next();
if (mask.isValid(player, type)) {
Region region = mask.getRegion();
if (region.contains(loc.toBlockPoint())) {
regions.add(region);
} else {
removed = true;
backupRegions.add(region);
}
} else {
player.print(Caption.of("fawe.error.region-mask-invalid", mask.getClass().getSimpleName()));
removed = true;
iterator.remove();
}
}
}
if (!removed) {
return regions.toArray(new Region[0]);
}
masks.clear();
}
}
for (FaweMaskManager manager : managers) {
if (player.hasPermission("fawe." + manager.getKey())) {
try {
if (manager.isExclusive() && !masks.isEmpty()) {
continue;
}
final FaweMask mask = manager.getMask(player, FaweMaskManager.MaskType.getDefaultMaskType(), isWhitelist);
if (mask != null) {
regions.add(mask.getRegion());
masks.add(mask);
if (manager.isExclusive()) {
break;
}
}
} catch (Throwable e) {
e.printStackTrace();
}
} else {
player.printError(TextComponent.of("Missing permission " + "fawe." + manager.getKey()));
}
}
if (isWhitelist) {
regions.addAll(backupRegions);
if (!masks.isEmpty()) {
player.setMeta("lastMask", masks);
} else {
player.deleteMeta("lastMask");
}
}
return regions.toArray(new Region[0]);
}
Aggregations