Dieser Commit ist enthalten in:
Ursprung
1b18fe5a28
Commit
9224d6f9a6
@ -0,0 +1,87 @@
|
||||
package de.steamwar.schematicsystem;
|
||||
|
||||
import de.steamwar.schematicsystem.commands.SchematicCommandUtils;
|
||||
import de.steamwar.sql.SchematicNode;
|
||||
import de.steamwar.sql.SteamwarUser;
|
||||
import lombok.NonNull;
|
||||
import org.bukkit.Material;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class SafeSchematicNode {
|
||||
|
||||
public static Result setParent(@NonNull SteamwarUser user, @NonNull SchematicNode node, SchematicNode newParent) {
|
||||
if(newParent == null) {
|
||||
if(SchematicNode.getSchematicsAccessibleByUser(user.getId(), 0)
|
||||
.stream().map(SchematicNode::getName).anyMatch(s -> s.equalsIgnoreCase(node.getName()))) {
|
||||
return Result.ALREADY_IN_DIRECTORY;
|
||||
}
|
||||
|
||||
node.setParent(0);
|
||||
} else {
|
||||
if(!newParent.isDir()) {
|
||||
return Result.NOT_A_DIR;
|
||||
}
|
||||
|
||||
if(SchematicNode.getSchematicsAccessibleByUser(user.getId(), newParent.getParent())
|
||||
.stream().map(SchematicNode::getName).anyMatch(s -> s.equalsIgnoreCase(node.getName()))) {
|
||||
return Result.ALREADY_IN_DIRECTORY;
|
||||
}
|
||||
|
||||
node.setParent(newParent.getId());
|
||||
}
|
||||
return Result.DONE;
|
||||
}
|
||||
|
||||
public static Result setName(@NonNull SteamwarUser user, @NonNull SchematicNode node, @NonNull String name) {
|
||||
if(invalidSchemName(name)) {
|
||||
return Result.INVALID_NAME;
|
||||
}
|
||||
|
||||
if(SchematicNode.getSchematicsAccessibleByUser(user.getId(), node.getParent()).stream().map(SchematicNode::getName).anyMatch(s -> s.equalsIgnoreCase(name))) {
|
||||
return Result.ALREADY_IN_DIRECTORY;
|
||||
}
|
||||
|
||||
node.setName(name);
|
||||
return Result.DONE;
|
||||
}
|
||||
|
||||
public static Result setItem(@NonNull SteamwarUser user, @NonNull SchematicNode node, @NonNull Material material) {
|
||||
|
||||
}
|
||||
|
||||
private static final List<String> FORBIDDEN_NAMES = Collections.unmodifiableList(Arrays.asList("public"));
|
||||
public static boolean invalidSchemName(String name) {
|
||||
if (name.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
if(name.length() > 64) {
|
||||
return true;
|
||||
}
|
||||
if (name.contains("/") ||
|
||||
name.contains("\\") ||
|
||||
name.contains("<") ||
|
||||
name.contains(">") ||
|
||||
name.contains("^") ||
|
||||
name.contains("°") ||
|
||||
name.contains("'") ||
|
||||
name.contains("\"") ||
|
||||
name.contains(" ")) {
|
||||
return true;
|
||||
}
|
||||
return FORBIDDEN_NAMES.contains(name.toLowerCase());
|
||||
}
|
||||
|
||||
public enum Result {
|
||||
DONE,
|
||||
NOT_A_DIR,
|
||||
ALREADY_IN_DIRECTORY,
|
||||
INVALID_NAME;
|
||||
|
||||
public boolean isSuccessful() {
|
||||
return this == DONE;
|
||||
}
|
||||
}
|
||||
}
|
5
pom.xml
5
pom.xml
@ -45,5 +45,10 @@
|
||||
<scope>system</scope>
|
||||
<systemPath>${main.basedir}/lib/SpigotCore.jar</systemPath>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.22</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
In neuem Issue referenzieren
Einen Benutzer sperren