forked from Slimefun/Slimefun4
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add StackResolver for backwards compatibility
- Loading branch information
Showing
2 changed files
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
src/main/java/io/github/thebusybiscuit/slimefun4/utils/multiversion/StackResolver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package io.github.thebusybiscuit.slimefun4.utils.multiversion; | ||
|
||
import io.github.thebusybiscuit.slimefun4.api.MinecraftVersion; | ||
import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; | ||
import org.bukkit.Material; | ||
import org.bukkit.inventory.ItemStack; | ||
|
||
/** | ||
* This utility class provides backwards compatibility to versions of minecraft | ||
* regarding the creation of ItemStacks. | ||
* | ||
* @author Vaan1310 | ||
*/ | ||
public final class StackResolver { | ||
|
||
private StackResolver() {} | ||
|
||
public static ItemStack of(Material material) { | ||
return of(material, 1); | ||
} | ||
|
||
public static ItemStack of(Material material, int amount) { | ||
var version = Slimefun.getMinecraftVersion(); | ||
|
||
if (version.isAtLeast(MinecraftVersion.MINECRAFT_1_21)) { | ||
return ItemStack.of(material, amount); | ||
} else { | ||
return new ItemStack(material, amount); | ||
} | ||
} | ||
} |