From 44f0f0bd374c1a7805b2c0e79ab4e18fea06d20e Mon Sep 17 00:00:00 2001 From: Yaruma3341 Date: Tue, 7 Jan 2020 17:15:24 +0100 Subject: [PATCH] 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!");