Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package me.devnatan.inventoryframework.runtime.command
import me.devnatan.inventoryframework.ViewFrame
import me.devnatan.inventoryframework.runtime.view.Failing
import me.devnatan.inventoryframework.runtime.view.ScheduledView
import me.devnatan.inventoryframework.runtime.view.ScheduledViewAdvanced
import me.devnatan.inventoryframework.runtime.view.SimplePagination
import net.minestom.server.command.CommandSender
import net.minestom.server.command.builder.Command
Expand All @@ -20,6 +21,7 @@ class IFExampleCommand(
"failing" to Failing::class.java,
"simple-pagination" to SimplePagination::class.java,
"scheduled" to ScheduledView::class.java,
"scheduled-advanced" to ScheduledViewAdvanced::class.java,
)

private val arg: Argument<String> =
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package me.devnatan.inventoryframework.runtime.view

import me.devnatan.inventoryframework.View
import me.devnatan.inventoryframework.ViewConfigBuilder
import me.devnatan.inventoryframework.context.Context
import me.devnatan.inventoryframework.context.RenderContext
import me.devnatan.inventoryframework.context.SlotClickContext
import me.devnatan.inventoryframework.runtime.ExampleUtil
import me.devnatan.inventoryframework.state.timerState
import net.minestom.server.item.Material
import kotlin.time.Duration.Companion.seconds

class ScheduledViewAdvanced : View() {
val counter = mutableState(0)
val timer = timerState(1.seconds)

override fun onInit(config: ViewConfigBuilder): Unit =
with(config) {
cancelOnClick()
size(3)
title("Simple Pagination")
layout(" ", " C ", "B ")
scheduleUpdate(timer)
}

override fun onFirstRender(render: RenderContext) {
render.layoutSlot('C').onRender {
it.item = ExampleUtil.displayItem(Material.STONE, counter.increment(it).toString())
}

render
.layoutSlot('B', ExampleUtil.displayItem(Material.PAPER, "Back"))
.displayIf(Context::canBack)
.onClick(SlotClickContext::back)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import me.devnatan.inventoryframework.ViewFrame;
import me.devnatan.inventoryframework.runtime.commands.IFExampleCommandExecutor;
import me.devnatan.inventoryframework.runtime.listener.PigListener;
import me.devnatan.inventoryframework.runtime.view.*;
import me.devnatan.inventoryframework.runtime.view.AnvilInputSample;
import me.devnatan.inventoryframework.runtime.view.AutoUpdate;
import me.devnatan.inventoryframework.runtime.view.Failing;
Expand All @@ -17,7 +18,12 @@ public void onEnable() {
System.out.println("ligoo");
ViewFrame viewFrame = ViewFrame.create(this)
.install(AnvilInputFeature.AnvilInput)
.with(new AnvilInputSample(), new Failing(), new SimplePagination(), new AutoUpdate())
.with(
new AnvilInputSample(),
new Failing(),
new SimplePagination(),
new AutoUpdate(),
new AutoUpdateAdvanced())
.register();

getCommand("ifexample").setExecutor(new IFExampleCommandExecutor(viewFrame));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package me.devnatan.inventoryframework.runtime.commands;

import me.devnatan.inventoryframework.ViewFrame;
import me.devnatan.inventoryframework.runtime.view.AnvilInputSample;
import me.devnatan.inventoryframework.runtime.view.AutoUpdate;
import me.devnatan.inventoryframework.runtime.view.Failing;
import me.devnatan.inventoryframework.runtime.view.SimplePagination;
import me.devnatan.inventoryframework.runtime.view.*;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
Expand Down Expand Up @@ -60,6 +57,11 @@ public boolean onCommand(
return true;
}

if (view.equalsIgnoreCase("auto-update-advanced")) {
viewFrame.open(AutoUpdateAdvanced.class, player);
return true;
}

commandSender.sendMessage("Unknown view: " + view);
return true;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package me.devnatan.inventoryframework.runtime.view;

import me.devnatan.inventoryframework.View;
import me.devnatan.inventoryframework.ViewConfigBuilder;
import me.devnatan.inventoryframework.context.Context;
import me.devnatan.inventoryframework.context.RenderContext;
import me.devnatan.inventoryframework.state.MutableIntState;
import me.devnatan.inventoryframework.state.TimerState;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;

public class AutoUpdateAdvanced extends View {

private final MutableIntState countState = mutableState(0);
private final TimerState autoUpdateState = timerState(10);

@Override
public void onInit(@NotNull ViewConfigBuilder config) {
config.cancelOnClick().title("Auto update (?)").scheduleUpdate(autoUpdateState);
}

@Override
public void onFirstRender(@NotNull RenderContext render) {
render.slot(1, new ItemStack(Material.DIAMOND)).onClick(click -> click.openForPlayer(SimplePagination.class));

render.slot(2, new ItemStack(Material.CLOCK)).onClick(click -> {
final var timer = autoUpdateState.get(click);
timer.togglePause();
});
}

@Override
public void onUpdate(@NotNull Context update) {
final int count = countState.increment(update);
final String pause = autoUpdateState.get(update).isPaused() ? "paused" : "running";
update.updateTitleForPlayer(String.format("Auto update (%d) [%b]", count, pause));
}
}
5 changes: 5 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ plugin-shadowjar = "8.3.7"
plugin-spotless = "7.0.4"
plugin-bukkit = "0.7.1"
minestom = "b39badc77b"
folialib = "0.5.1"

[libraries.spigot]
module = "org.spigotmc:spigot-api"
Expand Down Expand Up @@ -52,6 +53,10 @@ version.ref = "adventure-api"
module = "net.minestom:minestom-snapshots"
version.ref = "minestom"

[libraries.folialib]
module = "com.tcoded:FoliaLib"
version.ref = "folialib"

[plugins]
shadowjar = { id = "com.gradleup.shadow", version.ref = "plugin-shadowjar" }
spotless = { id = "com.diffplug.spotless", version.ref = "plugin-spotless" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.util.Set;
import java.util.stream.Collectors;
import me.devnatan.inventoryframework.exception.InvalidLayoutException;
import me.devnatan.inventoryframework.state.TimerState;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;

Expand All @@ -31,6 +32,7 @@ public final class ViewConfigBuilder {
private String[] layout = null;
private final Set<ViewConfig.Modifier> modifiers = new HashSet<>();
private long updateIntervalInTicks, interactionDelayInMillis;
private TimerState updateIntervalState;
private boolean transitiveInitialData;

/**
Expand Down Expand Up @@ -200,6 +202,19 @@ public ViewConfigBuilder scheduleUpdate(long intervalInTicks) {
return this;
}

/**
* Schedules the view to update every fixed interval.
*
* @param timerState The
* @return This configuration builder.
* @see <a href="https://github.com/DevNatan/inventory-framework/wiki/scheduled-updates">Scheduled Updates on Wiki</a>
*/
@ApiStatus.Experimental
public ViewConfigBuilder scheduleUpdate(TimerState timerState) {
this.updateIntervalState = timerState;
return this;
}

/**
* Waits a fixed delay before any player interaction.
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,99 +13,99 @@
*/
public interface IFSlotClickContext extends IFSlotContext, IFConfinedContext {

// TODO needs documentation
@NotNull
ViewContainer getClickedContainer();

Component getComponent();

int getClickedSlot();

/**
* If the click was using the left mouse button.
*
* @return If the click was using the left mouse button.
*/
boolean isLeftClick();

/**
* If the click was using the right mouse button.
*
* @return If the click was using the right mouse button.
*/
boolean isRightClick();

/**
* If the click was using the middle mouse button, commonly known as the scroll button.
*
* @return If the click was using the middle mouse button.
*/
boolean isMiddleClick();

/**
* If the click was accompanied by a click holding the keyboard shift button.
*
* @return If it was a click holding the keyboard shift button.
*/
boolean isShiftClick();

default boolean isShiftLeftClick() {
return isLeftClick() && isShiftClick();
}

default boolean isShiftRightClick() {
return isRightClick() && isShiftClick();
}

/**
* If the click source came from a keyboard, e.g. the player's toolbar number.
*
* @return If the click source came from a keyboard.
*/
boolean isKeyboardClick();

/**
* If the click did not occur within any containers.
*
* @return If the click did not occur within any containers.
*/
boolean isOutsideClick();

/**
* The click identifier, available only in cases where the library does not cover all types of
* clicks, so you can discover the type of click through its identifier.
*
* @return The click type identifier. Can be null if the click type is known or a platform doesn't implement an identifier.
*/
default String getClickIdentifier() {
return null;
}

/**
* If the click was cancelled.
*
* @return If the click was cancelled.
*/
boolean isCancelled();

/**
* Cancels the click.
*
* @param cancelled If the click should be cancelled.
*/
void setCancelled(boolean cancelled);

/**
* <b><i> This is an internal inventory-framework API that should not be used from outside of
* this library. No compatibility guarantees are provided. </i></b>
*/
@ApiStatus.Internal
Object getPlatformEvent();

/**
* <b><i> This is an internal inventory-framework API that should not be used from outside of
* this library. No compatibility guarantees are provided. </i></b>
*/
@ApiStatus.Internal
boolean isCombined();
// TODO needs documentation
@NotNull
ViewContainer getClickedContainer();

Component getComponent();

int getClickedSlot();

/**
* If the click was using the left mouse button.
*
* @return If the click was using the left mouse button.
*/
boolean isLeftClick();

/**
* If the click was using the right mouse button.
*
* @return If the click was using the right mouse button.
*/
boolean isRightClick();

/**
* If the click was using the middle mouse button, commonly known as the scroll button.
*
* @return If the click was using the middle mouse button.
*/
boolean isMiddleClick();

/**
* If the click was accompanied by a click holding the keyboard shift button.
*
* @return If it was a click holding the keyboard shift button.
*/
boolean isShiftClick();

default boolean isShiftLeftClick() {
return isLeftClick() && isShiftClick();
}

default boolean isShiftRightClick() {
return isRightClick() && isShiftClick();
}

/**
* If the click source came from a keyboard, e.g. the player's toolbar number.
*
* @return If the click source came from a keyboard.
*/
boolean isKeyboardClick();

/**
* If the click did not occur within any containers.
*
* @return If the click did not occur within any containers.
*/
boolean isOutsideClick();

/**
* The click identifier, available only in cases where the library does not cover all types of
* clicks, so you can discover the type of click through its identifier.
*
* @return The click type identifier. Can be null if the click type is known or a platform doesn't implement an identifier.
*/
default String getClickIdentifier() {
return null;
}

/**
* If the click was cancelled.
*
* @return If the click was cancelled.
*/
boolean isCancelled();

/**
* Cancels the click.
*
* @param cancelled If the click should be cancelled.
*/
void setCancelled(boolean cancelled);

/**
* <b><i> This is an internal inventory-framework API that should not be used from outside of
* this library. No compatibility guarantees are provided. </i></b>
*/
@ApiStatus.Internal
Object getPlatformEvent();

/**
* <b><i> This is an internal inventory-framework API that should not be used from outside of
* this library. No compatibility guarantees are provided. </i></b>
*/
@ApiStatus.Internal
boolean isCombined();
}
Loading
Loading