Skip to content

Commit aee8794

Browse files
committed
Apply StackResolver
1 parent b75158a commit aee8794

File tree

86 files changed

+854
-770
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+854
-770
lines changed

src/main/java/io/github/thebusybiscuit/slimefun4/api/events/PlayerRightClickEvent.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import javax.annotation.Nonnull;
66

7+
import io.github.thebusybiscuit.slimefun4.utils.multiversion.StackResolver;
78
import org.apache.commons.lang.Validate;
89
import org.bukkit.Material;
910
import org.bukkit.block.Block;
@@ -92,13 +93,13 @@ public PlayerInteractEvent getInteractEvent() {
9293
/**
9394
* This method returns the {@link ItemStack} that was held in the hand of the {@link Player}.
9495
* It will never return null, should there be no {@link ItemStack} then it will return
95-
* {@code new ItemStack(Material.AIR)}.
96+
* {@code StackResolver.of(Material.AIR)}.
9697
*
9798
* @return The {@link ItemStack} that the {@link Player} right clicked with
9899
*/
99100
@Nonnull
100101
public ItemStack getItem() {
101-
return itemStack.orElse(new ItemStack(Material.AIR));
102+
return itemStack.orElse(StackResolver.of(Material.AIR));
102103
}
103104

104105
/**

src/main/java/io/github/thebusybiscuit/slimefun4/api/items/SlimefunItemStack.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import javax.annotation.Nonnull;
1212
import javax.annotation.Nullable;
1313

14+
import io.github.thebusybiscuit.slimefun4.utils.multiversion.StackResolver;
1415
import org.apache.commons.lang.Validate;
1516
import org.bukkit.ChatColor;
1617
import org.bukkit.Color;
@@ -78,7 +79,7 @@ public SlimefunItemStack(@Nonnull String id, @Nonnull ItemStack item, @Nonnull C
7879
}
7980

8081
public SlimefunItemStack(@Nonnull String id, @Nonnull Material type, @Nonnull Consumer<ItemMeta> consumer) {
81-
this(id, new ItemStack(type), consumer);
82+
this(id, StackResolver.of(type), consumer);
8283
}
8384

8485
public SlimefunItemStack(@Nonnull String id, @Nonnull Material type, @Nullable String name, @Nonnull Consumer<ItemMeta> consumer) {
@@ -109,7 +110,7 @@ public SlimefunItemStack(@Nonnull String id, @Nonnull ItemStack item, @Nullable
109110
}
110111

111112
public SlimefunItemStack(@Nonnull String id, @Nonnull Material type, @Nullable String name, String... lore) {
112-
this(id, new ItemStack(type), name, lore);
113+
this(id, StackResolver.of(type), name, lore);
113114
}
114115

115116
public SlimefunItemStack(@Nonnull String id, @Nonnull Material type, @Nonnull Color color, @Nullable String name, String... lore) {
@@ -284,7 +285,7 @@ public void lock() {
284285

285286
private static @Nonnull ItemStack getSkull(@Nonnull String id, @Nonnull String texture) {
286287
if (Slimefun.getMinecraftVersion() == MinecraftVersion.UNIT_TEST) {
287-
return new ItemStack(Material.PLAYER_HEAD);
288+
return StackResolver.of(Material.PLAYER_HEAD);
288289
}
289290

290291
PlayerSkin skin = PlayerSkin.fromBase64(getTexture(id, texture));

src/main/java/io/github/thebusybiscuit/slimefun4/api/recipes/RecipeType.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import javax.annotation.Nullable;
1414
import javax.annotation.ParametersAreNonnullByDefault;
1515

16+
import io.github.thebusybiscuit.slimefun4.utils.multiversion.StackResolver;
1617
import org.bukkit.ChatColor;
1718
import org.bukkit.Keyed;
1819
import org.bukkit.Material;
@@ -113,7 +114,7 @@ public RecipeType(NamespacedKey key, ItemStack item) {
113114
}
114115

115116
public RecipeType(MinecraftRecipe<?> recipe) {
116-
this.item = new ItemStack(recipe.getMachine());
117+
this.item = StackResolver.of(recipe.getMachine());
117118
this.machine = "";
118119
this.key = NamespacedKey.minecraft(recipe.getRecipeClass().getSimpleName().toLowerCase(Locale.ROOT).replace("recipe", ""));
119120
}

src/main/java/io/github/thebusybiscuit/slimefun4/core/guide/options/GuideModeOption.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import javax.annotation.Nonnull;
88
import javax.annotation.ParametersAreNonnullByDefault;
99

10+
import io.github.thebusybiscuit.slimefun4.utils.multiversion.StackResolver;
1011
import org.bukkit.ChatColor;
1112
import org.bukkit.Material;
1213
import org.bukkit.NamespacedKey;
@@ -47,7 +48,7 @@ public Optional<ItemStack> getDisplayItem(Player p, ItemStack guide) {
4748

4849
if (current.isPresent()) {
4950
SlimefunGuideMode selectedMode = current.get();
50-
ItemStack item = new ItemStack(Material.AIR);
51+
ItemStack item = StackResolver.of(Material.AIR);
5152

5253
if (selectedMode == SlimefunGuideMode.SURVIVAL_MODE) {
5354
item.setType(Material.CHEST);

src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/ItemStackAndInteger.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import javax.annotation.Nonnull;
44

5+
import io.github.thebusybiscuit.slimefun4.utils.multiversion.StackResolver;
56
import org.apache.commons.lang.Validate;
67
import org.bukkit.inventory.ItemStack;
78

@@ -42,7 +43,7 @@ public void add(int amount) {
4243

4344
private void initializeItem() {
4445
if (this.item instanceof ItemStackWrapper) {
45-
ItemStack copy = new ItemStack(item.getType(), item.getAmount());
46+
ItemStack copy = StackResolver.of(item.getType(), item.getAmount());
4647
if (this.item.hasItemMeta()) {
4748
copy.setItemMeta(this.item.getItemMeta());
4849
}

src/main/java/io/github/thebusybiscuit/slimefun4/core/services/localization/SlimefunLocalization.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import javax.annotation.Nullable;
1212
import javax.annotation.ParametersAreNonnullByDefault;
1313

14+
import io.github.thebusybiscuit.slimefun4.utils.multiversion.StackResolver;
1415
import org.apache.commons.lang.Validate;
1516
import org.bukkit.ChatColor;
1617
import org.bukkit.Keyed;
@@ -315,7 +316,7 @@ protected void loadEmbeddedLanguages() {
315316

316317
if (item == null) {
317318
// Fixes #3088
318-
return new ItemStack(Material.AIR);
319+
return StackResolver.of(Material.AIR);
319320
}
320321

321322
Language language = getLanguage(p);

src/main/java/io/github/thebusybiscuit/slimefun4/implementation/guide/SurvivalSlimefunGuide.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import javax.annotation.Nonnull;
1212
import javax.annotation.ParametersAreNonnullByDefault;
1313

14+
import io.github.thebusybiscuit.slimefun4.utils.multiversion.StackResolver;
1415
import org.apache.commons.lang.Validate;
1516
import org.bukkit.ChatColor;
1617
import org.bukkit.Material;
@@ -484,15 +485,15 @@ private <T extends Recipe> void showRecipeChoices(T recipe, ItemStack[] recipeIt
484485
RecipeChoice[] choices = Slimefun.getMinecraftRecipeService().getRecipeShape(recipe);
485486

486487
if (choices.length == 1 && choices[0] instanceof MaterialChoice materialChoice) {
487-
recipeItems[4] = new ItemStack(materialChoice.getChoices().get(0));
488+
recipeItems[4] = StackResolver.of(materialChoice.getChoices().get(0));
488489

489490
if (materialChoice.getChoices().size() > 1) {
490491
task.add(recipeSlots[4], materialChoice);
491492
}
492493
} else {
493494
for (int i = 0; i < choices.length; i++) {
494495
if (choices[i] instanceof MaterialChoice materialChoice) {
495-
recipeItems[i] = new ItemStack(materialChoice.getChoices().get(0));
496+
recipeItems[i] = StackResolver.of(materialChoice.getChoices().get(0));
496497

497498
if (materialChoice.getChoices().size() > 1) {
498499
task.add(recipeSlots[i], materialChoice);

src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids/FarmerAndroid.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import javax.annotation.ParametersAreNonnullByDefault;
77

8+
import io.github.thebusybiscuit.slimefun4.utils.multiversion.StackResolver;
89
import org.bukkit.Bukkit;
910
import org.bukkit.Effect;
1011
import org.bukkit.Material;
@@ -69,13 +70,13 @@ private ItemStack getDropFromCrop(Material crop) {
6970
Random random = ThreadLocalRandom.current();
7071

7172
return switch (crop) {
72-
case WHEAT -> new ItemStack(Material.WHEAT, random.nextInt(2) + 1);
73-
case POTATOES -> new ItemStack(Material.POTATO, random.nextInt(3) + 1);
74-
case CARROTS -> new ItemStack(Material.CARROT, random.nextInt(3) + 1);
75-
case BEETROOTS -> new ItemStack(Material.BEETROOT, random.nextInt(3) + 1);
76-
case COCOA -> new ItemStack(Material.COCOA_BEANS, random.nextInt(3) + 1);
77-
case NETHER_WART -> new ItemStack(Material.NETHER_WART, random.nextInt(3) + 1);
78-
case SWEET_BERRY_BUSH -> new ItemStack(Material.SWEET_BERRIES, random.nextInt(3) + 1);
73+
case WHEAT -> StackResolver.of(Material.WHEAT, random.nextInt(2) + 1);
74+
case POTATOES -> StackResolver.of(Material.POTATO, random.nextInt(3) + 1);
75+
case CARROTS -> StackResolver.of(Material.CARROT, random.nextInt(3) + 1);
76+
case BEETROOTS -> StackResolver.of(Material.BEETROOT, random.nextInt(3) + 1);
77+
case COCOA -> StackResolver.of(Material.COCOA_BEANS, random.nextInt(3) + 1);
78+
case NETHER_WART -> StackResolver.of(Material.NETHER_WART, random.nextInt(3) + 1);
79+
case SWEET_BERRY_BUSH -> StackResolver.of(Material.SWEET_BERRIES, random.nextInt(3) + 1);
7980
default -> null;
8081
};
8182
}

src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids/FishermanAndroid.java

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import javax.annotation.ParametersAreNonnullByDefault;
66

7+
import io.github.thebusybiscuit.slimefun4.utils.multiversion.StackResolver;
78
import org.bukkit.Material;
89
import org.bukkit.Tag;
910
import org.bukkit.block.Block;
@@ -28,23 +29,23 @@ public FishermanAndroid(ItemGroup itemGroup, int tier, SlimefunItemStack item, R
2829

2930
// Fish
3031
for (Material fish : Tag.ITEMS_FISHES.getValues()) {
31-
fishingLoot.add(new ItemStack(fish), 25);
32+
fishingLoot.add(StackResolver.of(fish), 25);
3233
}
3334

3435
// Junk
35-
fishingLoot.add(new ItemStack(Material.BONE), 10);
36-
fishingLoot.add(new ItemStack(Material.STRING), 10);
37-
fishingLoot.add(new ItemStack(Material.INK_SAC), 8);
38-
fishingLoot.add(new ItemStack(Material.KELP), 6);
39-
fishingLoot.add(new ItemStack(Material.STICK), 5);
40-
fishingLoot.add(new ItemStack(Material.ROTTEN_FLESH), 3);
41-
fishingLoot.add(new ItemStack(Material.LEATHER), 2);
42-
fishingLoot.add(new ItemStack(Material.BAMBOO), 3);
36+
fishingLoot.add(StackResolver.of(Material.BONE), 10);
37+
fishingLoot.add(StackResolver.of(Material.STRING), 10);
38+
fishingLoot.add(StackResolver.of(Material.INK_SAC), 8);
39+
fishingLoot.add(StackResolver.of(Material.KELP), 6);
40+
fishingLoot.add(StackResolver.of(Material.STICK), 5);
41+
fishingLoot.add(StackResolver.of(Material.ROTTEN_FLESH), 3);
42+
fishingLoot.add(StackResolver.of(Material.LEATHER), 2);
43+
fishingLoot.add(StackResolver.of(Material.BAMBOO), 3);
4344

4445
// "loot"
45-
fishingLoot.add(new ItemStack(Material.SADDLE), 1);
46-
fishingLoot.add(new ItemStack(Material.NAME_TAG), 1);
47-
fishingLoot.add(new ItemStack(Material.NAUTILUS_SHELL), 1);
46+
fishingLoot.add(StackResolver.of(Material.SADDLE), 1);
47+
fishingLoot.add(StackResolver.of(Material.NAME_TAG), 1);
48+
fishingLoot.add(StackResolver.of(Material.NAUTILUS_SHELL), 1);
4849
}
4950

5051
@Override

src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/androids/MinerAndroid.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import javax.annotation.Nonnull;
77
import javax.annotation.ParametersAreNonnullByDefault;
88

9+
import io.github.thebusybiscuit.slimefun4.utils.multiversion.StackResolver;
910
import org.bukkit.Bukkit;
1011
import org.bukkit.Effect;
1112
import org.bukkit.Material;
@@ -52,7 +53,7 @@
5253
public class MinerAndroid extends ProgrammableAndroid {
5354

5455
// Determines the drops a miner android will get
55-
private final ItemStack effectivePickaxe = new ItemStack(Material.DIAMOND_PICKAXE);
56+
private final ItemStack effectivePickaxe = StackResolver.of(Material.DIAMOND_PICKAXE);
5657

5758
private final ItemSetting<Boolean> firesEvent = new ItemSetting<>(this, "trigger-event-for-generators", false);
5859
private final ItemSetting<Boolean> applyOptimizations = new ItemSetting<>(this, "reduced-block-updates", true);

0 commit comments

Comments
 (0)