Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c1a214f34e | ||
|
|
64d1fbb9b1 | ||
|
|
a5433fbb3f | ||
|
|
2a2aed52e0 |
@@ -98,5 +98,5 @@ build.dependsOn publishToMavenLocal
|
||||
|
||||
group = 'com.willfp'
|
||||
archivesBaseName = project.name
|
||||
version = '1.1.2'
|
||||
version = '1.2.0'
|
||||
java.sourceCompatibility = JavaVersion.VERSION_1_8
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.willfp.eco.util;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.Map;
|
||||
@@ -92,8 +93,10 @@ public class NumberUtils {
|
||||
* @param numeral The numeral to convert.
|
||||
* @return The number, converted from a roman numeral.
|
||||
*/
|
||||
public static int fromNumeral(String numeral) {
|
||||
if (numeral.isEmpty()) return 0;
|
||||
public static int fromNumeral(@NotNull final String numeral) {
|
||||
if (numeral.isEmpty()) {
|
||||
return 0;
|
||||
}
|
||||
for (Map.Entry<Integer, String> entry : NUMERALS.entrySet()) {
|
||||
if (numeral.startsWith(entry.getValue())) {
|
||||
return entry.getKey() + fromNumeral(numeral.substring(entry.getValue().length()));
|
||||
|
||||
@@ -6,9 +6,16 @@ import org.bukkit.util.Vector;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@UtilityClass
|
||||
public class VectorUtils {
|
||||
/**
|
||||
* Cached circles to prevent many sqrt calls.
|
||||
*/
|
||||
private static final Map<Integer, Vector[]> CIRCLE_CACHE = new HashMap<>();
|
||||
|
||||
/**
|
||||
* If vector has all components as finite.
|
||||
*
|
||||
@@ -66,6 +73,11 @@ public class VectorUtils {
|
||||
* @return An array of {@link Vector}s.
|
||||
*/
|
||||
public Vector[] getCircle(final int radius) {
|
||||
Vector[] cached = CIRCLE_CACHE.get(radius);
|
||||
if (cached != null) {
|
||||
return cached;
|
||||
}
|
||||
|
||||
ArrayList<Vector> circleVecs = new ArrayList<>();
|
||||
|
||||
double xoffset = -radius;
|
||||
@@ -85,7 +97,9 @@ public class VectorUtils {
|
||||
zoffset++;
|
||||
}
|
||||
|
||||
return circleVecs.toArray(new Vector[0]);
|
||||
Vector[] result = circleVecs.toArray(new Vector[0]);
|
||||
CIRCLE_CACHE.put(radius, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -13,7 +13,14 @@ import java.util.function.Function;
|
||||
|
||||
@UtilityClass
|
||||
public final class TelekinesisUtils {
|
||||
/**
|
||||
* Instance of registered telekinesis utils.
|
||||
*/
|
||||
private final Object instance;
|
||||
|
||||
/**
|
||||
* The class of the utils.
|
||||
*/
|
||||
private final Class<?> clazz;
|
||||
|
||||
/**
|
||||
@@ -21,6 +28,9 @@ public final class TelekinesisUtils {
|
||||
*/
|
||||
private final Method testMethod;
|
||||
|
||||
/**
|
||||
* The register service registered to bukkit.
|
||||
*/
|
||||
private final Method registerMethod;
|
||||
|
||||
/**
|
||||
|
||||
@@ -39,6 +39,8 @@ import com.willfp.eco.util.integrations.placeholder.PlaceholderManager;
|
||||
import com.willfp.eco.util.integrations.placeholder.plugins.PlaceholderIntegrationPAPI;
|
||||
import com.willfp.eco.util.optional.Prerequisite;
|
||||
import com.willfp.eco.util.protocollib.AbstractPacketAdapter;
|
||||
import com.willfp.eco.util.recipes.RecipeListener;
|
||||
import com.willfp.eco.util.recipes.RecipeManager;
|
||||
import com.willfp.eco.util.updater.UpdateChecker;
|
||||
import lombok.Getter;
|
||||
import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
|
||||
@@ -145,6 +147,12 @@ public abstract class AbstractEcoPlugin extends JavaPlugin {
|
||||
@Getter
|
||||
private final RunnableFactory runnableFactory;
|
||||
|
||||
/**
|
||||
* Recipe handler for crafting recipes.
|
||||
*/
|
||||
@Getter
|
||||
private final RecipeManager recipeManager;
|
||||
|
||||
/**
|
||||
* The loader for all plugin extensions.
|
||||
*
|
||||
@@ -193,6 +201,7 @@ public abstract class AbstractEcoPlugin extends JavaPlugin {
|
||||
this.runnableFactory = new RunnableFactory(this);
|
||||
this.extensionLoader = new EcoExtensionLoader(this);
|
||||
this.configHandler = new ConfigHandler(this);
|
||||
this.recipeManager = new RecipeManager(this);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -210,6 +219,7 @@ public abstract class AbstractEcoPlugin extends JavaPlugin {
|
||||
this.getEventManager().registerListener(new ArmorListener());
|
||||
this.getEventManager().registerListener(new DispenserArmorListener());
|
||||
this.getEventManager().registerListener(new EntityDeathByEntityListeners(this));
|
||||
this.getEventManager().registerListener(new RecipeListener(this));
|
||||
|
||||
new FastCollatedDropQueue.CollatedRunnable(this);
|
||||
|
||||
|
||||
@@ -61,6 +61,7 @@ public abstract class AbstractPacketAdapter extends PacketAdapter {
|
||||
* The code that should be executed once the packet has been received.
|
||||
*
|
||||
* @param packet The packet.
|
||||
* @param player The player.
|
||||
*/
|
||||
public void onReceive(@NotNull final PacketContainer packet,
|
||||
@NotNull final Player player) {
|
||||
@@ -71,6 +72,7 @@ public abstract class AbstractPacketAdapter extends PacketAdapter {
|
||||
* THe code that should be executed once the packet has been sent.
|
||||
*
|
||||
* @param packet The packet.
|
||||
* @param player The player.
|
||||
*/
|
||||
public void onSend(@NotNull final PacketContainer packet,
|
||||
@NotNull final Player player) {
|
||||
|
||||
261
src/main/java/com/willfp/eco/util/recipes/EcoShapedRecipe.java
Normal file
261
src/main/java/com/willfp/eco/util/recipes/EcoShapedRecipe.java
Normal file
@@ -0,0 +1,261 @@
|
||||
package com.willfp.eco.util.recipes;
|
||||
|
||||
import com.willfp.eco.util.interfaces.Registerable;
|
||||
import com.willfp.eco.util.internal.PluginDependent;
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import com.willfp.eco.util.recipes.parts.EmptyRecipePart;
|
||||
import com.willfp.eco.util.recipes.parts.RecipePart;
|
||||
import lombok.Getter;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public final class EcoShapedRecipe extends PluginDependent implements Registerable {
|
||||
/**
|
||||
* Recipe parts.
|
||||
*/
|
||||
private final RecipePart[] parts;
|
||||
|
||||
/**
|
||||
* The key of the recipe.
|
||||
*/
|
||||
@Getter
|
||||
private final String key;
|
||||
|
||||
/**
|
||||
* The recipe's output.
|
||||
*/
|
||||
@Getter
|
||||
private final ItemStack output;
|
||||
|
||||
private EcoShapedRecipe(@NotNull final AbstractEcoPlugin plugin,
|
||||
@NotNull final String key,
|
||||
@NotNull final RecipePart[] parts,
|
||||
@NotNull final ItemStack output) {
|
||||
super(plugin);
|
||||
|
||||
this.parts = parts;
|
||||
this.key = key;
|
||||
this.output = output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get item material at a specific index.
|
||||
*
|
||||
* @param index The index to check.
|
||||
* @return The material.
|
||||
*/
|
||||
public Material getMaterialAtIndex(final int index) {
|
||||
return parts[index].getDisplayed().getType();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get "real" item at specific index.
|
||||
*
|
||||
* @param index The index to check.
|
||||
* @return The item.
|
||||
*/
|
||||
public ItemStack getDisplayedAtIndex(final int index) {
|
||||
return parts[index].getDisplayed();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test matrix against recipe.
|
||||
*
|
||||
* @param matrix The matrix to check.
|
||||
* @return If the recipe matches.
|
||||
*/
|
||||
public boolean test(@NotNull final ItemStack[] matrix) {
|
||||
boolean matches = true;
|
||||
for (int i = 0; i < 9; i++) {
|
||||
if (!parts[i].matches(matrix[i])) {
|
||||
matches = false;
|
||||
}
|
||||
}
|
||||
|
||||
return matches;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the recipe.
|
||||
*/
|
||||
@Override
|
||||
public void register() {
|
||||
this.getPlugin().getRecipeManager().register(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "EcoShapedRecipe{"
|
||||
+ "parts=" + Arrays.toString(parts)
|
||||
+ ", key='" + key + '\''
|
||||
+ ", output=" + output
|
||||
+ '}';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new recipe builder.
|
||||
*
|
||||
* @param plugin The plugin that owns the recipe.
|
||||
* @param key The recipe key.
|
||||
* @return A new builder.
|
||||
*/
|
||||
public static Builder builder(@NotNull final AbstractEcoPlugin plugin,
|
||||
@NotNull final String key) {
|
||||
return new Builder(plugin, key);
|
||||
}
|
||||
|
||||
public static final class Builder {
|
||||
/**
|
||||
* The recipe parts.
|
||||
*/
|
||||
private final RecipePart[] recipeParts = new RecipePart[9];
|
||||
|
||||
/**
|
||||
* The output of the recipe.
|
||||
*/
|
||||
private ItemStack output = null;
|
||||
|
||||
/**
|
||||
* The key of the recipe.
|
||||
*/
|
||||
private final String key;
|
||||
|
||||
/**
|
||||
* The plugin that created the recipe.
|
||||
*/
|
||||
private final AbstractEcoPlugin plugin;
|
||||
|
||||
/**
|
||||
* Create a new recipe builder.
|
||||
*
|
||||
* @param plugin The plugin that owns the recipe.
|
||||
* @param key The recipe key.
|
||||
*/
|
||||
private Builder(@NotNull final AbstractEcoPlugin plugin,
|
||||
@NotNull final String key) {
|
||||
this.key = key;
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a recipe part.
|
||||
*
|
||||
* @param position The position of the recipe within a crafting matrix.
|
||||
* @param part The part of the recipe.
|
||||
* @return The builder.
|
||||
*/
|
||||
public Builder setRecipePart(@NotNull final RecipePosition position,
|
||||
@NotNull final RecipePart part) {
|
||||
this.recipeParts[position.getIndex()] = part;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a recipe part.
|
||||
*
|
||||
* @param position The position of the recipe within a crafting matrix.
|
||||
* @param part The part of the recipe.
|
||||
* @return The builder.
|
||||
*/
|
||||
public Builder setRecipePart(final int position,
|
||||
@NotNull final RecipePart part) {
|
||||
this.recipeParts[position] = part;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the output of the recipe.
|
||||
*
|
||||
* @param output The output.
|
||||
* @return The builder.
|
||||
*/
|
||||
public Builder setOutput(@NotNull final ItemStack output) {
|
||||
this.output = output;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the recipe.
|
||||
*
|
||||
* @return The built recipe.
|
||||
*/
|
||||
public EcoShapedRecipe build() {
|
||||
Validate.notNull(output, "Output cannot be null!");
|
||||
Validate.isTrue(output.getType() != Material.AIR, "Output cannot be blank!");
|
||||
|
||||
for (int i = 0; i < 9; i++) {
|
||||
if (recipeParts[i] == null) {
|
||||
recipeParts[i] = new EmptyRecipePart();
|
||||
}
|
||||
}
|
||||
|
||||
return new EcoShapedRecipe(plugin, key.toLowerCase(), recipeParts, output);
|
||||
}
|
||||
}
|
||||
|
||||
public enum RecipePosition {
|
||||
/**
|
||||
* Top left of matrix.
|
||||
*/
|
||||
TOP_LEFT(0),
|
||||
|
||||
/**
|
||||
* Top middle of matrix.
|
||||
*/
|
||||
TOP_MIDDLE(1),
|
||||
|
||||
/**
|
||||
* Top right of matrix.
|
||||
*/
|
||||
TOP_RIGHT(2),
|
||||
|
||||
/**
|
||||
* Middle left of matrix.
|
||||
*/
|
||||
MIDDLE_LEFT(3),
|
||||
|
||||
/**
|
||||
* Middle of matrix.
|
||||
*/
|
||||
MIDDLE(4),
|
||||
|
||||
/**
|
||||
* Middle right of matrix.
|
||||
*/
|
||||
MIDDLE_RIGHT(5),
|
||||
|
||||
/**
|
||||
* Bottom left of matrix.
|
||||
*/
|
||||
BOTTOM_LEFT(6),
|
||||
|
||||
/**
|
||||
* Bottom middle of matrix.
|
||||
*/
|
||||
BOTTOM_MIDDLE(7),
|
||||
|
||||
/**
|
||||
* Bottom right of matrix.
|
||||
*/
|
||||
BOTTOM_RIGHT(8);
|
||||
|
||||
/**
|
||||
* The index within a crafting table matrix.
|
||||
*/
|
||||
@Getter
|
||||
private final int index;
|
||||
|
||||
/**
|
||||
* Recipe position with crafting table index.
|
||||
*
|
||||
* @param index The index.
|
||||
*/
|
||||
RecipePosition(final int index) {
|
||||
this.index = index;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
package com.willfp.eco.util.recipes;
|
||||
|
||||
import com.willfp.eco.util.internal.PluginDependent;
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.CraftItemEvent;
|
||||
import org.bukkit.event.inventory.PrepareItemCraftEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.ShapedRecipe;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class RecipeListener extends PluginDependent implements Listener {
|
||||
/**
|
||||
* Pass an {@link AbstractEcoPlugin} in order to interface with it.
|
||||
*
|
||||
* @param plugin The plugin to manage.
|
||||
*/
|
||||
public RecipeListener(@NotNull final AbstractEcoPlugin plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called on item craft.
|
||||
*
|
||||
* @param event The event to listen for.
|
||||
*/
|
||||
@EventHandler
|
||||
public void prepareCraftListener(@NotNull final PrepareItemCraftEvent event) {
|
||||
if (!(event.getRecipe() instanceof ShapedRecipe)) {
|
||||
return;
|
||||
}
|
||||
|
||||
ShapedRecipe recipe = (ShapedRecipe) event.getRecipe();
|
||||
|
||||
if (!recipe.getKey().getNamespace().equals(this.getPlugin().getPluginName().toLowerCase())) {
|
||||
return;
|
||||
}
|
||||
|
||||
ItemStack[] matrix = event.getInventory().getMatrix();
|
||||
EcoShapedRecipe matched = this.getPlugin().getRecipeManager().getMatch(matrix);
|
||||
|
||||
if (matched == null) {
|
||||
event.getInventory().setResult(new ItemStack(Material.AIR));
|
||||
return;
|
||||
}
|
||||
|
||||
if (matched.test(matrix)) {
|
||||
event.getInventory().setResult(matched.getOutput());
|
||||
} else {
|
||||
event.getInventory().setResult(new ItemStack(Material.AIR));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called on item craft.
|
||||
*
|
||||
* @param event The event to listen for.
|
||||
*/
|
||||
@EventHandler
|
||||
public void craftListener(@NotNull final CraftItemEvent event) {
|
||||
if (!(event.getRecipe() instanceof ShapedRecipe)) {
|
||||
return;
|
||||
}
|
||||
|
||||
ShapedRecipe recipe = (ShapedRecipe) event.getRecipe();
|
||||
|
||||
if (!recipe.getKey().getNamespace().equals(this.getPlugin().getPluginName().toLowerCase())) {
|
||||
return;
|
||||
}
|
||||
|
||||
ItemStack[] matrix = event.getInventory().getMatrix();
|
||||
EcoShapedRecipe matched = this.getPlugin().getRecipeManager().getMatch(matrix);
|
||||
|
||||
if (matched == null) {
|
||||
event.getInventory().setResult(new ItemStack(Material.AIR));
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (matched.test(matrix)) {
|
||||
event.getInventory().setResult(matched.getOutput());
|
||||
} else {
|
||||
event.getInventory().setResult(new ItemStack(Material.AIR));
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
80
src/main/java/com/willfp/eco/util/recipes/RecipeManager.java
Normal file
80
src/main/java/com/willfp/eco/util/recipes/RecipeManager.java
Normal file
@@ -0,0 +1,80 @@
|
||||
package com.willfp.eco.util.recipes;
|
||||
|
||||
import com.google.common.collect.BiMap;
|
||||
import com.google.common.collect.HashBiMap;
|
||||
import com.willfp.eco.util.internal.PluginDependent;
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.RecipeChoice;
|
||||
import org.bukkit.inventory.ShapedRecipe;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class RecipeManager extends PluginDependent {
|
||||
/**
|
||||
* Registry of all recipes.
|
||||
*/
|
||||
private final BiMap<String, EcoShapedRecipe> registry = HashBiMap.create();
|
||||
|
||||
/**
|
||||
* Pass an {@link AbstractEcoPlugin} in order to interface with it.
|
||||
*
|
||||
* @param plugin The plugin to manage.
|
||||
*/
|
||||
public RecipeManager(@NotNull final AbstractEcoPlugin plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
void register(@NotNull final EcoShapedRecipe recipe) {
|
||||
String key = recipe.getKey();
|
||||
registry.forcePut(key, recipe);
|
||||
|
||||
NamespacedKey baseKey = this.getPlugin().getNamespacedKeyFactory().create(key);
|
||||
Bukkit.getServer().removeRecipe(baseKey);
|
||||
|
||||
NamespacedKey displayedKey = this.getPlugin().getNamespacedKeyFactory().create(key + "_displayed");
|
||||
Bukkit.getServer().removeRecipe(displayedKey);
|
||||
|
||||
ShapedRecipe shapedRecipe = new ShapedRecipe(baseKey, recipe.getOutput());
|
||||
shapedRecipe.shape("012", "345", "678");
|
||||
for (int i = 0; i < 9; i++) {
|
||||
char character = String.valueOf(i).toCharArray()[0];
|
||||
shapedRecipe.setIngredient(character, recipe.getMaterialAtIndex(i));
|
||||
}
|
||||
|
||||
ShapedRecipe displayedRecipe = new ShapedRecipe(displayedKey, recipe.getOutput());
|
||||
displayedRecipe.shape("012", "345", "678");
|
||||
for (int i = 0; i < 9; i++) {
|
||||
char character = String.valueOf(i).toCharArray()[0];
|
||||
displayedRecipe.setIngredient(character, new RecipeChoice.ExactChoice(recipe.getDisplayedAtIndex(i)));
|
||||
}
|
||||
|
||||
Bukkit.getServer().addRecipe(shapedRecipe);
|
||||
Bukkit.getServer().addRecipe(displayedRecipe);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get recipe matching matrix.
|
||||
*
|
||||
* @param matrix The matrix to test.
|
||||
* @return The match, or null if not found.
|
||||
*/
|
||||
@Nullable
|
||||
public EcoShapedRecipe getMatch(@NotNull final ItemStack[] matrix) {
|
||||
return registry.values().stream().filter(recipe -> recipe.test(matrix)).findFirst().orElse(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get shaped recipe by key.
|
||||
*
|
||||
* @param key The key.
|
||||
* @return The shaped recipe, or null if not found.
|
||||
*/
|
||||
@Nullable
|
||||
public EcoShapedRecipe getShapedRecipe(@NotNull final String key) {
|
||||
return registry.get(key);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.willfp.eco.util.recipes.parts;
|
||||
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class ComplexRecipePart implements RecipePart {
|
||||
/**
|
||||
* The test for itemstacks to pass.
|
||||
*/
|
||||
private final Predicate<ItemStack> predicate;
|
||||
|
||||
/**
|
||||
* Displayed itemstack: what the user should see.
|
||||
*/
|
||||
private final ItemStack displayed;
|
||||
|
||||
/**
|
||||
* Create a new complex recipe part.
|
||||
* @param predicate The test.
|
||||
* @param displayed The example itemstack.
|
||||
*/
|
||||
public ComplexRecipePart(@NotNull final Predicate<ItemStack> predicate,
|
||||
@NotNull final ItemStack displayed) {
|
||||
this.predicate = predicate;
|
||||
this.displayed = displayed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(@Nullable final ItemStack itemStack) {
|
||||
return predicate.test(itemStack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getDisplayed() {
|
||||
return displayed;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.willfp.eco.util.recipes.parts;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class EmptyRecipePart implements RecipePart {
|
||||
/**
|
||||
* Create a new empty recipe part.
|
||||
*/
|
||||
public EmptyRecipePart() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* If the item is empty.
|
||||
*
|
||||
* @param itemStack The item to test.
|
||||
* @return If the item is empty.
|
||||
*/
|
||||
@Override
|
||||
public boolean matches(@Nullable final ItemStack itemStack) {
|
||||
return itemStack == null || itemStack.getType() == Material.AIR;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getDisplayed() {
|
||||
return new ItemStack(Material.AIR);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.willfp.eco.util.recipes.parts;
|
||||
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public interface RecipePart {
|
||||
/**
|
||||
* If an ItemStack matches the recipe part.
|
||||
*
|
||||
* @param itemStack The item to test.
|
||||
* @return If the item matches.
|
||||
*/
|
||||
boolean matches(@Nullable ItemStack itemStack);
|
||||
|
||||
/**
|
||||
* Get a displayed itemstack, for autocraft.
|
||||
*
|
||||
* @return The item, displayed.
|
||||
*/
|
||||
ItemStack getDisplayed();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.willfp.eco.util.recipes.parts;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class SimpleRecipePart implements RecipePart {
|
||||
/**
|
||||
* The material.
|
||||
*/
|
||||
private final Material material;
|
||||
|
||||
/**
|
||||
* Create a new simple recipe part.
|
||||
*
|
||||
* @param material The material.
|
||||
*/
|
||||
public SimpleRecipePart(@NotNull final Material material) {
|
||||
this.material = material;
|
||||
}
|
||||
|
||||
/**
|
||||
* If the item matches the material.
|
||||
*
|
||||
* @param itemStack The item to test.
|
||||
* @return If the item is of the specified material.
|
||||
*/
|
||||
@Override
|
||||
public boolean matches(@Nullable final ItemStack itemStack) {
|
||||
return itemStack != null && itemStack.getType() == material;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getDisplayed() {
|
||||
return new ItemStack(material);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user