mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-06-12 04:23:54 +00:00
feat: improve (region) fawe mask handling (#2312)
* feat: improve fawe mask handling - Actually cache masks, even if the player has left the region - Fix P2 isValid test for single plots - Fixes #1946 * Fix incorrect delegated method
This commit is contained in:
@ -17,10 +17,30 @@ public class FaweMask implements IDelegateRegion {
|
||||
return region;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if the mask is still valid
|
||||
*
|
||||
* @param player player to test
|
||||
* @param type type of mask
|
||||
* @return if still valid
|
||||
*/
|
||||
public boolean isValid(Player player, FaweMaskManager.MaskType type) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if the mask is still valid
|
||||
*
|
||||
* @param player player to test
|
||||
* @param type type of mask
|
||||
* @param notify if the player should be notified
|
||||
* @return if still valid
|
||||
* @since TODO
|
||||
*/
|
||||
public boolean isValid(Player player, FaweMaskManager.MaskType type, boolean notify) {
|
||||
return isValid(player, type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Region clone() {
|
||||
throw new UnsupportedOperationException("Clone not supported");
|
||||
|
@ -1,7 +1,6 @@
|
||||
package com.fastasyncworldedit.core.regions;
|
||||
|
||||
import com.fastasyncworldedit.core.configuration.Settings;
|
||||
import com.fastasyncworldedit.core.regions.filter.RegionFilter;
|
||||
import com.sk89q.worldedit.entity.Player;
|
||||
|
||||
import java.util.Locale;
|
||||
@ -28,6 +27,15 @@ public abstract class FaweMaskManager {
|
||||
*/
|
||||
public abstract FaweMask getMask(final Player player, MaskType type, boolean isWhitelist);
|
||||
|
||||
/**
|
||||
* Get a {@link FaweMask} for the given player and {@link MaskType}. If isWhitelist is false, will return a "blacklist" mask.
|
||||
*
|
||||
* @since TODO
|
||||
*/
|
||||
public FaweMask getMask(final Player player, MaskType type, boolean isWhitelist, boolean notify) {
|
||||
return getMask(player, type, isWhitelist);
|
||||
}
|
||||
|
||||
public boolean isExclusive() {
|
||||
return Settings.settings().REGION_RESTRICTIONS_OPTIONS.EXCLUSIVE_MANAGERS.contains(this.key);
|
||||
}
|
||||
|
@ -108,27 +108,22 @@ public class WEManager {
|
||||
}
|
||||
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;
|
||||
boolean inMask = false;
|
||||
if (!masks.isEmpty()) {
|
||||
Iterator<FaweMask> iterator = masks.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
FaweMask mask = iterator.next();
|
||||
if (mask.isValid(player, type)) {
|
||||
if (mask.isValid(player, type, false)) {
|
||||
Region region = mask.getRegion();
|
||||
if (region.contains(loc.toBlockPoint())) {
|
||||
regions.add(region);
|
||||
} else {
|
||||
removed = true;
|
||||
backupRegions.add(region);
|
||||
}
|
||||
inMask |= region.contains(loc.toBlockPoint());
|
||||
regions.add(region);
|
||||
} else {
|
||||
if (Settings.settings().ENABLED_COMPONENTS.DEBUG) {
|
||||
player.printDebug(Caption.of("fawe.error.region-mask-invalid", mask.getClass().getSimpleName()));
|
||||
@ -138,39 +133,44 @@ public class WEManager {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!removed) {
|
||||
if (!removed && inMask) {
|
||||
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;
|
||||
synchronized (masks) {
|
||||
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,
|
||||
masks.isEmpty()
|
||||
);
|
||||
if (mask != null) {
|
||||
regions.add(mask.getRegion());
|
||||
masks.add(mask);
|
||||
if (manager.isExclusive()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
} else {
|
||||
player.printError(TextComponent.of("Missing permission " + "fawe." + manager.getKey()));
|
||||
}
|
||||
} 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");
|
||||
if (isWhitelist) {
|
||||
if (!masks.isEmpty()) {
|
||||
player.setMeta("lastMask", masks);
|
||||
} else {
|
||||
player.deleteMeta("lastMask");
|
||||
}
|
||||
}
|
||||
}
|
||||
return regions.toArray(new Region[0]);
|
||||
|
Reference in New Issue
Block a user