3
0
Mirror von https://github.com/IntellectualSites/FastAsyncWorldEdit.git synchronisiert 2024-09-16 04:51:22 +02:00

Don't allow edits on plots when owner is offline and player is only added (#1313)

Dieser Commit ist enthalten in:
dordsor21 2021-10-04 13:34:40 +01:00 committet von GitHub
Ursprung d44f297068
Commit 6895234815
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
11 geänderte Dateien mit 156 neuen und 55 gelöschten Zeilen

Datei anzeigen

@ -1,6 +1,7 @@
package com.fastasyncworldedit.bukkit.regions.plotsquared; package com.fastasyncworldedit.bukkit.regions.plotsquared;
import com.fastasyncworldedit.core.FaweAPI; import com.fastasyncworldedit.core.FaweAPI;
import com.fastasyncworldedit.core.configuration.Caption;
import com.fastasyncworldedit.core.regions.FaweMask; import com.fastasyncworldedit.core.regions.FaweMask;
import com.fastasyncworldedit.core.regions.FaweMaskManager; import com.fastasyncworldedit.core.regions.FaweMaskManager;
import com.fastasyncworldedit.core.regions.filter.RegionFilter; import com.fastasyncworldedit.core.regions.filter.RegionFilter;
@ -24,6 +25,7 @@ import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.regions.RegionIntersection; import com.sk89q.worldedit.regions.RegionIntersection;
import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.World;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.bukkit.Bukkit;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
@ -68,10 +70,57 @@ public class PlotSquaredFeature extends FaweMaskManager {
return false; return false;
} }
UUID uid = player.getUniqueId(); UUID uid = player.getUniqueId();
return !plot.getFlag(NoWorldeditFlag.class) && (plot.isOwner(uid) || type == MaskType.MEMBER && ( if (plot.getFlag(NoWorldeditFlag.class)) {
plot.getTrusted().contains(uid) || plot.getTrusted().contains(DBFunc.EVERYONE) player.print(Caption.of(
|| (plot.getMembers().contains(uid) || plot.getMembers().contains(DBFunc.EVERYONE)) && player "fawe.cancel.reason.no.region.reason",
.hasPermission("fawe.plotsquared.member")) || player.hasPermission("fawe.plotsquared.admin")); Caption.of("fawe.cancel.reason.no.region.plot.noworldeditflag")
));
return false;
}
if (plot.isOwner(uid) || player.hasPermission("fawe.plotsquared.admin")) {
return true;
}
if (type != MaskType.MEMBER) {
player.print(Caption.of(
"fawe.cancel.reason.no.region.reason",
Caption.of("fawe.cancel.reason.no.region.plot.owner.only")
));
return false;
}
if (plot.getTrusted().contains(uid) || plot.getTrusted().contains(DBFunc.EVERYONE)) {
return true;
}
if (plot.getMembers().contains(uid) || plot.getMembers().contains(DBFunc.EVERYONE)) {
if (!player.hasPermission("fawe.plotsquared.member")) {
player.print(Caption.of(
"fawe.cancel.reason.no.region.reason",
Caption.of("fawe.error.no-perm", "fawe.plotsquared.member")
));
return false;
}
if (!plot.getOwners().isEmpty() && plot.getOwners().stream().anyMatch(this::playerOnline)) {
return true;
} else {
player.print(Caption.of(
"fawe.cancel.reason.no.region.reason",
Caption.of("fawe.cancel.reason.no.region.plot.owner.offline")
));
return false;
}
}
player.print(Caption.of(
"fawe.cancel.reason.no.region.reason",
Caption.of("fawe.cancel.reason.no.region.not.added")
));
return false;
}
private boolean playerOnline(UUID uuid) {
if (uuid == null) {
return false;
}
org.bukkit.entity.Player player = Bukkit.getPlayer(uuid);
return player != null && player.isOnline();
} }
@Override @Override

Datei anzeigen

@ -1,6 +1,7 @@
package com.fastasyncworldedit.bukkit.regions.plotsquaredv4; package com.fastasyncworldedit.bukkit.regions.plotsquaredv4;
import com.fastasyncworldedit.core.FaweAPI; import com.fastasyncworldedit.core.FaweAPI;
import com.fastasyncworldedit.core.configuration.Caption;
import com.fastasyncworldedit.core.regions.FaweMask; import com.fastasyncworldedit.core.regions.FaweMask;
import com.fastasyncworldedit.core.regions.FaweMaskManager; import com.fastasyncworldedit.core.regions.FaweMaskManager;
import com.fastasyncworldedit.core.regions.RegionWrapper; import com.fastasyncworldedit.core.regions.RegionWrapper;
@ -25,6 +26,7 @@ import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.regions.RegionIntersection; import com.sk89q.worldedit.regions.RegionIntersection;
import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.World;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.bukkit.Bukkit;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
@ -96,12 +98,57 @@ public class PlotSquaredFeature extends FaweMaskManager {
return false; return false;
} }
UUID uid = player.getUniqueId(); UUID uid = player.getUniqueId();
return !Flags.NO_WORLDEDIT.isTrue(plot) && (plot.isOwner(uid) if (Flags.NO_WORLDEDIT.isTrue(plot)) {
|| type == MaskType.MEMBER && (plot.getTrusted().contains(uid) || plot.getTrusted() player.print(Caption.of(
.contains(DBFunc.EVERYONE) "fawe.cancel.reason.no.region.reason",
|| (plot.getMembers().contains(uid) || plot.getMembers().contains(DBFunc.EVERYONE)) Caption.of("fawe.cancel.reason.no.region.plot.noworldeditflag")
&& player.hasPermission("fawe.plotsquared.member")) || player ));
.hasPermission("fawe.plotsquared.admin")); return false;
}
if (plot.isOwner(uid) || player.hasPermission("fawe.plotsquared.admin")) {
return true;
}
if (type != MaskType.MEMBER) {
player.print(Caption.of(
"fawe.cancel.reason.no.region.reason",
Caption.of("fawe.cancel.reason.no.region.plot.owner.only")
));
return false;
}
if (plot.getTrusted().contains(uid) || plot.getTrusted().contains(DBFunc.EVERYONE)) {
return true;
}
if (plot.getMembers().contains(uid) || plot.getMembers().contains(DBFunc.EVERYONE)) {
if (!player.hasPermission("fawe.plotsquared.member")) {
player.print(Caption.of(
"fawe.cancel.reason.no.region.reason",
Caption.of("fawe.error.no-perm", "fawe.plotsquared.member")
));
return false;
}
if (!plot.getOwners().isEmpty() && plot.getOwners().stream().anyMatch(this::playerOnline)) {
return true;
} else {
player.print(Caption.of(
"fawe.cancel.reason.no.region.reason",
Caption.of("fawe.cancel.reason.no.region.plot.owner.offline")
));
return false;
}
}
player.print(Caption.of(
"fawe.cancel.reason.no.region.reason",
Caption.of("fawe.cancel.reason.no.region.not.added")
));
return false;
}
private boolean playerOnline(UUID uuid) {
if (uuid == null) {
return false;
}
org.bukkit.entity.Player player = Bukkit.getPlayer(uuid);
return player != null && player.isOnline();
} }
@Override @Override

Datei anzeigen

@ -134,52 +134,52 @@ public enum FaweCache implements Trimable {
*/ */
public static final FaweBlockBagException BLOCK_BAG = new FaweBlockBagException(); public static final FaweBlockBagException BLOCK_BAG = new FaweBlockBagException();
public static final FaweException MANUAL = new FaweException( public static final FaweException MANUAL = new FaweException(
Caption.of("fawe.cancel.worldedit.cancel.reason.manual"), Caption.of("fawe.cancel.reason.manual"),
Type.MANUAL Type.MANUAL
); );
public static final FaweException NO_REGION = new FaweException( public static final FaweException NO_REGION = new FaweException(
Caption.of("fawe.cancel.worldedit.cancel.reason.no.region"), Caption.of("fawe.cancel.reason.no.region"),
Type.NO_REGION Type.NO_REGION
); );
public static final FaweException OUTSIDE_REGION = new FaweException( public static final FaweException OUTSIDE_REGION = new FaweException(
Caption.of( Caption.of(
"fawe.cancel.worldedit.cancel.reason.outside.region"), "fawe.cancel.reason.outside.region"),
Type.OUTSIDE_REGION Type.OUTSIDE_REGION
); );
public static final FaweException MAX_CHECKS = new FaweException( public static final FaweException MAX_CHECKS = new FaweException(
Caption.of("fawe.cancel.worldedit.cancel.reason.max" + ".checks"), Caption.of("fawe.cancel.reason.max" + ".checks"),
Type.MAX_CHECKS Type.MAX_CHECKS
); );
public static final FaweException MAX_CHANGES = new FaweException( public static final FaweException MAX_CHANGES = new FaweException(
Caption.of("fawe.cancel.worldedit.cancel.reason.max" + ".changes"), Caption.of("fawe.cancel.reason.max" + ".changes"),
Type.MAX_CHANGES Type.MAX_CHANGES
); );
public static final FaweException LOW_MEMORY = new FaweException( public static final FaweException LOW_MEMORY = new FaweException(
Caption.of("fawe.cancel.worldedit.cancel.reason.low" + ".memory"), Caption.of("fawe.cancel.reason.low" + ".memory"),
Type.LOW_MEMORY Type.LOW_MEMORY
); );
public static final FaweException MAX_ENTITIES = new FaweException( public static final FaweException MAX_ENTITIES = new FaweException(
Caption.of( Caption.of(
"fawe.cancel.worldedit.cancel.reason.max.entities"), "fawe.cancel.reason.max.entities"),
Type.MAX_ENTITIES Type.MAX_ENTITIES
); );
public static final FaweException MAX_TILES = new FaweException(Caption.of( public static final FaweException MAX_TILES = new FaweException(Caption.of(
"fawe.cancel.worldedit.cancel.reason.max.tiles", "fawe.cancel.reason.max.tiles",
Type.MAX_TILES Type.MAX_TILES
)); ));
public static final FaweException MAX_ITERATIONS = new FaweException( public static final FaweException MAX_ITERATIONS = new FaweException(
Caption.of( Caption.of(
"fawe.cancel.worldedit.cancel.reason.max.iterations"), "fawe.cancel.reason.max.iterations"),
Type.MAX_ITERATIONS Type.MAX_ITERATIONS
); );
public static final FaweException PLAYER_ONLY = new FaweException( public static final FaweException PLAYER_ONLY = new FaweException(
Caption.of( Caption.of(
"fawe.cancel.worldedit.cancel.reason.player-only"), "fawe.cancel.reason.player-only"),
Type.PLAYER_ONLY Type.PLAYER_ONLY
); );
public static final FaweException ACTOR_REQUIRED = new FaweException( public static final FaweException ACTOR_REQUIRED = new FaweException(
Caption.of( Caption.of(
"fawe.cancel.worldedit.cancel.reason.actor-required"), "fawe.cancel.reason.actor-required"),
Type.ACTOR_REQUIRED Type.ACTOR_REQUIRED
); );

Datei anzeigen

@ -23,8 +23,8 @@ public class MemoryCheckingExtent extends PassthroughExtent {
if (MemUtil.isMemoryLimited()) { if (MemUtil.isMemoryLimited()) {
if (this.actor != null) { if (this.actor != null) {
actor.print(Caption.of( actor.print(Caption.of(
"fawe.cancel.worldedit.cancel.reason", "fawe.cancel.reason",
Caption.of("fawe.cancel.worldedit.cancel.reason.low.memory") Caption.of("fawe.cancel.reason.low.memory")
)); ));
if (Permission.hasPermission(this.actor, "worldedit.fast")) { if (Permission.hasPermission(this.actor, "worldedit.fast")) {
this.actor.print(Caption.of("fawe.info.worldedit.oom.admin")); this.actor.print(Caption.of("fawe.info.worldedit.oom.admin"));

Datei anzeigen

@ -1337,9 +1337,9 @@ public class EditSession extends PassthroughExtent implements AutoCloseable {
if (used.MAX_CHANGES > 0 || used.MAX_ENTITIES > 0) { if (used.MAX_CHANGES > 0 || used.MAX_ENTITIES > 0) {
actor.print(Caption.of("fawe.error.worldedit.some.fails", used.MAX_FAILS)); actor.print(Caption.of("fawe.error.worldedit.some.fails", used.MAX_FAILS));
} else if (new ExtentTraverser<>(getExtent()).findAndGet(FaweRegionExtent.class) != null) { } else if (new ExtentTraverser<>(getExtent()).findAndGet(FaweRegionExtent.class) != null) {
actor.print(Caption.of("fawe.cancel.worldedit.cancel.reason.outside.region")); actor.print(Caption.of("fawe.cancel.reason.outside.region"));
} else { } else {
actor.print(Caption.of("fawe.cancel.worldedit.cancel.reason.outside.level")); actor.print(Caption.of("fawe.cancel.reason.outside.level"));
} }
} }
if (wnaMode) { if (wnaMode) {

Datei anzeigen

@ -944,7 +944,7 @@ public class SchematicCommands {
} }
LOGGER.info(actor.getName() + " saved " + file.getCanonicalPath()); LOGGER.info(actor.getName() + " saved " + file.getCanonicalPath());
} else { } else {
actor.print(Caption.of("fawe.cancel.worldedit.cancel.reason.manual")); actor.print(Caption.of("fawe.cancel.reason.manual"));
} }
} }
//FAWE end //FAWE end

Datei anzeigen

@ -206,9 +206,9 @@ public class UtilityCommands {
desc = "Cancel your current command" desc = "Cancel your current command"
) )
@CommandPermissions(value = "fawe.cancel", queued = false) @CommandPermissions(value = "fawe.cancel", queued = false)
public void cancel(Actor actor) { public void cancel(Player player) {
int cancelled = actor.cancel(false); int cancelled = player.cancel(false);
actor.print(Caption.of("fawe.cancel.worldedit.cancel.count", cancelled)); player.print(Caption.of("fawe.cancel.count", cancelled));
} }
@Command( @Command(

Datei anzeigen

@ -61,7 +61,7 @@ public @interface Confirm {
* (long) value; * (long) value;
long max = 2 << 18; long max = 2 << 18;
if (max != -1 && area > max) { if (max != -1 && area > max) {
actor.print(Caption.of("fawe.cancel.worldedit.cancel.reason.confirm.region", actor.print(Caption.of("fawe.cancel.reason.confirm.region",
pos1, pos2, getArgs(context), region.getHeight() * area pos1, pos2, getArgs(context), region.getHeight() * area
)); ));
return confirm(actor, context); return confirm(actor, context);
@ -77,7 +77,7 @@ public @interface Confirm {
} }
int max = WorldEdit.getInstance().getConfiguration().maxRadius; int max = WorldEdit.getInstance().getConfiguration().maxRadius;
if (max != -1 && value > max) { if (max != -1 && value > max) {
actor.print(Caption.of("fawe.cancel.worldedit.cancel.reason.confirm.radius", actor.print(Caption.of("fawe.cancel.reason.confirm.radius",
value, max, getArgs(context) value, max, getArgs(context)
)); ));
return confirm(actor, context); return confirm(actor, context);
@ -93,7 +93,7 @@ public @interface Confirm {
} }
int max = 50; //TODO configurable, get Key.of(Method.class) @Limit int max = 50; //TODO configurable, get Key.of(Method.class) @Limit
if (max != -1 && value > max) { if (max != -1 && value > max) {
actor.print(Caption.of("fawe.cancel.worldedit.cancel.reason.confirm.limit", actor.print(Caption.of("fawe.cancel.reason.confirm.limit",
value, max, getArgs(context) value, max, getArgs(context)
)); ));
return confirm(actor, context); return confirm(actor, context);
@ -107,7 +107,7 @@ public @interface Confirm {
if (checkExisting(context)) { if (checkExisting(context)) {
return true; return true;
} }
actor.print(Caption.of("fawe.cancel.worldedit.cancel.reason.confirm", Processor.getArgs(context))); actor.print(Caption.of("fawe.cancel.reason.confirm", Processor.getArgs(context)));
return confirm(actor, context); return confirm(actor, context);
} }
}; };

Datei anzeigen

@ -763,7 +763,7 @@ public final class PlatformCommandManager {
actor.print(e.getRichMessage()); actor.print(e.getRichMessage());
} }
} catch (FaweException e) { } catch (FaweException e) {
actor.print(Caption.of("fawe.cancel.worldedit.cancel.reason", e.getComponent())); actor.print(Caption.of("fawe.cancel.reason", e.getComponent()));
} catch (UsageException e) { } catch (UsageException e) {
ImmutableList<Command> cmd = e.getCommands(); ImmutableList<Command> cmd = e.getCommands();
if (!cmd.isEmpty()) { if (!cmd.isEmpty()) {
@ -777,7 +777,7 @@ public final class PlatformCommandManager {
handleUnknownException(actor, e.getCause()); handleUnknownException(actor, e.getCause());
} catch (CommandException e) { } catch (CommandException e) {
if (e.getCause() instanceof FaweException) { if (e.getCause() instanceof FaweException) {
actor.print(Caption.of("fawe.cancel.worldedit.cancel.reason", ((FaweException) e.getCause()).getComponent())); actor.print(Caption.of("fawe.cancel.reason", ((FaweException) e.getCause()).getComponent()));
} else { } else {
Component msg = e.getRichMessage(); Component msg = e.getRichMessage();
if (msg == TextComponent.empty()) { if (msg == TextComponent.empty()) {

Datei anzeigen

@ -445,7 +445,7 @@ public class PlatformManager {
public void handleThrowable(Throwable e, Actor actor) { public void handleThrowable(Throwable e, Actor actor) {
FaweException faweException = FaweException.get(e); FaweException faweException = FaweException.get(e);
if (faweException != null) { if (faweException != null) {
actor.print(Caption.of("fawe.cancel.worldedit.cancel.reason", faweException.getComponent())); actor.print(Caption.of("fawe.cancel.reason", faweException.getComponent()));
} else { } else {
actor.print(Caption.of("worldedit.command.error.report")); actor.print(Caption.of("worldedit.command.error.report"));
actor.print(Caption.of(e.getClass().getName(), TextComponent.of(": "), TextComponent.of(e.getMessage()))); actor.print(Caption.of(e.getClass().getName(), TextComponent.of(": "), TextComponent.of(e.getMessage())));
@ -499,7 +499,7 @@ public class PlatformManager {
} catch (Throwable e) { } catch (Throwable e) {
FaweException faweException = FaweException.get(e); FaweException faweException = FaweException.get(e);
if (faweException != null) { if (faweException != null) {
player.print(Caption.of("fawe.cancel.worldedit.cancel.reason", faweException.getComponent())); player.print(Caption.of("fawe.cancel.reason", faweException.getComponent()));
} else { } else {
player.print(Caption.of("worldedit.command.error.report")); player.print(Caption.of("worldedit.command.error.report"));
player.print(Caption.of(e.getClass().getName() + ": " + e.getMessage())); player.print(Caption.of(e.getClass().getName() + ": " + e.getMessage()));

Datei anzeigen

@ -149,24 +149,29 @@
"fawe.error.clipboard.load.failure": "Could not load clipboard. Possible that the clipboard is still being written to from another server?!", "fawe.error.clipboard.load.failure": "Could not load clipboard. Possible that the clipboard is still being written to from another server?!",
"fawe.error.clipboard.on.disk.version.mismatch": "Clipboard version mismatch. Please delete your clipboards folder and restart the server.", "fawe.error.clipboard.on.disk.version.mismatch": "Clipboard version mismatch. Please delete your clipboards folder and restart the server.",
"fawe.cancel.worldedit.cancel.count": "Cancelled {0} edits.", "fawe.cancel.count": "Cancelled {0} edits.",
"fawe.cancel.worldedit.cancel.reason.confirm": "Use //confirm to execute {0}", "fawe.cancel.reason.confirm": "Use //confirm to execute {0}",
"fawe.cancel.worldedit.cancel.reason.confirm.region": "Your selection is large ({0} -> {1}, containing {3} blocks). Use //confirm to execute {2}", "fawe.cancel.reason.confirm.region": "Your selection is large ({0} -> {1}, containing {3} blocks). Use //confirm to execute {2}",
"fawe.cancel.worldedit.cancel.reason.confirm.radius": "Your radius is large ({0} > {1}). Use //confirm to execute {2}", "fawe.cancel.reason.confirm.radius": "Your radius is large ({0} > {1}). Use //confirm to execute {2}",
"fawe.cancel.worldedit.cancel.reason.confirm.limit": "You're exceeding your limit for this action ({0} > {1}). Use //confirm to execute {2}", "fawe.cancel.reason.confirm.limit": "You're exceeding your limit for this action ({0} > {1}). Use //confirm to execute {2}",
"fawe.cancel.worldedit.cancel.reason": "Your WorldEdit action was cancelled: {0}.", "fawe.cancel.reason": "Your WorldEdit action was cancelled: {0}.",
"fawe.cancel.worldedit.cancel.reason.manual": "Manual cancellation", "fawe.cancel.reason.manual": "Manual cancellation",
"fawe.cancel.worldedit.cancel.reason.low.memory": "Low memory", "fawe.cancel.reason.low.memory": "Low memory",
"fawe.cancel.worldedit.cancel.reason.max.changes": "Too many blocks changed", "fawe.cancel.reason.max.changes": "Too many blocks changed",
"fawe.cancel.worldedit.cancel.reason.max.checks": "Too many block checks", "fawe.cancel.reason.max.checks": "Too many block checks",
"fawe.cancel.worldedit.cancel.reason.max.tiles": "Too many block entities", "fawe.cancel.reason.max.tiles": "Too many block entities",
"fawe.cancel.worldedit.cancel.reason.max.entities": "Too many entities", "fawe.cancel.reason.max.entities": "Too many entities",
"fawe.cancel.worldedit.cancel.reason.max.iterations": "Max iterations", "fawe.cancel.reason.max.iterations": "Max iterations",
"fawe.cancel.worldedit.cancel.reason.outside.level": "Outside world", "fawe.cancel.reason.outside.level": "Outside world",
"fawe.cancel.worldedit.cancel.reason.outside.region": "Outside allowed region (bypass with /wea, or disable `region-restrictions` in config.yml)", "fawe.cancel.reason.outside.region": "Outside allowed region (bypass with /wea, or disable `region-restrictions` in config.yml)",
"fawe.cancel.worldedit.cancel.reason.no.region": "No allowed region (bypass with /wea, or disable `region-restrictions` in config.yml)", "fawe.cancel.reason.no.region": "No allowed region (bypass with /wea, or disable `region-restrictions` in config.yml)",
"fawe.cancel.worldedit.cancel.reason.player-only": "This operation requires a player, and cannot be executed from console, or without an actor.", "fawe.cancel.reason.no.region.reason": "No allowed region: {0}",
"fawe.cancel.worldedit.cancel.reason.actor-required": "This operation requires an actor.", "fawe.cancel.reason.no.region.plot.noworldeditflag": "Plot flag NoWorldeditFlag set",
"fawe.cancel.reason.no.region.plot.owner.offline": "Region owner offline",
"fawe.cancel.reason.no.region.plot.owner.only": "Only region owners may edit them",
"fawe.cancel.reason.no.region.not.added": "Not added to region",
"fawe.cancel.reason.player-only": "This operation requires a player, and cannot be executed from console, or without an actor.",
"fawe.cancel.reason.actor-required": "This operation requires an actor.",
"fawe.cancel.worldedit.failed.load.chunk": "Skipped loading chunk: {0};{1}. Try increasing chunk-wait.", "fawe.cancel.worldedit.failed.load.chunk": "Skipped loading chunk: {0};{1}. Try increasing chunk-wait.",
"fawe.navigation.no.block": "No block in sight! (or too far)", "fawe.navigation.no.block": "No block in sight! (or too far)",