From 95e719d8f66a431509ad9f85d171d05f257bb8ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hasan=20Demirta=C5=9F?= Date: Mon, 30 Sep 2024 20:38:57 +0300 Subject: [PATCH] update. --- .../java/net/infumia/frame/element/Element.java | 6 ++++++ .../pipeline/executor/PipelineExecutorFrame.java | 5 +---- .../net/infumia/frame/element/ElementImpl.java | 8 ++++++++ .../net/infumia/frame/element/ElementItemImpl.java | 14 ++++++++++++++ .../element/pagination/ElementPaginationImpl.java | 12 ++++++++++++ .../service/frame/ServiceListenerRegistered.java | 5 ++--- .../frame/ServiceListenerRegisteredLogging.java | 5 ++--- .../service/render/ServiceUpdateLogging.java | 6 +----- .../frame/state/value/StateValueHostImpl.java | 4 +--- 9 files changed, 47 insertions(+), 18 deletions(-) diff --git a/common/src/main/java/net/infumia/frame/element/Element.java b/common/src/main/java/net/infumia/frame/element/Element.java index 3b4afad..dd52a17 100644 --- a/common/src/main/java/net/infumia/frame/element/Element.java +++ b/common/src/main/java/net/infumia/frame/element/Element.java @@ -1,9 +1,12 @@ package net.infumia.frame.element; import java.util.Collection; +import java.util.concurrent.CompletableFuture; import java.util.function.Predicate; import net.infumia.frame.context.view.ContextRender; +import net.infumia.frame.service.ConsumerService; import net.infumia.frame.state.State; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; public interface Element { @@ -21,4 +24,7 @@ public interface Element { @Nullable Collection> updateOnStateAccess(); + + @NotNull + CompletableFuture update(); } diff --git a/common/src/main/java/net/infumia/frame/pipeline/executor/PipelineExecutorFrame.java b/common/src/main/java/net/infumia/frame/pipeline/executor/PipelineExecutorFrame.java index 4794cc5..eb28d29 100644 --- a/common/src/main/java/net/infumia/frame/pipeline/executor/PipelineExecutorFrame.java +++ b/common/src/main/java/net/infumia/frame/pipeline/executor/PipelineExecutorFrame.java @@ -31,10 +31,7 @@ CompletableFuture executeViewUnregistered( ); void applyViewCreated( - @NotNull Implementation< - PipelineContextFrame.ViewCreated, - Collection - > implementation + @NotNull Implementation> implementation ); void applyViewRegistered( diff --git a/core/src/main/java/net/infumia/frame/element/ElementImpl.java b/core/src/main/java/net/infumia/frame/element/ElementImpl.java index d7e285a..49be07d 100644 --- a/core/src/main/java/net/infumia/frame/element/ElementImpl.java +++ b/core/src/main/java/net/infumia/frame/element/ElementImpl.java @@ -2,10 +2,12 @@ import java.util.Collection; import java.util.UUID; +import java.util.concurrent.CompletableFuture; import java.util.function.Predicate; import net.infumia.frame.context.ContextBase; import net.infumia.frame.context.view.ContextRender; import net.infumia.frame.pipeline.executor.PipelineExecutorElement; +import net.infumia.frame.service.ConsumerService; import net.infumia.frame.state.State; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -114,6 +116,12 @@ public Collection> updateOnStateAccess() { return this.updateOnStateAccess; } + @NotNull + @Override + public CompletableFuture update() { + throw new UnsupportedOperationException("This element cannot be updated!"); + } + @Override public String key() { return this.key; diff --git a/core/src/main/java/net/infumia/frame/element/ElementItemImpl.java b/core/src/main/java/net/infumia/frame/element/ElementItemImpl.java index 7907ace..1dd6a87 100644 --- a/core/src/main/java/net/infumia/frame/element/ElementItemImpl.java +++ b/core/src/main/java/net/infumia/frame/element/ElementItemImpl.java @@ -1,12 +1,15 @@ package net.infumia.frame.element; +import java.util.concurrent.CompletableFuture; import java.util.function.Consumer; import net.infumia.frame.context.ContextBase; import net.infumia.frame.context.element.ContextElementItemClick; import net.infumia.frame.context.element.ContextElementItemRender; import net.infumia.frame.context.element.ContextElementItemUpdate; +import net.infumia.frame.context.view.ContextRender; import net.infumia.frame.pipeline.executor.PipelineExecutorElement; import net.infumia.frame.pipeline.executor.PipelineExecutorElementImpl; +import net.infumia.frame.service.ConsumerService; import net.infumia.frame.util.Preconditions; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; @@ -88,6 +91,17 @@ public ElementItemBuilderRich toBuilder() { return new ElementItemBuilderImpl(this); } + @NotNull + @Override + public CompletableFuture update() { + Preconditions.state( + this.parent instanceof ContextRender, + "You cannot update the element '%s' when the parent is not a ContextRender!", + this + ); + return this.pipelines.executeUpdate((ContextRender) this.parent, false); + } + @NotNull @Override public PipelineExecutorElement pipelines() { diff --git a/core/src/main/java/net/infumia/frame/element/pagination/ElementPaginationImpl.java b/core/src/main/java/net/infumia/frame/element/pagination/ElementPaginationImpl.java index 2ad9d8f..74233ef 100644 --- a/core/src/main/java/net/infumia/frame/element/pagination/ElementPaginationImpl.java +++ b/core/src/main/java/net/infumia/frame/element/pagination/ElementPaginationImpl.java @@ -24,6 +24,7 @@ import net.infumia.frame.extension.CompletableFutureExtensions; import net.infumia.frame.pipeline.executor.PipelineExecutorElement; import net.infumia.frame.pipeline.executor.PipelineExecutorElementImpl; +import net.infumia.frame.service.ConsumerService; import net.infumia.frame.slot.LayoutSlot; import net.infumia.frame.state.State; import net.infumia.frame.state.StateRich; @@ -321,6 +322,17 @@ public ElementPaginationBuilderRich toBuilder() { return new ElementPaginationBuilderImpl<>(this); } + @NotNull + @Override + public CompletableFuture update() { + Preconditions.state( + this.parent() instanceof ContextRender, + "You cannot update the element '%s' when the parent is not a ContextRender!", + this + ); + return this.pipelines.executeUpdate((ContextRender) this.parent(), false); + } + @NotNull @Override public PipelineExecutorElement pipelines() { diff --git a/core/src/main/java/net/infumia/frame/pipeline/service/frame/ServiceListenerRegistered.java b/core/src/main/java/net/infumia/frame/pipeline/service/frame/ServiceListenerRegistered.java index 497f7e4..bab46ca 100644 --- a/core/src/main/java/net/infumia/frame/pipeline/service/frame/ServiceListenerRegistered.java +++ b/core/src/main/java/net/infumia/frame/pipeline/service/frame/ServiceListenerRegistered.java @@ -8,9 +8,8 @@ public final class ServiceListenerRegistered implements PipelineServiceConsumer { - public static final PipelineServiceConsumer< - PipelineContextFrame.ListenerRegistered - > INSTANCE = new ServiceListenerRegistered(); + public static final PipelineServiceConsumer INSTANCE = + new ServiceListenerRegistered(); public static final String KEY = "register"; diff --git a/core/src/main/java/net/infumia/frame/pipeline/service/frame/ServiceListenerRegisteredLogging.java b/core/src/main/java/net/infumia/frame/pipeline/service/frame/ServiceListenerRegisteredLogging.java index d1424ed..2cf7355 100644 --- a/core/src/main/java/net/infumia/frame/pipeline/service/frame/ServiceListenerRegisteredLogging.java +++ b/core/src/main/java/net/infumia/frame/pipeline/service/frame/ServiceListenerRegisteredLogging.java @@ -7,9 +7,8 @@ public final class ServiceListenerRegisteredLogging implements PipelineServiceConsumer { - public static final PipelineServiceConsumer< - PipelineContextFrame.ListenerRegistered - > INSTANCE = new ServiceListenerRegisteredLogging(); + public static final PipelineServiceConsumer INSTANCE = + new ServiceListenerRegisteredLogging(); public static final String KEY = "logging"; diff --git a/core/src/main/java/net/infumia/frame/pipeline/service/render/ServiceUpdateLogging.java b/core/src/main/java/net/infumia/frame/pipeline/service/render/ServiceUpdateLogging.java index 4346433..49bf33c 100644 --- a/core/src/main/java/net/infumia/frame/pipeline/service/render/ServiceUpdateLogging.java +++ b/core/src/main/java/net/infumia/frame/pipeline/service/render/ServiceUpdateLogging.java @@ -20,11 +20,7 @@ public String key() { @Override public void accept(@NotNull final PipelineContextRender.Update ctx) { // TODO: portlek, More detailed message. - ctx - .context() - .frame() - .logger() - .debug("View '%s' updated.", ctx.context().view().instance()); + ctx.context().frame().logger().debug("View '%s' updated.", ctx.context().view().instance()); } private ServiceUpdateLogging() {} diff --git a/core/src/main/java/net/infumia/frame/state/value/StateValueHostImpl.java b/core/src/main/java/net/infumia/frame/state/value/StateValueHostImpl.java index acd9a30..a7d55cb 100644 --- a/core/src/main/java/net/infumia/frame/state/value/StateValueHostImpl.java +++ b/core/src/main/java/net/infumia/frame/state/value/StateValueHostImpl.java @@ -216,9 +216,7 @@ public void initializeState( @NotNull final StateValue value ) { this.values.put((StateRich) state, (StateValue) value); - this.context.frame() - .logger() - .debug("State '%s' initialized with value '%s'", state, value); + this.context.frame().logger().debug("State '%s' initialized with value '%s'", state, value); } @NotNull