Skip to content

Commit

Permalink
update.
Browse files Browse the repository at this point in the history
  • Loading branch information
portlek committed Sep 30, 2024
1 parent 687d9e6 commit 95e719d
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 18 deletions.
6 changes: 6 additions & 0 deletions common/src/main/java/net/infumia/frame/element/Element.java
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -21,4 +24,7 @@ public interface Element {

@Nullable
Collection<State<?>> updateOnStateAccess();

@NotNull
CompletableFuture<ConsumerService.State> update();
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@ CompletableFuture<ConsumerService.State> executeViewUnregistered(
);

void applyViewCreated(
@NotNull Implementation<
PipelineContextFrame.ViewCreated,
Collection<Object>
> implementation
@NotNull Implementation<PipelineContextFrame.ViewCreated, Collection<Object>> implementation
);

void applyViewRegistered(
Expand Down
8 changes: 8 additions & 0 deletions core/src/main/java/net/infumia/frame/element/ElementImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -114,6 +116,12 @@ public Collection<State<?>> updateOnStateAccess() {
return this.updateOnStateAccess;
}

@NotNull
@Override
public CompletableFuture<ConsumerService.State> update() {
throw new UnsupportedOperationException("This element cannot be updated!");
}

@Override
public String key() {
return this.key;
Expand Down
14 changes: 14 additions & 0 deletions core/src/main/java/net/infumia/frame/element/ElementItemImpl.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -88,6 +91,17 @@ public ElementItemBuilderRich toBuilder() {
return new ElementItemBuilderImpl(this);
}

@NotNull
@Override
public CompletableFuture<ConsumerService.State> 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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -321,6 +322,17 @@ public ElementPaginationBuilderRich<T> toBuilder() {
return new ElementPaginationBuilderImpl<>(this);
}

@NotNull
@Override
public CompletableFuture<ConsumerService.State> 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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@
public final class ServiceListenerRegistered
implements PipelineServiceConsumer<PipelineContextFrame.ListenerRegistered> {

public static final PipelineServiceConsumer<
PipelineContextFrame.ListenerRegistered
> INSTANCE = new ServiceListenerRegistered();
public static final PipelineServiceConsumer<PipelineContextFrame.ListenerRegistered> INSTANCE =
new ServiceListenerRegistered();

public static final String KEY = "register";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
public final class ServiceListenerRegisteredLogging
implements PipelineServiceConsumer<PipelineContextFrame.ListenerRegistered> {

public static final PipelineServiceConsumer<
PipelineContextFrame.ListenerRegistered
> INSTANCE = new ServiceListenerRegisteredLogging();
public static final PipelineServiceConsumer<PipelineContextFrame.ListenerRegistered> INSTANCE =
new ServiceListenerRegisteredLogging();

public static final String KEY = "logging";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,7 @@ public <T> void initializeState(
@NotNull final StateValue<T> value
) {
this.values.put((StateRich<Object>) state, (StateValue<Object>) 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
Expand Down

0 comments on commit 95e719d

Please sign in to comment.