Skip to content

Commit

Permalink
fix: Misc optimizations + Deprecating plugin task recipe API
Browse files Browse the repository at this point in the history
  • Loading branch information
phinner committed Dec 20, 2023
1 parent 9185a97 commit 347cf4d
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,10 @@ public final AnnotationParser<C> createAnnotationParser(final Class<C> type) {
* @param value the initial value of the recipe, usually a {@link cloud.commandframework.context.CommandContext
* command context}
* @return the created recipe
* @deprecated see {@link fr.xpdustry.distributor.api.scheduler.PluginScheduler#recipe(MindustryPlugin, Object)}
*/
@SuppressWarnings("removal")
@Deprecated
public final <V> PluginTaskRecipe<V> recipe(final V value) {
return DistributorProvider.get().getPluginScheduler().recipe(this.plugin, value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
public interface LocalizationSource {

/**
* Returns a {@code LocalizationSource} for the router language :^).
* Returns a {@code LocalizationSource} for the router language {@code :^)}.
*/
static LocalizationSource router() {
return RouterLocalizationSource.INSTANCE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ public interface PluginScheduler {
* @param plugin the plugin to schedule the task for.
* @param value the initial value.
* @return a new {@link PluginTaskRecipe} instance.
* @deprecated The recipe API is awful given the better alternatives such as completable futures, coroutines,
* or even the structured concurrency API of java 21.
*/
@Deprecated(forRemoval = true)
<V> PluginTaskRecipe<V> recipe(final MindustryPlugin plugin, final V value);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import java.util.function.Consumer;
import java.util.function.Function;

public final class RecipePluginTask<V> implements ScheduledPluginTask<V> {
final class RecipePluginTask<V> implements ScheduledPluginTask<V> {

private final SimplePluginScheduler scheduler;
private final MindustryPlugin plugin;
Expand Down Expand Up @@ -116,7 +116,7 @@ public long getNextExecutionTime() {
return 0L;
}

private abstract static sealed class RecipeStep<T, R> implements Function<T, R> {
abstract static sealed class RecipeStep<T, R> implements Function<T, R> {

public final boolean async;

Expand All @@ -125,7 +125,7 @@ private RecipeStep(final boolean async) {
}
}

private static final class ConsumerRecipeStep<T> extends RecipeStep<T, T> {
static final class ConsumerRecipeStep<T> extends RecipeStep<T, T> {

private final Consumer<T> consumer;

Expand All @@ -141,7 +141,7 @@ public T apply(final T object) {
}
}

private static final class FunctionRecipeStep<T, R> extends RecipeStep<T, R> {
static final class FunctionRecipeStep<T, R> extends RecipeStep<T, R> {

private final Function<T, R> function;

Expand All @@ -156,7 +156,7 @@ public R apply(final T object) {
}
}

private static final class RunnableRecipeStep<T> extends RecipeStep<T, T> {
static final class RunnableRecipeStep<T> extends RecipeStep<T, T> {

private final Runnable runnable;

Expand All @@ -172,7 +172,7 @@ public T apply(final T object) {
}
}

public static final class Builder<V> implements PluginTaskRecipe<V> {
static final class Builder<V> implements PluginTaskRecipe<V> {

private final SimplePluginScheduler scheduler;
private final MindustryPlugin plugin;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public PluginTaskBuilder scheduleSync(final MindustryPlugin plugin) {
return new SimplePluginTask.Builder(this, plugin, false);
}

@SuppressWarnings("removal")
@Override
public <V> PluginTaskRecipe<V> recipe(final MindustryPlugin plugin, final V value) {
return new RecipePluginTask.Builder<>(this, plugin, value, new ArrayList<>());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public void setPermission(final String permission, final Tristate state) {
}
node.value = state;
var index = parts.length - 1;
while (node.parent != null && node.children.size() == 0) {
while (node.parent != null && node.children.isEmpty()) {
node = node.parent;
node.children.remove(parts[index--]);
}
Expand Down

0 comments on commit 347cf4d

Please sign in to comment.