Compare commits

...

19 Commits
3.8.0 ... 4.0.0

Author SHA1 Message Date
Auxilor
bb42505d66 Hopeful fix 2021-02-17 16:07:08 +00:00
Auxilor
b4d59077e3 Fixed load order again 2021-02-17 15:55:39 +00:00
Auxilor
104d55c11b Changed load order again 2021-02-17 15:49:51 +00:00
Auxilor
b5af17cf08 Changed load order 2021-02-17 15:45:33 +00:00
Auxilor
78ae662ced Fixed RecipeParts 2021-02-17 15:20:39 +00:00
Auxilor
32e48db3ce Removed @Nullable because it's annoying 2021-02-17 15:02:52 +00:00
Auxilor
8a27e75c02 Fixed EcoPlugin 2021-02-17 14:55:34 +00:00
Auxilor
bf55e9b189 Constructor change 2021-02-17 14:54:28 +00:00
Auxilor
bfbaa3d033 Removed redundant check 2021-02-17 14:42:03 +00:00
Auxilor
64f87d5741 Cleaned up recipes 2021-02-17 13:54:02 +00:00
Auxilor
cb3441286c Removed redundant Registerable interface 2021-02-17 13:39:32 +00:00
Auxilor
5e97a0f894 Refactored ArrowDataListener 2021-02-17 13:35:32 +00:00
Auxilor
de2166dfdb Reworked tuples 2021-02-17 13:33:57 +00:00
Auxilor
abd361f4b5 Refactored config internals 2021-02-17 13:30:06 +00:00
Auxilor
422f8ead23 Removed RecipeListener from api 2021-02-17 13:27:28 +00:00
Auxilor
7c05dd7457 Reworked recipes 2021-02-17 13:20:34 +00:00
Auxilor
3ef7622c6f Updated to 4.0.0 2021-02-17 12:50:16 +00:00
Auxilor
8207d62b1f Reworked display system. 2021-02-17 12:50:01 +00:00
Auxilor
75a0b1dd0d Added @Internal annotations 2021-02-17 12:05:14 +00:00
32 changed files with 598 additions and 472 deletions

View File

@@ -23,12 +23,14 @@ import com.willfp.eco.spigot.integrations.antigrief.AntigriefLands;
import com.willfp.eco.spigot.integrations.antigrief.AntigriefTowny; import com.willfp.eco.spigot.integrations.antigrief.AntigriefTowny;
import com.willfp.eco.spigot.integrations.antigrief.AntigriefWorldGuard; import com.willfp.eco.spigot.integrations.antigrief.AntigriefWorldGuard;
import com.willfp.eco.spigot.integrations.mcmmo.McmmoIntegrationImpl; import com.willfp.eco.spigot.integrations.mcmmo.McmmoIntegrationImpl;
import com.willfp.eco.spigot.recipes.RecipeListener;
import com.willfp.eco.util.BlockUtils; import com.willfp.eco.util.BlockUtils;
import com.willfp.eco.util.PlayerUtils; import com.willfp.eco.util.PlayerUtils;
import com.willfp.eco.util.SkullUtils; import com.willfp.eco.util.SkullUtils;
import com.willfp.eco.util.TridentUtils; import com.willfp.eco.util.TridentUtils;
import com.willfp.eco.util.command.AbstractCommand; import com.willfp.eco.util.command.AbstractCommand;
import com.willfp.eco.util.display.Display; import com.willfp.eco.util.display.Display;
import com.willfp.eco.util.display.DisplayModule;
import com.willfp.eco.util.events.armorequip.ArmorListener; import com.willfp.eco.util.events.armorequip.ArmorListener;
import com.willfp.eco.util.events.armorequip.DispenserArmorListener; import com.willfp.eco.util.events.armorequip.DispenserArmorListener;
import com.willfp.eco.util.integrations.IntegrationLoader; import com.willfp.eco.util.integrations.IntegrationLoader;
@@ -39,6 +41,7 @@ import com.willfp.eco.util.plugin.AbstractEcoPlugin;
import com.willfp.eco.util.protocollib.AbstractPacketAdapter; import com.willfp.eco.util.protocollib.AbstractPacketAdapter;
import lombok.Getter; import lombok.Getter;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
@@ -71,6 +74,7 @@ public class EcoPlugin extends AbstractEcoPlugin {
this.getEventManager().registerListener(new ArmorListener()); this.getEventManager().registerListener(new ArmorListener());
this.getEventManager().registerListener(new DispenserArmorListener()); this.getEventManager().registerListener(new DispenserArmorListener());
this.getEventManager().registerListener(new EntityDeathByEntityListeners(this)); this.getEventManager().registerListener(new EntityDeathByEntityListeners(this));
this.getEventManager().registerListener(new RecipeListener());
} }
@Override @Override
@@ -140,4 +144,10 @@ public class EcoPlugin extends AbstractEcoPlugin {
public List<Class<?>> getUpdatableClasses() { public List<Class<?>> getUpdatableClasses() {
return new ArrayList<>(); return new ArrayList<>();
} }
@Override
@Nullable
protected DisplayModule createDisplayModule() {
return null;
}
} }

View File

@@ -0,0 +1,220 @@
package com.willfp.eco.spigot.recipes;
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
import com.willfp.eco.util.recipe.RecipeParts;
import com.willfp.eco.util.recipe.Recipes;
import com.willfp.eco.util.recipe.parts.RecipePart;
import com.willfp.eco.util.recipe.parts.SimpleRecipePart;
import com.willfp.eco.util.recipe.recipes.EcoShapedRecipe;
import org.bukkit.Material;
import org.bukkit.event.Event;
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.event.player.PlayerRecipeDiscoverEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.ShapedRecipe;
import org.jetbrains.annotations.NotNull;
public class RecipeListener implements Listener {
/**
* Called on item craft.
*
* @param event The event to listen for.
*/
@EventHandler
public void complexRecipeListener(@NotNull final PrepareItemCraftEvent event) {
if (!(event.getRecipe() instanceof ShapedRecipe)) {
return;
}
ShapedRecipe recipe = (ShapedRecipe) event.getRecipe();
if (!AbstractEcoPlugin.LOADED_ECO_PLUGINS.contains(recipe.getKey().getNamespace())) {
return;
}
ItemStack[] matrix = event.getInventory().getMatrix();
EcoShapedRecipe matched = Recipes.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 complexRecipeListener(@NotNull final CraftItemEvent event) {
if (!(event.getRecipe() instanceof ShapedRecipe)) {
return;
}
ShapedRecipe recipe = (ShapedRecipe) event.getRecipe();
if (!AbstractEcoPlugin.LOADED_ECO_PLUGINS.contains(recipe.getKey().getNamespace())) {
return;
}
ItemStack[] matrix = event.getInventory().getMatrix();
EcoShapedRecipe matched = Recipes.getMatch(matrix);
if (matched == null) {
event.getInventory().setResult(new ItemStack(Material.AIR));
event.setResult(Event.Result.DENY);
event.setCancelled(true);
return;
}
if (matched.test(matrix)) {
event.getInventory().setResult(matched.getOutput());
} else {
event.getInventory().setResult(new ItemStack(Material.AIR));
event.setResult(Event.Result.DENY);
event.setCancelled(true);
}
}
/**
* Called on item craft.
*
* @param event The event to listen for.
*/
@EventHandler
public void preventUsingComplexPartInEcoRecipe(@NotNull final PrepareItemCraftEvent event) {
if (!(event.getRecipe() instanceof ShapedRecipe)) {
return;
}
ShapedRecipe recipe = (ShapedRecipe) event.getRecipe();
EcoShapedRecipe ecoShapedRecipe = Recipes.getShapedRecipe(recipe.getKey());
if (ecoShapedRecipe == null) {
return;
}
for (int i = 0; i < 9; i++) {
ItemStack itemStack = event.getInventory().getMatrix()[i];
RecipePart part = ecoShapedRecipe.getParts()[i];
if (part instanceof SimpleRecipePart) {
if (RecipeParts.isRecipePart(itemStack)) {
event.getInventory().setResult(new ItemStack(Material.AIR));
return;
}
}
}
}
/**
* Called on item craft.
*
* @param event The event to listen for.
*/
@EventHandler
public void preventUsingComplexPartInEcoRecipe(@NotNull final CraftItemEvent event) {
if (!(event.getRecipe() instanceof ShapedRecipe)) {
return;
}
ShapedRecipe recipe = (ShapedRecipe) event.getRecipe();
EcoShapedRecipe ecoShapedRecipe = Recipes.getShapedRecipe(recipe.getKey());
if (ecoShapedRecipe == null) {
return;
}
for (int i = 0; i < 9; i++) {
ItemStack itemStack = event.getInventory().getMatrix()[i];
RecipePart part = ecoShapedRecipe.getParts()[i];
if (part instanceof SimpleRecipePart) {
if (RecipeParts.isRecipePart(itemStack)) {
event.getInventory().setResult(new ItemStack(Material.AIR));
event.setResult(Event.Result.DENY);
event.setCancelled(true);
return;
}
}
}
}
/**
* Prevents using talismans in recipes.
*
* @param event The event to listen for.
*/
@EventHandler
public void preventUsingComplexPartInVanillaRecipe(@NotNull final PrepareItemCraftEvent event) {
if (!(event.getRecipe() instanceof ShapedRecipe)) {
return;
}
ShapedRecipe recipe = (ShapedRecipe) event.getRecipe();
if (AbstractEcoPlugin.LOADED_ECO_PLUGINS.contains(recipe.getKey().getNamespace())) {
return;
}
for (ItemStack itemStack : event.getInventory().getMatrix()) {
if (RecipeParts.isRecipePart(itemStack)) {
event.getInventory().setResult(new ItemStack(Material.AIR));
return;
}
}
}
/**
* Prevents using talismans in recipes.
*
* @param event The event to listen for.
*/
@EventHandler
public void preventUsingComplexPartInVanillaRecipe(@NotNull final CraftItemEvent event) {
if (!(event.getRecipe() instanceof ShapedRecipe)) {
return;
}
ShapedRecipe recipe = (ShapedRecipe) event.getRecipe();
if (AbstractEcoPlugin.LOADED_ECO_PLUGINS.contains(recipe.getKey().getNamespace())) {
return;
}
for (ItemStack itemStack : event.getInventory().getMatrix()) {
if (RecipeParts.isRecipePart(itemStack)) {
event.getInventory().setResult(new ItemStack(Material.AIR));
event.setResult(Event.Result.DENY);
event.setCancelled(true);
return;
}
}
}
/**
* Prevents learning displayed recipes.
*
* @param event The event to listen for.
*/
@EventHandler
public void preventLearningDisplayedRecipes(@NotNull final PlayerRecipeDiscoverEvent event) {
if (!AbstractEcoPlugin.LOADED_ECO_PLUGINS.contains(event.getRecipe().getNamespace())) {
return;
}
if (event.getRecipe().getKey().contains("_displayed")) {
event.setCancelled(true);
}
}
}

View File

@@ -1,4 +1,4 @@
package com.willfp.eco.util.arrows; package com.willfp.eco.internal.arrows;
import com.willfp.eco.util.internal.PluginDependent; import com.willfp.eco.util.internal.PluginDependent;
import com.willfp.eco.util.plugin.AbstractEcoPlugin; import com.willfp.eco.util.plugin.AbstractEcoPlugin;

View File

@@ -1,4 +1,4 @@
package com.willfp.eco.util.config.internal; package com.willfp.eco.internal.config;
import com.willfp.eco.util.StringUtils; import com.willfp.eco.util.StringUtils;
import com.willfp.eco.util.internal.PluginDependent; import com.willfp.eco.util.internal.PluginDependent;

View File

@@ -1,4 +1,4 @@
package com.willfp.eco.util.config.internal; package com.willfp.eco.internal.config;
import com.willfp.eco.util.plugin.AbstractEcoPlugin; import com.willfp.eco.util.plugin.AbstractEcoPlugin;
import org.bukkit.configuration.InvalidConfigurationException; import org.bukkit.configuration.InvalidConfigurationException;

View File

@@ -6,6 +6,7 @@ import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.BlockFace; import org.bukkit.block.BlockFace;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.util.HashSet; import java.util.HashSet;
@@ -76,6 +77,7 @@ public class BlockUtils {
* *
* @param function The function. * @param function The function.
*/ */
@ApiStatus.Internal
public void initialize(@NotNull final BiConsumer<Player, Block> function) { public void initialize(@NotNull final BiConsumer<Player, Block> function) {
Validate.isTrue(!initialized, "Already initialized!"); Validate.isTrue(!initialized, "Already initialized!");

View File

@@ -4,6 +4,7 @@ import com.willfp.eco.util.optional.Prerequisite;
import lombok.experimental.UtilityClass; import lombok.experimental.UtilityClass;
import org.apache.commons.lang.Validate; import org.apache.commons.lang.Validate;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.util.function.Function; import java.util.function.Function;
@@ -42,6 +43,7 @@ public class PlayerUtils {
* *
* @param function The function. * @param function The function.
*/ */
@ApiStatus.Internal
public void initialize(@NotNull final Function<Player, Double> function) { public void initialize(@NotNull final Function<Player, Double> function) {
Validate.isTrue(!initialized, "Already initialized!"); Validate.isTrue(!initialized, "Already initialized!");

View File

@@ -3,6 +3,7 @@ package com.willfp.eco.util;
import lombok.experimental.UtilityClass; import lombok.experimental.UtilityClass;
import org.apache.commons.lang.Validate; import org.apache.commons.lang.Validate;
import org.bukkit.inventory.meta.SkullMeta; import org.bukkit.inventory.meta.SkullMeta;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.util.function.BiConsumer; import java.util.function.BiConsumer;
@@ -38,6 +39,7 @@ public class SkullUtils {
* *
* @param function The function. * @param function The function.
*/ */
@ApiStatus.Internal
public void initialize(@NotNull final BiConsumer<SkullMeta, String> function) { public void initialize(@NotNull final BiConsumer<SkullMeta, String> function) {
Validate.isTrue(!initialized, "Already initialized!"); Validate.isTrue(!initialized, "Already initialized!");

View File

@@ -4,6 +4,7 @@ import lombok.experimental.UtilityClass;
import org.apache.commons.lang.Validate; import org.apache.commons.lang.Validate;
import org.bukkit.entity.Trident; import org.bukkit.entity.Trident;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.util.function.Function; import java.util.function.Function;
@@ -38,6 +39,7 @@ public class TridentUtils {
* *
* @param function The function. * @param function The function.
*/ */
@ApiStatus.Internal
public void initialize(@NotNull final Function<Trident, ItemStack> function) { public void initialize(@NotNull final Function<Trident, ItemStack> function) {
Validate.isTrue(!initialized, "Already initialized!"); Validate.isTrue(!initialized, "Already initialized!");

View File

@@ -0,0 +1,11 @@
package com.willfp.eco.util.bukkit.scheduling;
public interface TimedRunnable extends Runnable {
/**
* The TimedRunnable interface is generally used for repeating tasks.
* This method is to retrieve the ticks between repetitions.
*
* @return The ticks between repetitions.
*/
long getTime();
}

View File

@@ -1,7 +1,6 @@
package com.willfp.eco.util.command; package com.willfp.eco.util.command;
import com.willfp.eco.util.internal.PluginDependent; import com.willfp.eco.util.internal.PluginDependent;
import com.willfp.eco.util.interfaces.Registerable;
import com.willfp.eco.util.plugin.AbstractEcoPlugin; import com.willfp.eco.util.plugin.AbstractEcoPlugin;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.command.Command; import org.bukkit.command.Command;
@@ -15,7 +14,7 @@ import org.jetbrains.annotations.Nullable;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
public abstract class AbstractCommand extends PluginDependent implements CommandExecutor, Registerable { public abstract class AbstractCommand extends PluginDependent implements CommandExecutor {
/** /**
* The name of the command * The name of the command
* <p> * <p>
@@ -130,7 +129,6 @@ public abstract class AbstractCommand extends PluginDependent implements Command
* <p> * <p>
* Requires the command name to exist, defined in plugin.yml. * Requires the command name to exist, defined in plugin.yml.
*/ */
@Override
public final void register() { public final void register() {
PluginCommand command = Bukkit.getPluginCommand(name); PluginCommand command = Bukkit.getPluginCommand(name);
assert command != null; assert command != null;

View File

@@ -1,6 +1,6 @@
package com.willfp.eco.util.config; package com.willfp.eco.util.config;
import com.willfp.eco.util.config.internal.AbstractUpdatableConfig; import com.willfp.eco.internal.config.AbstractUpdatableConfig;
import com.willfp.eco.util.plugin.AbstractEcoPlugin; import com.willfp.eco.util.plugin.AbstractEcoPlugin;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;

View File

@@ -1,6 +1,6 @@
package com.willfp.eco.util.config; package com.willfp.eco.util.config;
import com.willfp.eco.util.config.internal.AbstractUpdatableConfig; import com.willfp.eco.internal.config.AbstractUpdatableConfig;
import com.willfp.eco.util.plugin.AbstractEcoPlugin; import com.willfp.eco.util.plugin.AbstractEcoPlugin;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;

View File

@@ -1,6 +1,6 @@
package com.willfp.eco.util.config; package com.willfp.eco.util.config;
import com.willfp.eco.util.config.internal.AbstractConfig; import com.willfp.eco.internal.config.AbstractConfig;
import com.willfp.eco.util.plugin.AbstractEcoPlugin; import com.willfp.eco.util.plugin.AbstractEcoPlugin;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;

View File

@@ -1,5 +0,0 @@
package com.willfp.eco.util.config;
@Deprecated
public interface ValueGetter {
}

View File

@@ -14,25 +14,23 @@ import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.function.Function;
import java.util.function.Predicate;
@UtilityClass @UtilityClass
public class Display { public class Display {
/** /**
* Registered display functions. * The prefix for lore lines.
*/ */
private static final List<Map<String, Function<ItemStack, ItemStack>>> DISPLAY_FUNCTIONS = new ArrayList<>(10000); public static final String PREFIX = "§z";
/** /**
* Registered revert functions. * All registered display modules.
*/ */
private static final List<Function<ItemStack, ItemStack>> REVERT_FUNCTIONS = new ArrayList<>(); private static final Map<DisplayPriority, List<DisplayModule>> MODULES = new HashMap<>();
/** /**
* NamespacedKey for finalizing. * NamespacedKey for finalizing.
*/ */
private static NamespacedKey finalizeKey; private static NamespacedKey finalizeKey = null;
/** /**
* Register display module. * Register display module.
@@ -40,30 +38,11 @@ public class Display {
* @param module The module. * @param module The module.
*/ */
public void registerDisplayModule(@NotNull final DisplayModule module) { public void registerDisplayModule(@NotNull final DisplayModule module) {
int priority = module.getPriority(); List<DisplayModule> modules = MODULES.get(module.getPriority());
if (priority > 9999) {
priority = 9999;
}
Function<ItemStack, ItemStack> function = module.getFunction();
Map<String, Function<ItemStack, ItemStack>> functions = DISPLAY_FUNCTIONS.get(priority); modules.add(module);
if (functions == null) {
functions = new HashMap<>();
}
functions.remove(module.getId()); MODULES.put(module.getPriority(), modules);
functions.put(module.getId(), function);
DISPLAY_FUNCTIONS.set(priority, functions);
}
/**
* Register revert function.
*
* @param function The function.
*/
public void registerRevertModule(@NotNull final Function<ItemStack, ItemStack> function) {
REVERT_FUNCTIONS.add(function);
} }
/** /**
@@ -80,13 +59,20 @@ public class Display {
revert(itemStack); revert(itemStack);
for (Map<String, Function<ItemStack, ItemStack>> displayFunctions : DISPLAY_FUNCTIONS) { if (!itemStack.hasItemMeta()) {
if (displayFunctions == null) { return itemStack;
continue; }
}
for (Function<ItemStack, ItemStack> displayFunction : displayFunctions.values()) { ItemMeta meta = itemStack.getItemMeta();
displayFunction.apply(itemStack);
if (meta == null) {
return itemStack;
}
for (DisplayPriority priority : DisplayPriority.values()) {
List<DisplayModule> modules = MODULES.get(priority);
for (DisplayModule module : modules) {
module.display(itemStack);
} }
} }
@@ -115,8 +101,33 @@ public class Display {
return itemStack; return itemStack;
} }
for (Function<ItemStack, ItemStack> displayFunction : REVERT_FUNCTIONS) { if (!itemStack.hasItemMeta()) {
displayFunction.apply(itemStack); return itemStack;
}
ItemMeta meta = itemStack.getItemMeta();
if (meta == null) {
return itemStack;
}
List<String> lore = meta.getLore();
if (lore == null) {
lore = new ArrayList<>();
}
lore.removeIf(line -> line.startsWith(Display.PREFIX));
meta.setLore(lore);
itemStack.setItemMeta(meta);
for (DisplayPriority priority : DisplayPriority.values()) {
List<DisplayModule> modules = MODULES.get(priority);
for (DisplayModule module : modules) {
module.revert(itemStack);
}
} }
return itemStack; return itemStack;
@@ -130,13 +141,16 @@ public class Display {
*/ */
public ItemStack finalize(@NotNull final ItemStack itemStack) { public ItemStack finalize(@NotNull final ItemStack itemStack) {
Validate.notNull(finalizeKey, "Key cannot be null!"); Validate.notNull(finalizeKey, "Key cannot be null!");
if (itemStack.getType().getMaxStackSize() > 1) { if (itemStack.getType().getMaxStackSize() > 1) {
return itemStack; return itemStack;
} }
ItemMeta meta = itemStack.getItemMeta(); ItemMeta meta = itemStack.getItemMeta();
if (meta == null) { if (meta == null) {
return itemStack; return itemStack;
} }
PersistentDataContainer container = meta.getPersistentDataContainer(); PersistentDataContainer container = meta.getPersistentDataContainer();
container.set(finalizeKey, PersistentDataType.INTEGER, 1); container.set(finalizeKey, PersistentDataType.INTEGER, 1);
itemStack.setItemMeta(meta); itemStack.setItemMeta(meta);
@@ -151,10 +165,13 @@ public class Display {
*/ */
public ItemStack unfinalize(@NotNull final ItemStack itemStack) { public ItemStack unfinalize(@NotNull final ItemStack itemStack) {
Validate.notNull(finalizeKey, "Key cannot be null!"); Validate.notNull(finalizeKey, "Key cannot be null!");
ItemMeta meta = itemStack.getItemMeta(); ItemMeta meta = itemStack.getItemMeta();
if (meta == null) { if (meta == null) {
return itemStack; return itemStack;
} }
PersistentDataContainer container = meta.getPersistentDataContainer(); PersistentDataContainer container = meta.getPersistentDataContainer();
container.remove(finalizeKey); container.remove(finalizeKey);
itemStack.setItemMeta(meta); itemStack.setItemMeta(meta);
@@ -169,37 +186,17 @@ public class Display {
*/ */
public boolean isFinalized(@NotNull final ItemStack itemStack) { public boolean isFinalized(@NotNull final ItemStack itemStack) {
Validate.notNull(finalizeKey, "Key cannot be null!"); Validate.notNull(finalizeKey, "Key cannot be null!");
ItemMeta meta = itemStack.getItemMeta(); ItemMeta meta = itemStack.getItemMeta();
if (meta == null) { if (meta == null) {
return false; return false;
} }
PersistentDataContainer container = meta.getPersistentDataContainer(); PersistentDataContainer container = meta.getPersistentDataContainer();
return container.has(finalizeKey, PersistentDataType.INTEGER); return container.has(finalizeKey, PersistentDataType.INTEGER);
} }
/**
* Register finalize function.
*
* @param function The function.
* @deprecated Not needed.
*/
@Deprecated
public void registerFinalizeModule(@NotNull final Function<ItemStack, ItemStack> function) {
// This function is not needed.
}
/**
* Register finalize test function.
*
* @param function The function.
* @deprecated Not needed.
*/
@Deprecated
public void registerFinalizeTestModule(@NotNull final Predicate<ItemStack> function) {
// This isn't needed.
}
/** /**
* Set key to be used for finalization. * Set key to be used for finalization.
* *
@@ -211,8 +208,8 @@ public class Display {
} }
static { static {
for (int i = 0; i < 10000; i++) { for (DisplayPriority priority : DisplayPriority.values()) {
DISPLAY_FUNCTIONS.add(null); MODULES.put(priority, new ArrayList<>());
} }
} }
} }

View File

@@ -1,42 +1,41 @@
package com.willfp.eco.util.display; package com.willfp.eco.util.display;
import com.willfp.eco.util.internal.PluginDependent;
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
import lombok.Getter; import lombok.Getter;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.util.function.Function; public abstract class DisplayModule extends PluginDependent {
public class DisplayModule {
/** /**
* Priority of the display module, where lower numbers are executed sooner. * The priority of the module.
*/ */
@Getter @Getter
private final int priority; private final DisplayPriority priority;
/** /**
* The function executed on display. * Create a new display module.
*/
@Getter
private final Function<ItemStack, ItemStack> function;
/**
* Function id for unregistration.
*/
@Getter
private final String id;
/**
* Create new display module.
* *
* @param function The function. * @param plugin The plugin that the display is for.
* @param priority The priority. * @param priority The priority of the module.
* @param id The id.
*/ */
public DisplayModule(@NotNull final Function<ItemStack, ItemStack> function, protected DisplayModule(@NotNull final AbstractEcoPlugin plugin,
final int priority, @NotNull final DisplayPriority priority) {
@NotNull final String id) { super(plugin);
this.function = function;
this.priority = priority; this.priority = priority;
this.id = id;
} }
/**
* Display an item.
*
* @param itemStack The item.
*/
protected abstract void display(@NotNull ItemStack itemStack);
/**
* Revert an item.
*
* @param itemStack The item.
*/
protected abstract void revert(@NotNull ItemStack itemStack);
} }

View File

@@ -0,0 +1,23 @@
package com.willfp.eco.util.display;
public enum DisplayPriority {
/**
* Ran first.
*/
LOWEST,
/**
* Ran second.
*/
LOW,
/**
* Ran third.
*/
HIGH,
/**
* Ran last.
*/
HIGHEST
}

View File

@@ -1,11 +0,0 @@
package com.willfp.eco.util.interfaces;
public interface EcoRunnable extends Runnable {
/**
* The EcoRunnable interface is generally used for repeating tasks.
* This method is to retrieve the ticks between repetitions.
*
* @return The ticks between repetitions.
*/
long getTime();
}

View File

@@ -1,8 +0,0 @@
package com.willfp.eco.util.interfaces;
public interface Registerable {
/**
* Register an object with its respective registry.
*/
void register();
}

View File

@@ -1,10 +1,10 @@
package com.willfp.eco.util.plugin; package com.willfp.eco.util.plugin;
import com.willfp.eco.internal.arrows.ArrowDataListener;
import com.willfp.eco.internal.bukkit.events.EcoEventManager; import com.willfp.eco.internal.bukkit.events.EcoEventManager;
import com.willfp.eco.internal.bukkit.logging.EcoLogger; import com.willfp.eco.internal.bukkit.logging.EcoLogger;
import com.willfp.eco.internal.bukkit.scheduling.EcoScheduler; import com.willfp.eco.internal.bukkit.scheduling.EcoScheduler;
import com.willfp.eco.util.ClassUtils; import com.willfp.eco.internal.extensions.EcoExtensionLoader;
import com.willfp.eco.util.arrows.ArrowDataListener;
import com.willfp.eco.util.bukkit.events.EventManager; import com.willfp.eco.util.bukkit.events.EventManager;
import com.willfp.eco.util.bukkit.keys.NamespacedKeyFactory; import com.willfp.eco.util.bukkit.keys.NamespacedKeyFactory;
import com.willfp.eco.util.bukkit.logging.Logger; import com.willfp.eco.util.bukkit.logging.Logger;
@@ -15,15 +15,14 @@ import com.willfp.eco.util.command.AbstractCommand;
import com.willfp.eco.util.config.configs.Config; import com.willfp.eco.util.config.configs.Config;
import com.willfp.eco.util.config.configs.Lang; import com.willfp.eco.util.config.configs.Lang;
import com.willfp.eco.util.config.updating.ConfigHandler; import com.willfp.eco.util.config.updating.ConfigHandler;
import com.willfp.eco.internal.extensions.EcoExtensionLoader; import com.willfp.eco.util.display.Display;
import com.willfp.eco.util.display.DisplayModule;
import com.willfp.eco.util.extensions.loader.ExtensionLoader; import com.willfp.eco.util.extensions.loader.ExtensionLoader;
import com.willfp.eco.util.integrations.IntegrationLoader; import com.willfp.eco.util.integrations.IntegrationLoader;
import com.willfp.eco.util.integrations.placeholder.PlaceholderManager; import com.willfp.eco.util.integrations.placeholder.PlaceholderManager;
import com.willfp.eco.util.integrations.placeholder.plugins.PlaceholderIntegrationPAPI; import com.willfp.eco.util.integrations.placeholder.plugins.PlaceholderIntegrationPAPI;
import com.willfp.eco.util.optional.Prerequisite; import com.willfp.eco.util.optional.Prerequisite;
import com.willfp.eco.util.protocollib.AbstractPacketAdapter; import com.willfp.eco.util.protocollib.AbstractPacketAdapter;
import com.willfp.eco.util.recipe.RecipeListener;
import com.willfp.eco.util.recipe.RecipeManager;
import com.willfp.eco.util.updater.UpdateChecker; import com.willfp.eco.util.updater.UpdateChecker;
import lombok.Getter; import lombok.Getter;
import org.apache.maven.artifact.versioning.DefaultArtifactVersion; import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
@@ -33,6 +32,7 @@ import org.bukkit.event.Listener;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
@@ -141,12 +141,6 @@ public abstract class AbstractEcoPlugin extends JavaPlugin {
@Getter @Getter
private final RunnableFactory runnableFactory; private final RunnableFactory runnableFactory;
/**
* Recipe handler for crafting recipes.
*/
@Getter
private final RecipeManager recipeManager;
/** /**
* The loader for all plugin extensions. * The loader for all plugin extensions.
* *
@@ -161,6 +155,12 @@ public abstract class AbstractEcoPlugin extends JavaPlugin {
@Getter @Getter
private final ConfigHandler configHandler; private final ConfigHandler configHandler;
/**
* The display module for the plugin.
*/
@Getter
private DisplayModule displayModule;
/** /**
* If the server is running an outdated version of the plugin. * If the server is running an outdated version of the plugin.
*/ */
@@ -195,7 +195,6 @@ public abstract class AbstractEcoPlugin extends JavaPlugin {
this.runnableFactory = new RunnableFactory(this); this.runnableFactory = new RunnableFactory(this);
this.extensionLoader = new EcoExtensionLoader(this); this.extensionLoader = new EcoExtensionLoader(this);
this.configHandler = new ConfigHandler(this); this.configHandler = new ConfigHandler(this);
this.recipeManager = new RecipeManager(this);
this.langYml = new Lang(this); this.langYml = new Lang(this);
this.configYml = new Config(this); this.configYml = new Config(this);
@@ -214,7 +213,6 @@ public abstract class AbstractEcoPlugin extends JavaPlugin {
this.getLog().info("Loading " + this.color + this.pluginName); this.getLog().info("Loading " + this.color + this.pluginName);
this.getEventManager().registerListener(new ArrowDataListener(this)); this.getEventManager().registerListener(new ArrowDataListener(this));
this.getEventManager().registerListener(new RecipeListener(this));
new UpdateChecker(this).getVersion(version -> { new UpdateChecker(this).getVersion(version -> {
DefaultArtifactVersion currentVersion = new DefaultArtifactVersion(this.getDescription().getVersion()); DefaultArtifactVersion currentVersion = new DefaultArtifactVersion(this.getDescription().getVersion());
@@ -297,14 +295,18 @@ public abstract class AbstractEcoPlugin extends JavaPlugin {
* Default code to be executed after the server is up. * Default code to be executed after the server is up.
*/ */
public final void afterLoad() { public final void afterLoad() {
if (ClassUtils.exists("com.comphenix.protocol.events.PacketAdapter")) { this.displayModule = createDisplayModule();
this.getPacketAdapters().forEach(abstractPacketAdapter -> {
if (abstractPacketAdapter.isPostLoad()) { if (this.getDisplayModule() != null) {
abstractPacketAdapter.register(); Display.registerDisplayModule(this.getDisplayModule());
}
});
} }
this.getPacketAdapters().forEach(abstractPacketAdapter -> {
if (abstractPacketAdapter.isPostLoad()) {
abstractPacketAdapter.register();
}
});
if (!Prerequisite.HAS_PAPER.isMet()) { if (!Prerequisite.HAS_PAPER.isMet()) {
this.getLog().error(""); this.getLog().error("");
this.getLog().error("----------------------------"); this.getLog().error("----------------------------");
@@ -400,4 +402,12 @@ public abstract class AbstractEcoPlugin extends JavaPlugin {
* @return A list of all updatable classes. * @return A list of all updatable classes.
*/ */
public abstract List<Class<?>> getUpdatableClasses(); public abstract List<Class<?>> getUpdatableClasses();
/**
* Create the display module for the plugin.
*
* @return The display module, or null.
*/
@Nullable
protected abstract DisplayModule createDisplayModule();
} }

View File

@@ -1,89 +0,0 @@
package com.willfp.eco.util.recipe;
import com.willfp.eco.util.internal.PluginDependent;
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
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);
}
}
}

View File

@@ -0,0 +1,63 @@
package com.willfp.eco.util.recipe;
import com.willfp.eco.util.recipe.parts.EmptyRecipePart;
import com.willfp.eco.util.recipe.parts.RecipePart;
import com.willfp.eco.util.recipe.parts.SimpleRecipePart;
import lombok.experimental.UtilityClass;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import java.util.HashMap;
import java.util.Map;
@UtilityClass
@SuppressWarnings("deprecation")
public final class RecipeParts {
/**
* All recipe parts.
*/
private static final Map<NamespacedKey, RecipePart> PARTS = new HashMap<>();
/**
* Register a new recipe part.
*
* @param key The key of the recipe part.
* @param part The recipe part.
*/
public void registerRecipePart(@NotNull final NamespacedKey key,
@NotNull final RecipePart part) {
PARTS.put(key, part);
}
/**
* Lookup recipe part from string.
*
* @param key The string to test.
* @return The found recipe part, or null if not found.
*/
public RecipePart lookup(@NotNull final String key) {
String[] split = key.toLowerCase().split(":");
if (split.length == 1) {
Material material = Material.getMaterial(key.toUpperCase());
if (material == null || material == Material.AIR) {
return new EmptyRecipePart();
}
return new SimpleRecipePart(material);
}
RecipePart part = PARTS.get(new NamespacedKey(split[0], split[1]));
return part == null ? new EmptyRecipePart() : part;
}
/**
* Get if itemStack is a recipe part (used to check for custom items).
*
* @param itemStack The itemStack to check.
* @return If is recipe.
*/
public boolean isRecipePart(@NotNull final ItemStack itemStack) {
return PARTS.values().stream().anyMatch(recipePart -> recipePart.matches(itemStack));
}
}

View File

@@ -2,8 +2,8 @@ package com.willfp.eco.util.recipe;
import com.google.common.collect.BiMap; import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap; import com.google.common.collect.HashBiMap;
import com.willfp.eco.util.internal.PluginDependent; import com.willfp.eco.util.recipe.recipes.EcoShapedRecipe;
import com.willfp.eco.util.plugin.AbstractEcoPlugin; import lombok.experimental.UtilityClass;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.NamespacedKey; import org.bukkit.NamespacedKey;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@@ -12,40 +12,34 @@ import org.bukkit.inventory.ShapedRecipe;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@UtilityClass
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public class RecipeManager extends PluginDependent { public class Recipes {
/** /**
* Registry of all recipes. * Registry of all recipes.
*/ */
private final BiMap<String, EcoShapedRecipe> registry = HashBiMap.create(); private static final BiMap<NamespacedKey, EcoShapedRecipe> RECIPES = HashBiMap.create();
/** /**
* Pass an {@link AbstractEcoPlugin} in order to interface with it. * Register a recipe.
* *
* @param plugin The plugin to manage. * @param recipe The recipe.
*/ */
public RecipeManager(@NotNull final AbstractEcoPlugin plugin) { public void register(@NotNull final EcoShapedRecipe recipe) {
super(plugin); RECIPES.forcePut(recipe.getKey(), recipe);
}
void register(@NotNull final EcoShapedRecipe recipe) { Bukkit.getServer().removeRecipe(recipe.getKey());
String key = recipe.getKey(); Bukkit.getServer().removeRecipe(recipe.getDisplayedKey());
registry.forcePut(key, recipe);
NamespacedKey baseKey = this.getPlugin().getNamespacedKeyFactory().create(key); ShapedRecipe shapedRecipe = new ShapedRecipe(recipe.getKey(), recipe.getOutput());
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"); shapedRecipe.shape("012", "345", "678");
for (int i = 0; i < 9; i++) { for (int i = 0; i < 9; i++) {
char character = String.valueOf(i).toCharArray()[0]; char character = String.valueOf(i).toCharArray()[0];
shapedRecipe.setIngredient(character, recipe.getMaterialAtIndex(i)); shapedRecipe.setIngredient(character, recipe.getMaterialAtIndex(i));
} }
ShapedRecipe displayedRecipe = new ShapedRecipe(displayedKey, recipe.getOutput()); ShapedRecipe displayedRecipe = new ShapedRecipe(recipe.getDisplayedKey(), recipe.getOutput());
displayedRecipe.shape("012", "345", "678"); displayedRecipe.shape("012", "345", "678");
for (int i = 0; i < 9; i++) { for (int i = 0; i < 9; i++) {
char character = String.valueOf(i).toCharArray()[0]; char character = String.valueOf(i).toCharArray()[0];
@@ -64,7 +58,7 @@ public class RecipeManager extends PluginDependent {
*/ */
@Nullable @Nullable
public EcoShapedRecipe getMatch(@NotNull final ItemStack[] matrix) { public EcoShapedRecipe getMatch(@NotNull final ItemStack[] matrix) {
return registry.values().stream().filter(recipe -> recipe.test(matrix)).findFirst().orElse(null); return RECIPES.values().stream().filter(recipe -> recipe.test(matrix)).findFirst().orElse(null);
} }
/** /**
@@ -74,7 +68,18 @@ public class RecipeManager extends PluginDependent {
* @return The shaped recipe, or null if not found. * @return The shaped recipe, or null if not found.
*/ */
@Nullable @Nullable
public EcoShapedRecipe getShapedRecipe(@NotNull final String key) { public EcoShapedRecipe getShapedRecipe(@NotNull final NamespacedKey key) {
return registry.get(key); EcoShapedRecipe recipe = RECIPES.get(key);
if (recipe != null) {
return recipe;
}
if (key.getKey().contains("_displayed")) {
NamespacedKey otherKey = new NamespacedKey(key.getNamespace(), key.getKey().replace("_displayed", ""));
return RECIPES.get(otherKey);
}
return null;
} }
} }

View File

@@ -1,51 +0,0 @@
package com.willfp.eco.util.recipe.lookup;
import com.willfp.eco.util.recipe.parts.EmptyRecipePart;
import com.willfp.eco.util.recipe.parts.RecipePart;
import com.willfp.eco.util.recipe.parts.SimpleRecipePart;
import lombok.experimental.UtilityClass;
import org.bukkit.Material;
import org.jetbrains.annotations.NotNull;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Function;
@UtilityClass
public final class RecipePartUtils {
/**
* All recipes.
*/
private static final Map<String, Function<String, RecipePart>> TESTS = new HashMap<>();
/**
* Register a new lookup.
*
* @param key The key of the lookup.
* @param lookupFunction The lookup to register, where the output is the recipe part generated.
*/
public void registerLookup(@NotNull final String key,
@NotNull final Function<String, RecipePart> lookupFunction) {
TESTS.put(key, lookupFunction);
}
/**
* Lookup recipe part from string.
*
* @param key The string to test.
* @return The generated recipe part, or null if invalid.
*/
public RecipePart lookup(@NotNull final String key) {
Function<String, RecipePart> lookup = TESTS.get(key);
if (lookup == null) {
Material material = Material.getMaterial(key.toUpperCase());
if (material == null || material == Material.AIR) {
return new EmptyRecipePart();
}
return new SimpleRecipePart(material);
}
return lookup.apply(key);
}
}

View File

@@ -1,18 +1,19 @@
package com.willfp.eco.util.recipe; package com.willfp.eco.util.recipe.recipes;
import com.willfp.eco.util.interfaces.Registerable;
import com.willfp.eco.util.internal.PluginDependent; import com.willfp.eco.util.internal.PluginDependent;
import com.willfp.eco.util.plugin.AbstractEcoPlugin; import com.willfp.eco.util.plugin.AbstractEcoPlugin;
import com.willfp.eco.util.recipe.Recipes;
import com.willfp.eco.util.recipe.parts.EmptyRecipePart; import com.willfp.eco.util.recipe.parts.EmptyRecipePart;
import com.willfp.eco.util.recipe.parts.RecipePart; import com.willfp.eco.util.recipe.parts.RecipePart;
import lombok.Getter; import lombok.Getter;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.util.Arrays; import java.util.Arrays;
public final class EcoShapedRecipe extends PluginDependent implements Registerable { public final class EcoShapedRecipe extends PluginDependent {
/** /**
* Recipe parts. * Recipe parts.
*/ */
@@ -23,7 +24,13 @@ public final class EcoShapedRecipe extends PluginDependent implements Registerab
* The key of the recipe. * The key of the recipe.
*/ */
@Getter @Getter
private final String key; private final NamespacedKey key;
/**
* The key of the displayed recipe.
*/
@Getter
private final NamespacedKey displayedKey;
/** /**
* The recipe's output. * The recipe's output.
@@ -38,7 +45,8 @@ public final class EcoShapedRecipe extends PluginDependent implements Registerab
super(plugin); super(plugin);
this.parts = parts; this.parts = parts;
this.key = key; this.key = plugin.getNamespacedKeyFactory().create(key);
this.displayedKey = plugin.getNamespacedKeyFactory().create(key + "_displayed");
this.output = output; this.output = output;
} }
@@ -82,9 +90,8 @@ public final class EcoShapedRecipe extends PluginDependent implements Registerab
/** /**
* Register the recipe. * Register the recipe.
*/ */
@Override
public void register() { public void register() {
this.getPlugin().getRecipeManager().register(this); Recipes.register(this);
} }
@Override @Override
@@ -193,66 +200,4 @@ public final class EcoShapedRecipe extends PluginDependent implements Registerab
return new EcoShapedRecipe(plugin, key.toLowerCase(), recipeParts, output); 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;
}
}
} }

View File

@@ -0,0 +1,65 @@
package com.willfp.eco.util.recipe.recipes;
import lombok.Getter;
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;
}
}

View File

@@ -1,9 +1,26 @@
package com.willfp.eco.util.tuples; package com.willfp.eco.util.tuples;
import lombok.Getter;
import lombok.Setter;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@SuppressWarnings("deprecation") public class Pair<A, B> {
public class Pair<A, B> extends com.willfp.eco.util.tuplets.Pair<A, B> { /**
* The first item in the tuple.
*/
@Getter
@Setter
@Nullable
private A first;
/**
* The second item in the tuple.
*/
@Getter
@Setter
@Nullable
private B second;
/** /**
* Create a pair of values. * Create a pair of values.
* *
@@ -12,6 +29,7 @@ public class Pair<A, B> extends com.willfp.eco.util.tuplets.Pair<A, B> {
*/ */
public Pair(@Nullable final A first, public Pair(@Nullable final A first,
@Nullable final B second) { @Nullable final B second) {
super(first, second); this.first = first;
this.second = second;
} }
} }

View File

@@ -1,9 +1,18 @@
package com.willfp.eco.util.tuples; package com.willfp.eco.util.tuples;
import lombok.Getter;
import lombok.Setter;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@SuppressWarnings("deprecation") public class Triplet<A, B, C> extends Pair<A, B> {
public class Triplet<A, B, C> extends com.willfp.eco.util.tuplets.Triplet<A, B, C> { /**
* The third item in the tuple.
*/
@Getter
@Setter
@Nullable
private C third;
/** /**
* Create a triple of values. * Create a triple of values.
* *
@@ -14,6 +23,8 @@ public class Triplet<A, B, C> extends com.willfp.eco.util.tuplets.Triplet<A, B,
public Triplet(@Nullable final A first, public Triplet(@Nullable final A first,
@Nullable final B second, @Nullable final B second,
@Nullable final C third) { @Nullable final C third) {
super(first, second, third); super(first, second);
this.third = third;
} }
} }

View File

@@ -1,41 +0,0 @@
package com.willfp.eco.util.tuplets;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.jetbrains.annotations.Nullable;
@SuppressWarnings("DeprecatedIsStillUsed")
@ToString
@Deprecated
public class Pair<A, B> {
/**
* The first value in the pair.
*/
@Getter
@Setter
@Nullable
private A first;
/**
* The second value in the pair.
*/
@Getter
@Setter
@Nullable
private B second;
/**
* Create a pair of values.
* <p>
* This is deprecated because I forgot how to spell Tuples before putting this into production.
*
* @param first The first item in the pair.
* @param second The second item in the pair.
*/
public Pair(@Nullable final A first,
@Nullable final B second) {
this.first = first;
this.second = second;
}
}

View File

@@ -1,52 +0,0 @@
package com.willfp.eco.util.tuplets;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.jetbrains.annotations.Nullable;
@SuppressWarnings("DeprecatedIsStillUsed")
@ToString
@Deprecated
public class Triplet<A, B, C> {
/**
* The first item in the triplet.
*/
@Getter
@Setter
@Nullable
private A first;
/**
* The second item in the triplet.
*/
@Getter
@Setter
@Nullable
private B second;
/**
* The third item in the triplet.
*/
@Getter
@Setter
@Nullable
private C third;
/**
* Create a triplet.
* <p>
* This is deprecated because I forgot how to spell Tuples before putting this into production.
*
* @param first The first item in the triplet.
* @param second The second item in the triplet.
* @param third The third item in the triplet.
*/
public Triplet(@Nullable final A first,
@Nullable final B second,
@Nullable final C third) {
this.first = first;
this.second = second;
this.third = third;
}
}

View File

@@ -1,2 +1,2 @@
version = 3.8.0 version = 4.0.0
plugin-name = eco plugin-name = eco