Adjust mask managers

- Add list of "exclusive" managers to config to aid users in having some sort of prioritisation.
 - Fixes #960 if PlotSquared is added to exclusive managers, otherwise, there's no particularly sane way of adding prioritisation without requiring a treemap be added to YAML config, or for us to decide upon it ourselves
Dieser Commit ist enthalten in:
dordsor21 2021-09-18 03:19:27 +01:00
Ursprung fbbb4ed8fa
Commit bd95d5a86d
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 1E53E88969FFCF0B
7 geänderte Dateien mit 52 neuen und 36 gelöschten Zeilen

Datei anzeigen

@ -304,10 +304,10 @@ public class FaweBukkit implements IFawe, Listener {
return; return;
} }
if (plotSquared.getClass().getPackage().toString().contains("intellectualsites")) { if (plotSquared.getClass().getPackage().toString().contains("intellectualsites")) {
WEManager.IMP.managers.add(new com.fastasyncworldedit.bukkit.regions.plotsquaredv4.PlotSquaredFeature()); WEManager.IMP.addManager(new com.fastasyncworldedit.bukkit.regions.plotsquaredv4.PlotSquaredFeature());
LOGGER.info("Plugin 'PlotSquared' found. Using it now."); LOGGER.info("Plugin 'PlotSquared' found. Using it now.");
} else if (PlotSquared.get().getVersion().version[0] == 6) { } else if (PlotSquared.get().getVersion().version[0] == 6) {
WEManager.IMP.managers.add(new com.fastasyncworldedit.bukkit.regions.plotsquared.PlotSquaredFeature()); WEManager.IMP.addManager(new com.fastasyncworldedit.bukkit.regions.plotsquared.PlotSquaredFeature());
LOGGER.info("Plugin 'PlotSquared' found. Using it now."); LOGGER.info("Plugin 'PlotSquared' found. Using it now.");
} else { } else {
LOGGER.error("Incompatible version of PlotSquared found. Please use PlotSquared v6."); LOGGER.error("Incompatible version of PlotSquared found. Please use PlotSquared v6.");

Datei anzeigen

@ -124,20 +124,12 @@ public class WorldGuardFeature extends BukkitMaskManager implements Listener {
final BlockVector3 pos1; final BlockVector3 pos1;
final BlockVector3 pos2; final BlockVector3 pos2;
if (myregion.getId().equals("__global__")) { if (myregion.getId().equals("__global__")) {
pos1 = BlockVector3.at(Integer.MIN_VALUE, 0, Integer.MIN_VALUE); pos1 = BlockVector3.at(Integer.MIN_VALUE, wePlayer.getWorld().getMinY(), Integer.MIN_VALUE);
pos2 = BlockVector3.at(Integer.MAX_VALUE, 255, Integer.MAX_VALUE); pos2 = BlockVector3.at(Integer.MAX_VALUE, wePlayer.getWorld().getMaxY(), Integer.MAX_VALUE);
} else { } else {
if (myregion instanceof ProtectedCuboidRegion) { if (myregion instanceof ProtectedCuboidRegion) {
pos1 = BlockVector3.at( pos1 = myregion.getMinimumPoint();
myregion.getMinimumPoint().getBlockX(), pos2 = myregion.getMaximumPoint();
myregion.getMinimumPoint().getBlockY(),
myregion.getMinimumPoint().getBlockZ()
);
pos2 = BlockVector3.at(
myregion.getMaximumPoint().getBlockX(),
myregion.getMaximumPoint().getBlockY(),
myregion.getMaximumPoint().getBlockZ()
);
} else { } else {
return new FaweMask(adapt(myregion)) { return new FaweMask(adapt(myregion)) {
@Override @Override

Datei anzeigen

@ -125,7 +125,7 @@ public class Fawe {
// Delayed worldedit setup // Delayed worldedit setup
TaskManager.IMP.later(() -> { TaskManager.IMP.later(() -> {
try { try {
WEManager.IMP.managers.addAll(Fawe.this.implementation.getMaskManagers()); WEManager.IMP.addManagers(Fawe.this.implementation.getMaskManagers());
} catch (Throwable ignored) { } catch (Throwable ignored) {
} }
}, 0); }, 0);

Datei anzeigen

@ -139,7 +139,7 @@ public class FaweAPI {
* @return Set of FaweMaskManager * @return Set of FaweMaskManager
*/ */
public static Set<FaweMaskManager> getMaskManagers() { public static Set<FaweMaskManager> getMaskManagers() {
return new HashSet<>(WEManager.IMP.managers); return new HashSet<>(WEManager.IMP.getManagers());
} }
/** /**
@ -176,7 +176,7 @@ public class FaweAPI {
} }
public static void addMaskManager(FaweMaskManager maskMan) { public static void addMaskManager(FaweMaskManager maskMan) {
WEManager.IMP.managers.add(maskMan); WEManager.IMP.addManager(maskMan);
} }
/** /**

Datei anzeigen

@ -115,6 +115,14 @@ public class Settings extends Config {
" - OWNER = Players who own the region" " - OWNER = Players who own the region"
}) })
public String MODE = "MEMBER"; public String MODE = "MEMBER";
@Comment({
"List of plugin mask managers that should be exclusive. Exclusive managers are not ",
"checked for edit restrictions if another manager already allowed an edit, and further ",
"managers are not checked if an exclusive manager allows an edit.",
" - May be useful to add PlotSquared if using both P2 and WorldGuard on a server",
" - Some custom-implementations in other plugins may override this setting"
})
public List<String> EXCLUSIVE_MANAGERS = new ArrayList<>(Collections.singleton(("ExamplePlugin")));
} }

Datei anzeigen

@ -8,20 +8,6 @@ import java.util.Locale;
public abstract class FaweMaskManager { public abstract class FaweMaskManager {
public enum MaskType {
OWNER,
MEMBER;
public static MaskType getDefaultMaskType() {
try {
return MaskType
.valueOf(Settings.IMP.REGION_RESTRICTIONS_OPTIONS.MODE.toUpperCase(Locale.ROOT));
} catch (Exception ignored) {
return MEMBER;
}
}
}
private final String key; private final String key;
public FaweMaskManager(final String plugin) { public FaweMaskManager(final String plugin) {
@ -54,7 +40,21 @@ public abstract class FaweMaskManager {
} }
public boolean isExclusive() { public boolean isExclusive() {
return false; return Settings.IMP.REGION_RESTRICTIONS_OPTIONS.EXCLUSIVE_MANAGERS.contains(this.key);
}
public enum MaskType {
OWNER,
MEMBER;
public static MaskType getDefaultMaskType() {
try {
return MaskType
.valueOf(Settings.IMP.REGION_RESTRICTIONS_OPTIONS.MODE.toUpperCase(Locale.ROOT));
} catch (Exception ignored) {
return MEMBER;
}
}
} }
} }

Datei anzeigen

@ -19,17 +19,34 @@ import com.sk89q.worldedit.util.formatting.text.TextComponent;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import java.util.ArrayDeque; import java.util.ArrayDeque;
import java.util.Collection;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.Set; import java.util.Set;
public class WEManager { public class WEManager {
private static final Logger LOGGER = LogManagerCompat.getLogger();
public static final WEManager IMP = new WEManager(); public static final WEManager IMP = new WEManager();
private static final Logger LOGGER = LogManagerCompat.getLogger();
private final ArrayDeque<FaweMaskManager> managers = new ArrayDeque<>();
public final ArrayDeque<FaweMaskManager> managers = new ArrayDeque<>(); public ArrayDeque<FaweMaskManager> getManagers() {
return managers;
}
public void addManager(FaweMaskManager manager) {
if (manager.isExclusive()) {
managers.addFirst(manager);
} else {
managers.add(manager);
}
}
public void addManagers(Collection<FaweMaskManager> managers) {
for (FaweMaskManager manager : managers) {
addManager(manager);
}
}
public void cancelEditSafe(AbstractDelegateExtent parent, FaweException reason) throws FaweException { public void cancelEditSafe(AbstractDelegateExtent parent, FaweException reason) throws FaweException {
LOGGER.warn("CancelEditSafe was hit. Please ignore this message."); LOGGER.warn("CancelEditSafe was hit. Please ignore this message.");
@ -102,7 +119,6 @@ public class WEManager {
masks.clear(); masks.clear();
} }
} }
Set<FaweMask> tmpMasks = new HashSet<>();
for (FaweMaskManager manager : managers) { for (FaweMaskManager manager : managers) {
if (player.hasPermission("fawe." + manager.getKey())) { if (player.hasPermission("fawe." + manager.getKey())) {
try { try {