13
0

Merge pull request 'Schemnodes Schematic System' (#93) from nodes into master

Reviewed-on: #93
Reviewed-by: Lixfel <lixfel@steamwar.de>
Dieser Commit ist enthalten in:
Lixfel 2021-12-27 16:30:24 +01:00
Commit 13be5f1725
8 geänderte Dateien mit 1155 neuen und 641 gelöschten Zeilen

Datei anzeigen

@ -23,7 +23,7 @@ import com.sk89q.worldedit.extent.clipboard.Clipboard;
import de.steamwar.core.Core; import de.steamwar.core.Core;
import de.steamwar.core.VersionDependent; import de.steamwar.core.VersionDependent;
import de.steamwar.sql.NoClipboardException; import de.steamwar.sql.NoClipboardException;
import de.steamwar.sql.Schematic; import de.steamwar.sql.SchematicNode;
import de.steamwar.sql.SchematicType; import de.steamwar.sql.SchematicType;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
@ -88,7 +88,7 @@ public class CheckSchemType {
return types.get(type); return types.get(type);
} }
public AutoCheckResult autoCheck(Schematic schematic) { public AutoCheckResult autoCheck(SchematicNode schematic) {
AutoCheckResult result = new AutoCheckResult(this); AutoCheckResult result = new AutoCheckResult(this);
Clipboard clipboard; Clipboard clipboard;
try { try {

Datei anzeigen

@ -31,7 +31,7 @@ public class SchematicSystem extends JavaPlugin {
public void onEnable() { public void onEnable() {
instance = this; instance = this;
getCommand("schem").setExecutor(new SchematicCommand()); new SchematicCommand();
} }
public static SchematicSystem getInstance() { public static SchematicSystem getInstance() {

Datei anzeigen

@ -19,11 +19,7 @@
package de.steamwar.schematicsystem.commands; package de.steamwar.schematicsystem.commands;
import com.google.common.collect.Lists; import de.steamwar.inventory.*;
import de.steamwar.inventory.SWAnvilInv;
import de.steamwar.inventory.SWInventory;
import de.steamwar.inventory.SWItem;
import de.steamwar.inventory.SWListInv;
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;
@ -32,10 +28,122 @@ import org.bukkit.event.inventory.ClickType;
import java.util.*; import java.util.*;
class GUI { import static de.steamwar.schematicsystem.commands.SchematicCommandUtils.*;
public class GUI {
private GUI() {} private GUI() {}
static void changeType(Player p, Schematic schem){ public static void list(Player player) {
SchematicSelector selector = new SchematicSelector(player, SchematicSelector.selectSchematic(), new SchematicSelectorInjectable() {
@Override
public String createTitle(Player player) {
return "Schematics {1}";
}
@Override
public void onListRender(SchematicSelector selector, SWListInv<SchematicNode> inv, SchematicNode parent) {
if(parent == null) {
inv.setItem(49, Material.AIR, "", clickType -> {});
} else {
inv.setItem(49, Material.ANVIL, "§7Ordnereigenschaften", clickType -> {
info(selector.getPlayer(), parent);
});
}
}
}, node -> info(player, node));
selector.setSingleDirOpen(false);
selector.open();
}
private static void info(Player player, SchematicNode node) {
SteamwarUser user = getUser(player);
SWInventory inv = new SWInventory(player, 9, node.generateBreadcrumbs(user));
if(!node.isDir()) {
inv.setItem(0, SWItem.getMaterial("WOOD_AXE"), "§eLaden", click -> {
player.closeInventory();
SchematicCommandUtils.loadSchem(player, node);
});
}
if(node.getOwner() == user.getId()){
if(!node.isDir() && node.getSchemtype().writeable()){
List<CheckedSchematic> checkedSchematics = CheckedSchematic.getLastDeclined(player.getUniqueId());
ListIterator<CheckedSchematic> i = checkedSchematics.listIterator(checkedSchematics.size());
while(i.hasPrevious()) {
CheckedSchematic checkedSchematic = i.previous();
if(checkedSchematic.getNode() == node.getId()) {
inv.setItem(1, SWItem.getDye(10), (byte) 10, "§eStatus " + node.getSchemtype().name(), Collections.singletonList("§7" + checkedSchematic.getDeclineReason()), false, click -> {});
break;
}
}
}
Material mat = SWItem.getMaterial(node.getItem());
inv.setItem(2, mat, "§e" + mat.name(), Arrays.asList("§7Zum Ändern", "§7anklicken"), false, click -> {
player.closeInventory();
changeItem(player, node);
});
if(!node.isDir()) {
inv.setItem(3, SWItem.getMaterial("CAULDRON_ITEM"), "§e" + node.getSchemtype().name(), Arrays.asList("§7Zum Ändern", "§7anklicken"), false, click -> {
player.closeInventory();
changeType(player, node);
});
inv.setItem(4, SWItem.getMaterial("MAGENTA_GLAZED_TERRACOTTA"), "§eDownload", click -> {
player.closeInventory();
SchematicCommandUtils.download(player, node);
});
}
SWItem skull = SWItem.getPlayerSkull("MHF_STEVE");
skull.setCallback(click -> {
player.closeInventory();
delmembers(player, node);
});
skull.setName("§eMitglieder");
inv.setItem(5, skull);
inv.setItem(6, Material.ARROW, "§eVerschieben", clickType -> {
SchematicSelector selector = new SchematicSelector(player, SchematicSelector.selectDirectory(), npar -> {
node.setParent(npar==null?null:npar.getId());
info(player, SchematicNode.getSchematicNode(node.getId()));
});
selector.open();
});
Material finalMat = mat;
inv.setItem(7, Material.NAME_TAG, "§eUmbenennen", clickType -> {
SWAnvilInv anvilInv = new SWAnvilInv(player, node.getName() + " umbenennen", node.getName());
anvilInv.setItem(finalMat);
anvilInv.setCallback(s -> {
if (!invalidSchemName(player, new String[]{s})) {
node.setName(s);
}
info(player, node);
});
anvilInv.open();
});
inv.setItem(8, SWItem.getDye(1), (byte) 1, "§cLöschen", click -> {
player.closeInventory();
delete(player, node);
});
}else{
if(!node.isDir()) {
inv.setItem(4, SWItem.getMaterial("CAULDRON_ITEM"), "§e" + node.getSchemtype().name(), click -> {});
}
SteamwarUser owneruser = SteamwarUser.get(node.getOwner());
SWItem skull = SWItem.getPlayerSkull(owneruser.getUserName());
skull.setName("§7von §e" + owneruser.getUserName());
inv.setItem(6, skull.getItemStack(), clickType -> {});
inv.setItem(8, SWItem.getDye(1), (byte) 1, "§cZugriff entfernen", click -> {
player.closeInventory();
delete(player, node);
});
}
inv.setCallback(-999, click -> player.closeInventory());
inv.open();
}
static void changeType(Player p, SchematicNode schem){
List<SWListInv.SWListEntry<SchematicType>> types = new LinkedList<>(); List<SWListInv.SWListEntry<SchematicType>> types = new LinkedList<>();
for(SchematicType type : SchematicType.values()){ for(SchematicType type : SchematicType.values()){
if(!type.isAssignable()) if(!type.isAssignable())
@ -49,18 +157,20 @@ class GUI {
} }
SWListInv<SchematicType> inv = new SWListInv<>(p, "Typ ändern", types, (clickType, schematicType) -> { SWListInv<SchematicType> inv = new SWListInv<>(p, "Typ ändern", types, (clickType, schematicType) -> {
SchematicCommand.changetype(p, schem, schematicType); p.closeInventory();
SchematicCommandUtils.changeType(p, schem, schematicType, null);
}); });
inv.setCallback(-999, (ClickType click) -> p.closeInventory()); inv.setCallback(-999, (ClickType click) -> p.closeInventory());
inv.open(); inv.open();
} }
private static void deleteOwn(Player p, Schematic schem){ private static void deleteOwn(Player p, SchematicNode schem){
SWInventory inv = new SWInventory(p, 9, schem.getSchemName() + " löschen"); SteamwarUser user = getUser(p);
SWInventory inv = new SWInventory(p, 9, schem.generateBreadcrumbs(user) + " löschen");
inv.setItem(0, SWItem.getDye(1), (byte) 1, "§eLöschen", click -> { inv.setItem(0, SWItem.getDye(1), (byte) 1, "§eLöschen", click -> {
schem.remove(); schem.delete();
p.sendMessage(SchematicSystem.PREFIX + "Schematic §e" + schem.getSchemName() + " §7gelöscht"); p.sendMessage(SchematicSystem.PREFIX + "Schematic §e" + schem.generateBreadcrumbs(user) + " §7gelöscht");
p.closeInventory(); p.closeInventory();
}); });
inv.setItem(8, SWItem.getDye(14), (byte) 14, "§cAbbruch", click -> p.closeInventory()); inv.setItem(8, SWItem.getDye(14), (byte) 14, "§cAbbruch", click -> p.closeInventory());
@ -68,13 +178,14 @@ class GUI {
inv.open(); inv.open();
} }
private static void deleteMembership(Player p, Schematic schem){ private static void deleteMembership(Player p, SchematicNode schem){
SWInventory inv = new SWInventory(p, 9, schem.getSchemName() + " entfernen"); SteamwarUser user = getUser(p);
SWInventory inv = new SWInventory(p, 9, schem.generateBreadcrumbs(user) + " entfernen");
inv.setItem(0, SWItem.getDye(1), (byte) 1, "§eZugriff entfernen", click -> { inv.setItem(0, SWItem.getDye(1), (byte) 1, "§eZugriff entfernen", click -> {
SchematicMember member = SchematicMember.getSchemMemberFromDB(schem.getSchemName(), schem.getSchemOwner(), SteamwarUser.get(p.getUniqueId()).getId()); NodeMember member = NodeMember.getNodeMember(schem.getId(), user.getId());
if(member != null) if(member != null)
member.remove(); member.delete();
p.sendMessage(SchematicSystem.PREFIX + "Zugriff zu Schematic §e" + schem.getSchemName() + " §7entfernt"); p.sendMessage(SchematicSystem.PREFIX + "Zugriff zu Schematic §e" + schem.generateBreadcrumbs(user) + " §7entfernt");
p.closeInventory(); p.closeInventory();
}); });
inv.setItem(8, SWItem.getDye(14), (byte) 14, "§cAbbruch", click -> p.closeInventory()); inv.setItem(8, SWItem.getDye(14), (byte) 14, "§cAbbruch", click -> p.closeInventory());
@ -82,22 +193,22 @@ class GUI {
inv.open(); inv.open();
} }
static void delete(Player p, Schematic schem){ static void delete(Player p, SchematicNode schem){
if(SteamwarUser.get(p.getUniqueId()).getId() == schem.getSchemOwner()) if(SteamwarUser.get(p.getUniqueId()).getId() == schem.getOwner())
deleteOwn(p, schem); deleteOwn(p, schem);
else else
deleteMembership(p, schem); deleteMembership(p, schem);
} }
static void delmembers(Player p, Schematic schem){ static void delmembers(Player p, SchematicNode schem){
List<SWListInv.SWListEntry<SchematicMember>> members = new LinkedList<>(); List<SWListInv.SWListEntry<NodeMember>> members = new LinkedList<>();
for(SchematicMember member : SchematicMember.getSchemMembers(schem.getSchemName(), schem.getSchemOwner())){ for(NodeMember member : schem.getMembers()){
SteamwarUser user = SteamwarUser.get(member.getMember()); SteamwarUser user = SteamwarUser.get(member.getMember());
members.add(new SWListInv.SWListEntry<>(SWItem.getPlayerSkull(user.getUserName()), member)); members.add(new SWListInv.SWListEntry<>(SWItem.getPlayerSkull(user.getUserName()), member));
} }
SWListInv<SchematicMember> inv = new SWListInv<>(p, "Mitglieder entfernen", members, (clickType, member) -> { SWListInv<NodeMember> inv = new SWListInv<>(p, "Mitglieder entfernen", members, (clickType, member) -> {
member.remove(); member.delete();
p.closeInventory(); p.closeInventory();
delmembers(p, schem); delmembers(p, schem);
}); });
@ -105,128 +216,11 @@ class GUI {
inv.open(); inv.open();
} }
private static void changeItem(Player p, Schematic schem){ private static void changeItem(Player p, SchematicNode schem){
List<SWListInv.SWListEntry<Material>> materials = new LinkedList<>(); UtilGui.openMaterialSelector(p, "Item ändern", material -> {
for(Material material : Material.values()){
if(material.name().startsWith("LEGACY_"))
continue;
SWItem item = new SWItem(material, "§7" + material.name());
if(item.getItemMeta() != null && material.isItem())
materials.add(new SWListInv.SWListEntry<>(item, material));
}
SWListInv<Material> inv = new SWListInv<>(p, "Item ändern", materials, (clickType, material) -> {
schem.setItem(material.name()); schem.setItem(material.name());
p.closeInventory(); p.closeInventory();
info(p, schem); info(p, schem);
}); });
inv.setCallback(-999, (ClickType click) -> p.closeInventory());
inv.open();
}
private static void info(Player p, Schematic schem){
SWInventory inv = new SWInventory(p, 9, schem.getSchemName());
if(schem.availible())
inv.setItem(0, SWItem.getMaterial("WOOD_AXE"), "§eLaden", click -> {
SchematicCommand.load(p, schem);
p.closeInventory();
});
if(schem.getSchemOwner() == SteamwarUser.get(p.getUniqueId()).getId()){
if(schem.getSchemType().writeable()){
List<CheckedSchematic> checkedSchematics = CheckedSchematic.getLastDeclined(p.getUniqueId());
ListIterator<CheckedSchematic> i = checkedSchematics.listIterator(checkedSchematics.size());
while(i.hasPrevious()) {
CheckedSchematic checkedSchematic = i.previous();
if(checkedSchematic.getSchemName().equals(schem.getSchemName()) &&
checkedSchematic.getSchemOwner() == schem.getSchemOwner()) {
inv.setItem(1, SWItem.getDye(10), (byte) 10, "§eStatus " + schem.getSchemType().name(), Collections.singletonList("§7" + checkedSchematic.getDeclineReason()), false, click -> {});
break;
}
}
}
Material mat = SWItem.getMaterial("CAULDRON_ITEM");
if(schem.getItem() != null && !schem.getItem().equals(""))
mat = SWItem.getMaterial(schem.getItem());
inv.setItem(2, mat, "§e" + mat.name(), Arrays.asList("§7Zum Ändern", "§7anklicken"), false, click -> {
p.closeInventory();
changeItem(p, schem);
});
if(schem.availible())
inv.setItem(4, SWItem.getMaterial("CAULDRON_ITEM"), "§e" + schem.getSchemType().name(), Arrays.asList("§7Zum Ändern", "§7anklicken"), false, click -> {
p.closeInventory();
changeType(p, schem);
});
inv.setItem(5, SWItem.getMaterial("MAGENTA_GLAZED_TERRACOTTA"), "§eDownload", click -> {
p.closeInventory();
SchematicCommand.download(p, schem);
});
SWItem skull = SWItem.getPlayerSkull("MHF_STEVE");
skull.setCallback(click -> {
p.closeInventory();
delmembers(p, schem);
});
skull.setName("§eMitglieder");
inv.setItem(6, skull);
inv.setItem(8, SWItem.getDye(1), (byte) 1, "§cLöschen", click -> {
p.closeInventory();
delete(p, schem);
});
}else{
inv.setItem(4, SWItem.getMaterial("CAULDRON_ITEM"), "§e" + schem.getSchemType().name(), click -> {});
SteamwarUser owneruser = SteamwarUser.get(schem.getSchemOwner());
SWItem skull = SWItem.getPlayerSkull(owneruser.getUserName());
skull.setName("§7von §e" + owneruser.getUserName());
inv.setItem(6, skull);
inv.setItem(8, SWItem.getDye(1), (byte) 1, "§cZugriff entfernen", click -> {
p.closeInventory();
delete(p, schem);
});
}
inv.setCallback(-999, click -> p.closeInventory());
inv.open();
}
static void list(Player p){
list(p, Schematic.getSchemsAccessibleByUser(SteamwarUser.get(p.getUniqueId()).getId()), false);
}
private static void list(Player p, List<Schematic> schems, boolean publics){
List<SWListInv.SWListEntry<Schematic>> schemList = new ArrayList<>();
for(Schematic schem : schems) {
Material m;
if (schem.getItem().isEmpty())
m = SWItem.getMaterial("CAULDRON_ITEM");
else
m = SWItem.getMaterial(schem.getItem());
SWItem item = new SWItem(m, "§e" + schem.getSchemName(), Collections.singletonList("§7" + schem.getSchemType().name()), !schem.getSchemType().writeable(), click -> {});
if(schem.getRank() > 0)
item.setLore(Lists.newArrayList("§7" + schem.getSchemType().name(), "§8Rang " + schem.getRank()));
schemList.add(new SWListInv.SWListEntry<>(item, schem));
}
SWListInv<Schematic> inv = new SWListInv<>(p, "§eSchematicliste", false, schemList, (clickType, schem) -> info(p, schem));
if(publics)
inv.setItem(48, Material.BUCKET, "§7Eigene Schematics", clickType -> list(p));
else
inv.setItem(48, Material.GLASS, "§7Public Schematics", clickType -> list(p, Schematic.getSchemsAccessibleByUser(0), true));
inv.setItem(50, Material.NAME_TAG, "§7Suche", clickType -> search(p, schems));
inv.open();
}
static void search(Player p, List<Schematic> schems){
SWAnvilInv inv = new SWAnvilInv(p, "§7Schematicsuche");
inv.setCallback(term -> {
ArrayList<Schematic> schemCopy = new ArrayList<>(schems);
schemCopy.removeIf(schem -> !schem.getSchemName().toLowerCase().contains(term.toLowerCase()));
list(p, schemCopy, false);
});
inv.open();
} }
} }

Datei anzeigen

@ -0,0 +1,88 @@
/*
This file is a part of the SteamWar software.
Copyright (C) 2020 SteamWar.de-Serverteam
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.schematicsystem.commands;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.HoverEvent;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.entity.Player;
public class SchematicCommandHelp {
private SchematicCommandHelp() {
}
public static void printHelpMainPage(Player player) {
player.sendMessage("§e§lSchematicSystem §8§lHilfe");
for (HelpPage page : HelpPage.values()) {
TextComponent pageComp = new TextComponent(page.mainText);
pageComp.setColor(ChatColor.GRAY);
pageComp.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText("§e" + page.hover)));
pageComp.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/schem help " + page.name()));
player.spigot().sendMessage(pageComp);
}
}
public static void printHelpPage(Player player, HelpPage page) {
player.sendMessage("§e§lSchematicSystem §8§lHilfe");
for (String s : page.content) {
player.sendMessage(s);
}
}
public enum HelpPage {
ANSICHT("Finden & Laden", "Suche oder lade Schematics", new String[]{
"§8/§7schem §einfo §8[§7Schematic§8] - §7Zeigt dir Informationen zur Schematic",
"§8/§7schem §elist §8- §7Zeigt dir deine Schematics an",
"§8/§7schem §elist public §8- §7Zeigt alle Public-Schematics",
"§8/§7schem §esearch §8[§7Stichwort§8] - §7Sucht nach passenden Schematics",
"§8/§7schem §eload §8[§7Schematic§8] - §7Lädt eine Schematic",
"§8/§7schem §edownload §8[§7Schematic§8] - §7Gibt dir einen Downloadlink (1 min gültig)"
}),
BEARBEITUNG("Speichern & Bearbeiten", "Modifizierung von Schematics und Ordnern", new String[]{
"§8/§7schem §esave §8[§7Schematic§8] - §7Speichert dein Clipboard als Schematic",
"§8/§7schem §eordner §8[§7Ordner§8] - §7Erstelle einen leeren Ordner",
"§8/§7schem §emove §8[§7Schematic§8] [§7Neuer Pfad§8] - §7Verschiebe eine Schematic",
"§8/§7schem §erename §8[§7Schematic§8] [§7Neuer Name§8] - §7Gib der Schematic einen neuen Namen",
"§8/§7schem §echangetype §8[§7Schematic§8] - §7Ändert die Art deiner Schematic",
"§8/§7schem §edelete §8[§7Schematic§8] - §7Löscht eine Schematic"
}),
MEMBER("Besitzrechte", "Schematics mit anderen teilen", new String[]{
"§8/§7schem §eaddmember §8[§7Schematic§8] §8[§7Spieler§8] - §7Fügt einen Spieler zu einer Schematic hinzu",
"§8/§7schem §edelmember §8[§7Schematic§8] §8[§7Spieler§8] - §7Entfernt einen Spieler von einer Schematic",
"§8/§7schem §eclearmember §8[§7Schematic§8] - §7Entfernt alle Spieler von der Schematic",
"§8/§7schem §eaddteam §8[§7Schematic§8] - §7Füge jeden aus deinem Team auf die Schematic hinzu",
"§8/§7schem §eremteam §8[§7Schematic§8] - §7Entferne jeden aus deinem Team von der Schematic"
});
private final String mainText;
private final String[] content;
private final String hover;
HelpPage(String mainText, String hover, String[] content) {
this.mainText = mainText;
this.hover = hover;
this.content = content;
}
}
}

Datei anzeigen

@ -0,0 +1,385 @@
/*
This file is a part of the SteamWar software.
Copyright (C) 2020 SteamWar.de-Serverteam
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.schematicsystem.commands;
import de.steamwar.comms.packets.PrepareSchemPacket;
import de.steamwar.inventory.SWInventory;
import de.steamwar.inventory.SWItem;
import de.steamwar.schematicsystem.AutoCheckResult;
import de.steamwar.schematicsystem.CheckSchemType;
import de.steamwar.schematicsystem.SchematicSystem;
import de.steamwar.sql.*;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.ComponentBuilder;
import net.md_5.bungee.api.chat.HoverEvent;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.logging.Level;
import java.util.stream.Collectors;
public class SchematicCommandUtils {
private static final int CHUNK_SIZE = 15;
private static final List<Player> PUBLIC_TOGGLED = new ArrayList<>();
private static final List<String> FORBIDDEN_NAMES = Collections.unmodifiableList(Arrays.asList("public"));
private SchematicCommandUtils() {}
public static boolean invalidSchemName(Player player, String[] layers) {
for (String layer : layers) {
if (layer.isEmpty()) {
player.sendMessage(SchematicSystem.PREFIX + "§cDeine Ordner brauchen schon einen Namen!");
return true;
}
if (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;
}
if(FORBIDDEN_NAMES.contains(layer.toLowerCase())) {
player.sendMessage(SchematicSystem.PREFIX + "§cDer Pfad darf nicht \"§l" + layer + "§c\" enthalten");
return true;
}
}
return false;
}
public static void renderSchemlist(Player player, List<SchematicNode> nodes, int chunk, String breadcrumbs, boolean isPublic, SchematicNode parent) {
nodes.sort(Comparator.comparing(SchematicNode::getName));
SteamwarUser user = getUser(player);
int pageCount = (int) Math.ceil(nodes.size() / (double) CHUNK_SIZE);
player.sendMessage("§eSchematics §8(§e" + nodes.size() + "§8)");
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));
player.spigot().sendMessage(back);
}
for (int i = chunk * CHUNK_SIZE; i < nodes.size() && i < (chunk + 1) * CHUNK_SIZE; i++) {
SchematicNode node = nodes.get(i);
StringBuilder nodeString = new StringBuilder();
if (node.isDir()) {
nodeString.append("§7§lDIR §e");
} else {
SchematicType type = node.getSchemtype();
if (type != SchematicType.Normal) {
nodeString.append("§8§l")
.append(type.getKuerzel().toUpperCase())
.append(" ");
}
nodeString.append("§e");
}
nodeString.append(node.getName());
if (node.isDir()) {
nodeString.append("/");
}
if (node.getOwner() != user.getId()) {
nodeString.append(" §8von §7")
.append(SteamwarUser.get(node.getOwner()).getUserName());
}
TextComponent schematics = new TextComponent(nodeString.toString());
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() + "/"));
} 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()));
}
player.spigot().sendMessage(schematics);
}
if (parent != null && parent.getOwner() != user.getId() && NodeMember.getNodeMember(parent.getId(), user.getId()) != null) {
TextComponent deadd = new TextComponent("[Entfernen]");
deadd.setColor(ChatColor.RED);
deadd.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText("§7Entferne dich von dem Ordner")));
deadd.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/schem delete " + parent.generateBreadcrumbs(user)));
player.spigot().sendMessage(deadd);
}
TextComponent beforePage = new TextComponent("««");
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.setColor(ChatColor.RED);
}
TextComponent nextPage = new TextComponent(" Seite (" + (chunk + 1) + "/" + Math.max(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.setColor(ChatColor.RED);
}
beforePage.addExtra(nextPage);
player.spigot().sendMessage(beforePage);
}
public static void printSchemInfo(Player player, SchematicNode node) {
SteamwarUser user = getUser(player);
player.sendMessage("§7Schematic: §e" + node.getName());
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("§7Letzes Update: §e" + node.getLastUpdate().toLocalDateTime().format(DateTimeFormatter.ofPattern("HH:mm dd.MM.yyyy", Locale.GERMAN)));
player.sendMessage("§7Typ: §e" + (node.isDir() ? "§7DIR" : node.getSchemtype().name()));
if (!node.isDir()) {
if (node.getRank() > 0) {
player.sendMessage("§7Rang: §e" + node.getRank());
}
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()) &&
checkedSchematic.getSchemOwner() == node.getOwner()) {
player.sendMessage("§cStatus: §c" + checkedSchematic.getStartTime() + " : " + checkedSchematic.getDeclineReason());
break;
}
}
}
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);
}
TextComponent base = new TextComponent();
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)));
base.addExtra(load);
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()) {
TextComponent addMember = new TextComponent("[Hinzufügen] ");
addMember.setColor(ChatColor.AQUA);
addMember.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText("§eMember hinzufügen")));
addMember.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/schem addmember " + node.generateBreadcrumbs(user) + " "));
base.addExtra(addMember);
TextComponent delMember = new TextComponent("[Entfernen] ");
delMember.setColor(ChatColor.RED);
delMember.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText("§eMember entfernen")));
delMember.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/schem delmember " + node.generateBreadcrumbs(user) + " "));
base.addExtra(delMember);
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("[" + (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);
}
}
public static SchematicNode mkdirs(String[] layers, SteamwarUser user, int minus) {
SchematicNode currentNode = null;
for (int i = 0; i < layers.length - minus; 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()) {
currentNode = SchematicNode.createSchematicDirectory(user.getId(), layers[i], currentNode == null ? 0 : currentNode.getId());
} else {
if (!nodes.get(0).isDir()) {
nodes.set(0, SchematicNode.createSchematicDirectory(user.getId(), layers[i] + "-dir-" + System.currentTimeMillis() % 100, currentNode == null ? 0 : currentNode.getId()));
}
currentNode = nodes.get(0);
}
}
return currentNode;
}
public static SteamwarUser getUser(Player player) {
if (PUBLIC_TOGGLED.contains(player)) {
return SteamwarUser.get(0);
} else {
return SteamwarUser.get(player.getUniqueId());
}
}
public static boolean togglePublic(Player player) {
if (PUBLIC_TOGGLED.contains(player)) {
PUBLIC_TOGGLED.remove(player);
return false;
} else {
PUBLIC_TOGGLED.add(player);
return true;
}
}
public static void turnOffPublic(Player player) {
PUBLIC_TOGGLED.remove(player);
}
public static void loadSchem(Player player, SchematicNode node) {
if (node.isDir()) {
player.sendMessage(SchematicSystem.PREFIX + "§cDu kannst keine Ordner Laden");
return;
}
try {
node.loadToPlayer(player);
player.sendMessage(SchematicSystem.PREFIX + "§7Schematic §e" + node.getName() + " §7geladen!");
Bukkit.getLogger().log(Level.INFO, "{0} has loaded Schematic {1} {2}", 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) {
player.sendMessage(SchematicSystem.PREFIX + "§cDie Schematic konnte nicht geladen werden.");
throw new SecurityException(e);
}
}
public static void download(Player player, SchematicNode node) {
SteamwarUser user = getUser(player);
if (node.getOwner() != user.getId()) {
player.sendMessage("§cDu darfst nur deine eigenen Schematics herunterladen!");
return;
}
player.sendMessage(SchematicSystem.PREFIX + "Dein Download Link:");
player.sendMessage(NodeDownload.getLink(node));
}
public static void changeType(Player player, SchematicNode node, SchematicType type, SchematicCommand.Extend extend) {
SteamwarUser user = getUser(player);
if (node.getOwner() != user.getId()) {
player.sendMessage(SchematicSystem.PREFIX + "§cDu kannst nur deine eigenen Schematics einsenden.");
return;
}
if (node.isDir()) {
player.sendMessage(SchematicSystem.PREFIX + "§cOrdner haben keinen Typen.");
return;
}
if(!type.isAssignable()) {
player.sendMessage(SchematicSystem.PREFIX + "§cZu diesem Typen können keine Schematics geändert werden.");
}
if (node.getSchemtype().equals(type)) {
player.sendMessage(SchematicSystem.PREFIX + "§cDie Schematic hat schon diesen Typen");
return;
}
if (type.writeable()) {
node.setSchemtype(type);
player.sendMessage(SchematicSystem.PREFIX + "§aSchematictyp geändert");
} 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()) {
player.sendMessage(" §e" + warning);
}
for (String error : errors) {
player.sendMessage(" §c" + error);
}
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 -> {
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 -> {
node.setSchemtype(type.checkType());
player.sendMessage(SchematicSystem.PREFIX + "§aDie Schematic wird zeitnah überprüft");
player.closeInventory();
});
inv.setCallback(-999, click -> player.closeInventory());
inv.open();
} else if (extend == SchematicCommand.Extend.AUSFAHREN) {
new PrepareSchemPacket(SteamwarUser.get(player.getUniqueId()), node, type).send(player);
player.sendMessage(SchematicSystem.PREFIX + "§aDer Vorbereitungsserver wird gestartet");
}
}
}
}

Datei anzeigen

@ -1,13 +1,9 @@
name: SchematicSystem name: SchematicSystem
version: "1.0" version: "2.0"
authors: [Yaruma3341, Lixfel] authors: [Yaruma3341, Lixfel, Chaoscaot]
depend: [SpigotCore, WorldEdit] depend: [SpigotCore, WorldEdit]
main: de.steamwar.schematicsystem.SchematicSystem main: de.steamwar.schematicsystem.SchematicSystem
website: steamwar.de
api-version: "1.13" api-version: "1.13"
commands: commands:
schem:
aliases:
- schematic
- /schematic
- /schem

Datei anzeigen

@ -16,6 +16,7 @@
</properties> </properties>
<build> <build>
<defaultGoal>clean package</defaultGoal>
<plugins> <plugins>
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>