From 44f0f0bd374c1a7805b2c0e79ab4e18fea06d20e Mon Sep 17 00:00:00 2001 From: Yaruma3341 Date: Tue, 7 Jan 2020 17:15:24 +0100 Subject: [PATCH 1/4] added schematic search --- .../schematicsystem/commands/GUI.java | 33 ++++++++++++++++--- .../commands/SchematicCommand.java | 11 +++++++ 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/GUI.java b/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/GUI.java index fac69a7..b56a3e0 100644 --- a/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/GUI.java +++ b/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/GUI.java @@ -13,10 +13,7 @@ import org.bukkit.event.inventory.ClickType; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.SkullMeta; -import java.util.Arrays; -import java.util.Collections; -import java.util.LinkedList; -import java.util.List; +import java.util.*; class GUI { private GUI(){} @@ -182,4 +179,32 @@ class GUI { inv.setCallback(-999, (ClickType click) -> p.closeInventory()); inv.open(); } + + static void listSearch(Player player, String search) { + List> schemList = new LinkedList<>(); + List filteredSchems = new ArrayList<>(); + + for(Schematic currentSchem : filteredSchems) { + if(currentSchem.getSchemName().toLowerCase().contains(search.toLowerCase())) + filteredSchems.add(currentSchem); + } + + for(Schematic currentSchem : filteredSchems) { + Material m; + if (currentSchem.getItem().isEmpty()) + m = SWItem.getMaterial("CAULDRON_ITEM"); + 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 Pair<>(item, currentSchem)); + } + + SWListInv inv = new SWListInv<>(player, "§eSuchergebnisse", (clickType, schem) -> { + player.closeInventory(); + info(player, schem); + }, schemList); + inv.setCallback(-999, (ClickType click) -> player.closeInventory()); + inv.open(); + } } diff --git a/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/SchematicCommand.java b/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/SchematicCommand.java index f83733a..82c559b 100644 --- a/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/SchematicCommand.java +++ b/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/SchematicCommand.java @@ -68,6 +68,9 @@ public class SchematicCommand implements CommandExecutor { case "download": download(player, args); break; + case "search": + search(player, args); + break; default: help(player); } @@ -330,6 +333,14 @@ public class SchematicCommand implements CommandExecutor { download(player, schematic); } + private void search(Player player, String[] args) { + if(args.length != 1) { + help(player); + return; + } + GUI.listSearch(player, args[0]); + } + static void download(Player player, Schematic schematic){ if(schematic.getSchemOwner() != SteamwarUser.get(player.getUniqueId()).getId()){ player.sendMessage("§cDu darfst nur deine eigenen Schematics herunterladen!"); -- 2.39.5 From d2f54b9206f87a0d5eb1122a99a9c09af8858fea Mon Sep 17 00:00:00 2001 From: Yaruma3341 Date: Tue, 7 Jan 2020 22:51:06 +0100 Subject: [PATCH 2/4] added empty check --- .../src/de/steamwar/schematicsystem/commands/GUI.java | 6 +++++- .../steamwar/schematicsystem/commands/SchematicCommand.java | 5 +++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/GUI.java b/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/GUI.java index b56a3e0..b301821 100644 --- a/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/GUI.java +++ b/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/GUI.java @@ -180,7 +180,7 @@ class GUI { inv.open(); } - static void listSearch(Player player, String search) { + static boolean listSearch(Player player, String search) { List> schemList = new LinkedList<>(); List filteredSchems = new ArrayList<>(); @@ -189,6 +189,9 @@ class GUI { filteredSchems.add(currentSchem); } + if(filteredSchems.isEmpty()) + return false; + for(Schematic currentSchem : filteredSchems) { Material m; if (currentSchem.getItem().isEmpty()) @@ -206,5 +209,6 @@ class GUI { }, schemList); inv.setCallback(-999, (ClickType click) -> player.closeInventory()); inv.open(); + return true; } } diff --git a/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/SchematicCommand.java b/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/SchematicCommand.java index 82c559b..a78502f 100644 --- a/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/SchematicCommand.java +++ b/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/SchematicCommand.java @@ -334,11 +334,12 @@ public class SchematicCommand implements CommandExecutor { } private void search(Player player, String[] args) { - if(args.length != 1) { + if(args.length < 2) { help(player); return; } - GUI.listSearch(player, args[0]); + if(!GUI.listSearch(player, args[1])) + player.sendMessage("§cEs wurden keine Schematics gefunden!"); } static void download(Player player, Schematic schematic){ -- 2.39.5 From 62307e933e7a603471cc6d0880f1a59be6baac3a Mon Sep 17 00:00:00 2001 From: Yaruma3341 Date: Tue, 7 Jan 2020 22:55:01 +0100 Subject: [PATCH 3/4] added iml to gitignore --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 7eae63f..02142ca 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .idea target -dependency-reduced-pom.xml \ No newline at end of file +dependency-reduced-pom.xml +*.iml \ No newline at end of file -- 2.39.5 From 727c74a35baa5b327b6489ea2092b6646b97a536 Mon Sep 17 00:00:00 2001 From: Yaruma3341 Date: Wed, 8 Jan 2020 17:13:48 +0100 Subject: [PATCH 4/4] bugfixes --- .../src/de/steamwar/schematicsystem/commands/GUI.java | 2 +- .../de/steamwar/schematicsystem/commands/SchematicCommand.java | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/GUI.java b/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/GUI.java index b301821..3fbd253 100644 --- a/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/GUI.java +++ b/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/GUI.java @@ -184,7 +184,7 @@ class GUI { List> schemList = new LinkedList<>(); List filteredSchems = new ArrayList<>(); - for(Schematic currentSchem : filteredSchems) { + for(Schematic currentSchem : Schematic.getSchemsAccessibleByUser(player.getUniqueId())) { if(currentSchem.getSchemName().toLowerCase().contains(search.toLowerCase())) filteredSchems.add(currentSchem); } diff --git a/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/SchematicCommand.java b/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/SchematicCommand.java index a78502f..51a8cf8 100644 --- a/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/SchematicCommand.java +++ b/SchematicSystem_Main/src/de/steamwar/schematicsystem/commands/SchematicCommand.java @@ -438,6 +438,7 @@ public class SchematicCommand implements CommandExecutor { 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"); -- 2.39.5