diff --git a/eco-api/src/main/java/com/willfp/eco/core/EcoPlugin.java b/eco-api/src/main/java/com/willfp/eco/core/EcoPlugin.java index 0cc874a1..e29375e4 100644 --- a/eco-api/src/main/java/com/willfp/eco/core/EcoPlugin.java +++ b/eco-api/src/main/java/com/willfp/eco/core/EcoPlugin.java @@ -3,7 +3,7 @@ package com.willfp.eco.core; import com.willfp.eco.core.command.AbstractCommand; import com.willfp.eco.core.config.configs.Config; import com.willfp.eco.core.config.configs.Lang; -import com.willfp.eco.core.config.updating.ConfigHandler; +import com.willfp.eco.internal.config.updating.ConfigHandler; import com.willfp.eco.core.display.Display; import com.willfp.eco.core.display.DisplayModule; import com.willfp.eco.core.events.EventManager; @@ -38,6 +38,7 @@ import java.util.Arrays; import java.util.HashSet; import java.util.List; import java.util.Set; +import java.util.logging.Logger; import java.util.stream.Collectors; public abstract class EcoPlugin extends JavaPlugin { @@ -154,6 +155,11 @@ public abstract class EcoPlugin extends JavaPlugin { @Getter private DisplayModule displayModule; + /** + * The logger for the plugin. + */ + private Logger logger; + /** * If the server is running an outdated version of the plugin. */ @@ -404,4 +410,10 @@ public abstract class EcoPlugin extends JavaPlugin { protected DisplayModule createDisplayModule() { return null; } + + @NotNull + @Override + public Logger getLogger() { + return logger; + } } diff --git a/eco-api/src/main/java/com/willfp/eco/core/recipe/parts/ComplexRecipePart.java b/eco-api/src/main/java/com/willfp/eco/core/items/CustomItem.java similarity index 52% rename from eco-api/src/main/java/com/willfp/eco/core/recipe/parts/ComplexRecipePart.java rename to eco-api/src/main/java/com/willfp/eco/core/items/CustomItem.java index 271eaa60..3dae3a45 100644 --- a/eco-api/src/main/java/com/willfp/eco/core/recipe/parts/ComplexRecipePart.java +++ b/eco-api/src/main/java/com/willfp/eco/core/items/CustomItem.java @@ -1,4 +1,4 @@ -package com.willfp.eco.core.recipe.parts; +package com.willfp.eco.core.items; import lombok.Getter; import org.bukkit.inventory.ItemStack; @@ -7,27 +7,27 @@ import org.jetbrains.annotations.Nullable; import java.util.function.Predicate; -public class ComplexRecipePart implements RecipePart { +public class CustomItem implements TestableItem { /** - * The test for itemstacks to pass. + * The test for ItemStacks to pass. */ @Getter private final Predicate predicate; /** - * Displayed itemstack: what the user should see. + * Example Item: what the user should see. */ - private final ItemStack displayed; + private final ItemStack item; /** * Create a new complex recipe part. * @param predicate The test. - * @param displayed The example itemstack. + * @param item The example ItemStacks. */ - public ComplexRecipePart(@NotNull final Predicate predicate, - @NotNull final ItemStack displayed) { + public CustomItem(@NotNull final Predicate predicate, + @NotNull final ItemStack item) { this.predicate = predicate; - this.displayed = displayed; + this.item = item; } @Override @@ -36,7 +36,7 @@ public class ComplexRecipePart implements RecipePart { } @Override - public ItemStack getDisplayed() { - return displayed; + public ItemStack getItem() { + return item; } } diff --git a/eco-api/src/main/java/com/willfp/eco/core/items/CustomItems.java b/eco-api/src/main/java/com/willfp/eco/core/items/CustomItems.java new file mode 100644 index 00000000..2be5041a --- /dev/null +++ b/eco-api/src/main/java/com/willfp/eco/core/items/CustomItems.java @@ -0,0 +1,64 @@ +package com.willfp.eco.core.items; + +import com.willfp.eco.core.recipe.parts.EmptyTestableItem; +import com.willfp.eco.core.recipe.parts.MaterialTestableItem; +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 CustomItems { + /** + * All recipe parts. + */ + private static final Map REGISTRY = new HashMap<>(); + + /** + * Register a new recipe part. + * + * @param key The key of the recipe part. + * @param part The recipe part. + */ + public void registerCustomItem(@NotNull final NamespacedKey key, + @NotNull final TestableItem part) { + REGISTRY.put(key, part); + } + + /** + * Lookup item from string. + *

+ * Used for recipes. + * + * @param key The string to test. + * @return The found testable item, or null if not found. + */ + public TestableItem 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 EmptyTestableItem(); + } + return new MaterialTestableItem(material); + } + + TestableItem part = REGISTRY.get(new NamespacedKey(split[0], split[1])); + return part == null ? new EmptyTestableItem() : part; + } + + /** + * Get if itemStack is a custom item. + * + * @param itemStack The itemStack to check. + * @return If is recipe. + */ + public boolean isCustomItem(@NotNull final ItemStack itemStack) { + return REGISTRY.values().stream().anyMatch(recipePart -> recipePart.matches(itemStack)); + } +} diff --git a/eco-api/src/main/java/com/willfp/eco/core/recipe/parts/RecipePart.java b/eco-api/src/main/java/com/willfp/eco/core/items/TestableItem.java similarity index 79% rename from eco-api/src/main/java/com/willfp/eco/core/recipe/parts/RecipePart.java rename to eco-api/src/main/java/com/willfp/eco/core/items/TestableItem.java index b0e6d4be..94089770 100644 --- a/eco-api/src/main/java/com/willfp/eco/core/recipe/parts/RecipePart.java +++ b/eco-api/src/main/java/com/willfp/eco/core/items/TestableItem.java @@ -1,9 +1,9 @@ -package com.willfp.eco.core.recipe.parts; +package com.willfp.eco.core.items; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.Nullable; -public interface RecipePart { +public interface TestableItem { /** * If an ItemStack matches the recipe part. * @@ -17,6 +17,5 @@ public interface RecipePart { * * @return The item, displayed. */ - ItemStack getDisplayed(); + ItemStack getItem(); } - diff --git a/eco-api/src/main/java/com/willfp/eco/core/recipe/RecipeParts.java b/eco-api/src/main/java/com/willfp/eco/core/recipe/RecipeParts.java deleted file mode 100644 index d5d2f7f9..00000000 --- a/eco-api/src/main/java/com/willfp/eco/core/recipe/RecipeParts.java +++ /dev/null @@ -1,63 +0,0 @@ -package com.willfp.eco.core.recipe; - -import com.willfp.eco.core.recipe.parts.EmptyRecipePart; -import com.willfp.eco.core.recipe.parts.RecipePart; -import com.willfp.eco.core.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 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)); - } -} diff --git a/eco-api/src/main/java/com/willfp/eco/core/recipe/parts/EmptyRecipePart.java b/eco-api/src/main/java/com/willfp/eco/core/recipe/parts/EmptyTestableItem.java similarity index 77% rename from eco-api/src/main/java/com/willfp/eco/core/recipe/parts/EmptyRecipePart.java rename to eco-api/src/main/java/com/willfp/eco/core/recipe/parts/EmptyTestableItem.java index 23312b5a..8d6912c1 100644 --- a/eco-api/src/main/java/com/willfp/eco/core/recipe/parts/EmptyRecipePart.java +++ b/eco-api/src/main/java/com/willfp/eco/core/recipe/parts/EmptyTestableItem.java @@ -1,14 +1,15 @@ package com.willfp.eco.core.recipe.parts; +import com.willfp.eco.core.items.TestableItem; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.Nullable; -public class EmptyRecipePart implements RecipePart { +public class EmptyTestableItem implements TestableItem { /** * Create a new empty recipe part. */ - public EmptyRecipePart() { + public EmptyTestableItem() { } @@ -24,7 +25,7 @@ public class EmptyRecipePart implements RecipePart { } @Override - public ItemStack getDisplayed() { + public ItemStack getItem() { return new ItemStack(Material.AIR); } } diff --git a/eco-api/src/main/java/com/willfp/eco/core/recipe/parts/SimpleRecipePart.java b/eco-api/src/main/java/com/willfp/eco/core/recipe/parts/MaterialTestableItem.java similarity index 79% rename from eco-api/src/main/java/com/willfp/eco/core/recipe/parts/SimpleRecipePart.java rename to eco-api/src/main/java/com/willfp/eco/core/recipe/parts/MaterialTestableItem.java index 8035fa85..511cb983 100644 --- a/eco-api/src/main/java/com/willfp/eco/core/recipe/parts/SimpleRecipePart.java +++ b/eco-api/src/main/java/com/willfp/eco/core/recipe/parts/MaterialTestableItem.java @@ -1,12 +1,13 @@ package com.willfp.eco.core.recipe.parts; +import com.willfp.eco.core.items.TestableItem; import lombok.Getter; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -public class SimpleRecipePart implements RecipePart { +public class MaterialTestableItem implements TestableItem { /** * The material. */ @@ -18,7 +19,7 @@ public class SimpleRecipePart implements RecipePart { * * @param material The material. */ - public SimpleRecipePart(@NotNull final Material material) { + public MaterialTestableItem(@NotNull final Material material) { this.material = material; } @@ -34,7 +35,7 @@ public class SimpleRecipePart implements RecipePart { } @Override - public ItemStack getDisplayed() { + public ItemStack getItem() { return new ItemStack(material); } } diff --git a/eco-api/src/main/java/com/willfp/eco/core/recipe/recipes/CraftingRecipe.java b/eco-api/src/main/java/com/willfp/eco/core/recipe/recipes/CraftingRecipe.java index edfba9b1..7434381f 100644 --- a/eco-api/src/main/java/com/willfp/eco/core/recipe/recipes/CraftingRecipe.java +++ b/eco-api/src/main/java/com/willfp/eco/core/recipe/recipes/CraftingRecipe.java @@ -1,6 +1,6 @@ package com.willfp.eco.core.recipe.recipes; -import com.willfp.eco.core.recipe.parts.RecipePart; +import com.willfp.eco.core.items.TestableItem; import org.bukkit.Material; import org.bukkit.NamespacedKey; import org.bukkit.inventory.ItemStack; @@ -41,7 +41,7 @@ public interface CraftingRecipe { * * @return The parts. */ - RecipePart[] getParts(); + TestableItem[] getParts(); /** * Get the recipe key. diff --git a/eco-api/src/main/java/com/willfp/eco/core/recipe/recipes/ShapedCraftingRecipe.java b/eco-api/src/main/java/com/willfp/eco/core/recipe/recipes/ShapedCraftingRecipe.java index 452a138c..1b2652c4 100644 --- a/eco-api/src/main/java/com/willfp/eco/core/recipe/recipes/ShapedCraftingRecipe.java +++ b/eco-api/src/main/java/com/willfp/eco/core/recipe/recipes/ShapedCraftingRecipe.java @@ -2,9 +2,9 @@ package com.willfp.eco.core.recipe.recipes; import com.willfp.eco.core.PluginDependent; import com.willfp.eco.core.EcoPlugin; +import com.willfp.eco.core.items.TestableItem; import com.willfp.eco.core.recipe.Recipes; -import com.willfp.eco.core.recipe.parts.EmptyRecipePart; -import com.willfp.eco.core.recipe.parts.RecipePart; +import com.willfp.eco.core.recipe.parts.EmptyTestableItem; import lombok.Getter; import org.bukkit.Material; import org.bukkit.NamespacedKey; @@ -18,7 +18,7 @@ public final class ShapedCraftingRecipe extends PluginDependent implements Craft * Recipe parts. */ @Getter - private final RecipePart[] parts; + private final TestableItem[] parts; /** * The key of the recipe. @@ -40,7 +40,7 @@ public final class ShapedCraftingRecipe extends PluginDependent implements Craft private ShapedCraftingRecipe(@NotNull final EcoPlugin plugin, @NotNull final String key, - @NotNull final RecipePart[] parts, + @NotNull final TestableItem[] parts, @NotNull final ItemStack output) { super(plugin); @@ -52,12 +52,12 @@ public final class ShapedCraftingRecipe extends PluginDependent implements Craft @Override public Material getMaterialAtIndex(final int index) { - return parts[index].getDisplayed().getType(); + return parts[index].getItem().getType(); } @Override public ItemStack getDisplayedAtIndex(final int index) { - return parts[index].getDisplayed(); + return parts[index].getItem(); } @Override @@ -102,7 +102,7 @@ public final class ShapedCraftingRecipe extends PluginDependent implements Craft /** * The recipe parts. */ - private final RecipePart[] recipeParts = new RecipePart[9]; + private final TestableItem[] recipeParts = new TestableItem[9]; /** * The output of the recipe. @@ -139,7 +139,7 @@ public final class ShapedCraftingRecipe extends PluginDependent implements Craft * @return The builder. */ public Builder setRecipePart(@NotNull final RecipePosition position, - @NotNull final RecipePart part) { + @NotNull final TestableItem part) { this.recipeParts[position.getIndex()] = part; return this; } @@ -152,7 +152,7 @@ public final class ShapedCraftingRecipe extends PluginDependent implements Craft * @return The builder. */ public Builder setRecipePart(final int position, - @NotNull final RecipePart part) { + @NotNull final TestableItem part) { this.recipeParts[position] = part; return this; } @@ -176,7 +176,7 @@ public final class ShapedCraftingRecipe extends PluginDependent implements Craft public ShapedCraftingRecipe build() { for (int i = 0; i < 9; i++) { if (recipeParts[i] == null) { - recipeParts[i] = new EmptyRecipePart(); + recipeParts[i] = new EmptyTestableItem(); } } diff --git a/eco-api/src/main/java/com/willfp/eco/core/config/updating/ConfigHandler.java b/eco-api/src/main/java/com/willfp/eco/internal/config/updating/ConfigHandler.java similarity index 89% rename from eco-api/src/main/java/com/willfp/eco/core/config/updating/ConfigHandler.java rename to eco-api/src/main/java/com/willfp/eco/internal/config/updating/ConfigHandler.java index 6ed64dfb..9a5c412d 100644 --- a/eco-api/src/main/java/com/willfp/eco/core/config/updating/ConfigHandler.java +++ b/eco-api/src/main/java/com/willfp/eco/internal/config/updating/ConfigHandler.java @@ -1,8 +1,8 @@ -package com.willfp.eco.core.config.updating; +package com.willfp.eco.internal.config.updating; -import com.willfp.eco.core.config.updating.annotations.ConfigUpdater; -import com.willfp.eco.core.config.updating.exceptions.InvalidUpdatableClassException; -import com.willfp.eco.core.config.updating.exceptions.InvalidUpdateMethodException; +import com.willfp.eco.internal.config.updating.annotations.ConfigUpdater; +import com.willfp.eco.internal.config.updating.exceptions.InvalidUpdatableClassException; +import com.willfp.eco.internal.config.updating.exceptions.InvalidUpdateMethodException; import com.willfp.eco.core.PluginDependent; import com.willfp.eco.core.EcoPlugin; import org.jetbrains.annotations.NotNull; diff --git a/eco-api/src/main/java/com/willfp/eco/core/config/updating/annotations/ConfigUpdater.java b/eco-api/src/main/java/com/willfp/eco/internal/config/updating/annotations/ConfigUpdater.java similarity index 81% rename from eco-api/src/main/java/com/willfp/eco/core/config/updating/annotations/ConfigUpdater.java rename to eco-api/src/main/java/com/willfp/eco/internal/config/updating/annotations/ConfigUpdater.java index af4a4a74..475a1d5b 100644 --- a/eco-api/src/main/java/com/willfp/eco/core/config/updating/annotations/ConfigUpdater.java +++ b/eco-api/src/main/java/com/willfp/eco/internal/config/updating/annotations/ConfigUpdater.java @@ -1,4 +1,4 @@ -package com.willfp.eco.core.config.updating.annotations; +package com.willfp.eco.internal.config.updating.annotations; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; diff --git a/eco-api/src/main/java/com/willfp/eco/core/config/updating/exceptions/InvalidUpdatableClassException.java b/eco-api/src/main/java/com/willfp/eco/internal/config/updating/exceptions/InvalidUpdatableClassException.java similarity index 75% rename from eco-api/src/main/java/com/willfp/eco/core/config/updating/exceptions/InvalidUpdatableClassException.java rename to eco-api/src/main/java/com/willfp/eco/internal/config/updating/exceptions/InvalidUpdatableClassException.java index 7449ed3c..b372d5d3 100644 --- a/eco-api/src/main/java/com/willfp/eco/core/config/updating/exceptions/InvalidUpdatableClassException.java +++ b/eco-api/src/main/java/com/willfp/eco/internal/config/updating/exceptions/InvalidUpdatableClassException.java @@ -1,6 +1,6 @@ -package com.willfp.eco.core.config.updating.exceptions; +package com.willfp.eco.internal.config.updating.exceptions; -import com.willfp.eco.core.config.updating.ConfigHandler; +import com.willfp.eco.internal.config.updating.ConfigHandler; import org.jetbrains.annotations.NotNull; public class InvalidUpdatableClassException extends RuntimeException { diff --git a/eco-api/src/main/java/com/willfp/eco/core/config/updating/exceptions/InvalidUpdateMethodException.java b/eco-api/src/main/java/com/willfp/eco/internal/config/updating/exceptions/InvalidUpdateMethodException.java similarity index 88% rename from eco-api/src/main/java/com/willfp/eco/core/config/updating/exceptions/InvalidUpdateMethodException.java rename to eco-api/src/main/java/com/willfp/eco/internal/config/updating/exceptions/InvalidUpdateMethodException.java index 3147cd38..a8b6b998 100644 --- a/eco-api/src/main/java/com/willfp/eco/core/config/updating/exceptions/InvalidUpdateMethodException.java +++ b/eco-api/src/main/java/com/willfp/eco/internal/config/updating/exceptions/InvalidUpdateMethodException.java @@ -1,4 +1,4 @@ -package com.willfp.eco.core.config.updating.exceptions; +package com.willfp.eco.internal.config.updating.exceptions; import org.jetbrains.annotations.NotNull; diff --git a/eco-api/src/main/java/com/willfp/eco/internal/logging/EcoLogger.java b/eco-api/src/main/java/com/willfp/eco/internal/logging/EcoLogger.java new file mode 100644 index 00000000..b98f0020 --- /dev/null +++ b/eco-api/src/main/java/com/willfp/eco/internal/logging/EcoLogger.java @@ -0,0 +1,27 @@ +package com.willfp.eco.internal.logging; + +import com.willfp.eco.core.EcoPlugin; +import com.willfp.eco.util.StringUtils; +import org.bukkit.plugin.PluginLogger; +import org.jetbrains.annotations.NotNull; + +public class EcoLogger extends PluginLogger { + public EcoLogger(@NotNull final EcoPlugin context) { + super(context); + } + + @Override + public void info(@NotNull final String msg) { + super.info(StringUtils.translate(msg)); + } + + @Override + public void warning(@NotNull final String msg) { + super.warning(StringUtils.translate(msg)); + } + + @Override + public void severe(@NotNull final String msg) { + super.severe(StringUtils.translate(msg)); + } +} diff --git a/eco-core/core-plugin/src/main/java/com/willfp/eco/spigot/recipes/RecipeListener.java b/eco-core/core-plugin/src/main/java/com/willfp/eco/spigot/recipes/RecipeListener.java index b797974c..c7e07031 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/eco/spigot/recipes/RecipeListener.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/eco/spigot/recipes/RecipeListener.java @@ -1,10 +1,10 @@ package com.willfp.eco.spigot.recipes; import com.willfp.eco.core.EcoPlugin; -import com.willfp.eco.core.recipe.RecipeParts; +import com.willfp.eco.core.items.CustomItems; +import com.willfp.eco.core.items.TestableItem; import com.willfp.eco.core.recipe.Recipes; -import com.willfp.eco.core.recipe.parts.RecipePart; -import com.willfp.eco.core.recipe.parts.SimpleRecipePart; +import com.willfp.eco.core.recipe.parts.MaterialTestableItem; import com.willfp.eco.core.recipe.recipes.ShapedCraftingRecipe; import org.bukkit.Material; import org.bukkit.event.Event; @@ -107,9 +107,9 @@ public class RecipeListener implements Listener { for (int i = 0; i < 9; i++) { ItemStack itemStack = event.getInventory().getMatrix()[i]; - RecipePart part = shapedCraftingRecipe.getParts()[i]; - if (part instanceof SimpleRecipePart) { - if (RecipeParts.isRecipePart(itemStack)) { + TestableItem part = shapedCraftingRecipe.getParts()[i]; + if (part instanceof MaterialTestableItem) { + if (CustomItems.isCustomItem(itemStack)) { event.getInventory().setResult(new ItemStack(Material.AIR)); return; } @@ -138,9 +138,9 @@ public class RecipeListener implements Listener { for (int i = 0; i < 9; i++) { ItemStack itemStack = event.getInventory().getMatrix()[i]; - RecipePart part = shapedCraftingRecipe.getParts()[i]; - if (part instanceof SimpleRecipePart) { - if (RecipeParts.isRecipePart(itemStack)) { + TestableItem part = shapedCraftingRecipe.getParts()[i]; + if (part instanceof MaterialTestableItem) { + if (CustomItems.isCustomItem(itemStack)) { event.getInventory().setResult(new ItemStack(Material.AIR)); event.setResult(Event.Result.DENY); event.setCancelled(true); @@ -168,7 +168,7 @@ public class RecipeListener implements Listener { } for (ItemStack itemStack : event.getInventory().getMatrix()) { - if (RecipeParts.isRecipePart(itemStack)) { + if (CustomItems.isCustomItem(itemStack)) { event.getInventory().setResult(new ItemStack(Material.AIR)); return; } @@ -193,7 +193,7 @@ public class RecipeListener implements Listener { } for (ItemStack itemStack : event.getInventory().getMatrix()) { - if (RecipeParts.isRecipePart(itemStack)) { + if (CustomItems.isCustomItem(itemStack)) { event.getInventory().setResult(new ItemStack(Material.AIR)); event.setResult(Event.Result.DENY); event.setCancelled(true);