-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
205 additions
and
112 deletions.
There are no files selected for viewing
36 changes: 1 addition & 35 deletions
36
...framework-api/src/main/java/me/devnatan/inventoryframework/component/ComponentHandle.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,6 @@ | ||
package me.devnatan.inventoryframework.component; | ||
|
||
import me.devnatan.inventoryframework.VirtualView; | ||
import me.devnatan.inventoryframework.context.IFComponentContext; | ||
import me.devnatan.inventoryframework.context.IFComponentRenderContext; | ||
import me.devnatan.inventoryframework.context.IFComponentUpdateContext; | ||
import me.devnatan.inventoryframework.context.IFSlotClickContext; | ||
import me.devnatan.inventoryframework.pipeline.PipelineInterceptor; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public abstract class ComponentHandle implements PipelineInterceptor<VirtualView> { | ||
|
||
/** | ||
* Renders this component to the given context. | ||
* | ||
* @param context The context that this component will be rendered on. | ||
*/ | ||
void rendered(@NotNull IFComponentRenderContext context) {} | ||
|
||
/** | ||
* Called when this component is updated in the given context. | ||
* | ||
* @param context The update context. | ||
*/ | ||
void updated(@NotNull IFComponentUpdateContext context) {} | ||
|
||
/** | ||
* Clears this component from the given context. | ||
* | ||
* @param context The context that this component will be cleared from. | ||
*/ | ||
public void cleared(@NotNull IFComponentContext context) {} | ||
|
||
/** | ||
* Called when a viewer clicks in that component. | ||
* | ||
* @param context The click context. | ||
*/ | ||
void clicked(@NotNull IFSlotClickContext context) {} | ||
} | ||
public abstract class ComponentHandle implements PipelineInterceptor<VirtualView> {} |
14 changes: 14 additions & 0 deletions
14
...ork-api/src/main/java/me/devnatan/inventoryframework/context/IFComponentClearContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package me.devnatan.inventoryframework.context; | ||
|
||
import me.devnatan.inventoryframework.ViewContainer; | ||
|
||
public interface IFComponentClearContext extends IFComponentContext, IFConfinedContext { | ||
|
||
IFRenderContext getParent(); | ||
|
||
ViewContainer getContainer(); | ||
|
||
boolean isCancelled(); | ||
|
||
void setCancelled(boolean cancelled); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 32 additions & 8 deletions
40
...-bukkit/src/main/java/me/devnatan/inventoryframework/component/BukkitComponentHandle.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,53 @@ | ||
package me.devnatan.inventoryframework.component; | ||
|
||
import java.util.Objects; | ||
import me.devnatan.inventoryframework.VirtualView; | ||
import me.devnatan.inventoryframework.context.ComponentClearContext; | ||
import me.devnatan.inventoryframework.context.ComponentRenderContext; | ||
import me.devnatan.inventoryframework.context.ComponentUpdateContext; | ||
import me.devnatan.inventoryframework.context.Context; | ||
import me.devnatan.inventoryframework.context.RenderContext; | ||
import me.devnatan.inventoryframework.context.SlotClickContext; | ||
import me.devnatan.inventoryframework.pipeline.PipelineContext; | ||
import me.devnatan.inventoryframework.pipeline.PipelinePhase; | ||
|
||
public abstract class BukkitComponentHandle<T> extends AbstractComponentHandle<Context, T> { | ||
public abstract class BukkitComponentHandle<T> extends PlatformComponentHandle<Context, T> { | ||
|
||
/** | ||
* Renders the component in the given context. | ||
* | ||
* @param context The context that this component will be rendered on. | ||
*/ | ||
protected abstract void rendered(ComponentRenderContext context); | ||
|
||
/** | ||
* Called when the component is updated in the given context. | ||
* | ||
* @param context The update context. | ||
*/ | ||
protected void updated(ComponentUpdateContext context) {} | ||
|
||
// TODO Create ComponentClearContext | ||
protected void cleared(RenderContext context) {} | ||
/** | ||
* Called when the component is cleared from the given context. | ||
* | ||
* @param context The context that this component will be cleared from. | ||
*/ | ||
protected void cleared(ComponentClearContext context) {} | ||
|
||
/** | ||
* Called when a viewer clicks in the component. | ||
* | ||
* @param context The click context. | ||
*/ | ||
protected void clicked(SlotClickContext context) {} | ||
|
||
@Override | ||
public final void intercept(PipelineContext<VirtualView> pipeline, VirtualView subject) { | ||
if (pipeline.getPhase() == Component.RENDER) rendered((ComponentRenderContext) subject); | ||
if (pipeline.getPhase() == Component.UPDATE) updated((ComponentUpdateContext) subject); | ||
if (pipeline.getPhase() == Component.CLICK) clicked((SlotClickContext) subject); | ||
if (pipeline.getPhase() == Component.CLEAR) cleared((RenderContext) subject); | ||
final PipelinePhase phase = Objects.requireNonNull( | ||
pipeline.getPhase(), "Pipeline phase cannot be null in ComponentHandle interceptor"); | ||
|
||
if (phase == Component.RENDER) rendered((ComponentRenderContext) subject); | ||
if (phase == Component.UPDATE) updated((ComponentUpdateContext) subject); | ||
if (phase == Component.CLEAR) cleared((ComponentClearContext) subject); | ||
if (phase == Component.CLICK) clicked((SlotClickContext) subject); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.