VirtualInventory#getWindows, Item#getWindows

This commit is contained in:
NichtStudioCode 2021-05-11 19:32:14 +02:00
parent d42c242947
commit 048568cfac
3 changed files with 16 additions and 3 deletions

@ -36,9 +36,11 @@ public interface Item {
void removeWindow(Window window); void removeWindow(Window window);
/** /**
* Gets all the {@link Window}s the {@link Item} is displayed in. * Gets an immutable {@link Set} of all the {@link Window}s where this
* {@link Item} is displayed in.
* *
* @return The {@link Set} of {@link Window}s the {@link Item} is displayed in. * @return An immutable view of the {@link Set} of all the {@link Window}s
* where this {@link Item} is displayed in.
*/ */
Set<Window> getWindows(); Set<Window> getWindows();

@ -3,6 +3,7 @@ package de.studiocode.invui.item.impl;
import de.studiocode.invui.item.Item; import de.studiocode.invui.item.Item;
import de.studiocode.invui.window.Window; import de.studiocode.invui.window.Window;
import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
@ -25,7 +26,7 @@ public abstract class BaseItem implements Item {
@Override @Override
public Set<Window> getWindows() { public Set<Window> getWindows() {
return windows; return Collections.unmodifiableSet(windows);
} }
@Override @Override

@ -550,6 +550,16 @@ public class VirtualInventory implements ConfigurationSerializable {
windows.remove(window); windows.remove(window);
} }
/**
* Gets an immutable view of the {@link Set} that contains all the {@link Window}s that
* display this {@link VirtualInventory}.
*
* @return An UnmodifiableSet of all the {@link Window}s that show this {@link VirtualInventory}.
*/
public Set<Window> getWindows() {
return Collections.unmodifiableSet(windows);
}
/** /**
* Notifies all {@link Window}s displaying this {@link VirtualInventory} to update their * Notifies all {@link Window}s displaying this {@link VirtualInventory} to update their
* representative {@link ItemStack}s. * representative {@link ItemStack}s.