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 @@ -22,6 +22,8 @@
import org.bukkit.block.Block;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.inventory.InventoryEvent;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
Expand Down Expand Up @@ -248,10 +250,20 @@ private static class InventoryNameHandler implements ExpressionPropertyHandler<I
}

@Override
public String convert(Inventory inventory) {
public String convert(Event event, Inventory inventory) {
if (event instanceof InventoryEvent inventoryEvent
&& inventoryEvent.getInventory().equals(inventory)
) {
return InventoryUtils.getTitle(inventoryEvent.getView());
}
return convert(inventory);
}

@Override
public @Nullable String convert(Inventory inventory) {
if (inventory.getViewers().isEmpty())
return null;
return InventoryUtils.getTitle(inventory.getViewers().get(0).getOpenInventory());
return InventoryUtils.getTitle(inventory.getViewers().getFirst().getOpenInventory());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public boolean init(Expression<?>[] expressions, int matchedPattern, Kleenean is
*/
@SuppressWarnings("unchecked")
protected <T> @Nullable Object convert(Event event, Handler handler, T source) {
return ((ExpressionPropertyHandler<T, ?>) handler).convert(source);
return ((ExpressionPropertyHandler<T, ?>) handler).convert(event, source);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import ch.njol.skript.classes.Changer;
import ch.njol.skript.lang.Expression;
import org.bukkit.event.Event;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
Expand All @@ -25,6 +26,20 @@ public interface ExpressionPropertyHandler<Type, ReturnType> extends PropertyHan

/**
* Converts the given object to the property value. This method may return arrays if the property is multi-valued.
* Prefer putting the majority of logic in {@link #convert(Object)} and delegating to it where possible.
* This method should contain event-specific logic only.
*
* @param event The event this is taking place in.
* @param propertyHolder The object to convert.
* @return The property value.
*/
default @Nullable ReturnType convert(Event event, Type propertyHolder) {
return convert(propertyHolder);
}

/**
* Converts the given object to the property value. This method may return arrays if the property is multi-valued.
* Callers should always prefer {@link #convert(Event, Object)}.
*
* @param propertyHolder The object to convert.
* @return The property value.
Expand Down