public class ItemSet
extends java.lang.Object
CfItems
known to the player.Modifier and Type | Field and Description |
---|---|
private java.util.Map<java.lang.Integer,CfItem> |
allItems
Maps item tags to items.
|
private HashedEventListenerList<ItemListener> |
itemListeners
The registered
ItemListeners to be notified about
changes. |
private java.util.Map<java.lang.Integer,java.util.List<CfItem>> |
items
Maps location (=tag) to list of items in that location.
|
private EventListenerList2<ItemSetListener> |
itemSetListeners
The list of
ItemSetListeners to be notified about
changes. |
private int |
openContainerFloor
The currently opened container or
0 . |
private CfItem |
player
The current player object this client controls.
|
private java.lang.Object |
sync
The synchronization object for
player . |
Constructor and Description |
---|
ItemSet() |
Modifier and Type | Method and Description |
---|---|
void |
addInventoryListener(int tag,
ItemListener listener)
Adds an
ItemListener to be notified about changes. |
void |
addItem(CfItem item)
Adds an item.
|
private void |
addItem(CfItem item,
boolean notifyListeners)
Adds a
CfItem . |
void |
addItemSetListener(ItemSetListener listener)
Adds an
ItemSetListener to be notified about changes. |
void |
cleanInventory(int tag)
Clears the inventory of an item.
|
private java.util.List<CfItem> |
getInventoryByTag(int tag)
Returns the inventory of an item.
|
CfItem |
getInventoryItem(int tag,
int index)
Returns a
CfItem from the inventory of an item. |
CfItem |
getItemByTag(int tag)
Returns an item by tag.
|
private CfItem |
getItemOrPlayer(int tag)
Returns an item by tag.
|
java.util.List<CfItem> |
getItemsByLocation(int location)
Returns a list of items in a given location.
|
int |
getNumberOfItemsByLocation(int location)
Returns the number of items in a given location.
|
int |
getOpenContainer()
Returns the currently opened container.
|
CfItem |
getPlayer()
Returns the player object this client controls.
|
java.lang.Iterable<CfItem> |
getPlayerInventory()
Returns the player's inventory.
|
void |
removeInventoryListener(int tag,
ItemListener listener)
Removes an
ItemListener to be notified about changes. |
private int |
removeItemByTag(int tag,
boolean notifyListeners)
Removes a
CfItem . |
void |
removeItems(int[] tags)
Deletes items by tag.
|
void |
removeItemSetListener(ItemSetListener listener)
Removes an
ItemSetListener to be notified about changes. |
void |
reset()
Resets the manager's state.
|
private void |
setOpenContainer(int openContainerFloor)
Sets the currently opened container.
|
void |
setPlayer(CfItem player)
Sets the player object this client controls.
|
void |
updateItem(int flags,
int tag,
int valLocation,
int valFlags,
int valWeight,
Face valFace,
java.lang.String valName,
java.lang.String valNamePl,
int valAnim,
int valAnimSpeed,
int valNrof)
Processes an "upditem" command.
|
@NotNull private final java.util.Map<java.lang.Integer,CfItem> allItems
@NotNull private final HashedEventListenerList<ItemListener> itemListeners
ItemListeners
to be notified about
changes.@NotNull private final java.util.Map<java.lang.Integer,java.util.List<CfItem>> items
@NotNull private final EventListenerList2<ItemSetListener> itemSetListeners
ItemSetListeners
to be notified about
changes.private int openContainerFloor
0
.@Nullable private CfItem player
@NotNull private final java.lang.Object sync
player
.public void addInventoryListener(int tag, @NotNull ItemListener listener)
ItemListener
to be notified about changes.tag
- the item tag to watchlistener
- the listener to addpublic void addItem(@NotNull CfItem item)
item
- the item to addprivate void addItem(@NotNull CfItem item, boolean notifyListeners)
CfItem
.item
- the item to addnotifyListeners
- whether listeners should be notified about the
additionpublic void addItemSetListener(@NotNull ItemSetListener listener)
ItemSetListener
to be notified about changes.listener
- the listener to addpublic void cleanInventory(int tag)
tag
- the item tag@NotNull private java.util.List<CfItem> getInventoryByTag(int tag)
tag
- the item's tag@Nullable public CfItem getInventoryItem(int tag, int index)
CfItem
from the inventory of an item.tag
- the item's tagindex
- the index of the inventory item to returnnull
if the index does not exist@Nullable public CfItem getItemByTag(int tag)
tag
- the tagnull
if no such items exists@Nullable private CfItem getItemOrPlayer(int tag)
tag
- the tagnull
if no such item exists@NotNull public java.util.List<CfItem> getItemsByLocation(int location)
location
- the locationpublic int getNumberOfItemsByLocation(int location)
0
.location
- the location to checkpublic int getOpenContainer()
@Nullable public CfItem getPlayer()
@NotNull public java.lang.Iterable<CfItem> getPlayerInventory()
public void removeInventoryListener(int tag, @NotNull ItemListener listener)
ItemListener
to be notified about changes.tag
- the item tag to watchlistener
- the listener to addprivate int removeItemByTag(int tag, boolean notifyListeners)
CfItem
.tag
- the item's tag to removenotifyListeners
- whether listeners should be notified about the
removal-1
public void removeItems(@NotNull int[] tags)
tags
- the tags to deletepublic void removeItemSetListener(@NotNull ItemSetListener listener)
ItemSetListener
to be notified about changes.listener
- the listener to removepublic void reset()
private void setOpenContainer(int openContainerFloor)
openContainerFloor
- the opened container's tag or 0
public void setPlayer(@Nullable CfItem player)
player
- the new player objectpublic void updateItem(int flags, int tag, int valLocation, int valFlags, int valWeight, Face valFace, @NotNull java.lang.String valName, @NotNull java.lang.String valNamePl, int valAnim, int valAnimSpeed, int valNrof)
flags
- the changed valuestag
- the item's tagvalLocation
- the item's locationvalFlags
- the item's flagsvalWeight
- the item's weightvalFace
- the item's facevalName
- the item's singular namevalNamePl
- the item's plural namevalAnim
- the item's animation IDvalAnimSpeed
- the item's animation speedvalNrof
- the number of items