SteamWar/BauSystem2.0
Archiviert
12
0

Add direct searching to MaterialCommand
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
yoyosource 2022-06-26 17:48:32 +02:00
Ursprung 1e214d49d5
Commit 89272f76cc

Datei anzeigen

@ -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<String> searchMapper() {
List<List<String>> 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<String>() {
@Override
public String map(CommandSender commandSender, String[] previousArguments, String s) {
return s;
}
@Override
public Collection<String> tabCompletes(CommandSender commandSender, String[] strings, String s) {
List<String> 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<SWListInv.SWListEntry<Material>> swListEntries = new ArrayList<>();
materialData.forEach(data -> {
if (data.is(searchMap.get(p))) {
if (data.is(search)) {
swListEntries.add(data.toSWItem(p));
}
});