13
0

Separate GUI from CLI #74

Manuell gemergt
Lixfel hat 1 Commits von separateGUI nach master 2020-12-25 23:03:19 +01:00 zusammengeführt
2 geänderte Dateien mit 55 neuen und 59 gelöschten Zeilen
Nur Änderungen aus Commit b32ca71205 werden angezeigt - Alle Commits anzeigen

Datei anzeigen

@ -20,6 +20,7 @@
package de.steamwar.schematicsystem.commands; package de.steamwar.schematicsystem.commands;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import de.steamwar.inventory.SWAnvilInv;
import de.steamwar.inventory.SWInventory; import de.steamwar.inventory.SWInventory;
import de.steamwar.inventory.SWItem; import de.steamwar.inventory.SWItem;
import de.steamwar.inventory.SWListInv; import de.steamwar.inventory.SWListInv;
@ -198,12 +199,11 @@ class GUI {
} }
static void list(Player p){ static void list(Player p){
list(p, SteamwarUser.get(p.getUniqueId()).getId()); list(p, Schematic.getSchemsAccessibleByUser(SteamwarUser.get(p.getUniqueId()).getId()), false);
} }
static void list(Player p, int pid){ private static void list(Player p, List<Schematic> schems, boolean publics){
List<SWListInv.SWListEntry<Schematic>> schemList = new LinkedList<>(); List<SWListInv.SWListEntry<Schematic>> schemList = new ArrayList<>();
List<Schematic> schems = Schematic.getSchemsAccessibleByUser(pid);
for(Schematic schem : schems) { for(Schematic schem : schems) {
Material m; Material m;
@ -218,43 +218,22 @@ class GUI {
schemList.add(new SWListInv.SWListEntry<>(item, schem)); schemList.add(new SWListInv.SWListEntry<>(item, schem));
} }
SWListInv<Schematic> inv = new SWListInv<>(p, "§eSchematicliste", schemList, (clickType, schem) -> { SWListInv<Schematic> inv = new SWListInv<>(p, "§eSchematicliste", false, schemList, (clickType, schem) -> info(p, schem));
p.closeInventory(); if(publics)
info(p, schem); inv.setItem(48, Material.BUCKET, "§7Eigene Schematics", clickType -> list(p));
});
inv.setCallback(-999, (ClickType click) -> p.closeInventory());
inv.open();
}
static boolean listSearch(Player player, String search) {
List<SWListInv.SWListEntry<Schematic>> schemList = new LinkedList<>();
List<Schematic> filteredSchems = new ArrayList<>();
for(Schematic currentSchem : Schematic.getSchemsAccessibleByUser(player.getUniqueId())) {
if(currentSchem.getSchemName().toLowerCase().contains(search.toLowerCase()))
filteredSchems.add(currentSchem);
}
if(filteredSchems.isEmpty())
return false;
for(Schematic currentSchem : filteredSchems) {
Material m;
if (currentSchem.getItem().isEmpty())
m = SWItem.getMaterial("CAULDRON_ITEM");
else else
m = SWItem.getMaterial(currentSchem.getItem()); 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));
SWItem item = new SWItem(m, "§e" + currentSchem.getSchemName(), Collections.singletonList("§7" + currentSchem.getSchemType().name()), !currentSchem.getSchemType().writeable(), click -> {}); inv.open();
schemList.add(new SWListInv.SWListEntry<>(item, currentSchem));
} }
SWListInv<Schematic> inv = new SWListInv<>(player, "§eSuchergebnisse", schemList, (clickType, schem) -> { static void search(Player p, List<Schematic> schems){
player.closeInventory(); SWAnvilInv inv = new SWAnvilInv(p, "§7Schematicsuche");
info(player, schem); inv.setCallback(term -> {
ArrayList<Schematic> schemCopy = new ArrayList<>(schems);
schemCopy.removeIf(schem -> !schem.getSchemName().toLowerCase().contains(term.toLowerCase()));
list(p, schemCopy, false);
}); });
inv.setCallback(-999, (ClickType click) -> player.closeInventory());
inv.open(); inv.open();
return true;
} }
} }

Datei anzeigen

@ -97,35 +97,40 @@ public class SchematicCommand implements CommandExecutor {
private void list(Player player, String[] args){ private void list(Player player, String[] args){
if(args.length <= 1){ if(args.length <= 1){
sendPlayerSchematicList(0, SteamwarUser.get(player.getUniqueId()).getId(), player); sendPlayerSchematicList(0, player, "/schem list ", Schematic.getSchemsAccessibleByUser(SteamwarUser.get(player.getUniqueId()).getId()));
return; return;
} }
if("public".equalsIgnoreCase(args[1])){ if("public".equalsIgnoreCase(args[1])){
GUI.list(player, 0); if(args.length == 2){
sendPlayerSchematicList(0, player, "/schem list public ", Schematic.getSchemsAccessibleByUser(0));
return; return;
} }
try { try {
sendPlayerSchematicList(Integer.parseInt(args[1]), SteamwarUser.get(player.getUniqueId()).getId(), player); sendPlayerSchematicList(Integer.parseInt(args[2]), player, "/schem list public ", Schematic.getSchemsAccessibleByUser(0));
} catch (NumberFormatException ex) {
player.sendMessage(SchematicSystem.PREFIX + "§cUngültige Seitenzahl");
}
return;
}
try {
sendPlayerSchematicList(Integer.parseInt(args[1]), player, "/schem list ", Schematic.getSchemsAccessibleByUser(SteamwarUser.get(player.getUniqueId()).getId()));
} catch (NumberFormatException ex) { } catch (NumberFormatException ex) {
player.sendMessage(SchematicSystem.PREFIX + "§cUngültige Seitenzahl"); player.sendMessage(SchematicSystem.PREFIX + "§cUngültige Seitenzahl");
} }
} }
private boolean schemnameForbidden(String schematicName) {
return schematicName.contains("/") ||
schematicName.contains("\\") ||
schematicName.contains("<") ||
schematicName.contains(">") ||
schematicName.contains("^") ||
schematicName.contains("°") ||
schematicName.contains("'") ||
schematicName.contains("\"");
}
private boolean invalidSchemName(Player player, String name){ private boolean invalidSchemName(Player player, String name){
if(schemnameForbidden(name)){ if(name.contains("/") ||
name.contains("\\") ||
name.contains("<") ||
name.contains(">") ||
name.contains("^") ||
name.contains("°") ||
name.contains("'") ||
name.contains("\"")){
player.sendMessage(SchematicSystem.PREFIX + "§cDer angegebene Schematicname enthält verbotene Zeichen"); player.sendMessage(SchematicSystem.PREFIX + "§cDer angegebene Schematicname enthält verbotene Zeichen");
return true; return true;
} }
@ -363,8 +368,20 @@ public class SchematicCommand implements CommandExecutor {
help(player); help(player);
return; return;
} }
if(!GUI.listSearch(player, args[1]))
player.sendMessage("§cEs wurden keine Schematics gefunden!"); List<Schematic> schems = Schematic.getSchemsAccessibleByUser(SteamwarUser.get(player.getUniqueId()).getId());
schems.removeIf(schem -> !schem.getSchemName().toLowerCase().contains(args[1].toLowerCase()));
if(args.length == 2){
sendPlayerSchematicList(0, player, "/schem search " + args[1] + " ", schems);
return;
}
try {
sendPlayerSchematicList(Integer.parseInt(args[2]), player, "/schem search " + args[1] + " ", schems);
} catch (NumberFormatException ex) {
player.sendMessage(SchematicSystem.PREFIX + "§cUngültige Seitenzahl");
}
} }
static void download(Player player, Schematic schematic){ static void download(Player player, Schematic schematic){
@ -474,8 +491,8 @@ public class SchematicCommand implements CommandExecutor {
player.sendMessage("§8/§eschem delmember §8[§7Schematic§8] §8[§7Spieler§8] - §7Entfernt einen Spieler von einer Schematic"); player.sendMessage("§8/§eschem delmember §8[§7Schematic§8] §8[§7Spieler§8] - §7Entfernt einen Spieler von einer Schematic");
} }
private void sendPlayerSchematicList(int currentPage, int schemOwner, Player player) { private void sendPlayerSchematicList(int currentPage, Player player, String precommand, List<Schematic> schematicList) {
List<Schematic> schematicList = Schematic.getSchemsAccessibleByUser(schemOwner); SteamwarUser user = SteamwarUser.get(player.getUniqueId());
if(schematicList.isEmpty()) { if(schematicList.isEmpty()) {
player.sendMessage(SchematicSystem.PREFIX + "§cDu hast noch keine Schematics"); player.sendMessage(SchematicSystem.PREFIX + "§cDu hast noch keine Schematics");
@ -504,7 +521,7 @@ public class SchematicCommand implements CommandExecutor {
Schematic schematic = schematicList.get(i); Schematic schematic = schematicList.get(i);
String schematicPlayer = ""; String schematicPlayer = "";
if(schematic.getSchemOwner() != schemOwner) if(schematic.getSchemOwner() != user.getId())
schematicPlayer = " §8von §7" + SteamwarUser.get(schematic.getSchemOwner()).getUserName(); schematicPlayer = " §8von §7" + SteamwarUser.get(schematic.getSchemOwner()).getUserName();
TextComponent schematics = new TextComponent("§e" + schematic.getSchemType().getKuerzel() + " §7" + schematic.getSchemName() + schematicPlayer); TextComponent schematics = new TextComponent("§e" + schematic.getSchemType().getKuerzel() + " §7" + schematic.getSchemName() + schematicPlayer);
@ -522,7 +539,7 @@ public class SchematicCommand implements CommandExecutor {
if(currentPage > 0){ if(currentPage > 0){
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 " + (currentPage - 1))); beforePage.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, precommand + (currentPage - 1)));
}else }else
beforePage.setColor(ChatColor.RED); beforePage.setColor(ChatColor.RED);
@ -530,7 +547,7 @@ public class SchematicCommand implements CommandExecutor {
if(currentPage < pages-1){ if(currentPage < pages-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 " + (currentPage + 1))); nextPage.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, precommand + (currentPage + 1)));
}else }else
nextPage.setColor(ChatColor.RED); nextPage.setColor(ChatColor.RED);