feat: Add worldedit.schematic.list.other permission and functionality (#1507)

* Add worldedit.schematic.list.other permission and functionality

* Implement StringMan#containsUuid

* Javadocs

* chore: Add since annotation

Co-authored-by: NotMyFault <mc.cache@web.de>
This commit is contained in:
Owen1212055 2022-01-05 10:21:44 -05:00 committed by GitHub
parent f4658cc668
commit c27a34ce40
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 0 deletions

View File

@ -9,11 +9,14 @@ import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Set; import java.util.Set;
import java.util.function.Function; import java.util.function.Function;
import java.util.regex.Pattern;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.IntStream; import java.util.stream.IntStream;
public class StringMan { public class StringMan {
private static final Pattern UUID_PATTERN = Pattern.compile("[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}");
public static boolean containsAny(CharSequence sequence, String any) { public static boolean containsAny(CharSequence sequence, String any) {
return IntStream.range(0, sequence.length()) return IntStream.range(0, sequence.length())
.anyMatch(i -> any.indexOf(sequence.charAt(i)) != -1); .anyMatch(i -> any.indexOf(sequence.charAt(i)) != -1);
@ -542,4 +545,16 @@ public class StringMan {
return IntStream.range(0, n).mapToObj(i -> s).collect(Collectors.joining()); return IntStream.range(0, n).mapToObj(i -> s).collect(Collectors.joining());
} }
/**
* Returns if there is a valid uuid contained inside the
* provided String.
*
* @param str provided string
* @return true if an uuid was found, false if not
* @since 2.0.0
*/
public static boolean containsUuid(String str) {
return UUID_PATTERN.matcher(str).find();
}
} }

View File

@ -25,6 +25,7 @@ import com.fastasyncworldedit.core.configuration.Settings;
import com.fastasyncworldedit.core.function.QuadFunction; import com.fastasyncworldedit.core.function.QuadFunction;
import com.fastasyncworldedit.core.util.MainUtil; import com.fastasyncworldedit.core.util.MainUtil;
import com.fastasyncworldedit.core.util.MaskTraverser; import com.fastasyncworldedit.core.util.MaskTraverser;
import com.fastasyncworldedit.core.util.StringMan;
import com.fastasyncworldedit.core.util.TaskManager; import com.fastasyncworldedit.core.util.TaskManager;
import com.fastasyncworldedit.core.util.image.ImageUtil; import com.fastasyncworldedit.core.util.image.ImageUtil;
import com.fastasyncworldedit.core.util.task.DelegateConsumer; import com.fastasyncworldedit.core.util.task.DelegateConsumer;
@ -1033,7 +1034,27 @@ public class UtilityCommands {
if (playerFolder) { if (playerFolder) {
if (listMine) { if (listMine) {
File playerDir = MainUtil.resolveRelative(new File(dir, actor.getUniqueId() + dirFilter)); File playerDir = MainUtil.resolveRelative(new File(dir, actor.getUniqueId() + dirFilter));
//FAWE start - Schematic list other permission
if (!actor.hasPermission("worldedit.schematic.list.other") && StringMan.containsUuid(dirFilter)) {
return;
}
if (playerDir.exists()) { if (playerDir.exists()) {
if (!actor.hasPermission("worldedit.schematic.list.other")) {
forEachFile = new DelegateConsumer<>(forEachFile) {
@Override
public void accept(File f) {
try {
if (f.isDirectory() && !UUID.fromString(f.getName()).equals(actor.getUniqueId())) { // Ignore
// directories of other players
return;
}
} catch (IllegalArgumentException ignored) {
}
super.accept(f);
}
};
}
//FAWE end
allFiles(playerDir.listFiles(), false, forEachFile); allFiles(playerDir.listFiles(), false, forEachFile);
} }
} }