13
0

Update to new SchematicSelector

Signed-off-by: Chaoscaot <chaoscaot444@gmail.com>
Dieser Commit ist enthalten in:
Chaoscaot 2021-11-26 16:35:30 +01:00
Ursprung 441bc4ee6c
Commit c22109daa9
3 geänderte Dateien mit 15 neuen und 54 gelöschten Zeilen

Datei anzeigen

@ -26,7 +26,7 @@ import de.steamwar.inventory.SWListInv;
import de.steamwar.schematicsystem.SchematicSystem;
import de.steamwar.sql.*;
import de.steamwar.util.SchematicSelector;
import de.steamwar.util.SchematicSelectorInjectableAdapter;
import de.steamwar.util.SchematicSelectorInjectable;
import de.steamwar.util.UtilGui;
import org.bukkit.Material;
import org.bukkit.entity.Player;
@ -34,8 +34,7 @@ import org.bukkit.event.inventory.ClickType;
import java.util.*;
import static de.steamwar.schematicsystem.commands.SchematicCommandUtils.getUser;
import static de.steamwar.schematicsystem.commands.SchematicCommandUtils.invalidSchemName;
import static de.steamwar.schematicsystem.commands.SchematicCommandUtils.*;
public class GUI {
@ -44,7 +43,7 @@ public class GUI {
}
private static void list(Player player) {
SchematicSelector selector = new SchematicSelector(player, SchematicSelector.selectSchematic(), new SchematicSelectorInjectableAdapter() {
SchematicSelector selector = new SchematicSelector(player, SchematicSelector.selectSchematic(), new SchematicSelectorInjectable() {
@Override
public void onListRender(SchematicSelector selector, SWListInv<SchematicNode> inv, SchematicNode parent) {
if(parent == null) {
@ -58,7 +57,8 @@ public class GUI {
}, node -> {
info(player, node);
});
selector.setTitle("Schematic GUI: {1}");
selector.setSingleDirOpen(false);
selector.setTitle(player1 -> "Schematic GUI: {1}");
selector.open();
}

Datei anzeigen

@ -384,7 +384,7 @@ public class SchematicCommand extends SWCommand {
player.closeInventory();
});
inv.setItem(8, SWItem.getDye(7), (byte) 7, "§eDirekt einsenden", click -> {
node.setType(type.checkType().toDB());
node.setSchemtype(type.checkType());
player.sendMessage(SchematicSystem.PREFIX + "§aDie Schematic wird zeitnah überprüft");
player.closeInventory();
});
@ -566,7 +566,7 @@ public class SchematicCommand extends SWCommand {
@Override
public SchematicNode map(CommandSender commandSender, String[] previousArguments, String s) {
return mapNode(SteamwarUser.get(0), previousArguments, s);
return SchematicNode.getNodeFromPath(SteamwarUser.get(0), s);
}
};
}
@ -665,7 +665,7 @@ public class SchematicCommand extends SWCommand {
@Override
public SchematicNode map(CommandSender commandSender, String[] previousArguments, String s) {
return mapNode(getUser((Player) commandSender), previousArguments, s);
return SchematicNode.getNodeFromPath(getUser((Player) commandSender), s);
}
};
}

Datei anzeigen

@ -40,45 +40,6 @@ public class SchematicCommandUtils {
private SchematicCommandUtils() {
}
public static SchematicNode mapNode(SteamwarUser user, String[] previousArguments, String s) {
if (s.startsWith("/")) {
s = s.substring(1);
}
if (s.isEmpty()) {
return null;
}
if (s.contains("/")) {
String[] layers = s.split("/");
SchematicNode currentNode = null;
for (int i = 0; i < layers.length; i++) {
int finalI = i;
List<SchematicNode> nodes;
if (currentNode == null) {
nodes = SchematicNode.getSchematicsAccessibleByUser(user.getId(), 0).stream().filter(node -> node.getName().equals(layers[finalI])).collect(Collectors.toList());
} else {
nodes = SchematicNode.getSchematicNodeInNode(currentNode).stream().filter(node -> node.getName().equals(layers[finalI])).collect(Collectors.toList());
}
if (nodes.isEmpty()) {
return null;
} else {
currentNode = nodes.get(0);
if (!currentNode.isDir() && i != layers.length - 1) {
return null;
}
}
}
return currentNode;
} else {
String finalS = s;
List<SchematicNode> nodes = SchematicNode.getSchematicsAccessibleByUser(user.getId(), 0).stream().filter(node -> node.getName().equals(finalS)).collect(Collectors.toList());
if (nodes.isEmpty()) {
return null;
} else {
return nodes.get(0);
}
}
}
public static List<String> getNodeTabcomplete(SteamwarUser user, String[] strings, String s) {
List<String> list = new ArrayList<>();
boolean sws = s.startsWith("/");
@ -87,7 +48,7 @@ public class SchematicCommandUtils {
}
if (s.contains("/")) {
String preTab = s.substring(0, s.lastIndexOf("/") + 1);
SchematicNode pa = mapNode(user, strings, preTab);
SchematicNode pa = SchematicNode.getNodeFromPath(user, preTab);
if (pa == null) return Collections.emptyList();
List<SchematicNode> nodes = SchematicNode.getSchematicNodeInNode(pa);
nodes.forEach(node -> list.add((sws ? "/" : "") + node.generateBreadcrumbs(user)));
@ -281,13 +242,13 @@ public class SchematicCommandUtils {
rename.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText("§e" + (node.isDir() ? "Ordner" : "Schematic") + " umbenennen")));
rename.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/schem rename " + node.generateBreadcrumbs(user) + " [Neuer Name]"));
base.addExtra(rename);
}
TextComponent delete = new TextComponent("[Löschen] ");
TextComponent delete = new TextComponent("[" + (node.getOwner()==user.getId()?"Löschen":"Entfernen") + "] ");
delete.setColor(ChatColor.DARK_RED);
delete.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText("§e" + (node.isDir() ? "Ordner" : "Schematic") + " Löschen")));
delete.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/schem delete " + node.generateBreadcrumbs(user)));
base.addExtra(delete);
}
if (!base.getExtra().isEmpty()) {
player.spigot().sendMessage(base);