13
0

More Refactoring

Signed-off-by: Chaoscaot <chaoscaot444@gmail.com>
Dieser Commit ist enthalten in:
Chaoscaot 2021-07-25 18:50:31 +02:00
Ursprung ad5e7f977b
Commit 2f9cdff26d

Datei anzeigen

@ -39,7 +39,6 @@ import org.bukkit.entity.Player;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.*; import java.util.*;
import java.util.List;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -51,23 +50,24 @@ public class SchematicCommand extends SWCommand {
super("schematic", "/schematic", "schem", "/schem"); super("schematic", "/schematic", "schem", "/schem");
} }
@Register(help = true) private static List<String> getNodeTabcomplete(SteamwarUser user, String[] strings, String s) {
public void genericHelp(Player player, String... args) { List<String> list = new ArrayList<>();
player.sendMessage(SchematicSystem.PREFIX + "Befehle§8:"); boolean sws = s.startsWith("/");
player.sendMessage("§8/§eschem gui §8- §7Öffnet die Schematic-GUI"); if (sws) {
player.sendMessage("§8/§eschem list §8- §7Zeigt dir deine Schematics an"); s = s.substring(1);
player.sendMessage("§8/§eschem list public §8- §7Zeigt alle Public-Schematics"); }
player.sendMessage("§8/§eschem search §8[§7Stichwort§8] - §7Sucht nach passenden Schematics"); if (s.contains("/")) {
player.sendMessage("§8/§eschem load §8[§7Schematic§8] - §7Lädt eine Schematic"); String preTab = s.substring(0, s.lastIndexOf("/") + 1);
player.sendMessage("§8/§eschem save §8[§7Schematic§8] - §7Speichert dein Clipboard als Schematic"); SchematicNode pa = mapNode(user, strings, preTab);
player.sendMessage("§8/§eschem changetype §8[§7Schematic§8] - §7Ändert die Art deiner Schematic"); if (pa == null) return Collections.emptyList();
player.sendMessage("§8/§eschem delete §8[§7Schematic§8] - §7Löscht eine Schematic"); List<SchematicNode> nodes = SchematicNode.getSchematicNodeInNode(pa);
player.sendMessage("§8/§eschem info §8[§7Schematic§8] - §7Zeigt dir Informationen zur Schematic"); nodes.forEach(node -> list.add(node.generateBreadcrumbs(user)));
player.sendMessage("§8/§eschem download §8[§7Schematic§8] - §7Gibt dir einen Downloadlink (1 min gültig)"); } else {
player.sendMessage("§8/§eschem addmember §8[§7Schematic§8] §8[§7Spieler§8] - §7Fügt einen Spieler zu einer Schematic hinzu"); List<SchematicNode> nodes = SchematicNode.getSchematicsAccessibleByUser(user.getId(), 0);
player.sendMessage("§8/§eschem delmember §8[§7Schematic§8] §8[§7Spieler§8] - §7Entfernt einen Spieler von einer Schematic"); nodes.forEach(node -> list.add((sws ? "/" : "") + node.getName() + (node.isDir() ? "/" : "")));
player.sendMessage("§8/§eschem mkdirs §8[§7Ordner§8] - §7Erstelle einen Leeren Ordner"); }
player.sendMessage("§8/§eschem move §8[§7Schematic§8] [§7Neuer Pfad§8] - §7Verschiebe eine Schematic"); list.remove("//copy");
return list;
} }
@Register("gui") @Register("gui")
@ -87,24 +87,66 @@ public class SchematicCommand extends SWCommand {
renderSchemlist(player, SchematicNode.getSchematicsAccessibleByUser(SteamwarUser.get(player.getUniqueId()).getId(), 0), page, "", false); renderSchemlist(player, SchematicNode.getSchematicsAccessibleByUser(SteamwarUser.get(player.getUniqueId()).getId(), 0), page, "", false);
} }
@Register("list") private static SchematicNode mapNode(SteamwarUser user, String[] previousArguments, String s) {
public void schemList(Player player, @Mapper("dirMapper") SchematicNode node) { if (s.startsWith("/")) {
SteamwarUser user = SteamwarUser.get(player.getUniqueId()); s = s.substring(1);
if(!node.isDir()) { }
player.sendMessage("haethate"); 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 { } else {
renderSchemlist(player, SchematicNode.getSchematicNodeInNode(node), 0, node.generateBreadcrumbs(user), node.getOwner()==0); 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);
}
} }
} }
@Register("list") @Register(help = true)
public void schemList(Player player, @Mapper("dirMapper") SchematicNode node, int page) { public void genericHelp(Player player, String... args) {
SteamwarUser user = SteamwarUser.get(player.getUniqueId()); player.sendMessage(SchematicSystem.PREFIX + "Befehle§8:");
if(!node.isDir()) { player.sendMessage("§8/§eschem gui §8- §7Öffnet die Schematic-GUI");
player.sendMessage("haethate"); player.sendMessage("§8/§eschem list §8- §7Zeigt dir deine Schematics an");
} else { player.sendMessage("§8/§eschem list public §8- §7Zeigt alle Public-Schematics");
renderSchemlist(player, SchematicNode.getSchematicNodeInNode(node), page, node.generateBreadcrumbs(user), node.getOwner()==0); player.sendMessage("§8/§eschem search §8[§7Stichwort§8] - §7Sucht nach passenden Schematics");
} player.sendMessage("§8/§eschem load §8[§7Schematic§8] - §7Lädt eine Schematic");
player.sendMessage("§8/§eschem save §8[§7Schematic§8] - §7Speichert dein Clipboard als Schematic");
player.sendMessage("§8/§eschem changetype §8[§7Schematic§8] - §7Ändert die Art deiner Schematic");
player.sendMessage("§8/§eschem delete §8[§7Schematic§8] - §7Löscht eine Schematic");
player.sendMessage("§8/§eschem info §8[§7Schematic§8] - §7Zeigt dir Informationen zur Schematic");
player.sendMessage("§8/§eschem download §8[§7Schematic§8] - §7Gibt dir einen Downloadlink (1 min gültig)");
player.sendMessage("§8/§eschem addmember §8[§7Schematic§8] §8[§7Spieler§8] - §7Fügt einen Spieler zu einer Schematic hinzu");
player.sendMessage("§8/§eschem delmember §8[§7Schematic§8] §8[§7Spieler§8] - §7Entfernt einen Spieler von einer Schematic");
player.sendMessage("§8/§eschem clearmember §8[§7Schematic§8] - §7Entfernt alle Spieler von der Schematic");
player.sendMessage("§8/§eschem mkdir §8[§7Ordner§8] - §7Erstelle einen Leeren Ordner");
player.sendMessage("§8/§eschem move §8[§7Schematic§8] [§7Neuer Pfad§8] - §7Verschiebe eine Schematic");
player.sendMessage("§8/§eschem rename §8[§7Schematic§8] [§7Neuer Name§8] - §7Gib der Schematic einen neuen Namen");
player.sendMessage("§8/§eschem addteam §8[§7Schematic§8] - §7Füge jeden aus deinem Team auf die Schematic hinzu");
player.sendMessage("§8/§eschem remteam §8[§7Schematic§8] - §7Entferne jeden aus deinem Team von der Schematic");
} }
@Register({"list", "public"}) @Register({"list", "public"})
@ -135,6 +177,40 @@ public class SchematicCommand extends SWCommand {
schemInfo(player, node); schemInfo(player, node);
} }
@Register("list")
public void schemList(Player player, @Mapper("dirMapper") SchematicNode node) {
SteamwarUser user = SteamwarUser.get(player.getUniqueId());
if (!node.isDir()) {
player.sendMessage(SchematicSystem.PREFIX + "Das ist eine Schematic und kein Ordner");
} else {
renderSchemlist(player, SchematicNode.getSchematicNodeInNode(node), 0, node.generateBreadcrumbs(user), node.getOwner() == 0);
}
}
@Register({"info", "/"})
public void schemInfoSecret(Player player) {
player.sendMessage("§7--==( §eSteam§8War §eSchematic-System §7)==--");
player.sendMessage("§7Anzahl an Schematics: §e" + SchematicNode.countNodes());
player.sendMessage("§7Von dir einsehbar: §e" + SchematicNode.getAllSchematicsAccessibleByUser(SteamwarUser.get(player.getUniqueId()).getId()).size());
player.sendMessage("§7Autoren: §e" + Arrays.toString(SchematicSystem.INSTANCE.getDescription().getAuthors().toArray()));
}
@Register("list")
public void schemList(Player player, @Mapper("dirMapper") SchematicNode node, int page) {
SteamwarUser user = SteamwarUser.get(player.getUniqueId());
if (!node.isDir()) {
player.sendMessage(SchematicSystem.PREFIX + "Das ist eine Schematic und kein Ordner");
} else {
renderSchemlist(player, SchematicNode.getSchematicNodeInNode(node), page, node.generateBreadcrumbs(user), node.getOwner() == 0);
}
}
@Register({"l", "public"})
@Register({"load", "public"})
public void loadSchemPublic(Player player, @Mapper("publicMapper") SchematicNode node) {
loadSchem(player, node);
}
@Register("info") @Register("info")
public void schemInfo(Player player, SchematicNode node) { public void schemInfo(Player player, SchematicNode node) {
SteamwarUser user = SteamwarUser.get(player.getUniqueId()); SteamwarUser user = SteamwarUser.get(player.getUniqueId());
@ -161,7 +237,7 @@ public class SchematicCommand extends SWCommand {
List<String> schematicMembers = new ArrayList<>(); List<String> schematicMembers = new ArrayList<>();
NodeMember.getNodeMembers(node.getId()).forEach(nodeMember -> schematicMembers.add(SteamwarUser.get(nodeMember.getMember()).getUserName())); NodeMember.getNodeMembers(node.getId()).forEach(nodeMember -> schematicMembers.add(SteamwarUser.get(nodeMember.getMember()).getUserName()));
if (!schematicMembers.isEmpty()) { if (!schematicMembers.isEmpty()) {
player.sendMessage("§7Mitglieder: §e" + schematicMembers.toString()); player.sendMessage("§7Mitglieder: §e" + schematicMembers);
} }
TextComponent base = new TextComponent(); TextComponent base = new TextComponent();
@ -179,6 +255,12 @@ public class SchematicCommand extends SWCommand {
download.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText("§eSchematic downloaden"))); download.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText("§eSchematic downloaden")));
download.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/schem download " + node.generateBreadcrumbs(user))); download.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/schem download " + node.generateBreadcrumbs(user)));
base.addExtra(download); base.addExtra(download);
TextComponent changeTyp = new TextComponent("[Typ ändern] ");
changeTyp.setColor(ChatColor.BLUE);
changeTyp.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText("§eSchematic Typ ändern")));
changeTyp.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/schem changetype " + node.generateBreadcrumbs(user)));
base.addExtra(changeTyp);
} }
} }
@ -195,26 +277,28 @@ public class SchematicCommand extends SWCommand {
delMember.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/schem delmember " + node.generateBreadcrumbs(user) + " ")); delMember.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/schem delmember " + node.generateBreadcrumbs(user) + " "));
base.addExtra(delMember); base.addExtra(delMember);
TextComponent delete = new TextComponent("[Delete] "); TextComponent move = new TextComponent("[Verschieben] ");
move.setColor(ChatColor.DARK_PURPLE);
move.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText("§e" + (node.isDir() ? "Ordner" : "Schematic") + " verschieben")));
move.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/schem move " + node.generateBreadcrumbs(user) + " " + node.generateBreadcrumbs(user).replace("/" + node.getName(), "")));
base.addExtra(move);
TextComponent rename = new TextComponent("[Umbenennen] ");
rename.setColor(ChatColor.LIGHT_PURPLE);
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] ");
delete.setColor(ChatColor.DARK_RED); delete.setColor(ChatColor.DARK_RED);
delete.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText("§e" + (node.isDir() ? "Ordner" : "Schematic") + " Löschen"))); 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))); delete.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/schem delete " + node.generateBreadcrumbs(user)));
base.addExtra(delete); base.addExtra(delete);
} }
player.spigot().sendMessage(base); player.spigot().sendMessage(base);
} }
@Register({"info", "/"})
public void schemInfoSecret(Player player) {
player.sendMessage("§7--==( §eSteam§8War §eSchematic-System §7)==--");
player.sendMessage("§7Anzahl an Schematics: §e" + SchematicNode.countNodes());
player.sendMessage("§7Von dir einsehbar: §e" + SchematicNode.getAllSchematicsAccessibleByUser(SteamwarUser.get(player.getUniqueId()).getId()).size());
player.sendMessage("§7Autoren: §e" + Arrays.toString(SchematicSystem.INSTANCE.getDescription().getAuthors().toArray()));
}
@Register("l") @Register("l")
@Register("load") @Register("load")
public void loadSchem(Player player, SchematicNode node) { public void loadSchem(Player player, SchematicNode node) {
@ -235,12 +319,6 @@ public class SchematicCommand extends SWCommand {
} }
} }
@Register({"l", "public"})
@Register({"load", "public"})
public void loadSchemPublic(Player player, @Mapper("publicMapper") SchematicNode node) {
loadSchem(player, node);
}
@Register("save") @Register("save")
@Register("s") @Register("s")
public void saveSchem(Player player, @Mapper("dirStringMapper") String name) { public void saveSchem(Player player, @Mapper("dirStringMapper") String name) {
@ -277,11 +355,12 @@ public class SchematicCommand extends SWCommand {
return; return;
} }
if (newSchem) if (newSchem) {
player.sendMessage(SchematicSystem.PREFIX + "Schematic §e" + node.getName() + " §7gespeichert"); player.sendMessage(SchematicSystem.PREFIX + "Schematic §e" + node.getName() + " §7gespeichert");
else } else {
player.sendMessage(SchematicSystem.PREFIX + "Schematic §e" + node.getName() + " §7überschrieben"); player.sendMessage(SchematicSystem.PREFIX + "Schematic §e" + node.getName() + " §7überschrieben");
} }
}
@Register("addmember") @Register("addmember")
public void addMember(Player player, SchematicNode node, SteamwarUser target) { public void addMember(Player player, SchematicNode node, SteamwarUser target) {
@ -296,18 +375,18 @@ public class SchematicCommand extends SWCommand {
return; return;
} }
NodeMember member = NodeMember.getNodeMember(node.getId(), target.getId()); if (NodeMember.getNodeMember(node.getId(), target.getId()) != null) {
if(member != null) {
player.sendMessage(SchematicSystem.PREFIX + "§cDieser Spieler ist bereits auf diese Schematic geaddet"); player.sendMessage(SchematicSystem.PREFIX + "§cDieser Spieler ist bereits auf diese Schematic geaddet");
return; return;
} }
member = NodeMember.createNodeMember(node.getId(), target.getId()); NodeMember.createNodeMember(node.getId(), target.getId());
player.sendMessage(SchematicSystem.PREFIX + "Der Spieler §e" + target.getUserName() + " §7hat nun Zugriff auf die Schematic §e" + node.generateBreadcrumbs(user)); player.sendMessage(SchematicSystem.PREFIX + "Der Spieler §e" + target.getUserName() + " §7hat nun Zugriff auf die Schematic §e" + node.generateBreadcrumbs(user));
Player t = Bukkit.getPlayer(target.getUUID()); Player t = Bukkit.getPlayer(target.getUUID());
if(t != null) if (t != null) {
t.sendMessage(SchematicSystem.PREFIX + "Du hast nun Zugriff auf die Schematic §e" + node.getName() + " §7von §e" + player.getName()); t.sendMessage(SchematicSystem.PREFIX + "Du hast nun Zugriff auf die Schematic §e" + node.getName() + " §7von §e" + player.getName());
} }
}
@Register("delmember") @Register("delmember")
@Register("remmember") @Register("remmember")
@ -331,6 +410,21 @@ public class SchematicCommand extends SWCommand {
} }
} }
@Register("search")
public void schemSearch(Player player, String quarry) {
SteamwarUser user = SteamwarUser.get(player.getUniqueId());
List<SchematicNode> nodes = SchematicNode.filterSchems(user.getId(), node -> node.getName().contains(quarry));
player.sendMessage("§7--==( §eSchematics §8(§e" + nodes.size() + "§8) §7)==--");
nodes.forEach(node -> {
String br = node.generateBreadcrumbs(user);
TextComponent schematics = new TextComponent("§7" + br.replace(quarry, "§e§l" + quarry + "§7"));
schematics.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§eSchematic verwalten").create()));
schematics.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/schem info " + br));
player.spigot().sendMessage(schematics);
});
}
@Register("download") @Register("download")
public void download(Player player, SchematicNode node) { public void download(Player player, SchematicNode node) {
SteamwarUser user = SteamwarUser.get(player.getUniqueId()); SteamwarUser user = SteamwarUser.get(player.getUniqueId());
@ -356,21 +450,6 @@ public class SchematicCommand extends SWCommand {
player.sendMessage(SchematicSystem.PREFIX + "§7Ordner §e" + node.generateBreadcrumbs(user) + " §7erstellt"); player.sendMessage(SchematicSystem.PREFIX + "§7Ordner §e" + node.generateBreadcrumbs(user) + " §7erstellt");
} }
@Register("search")
public void schemSearch(Player player, String quarry) {
SteamwarUser user = SteamwarUser.get(player.getUniqueId());
List<SchematicNode> nodes = SchematicNode.filterSchems(user.getId(), node -> node.getName().contains(quarry));
player.sendMessage("§7--==( §eSchematics §8(§e" + nodes.size() + "§8) §7)==--");
nodes.forEach(node -> {
String br = node.generateBreadcrumbs(user);
TextComponent schematics = new TextComponent("§7" + br.replace(quarry, "§e§l" + quarry + "§7"));
schematics.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§eSchematic verwalten").create()));
schematics.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/schem info " + br));
player.spigot().sendMessage(schematics);
});
}
@Register("changetype") @Register("changetype")
public void changeType(Player player, SchematicNode node) { public void changeType(Player player, SchematicNode node) {
SteamwarUser user = SteamwarUser.get(player.getUniqueId()); SteamwarUser user = SteamwarUser.get(player.getUniqueId());
@ -392,6 +471,11 @@ public class SchematicCommand extends SWCommand {
@Register("changetype") @Register("changetype")
public void changeType(Player player, SchematicNode node, SchematicType type) { public void changeType(Player player, SchematicNode node, SchematicType type) {
changeType(player, node, type, null);
}
@Register("changetype")
public void changeType(Player player, SchematicNode node, SchematicType type, Extend extend) {
if (node.isDir()) { if (node.isDir()) {
player.sendMessage(SchematicSystem.PREFIX + "§cOrdner haben keinen Typen."); player.sendMessage(SchematicSystem.PREFIX + "§cOrdner haben keinen Typen.");
return; return;
@ -424,6 +508,7 @@ public class SchematicCommand extends SWCommand {
return; return;
} }
if (extend == null) {
SWInventory inv = new SWInventory(player, 9, "Schematic ausfahren"); SWInventory inv = new SWInventory(player, 9, "Schematic ausfahren");
inv.setItem(0, SWItem.getDye(10), (byte) 10, "§eSchematic ausfahren", click -> { inv.setItem(0, SWItem.getDye(10), (byte) 10, "§eSchematic ausfahren", click -> {
new PrepareSchemPacket(SteamwarUser.get(player.getUniqueId()), node, type).send(player); new PrepareSchemPacket(SteamwarUser.get(player.getUniqueId()), node, type).send(player);
@ -437,29 +522,119 @@ public class SchematicCommand extends SWCommand {
}); });
inv.setCallback(-999, click -> player.closeInventory()); inv.setCallback(-999, click -> player.closeInventory());
inv.open(); inv.open();
} else if (extend == Extend.AUSFAHREN) {
new PrepareSchemPacket(SteamwarUser.get(player.getUniqueId()), node, type).send(player);
player.sendMessage(SchematicSystem.PREFIX + "§aDer Vorbereitungsserver wird gestartet");
}
} }
} }
@Register("move") @Register("move")
public void renameMove(Player player, SchematicNode node, @Mapper("dirStringMapper") String name) { public void move(Player player, SchematicNode node, @Mapper("dirStringMapper") String name) {
SteamwarUser user = SteamwarUser.get(player.getUniqueId()); SteamwarUser user = SteamwarUser.get(player.getUniqueId());
if (node.getOwner() != user.getId()) { if (node.getOwner() != user.getId()) {
player.sendMessage(SchematicSystem.PREFIX + "§cDas kannst du nur bei deinen eigenen Schems machen"); player.sendMessage(SchematicSystem.PREFIX + "§cDas kannst du nur bei deinen eigenen Schems machen");
return; return;
} }
if (name.equals("/")) {
node.setParent(0);
} else {
if (name.startsWith("/")) name = name.substring(1); if (name.startsWith("/")) name = name.substring(1);
if (name.endsWith("/")) name = name.substring(0, name.length() - 1); if (name.endsWith("/")) name = name.substring(0, name.length() - 1);
String[] layers = name.split("/"); String[] layers = name.split("/");
if (invalidSchemName(player, layers)) return; if (invalidSchemName(player, layers)) return;
if(name.contains("/")) { SchematicNode newNode = mkdirs(layers, user, 0);
SchematicNode newNode = mkdirs(layers, user, 1);
node.setParent(newNode.getId()); node.setParent(newNode.getId());
} else {
node.setParent(0);
} }
String schemName = layers[layers.length-1]; player.sendMessage(SchematicSystem.PREFIX + "§7Die Schematic ist nun unter §e" + node.generateBreadcrumbs(user) + " §7zu finden");
node.setName(schemName); }
player.sendMessage(SchematicSystem.PREFIX + "§7Die Schematic heist nun §7" + node.generateBreadcrumbs(user));
@Register("rename")
public void rename(Player player, SchematicNode node, String name) {
SteamwarUser user = SteamwarUser.get(player.getUniqueId());
if (node.getOwner() != user.getId()) {
player.sendMessage(SchematicSystem.PREFIX + "§cDas kannst du nur bei deinen eigenen Schems machen");
return;
}
if (invalidSchemName(player, new String[]{name})) {
return;
}
node.setName(name);
player.sendMessage(SchematicSystem.PREFIX + "§7Die Schematic heist nun §e" + node.generateBreadcrumbs(user));
}
@Register("addteam")
public void addTeam(Player player, SchematicNode node) {
SteamwarUser user = SteamwarUser.get(player.getUniqueId());
if (node.getOwner() != user.getId()) {
player.sendMessage(SchematicSystem.PREFIX + "§cDas kannst du nur bei deinen eigenen Schems machen");
return;
}
Team team = Team.get(user.getTeam());
if (team == null) {
player.sendMessage(SchematicSystem.PREFIX + "§cDu bist in keinem Team");
return;
}
List<String> added = new ArrayList<>();
for (Integer member : team.getMembers()) {
if (user.getId() == member) continue;
if (NodeMember.getNodeMember(node.getId(), member) == null) {
NodeMember.createNodeMember(node.getId(), member);
added.add(SteamwarUser.get(member).getUserName());
}
}
Optional<String> reduced = added.stream().reduce((s, s2) -> s + ", " + s2);
if (reduced.isPresent()) {
player.sendMessage(SchematicSystem.PREFIX + "§7Die Spieler §e" + reduced.get() + " §7wurden auf die Schematic hinzugefügt");
} else {
player.sendMessage(SchematicSystem.PREFIX + "§7Es wurde kein Spieler hinzugefügt");
}
}
@Register("remteam")
public void remTeam(Player player, SchematicNode node) {
SteamwarUser user = SteamwarUser.get(player.getUniqueId());
if (node.getOwner() != user.getId()) {
player.sendMessage(SchematicSystem.PREFIX + "§cDas kannst du nur bei deinen eigenen Schems machen");
return;
}
Team team = Team.get(user.getTeam());
if (team == null) {
player.sendMessage(SchematicSystem.PREFIX + "§cDu bist in keinem Team");
return;
}
List<String> removed = new ArrayList<>();
for (Integer member : team.getMembers()) {
if (user.getId() == member) continue;
NodeMember nodeMember = NodeMember.getNodeMember(node.getId(), member);
if (nodeMember != null) {
nodeMember.delete();
removed.add(SteamwarUser.get(member).getUserName());
}
}
Optional<String> reduced = removed.stream().reduce((s, s2) -> s + ", " + s2);
if (reduced.isPresent()) {
player.sendMessage(SchematicSystem.PREFIX + "§7Die Spieler §e" + reduced.get() + " §7wurden von der Schematic entfernt");
} else {
player.sendMessage(SchematicSystem.PREFIX + "§7Es wurde kein Spieler entfernt");
}
}
@Register("remallmember")
@Register("clearmember")
public void clearMember(Player player, SchematicNode node) {
SteamwarUser user = SteamwarUser.get(player.getUniqueId());
if (node.getOwner() != user.getId()) {
player.sendMessage(SchematicSystem.PREFIX + "§cDas kannst du nur bei deinen eigenen Schems machen");
return;
}
node.getMembers().forEach(NodeMember::delete);
player.sendMessage(SchematicSystem.PREFIX + "§7Alle Spieler wurden von der Schematic entfernt");
} }
private boolean invalidSchemName(Player player, String[] layers) { private boolean invalidSchemName(Player player, String[] layers) {
@ -502,6 +677,9 @@ public class SchematicCommand extends SWCommand {
return currentNode; return currentNode;
} }
private final TypeMapper<SchematicNode> schematicCommandTypeMapper = nodeTypeMapper();
private final TypeMapper<SchematicNode> publicCommandTypeMapper = publicNodeTypeMapper();
private void renderSchemlist(Player player, List<SchematicNode> nodes, int chunk, String breadcrumbs, boolean isPublic) { private void renderSchemlist(Player player, List<SchematicNode> nodes, int chunk, String breadcrumbs, boolean isPublic) {
nodes.sort(Comparator.comparing(SchematicNode::getName)); nodes.sort(Comparator.comparing(SchematicNode::getName));
SteamwarUser user = SteamwarUser.get(player.getUniqueId()); SteamwarUser user = SteamwarUser.get(player.getUniqueId());
@ -562,23 +740,37 @@ public class SchematicCommand extends SWCommand {
beforePage.setColor(ChatColor.YELLOW); beforePage.setColor(ChatColor.YELLOW);
beforePage.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§eVorherige Seite").create())); beforePage.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§eVorherige Seite").create()));
beforePage.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/schem list " + (isPublic ? "public" : "") + " " + breadcrumbs + " " + (chunk - 1))); beforePage.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/schem list " + (isPublic ? "public" : "") + " " + breadcrumbs + " " + (chunk - 1)));
}else } else {
beforePage.setColor(ChatColor.RED); beforePage.setColor(ChatColor.RED);
}
TextComponent nextPage = new TextComponent(" Seite (" + (chunk + 1) + "/" + Math.max(pageCount, 1) + ") »»"); TextComponent nextPage = new TextComponent(" Seite (" + (chunk + 1) + "/" + Math.max(pageCount, 1) + ") »»");
if (chunk < pageCount - 1) { if (chunk < pageCount - 1) {
nextPage.setColor(ChatColor.YELLOW); nextPage.setColor(ChatColor.YELLOW);
nextPage.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§eNächste Seite").create())); nextPage.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§eNächste Seite").create()));
nextPage.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/schem list " + (isPublic ? "public" : "") + " " + breadcrumbs + " " + (chunk + 1))); nextPage.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/schem list " + (isPublic ? "public" : "") + " " + breadcrumbs + " " + (chunk + 1)));
}else } else {
nextPage.setColor(ChatColor.RED); nextPage.setColor(ChatColor.RED);
}
beforePage.addExtra(nextPage); beforePage.addExtra(nextPage);
player.spigot().sendMessage(beforePage); player.spigot().sendMessage(beforePage);
} }
private final TypeMapper<SchematicNode> schematicCommandTypeMapper = nodeTypeMapper(); @Mapper("publicMapper")
private final TypeMapper<SchematicNode> publicCommandTypeMapper = publicNodeTypeMapper(); public TypeMapper<SchematicNode> publicNodeTypeMapper() {
return new TypeMapper<SchematicNode>() {
@Override
public List<String> tabCompletes(CommandSender commandSender, String[] strings, String s) {
return getNodeTabcomplete(SteamwarUser.get(0), strings, s);
}
@Override
public SchematicNode map(CommandSender commandSender, String[] previousArguments, String s) {
return mapNode(SteamwarUser.get(0), previousArguments, s);
}
};
}
@Mapper("memberMapper") @Mapper("memberMapper")
public TypeMapper<NodeMember> nodeMemberTypeMapper() { public TypeMapper<NodeMember> nodeMemberTypeMapper() {
@ -603,21 +795,6 @@ public class SchematicCommand extends SWCommand {
}; };
} }
@Mapper("publicMapper")
public TypeMapper<SchematicNode> publicNodeTypeMapper() {
return new TypeMapper<SchematicNode>() {
@Override
public List<String> tabCompletes(CommandSender commandSender, String[] strings, String s) {
return getNodeTabcomplete(SteamwarUser.get(0), strings, s);
}
@Override
public SchematicNode map(CommandSender commandSender, String[] previousArguments, String s) {
return mapNode(SteamwarUser.get(0), previousArguments, s);
}
};
}
@Mapper("dirMapper") @Mapper("dirMapper")
public TypeMapper<SchematicNode> dirNodeTypeMapper() { public TypeMapper<SchematicNode> dirNodeTypeMapper() {
return new TypeMapper<SchematicNode>() { return new TypeMapper<SchematicNode>() {
@ -662,63 +839,21 @@ public class SchematicCommand extends SWCommand {
}; };
} }
private static List<String> getNodeTabcomplete(SteamwarUser user, String[] strings, String s) { @Mapper("dirStringMapper")
List<String> list = new ArrayList<>(); public TypeMapper<String> stringTabMapper() {
boolean sws = s.startsWith("/"); return new TypeMapper<String>() {
if(sws) { @Override
s = s.substring(1); public List<String> tabCompletes(CommandSender commandSender, String[] strings, String s) {
} List<String> list = getNodeTabcomplete(SteamwarUser.get(((Player) commandSender).getUniqueId()), strings, s);
if(s.contains("/")) { list.removeIf(s1 -> !s1.endsWith("/"));
String preTab = s.substring(0, s.lastIndexOf("/") + 1);
SchematicNode pa = mapNode(user, strings, preTab);
if(pa == null) return Collections.emptyList();
List<SchematicNode> nodes = SchematicNode.getSchematicNodeInNode(pa);
nodes.forEach(node -> list.add(node.generateBreadcrumbs(user)));
} else {
List<SchematicNode> nodes = SchematicNode.getSchematicsAccessibleByUser(user.getId(), 0);
nodes.forEach(node -> list.add((sws ?"/":"") + node.getName() + (node.isDir()?"/":"")));
}
list.remove("//copy");
return list; return list;
} }
private static SchematicNode mapNode(SteamwarUser user, String[] previousArguments, String s) { @Override
if(s.startsWith("/")) { public String map(CommandSender commandSender, String[] previousArguments, String s) {
s = s.substring(1); return s;
}
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);
}
} }
};
} }
@ClassMapper(SchematicNode.class) @ClassMapper(SchematicNode.class)
@ -751,19 +886,9 @@ public class SchematicCommand extends SWCommand {
}; };
} }
@Mapper("dirStringMapper") enum Extend {
public TypeMapper<String> stringTabMapper() { AUSFAHREN,
return new TypeMapper<String>() { NORMAL
@Override
public List<String> tabCompletes(CommandSender commandSender, String[] strings, String s) {
return getNodeTabcomplete(SteamwarUser.get(((Player) commandSender).getUniqueId()), strings, s);
}
@Override
public String map(CommandSender commandSender, String[] previousArguments, String s) {
return s;
}
};
} }
} }