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

Datei anzeigen

@ -20,6 +20,7 @@
package de.steamwar.schematicsystem.commands;
import com.google.common.collect.Lists;
import de.steamwar.inventory.SWAnvilInv;
import de.steamwar.inventory.SWInventory;
import de.steamwar.inventory.SWItem;
import de.steamwar.inventory.SWListInv;
@ -198,12 +199,11 @@ class GUI {
}
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){
List<SWListInv.SWListEntry<Schematic>> schemList = new LinkedList<>();
List<Schematic> schems = Schematic.getSchemsAccessibleByUser(pid);
private static void list(Player p, List<Schematic> schems, boolean publics){
List<SWListInv.SWListEntry<Schematic>> schemList = new ArrayList<>();
for(Schematic schem : schems) {
Material m;
@ -218,43 +218,22 @@ class GUI {
schemList.add(new SWListInv.SWListEntry<>(item, schem));
}
SWListInv<Schematic> inv = new SWListInv<>(p, "§eSchematicliste", schemList, (clickType, schem) -> {
p.closeInventory();
info(p, schem);
});
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");
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
m = SWItem.getMaterial(currentSchem.getItem());
SWItem item = new SWItem(m, "§e" + currentSchem.getSchemName(), Collections.singletonList("§7" + currentSchem.getSchemType().name()), !currentSchem.getSchemType().writeable(), click -> {});
schemList.add(new SWListInv.SWListEntry<>(item, currentSchem));
}
SWListInv<Schematic> inv = new SWListInv<>(player, "§eSuchergebnisse", schemList, (clickType, schem) -> {
player.closeInventory();
info(player, schem);
});
inv.setCallback(-999, (ClickType click) -> player.closeInventory());
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();
return true;
}
}

Datei anzeigen

@ -97,35 +97,40 @@ public class SchematicCommand implements CommandExecutor {
private void list(Player player, String[] args){
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;
}
if("public".equalsIgnoreCase(args[1])){
GUI.list(player, 0);
if(args.length == 2){
sendPlayerSchematicList(0, player, "/schem list public ", Schematic.getSchemsAccessibleByUser(0));
return;
}
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) {
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){
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");
return true;
}
@ -363,8 +368,20 @@ public class SchematicCommand implements CommandExecutor {
help(player);
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){
@ -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");
}
private void sendPlayerSchematicList(int currentPage, int schemOwner, Player player) {
List<Schematic> schematicList = Schematic.getSchemsAccessibleByUser(schemOwner);
private void sendPlayerSchematicList(int currentPage, Player player, String precommand, List<Schematic> schematicList) {
SteamwarUser user = SteamwarUser.get(player.getUniqueId());
if(schematicList.isEmpty()) {
player.sendMessage(SchematicSystem.PREFIX + "§cDu hast noch keine Schematics");
@ -504,7 +521,7 @@ public class SchematicCommand implements CommandExecutor {
Schematic schematic = schematicList.get(i);
String schematicPlayer = "";
if(schematic.getSchemOwner() != schemOwner)
if(schematic.getSchemOwner() != user.getId())
schematicPlayer = " §8von §7" + SteamwarUser.get(schematic.getSchemOwner()).getUserName();
TextComponent schematics = new TextComponent("§e" + schematic.getSchemType().getKuerzel() + " §7" + schematic.getSchemName() + schematicPlayer);
@ -522,7 +539,7 @@ public class SchematicCommand implements CommandExecutor {
if(currentPage > 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 " + (currentPage - 1)));
beforePage.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, precommand + (currentPage - 1)));
}else
beforePage.setColor(ChatColor.RED);
@ -530,7 +547,7 @@ public class SchematicCommand implements CommandExecutor {
if(currentPage < pages-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 " + (currentPage + 1)));
nextPage.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, precommand + (currentPage + 1)));
}else
nextPage.setColor(ChatColor.RED);