Skip to content
Merged
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 @@ -181,4 +181,48 @@ public interface IFContext extends VirtualView, StateValueHost {
*/
@ApiStatus.Experimental
boolean isShared();

/**
* Updates the container title for everyone that's viewing it.
*
* <p>This should not be used before the container is opened, if you need to set the __initial
* title__ use {@link IFOpenContext#modifyConfig()} on open handler instead.
*
* <p>This method is version dependant, so it may be that your server version is not yet
* supported, if you try to use this method and fail (can fail silently), report it to the
* library developers to add support to your version.
*
* @param title The new container title.
*/
void updateTitleForEveryone(@NotNull String title);

/**
* Updates the container title to all viewers in this context, to the initially defined title.
* Must be used after {@link #updateTitleForEveryone(String)} to take effect.
*/
void resetTitleForEveryone();

/**
* Closes this context's container to all viewers who are viewing it.
*/
void closeForEveryone();

/**
* Opens a new view for all viewers in that context.
* <p>
* This context will be immediately invalidated if there are no viewers left after opening.
*
* @param other The view to be opened.
*/
void openForEveryone(@NotNull Class<? extends RootView> other);

/**
* Opens a new view for all viewers in that context with an initially defined data.
* <p>
* This context will be immediately invalidated if there are no viewers left after opening.
*
* @param other The view to be opened.
* @param initialData The initial data.
*/
void openForEveryone(@NotNull Class<? extends RootView> other, Object initialData);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
import org.bukkit.entity.Player;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.UnknownNullability;

public interface Context extends IFContext {
public interface Context extends IFConfinedContext {

/**
* The player for the current interaction context.
Expand All @@ -15,8 +16,8 @@ public interface Context extends IFContext {
*
* @return A player in this interaction context.
*/
// @UnknownNullability
// Player getPlayer();
@UnknownNullability
Player getPlayer();

/**
* <p><b><i> This API is experimental and is not subject to the general compatibility guarantees
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
package me.devnatan.inventoryframework.context;

import me.devnatan.inventoryframework.BukkitViewer;
import me.devnatan.inventoryframework.RootView;
import me.devnatan.inventoryframework.Viewer;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.UnknownNullability;

public class SlotRenderContext extends SlotContext implements IFSlotRenderContext {

private final Player player;
private final Viewer viewer;

private ItemStack item;
Expand All @@ -19,6 +23,12 @@ public class SlotRenderContext extends SlotContext implements IFSlotRenderContex
public SlotRenderContext(int slot, @NotNull IFRenderContext parent, @Nullable Viewer viewer) {
super(slot, parent);
this.viewer = viewer;
this.player = viewer == null ? null : ((BukkitViewer) viewer).getPlayer();
}

@Override
public final @UnknownNullability Player getPlayer() {
return player;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,7 @@ public void onOpen(@NotNull TOpenContext open) {}
* This function should only be used to render items, any external call is completely forbidden
* as the function runs on the main thread.
*
* @param render The renderization context.
* @param render The rendering context.
*/
@ApiStatus.OverrideOnly
public void onFirstRender(@NotNull TRenderContext render) {}
Expand All @@ -768,7 +768,7 @@ public void onFirstRender(@NotNull TRenderContext render) {}
*
* <p>This is a rendering function and can modify the view's inventory.
*
* @param update The player view context.
* @param update The update context.
*/
@ApiStatus.OverrideOnly
public void onUpdate(@NotNull TContext update) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public final void closeForEveryone() {
*
* @param other The view to be opened.
*/
public final void openForEveryone(Class<? extends RootView> other) {
public final void openForEveryone(@NotNull Class<? extends RootView> other) {
openForEveryone(other, null);
}

Expand All @@ -102,7 +102,7 @@ public final void openForEveryone(Class<? extends RootView> other) {
* @param initialData The initial data.
*/
@SuppressWarnings("unchecked")
public final void openForEveryone(Class<? extends RootView> other, Object initialData) {
public final void openForEveryone(@NotNull Class<? extends RootView> other, Object initialData) {
getRoot().navigateTo(other, this, initialData);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import me.devnatan.inventoryframework.RootView;
import me.devnatan.inventoryframework.VirtualView;
import me.devnatan.inventoryframework.context.IFCloseContext;
import me.devnatan.inventoryframework.context.PlatformRenderContext;
import me.devnatan.inventoryframework.context.IFRenderContext;
import org.jetbrains.annotations.NotNull;

@SuppressWarnings("unchecked")
Expand All @@ -16,16 +16,16 @@ public void intercept(@NotNull PipelineContext<VirtualView> pipeline, VirtualVie
if (!(subject instanceof IFCloseContext)) return;

final IFCloseContext context = (IFCloseContext) subject;
final PlatformRenderContext parent = (PlatformRenderContext) context.getParent();
final PlatformView root = parent.getRoot();
final IFRenderContext parent = context.getParent();
final RootView root = parent.getRoot();
tryCallPlatformRootCloseHandler(root, context);

if (context.isCancelled()) {
pipeline.finish();
return;
}

root.removeAndTryInvalidateContext(context.getViewer(), context);
((PlatformView) root).removeAndTryInvalidateContext(context.getViewer(), context);
}

/**
Expand Down