SteamWar/BauSystem2.0
Archiviert
12
0

Add MaterialLazyInit
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
yoyosource 2022-08-26 20:16:38 +02:00
Ursprung 948c19167a
Commit 6830852c78
2 geänderte Dateien mit 174 neuen und 143 gelöschten Zeilen

Datei anzeigen

@ -33,8 +33,6 @@ import lombok.AllArgsConstructor;
import lombok.Getter;
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;
@ -44,10 +42,7 @@ 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;
@Linked(LinkageType.COMMAND)
@Linked(LinkageType.LISTENER)
@ -57,150 +52,26 @@ public class MaterialCommand extends SWCommand implements Listener {
super("material");
}
private List<MaterialData> materialData = new ArrayList<>();
private Map<Player, Search> searchMap = new HashMap<>();
{
for (Material value : Material.values()) {
if (!value.isBlock()) {
continue;
}
if (value.isLegacy()) {
continue;
}
materialData.add(new MaterialData(value));
}
}
private static class MaterialData {
private Material material;
private Material originalMaterial;
private String name;
private double blastResistance;
private double hardness;
private boolean transparent;
private boolean solid;
private boolean gravity;
private boolean occluding;
private boolean interacteable;
private boolean flammable;
private boolean burnable;
private boolean waterloggable;
public MaterialData(Material material) {
this.originalMaterial = material;
name = material.name();
blastResistance = material.getBlastResistance();
hardness = material.getHardness();
transparent = material.isTransparent();
solid = material.isSolid();
gravity = material.hasGravity();
occluding = material.isOccluding();
interacteable = material.isInteractable();
flammable = material.isFlammable();
burnable = material.isBurnable();
BlockData blockData = material.createBlockData();
waterloggable = blockData instanceof Waterlogged;
if (material.isItem() && material != Material.AIR) {
this.material = material;
} else {
this.material = Material.GHAST_TEAR;
}
}
public SWListInv.SWListEntry<Material> toSWItem(Player p) {
List<String> lore = new ArrayList<>();
lore.add(BauSystem.MESSAGE.parse("MATERIAL_BLAST_RESISTANCE", p, blastResistance));
lore.add(BauSystem.MESSAGE.parse(blastResistance > 9 ? "MATERIAL_TNT_UNBREAKABLE" : "MATERIAL_TNT_BREAKABLE", p));
lore.add(BauSystem.MESSAGE.parse("MATERIAL_HARDNESS", p, hardness));
if (transparent) {
lore.add(BauSystem.MESSAGE.parse("MATERIAL_TRANSPARENT", p));
}
if (solid) {
lore.add(BauSystem.MESSAGE.parse("MATERIAL_SOLID", p));
}
if (gravity) {
lore.add(BauSystem.MESSAGE.parse("MATERIAL_GRAVITY", p));
}
if (occluding) {
lore.add(BauSystem.MESSAGE.parse("MATERIAL_OCCLUDING", p));
}
if (interacteable) {
lore.add(BauSystem.MESSAGE.parse("MATERIAL_INTERACTABLE", p));
}
if (flammable) {
lore.add(BauSystem.MESSAGE.parse("MATERIAL_FLAMMABLE", p));
}
if (burnable) {
lore.add(BauSystem.MESSAGE.parse("MATERIAL_BURNABLE", p));
}
if (waterloggable) {
lore.add(BauSystem.MESSAGE.parse("MATERIAL_WATERLOGGABLE", p));
}
return new SWListInv.SWListEntry<>(new SWItem(material, "§e" + name, lore, false, clickType -> {
}), originalMaterial);
}
public boolean is(Search search) {
boolean result = true;
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 (!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(2))) 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(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;
}
}
}
if (search.name.isEmpty()) {
return true;
}
return Pattern.compile(search.name.toLowerCase().replace(".", ".+").replace(" ", ".")).asPredicate().test(name.toLowerCase());
}
}
@Getter
@Setter
private static class Search {
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;
static class Search {
SearchType transparent = SearchType.IGNORE;
SearchType solid = SearchType.IGNORE;
SearchType gravity = SearchType.IGNORE;
SearchType occluding = SearchType.IGNORE;
SearchType interacteable = SearchType.IGNORE;
SearchType flammable = SearchType.IGNORE;
SearchType burnable = SearchType.IGNORE;
SearchType waterloggable = SearchType.IGNORE;
private String blastResistance = ">=0";
private String name = "";
String blastResistance = ">=0";
String name = "";
}
@AllArgsConstructor
private enum SearchType implements EnumDisplay {
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);
@ -307,12 +178,12 @@ public class MaterialCommand extends SWCommand implements Listener {
public void materialGUI(Player p, Search search) {
List<SWListInv.SWListEntry<Material>> swListEntries = new ArrayList<>();
materialData.forEach(data -> {
MaterialLazyInit.materialData.forEach(data -> {
if (data.is(search)) {
swListEntries.add(data.toSWItem(p));
}
});
SWListInv<Material> materialSWListInv = new SWListInv<>(p, BauSystem.MESSAGE.parse("MATERIAL_INV_NAME", p, swListEntries.size(), materialData.size()), false, swListEntries, (clickType, material) -> {
SWListInv<Material> materialSWListInv = new SWListInv<>(p, BauSystem.MESSAGE.parse("MATERIAL_INV_NAME", p, swListEntries.size(), MaterialLazyInit.materialData.size()), false, swListEntries, (clickType, material) -> {
});
materialSWListInv.setItem(49, new SWItem(Material.NAME_TAG, BauSystem.MESSAGE.parse("MATERIAL_SEARCH", p), clickType -> {
searchGUI(p);

Datei anzeigen

@ -0,0 +1,160 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2022 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.util;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.inventory.SWItem;
import de.steamwar.inventory.SWListInv;
import org.bukkit.Material;
import org.bukkit.block.data.BlockData;
import org.bukkit.block.data.Waterlogged;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;
public class MaterialLazyInit {
static List<MaterialData> materialData = new ArrayList<>();
{
for (Material value : Material.values()) {
if (!value.isBlock()) {
continue;
}
if (value.isLegacy()) {
continue;
}
materialData.add(new MaterialData(value));
}
}
static class MaterialData {
private Material material;
private Material originalMaterial;
private String name;
private double blastResistance;
private double hardness;
private boolean transparent;
private boolean solid;
private boolean gravity;
private boolean occluding;
private boolean interacteable;
private boolean flammable;
private boolean burnable;
private boolean waterloggable;
public MaterialData(Material material) {
this.originalMaterial = material;
name = material.name();
blastResistance = material.getBlastResistance();
hardness = material.getHardness();
transparent = material.isTransparent();
solid = material.isSolid();
gravity = material.hasGravity();
occluding = material.isOccluding();
interacteable = material.isInteractable();
flammable = material.isFlammable();
burnable = material.isBurnable();
BlockData blockData = material.createBlockData();
waterloggable = blockData instanceof Waterlogged;
if (material.isItem() && material != Material.AIR) {
this.material = material;
} else {
this.material = Material.GHAST_TEAR;
}
}
public SWListInv.SWListEntry<Material> toSWItem(Player p) {
List<String> lore = new ArrayList<>();
lore.add(BauSystem.MESSAGE.parse("MATERIAL_BLAST_RESISTANCE", p, blastResistance));
lore.add(BauSystem.MESSAGE.parse(blastResistance > 9 ? "MATERIAL_TNT_UNBREAKABLE" : "MATERIAL_TNT_BREAKABLE", p));
lore.add(BauSystem.MESSAGE.parse("MATERIAL_HARDNESS", p, hardness));
if (transparent) {
lore.add(BauSystem.MESSAGE.parse("MATERIAL_TRANSPARENT", p));
}
if (solid) {
lore.add(BauSystem.MESSAGE.parse("MATERIAL_SOLID", p));
}
if (gravity) {
lore.add(BauSystem.MESSAGE.parse("MATERIAL_GRAVITY", p));
}
if (occluding) {
lore.add(BauSystem.MESSAGE.parse("MATERIAL_OCCLUDING", p));
}
if (interacteable) {
lore.add(BauSystem.MESSAGE.parse("MATERIAL_INTERACTABLE", p));
}
if (flammable) {
lore.add(BauSystem.MESSAGE.parse("MATERIAL_FLAMMABLE", p));
}
if (burnable) {
lore.add(BauSystem.MESSAGE.parse("MATERIAL_BURNABLE", p));
}
if (waterloggable) {
lore.add(BauSystem.MESSAGE.parse("MATERIAL_WATERLOGGABLE", p));
}
return new SWListInv.SWListEntry<>(new SWItem(material, "§e" + name, lore, false, clickType -> {
}), originalMaterial);
}
public boolean is(MaterialCommand.Search search) {
boolean result = true;
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 (!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(2))) 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(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;
}
}
}
if (search.name.isEmpty()) {
return true;
}
return Pattern.compile(search.name.toLowerCase().replace(".", ".+").replace(" ", ".")).asPredicate().test(name.toLowerCase());
}
}
}