forked from SteamWar/SteamWar
Improve MaterialCommand
This commit is contained in:
+3
-4
@@ -22,13 +22,12 @@ package de.steamwar.bausystem.features.slaves.laufbau;
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.core.SWPlayer;
|
||||
import de.steamwar.inventory.SWItem;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import de.steamwar.sql.UserConfig;
|
||||
import lombok.Cleanup;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import yapion.hierarchy.output.StreamOutput;
|
||||
import yapion.hierarchy.types.YAPIONObject;
|
||||
@@ -45,8 +44,8 @@ import java.util.stream.Collectors;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
import java.util.zip.GZIPOutputStream;
|
||||
|
||||
@Linked
|
||||
public class LaufbauUtils implements Listener {
|
||||
@UtilityClass
|
||||
public class LaufbauUtils {
|
||||
|
||||
public static class LaufbauComponent implements SWPlayer.Component {
|
||||
|
||||
|
||||
+37
-48
@@ -26,6 +26,7 @@ import de.steamwar.bausystem.shared.EnumDisplay;
|
||||
import de.steamwar.command.PreviousArguments;
|
||||
import de.steamwar.command.SWCommand;
|
||||
import de.steamwar.command.TypeMapper;
|
||||
import de.steamwar.core.SWPlayer;
|
||||
import de.steamwar.data.CMDs;
|
||||
import de.steamwar.inventory.SWAnvilInv;
|
||||
import de.steamwar.inventory.SWInventory;
|
||||
@@ -56,11 +57,9 @@ public class MaterialCommand extends SWCommand implements Listener {
|
||||
WorldEditListener.addCommandExclusion("material");
|
||||
}
|
||||
|
||||
private Map<Player, Search> searchMap = new HashMap<>();
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
static class Search {
|
||||
public class SearchParameter implements SWPlayer.Component {
|
||||
SearchType transparent = SearchType.IGNORE;
|
||||
SearchType solid = SearchType.IGNORE;
|
||||
SearchType gravity = SearchType.IGNORE;
|
||||
@@ -104,10 +103,10 @@ public class MaterialCommand extends SWCommand implements Listener {
|
||||
|
||||
@Register
|
||||
public void materialGUI(Player p) {
|
||||
materialGUI(p, searchMap.get(p));
|
||||
materialGUI(p, SWPlayer.of(p).getComponentOrDefault(SearchParameter.class, SearchParameter::new));
|
||||
}
|
||||
|
||||
private static final Map<String, BiConsumer<Search, SearchType>> elements = new HashMap<>();
|
||||
private static final Map<String, BiConsumer<SearchParameter, SearchType>> elements = new HashMap<>();
|
||||
static {
|
||||
elements.put("-transparent", (search, searchType) -> search.transparent = searchType);
|
||||
elements.put("-solid", (search, searchType) -> search.solid = searchType);
|
||||
@@ -122,15 +121,15 @@ public class MaterialCommand extends SWCommand implements Listener {
|
||||
|
||||
@Register
|
||||
public void search(Player p, @Mapper("search") String... searches) {
|
||||
Search search = new Search();
|
||||
SearchParameter searchParameter = SWPlayer.of(p).getComponentOrDefault(SearchParameter.class, SearchParameter::new);
|
||||
for (String s : searches) {
|
||||
boolean has = false;
|
||||
for (Map.Entry<String, BiConsumer<Search, SearchType>> element: elements.entrySet()) {
|
||||
for (Map.Entry<String, BiConsumer<SearchParameter, SearchType>> element: elements.entrySet()) {
|
||||
if (s.startsWith(element.getKey() + ":")) {
|
||||
element.getValue().accept(search, SearchType.valueOf(s.substring(element.getKey().length() + 1).toUpperCase()));
|
||||
element.getValue().accept(searchParameter, SearchType.valueOf(s.substring(element.getKey().length() + 1).toUpperCase()));
|
||||
has = true;
|
||||
} else if (s.startsWith(element.getKey().substring(0, 2) + ":")) {
|
||||
element.getValue().accept(search, SearchType.valueOf(s.substring(element.getKey().substring(0, 2).length() + 1).toUpperCase()));
|
||||
element.getValue().accept(searchParameter, SearchType.valueOf(s.substring(element.getKey().substring(0, 2).length() + 1).toUpperCase()));
|
||||
has = true;
|
||||
}
|
||||
if (has) break;
|
||||
@@ -141,15 +140,15 @@ public class MaterialCommand extends SWCommand implements Listener {
|
||||
case "-blastresistance:":
|
||||
s = s.substring(s.indexOf(':') + 1).replace('_', ' ');
|
||||
if (s.isEmpty() || s.matches("((([><]=?)|!|=)\\d+(\\.|,\\d+)?)( ((([><]=?)|!|=)\\d+(\\.|,\\d+)?))*")) {
|
||||
search.blastResistance = s;
|
||||
searchParameter.blastResistance = s;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
search.name = s;
|
||||
searchParameter.name = s;
|
||||
break;
|
||||
}
|
||||
}
|
||||
materialGUI(p, search);
|
||||
materialGUI(p, searchParameter);
|
||||
}
|
||||
|
||||
@Mapper(value = "search", local = true)
|
||||
@@ -182,7 +181,7 @@ public class MaterialCommand extends SWCommand implements Listener {
|
||||
};
|
||||
}
|
||||
|
||||
public void materialGUI(Player p, Search search) {
|
||||
public void materialGUI(Player p, SearchParameter search) {
|
||||
List<SWListInv.SWListEntry<Material>> swListEntries = new ArrayList<>();
|
||||
MaterialLazyInit.materialData.forEach(data -> {
|
||||
if (data.is(search)) {
|
||||
@@ -202,59 +201,59 @@ public class MaterialCommand extends SWCommand implements Listener {
|
||||
|
||||
private void searchGUI(Player p) {
|
||||
SWInventory swInventory = new SWInventory(p, 54, BauSystem.MESSAGE.parse("MATERIAL_SEARCH", p));
|
||||
Search search = searchMap.get(p);
|
||||
SearchParameter searchParameter = SWPlayer.of(p).getComponentOrDefault(SearchParameter.class, SearchParameter::new);
|
||||
swInventory.setItem(0, new SWItem(Material.ARROW, BauSystem.MESSAGE.parse("MATERIAL_BACK", p), clickType -> {
|
||||
materialGUI(p);
|
||||
}).setCustomModelData(CMDs.BACK));
|
||||
swInventory.setItem(10, new SWItem(Material.NAME_TAG, BauSystem.MESSAGE.parse("MATERIAL_SEARCH_NAME", p) + BauSystem.MESSAGE.parse("MATERIAL_SEARCH_VALUE", p, search.name), clickType -> {
|
||||
SWAnvilInv swAnvilInv = new SWAnvilInv(p, BauSystem.MESSAGE.parse("MATERIAL_SEARCH_NAME", p), search.name);
|
||||
swInventory.setItem(10, new SWItem(Material.NAME_TAG, BauSystem.MESSAGE.parse("MATERIAL_SEARCH_NAME", p) + BauSystem.MESSAGE.parse("MATERIAL_SEARCH_VALUE", p, searchParameter.name), clickType -> {
|
||||
SWAnvilInv swAnvilInv = new SWAnvilInv(p, BauSystem.MESSAGE.parse("MATERIAL_SEARCH_NAME", p), searchParameter.name);
|
||||
swAnvilInv.setCallback(s -> {
|
||||
search.name = s;
|
||||
searchParameter.name = s;
|
||||
searchGUI(p);
|
||||
});
|
||||
swAnvilInv.open();
|
||||
}));
|
||||
swInventory.setItem(19, new SWItem(Material.GLASS, BauSystem.MESSAGE.parse("MATERIAL_SEARCH_TRANSPARENT", p) + BauSystem.MESSAGE.parse("MATERIAL_SEARCH_VALUE", p, BauSystem.MESSAGE.parse(search.transparent.getChatValue(), p)), clickType -> {
|
||||
search.transparent = search.transparent.next();
|
||||
swInventory.setItem(19, new SWItem(Material.GLASS, BauSystem.MESSAGE.parse("MATERIAL_SEARCH_TRANSPARENT", p) + BauSystem.MESSAGE.parse("MATERIAL_SEARCH_VALUE", p, BauSystem.MESSAGE.parse(searchParameter.transparent.getChatValue(), p)), clickType -> {
|
||||
searchParameter.transparent = searchParameter.transparent.next();
|
||||
searchGUI(p);
|
||||
}));
|
||||
swInventory.setItem(20, new SWItem(Material.BRICK, BauSystem.MESSAGE.parse("MATERIAL_SEARCH_SOLID", p) + BauSystem.MESSAGE.parse("MATERIAL_SEARCH_VALUE", p, BauSystem.MESSAGE.parse(search.solid.getChatValue(), p)), clickType -> {
|
||||
search.solid = search.solid.next();
|
||||
swInventory.setItem(20, new SWItem(Material.BRICK, BauSystem.MESSAGE.parse("MATERIAL_SEARCH_SOLID", p) + BauSystem.MESSAGE.parse("MATERIAL_SEARCH_VALUE", p, BauSystem.MESSAGE.parse(searchParameter.solid.getChatValue(), p)), clickType -> {
|
||||
searchParameter.solid = searchParameter.solid.next();
|
||||
searchGUI(p);
|
||||
}));
|
||||
swInventory.setItem(21, new SWItem(Material.BLACK_CONCRETE_POWDER, BauSystem.MESSAGE.parse("MATERIAL_SEARCH_GRAVITY", p) + BauSystem.MESSAGE.parse("MATERIAL_SEARCH_VALUE", p, BauSystem.MESSAGE.parse(search.gravity.getChatValue(), p)), clickType -> {
|
||||
search.gravity = search.gravity.next();
|
||||
swInventory.setItem(21, new SWItem(Material.BLACK_CONCRETE_POWDER, BauSystem.MESSAGE.parse("MATERIAL_SEARCH_GRAVITY", p) + BauSystem.MESSAGE.parse("MATERIAL_SEARCH_VALUE", p, BauSystem.MESSAGE.parse(searchParameter.gravity.getChatValue(), p)), clickType -> {
|
||||
searchParameter.gravity = searchParameter.gravity.next();
|
||||
searchGUI(p);
|
||||
}));
|
||||
swInventory.setItem(22, new SWItem(Material.BIRCH_LOG, BauSystem.MESSAGE.parse("MATERIAL_SEARCH_OCCLUDING", p) + BauSystem.MESSAGE.parse("MATERIAL_SEARCH_VALUE", p, BauSystem.MESSAGE.parse(search.occluding.getChatValue(), p)), clickType -> {
|
||||
search.occluding = search.occluding.next();
|
||||
swInventory.setItem(22, new SWItem(Material.BIRCH_LOG, BauSystem.MESSAGE.parse("MATERIAL_SEARCH_OCCLUDING", p) + BauSystem.MESSAGE.parse("MATERIAL_SEARCH_VALUE", p, BauSystem.MESSAGE.parse(searchParameter.occluding.getChatValue(), p)), clickType -> {
|
||||
searchParameter.occluding = searchParameter.occluding.next();
|
||||
searchGUI(p);
|
||||
}));
|
||||
swInventory.setItem(23, new SWItem(Material.OAK_BUTTON, BauSystem.MESSAGE.parse("MATERIAL_SEARCH_INTERACTEABLE", p) + BauSystem.MESSAGE.parse("MATERIAL_SEARCH_VALUE", p, BauSystem.MESSAGE.parse(search.interacteable.getChatValue(), p)), clickType -> {
|
||||
search.interacteable = search.interacteable.next();
|
||||
swInventory.setItem(23, new SWItem(Material.OAK_BUTTON, BauSystem.MESSAGE.parse("MATERIAL_SEARCH_INTERACTEABLE", p) + BauSystem.MESSAGE.parse("MATERIAL_SEARCH_VALUE", p, BauSystem.MESSAGE.parse(searchParameter.interacteable.getChatValue(), p)), clickType -> {
|
||||
searchParameter.interacteable = searchParameter.interacteable.next();
|
||||
searchGUI(p);
|
||||
}));
|
||||
swInventory.setItem(24, new SWItem(Material.FLINT_AND_STEEL, BauSystem.MESSAGE.parse("MATERIAL_SEARCH_FLAMMABLE", p) + BauSystem.MESSAGE.parse("MATERIAL_SEARCH_VALUE", p, BauSystem.MESSAGE.parse(search.flammable.getChatValue(), p)), clickType -> {
|
||||
search.flammable = search.flammable.next();
|
||||
swInventory.setItem(24, new SWItem(Material.FLINT_AND_STEEL, BauSystem.MESSAGE.parse("MATERIAL_SEARCH_FLAMMABLE", p) + BauSystem.MESSAGE.parse("MATERIAL_SEARCH_VALUE", p, BauSystem.MESSAGE.parse(searchParameter.flammable.getChatValue(), p)), clickType -> {
|
||||
searchParameter.flammable = searchParameter.flammable.next();
|
||||
searchGUI(p);
|
||||
}));
|
||||
swInventory.setItem(25, new SWItem(Material.LAVA_BUCKET, BauSystem.MESSAGE.parse("MATERIAL_SEARCH_BURNABLE", p) + BauSystem.MESSAGE.parse("MATERIAL_SEARCH_VALUE", p, BauSystem.MESSAGE.parse(search.burnable.getChatValue(), p)), clickType -> {
|
||||
search.burnable = search.burnable.next();
|
||||
swInventory.setItem(25, new SWItem(Material.LAVA_BUCKET, BauSystem.MESSAGE.parse("MATERIAL_SEARCH_BURNABLE", p) + BauSystem.MESSAGE.parse("MATERIAL_SEARCH_VALUE", p, BauSystem.MESSAGE.parse(searchParameter.burnable.getChatValue(), p)), clickType -> {
|
||||
searchParameter.burnable = searchParameter.burnable.next();
|
||||
searchGUI(p);
|
||||
}));
|
||||
swInventory.setItem(28, new SWItem(Material.WATER_BUCKET, BauSystem.MESSAGE.parse("MATERIAL_SEARCH_WATERLOGGABLE", p) + BauSystem.MESSAGE.parse("MATERIAL_SEARCH_VALUE", p, BauSystem.MESSAGE.parse(search.waterloggable.getChatValue(), p)), clickType -> {
|
||||
search.waterloggable = search.waterloggable.next();
|
||||
swInventory.setItem(28, new SWItem(Material.WATER_BUCKET, BauSystem.MESSAGE.parse("MATERIAL_SEARCH_WATERLOGGABLE", p) + BauSystem.MESSAGE.parse("MATERIAL_SEARCH_VALUE", p, BauSystem.MESSAGE.parse(searchParameter.waterloggable.getChatValue(), p)), clickType -> {
|
||||
searchParameter.waterloggable = searchParameter.waterloggable.next();
|
||||
searchGUI(p);
|
||||
}));
|
||||
swInventory.setItem(29, new SWItem(Material.PISTON, BauSystem.MESSAGE.parse("MATERIAL_SEARCH_UNMOVEABLE", p) + BauSystem.MESSAGE.parse("MATERIAL_SEARCH_VALUE", p, BauSystem.MESSAGE.parse(search.unmoveable.getChatValue(), p)), clickType -> {
|
||||
search.unmoveable = search.unmoveable.next();
|
||||
swInventory.setItem(29, new SWItem(Material.PISTON, BauSystem.MESSAGE.parse("MATERIAL_SEARCH_UNMOVEABLE", p) + BauSystem.MESSAGE.parse("MATERIAL_SEARCH_VALUE", p, BauSystem.MESSAGE.parse(searchParameter.unmoveable.getChatValue(), p)), clickType -> {
|
||||
searchParameter.unmoveable = searchParameter.unmoveable.next();
|
||||
searchGUI(p);
|
||||
}));
|
||||
swInventory.setItem(34, new SWItem(Material.NETHER_BRICK, BauSystem.MESSAGE.parse("MATERIAL_SEARCH_BLASTRESISTANCE", p) + BauSystem.MESSAGE.parse("MATERIAL_SEARCH_VALUE", p, search.blastResistance), clickType -> {
|
||||
SWAnvilInv swAnvilInv = new SWAnvilInv(p, BauSystem.MESSAGE.parse("MATERIAL_SEARCH_BLASTRESISTANCE", p), search.blastResistance);
|
||||
swInventory.setItem(34, new SWItem(Material.NETHER_BRICK, BauSystem.MESSAGE.parse("MATERIAL_SEARCH_BLASTRESISTANCE", p) + BauSystem.MESSAGE.parse("MATERIAL_SEARCH_VALUE", p, searchParameter.blastResistance), clickType -> {
|
||||
SWAnvilInv swAnvilInv = new SWAnvilInv(p, BauSystem.MESSAGE.parse("MATERIAL_SEARCH_BLASTRESISTANCE", p), searchParameter.blastResistance);
|
||||
swAnvilInv.setCallback(s -> {
|
||||
if (s.isEmpty() || s.matches("((([><]=?)|!|=)\\d+(\\.|,\\d+)?)( ((([><]=?)|!|=)\\d+(\\.|,\\d+)?))*")) {
|
||||
search.blastResistance = s;
|
||||
searchParameter.blastResistance = s;
|
||||
}
|
||||
searchGUI(p);
|
||||
});
|
||||
@@ -262,14 +261,4 @@ public class MaterialCommand extends SWCommand implements Listener {
|
||||
}));
|
||||
swInventory.open();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
searchMap.put(event.getPlayer(), new Search());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||
searchMap.remove(event.getPlayer());
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -132,7 +132,7 @@ public class MaterialLazyInit {
|
||||
}), originalMaterial);
|
||||
}
|
||||
|
||||
public boolean is(MaterialCommand.Search search) {
|
||||
public boolean is(MaterialCommand.SearchParameter search) {
|
||||
boolean result = true;
|
||||
result &= search.transparent.test(transparent);
|
||||
result &= search.solid.test(solid);
|
||||
|
||||
Reference in New Issue
Block a user