Dieser Commit ist enthalten in:
Ursprung
9224d6f9a6
Commit
0591a1c5cc
@ -1,10 +1,10 @@
|
|||||||
package de.steamwar.schematicsystem;
|
package de.steamwar.schematicsystem;
|
||||||
|
|
||||||
import de.steamwar.schematicsystem.commands.SchematicCommandUtils;
|
|
||||||
import de.steamwar.sql.SchematicNode;
|
import de.steamwar.sql.SchematicNode;
|
||||||
import de.steamwar.sql.SteamwarUser;
|
import de.steamwar.sql.SteamwarUser;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@ -13,6 +13,9 @@ import java.util.List;
|
|||||||
public class SafeSchematicNode {
|
public class SafeSchematicNode {
|
||||||
|
|
||||||
public static Result setParent(@NonNull SteamwarUser user, @NonNull SchematicNode node, SchematicNode newParent) {
|
public static Result setParent(@NonNull SteamwarUser user, @NonNull SchematicNode node, SchematicNode newParent) {
|
||||||
|
if(user.getId() != node.getId()) {
|
||||||
|
return Result.NOT_OWNER;
|
||||||
|
}
|
||||||
if(newParent == null) {
|
if(newParent == null) {
|
||||||
if(SchematicNode.getSchematicsAccessibleByUser(user.getId(), 0)
|
if(SchematicNode.getSchematicsAccessibleByUser(user.getId(), 0)
|
||||||
.stream().map(SchematicNode::getName).anyMatch(s -> s.equalsIgnoreCase(node.getName()))) {
|
.stream().map(SchematicNode::getName).anyMatch(s -> s.equalsIgnoreCase(node.getName()))) {
|
||||||
@ -36,6 +39,10 @@ public class SafeSchematicNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Result setName(@NonNull SteamwarUser user, @NonNull SchematicNode node, @NonNull String name) {
|
public static Result setName(@NonNull SteamwarUser user, @NonNull SchematicNode node, @NonNull String name) {
|
||||||
|
if(user.getId() != node.getId()) {
|
||||||
|
return Result.NOT_OWNER;
|
||||||
|
}
|
||||||
|
|
||||||
if(invalidSchemName(name)) {
|
if(invalidSchemName(name)) {
|
||||||
return Result.INVALID_NAME;
|
return Result.INVALID_NAME;
|
||||||
}
|
}
|
||||||
@ -48,10 +55,6 @@ public class SafeSchematicNode {
|
|||||||
return Result.DONE;
|
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"));
|
private static final List<String> FORBIDDEN_NAMES = Collections.unmodifiableList(Arrays.asList("public"));
|
||||||
public static boolean invalidSchemName(String name) {
|
public static boolean invalidSchemName(String name) {
|
||||||
if (name.isEmpty()) {
|
if (name.isEmpty()) {
|
||||||
@ -74,11 +77,19 @@ public class SafeSchematicNode {
|
|||||||
return FORBIDDEN_NAMES.contains(name.toLowerCase());
|
return FORBIDDEN_NAMES.contains(name.toLowerCase());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@AllArgsConstructor
|
||||||
public enum Result {
|
public enum Result {
|
||||||
DONE,
|
DONE("No"),
|
||||||
NOT_A_DIR,
|
NOT_A_DIR(SchematicSystem.PREFIX + "§cDie ausgewählte Schematic ist kein Ordner"),
|
||||||
ALREADY_IN_DIRECTORY,
|
ALREADY_IN_DIRECTORY(SchematicSystem.PREFIX + "§cDie Schematic gibt es bereits in diesem Ordner"),
|
||||||
INVALID_NAME;
|
INVALID_NAME(SchematicSystem.PREFIX + "§cDieser Name ist unzulässig"),
|
||||||
|
NOT_OWNER(SchematicSystem.PREFIX + "§cDu bist nicht der Besitzer dieser Schematic");
|
||||||
|
|
||||||
|
private String errorMessage;
|
||||||
|
|
||||||
|
public void sendError(Player player) {
|
||||||
|
player.sendMessage(errorMessage);
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isSuccessful() {
|
public boolean isSuccessful() {
|
||||||
return this == DONE;
|
return this == DONE;
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
package de.steamwar.schematicsystem.commands;
|
package de.steamwar.schematicsystem.commands;
|
||||||
|
|
||||||
import de.steamwar.inventory.*;
|
import de.steamwar.inventory.*;
|
||||||
|
import de.steamwar.schematicsystem.SafeSchematicNode;
|
||||||
import de.steamwar.schematicsystem.SchematicSystem;
|
import de.steamwar.schematicsystem.SchematicSystem;
|
||||||
import de.steamwar.sql.*;
|
import de.steamwar.sql.*;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
@ -102,8 +103,12 @@ public class GUI {
|
|||||||
inv.setItem(5, skull);
|
inv.setItem(5, skull);
|
||||||
inv.setItem(6, Material.ARROW, "§eVerschieben", clickType -> {
|
inv.setItem(6, Material.ARROW, "§eVerschieben", clickType -> {
|
||||||
SchematicSelector selector = new SchematicSelector(player, SchematicSelector.selectDirectory(), npar -> {
|
SchematicSelector selector = new SchematicSelector(player, SchematicSelector.selectDirectory(), npar -> {
|
||||||
node.setParent(npar==null?null:npar.getId());
|
SafeSchematicNode.Result result = SafeSchematicNode.setParent(user, node, npar);
|
||||||
info(player, SchematicNode.getSchematicNode(node.getId()));
|
if(result.isSuccessful()) {
|
||||||
|
info(player, SchematicNode.getSchematicNode(node.getId()));
|
||||||
|
} else {
|
||||||
|
result.sendError(player);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
selector.open();
|
selector.open();
|
||||||
});
|
});
|
||||||
@ -112,10 +117,12 @@ public class GUI {
|
|||||||
SWAnvilInv anvilInv = new SWAnvilInv(player, node.getName() + " umbenennen", node.getName());
|
SWAnvilInv anvilInv = new SWAnvilInv(player, node.getName() + " umbenennen", node.getName());
|
||||||
anvilInv.setItem(finalMat);
|
anvilInv.setItem(finalMat);
|
||||||
anvilInv.setCallback(s -> {
|
anvilInv.setCallback(s -> {
|
||||||
if (!invalidSchemName(player, new String[]{s})) {
|
SafeSchematicNode.Result result = SafeSchematicNode.setName(user, node, s);
|
||||||
node.setName(s);
|
if(result.isSuccessful()) {
|
||||||
|
info(player, node);
|
||||||
|
} else {
|
||||||
|
result.sendError(player);
|
||||||
}
|
}
|
||||||
info(player, node);
|
|
||||||
});
|
});
|
||||||
anvilInv.open();
|
anvilInv.open();
|
||||||
});
|
});
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren