Skip to content

Commit

Permalink
Merge pull request #7333 from TownyAdvanced/feat/generic-include-list
Browse files Browse the repository at this point in the history
Make addItemList accept any list of the same type
  • Loading branch information
LlmDl authored Jun 1, 2024
2 parents 73f3921 + 02cac87 commit 690695b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@

import com.palmergames.bukkit.towny.TownyMessaging;
import com.palmergames.bukkit.util.BukkitTools;
import com.palmergames.bukkit.util.ItemLists;

import org.bukkit.Bukkit;
import org.bukkit.Keyed;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.Registry;
import org.bukkit.Tag;
Expand Down Expand Up @@ -175,18 +173,12 @@ public Builder<T, F> add(@NotNull String... names) {
}

/**
* Adds an entire ItemLists contents.
* @param itemList ItemLists to add.
* Adds an entire lists contents.
* @param list list to add.
*/
public Builder<T, F> addItemList(@NotNull ItemLists itemList) {
for (Material mat: itemList.tagged) {
final T match = BukkitTools.matchRegistry(this.registry, mat.name());
if (match != null)
anyMatchPredicates.add(t -> t.equals(match));
else {
TownyMessaging.sendDebugMsg("Expected element with name '" + mat.name() + "' was not found in the " + this.clazz.getSimpleName() + " registry.");
anyMatchPredicates.add(t -> false);
}
public Builder<T, F> includeList(@NotNull AbstractRegistryList<T> list) {
for (final T element : list.tagged) {
anyMatchPredicates.add(t -> t.equals(element));
}

return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,10 +295,10 @@ public Collection<String> getMaterialNameCollection() {
.endsWith("RAIL")
.endsWith("PUMPKIN_STEM").endsWith("MELON_STEM")
.endsWith("_AMETHYST_BUD").add("AMETHYST_CLUSTER")
.addItemList(FLOWERS)
.addItemList(SAPLINGS)
.addItemList(PRESSURE_PLATES)
.addItemList(WOOD_DOORS)
.includeList(FLOWERS)
.includeList(SAPLINGS)
.includeList(PRESSURE_PLATES)
.includeList(WOOD_DOORS)
.build();

/**
Expand Down

0 comments on commit 690695b

Please sign in to comment.