diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/meta/EnchantmentType.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/meta/EnchantmentType.java index f3c8391f..5f96d31b 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/meta/EnchantmentType.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/meta/EnchantmentType.java @@ -3,7 +3,6 @@ package com.willfp.ecoenchants.enchantments.meta; import com.google.common.collect.ImmutableList; import com.willfp.eco.util.config.Configs; import com.willfp.eco.util.config.annotations.ConfigUpdater; -import com.willfp.eco.util.lambda.ObjectCallable; import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.itemtypes.Artifact; import com.willfp.ecoenchants.enchantments.itemtypes.Spell; @@ -13,6 +12,7 @@ import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.List; +import java.util.function.Supplier; public class EnchantmentType { /** @@ -80,12 +80,12 @@ public class EnchantmentType { /** * Lambda to fetch the color of the type. */ - private final ObjectCallable colorCallable; + private final Supplier colorSupplier; /** * Lambda to fetch the singularity of the type. */ - private final ObjectCallable singularCallable; + private final Supplier singularSupplier; /** * If only one enchantment of this type is allowed on an item. @@ -136,12 +136,12 @@ public class EnchantmentType { * * @param name The name of the type. * @param singular Whether an item can have several enchantments of this type. - * @param colorCallable Lambda to fetch the color of enchantments with this type to have. Updates on /ecoreload. + * @param colorSupplier Lambda to fetch the color of enchantments with this type to have. Updates on /ecoreload. */ public EnchantmentType(@NotNull final String name, final boolean singular, - @NotNull final ObjectCallable colorCallable) { - this(name, () -> singular, colorCallable); + @NotNull final Supplier colorSupplier) { + this(name, () -> singular, colorSupplier); } /** @@ -151,57 +151,57 @@ public class EnchantmentType { * * @param name The name of the type. * @param singular Whether an item can have several enchantments of this type. - * @param colorCallable Lambda to fetch the color of enchantments with this type to have. Updates on /ecoreload. + * @param colorSupplier Lambda to fetch the color of enchantments with this type to have. Updates on /ecoreload. * @param requiredToExtend Class that all enchantments of this type must extend - or null if not required. */ public EnchantmentType(@NotNull final String name, final boolean singular, - @NotNull final ObjectCallable colorCallable, + @NotNull final Supplier colorSupplier, @Nullable final Class requiredToExtend) { - this(name, () -> singular, colorCallable, requiredToExtend); + this(name, () -> singular, colorSupplier, requiredToExtend); } /** * Create EnchantmentType with updatable color and singularity. * * @param name The name of the type. - * @param singularCallable Lambda to fetch whether an item can have several enchantments of this type. Updates on /ecoreload. - * @param colorCallable Lambda to fetch the color of enchantments with this type to have. Updates on /ecoreload. + * @param singularSupplier Lambda to fetch whether an item can have several enchantments of this type. Updates on /ecoreload. + * @param colorSupplier Lambda to fetch the color of enchantments with this type to have. Updates on /ecoreload. */ public EnchantmentType(@NotNull final String name, - @NotNull final ObjectCallable singularCallable, - @NotNull final ObjectCallable colorCallable) { - this(name, singularCallable, colorCallable, null); + @NotNull final Supplier singularSupplier, + @NotNull final Supplier colorSupplier) { + this(name, singularSupplier, colorSupplier, null); } /** * Create EnchantmentType with updatable color and singularity that must extend a specified class. * * @param name The name of the type. - * @param singularCallable Lambda to fetch whether an item can have several enchantments of this type. Updates on /ecoreload. - * @param colorCallable Lambda to fetch the color of enchantments with this type to have. Updates on /ecoreload. + * @param singularSupplier Lambda to fetch whether an item can have several enchantments of this type. Updates on /ecoreload. + * @param colorSupplier Lambda to fetch the color of enchantments with this type to have. Updates on /ecoreload. * @param requiredToExtend Class that all enchantments of this type must extend - or null if not required. */ public EnchantmentType(@NotNull final String name, - @NotNull final ObjectCallable singularCallable, - @NotNull final ObjectCallable colorCallable, + @NotNull final Supplier singularSupplier, + @NotNull final Supplier colorSupplier, @Nullable final Class requiredToExtend) { this.name = name; - this.singularCallable = singularCallable; - this.colorCallable = colorCallable; + this.singularSupplier = singularSupplier; + this.colorSupplier = colorSupplier; this.requiredToExtend = requiredToExtend; - color = colorCallable.call(); - singular = singularCallable.call(); + color = colorSupplier.get(); + singular = singularSupplier.get(); REGISTERED.add(this); } private void refresh() { - this.color = colorCallable.call(); - this.singular = singularCallable.call(); + this.color = colorSupplier.get(); + this.singular = singularSupplier.get(); } /** - * Update callables of all types. + * Update suppliers of all types. */ @ConfigUpdater public static void update() { diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/util/SpellRunnable.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/util/SpellRunnable.java index 861f345c..65c8522c 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/util/SpellRunnable.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/util/SpellRunnable.java @@ -1,7 +1,6 @@ package com.willfp.ecoenchants.enchantments.util; -import com.willfp.eco.util.lambda.Callable; import com.willfp.ecoenchants.enchantments.itemtypes.Spell; import lombok.Getter; import lombok.Setter; @@ -32,7 +31,7 @@ public class SpellRunnable { * Must be set before execution. */ @Setter - private Callable task = () -> { + private Runnable task = () -> { // Empty as must be set using this#setTask }; @@ -52,7 +51,7 @@ public class SpellRunnable { * Run the runnable. */ public void run() { - task.call(); + task.run(); updateEndTime(); } diff --git a/eco-util/src/main/java/com/willfp/eco/util/bukkit/scheduling/EcoScheduler.java b/eco-util/src/main/java/com/willfp/eco/util/bukkit/scheduling/EcoScheduler.java index 0c694d0b..6f0bbd19 100644 --- a/eco-util/src/main/java/com/willfp/eco/util/bukkit/scheduling/EcoScheduler.java +++ b/eco-util/src/main/java/com/willfp/eco/util/bukkit/scheduling/EcoScheduler.java @@ -1,7 +1,6 @@ package com.willfp.eco.util.bukkit.scheduling; import com.willfp.eco.util.injection.PluginDependent; -import com.willfp.eco.util.lambda.Callable; import com.willfp.eco.util.plugin.AbstractEcoPlugin; import org.bukkit.Bukkit; import org.bukkit.scheduler.BukkitTask; @@ -22,44 +21,44 @@ public class EcoScheduler extends PluginDependent implements Scheduler { /** * Run the task after a specified tick delay. * - * @param callable The lambda to run. + * @param runnable The lambda to run. * @param ticksLater The amount of ticks to wait before execution. * @return The created {@link BukkitTask}. */ @Override - public BukkitTask runLater(@NotNull final Callable callable, + public BukkitTask runLater(@NotNull final Runnable runnable, final long ticksLater) { - return Bukkit.getScheduler().runTaskLater(this.getPlugin(), callable::call, ticksLater); + return Bukkit.getScheduler().runTaskLater(this.getPlugin(), runnable, ticksLater); } /** * Run the task repeatedly on a timer. * - * @param callable The lambda to run. + * @param runnable The lambda to run. * @param delay The amount of ticks to wait before the first execution. * @param repeat The amount of ticks to wait between executions. * @return The created {@link BukkitTask}. */ @Override - public BukkitTask runTimer(@NotNull final Callable callable, + public BukkitTask runTimer(@NotNull final Runnable runnable, final long delay, final long repeat) { - return Bukkit.getScheduler().runTaskTimer(this.getPlugin(), callable::call, delay, repeat); + return Bukkit.getScheduler().runTaskTimer(this.getPlugin(), runnable, delay, repeat); } /** * Run the task repeatedly and asynchronously on a timer. * - * @param callable The lambda to run. + * @param runnable The lambda to run. * @param delay The amount of ticks to wait before the first execution. * @param repeat The amount of ticks to wait between executions. * @return The created {@link BukkitTask}. */ @Override - public BukkitTask runAsyncTimer(@NotNull final Callable callable, + public BukkitTask runAsyncTimer(@NotNull final Runnable runnable, final long delay, final long repeat) { - return Bukkit.getScheduler().runTaskTimerAsynchronously(this.getPlugin(), callable::call, delay, repeat); + return Bukkit.getScheduler().runTaskTimerAsynchronously(this.getPlugin(), runnable, delay, repeat); } /** @@ -76,12 +75,12 @@ public class EcoScheduler extends PluginDependent implements Scheduler { /** * Run the task asynchronously. * - * @param callable The lambda to run. + * @param runnable The lambda to run. * @return The created {@link BukkitTask}. */ @Override - public BukkitTask runAsync(@NotNull final Callable callable) { - return Bukkit.getScheduler().runTaskAsynchronously(this.getPlugin(), callable::call); + public BukkitTask runAsync(@NotNull final Runnable runnable) { + return Bukkit.getScheduler().runTaskAsynchronously(this.getPlugin(), runnable); } /** diff --git a/eco-util/src/main/java/com/willfp/eco/util/bukkit/scheduling/RunnableFactory.java b/eco-util/src/main/java/com/willfp/eco/util/bukkit/scheduling/RunnableFactory.java index d128fea3..1004dbda 100644 --- a/eco-util/src/main/java/com/willfp/eco/util/bukkit/scheduling/RunnableFactory.java +++ b/eco-util/src/main/java/com/willfp/eco/util/bukkit/scheduling/RunnableFactory.java @@ -1,10 +1,11 @@ package com.willfp.eco.util.bukkit.scheduling; import com.willfp.eco.util.factory.PluginDependentFactory; -import com.willfp.eco.util.lambda.InputCallable; import com.willfp.eco.util.plugin.AbstractEcoPlugin; import org.jetbrains.annotations.NotNull; +import java.util.function.Consumer; + public class RunnableFactory extends PluginDependentFactory { /** * Factory class to produce {@link EcoBukkitRunnable}s associated with an {@link AbstractEcoPlugin}. @@ -18,14 +19,14 @@ public class RunnableFactory extends PluginDependentFactory { /** * Create an {@link EcoBukkitRunnable}. * - * @param callable Lambda of the code to run, where the parameter represents the instance of the runnable. + * @param consumer Lambda of the code to run, where the parameter represents the instance of the runnable. * @return The created {@link EcoBukkitRunnable}. */ - public EcoBukkitRunnable create(@NotNull final InputCallable callable) { + public EcoBukkitRunnable create(@NotNull final Consumer consumer) { return new EcoBukkitRunnable(this.getPlugin()) { @Override public void run() { - callable.call(this); + consumer.accept(this); } }; } diff --git a/eco-util/src/main/java/com/willfp/eco/util/bukkit/scheduling/Scheduler.java b/eco-util/src/main/java/com/willfp/eco/util/bukkit/scheduling/Scheduler.java index 03fe68af..ae597b3c 100644 --- a/eco-util/src/main/java/com/willfp/eco/util/bukkit/scheduling/Scheduler.java +++ b/eco-util/src/main/java/com/willfp/eco/util/bukkit/scheduling/Scheduler.java @@ -1,6 +1,5 @@ package com.willfp.eco.util.bukkit.scheduling; -import com.willfp.eco.util.lambda.Callable; import com.willfp.eco.util.plugin.AbstractEcoPlugin; import org.bukkit.scheduler.BukkitTask; import org.jetbrains.annotations.NotNull; @@ -9,31 +8,31 @@ public interface Scheduler { /** * Run the task after a specified tick delay. * - * @param callable The lambda to run. + * @param runnable The lambda to run. * @param ticksLater The amount of ticks to wait before execution. * @return The created {@link BukkitTask}. */ - BukkitTask runLater(@NotNull Callable callable, long ticksLater); + BukkitTask runLater(@NotNull Runnable runnable, long ticksLater); /** * Run the task repeatedly on a timer. * - * @param callable The lambda to run. + * @param runnable The lambda to run. * @param delay The amount of ticks to wait before the first execution. * @param repeat The amount of ticks to wait between executions. * @return The created {@link BukkitTask}. */ - BukkitTask runTimer(@NotNull Callable callable, long delay, long repeat); + BukkitTask runTimer(@NotNull Runnable runnable, long delay, long repeat); /** * Run the task repeatedly and asynchronously on a timer. * - * @param callable The lambda to run. + * @param runnable The lambda to run. * @param delay The amount of ticks to wait before the first execution. * @param repeat The amount of ticks to wait between executions. * @return The created {@link BukkitTask}. */ - BukkitTask runAsyncTimer(@NotNull Callable callable, long delay, long repeat); + BukkitTask runAsyncTimer(@NotNull Runnable runnable, long delay, long repeat); /** * Run the task. @@ -46,10 +45,10 @@ public interface Scheduler { /** * Run the task asynchronously. * - * @param callable The lambda to run. + * @param runnable The lambda to run. * @return The created {@link BukkitTask}. */ - BukkitTask runAsync(@NotNull Callable callable); + BukkitTask runAsync(@NotNull Runnable runnable); /** * Schedule the task to be ran repeatedly on a timer. diff --git a/eco-util/src/main/java/com/willfp/eco/util/drops/telekinesis/EcoTelekinesisTests.java b/eco-util/src/main/java/com/willfp/eco/util/drops/telekinesis/EcoTelekinesisTests.java index ac283cbf..bf20ed47 100644 --- a/eco-util/src/main/java/com/willfp/eco/util/drops/telekinesis/EcoTelekinesisTests.java +++ b/eco-util/src/main/java/com/willfp/eco/util/drops/telekinesis/EcoTelekinesisTests.java @@ -1,17 +1,17 @@ package com.willfp.eco.util.drops.telekinesis; -import com.willfp.eco.util.lambda.ObjectInputCallable; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; import java.util.HashSet; import java.util.Set; +import java.util.function.Function; public class EcoTelekinesisTests implements TelekinesisTests { /** * Set of tests that return if the player is telekinetic. */ - private final Set> tests = new HashSet<>(); + private final Set> tests = new HashSet<>(); /** * Register a new test to check against. @@ -19,7 +19,7 @@ public class EcoTelekinesisTests implements TelekinesisTests { * @param test The test to register, where the boolean output is if the player is telekinetic. */ @Override - public void registerTest(@NotNull final ObjectInputCallable test) { + public void registerTest(@NotNull final Function test) { tests.add(test); } @@ -33,8 +33,8 @@ public class EcoTelekinesisTests implements TelekinesisTests { */ @Override public boolean testPlayer(@NotNull final Player player) { - for (ObjectInputCallable test : tests) { - if (test.call(player)) { + for (Function test : tests) { + if (test.apply(player)) { return true; } } diff --git a/eco-util/src/main/java/com/willfp/eco/util/drops/telekinesis/TelekinesisTests.java b/eco-util/src/main/java/com/willfp/eco/util/drops/telekinesis/TelekinesisTests.java index ad5ab5d0..b5c58475 100644 --- a/eco-util/src/main/java/com/willfp/eco/util/drops/telekinesis/TelekinesisTests.java +++ b/eco-util/src/main/java/com/willfp/eco/util/drops/telekinesis/TelekinesisTests.java @@ -1,16 +1,17 @@ package com.willfp.eco.util.drops.telekinesis; -import com.willfp.eco.util.lambda.ObjectInputCallable; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; +import java.util.function.Function; + public interface TelekinesisTests { /** * Register a new test to check against. * * @param test The test to register, where the boolean output is if the player is telekinetic. */ - void registerTest(@NotNull ObjectInputCallable test); + void registerTest(@NotNull Function test); /** * Test the player for telekinesis. diff --git a/eco-util/src/main/java/com/willfp/eco/util/integrations/IntegrationLoader.java b/eco-util/src/main/java/com/willfp/eco/util/integrations/IntegrationLoader.java index 3c4d5177..2b86a549 100644 --- a/eco-util/src/main/java/com/willfp/eco/util/integrations/IntegrationLoader.java +++ b/eco-util/src/main/java/com/willfp/eco/util/integrations/IntegrationLoader.java @@ -1,6 +1,5 @@ package com.willfp.eco.util.integrations; -import com.willfp.eco.util.lambda.Callable; import lombok.Getter; import org.jetbrains.annotations.NotNull; @@ -8,7 +7,7 @@ public class IntegrationLoader { /** * The lambda to be ran if the plugin is present. */ - private final Callable callable; + private final Runnable runnable; /** * The plugin to require to load the integration. @@ -23,8 +22,8 @@ public class IntegrationLoader { * @param onLoad The lambda to be ran if the plugin is present. */ public IntegrationLoader(@NotNull final String pluginName, - @NotNull final Callable onLoad) { - this.callable = onLoad; + @NotNull final Runnable onLoad) { + this.runnable = onLoad; this.pluginName = pluginName; } @@ -32,6 +31,6 @@ public class IntegrationLoader { * Load the integration. */ public void load() { - callable.call(); + runnable.run(); } } diff --git a/eco-util/src/main/java/com/willfp/eco/util/integrations/placeholder/PlaceholderEntry.java b/eco-util/src/main/java/com/willfp/eco/util/integrations/placeholder/PlaceholderEntry.java index 305d2b89..041adc02 100644 --- a/eco-util/src/main/java/com/willfp/eco/util/integrations/placeholder/PlaceholderEntry.java +++ b/eco-util/src/main/java/com/willfp/eco/util/integrations/placeholder/PlaceholderEntry.java @@ -1,12 +1,13 @@ package com.willfp.eco.util.integrations.placeholder; -import com.willfp.eco.util.lambda.ObjectInputCallable; import lombok.Getter; import org.apache.commons.lang.Validate; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.function.Function; + public class PlaceholderEntry { /** * The name of the placeholder, used in lookups. @@ -17,7 +18,7 @@ public class PlaceholderEntry { /** * The lambda to retrieve the output of the placeholder given a player. */ - private final ObjectInputCallable function; + private final Function function; /** * If the placeholder requires a player to lookup. @@ -31,7 +32,7 @@ public class PlaceholderEntry { * @param function A lambda to get the result of the placeholder given a player. */ public PlaceholderEntry(@NotNull final String identifier, - @NotNull final ObjectInputCallable function) { + @NotNull final Function function) { this(identifier, function, false); } @@ -43,7 +44,7 @@ public class PlaceholderEntry { * @param requiresPlayer If the placeholder requires a player. */ public PlaceholderEntry(@NotNull final String identifier, - @NotNull final ObjectInputCallable function, + @NotNull final Function function, final boolean requiresPlayer) { this.identifier = identifier; this.function = function; @@ -60,7 +61,7 @@ public class PlaceholderEntry { if (player == null) { Validate.isTrue(!requiresPlayer, "null player passed to requiresPlayer placeholder."); } - return this.function.call(player); + return this.function.apply(player); } /** diff --git a/eco-util/src/main/java/com/willfp/eco/util/lambda/Callable.java b/eco-util/src/main/java/com/willfp/eco/util/lambda/Callable.java deleted file mode 100644 index e7fbdec3..00000000 --- a/eco-util/src/main/java/com/willfp/eco/util/lambda/Callable.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.willfp.eco.util.lambda; - -/** - * Represents code that can be later executed. - */ -@FunctionalInterface -public interface Callable { - /** - * Execute the lambda. - */ - void call(); -} diff --git a/eco-util/src/main/java/com/willfp/eco/util/lambda/InputCallable.java b/eco-util/src/main/java/com/willfp/eco/util/lambda/InputCallable.java deleted file mode 100644 index 3e55bbf6..00000000 --- a/eco-util/src/main/java/com/willfp/eco/util/lambda/InputCallable.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.willfp.eco.util.lambda; - -/** - * Functional Interface that requires an object as a parameter. - * - * @param The type of the object to require. - */ -@FunctionalInterface -public interface InputCallable { - /** - * Execute the lambda. - * - * @param object The lambda parameter. - */ - void call(A object); -} diff --git a/eco-util/src/main/java/com/willfp/eco/util/lambda/ObjectCallable.java b/eco-util/src/main/java/com/willfp/eco/util/lambda/ObjectCallable.java deleted file mode 100644 index 1599a872..00000000 --- a/eco-util/src/main/java/com/willfp/eco/util/lambda/ObjectCallable.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.willfp.eco.util.lambda; - -/** - * Functional Interface to return a value of a given type. - * - * @param The type to return. - */ -@FunctionalInterface -public interface ObjectCallable { - /** - * Execute the lambda. - * - * @return The return value of the specified type. - */ - A call(); -} diff --git a/eco-util/src/main/java/com/willfp/eco/util/lambda/ObjectInputCallable.java b/eco-util/src/main/java/com/willfp/eco/util/lambda/ObjectInputCallable.java deleted file mode 100644 index 674c981e..00000000 --- a/eco-util/src/main/java/com/willfp/eco/util/lambda/ObjectInputCallable.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.willfp.eco.util.lambda; - -/** - * Functional Interface to return a value of a specified type given a certain parameter. - * - * @param The type of object to return - * @param The type of object for the parameter - */ -@FunctionalInterface -public interface ObjectInputCallable { - /** - * Execute the lambda. - * - * @param object The lambda parameter. - * @return The required return type. - */ - A call(B object); -} diff --git a/eco-util/src/main/java/com/willfp/eco/util/optional/Prerequisite.java b/eco-util/src/main/java/com/willfp/eco/util/optional/Prerequisite.java index fe581904..8b7bc6da 100644 --- a/eco-util/src/main/java/com/willfp/eco/util/optional/Prerequisite.java +++ b/eco-util/src/main/java/com/willfp/eco/util/optional/Prerequisite.java @@ -1,7 +1,6 @@ package com.willfp.eco.util.optional; import com.willfp.eco.util.ClassUtils; -import com.willfp.eco.util.lambda.ObjectCallable; import lombok.Getter; import org.bukkit.Bukkit; import org.jetbrains.annotations.NotNull; @@ -9,6 +8,7 @@ import org.jetbrains.annotations.NotNull; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.function.Supplier; public class Prerequisite { /** @@ -41,7 +41,7 @@ public class Prerequisite { /** * Retrieve if the necessary prerequisite condition is met. */ - private final ObjectCallable isMetCallable; + private final Supplier isMetSupplier; /** * The description of the requirements of the prerequisite. @@ -52,22 +52,22 @@ public class Prerequisite { /** * Create a prerequisite. * - * @param isMetCallable An {@link ObjectCallable} that returns if the prerequisite is met + * @param isMetSupplier An {@link Supplier} that returns if the prerequisite is met * @param description The description of the prerequisite, shown to the user if it isn't */ - public Prerequisite(@NotNull final ObjectCallable isMetCallable, + public Prerequisite(@NotNull final Supplier isMetSupplier, @NotNull final String description) { - this.isMetCallable = isMetCallable; - this.isMet = isMetCallable.call(); + this.isMetSupplier = isMetSupplier; + this.isMet = isMetSupplier.get(); this.description = description; VALUES.add(this); } /** - * Refresh the condition set in the callable, updates {@link this#isMet}. + * Refresh the condition set in the supplier, updates {@link this#isMet}. */ private void refresh() { - this.isMet = this.isMetCallable.call(); + this.isMet = this.isMetSupplier.get(); } /**