mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2024-12-22 17:27:38 +00:00
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:
parent
f4658cc668
commit
c27a34ce40
@ -9,11 +9,14 @@ import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
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) {
|
||||
return IntStream.range(0, sequence.length())
|
||||
.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());
|
||||
}
|
||||
|
||||
/**
|
||||
* 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();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -25,6 +25,7 @@ import com.fastasyncworldedit.core.configuration.Settings;
|
||||
import com.fastasyncworldedit.core.function.QuadFunction;
|
||||
import com.fastasyncworldedit.core.util.MainUtil;
|
||||
import com.fastasyncworldedit.core.util.MaskTraverser;
|
||||
import com.fastasyncworldedit.core.util.StringMan;
|
||||
import com.fastasyncworldedit.core.util.TaskManager;
|
||||
import com.fastasyncworldedit.core.util.image.ImageUtil;
|
||||
import com.fastasyncworldedit.core.util.task.DelegateConsumer;
|
||||
@ -1033,7 +1034,27 @@ public class UtilityCommands {
|
||||
if (playerFolder) {
|
||||
if (listMine) {
|
||||
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 (!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);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user