More Refactoring
Signed-off-by: Chaoscaot <chaoscaot444@gmail.com>
Dieser Commit ist enthalten in:
Ursprung
ad5e7f977b
Commit
2f9cdff26d
@ -39,7 +39,6 @@ import org.bukkit.entity.Player;
|
||||
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@ -51,23 +50,24 @@ public class SchematicCommand extends SWCommand {
|
||||
super("schematic", "/schematic", "schem", "/schem");
|
||||
}
|
||||
|
||||
@Register(help = true)
|
||||
public void genericHelp(Player player, String... args) {
|
||||
player.sendMessage(SchematicSystem.PREFIX + "Befehle§8:");
|
||||
player.sendMessage("§8/§eschem gui §8- §7Öffnet die Schematic-GUI");
|
||||
player.sendMessage("§8/§eschem list §8- §7Zeigt dir deine Schematics an");
|
||||
player.sendMessage("§8/§eschem list public §8- §7Zeigt alle Public-Schematics");
|
||||
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 mkdirs §8[§7Ordner§8] - §7Erstelle einen Leeren Ordner");
|
||||
player.sendMessage("§8/§eschem move §8[§7Schematic§8] [§7Neuer Pfad§8] - §7Verschiebe eine Schematic");
|
||||
private static List<String> getNodeTabcomplete(SteamwarUser user, String[] strings, String s) {
|
||||
List<String> list = new ArrayList<>();
|
||||
boolean sws = s.startsWith("/");
|
||||
if (sws) {
|
||||
s = s.substring(1);
|
||||
}
|
||||
if (s.contains("/")) {
|
||||
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;
|
||||
}
|
||||
|
||||
@Register("gui")
|
||||
@ -87,24 +87,66 @@ public class SchematicCommand extends SWCommand {
|
||||
renderSchemlist(player, SchematicNode.getSchematicsAccessibleByUser(SteamwarUser.get(player.getUniqueId()).getId(), 0), page, "", false);
|
||||
}
|
||||
|
||||
@Register("list")
|
||||
public void schemList(Player player, @Mapper("dirMapper") SchematicNode node) {
|
||||
SteamwarUser user = SteamwarUser.get(player.getUniqueId());
|
||||
if(!node.isDir()) {
|
||||
player.sendMessage("haethate");
|
||||
private 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 {
|
||||
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")
|
||||
public void schemList(Player player, @Mapper("dirMapper") SchematicNode node, int page) {
|
||||
SteamwarUser user = SteamwarUser.get(player.getUniqueId());
|
||||
if(!node.isDir()) {
|
||||
player.sendMessage("haethate");
|
||||
} else {
|
||||
renderSchemlist(player, SchematicNode.getSchematicNodeInNode(node), page, node.generateBreadcrumbs(user), node.getOwner()==0);
|
||||
}
|
||||
@Register(help = true)
|
||||
public void genericHelp(Player player, String... args) {
|
||||
player.sendMessage(SchematicSystem.PREFIX + "Befehle§8:");
|
||||
player.sendMessage("§8/§eschem gui §8- §7Öffnet die Schematic-GUI");
|
||||
player.sendMessage("§8/§eschem list §8- §7Zeigt dir deine Schematics an");
|
||||
player.sendMessage("§8/§eschem list public §8- §7Zeigt alle Public-Schematics");
|
||||
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"})
|
||||
@ -135,20 +177,54 @@ public class SchematicCommand extends SWCommand {
|
||||
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")
|
||||
public void schemInfo(Player player, SchematicNode node) {
|
||||
SteamwarUser user = SteamwarUser.get(player.getUniqueId());
|
||||
player.sendMessage("§7--==( §e" + node.getName() + " §7)==--");
|
||||
player.sendMessage("§7Name: §e" + node.generateBreadcrumbs(user));
|
||||
player.sendMessage("§7Besitzer: §e" + SteamwarUser.get(node.getOwner()).getUserName());
|
||||
player.sendMessage("§7Ordner: §e" + (node.getParent() == null || node.getParent() == 0?"/":node.getParentNode().generateBreadcrumbs(user)));
|
||||
player.sendMessage("§7Ordner: §e" + (node.getParent() == null || node.getParent() == 0 ? "/" : node.getParentNode().generateBreadcrumbs(user)));
|
||||
player.sendMessage("§7Letzes Update: §e" + node.getLastUpdate().toLocalDateTime().format(DateTimeFormatter.ofPattern("HH:mm dd.MM.yyyy", Locale.GERMAN)));
|
||||
player.sendMessage("§7Typ: §e" + (node.isDir()?"§9DIR":node.getSchemtype().name()));
|
||||
if(!node.isDir()) {
|
||||
if(node.getRank() > 0) {
|
||||
player.sendMessage("§7Typ: §e" + (node.isDir() ? "§9DIR" : node.getSchemtype().name()));
|
||||
if (!node.isDir()) {
|
||||
if (node.getRank() > 0) {
|
||||
player.sendMessage("§7Rang: §e" + node.getRank());
|
||||
}
|
||||
player.sendMessage("§7Format: §e" + (node.getSchemFormat()?".schem":".schematic"));
|
||||
player.sendMessage("§7Format: §e" + (node.getSchemFormat() ? ".schem" : ".schematic"));
|
||||
List<CheckedSchematic> checkedSchematics = CheckedSchematic.getLastDeclined(player.getUniqueId());
|
||||
for (CheckedSchematic checkedSchematic : checkedSchematics) {
|
||||
if (checkedSchematic.getSchemName().equals(node.getName()) &&
|
||||
@ -160,29 +236,35 @@ public class SchematicCommand extends SWCommand {
|
||||
}
|
||||
List<String> schematicMembers = new ArrayList<>();
|
||||
NodeMember.getNodeMembers(node.getId()).forEach(nodeMember -> schematicMembers.add(SteamwarUser.get(nodeMember.getMember()).getUserName()));
|
||||
if(!schematicMembers.isEmpty()) {
|
||||
player.sendMessage("§7Mitglieder: §e" + schematicMembers.toString());
|
||||
if (!schematicMembers.isEmpty()) {
|
||||
player.sendMessage("§7Mitglieder: §e" + schematicMembers);
|
||||
}
|
||||
|
||||
TextComponent base = new TextComponent();
|
||||
|
||||
if(!node.isDir()) {
|
||||
if (!node.isDir()) {
|
||||
TextComponent load = new TextComponent("[Laden] ");
|
||||
load.setColor(ChatColor.GREEN);
|
||||
load.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText("§eSchematic laden")));
|
||||
load.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/schem load " + (node.getOwner()==0?"public ":"") + node.generateBreadcrumbs(user)));
|
||||
load.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/schem load " + (node.getOwner() == 0 ? "public " : "") + node.generateBreadcrumbs(user)));
|
||||
base.addExtra(load);
|
||||
|
||||
if(node.getOwner() == user.getId()) {
|
||||
if (node.getOwner() == user.getId()) {
|
||||
TextComponent download = new TextComponent("[Download] ");
|
||||
download.setColor(ChatColor.GOLD);
|
||||
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)));
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
if(node.getOwner() == user.getId()) {
|
||||
if (node.getOwner() == user.getId()) {
|
||||
TextComponent addMember = new TextComponent("[Hinzufügen] ");
|
||||
addMember.setColor(ChatColor.AQUA);
|
||||
addMember.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText("§eMember hinzufügen")));
|
||||
@ -195,30 +277,32 @@ public class SchematicCommand extends SWCommand {
|
||||
delMember.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/schem delmember " + node.generateBreadcrumbs(user) + " "));
|
||||
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.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)));
|
||||
base.addExtra(delete);
|
||||
}
|
||||
|
||||
|
||||
|
||||
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("load")
|
||||
public void loadSchem(Player player, SchematicNode node) {
|
||||
if(node.isDir()) {
|
||||
if (node.isDir()) {
|
||||
player.sendMessage(SchematicSystem.PREFIX + "§cDu kannst keine Ordner Laden");
|
||||
return;
|
||||
}
|
||||
@ -226,7 +310,7 @@ public class SchematicCommand extends SWCommand {
|
||||
try {
|
||||
node.loadToPlayer(player);
|
||||
player.sendMessage(SchematicSystem.PREFIX + "§7Schematic §e" + node.getName() + " §7geladen!");
|
||||
Bukkit.getLogger().log(Level.INFO, "{} has loaded Schematic {} {}", new Object[] {player.getName(), node.getId(), node.getName()});
|
||||
Bukkit.getLogger().log(Level.INFO, "{} has loaded Schematic {} {}", new Object[]{player.getName(), node.getId(), node.getName()});
|
||||
} catch (NoClipboardException e) {
|
||||
player.sendMessage(SchematicSystem.PREFIX + "§cEs konnte keine Daten in der Schematic gefunden werden.");
|
||||
} catch (Exception e) {
|
||||
@ -235,86 +319,81 @@ 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("s")
|
||||
public void saveSchem(Player player, @Mapper("dirStringMapper") String name) {
|
||||
SteamwarUser user = SteamwarUser.get(player.getUniqueId());
|
||||
if(name.startsWith("/")) name = name.substring(1);
|
||||
if (name.startsWith("/")) name = name.substring(1);
|
||||
String[] layers = name.split("/");
|
||||
if(invalidSchemName(player, layers)) return;
|
||||
if (invalidSchemName(player, layers)) return;
|
||||
SchematicNode currentNode = mkdirs(layers, user, 1);
|
||||
|
||||
SchematicNode node = SchematicNode.getSchematicInParent(layers[layers.length-1], currentNode==null?0:currentNode.getId());
|
||||
if(node != null && !node.getSchemtype().writeable()) {
|
||||
SchematicNode node = SchematicNode.getSchematicInParent(layers[layers.length - 1], currentNode == null ? 0 : currentNode.getId());
|
||||
if (node != null && !node.getSchemtype().writeable()) {
|
||||
player.sendMessage(SchematicSystem.PREFIX + "§cDu darfst diese Schematic nicht überschreiben");
|
||||
return;
|
||||
}
|
||||
|
||||
boolean newSchem = false;
|
||||
if(node == null) {
|
||||
if (node == null) {
|
||||
newSchem = true;
|
||||
node = SchematicNode.createSchematic(user.getId(), layers[layers.length-1], currentNode==null?0:currentNode.getId());
|
||||
node = SchematicNode.createSchematic(user.getId(), layers[layers.length - 1], currentNode == null ? 0 : currentNode.getId());
|
||||
}
|
||||
|
||||
try {
|
||||
node.saveFromPlayer(player);
|
||||
}catch (NoClipboardException e) {
|
||||
} catch (NoClipboardException e) {
|
||||
player.sendMessage(SchematicSystem.PREFIX + "§cDein Clipboard ist leer");
|
||||
if(newSchem)
|
||||
if (newSchem)
|
||||
node.delete();
|
||||
return;
|
||||
}catch(Exception ex){
|
||||
} catch (Exception ex) {
|
||||
Bukkit.getLogger().log(Level.SEVERE, "Could not save schematic", ex);
|
||||
player.sendMessage(SchematicSystem.PREFIX + "§cFehler beim Speichern der Schematic.");
|
||||
if(newSchem)
|
||||
if (newSchem)
|
||||
node.delete();
|
||||
return;
|
||||
}
|
||||
|
||||
if (newSchem)
|
||||
if (newSchem) {
|
||||
player.sendMessage(SchematicSystem.PREFIX + "Schematic §e" + node.getName() + " §7gespeichert");
|
||||
else
|
||||
} else {
|
||||
player.sendMessage(SchematicSystem.PREFIX + "Schematic §e" + node.getName() + " §7überschrieben");
|
||||
}
|
||||
}
|
||||
|
||||
@Register("addmember")
|
||||
public void addMember(Player player, SchematicNode node, SteamwarUser target) {
|
||||
SteamwarUser user = SteamwarUser.get(player.getUniqueId());
|
||||
if(node.getOwner() != user.getId()) {
|
||||
if (node.getOwner() != user.getId()) {
|
||||
player.sendMessage(SchematicSystem.PREFIX + "§cDu kannst nur auf deine eigenen Sachen jemanden hinzufügen.");
|
||||
return;
|
||||
}
|
||||
|
||||
if(user.getId() == target.getId()) {
|
||||
if (user.getId() == target.getId()) {
|
||||
player.sendMessage(SchematicSystem.PREFIX + "§cAlso bitte: Das ist deine eigene Schematic!");
|
||||
return;
|
||||
}
|
||||
|
||||
NodeMember member = NodeMember.getNodeMember(node.getId(), target.getId());
|
||||
if(member != null) {
|
||||
if (NodeMember.getNodeMember(node.getId(), target.getId()) != null) {
|
||||
player.sendMessage(SchematicSystem.PREFIX + "§cDieser Spieler ist bereits auf diese Schematic geaddet");
|
||||
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 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());
|
||||
}
|
||||
}
|
||||
|
||||
@Register("delmember")
|
||||
@Register("remmember")
|
||||
public void delMember(Player player, SchematicNode node, @Mapper("memberMapper") NodeMember member) {
|
||||
SteamwarUser user = SteamwarUser.get(player.getUniqueId());
|
||||
|
||||
if(node.getOwner() != user.getId()) {
|
||||
if (node.getOwner() != user.getId()) {
|
||||
player.sendMessage(SchematicSystem.PREFIX + "§cDu kannst nur auf deine eigenen Sachen jemanden entfernen.");
|
||||
return;
|
||||
}
|
||||
@ -322,40 +401,15 @@ public class SchematicCommand extends SWCommand {
|
||||
member.delete();
|
||||
|
||||
List<SchematicNode> nodes = SchematicNode.deepGet(node.getId(), node1 -> node1.getOwner() != user.getId());
|
||||
if(!nodes.isEmpty()) {
|
||||
if (!nodes.isEmpty()) {
|
||||
SteamwarUser target = SteamwarUser.get(member.getMember());
|
||||
for (SchematicNode schematicNode : nodes) {
|
||||
SchematicNode newNode = mkdirs(schematicNode.generateBreadcrumbs(user).split("/"), target, 1);
|
||||
schematicNode.setParent(newNode==null?0:newNode.getId());
|
||||
schematicNode.setParent(newNode == null ? 0 : newNode.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Register("download")
|
||||
public void download(Player player, SchematicNode node) {
|
||||
SteamwarUser user = SteamwarUser.get(player.getUniqueId());
|
||||
if(node.getOwner() != user.getId()) {
|
||||
player.sendMessage("§cDu darfst nur deine eigenen Schematics herunterladen!");
|
||||
return;
|
||||
}
|
||||
|
||||
player.sendMessage(SchematicSystem.PREFIX + "Dein Download Link:");
|
||||
player.sendMessage(DownloadSchematic.getLink(node));
|
||||
}
|
||||
|
||||
@Register("dir")
|
||||
@Register("ordner")
|
||||
@Register("mkdir")
|
||||
public void mkdir(Player player, @Mapper("dirStringMapper") String name) {
|
||||
SteamwarUser user = SteamwarUser.get(player.getUniqueId());
|
||||
if(name.startsWith("/")) name = name.substring(1);
|
||||
if(name.endsWith("/")) name = name.substring(0, name.length()-1);
|
||||
String[] layers = name.split("/");
|
||||
if(invalidSchemName(player, layers)) return;
|
||||
SchematicNode node = mkdirs(layers, user, 0);
|
||||
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());
|
||||
@ -371,13 +425,38 @@ public class SchematicCommand extends SWCommand {
|
||||
});
|
||||
}
|
||||
|
||||
@Register("download")
|
||||
public void download(Player player, SchematicNode node) {
|
||||
SteamwarUser user = SteamwarUser.get(player.getUniqueId());
|
||||
if (node.getOwner() != user.getId()) {
|
||||
player.sendMessage("§cDu darfst nur deine eigenen Schematics herunterladen!");
|
||||
return;
|
||||
}
|
||||
|
||||
player.sendMessage(SchematicSystem.PREFIX + "Dein Download Link:");
|
||||
player.sendMessage(DownloadSchematic.getLink(node));
|
||||
}
|
||||
|
||||
@Register("dir")
|
||||
@Register("ordner")
|
||||
@Register("mkdir")
|
||||
public void mkdir(Player player, @Mapper("dirStringMapper") String name) {
|
||||
SteamwarUser user = SteamwarUser.get(player.getUniqueId());
|
||||
if (name.startsWith("/")) name = name.substring(1);
|
||||
if (name.endsWith("/")) name = name.substring(0, name.length() - 1);
|
||||
String[] layers = name.split("/");
|
||||
if (invalidSchemName(player, layers)) return;
|
||||
SchematicNode node = mkdirs(layers, user, 0);
|
||||
player.sendMessage(SchematicSystem.PREFIX + "§7Ordner §e" + node.generateBreadcrumbs(user) + " §7erstellt");
|
||||
}
|
||||
|
||||
@Register("changetype")
|
||||
public void changeType(Player player, SchematicNode node) {
|
||||
SteamwarUser user = SteamwarUser.get(player.getUniqueId());
|
||||
TextComponent base = new TextComponent();
|
||||
|
||||
SchematicType.values().forEach(type -> {
|
||||
if(!type.isAssignable()) return;
|
||||
if (!type.isAssignable()) return;
|
||||
|
||||
TextComponent component = new TextComponent(type.name() + " ");
|
||||
component.setColor(ChatColor.GRAY);
|
||||
@ -392,90 +471,186 @@ public class SchematicCommand extends SWCommand {
|
||||
|
||||
@Register("changetype")
|
||||
public void changeType(Player player, SchematicNode node, SchematicType type) {
|
||||
if(node.isDir()) {
|
||||
changeType(player, node, type, null);
|
||||
}
|
||||
|
||||
@Register("changetype")
|
||||
public void changeType(Player player, SchematicNode node, SchematicType type, Extend extend) {
|
||||
if (node.isDir()) {
|
||||
player.sendMessage(SchematicSystem.PREFIX + "§cOrdner haben keinen Typen.");
|
||||
return;
|
||||
}
|
||||
|
||||
if(node.getType().equals(type.toDB())) {
|
||||
if (node.getType().equals(type.toDB())) {
|
||||
player.sendMessage(SchematicSystem.PREFIX + "§cDie Schematic hat schon diesen Typen");
|
||||
return;
|
||||
}
|
||||
|
||||
if(type.writeable()) {
|
||||
if (type.writeable()) {
|
||||
node.setType(type.toDB());
|
||||
player.sendMessage(SchematicSystem.PREFIX + "§aSchematictyp geändert");
|
||||
} else if(type.fightType()) {
|
||||
if(node.getSchemtype().check()){
|
||||
} else if (type.fightType()) {
|
||||
if (node.getSchemtype().check()) {
|
||||
player.sendMessage(SchematicSystem.PREFIX + "§cDu hast diese Schematic bereits eingesendet");
|
||||
return;
|
||||
}
|
||||
|
||||
AutoCheckResult result = CheckSchemType.get(type).autoCheck(node);
|
||||
Collection<String> errors = result.errors();
|
||||
for(String warning : result.warnings()){
|
||||
for (String warning : result.warnings()) {
|
||||
player.sendMessage(" §e" + warning);
|
||||
}
|
||||
for(String error : errors){
|
||||
for (String error : errors) {
|
||||
player.sendMessage(" §c" + error);
|
||||
}
|
||||
if(!errors.isEmpty()){
|
||||
if (!errors.isEmpty()) {
|
||||
player.sendMessage(SchematicSystem.PREFIX + "§cDie Schematic ist nicht regelkonform");
|
||||
return;
|
||||
}
|
||||
|
||||
if (extend == null) {
|
||||
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);
|
||||
player.sendMessage(SchematicSystem.PREFIX + "§aDer Vorbereitungsserver wird gestartet");
|
||||
player.closeInventory();
|
||||
});
|
||||
inv.setItem(8, SWItem.getDye(7), (byte)7, "§eDirekt einsenden", click -> {
|
||||
inv.setItem(8, SWItem.getDye(7), (byte) 7, "§eDirekt einsenden", click -> {
|
||||
node.setType(type.checkType().toDB());
|
||||
player.sendMessage(SchematicSystem.PREFIX + "§aDie Schematic wird zeitnah überprüft");
|
||||
player.closeInventory();
|
||||
});
|
||||
inv.setCallback(-999, click -> player.closeInventory());
|
||||
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")
|
||||
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());
|
||||
if(node.getOwner() != user.getId()) {
|
||||
if (node.getOwner() != user.getId()) {
|
||||
player.sendMessage(SchematicSystem.PREFIX + "§cDas kannst du nur bei deinen eigenen Schems machen");
|
||||
return;
|
||||
}
|
||||
if(name.startsWith("/")) name = name.substring(1);
|
||||
if(name.endsWith("/")) name = name.substring(0, name.length()-1);
|
||||
String[] layers = name.split("/");
|
||||
if(invalidSchemName(player, layers)) return;
|
||||
if(name.contains("/")) {
|
||||
SchematicNode newNode = mkdirs(layers, user, 1);
|
||||
node.setParent(newNode.getId());
|
||||
} else {
|
||||
if (name.equals("/")) {
|
||||
node.setParent(0);
|
||||
} else {
|
||||
if (name.startsWith("/")) name = name.substring(1);
|
||||
if (name.endsWith("/")) name = name.substring(0, name.length() - 1);
|
||||
String[] layers = name.split("/");
|
||||
if (invalidSchemName(player, layers)) return;
|
||||
SchematicNode newNode = mkdirs(layers, user, 0);
|
||||
node.setParent(newNode.getId());
|
||||
}
|
||||
String schemName = layers[layers.length-1];
|
||||
node.setName(schemName);
|
||||
player.sendMessage(SchematicSystem.PREFIX + "§7Die Schematic heist nun §7" + node.generateBreadcrumbs(user));
|
||||
player.sendMessage(SchematicSystem.PREFIX + "§7Die Schematic ist nun unter §e" + node.generateBreadcrumbs(user) + " §7zu finden");
|
||||
}
|
||||
|
||||
private boolean invalidSchemName(Player player, String[] layers){
|
||||
@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) {
|
||||
for (String layer : layers) {
|
||||
if(layer.isEmpty()) {
|
||||
if (layer.isEmpty()) {
|
||||
player.sendMessage(SchematicSystem.PREFIX + "§cDeine Ordner brauchen schon einen Namen!");
|
||||
return true;
|
||||
}
|
||||
if(layer.contains("/") ||
|
||||
if (layer.contains("/") ||
|
||||
layer.contains("\\") ||
|
||||
layer.contains("<") ||
|
||||
layer.contains(">") ||
|
||||
layer.contains("^") ||
|
||||
layer.contains("°") ||
|
||||
layer.contains("'") ||
|
||||
layer.contains("\"")){
|
||||
layer.contains("\"")) {
|
||||
player.sendMessage(SchematicSystem.PREFIX + "§cDer angegebene Schematicname enthält verbotene Zeichen");
|
||||
return true;
|
||||
}
|
||||
@ -488,13 +663,13 @@ public class SchematicCommand extends SWCommand {
|
||||
for (int i = 0; i < layers.length - minus; i++) {
|
||||
int finalI = i;
|
||||
List<SchematicNode> nodes;
|
||||
if(currentNode == null) {
|
||||
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()) {
|
||||
currentNode = SchematicNode.createSchematicDirectory(user.getId(), layers[i], currentNode==null?0:currentNode.getId());
|
||||
if (nodes.isEmpty()) {
|
||||
currentNode = SchematicNode.createSchematicDirectory(user.getId(), layers[i], currentNode == null ? 0 : currentNode.getId());
|
||||
} else {
|
||||
currentNode = nodes.get(0);
|
||||
}
|
||||
@ -502,18 +677,21 @@ public class SchematicCommand extends SWCommand {
|
||||
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) {
|
||||
nodes.sort(Comparator.comparing(SchematicNode::getName));
|
||||
SteamwarUser user = SteamwarUser.get(player.getUniqueId());
|
||||
int pageCount = (int) Math.ceil(nodes.size() / (double) CHUNK_SIZE);
|
||||
|
||||
player.sendMessage("§7--==( §eSchematics §8(§e" + nodes.size() + "§8) §7)==--");
|
||||
player.sendMessage("§7Aktueller Pfad: §e" + (breadcrumbs.isEmpty()?"/":breadcrumbs));
|
||||
if(!breadcrumbs.isEmpty()) {
|
||||
player.sendMessage("§7Aktueller Pfad: §e" + (breadcrumbs.isEmpty() ? "/" : breadcrumbs));
|
||||
if (!breadcrumbs.isEmpty()) {
|
||||
TextComponent back = new TextComponent("§e../");
|
||||
String str = breadcrumbs.substring(0, Math.max(0, breadcrumbs.substring(0, breadcrumbs.length() - 1).lastIndexOf("/")));
|
||||
back.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§eZurück gehen" + str).create()));
|
||||
back.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/schem list " + (isPublic?"public":"") + " " + str));
|
||||
back.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/schem list " + (isPublic ? "public" : "") + " " + str));
|
||||
|
||||
player.spigot().sendMessage(back);
|
||||
}
|
||||
@ -522,11 +700,11 @@ public class SchematicCommand extends SWCommand {
|
||||
|
||||
StringBuilder nodeString = new StringBuilder();
|
||||
|
||||
if(node.isDir()) {
|
||||
if (node.isDir()) {
|
||||
nodeString.append("§9DIR §e");
|
||||
} else {
|
||||
SchematicType type = node.getSchemtype();
|
||||
if(type != SchematicType.Normal) {
|
||||
if (type != SchematicType.Normal) {
|
||||
nodeString.append("§8§l")
|
||||
.append(type.getKuerzel().toUpperCase())
|
||||
.append(" ");
|
||||
@ -536,73 +714,49 @@ public class SchematicCommand extends SWCommand {
|
||||
|
||||
nodeString.append(node.getName());
|
||||
|
||||
if(node.isDir()) {
|
||||
if (node.isDir()) {
|
||||
nodeString.append("/");
|
||||
}
|
||||
|
||||
if(node.getOwner() != user.getId()) {
|
||||
if (node.getOwner() != user.getId()) {
|
||||
nodeString.append(" §8von §7")
|
||||
.append(SteamwarUser.get(node.getOwner()).getUserName());
|
||||
}
|
||||
TextComponent schematics = new TextComponent(nodeString.toString());
|
||||
|
||||
if(node.isDir()) {
|
||||
if (node.isDir()) {
|
||||
schematics.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§eOrdner anzeigen").create()));
|
||||
schematics.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/schem list " + (isPublic?"public":"") + " " + breadcrumbs + node.getName() + "/"));
|
||||
schematics.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/schem list " + (isPublic ? "public" : "") + " " + breadcrumbs + node.getName() + "/"));
|
||||
} else {
|
||||
schematics.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§eSchematic verwalten").create()));
|
||||
schematics.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/schem info " + (isPublic?"public":"") + " " + breadcrumbs + node.getName()));
|
||||
schematics.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/schem info " + (isPublic ? "public" : "") + " " + breadcrumbs + node.getName()));
|
||||
}
|
||||
|
||||
player.spigot().sendMessage(schematics);
|
||||
}
|
||||
|
||||
TextComponent beforePage = new TextComponent("««");
|
||||
if(chunk > 0){
|
||||
if (chunk > 0) {
|
||||
beforePage.setColor(ChatColor.YELLOW);
|
||||
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)));
|
||||
}else
|
||||
beforePage.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/schem list " + (isPublic ? "public" : "") + " " + breadcrumbs + " " + (chunk - 1)));
|
||||
} else {
|
||||
beforePage.setColor(ChatColor.RED);
|
||||
}
|
||||
|
||||
TextComponent nextPage = new TextComponent(" Seite (" + (chunk + 1) + "/" + Math.max(pageCount, 1) + ") »»");
|
||||
if(chunk < pageCount-1){
|
||||
if (chunk < pageCount - 1) {
|
||||
nextPage.setColor(ChatColor.YELLOW);
|
||||
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)));
|
||||
}else
|
||||
nextPage.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/schem list " + (isPublic ? "public" : "") + " " + breadcrumbs + " " + (chunk + 1)));
|
||||
} else {
|
||||
nextPage.setColor(ChatColor.RED);
|
||||
}
|
||||
|
||||
beforePage.addExtra(nextPage);
|
||||
player.spigot().sendMessage(beforePage);
|
||||
}
|
||||
|
||||
private final TypeMapper<SchematicNode> schematicCommandTypeMapper = nodeTypeMapper();
|
||||
private final TypeMapper<SchematicNode> publicCommandTypeMapper = publicNodeTypeMapper();
|
||||
|
||||
@Mapper("memberMapper")
|
||||
public TypeMapper<NodeMember> nodeMemberTypeMapper() {
|
||||
return new TypeMapper<NodeMember>() {
|
||||
@Override
|
||||
public NodeMember map(CommandSender commandSender, String[] previousArguments, String s) {
|
||||
SchematicNode node = schematicCommandTypeMapper.map(commandSender, previousArguments, previousArguments[previousArguments.length - 1]);
|
||||
SteamwarUser user = SteamwarUser.get(s);
|
||||
return NodeMember.getNodeMember(node.getId(), user.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabCompletes(CommandSender commandSender, String[] strings, String s) {
|
||||
List<String> list = new ArrayList<>();
|
||||
SchematicNode node = schematicCommandTypeMapper.map(commandSender, strings, strings[strings.length - 1]);
|
||||
if(node == null) {
|
||||
return list;
|
||||
}
|
||||
node.getMembers().forEach(nodeMember -> list.add(SteamwarUser.get(nodeMember.getMember()).getUserName()));
|
||||
return list;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Mapper("publicMapper")
|
||||
public TypeMapper<SchematicNode> publicNodeTypeMapper() {
|
||||
return new TypeMapper<SchematicNode>() {
|
||||
@ -618,6 +772,29 @@ public class SchematicCommand extends SWCommand {
|
||||
};
|
||||
}
|
||||
|
||||
@Mapper("memberMapper")
|
||||
public TypeMapper<NodeMember> nodeMemberTypeMapper() {
|
||||
return new TypeMapper<NodeMember>() {
|
||||
@Override
|
||||
public NodeMember map(CommandSender commandSender, String[] previousArguments, String s) {
|
||||
SchematicNode node = schematicCommandTypeMapper.map(commandSender, previousArguments, previousArguments[previousArguments.length - 1]);
|
||||
SteamwarUser user = SteamwarUser.get(s);
|
||||
return NodeMember.getNodeMember(node.getId(), user.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabCompletes(CommandSender commandSender, String[] strings, String s) {
|
||||
List<String> list = new ArrayList<>();
|
||||
SchematicNode node = schematicCommandTypeMapper.map(commandSender, strings, strings[strings.length - 1]);
|
||||
if (node == null) {
|
||||
return list;
|
||||
}
|
||||
node.getMembers().forEach(nodeMember -> list.add(SteamwarUser.get(nodeMember.getMember()).getUserName()));
|
||||
return list;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Mapper("dirMapper")
|
||||
public TypeMapper<SchematicNode> dirNodeTypeMapper() {
|
||||
return new TypeMapper<SchematicNode>() {
|
||||
@ -631,7 +808,7 @@ public class SchematicCommand extends SWCommand {
|
||||
@Override
|
||||
public SchematicNode map(CommandSender commandSender, String[] previousArguments, String s) {
|
||||
SchematicNode result = schematicCommandTypeMapper.map(commandSender, previousArguments, s);
|
||||
if(result == null || !result.isDir()) {
|
||||
if (result == null || !result.isDir()) {
|
||||
return null;
|
||||
} else {
|
||||
return result;
|
||||
@ -653,7 +830,7 @@ public class SchematicCommand extends SWCommand {
|
||||
@Override
|
||||
public SchematicNode map(CommandSender commandSender, String[] previousArguments, String s) {
|
||||
SchematicNode result = publicCommandTypeMapper.map(commandSender, previousArguments, s);
|
||||
if(result == null || !result.isDir()) {
|
||||
if (result == null || !result.isDir()) {
|
||||
return null;
|
||||
} else {
|
||||
return result;
|
||||
@ -662,63 +839,21 @@ public class SchematicCommand extends SWCommand {
|
||||
};
|
||||
}
|
||||
|
||||
private static List<String> getNodeTabcomplete(SteamwarUser user, String[] strings, String s) {
|
||||
List<String> list = new ArrayList<>();
|
||||
boolean sws = s.startsWith("/");
|
||||
if(sws) {
|
||||
s = s.substring(1);
|
||||
}
|
||||
if(s.contains("/")) {
|
||||
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");
|
||||
@Mapper("dirStringMapper")
|
||||
public TypeMapper<String> stringTabMapper() {
|
||||
return new TypeMapper<String>() {
|
||||
@Override
|
||||
public List<String> tabCompletes(CommandSender commandSender, String[] strings, String s) {
|
||||
List<String> list = getNodeTabcomplete(SteamwarUser.get(((Player) commandSender).getUniqueId()), strings, s);
|
||||
list.removeIf(s1 -> !s1.endsWith("/"));
|
||||
return list;
|
||||
}
|
||||
|
||||
private 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);
|
||||
}
|
||||
@Override
|
||||
public String map(CommandSender commandSender, String[] previousArguments, String s) {
|
||||
return s;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@ClassMapper(SchematicNode.class)
|
||||
@ -751,19 +886,9 @@ public class SchematicCommand extends SWCommand {
|
||||
};
|
||||
}
|
||||
|
||||
@Mapper("dirStringMapper")
|
||||
public TypeMapper<String> stringTabMapper() {
|
||||
return new TypeMapper<String>() {
|
||||
@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;
|
||||
}
|
||||
};
|
||||
enum Extend {
|
||||
AUSFAHREN,
|
||||
NORMAL
|
||||
}
|
||||
|
||||
}
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren