diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/util/MaterialCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/util/MaterialCommand.java index 393367ed..88aa8aec 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/util/MaterialCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/util/MaterialCommand.java @@ -23,6 +23,7 @@ import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.linkage.LinkageType; import de.steamwar.bausystem.linkage.Linked; import de.steamwar.command.SWCommand; +import de.steamwar.command.TypeMapper; import de.steamwar.inventory.SWAnvilInv; import de.steamwar.inventory.SWInventory; import de.steamwar.inventory.SWItem; @@ -32,17 +33,16 @@ import lombok.Setter; import org.bukkit.Material; import org.bukkit.block.data.BlockData; import org.bukkit.block.data.Waterlogged; +import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerQuitEvent; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.regex.Pattern; +import java.util.stream.Collectors; @Linked(LinkageType.COMMAND) @Linked(LinkageType.LISTENER) @@ -197,9 +197,90 @@ public class MaterialCommand extends SWCommand implements Listener { @Register public void materialGUI(Player p) { + materialGUI(p, searchMap.get(p)); + } + + @Register + public void search(Player p, @Mapper("search") String... searches) { + Search search = new Search(); + for (String s : searches) { + switch (s.toLowerCase()) { + case "-t": + case "-transparent": + search.transparent = true; + break; + case "-s": + case "-solid": + search.solid = true; + break; + case "-g": + case "-gravity": + search.gravity = true; + break; + case "-o": + case "-occluding": + search.occluding = true; + break; + case "-i": + case "-interacteable": + search.interacteable = true; + break; + case "-f": + case "-flammable": + search.flammable = true; + break; + case "-b": + case "-burnable": + search.burnable = true; + break; + case "-w": + case "-waterloggable": + search.waterloggable = true; + break; + default: + search.name = s; + break; + } + } + materialGUI(p, search); + } + + @Mapper(value = "search", local = true) + private TypeMapper searchMapper() { + List> results = new ArrayList<>(); + results.add(Arrays.asList("-t", "-transparent")); + results.add(Arrays.asList("-s", "-solid")); + results.add(Arrays.asList("-g", "-gravity")); + results.add(Arrays.asList("-o", "-occluding")); + results.add(Arrays.asList("-i", "-interacteable")); + results.add(Arrays.asList("-f", "-flammable")); + results.add(Arrays.asList("-b", "-burnable")); + results.add(Arrays.asList("-w", "-waterloggable")); + + return new TypeMapper() { + @Override + public String map(CommandSender commandSender, String[] previousArguments, String s) { + return s; + } + + @Override + public Collection tabCompletes(CommandSender commandSender, String[] strings, String s) { + List result = results.stream().filter(current -> { + for (String t : strings) { + if (current.contains(t)) return false; + } + return true; + }).flatMap(Collection::stream).collect(Collectors.toList()); + result.add(s); + return result; + } + }; + } + + public void materialGUI(Player p, Search search) { List> swListEntries = new ArrayList<>(); materialData.forEach(data -> { - if (data.is(searchMap.get(p))) { + if (data.is(search)) { swListEntries.add(data.toSWItem(p)); } });