13
0

Safe Schematic Node #105

Zusammengeführt
Chaoscaot hat 5 Commits von safe_node nach master 2022-01-29 15:08:33 +01:00 zusammengeführt
2 geänderte Dateien mit 92 neuen und 0 gelöschten Zeilen
Nur Änderungen aus Commit 9224d6f9a6 werden angezeigt - Alle Commits anzeigen

Datei anzeigen

@ -0,0 +1,87 @@
package de.steamwar.schematicsystem;
Chaoscaot markierte diese Unterhaltung als gelöst Veraltet
Veraltet
Review

©

©
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;
}
}
}

Datei anzeigen

@ -45,5 +45,10 @@
<scope>system</scope> <scope>system</scope>
<systemPath>${main.basedir}/lib/SpigotCore.jar</systemPath> <systemPath>${main.basedir}/lib/SpigotCore.jar</systemPath>
</dependency> </dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.22</version>
</dependency>
</dependencies> </dependencies>
</project> </project>