Finishes the scrapper implementation
Some checks failed
EpicKnarvik97/Blacksmith/pipeline/head There was a failure building this commit

This commit is contained in:
2024-05-04 01:01:56 +02:00
parent 455db78988
commit 4012e532da
30 changed files with 501 additions and 216 deletions

View File

@@ -4,6 +4,7 @@ import net.knarcraft.blacksmith.BlacksmithPlugin;
import net.knarcraft.blacksmith.util.ItemHelper;
import org.bukkit.Material;
import org.bukkit.Tag;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.List;
@@ -46,7 +47,7 @@ public enum SmithPreset {
*
* @param filters <p>The filters applicable to this preset</p>
*/
SmithPreset(SmithPresetFilter[] filters) {
SmithPreset(@NotNull SmithPresetFilter[] filters) {
this.filters = filters;
}
@@ -56,7 +57,7 @@ public enum SmithPreset {
* @param filter <p>The filter to check</p>
* @return <p>True if the filter is supported</p>
*/
public boolean supportsFilter(SmithPresetFilter filter) {
public boolean supportsFilter(@NotNull SmithPresetFilter filter) {
return List.of(filters).contains(filter);
}
@@ -65,6 +66,7 @@ public enum SmithPreset {
*
* @return <p>The filters supported by this preset</p>
*/
@NotNull
public List<SmithPresetFilter> getSupportedFilters() {
return List.of(filters);
}
@@ -74,6 +76,7 @@ public enum SmithPreset {
*
* @return <p>All available smith presets</p>
*/
@NotNull
public static List<String> getPresetNames() {
List<String> presetNames = new ArrayList<>();
for (SmithPreset preset : SmithPreset.values()) {
@@ -88,7 +91,8 @@ public enum SmithPreset {
* @param possiblePreset <p>The string that might be a preset</p>
* @return <p>The string, possibly with the preset replaced</p>
*/
public static String replacePreset(String possiblePreset) {
@NotNull
public static String replacePreset(@NotNull String possiblePreset) {
boolean negated = false;
String upperCasedPreset = possiblePreset.replace('-', '_').toUpperCase();
@@ -143,6 +147,7 @@ public enum SmithPreset {
* @param filter <p>The filter to use for filtering</p>
* @return <p>The materials included in this preset, filtered using the given filter</p>
*/
@NotNull
public List<Material> getFilteredMaterials(SmithPresetFilter filter) {
List<Material> materials = new ArrayList<>(this.getMaterials());
materials.removeIf((item) -> !filter.isIncluded(item));
@@ -154,6 +159,7 @@ public enum SmithPreset {
*
* @return <p>All materials in this preset</p>
*/
@NotNull
public List<Material> getMaterials() {
return switch (this) {
case BLACKSMITH -> ItemHelper.getAllReforgeAbleMaterials();
@@ -168,6 +174,7 @@ public enum SmithPreset {
*
* @return <p>All ranged weapon materials</p>
*/
@NotNull
private List<Material> getRanged() {
List<Material> ranged = new ArrayList<>();
ranged.add(Material.TRIDENT);
@@ -181,6 +188,7 @@ public enum SmithPreset {
*
* @return <p>All tool materials</p>
*/
@NotNull
private List<Material> getTools() {
List<Material> tools = new ArrayList<>();
tools.addAll(Tag.ITEMS_HOES.getValues());
@@ -198,6 +206,7 @@ public enum SmithPreset {
*
* @return <p>All weapon materials</p>
*/
@NotNull
private List<Material> getWeapons() {
List<Material> weapons = new ArrayList<>(getSwords());
weapons.addAll(getRanged());
@@ -210,10 +219,17 @@ public enum SmithPreset {
*
* @return <p>All sword materials</p>
*/
@NotNull
private Set<Material> getSwords() {
return Tag.ITEMS_SWORDS.getValues();
}
/**
* Gets all types of armor
*
* @return <p>All armor types</p>
*/
@NotNull
private List<Material> getArmor() {
List<Material> armor = new ArrayList<>();
armor.addAll(getMaterialsEndingWith("HELMET"));
@@ -230,7 +246,8 @@ public enum SmithPreset {
* @param end <p>The string to look for</p>
* @return <p>The resulting materials</p>
*/
private List<Material> getMaterialsEndingWith(String end) {
@NotNull
private List<Material> getMaterialsEndingWith(@NotNull String end) {
List<Material> matchedMaterials = new ArrayList<>();
for (Material material : ItemHelper.getAllReforgeAbleMaterials()) {
if (!material.name().startsWith("LEGACY") && material.name().endsWith(end)) {
@@ -245,6 +262,7 @@ public enum SmithPreset {
*
* @return <p>All material names for this smith</p>
*/
@NotNull
private List<String> getMaterialNames() {
return getNames(this.getMaterials());
}
@@ -255,7 +273,8 @@ public enum SmithPreset {
* @param filter <p>The filter used for filtering materials</p>
* @return <p>All material names for this smith</p>
*/
private List<String> getMaterialNames(SmithPresetFilter filter) {
@NotNull
private List<String> getMaterialNames(@NotNull SmithPresetFilter filter) {
return getNames(this.getFilteredMaterials(filter));
}
@@ -265,7 +284,8 @@ public enum SmithPreset {
* @param materials <p>The materials to get the names of</p>
* @return <p>The names of the materials</p>
*/
private List<String> getNames(List<Material> materials) {
@NotNull
private List<String> getNames(@NotNull List<Material> materials) {
List<String> items = new ArrayList<>();
for (Material material : materials) {
items.add(material.name().toLowerCase().replace("_", "-"));
@@ -279,7 +299,8 @@ public enum SmithPreset {
* @param materials <p>The material names to negate</p>
* @return <p>The negated material names</p>
*/
private static List<String> negateMaterials(List<String> materials) {
@NotNull
private static List<String> negateMaterials(@NotNull List<String> materials) {
List<String> negatedMaterials = new ArrayList<>(materials.size());
materials.forEach((material) -> {
if (material != null && !material.isBlank()) {