Skip to content

Commit

Permalink
Added mask materials option
Browse files Browse the repository at this point in the history
  • Loading branch information
WillFP committed Aug 12, 2021
1 parent 341a30e commit e053514
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 20 deletions.
52 changes: 32 additions & 20 deletions eco-api/src/main/java/com/willfp/eco/core/gui/slot/FillerMask.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;

import java.util.Arrays;
import java.util.List;

/**
Expand Down Expand Up @@ -39,35 +40,46 @@ public class FillerMask {
*/
public FillerMask(@NotNull final Material material,
@NotNull final String... pattern) {
if (material == Material.AIR) {
throw new IllegalArgumentException("Material cannot be air!");
this(new MaskMaterials(material), pattern);
}

/**
* Create a new filler mask.
*
* @param materials The mask materials.
* @param pattern The pattern.
*/
public FillerMask(@NotNull final MaskMaterials materials,
@NotNull final String... pattern) {
if (Arrays.stream(materials.materials()).anyMatch(material -> material == Material.AIR)) {
throw new IllegalArgumentException("Materials cannot be air!");
}

mask = ListUtils.create2DList(6, 9);

ItemStack itemStack = new ItemStackBuilder(material)
.setDisplayName("&r")
.build();
for (int i = 0; i < materials.materials().length; i++) {
ItemStack itemStack = new ItemStackBuilder(materials.materials()[i])
.setDisplayName("&r")
.build();

int row = 0;
int row = 0;

for (String patternRow : pattern) {
int column = 0;
if (patternRow.length() != 9) {
throw new IllegalArgumentException("Invalid amount of columns in pattern!");
}
for (char c : patternRow.toCharArray()) {
if (c == '0') {
mask.get(row).set(column, null);
} else if (c == '1') {
mask.get(row).set(column, new FillerSlot(itemStack));
} else {
throw new IllegalArgumentException("Invalid character in pattern! (Must only be 0 and 1)");
for (String patternRow : pattern) {
int column = 0;
if (patternRow.length() != 9) {
throw new IllegalArgumentException("Invalid amount of columns in pattern!");
}
for (char c : patternRow.toCharArray()) {
if (c == '0') {
mask.get(row).set(column, null);
} else if (c == Character.forDigit(i + 1, 10)) {
mask.get(row).set(column, new FillerSlot(itemStack));
}

column++;
column++;
}
row++;
}
row++;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.willfp.eco.core.gui.slot;

import org.bukkit.Material;
import org.jetbrains.annotations.NotNull;

/**
* Mask materials store a set of materials which can be accessed by
* a filler mask.
*
* @param materials The materials.
*/
public record MaskMaterials(@NotNull Material... materials) {

}

0 comments on commit e053514

Please sign in to comment.