SteamWar/BauSystem2.0
Archiviert
12
0

Update MaterialCommand
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
yoyosource 2022-08-08 17:57:42 +02:00
Ursprung 7ae525391e
Commit 09c69e4b3c
3 geänderte Dateien mit 139 neuen und 148 gelöschten Zeilen

Datei anzeigen

@ -931,6 +931,9 @@ NAVIGATION_WAND=§eNavigation Wand
NAVIGATION_WAND_LEFT_CLICK=§eLeft click: jump to location
NAVIGATION_WAND_RIGHT_CLICK=§eRight click: pass through walls
# Material
MATERIAL_SEARCH_PROPERTY_TRUE = §aShould have
MATERIAL_SEARCH_PROPERTY_FALSE = §cShould not have
MATERIAL_SEARCH_PROPERTY_IGNORE = §eIgnore
MATERIAL_INV_NAME=§eMaterial {0}/{1}
MATERIAL_SEARCH=§eSearch
MATERIAL_BACK=§eBack
@ -944,9 +947,6 @@ MATERIAL_SEARCH_FLAMMABLE=§eFlammable
MATERIAL_SEARCH_BURNABLE=§eBurnable
MATERIAL_SEARCH_WATERLOGGABLE=§eWaterloggable
MATERIAL_SEARCH_BLASTRESISTANCE=§eBlast resistance
MATERIAL_SEARCH_BLASTRESISTANCE_MIN=§eBlast resistance minimum
MATERIAL_SEARCH_BLASTRESISTANCE_MAX=§eBlast resistance maximum
MATERIAL_SEARCH_BLASTRESISTANCE_EXACT=§eBlast resistance
MATERIAL_SEARCH_VALUE=§8: §e{0}
MATERIAL_BLAST_RESISTANCE=§8- §eBlast resistance§8: §7{0}
MATERIAL_HARDNESS=§8- §eHardness§8: §7{0}

Datei anzeigen

@ -911,6 +911,9 @@ NAVIGATION_WAND=§eNavigation Wand
NAVIGATION_WAND_LEFT_CLICK=§eLeft click: jump to location
NAVIGATION_WAND_RIGHT_CLICK=§eRight click: pass through walls
# Material
MATERIAL_SEARCH_PROPERTY_TRUE = §aHat
MATERIAL_SEARCH_PROPERTY_FALSE = §cHat nicht
MATERIAL_SEARCH_PROPERTY_IGNORE = §eEgal
MATERIAL_INV_NAME=§eMaterial {0}/{1}
MATERIAL_SEARCH=§eSuchen
MATERIAL_BACK=§eZurück
@ -924,9 +927,6 @@ MATERIAL_SEARCH_FLAMMABLE=§eFlammbar
MATERIAL_SEARCH_BURNABLE=§eBrennbar
MATERIAL_SEARCH_WATERLOGGABLE=§eWasserspeicherbar
MATERIAL_SEARCH_BLASTRESISTANCE=§eBlast Resistance
MATERIAL_SEARCH_BLASTRESISTANCE_MIN=§eBlast Resistance mindestens
MATERIAL_SEARCH_BLASTRESISTANCE_MAX=§eBlast Resistance maximal
MATERIAL_SEARCH_BLASTRESISTANCE_EXACT=§eBlast Resistance
MATERIAL_SEARCH_VALUE=§8: §e{0}
MATERIAL_BLAST_RESISTANCE=§8- §eBlast Resistance§8: §7{0}
MATERIAL_HARDNESS=§8- §eHärte§8: §7{0}

Datei anzeigen

@ -22,12 +22,14 @@ package de.steamwar.bausystem.features.util;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.linkage.LinkageType;
import de.steamwar.bausystem.linkage.Linked;
import de.steamwar.bausystem.shared.EnumDisplay;
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;
import de.steamwar.inventory.SWListInv;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;
import org.bukkit.Material;
@ -41,6 +43,9 @@ import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import java.util.*;
import java.util.function.BiConsumer;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
@ -141,101 +146,126 @@ public class MaterialCommand extends SWCommand implements Listener {
public boolean is(Search search) {
boolean result = true;
if (search.transparent) {
result &= transparent;
}
if (search.solid) {
result &= solid;
}
if (search.gravity) {
result &= gravity;
}
if (search.occluding) {
result &= occluding;
}
if (search.interacteable) {
result &= interacteable;
}
if (search.flammable) {
result &= flammable;
}
if (search.burnable) {
result &= burnable;
}
if (search.waterloggable) {
result &= waterloggable;
}
result &= search.transparent.test(transparent);
result &= search.solid.test(solid);
result &= search.gravity.test(gravity);
result &= search.occluding.test(occluding);
result &= search.interacteable.test(interacteable);
result &= search.flammable.test(flammable);
result &= search.burnable.test(burnable);
result &= search.waterloggable.test(waterloggable);
if (!result) {
return false;
}
if (!(blastResistance >= search.blastResistanceMin && blastResistance < search.blastResistanceMax)) {
return false;
if (!search.blastResistance.isEmpty()) {
String[] strings = search.blastResistance.split(" ");
for (String string : strings) {
string = string.replace(",", ".");
if (string.startsWith("=")) {
if (blastResistance != Double.parseDouble(string.substring(1))) return false;
} else if (string.startsWith(">")) {
if (blastResistance <= Double.parseDouble(string.substring(1))) return false;
} else if (string.startsWith("<")) {
if (blastResistance >= Double.parseDouble(string.substring(1))) return false;
} else if (string.startsWith("!")) {
if (blastResistance == Double.parseDouble(string.substring(1))) return false;
} else if (string.startsWith(">=")) {
if (blastResistance < Double.parseDouble(string.substring(2))) return false;
} else if (string.startsWith("<=")) {
if (blastResistance > Double.parseDouble(string.substring(2)))return false;
}
}
}
if (search.name.isEmpty()) {
return true;
}
return Pattern.compile(".*" + search.name.toLowerCase().replace(' ', '.') + ".*").asPredicate().test(name.toLowerCase());
return Pattern.compile(search.name.toLowerCase().replace(".", ".+").replace(" ", ".")).asPredicate().test(name.toLowerCase());
}
}
@Getter
@Setter
private static class Search {
private boolean transparent = false;
private boolean solid = false;
private boolean gravity = false;
private boolean occluding = false;
private boolean interacteable = false;
private boolean flammable = false;
private boolean burnable = false;
private boolean waterloggable = false;
private SearchType transparent = SearchType.IGNORE;
private SearchType solid = SearchType.IGNORE;
private SearchType gravity = SearchType.IGNORE;
private SearchType occluding = SearchType.IGNORE;
private SearchType interacteable = SearchType.IGNORE;
private SearchType flammable = SearchType.IGNORE;
private SearchType burnable = SearchType.IGNORE;
private SearchType waterloggable = SearchType.IGNORE;
private double blastResistanceMin = 0;
private double blastResistanceMax = 5000000;
private String blastResistance = "";
private String name = "";
}
@AllArgsConstructor
private enum SearchType implements EnumDisplay {
TRUE("MATERIAL_SEARCH_PROPERTY_TRUE", b -> b),
FALSE("MATERIAL_SEARCH_PROPERTY_FALSE", b -> !b),
IGNORE("MATERIAL_SEARCH_PROPERTY_IGNORE", b -> true);
@Getter
private String chatValue;
private Predicate<Boolean> predicate;
public boolean test(boolean b) {
return predicate.test(b);
}
public SearchType next() {
switch (this) {
case TRUE:
return FALSE;
case FALSE:
return IGNORE;
case IGNORE:
return TRUE;
}
return IGNORE;
}
}
@Register
public void materialGUI(Player p) {
materialGUI(p, searchMap.get(p));
}
private static final Map<String, BiConsumer<Search, SearchType>> elements = new HashMap<>();
static {
elements.put("-transparent", (search, searchType) -> search.transparent = searchType);
elements.put("-solid", (search, searchType) -> search.solid = searchType);
elements.put("-gravity", (search, searchType) -> search.gravity = searchType);
elements.put("-occluding", (search, searchType) -> search.occluding = searchType);
elements.put("-interacteable", (search, searchType) -> search.interacteable = searchType);
elements.put("-flammable", (search, searchType) -> search.flammable = searchType);
elements.put("-burnable", (search, searchType) -> search.burnable = searchType);
elements.put("-waterloggable", (search, searchType) -> search.waterloggable = searchType);
}
@Register
public void search(Player p, @Mapper("search") String... searches) {
Search search = new Search();
for (String s : searches) {
boolean has = false;
for (Map.Entry<String, BiConsumer<Search, SearchType>> element: elements.entrySet()) {
if (s.startsWith(element.getKey() + ":")) {
element.getValue().accept(search, 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()));
has = true;
}
if (has) break;
}
if (has) continue;
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;
case "-br:":
case "-blastresistance:":
s = s.substring(s.indexOf(':') + 1).replace('_', ' ');
if (s.isEmpty() || s.matches("((([><]=?)|!|=)\\d+(\\.|,\\d+)?)( ((([><]=?)|!|=)\\d+(\\.|,\\d+)?))*")) {
search.blastResistance = s;
}
break;
default:
search.name = s;
@ -247,15 +277,17 @@ public class MaterialCommand extends SWCommand implements Listener {
@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"));
List<String> results = new ArrayList<>();
for (String s : Arrays.asList("-transparent", "-solid", "-gravity", "-occluding", "-interacteable", "-flammable", "-burnable", "-waterloggable")) {
results.add(s + ":true");
results.add(s + ":false");
results.add(s + ":ignore");
s = s.substring(0, 2);
results.add(s + ":true");
results.add(s + ":false");
results.add(s + ":ignore");
}
return new TypeMapper<String>() {
@Override
@ -265,14 +297,10 @@ public class MaterialCommand extends SWCommand implements Listener {
@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;
List<String> tabCompletes = new ArrayList<>();
tabCompletes.addAll(results);
tabCompletes.add(s);
return tabCompletes;
}
};
}
@ -306,80 +334,43 @@ public class MaterialCommand extends SWCommand implements Listener {
});
swAnvilInv.open();
}));
swInventory.setItem(19, new SWItem(Material.GLASS, BauSystem.MESSAGE.parse("MATERIAL_SEARCH_TRANSPARENT", p) + BauSystem.MESSAGE.parse("MATERIAL_SEARCH_VALUE", p, search.transparent), clickType -> {
search.transparent = !search.transparent;
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();
searchGUI(p);
}));
swInventory.setItem(20, new SWItem(Material.BRICK, BauSystem.MESSAGE.parse("MATERIAL_SEARCH_SOLID", p) + BauSystem.MESSAGE.parse("MATERIAL_SEARCH_VALUE", p, search.solid), clickType -> {
search.solid = !search.solid;
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();
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, search.gravity), clickType -> {
search.gravity = !search.gravity;
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();
searchGUI(p);
}));
swInventory.setItem(22, new SWItem(Material.BIRCH_LOG, BauSystem.MESSAGE.parse("MATERIAL_SEARCH_OCCLUDING", p) + BauSystem.MESSAGE.parse("MATERIAL_SEARCH_VALUE", p, search.occluding), clickType -> {
search.occluding = !search.occluding;
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();
searchGUI(p);
}));
swInventory.setItem(23, new SWItem(Material.OAK_BUTTON, BauSystem.MESSAGE.parse("MATERIAL_SEARCH_INTERACTEABLE", p) + BauSystem.MESSAGE.parse("MATERIAL_SEARCH_VALUE", p, search.interacteable), clickType -> {
search.interacteable = !search.interacteable;
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();
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, search.flammable), clickType -> {
search.flammable = !search.flammable;
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();
searchGUI(p);
}));
swInventory.setItem(25, new SWItem(Material.LAVA_BUCKET, BauSystem.MESSAGE.parse("MATERIAL_SEARCH_BURNABLE", p) + BauSystem.MESSAGE.parse("MATERIAL_SEARCH_VALUE", p, search.burnable), clickType -> {
search.burnable = !search.burnable;
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();
searchGUI(p);
}));
swInventory.setItem(28, new SWItem(Material.WATER_BUCKET, BauSystem.MESSAGE.parse("MATERIAL_SEARCH_WATERLOGGABLE", p) + BauSystem.MESSAGE.parse("MATERIAL_SEARCH_VALUE", p, search.waterloggable), clickType -> {
search.waterloggable = !search.waterloggable;
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();
searchGUI(p);
}));
swInventory.setItem(30, new SWItem(Material.FIRE_CHARGE, BauSystem.MESSAGE.parse("MATERIAL_SEARCH_BLASTRESISTANCE_MIN", p) + BauSystem.MESSAGE.parse("MATERIAL_SEARCH_VALUE", p, search.blastResistanceMin), clickType -> {
SWAnvilInv swAnvilInv = new SWAnvilInv(p, BauSystem.MESSAGE.parse("MATERIAL_SEARCH_BLASTRESISTANCE", p), search.blastResistanceMin + "");
swInventory.setItem(30, 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);
swAnvilInv.setCallback(s -> {
try {
search.blastResistanceMin = Double.parseDouble(s);
if (search.blastResistanceMin < 0) search.blastResistanceMin = 0;
if (search.blastResistanceMin > 5000000) search.blastResistanceMin = 5000000;
if (search.blastResistanceMin > search.blastResistanceMax)
search.blastResistanceMin = search.blastResistanceMax;
} catch (NumberFormatException e) {
// Ignored
}
searchGUI(p);
});
swAnvilInv.open();
}));
swInventory.setItem(31, new SWItem(Material.TNT, BauSystem.MESSAGE.parse("MATERIAL_SEARCH_BLASTRESISTANCE_MAX", p) + BauSystem.MESSAGE.parse("MATERIAL_SEARCH_VALUE", p, search.blastResistanceMax), clickType -> {
SWAnvilInv swAnvilInv = new SWAnvilInv(p, BauSystem.MESSAGE.parse("MATERIAL_SEARCH_BLASTRESISTANCE", p), search.blastResistanceMax + "");
swAnvilInv.setCallback(s -> {
try {
search.blastResistanceMax = Double.parseDouble(s);
if (search.blastResistanceMax > 5000000) search.blastResistanceMax = 5000000;
if (search.blastResistanceMax < 0) search.blastResistanceMax = 0;
if (search.blastResistanceMax < search.blastResistanceMin)
search.blastResistanceMax = search.blastResistanceMin;
} catch (NumberFormatException e) {
// Ignored
}
searchGUI(p);
});
swAnvilInv.open();
}));
swInventory.setItem(32, new SWItem(Material.NETHER_BRICK, BauSystem.MESSAGE.parse("MATERIAL_SEARCH_BLASTRESISTANCE_EXACT", p) + BauSystem.MESSAGE.parse("MATERIAL_SEARCH_VALUE", p, search.blastResistanceMin + "-" + search.blastResistanceMax), clickType -> {
SWAnvilInv swAnvilInv = new SWAnvilInv(p, BauSystem.MESSAGE.parse("MATERIAL_SEARCH_BLASTRESISTANCE", p), search.blastResistanceMax + "");
swAnvilInv.setCallback(s -> {
try {
search.blastResistanceMax = Double.parseDouble(s);
if (search.blastResistanceMax > 5000000) search.blastResistanceMax = 5000000;
if (search.blastResistanceMax < 0) search.blastResistanceMax = 0;
search.blastResistanceMin = search.blastResistanceMax;
} catch (NumberFormatException e) {
// Ignored
if (s.isEmpty() || s.matches("((([><]=?)|!|=)\\d+(\\.|,\\d+)?)( ((([><]=?)|!|=)\\d+(\\.|,\\d+)?))*")) {
search.blastResistance = s;
}
searchGUI(p);
});