Add direct searching to MaterialCommand
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful
Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
Ursprung
1e214d49d5
Commit
89272f76cc
@ -23,6 +23,7 @@ import de.steamwar.bausystem.BauSystem;
|
|||||||
import de.steamwar.bausystem.linkage.LinkageType;
|
import de.steamwar.bausystem.linkage.LinkageType;
|
||||||
import de.steamwar.bausystem.linkage.Linked;
|
import de.steamwar.bausystem.linkage.Linked;
|
||||||
import de.steamwar.command.SWCommand;
|
import de.steamwar.command.SWCommand;
|
||||||
|
import de.steamwar.command.TypeMapper;
|
||||||
import de.steamwar.inventory.SWAnvilInv;
|
import de.steamwar.inventory.SWAnvilInv;
|
||||||
import de.steamwar.inventory.SWInventory;
|
import de.steamwar.inventory.SWInventory;
|
||||||
import de.steamwar.inventory.SWItem;
|
import de.steamwar.inventory.SWItem;
|
||||||
@ -32,17 +33,16 @@ import lombok.Setter;
|
|||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.data.BlockData;
|
import org.bukkit.block.data.BlockData;
|
||||||
import org.bukkit.block.data.Waterlogged;
|
import org.bukkit.block.data.Waterlogged;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Linked(LinkageType.COMMAND)
|
@Linked(LinkageType.COMMAND)
|
||||||
@Linked(LinkageType.LISTENER)
|
@Linked(LinkageType.LISTENER)
|
||||||
@ -197,9 +197,90 @@ public class MaterialCommand extends SWCommand implements Listener {
|
|||||||
|
|
||||||
@Register
|
@Register
|
||||||
public void materialGUI(Player p) {
|
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<>();
|
List<SWListInv.SWListEntry<Material>> swListEntries = new ArrayList<>();
|
||||||
materialData.forEach(data -> {
|
materialData.forEach(data -> {
|
||||||
if (data.is(searchMap.get(p))) {
|
if (data.is(search)) {
|
||||||
swListEntries.add(data.toSWItem(p));
|
swListEntries.add(data.toSWItem(p));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren